Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/env-empty-string.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

fix: don't report empty environment variables as missing
2 changes: 1 addition & 1 deletion packages/kit/src/exports/internal/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export function validate(variables, value, name, issues) {
const validator = config.schema;

if (!validator) {
if (!value) issues[name] = [MISSING];
if (value === undefined) issues[name] = [MISSING];
return value;
}

Expand Down
19 changes: 19 additions & 0 deletions packages/kit/src/exports/internal/env.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { assert, test } from 'vitest';
import { validate } from './env.js';

test('reports a variable without a validator as missing when it is undefined', () => {
/** @type {Record<string, import('@standard-schema/spec').StandardSchemaV1.Issue[]>} */
const issues = {};
validate({}, undefined, 'FOO', issues);

assert.ok(issues.FOO);
});

test('accepts an empty string for a variable without a validator', () => {
/** @type {Record<string, import('@standard-schema/spec').StandardSchemaV1.Issue[]>} */
const issues = {};
const value = validate({}, '', 'FOO', issues);

assert.equal(value, '');
assert.deepEqual(issues, {});
});
2 changes: 1 addition & 1 deletion packages/kit/src/exports/public.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2457,7 +2457,7 @@ export interface EnvVarConfig<T> {
* The validator can output any value — not necessarily a string — but public, non-static values must be
* serializable by [devalue](https://github.com/sveltejs/devalue) so that they can be sent to the browser.
*
* If omitted, the value must be a non-empty string.
* If omitted, the value must be set, but may be an empty string.
*/
schema?: StandardSchemaV1<string | undefined, T>;
/**
Expand Down
2 changes: 1 addition & 1 deletion packages/kit/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2414,7 +2414,7 @@ declare module '@sveltejs/kit' {
* The validator can output any value — not necessarily a string — but public, non-static values must be
* serializable by [devalue](https://github.com/sveltejs/devalue) so that they can be sent to the browser.
*
* If omitted, the value must be a non-empty string.
* If omitted, the value must be set, but may be an empty string.
*/
schema?: StandardSchemaV1<string | undefined, T>;
/**
Expand Down
Loading