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/true-moles-tap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

chore: consolidate dev checks to use `esm-env` instead of a `__SVELTEKIT_DEV__` global
4 changes: 3 additions & 1 deletion packages/kit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@
"test:cross-platform:build": "pnpm test:unit && pnpm -r --workspace-concurrency 1 --filter=\"./test/**\" test:cross-platform:build",
"test:server-side-route-resolution:dev": "pnpm -r --workspace-concurrency 1 --filter=\"./test/**\" test:server-side-route-resolution:dev",
"test:server-side-route-resolution:build": "pnpm test:unit && pnpm -r --workspace-concurrency 1 --filter=\"./test/**\" test:server-side-route-resolution:build",
"test:unit": "vitest --config kit.vitest.config.js run",
"test:unit:dev": "vitest --config kit.vitest.config.js run",
"test:unit:prod": "NODE_ENV=production vitest --config kit.vitest.config.js run csp.spec.js cookie.spec.js",
"test:unit": "pnpm test:unit:dev && pnpm test:unit:prod",
"prepublishOnly": "pnpm generate:types",
"generate:version": "node scripts/generate-version.js",
"generate:types": "node scripts/generate-dts.js"
Expand Down
2 changes: 0 additions & 2 deletions packages/kit/src/exports/vite/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,6 @@ async function kit({ svelte_config }) {
__SVELTEKIT_ADAPTER_NAME__: s(kit.adapter?.name),
__SVELTEKIT_APP_VERSION_FILE__: s(`${kit.appDir}/version.json`),
__SVELTEKIT_APP_VERSION_POLL_INTERVAL__: s(kit.version.pollInterval),
__SVELTEKIT_DEV__: 'false',
__SVELTEKIT_EMBEDDED__: s(kit.embedded),
__SVELTEKIT_EXPERIMENTAL__REMOTE_FUNCTIONS__: s(kit.experimental.remoteFunctions),
__SVELTEKIT_CLIENT_ROUTING__: s(kit.router.resolution === 'client'),
Expand All @@ -351,7 +350,6 @@ async function kit({ svelte_config }) {
} else {
new_config.define = {
__SVELTEKIT_APP_VERSION_POLL_INTERVAL__: '0',
__SVELTEKIT_DEV__: 'true',
__SVELTEKIT_EMBEDDED__: s(kit.embedded),
__SVELTEKIT_EXPERIMENTAL__REMOTE_FUNCTIONS__: s(kit.experimental.remoteFunctions),
__SVELTEKIT_CLIENT_ROUTING__: s(kit.router.resolution === 'client'),
Expand Down
18 changes: 9 additions & 9 deletions packages/kit/src/runtime/app/state/server.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { DEV } from 'esm-env';
import { getContext } from 'svelte';

function context() {
Expand All @@ -16,31 +17,30 @@ function context_dev(name) {
}
}

// TODO we're using DEV in some places and __SVELTEKIT_DEV__ in others - why? Can we consolidate?
export const page = {
get data() {
return (__SVELTEKIT_DEV__ ? context_dev('page.data') : context()).page.data;
return (DEV ? context_dev('page.data') : context()).page.data;
},
get error() {
return (__SVELTEKIT_DEV__ ? context_dev('page.error') : context()).page.error;
return (DEV ? context_dev('page.error') : context()).page.error;
},
get form() {
return (__SVELTEKIT_DEV__ ? context_dev('page.form') : context()).page.form;
return (DEV ? context_dev('page.form') : context()).page.form;
},
get params() {
return (__SVELTEKIT_DEV__ ? context_dev('page.params') : context()).page.params;
return (DEV ? context_dev('page.params') : context()).page.params;
},
get route() {
return (__SVELTEKIT_DEV__ ? context_dev('page.route') : context()).page.route;
return (DEV ? context_dev('page.route') : context()).page.route;
},
get state() {
return (__SVELTEKIT_DEV__ ? context_dev('page.state') : context()).page.state;
return (DEV ? context_dev('page.state') : context()).page.state;
},
get status() {
return (__SVELTEKIT_DEV__ ? context_dev('page.status') : context()).page.status;
return (DEV ? context_dev('page.status') : context()).page.status;
},
get url() {
return (__SVELTEKIT_DEV__ ? context_dev('page.url') : context()).page.url;
return (DEV ? context_dev('page.url') : context()).page.url;
}
};

Expand Down
8 changes: 4 additions & 4 deletions packages/kit/src/runtime/app/stores.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getContext } from 'svelte';
import { BROWSER } from 'esm-env';
import { BROWSER, DEV } from 'esm-env';
import { stores as browser_stores } from '../client/client.js';

/**
Expand Down Expand Up @@ -35,7 +35,7 @@ export const getStores = () => {
*/
export const page = {
subscribe(fn) {
const store = __SVELTEKIT_DEV__ ? get_store('page') : getStores().page;
const store = DEV ? get_store('page') : getStores().page;
return store.subscribe(fn);
}
};
Expand All @@ -52,7 +52,7 @@ export const page = {
*/
export const navigating = {
subscribe(fn) {
const store = __SVELTEKIT_DEV__ ? get_store('navigating') : getStores().navigating;
const store = DEV ? get_store('navigating') : getStores().navigating;
return store.subscribe(fn);
}
};
Expand All @@ -67,7 +67,7 @@ export const navigating = {
*/
export const updated = {
subscribe(fn) {
const store = __SVELTEKIT_DEV__ ? get_store('updated') : getStores().updated;
const store = DEV ? get_store('updated') : getStores().updated;

if (BROWSER) {
updated.check = store.check;
Expand Down
5 changes: 3 additions & 2 deletions packages/kit/src/runtime/server/cookie.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { parse, serialize } from 'cookie';
import { DEV } from 'esm-env';
import { normalize_path, resolve } from '../../utils/url.js';
import { add_data_suffix } from '../pathname.js';
import { text_encoder } from '../utils.js';
Expand Down Expand Up @@ -96,7 +97,7 @@ export function get_cookies(request, url) {
// in development, if the cookie was set during this session with `cookies.set`,
// but at a different path, warn the user. (ignore cookies from request headers,
// since we don't know which path they were set at)
if (__SVELTEKIT_DEV__ && !cookie) {
if (DEV && !cookie) {
const paths = Array.from(cookie_paths[name] ?? []).filter((path) => {
// we only care about paths that are _more_ specific than the current path
return path_matches(path, url.pathname) && path !== url.pathname;
Expand Down Expand Up @@ -252,7 +253,7 @@ export function get_cookies(request, url) {
const cookie = { name, value, options: { ...options, path } };
new_cookies.set(cookie_key, cookie);

if (__SVELTEKIT_DEV__) {
if (DEV) {
const serialized = serialize(name, value, cookie.options);
if (text_encoder.encode(serialized).byteLength > MAX_COOKIE_SIZE) {
throw new Error(`Cookie "${name}" is too large, and will be discarded by the browser`);
Expand Down
Loading
Loading