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/legacy-env-imports.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': minor
---

feat: reinstate `$env/static/private`, `$env/dynamic/private`, `$env/static/public`, `$env/dynamic/public` and `$app/environment` as deprecated aliases for `$app/env/private` `$app/env/public` and `$app/env`
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ After following the setup below, they can be imported via the following modules:
- [`$app/env/public`]($app-env-public)

> [!LEGACY]
> The `$env/*` modules, along with `$app/environment` were removed in SvelteKit 3 in favour of explicit environment variables that were added in SvelteKit 2.62 as an experimental option.
> The `$env/*` modules, along with `$app/environment` were deprecated in SvelteKit 3 (and will be removed in SvelteKit 4) in favour of explicit environment variables that were added in SvelteKit 2.62 as an experimental option.

### Setup

Expand Down
2 changes: 1 addition & 1 deletion documentation/docs/98-reference/20-$app-environment.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
title: $app/environment
---

This module was removed in SvelteKit 3 in favour of [$app/env]($app-env).
This module was deprecated in SvelteKit 3 in favour of [$app/env]($app-env). It will be removed in SvelteKit 4.
2 changes: 1 addition & 1 deletion documentation/docs/98-reference/25-$env-dynamic-private.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
title: $env/dynamic/private
---

This module was removed in SvelteKit 3 in favour of [explicit environment variables](environment-variables).
This module was deprecated in SvelteKit 3 in favour of [explicit environment variables](environment-variables). It will be removed in SvelteKit 4.
2 changes: 1 addition & 1 deletion documentation/docs/98-reference/25-$env-dynamic-public.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
title: $env/dynamic/public
---

This module was removed in SvelteKit 3 in favour of [explicit environment variables](environment-variables).
This module was deprecated in SvelteKit 3 in favour of [explicit environment variables](environment-variables). It will be removed in SvelteKit 4.
2 changes: 1 addition & 1 deletion documentation/docs/98-reference/25-$env-static-private.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
title: $env/static/private
---

This module was removed in SvelteKit 3 in favour of [explicit environment variables](environment-variables).
This module was deprecated in SvelteKit 3 in favour of [explicit environment variables](environment-variables). It will be removed in SvelteKit 4.
2 changes: 1 addition & 1 deletion documentation/docs/98-reference/25-$env-static-public.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
title: $env/static/public
---

This module was removed in SvelteKit 3 in favour of [explicit environment variables](environment-variables).
This module was deprecated in SvelteKit 3 in favour of [explicit environment variables](environment-variables). It will be removed in SvelteKit 4.
2 changes: 2 additions & 0 deletions packages/kit/src/exports/vite/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ const enforced_config = {
resolve: {
alias: {
$app: true,
$env: true,
$lib: true,
'$service-worker': true
}
Expand Down Expand Up @@ -386,6 +387,7 @@ function kit({ svelte_config }) {
alias: [
{ find: '__SERVER__', replacement: `${generated}/server` },
{ find: '$app', replacement: `${runtime_directory}/app` },
{ find: '$env', replacement: `${runtime_directory}/env` },
...get_config_aliases(kit, root)
]
},
Expand Down
6 changes: 3 additions & 3 deletions packages/kit/src/runtime/app/environment/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { dev } from '../env/index.js';
import { DEV } from 'esm-env';
export * from '../env/index.js';

if (dev) {
console.warn('`$app/environment` is now `$app/env`');
if (DEV) {
console.warn('`$app/environment` is deprecated, use `$app/env` instead');
}
7 changes: 7 additions & 0 deletions packages/kit/src/runtime/env/dynamic/private.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { DEV } from 'esm-env';
import * as env from '../../app/env/private.js';
export { env };

if (DEV) {
console.warn('`$env/dynamic/private` is deprecated, use `$app/env/private` instead');
}
7 changes: 7 additions & 0 deletions packages/kit/src/runtime/env/dynamic/public.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { DEV } from 'esm-env';
import * as env from '../../app/env/public/index.js';
export { env };

if (DEV) {
console.warn('`$env/dynamic/public` is deprecated, use `$app/env/public` instead');
}
6 changes: 6 additions & 0 deletions packages/kit/src/runtime/env/static/private.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { DEV } from 'esm-env';
export * from '../../app/env/private.js';

if (DEV) {
console.warn('`$env/static/private` is deprecated, use `$app/env/private` instead');
}
6 changes: 6 additions & 0 deletions packages/kit/src/runtime/env/static/public.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { DEV } from 'esm-env';
export * from '../../app/env/public/index.js';

if (DEV) {
console.warn('`$env/static/public` is deprecated, use `$app/env/public` instead');
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// @ts-expect-error no type definitions since deprecated
import { PRIVATE_STATIC } from '$env/static/private';
// @ts-expect-error no type definitions since deprecated
import { env as dynamic_private } from '$env/dynamic/private';

export function load() {
return {
PRIVATE_STATIC,
PRIVATE_DYNAMIC: dynamic_private.PRIVATE_DYNAMIC
};
}
15 changes: 15 additions & 0 deletions packages/kit/test/apps/basics/src/routes/env/legacy/+page.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<script>
// @ts-expect-error no type definitions since deprecated
import { PUBLIC_STATIC } from '$env/static/public';
// @ts-expect-error no type definitions since deprecated
import { env as dynamic_public } from '$env/dynamic/public';

/** @type {import('./$types').PageData} */
export let data;
</script>

<p id="static-private">PRIVATE_STATIC: {data.PRIVATE_STATIC}</p>
<p id="dynamic-private">PRIVATE_DYNAMIC: {data.PRIVATE_DYNAMIC}</p>

<p id="static-public">PUBLIC_STATIC: {PUBLIC_STATIC}</p>
<p id="dynamic-public">PUBLIC_DYNAMIC: {dynamic_public.PUBLIC_DYNAMIC}</p>
18 changes: 18 additions & 0 deletions packages/kit/test/apps/basics/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,24 @@
'PUBLIC_DYNAMIC: accessible anywhere/evaluated at run time'
);
});

test('legacy $env/* imports still work', async ({ page }) => {
await page.goto('/env/legacy');

await expect(page.locator('#static-private')).toHaveText(
'PRIVATE_STATIC: accessible to server-side code/replaced at build time'
);
await expect(page.locator('#dynamic-private')).toHaveText(
'PRIVATE_DYNAMIC: accessible to server-side code/evaluated at run time'
);

await expect(page.locator('#static-public')).toHaveText(
'PUBLIC_STATIC: accessible anywhere/replaced at build time'
);
await expect(page.locator('#dynamic-public')).toHaveText(
'PUBLIC_DYNAMIC: accessible anywhere/evaluated at run time'
);
});
});

test.describe('Load', () => {
Expand Down Expand Up @@ -564,7 +582,7 @@
);
});

test('Prerendered +server.js called from a non-prerendered handle hook works', async ({

Check warning on line 585 in packages/kit/test/apps/basics/test/test.js

View workflow job for this annotation

GitHub Actions / test-kit (22, ubuntu-latest, chromium, current)

flaky test: Prerendered +server.js called from a non-prerendered handle hook works

retries: 2
clicknav,
page,
javaScriptEnabled
Expand Down Expand Up @@ -620,7 +638,7 @@
expect(await page.textContent('h1')).toBe('Hello from inside the nested layout component');
});

test('renders errors in the right layout', async ({ page }) => {

Check warning on line 641 in packages/kit/test/apps/basics/test/test.js

View workflow job for this annotation

GitHub Actions / test-kit (22, ubuntu-latest, chromium, current)

flaky test: renders errors in the right layout

retries: 2
await page.goto('/nested-layout/error');

expect(await page.textContent('footer')).toBe('Custom layout');
Expand Down
Loading