@sveltejs/kit 3.0.0-next.2 → 3.0.0-next.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +62 -36
- package/src/cli.js +15 -12
- package/src/constants.js +6 -1
- package/src/core/adapt/builder.js +66 -72
- package/src/core/adapt/index.js +17 -6
- package/src/core/config/index.js +134 -80
- package/src/core/config/options.js +295 -273
- package/src/core/config/types.d.ts +1 -1
- package/src/core/env.js +146 -16
- package/src/core/generate_manifest/index.js +18 -15
- package/src/core/postbuild/analyse.js +8 -20
- package/src/core/postbuild/crawl.js +22 -6
- package/src/core/postbuild/entities.js +8 -2
- package/src/core/postbuild/fallback.js +4 -2
- package/src/core/postbuild/prerender.js +222 -70
- package/src/core/postbuild/queue.js +2 -1
- package/src/core/sync/create_manifest_data/conflict.js +1 -1
- package/src/core/sync/create_manifest_data/index.js +82 -62
- package/src/core/sync/sync.js +40 -31
- package/src/core/sync/ts.js +1 -1
- package/src/core/sync/utils.js +22 -2
- package/src/core/sync/{write_non_ambient.js → write_app_types.js} +107 -58
- package/src/core/sync/write_client_manifest.js +14 -29
- package/src/core/sync/write_env.js +7 -5
- package/src/core/sync/write_server.js +37 -45
- package/src/core/sync/write_tsconfig/index.js +274 -0
- package/src/core/sync/write_tsconfig/test-app/package.json +7 -0
- package/src/core/sync/write_tsconfig/utils.js +77 -0
- package/src/core/sync/write_tsconfig/validate.js +128 -0
- package/src/core/sync/write_types/index.js +127 -123
- package/src/core/utils.js +30 -5
- package/src/exports/env/index.js +77 -0
- package/src/exports/env/public.d.ts +55 -0
- package/src/exports/hooks/index.js +3 -9
- package/src/exports/hooks/public.d.ts +195 -0
- package/src/exports/hooks/sequence.js +9 -6
- package/src/exports/index.js +52 -29
- package/src/exports/internal/client.js +5 -0
- package/src/exports/internal/env.js +8 -5
- package/src/exports/internal/index.js +1 -90
- package/src/exports/internal/{event.js → server/event.js} +2 -3
- package/src/exports/internal/server/index.js +37 -0
- package/src/exports/internal/server/telemetry.js +95 -0
- package/src/exports/internal/shared.js +90 -0
- package/src/exports/node/index.js +64 -22
- package/src/exports/params/index.js +70 -0
- package/src/exports/params/public.d.ts +63 -0
- package/src/exports/public.d.ts +50 -1733
- package/src/exports/remote/index.js +11 -0
- package/src/exports/remote/public.d.ts +519 -0
- package/src/exports/url.js +86 -0
- package/src/exports/vite/build/build_server.js +54 -65
- package/src/exports/vite/build/remote.js +24 -19
- package/src/exports/vite/build/utils.js +0 -8
- package/src/exports/vite/dev/index.js +218 -146
- package/src/exports/vite/index.js +1590 -858
- package/src/exports/vite/module_ids.js +2 -2
- package/src/exports/vite/preview/index.js +40 -32
- package/src/exports/vite/public.d.ts +588 -0
- package/src/exports/vite/utils.js +84 -46
- package/src/pathname.js +55 -0
- package/src/runner.js +15 -0
- package/src/runtime/app/env/internal.js +4 -4
- package/src/runtime/app/env/types.d.ts +1 -1
- package/src/runtime/app/environment/index.js +3 -3
- package/src/runtime/app/{forms.js → forms/index.js} +73 -42
- package/src/runtime/app/forms/public.d.ts +2 -0
- package/src/runtime/app/forms/types.d.ts +56 -0
- package/src/runtime/app/internal/transport.js +53 -0
- package/src/runtime/app/manifest/index.js +1 -0
- package/src/runtime/app/{navigation.js → navigation/index.js} +2 -1
- package/src/runtime/app/navigation/public.d.ts +237 -0
- package/src/runtime/app/paths/client.js +37 -37
- package/src/runtime/app/paths/index.js +1 -1
- package/src/runtime/app/paths/internal/client.js +34 -2
- package/src/runtime/app/paths/internal/server.js +6 -23
- package/src/runtime/app/paths/internal.d.ts +3 -0
- package/src/runtime/app/paths/public.d.ts +1 -29
- package/src/runtime/app/paths/server.js +36 -17
- package/src/runtime/app/paths/types.d.ts +11 -19
- package/src/runtime/app/server/index.js +2 -2
- package/src/runtime/app/server/public.d.ts +201 -0
- package/src/runtime/app/server/remote/command.js +13 -11
- package/src/runtime/app/server/remote/form.js +61 -39
- package/src/runtime/app/server/remote/prerender.js +45 -45
- package/src/runtime/app/server/remote/query.js +106 -108
- package/src/runtime/app/server/remote/requested.js +27 -19
- package/src/runtime/app/server/remote/shared.js +76 -76
- package/src/runtime/app/service-worker/index.js +24 -0
- package/src/runtime/app/state/client.js +4 -2
- package/src/runtime/app/state/index.js +7 -5
- package/src/runtime/app/state/public.d.ts +72 -0
- package/src/runtime/app/state/server.js +3 -0
- package/src/runtime/app/stores.js +15 -78
- package/src/runtime/client/bundle.js +1 -1
- package/src/runtime/client/client-entry.js +3 -0
- package/src/runtime/client/client.js +1336 -648
- package/src/runtime/client/constants.js +3 -6
- package/src/runtime/client/entry.js +24 -3
- package/src/runtime/client/fetcher.js +25 -25
- package/src/runtime/client/ndjson.js +1 -1
- package/src/runtime/client/parse.js +1 -1
- package/src/runtime/client/payload.js +17 -0
- package/src/runtime/client/remote-functions/cache.svelte.js +3 -1
- package/src/runtime/client/remote-functions/command.svelte.js +37 -61
- package/src/runtime/client/remote-functions/form.svelte.js +267 -178
- package/src/runtime/client/remote-functions/prerender.svelte.js +32 -11
- package/src/runtime/client/remote-functions/query/index.js +10 -17
- package/src/runtime/client/remote-functions/query/instance.svelte.js +64 -18
- package/src/runtime/client/remote-functions/query/proxy.js +5 -5
- package/src/runtime/client/remote-functions/query-batch.svelte.js +61 -70
- package/src/runtime/client/remote-functions/query-live/index.js +1 -1
- package/src/runtime/client/remote-functions/query-live/instance.svelte.js +63 -21
- package/src/runtime/client/remote-functions/query-live/iterator.js +15 -12
- package/src/runtime/client/remote-functions/query-live/proxy.js +2 -12
- package/src/runtime/client/remote-functions/shared.svelte.js +90 -65
- package/src/runtime/client/snapshots.js +147 -0
- package/src/runtime/client/state.svelte.js +94 -55
- package/src/runtime/client/stream.js +3 -2
- package/src/runtime/client/types.d.ts +13 -9
- package/src/runtime/client/utils.js +22 -110
- package/src/runtime/components/root.svelte +56 -0
- package/src/runtime/env/dynamic/private.js +7 -0
- package/src/runtime/env/dynamic/public.js +7 -0
- package/src/runtime/env/static/private.js +6 -0
- package/src/runtime/env/static/public.js +6 -0
- package/src/runtime/form-utils.js +172 -61
- package/src/runtime/pathname.js +20 -32
- package/src/runtime/props.svelte.js +72 -0
- package/src/runtime/server/constants.js +0 -3
- package/src/runtime/server/cookie.js +72 -55
- package/src/runtime/server/csrf.js +65 -0
- package/src/runtime/server/data/index.js +49 -53
- package/src/runtime/server/dev.js +22 -0
- package/src/runtime/server/endpoint.js +6 -7
- package/src/runtime/server/env_module.js +0 -5
- package/src/runtime/server/errors.js +160 -0
- package/src/runtime/server/fetch.js +32 -39
- package/src/runtime/server/index.js +90 -64
- package/src/runtime/server/internal.js +71 -0
- package/src/runtime/server/page/actions.js +85 -64
- package/src/runtime/server/page/crypto.js +2 -2
- package/src/runtime/server/page/csp.js +88 -104
- package/src/runtime/server/page/data_serializer.js +24 -25
- package/src/runtime/server/page/index.js +36 -53
- package/src/runtime/server/page/load_data.js +50 -57
- package/src/runtime/server/page/render.js +173 -239
- package/src/runtime/server/page/respond_with_error.js +17 -31
- package/src/runtime/server/page/serialize_data.js +2 -13
- package/src/runtime/server/page/server_routing.js +85 -26
- package/src/runtime/server/remote-functions.js +640 -0
- package/src/runtime/server/respond.js +190 -131
- package/src/runtime/server/sourcemaps.js +183 -0
- package/src/runtime/server/state.js +53 -0
- package/src/runtime/server/utils.js +13 -155
- package/src/runtime/shared.js +20 -40
- package/src/runtime/utils.js +3 -0
- package/src/types/ambient-private.d.ts +11 -1
- package/src/types/ambient.d.ts +87 -36
- package/src/types/global-private.d.ts +25 -25
- package/src/types/internal.d.ts +163 -157
- package/src/types/private.d.ts +41 -1
- package/src/utils/error.js +28 -4
- package/src/utils/escape.js +9 -25
- package/src/utils/features.js +1 -1
- package/src/utils/filesystem.js +1 -23
- package/src/utils/fork.js +7 -2
- package/src/utils/hash.js +21 -0
- package/src/utils/http.js +8 -7
- package/src/utils/import.js +9 -2
- package/src/utils/imports.js +83 -0
- package/src/utils/mime.js +9 -0
- package/src/utils/page_nodes.js +6 -7
- package/src/utils/params.js +67 -0
- package/src/utils/regex.js +9 -0
- package/src/utils/routing.js +145 -73
- package/src/utils/shared-iterator.js +5 -0
- package/src/utils/streaming.js +14 -4
- package/src/utils/url.js +33 -2
- package/src/version.js +1 -1
- package/types/index.d.ts +2616 -2433
- package/types/index.d.ts.map +120 -106
- package/src/core/sync/write_ambient.js +0 -18
- package/src/core/sync/write_root.js +0 -148
- package/src/core/sync/write_tsconfig.js +0 -250
- package/src/exports/internal/server.js +0 -22
- package/src/exports/node/polyfills.js +0 -30
- package/src/runtime/server/app.js +0 -9
- package/src/runtime/server/remote.js +0 -457
- package/src/runtime/shared-server.js +0 -7
- package/src/runtime/telemetry/otel.js +0 -21
- package/src/runtime/telemetry/record_span.js +0 -65
- package/src/types/synthetic/$lib.md +0 -5
- /package/src/exports/internal/{remote-functions.js → server/remote-functions.js} +0 -0
- /package/src/{runtime/telemetry/noop.js → telemetry.js} +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sveltejs/kit",
|
|
3
|
-
"version": "3.0.0-next.
|
|
3
|
+
"version": "3.0.0-next.21",
|
|
4
4
|
"description": "SvelteKit is the fastest way to build Svelte apps",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"framework",
|
|
@@ -18,37 +18,39 @@
|
|
|
18
18
|
"homepage": "https://svelte.dev",
|
|
19
19
|
"type": "module",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@
|
|
22
|
-
"@
|
|
23
|
-
"acorn": "^
|
|
24
|
-
"
|
|
25
|
-
"
|
|
21
|
+
"@rolldown/pluginutils": "^1.0.1",
|
|
22
|
+
"@standard-schema/spec": "^1.1.0",
|
|
23
|
+
"@sveltejs/acorn-typescript": "^1.0.12",
|
|
24
|
+
"acorn": "^8.18.0",
|
|
25
|
+
"cookie": "^2.0.1",
|
|
26
|
+
"devalue": "^5.9.0",
|
|
26
27
|
"esm-env": "^1.2.2",
|
|
27
|
-
"magic-string": "^
|
|
28
|
-
"mrmime": "^2.0.
|
|
29
|
-
"sirv": "^3.0.
|
|
28
|
+
"magic-string": "^1.1.0",
|
|
29
|
+
"mrmime": "^2.0.1",
|
|
30
|
+
"sirv": "^3.0.2"
|
|
30
31
|
},
|
|
31
32
|
"devDependencies": {
|
|
32
|
-
"@opentelemetry/api": "^1.
|
|
33
|
-
"@playwright/test": "^1.
|
|
34
|
-
"@sveltejs/vite-plugin-svelte": "^7.
|
|
33
|
+
"@opentelemetry/api": "^1.9.1",
|
|
34
|
+
"@playwright/test": "^1.62.0",
|
|
35
|
+
"@sveltejs/vite-plugin-svelte": "^7.3.0",
|
|
35
36
|
"@types/connect": "^3.4.38",
|
|
37
|
+
"@typescript/native": "npm:typescript@^7.0.2",
|
|
36
38
|
"@types/node": "^22.19.19",
|
|
37
|
-
"dts-buddy": "^0.8.
|
|
38
|
-
"jsdom": "^
|
|
39
|
-
"
|
|
40
|
-
"svelte": "^5.55.7",
|
|
39
|
+
"dts-buddy": "^0.8.3",
|
|
40
|
+
"jsdom": "^30.0.0",
|
|
41
|
+
"svelte": "^5.56.8",
|
|
41
42
|
"svelte-preprocess": "^6.0.5",
|
|
42
|
-
"typescript": "~6.0.
|
|
43
|
-
"
|
|
44
|
-
"
|
|
43
|
+
"typescript": "~6.0.3",
|
|
44
|
+
"valibot": "^1.4.2",
|
|
45
|
+
"vite": "^8.2.1",
|
|
46
|
+
"vitest": "^4.1.10"
|
|
45
47
|
},
|
|
46
48
|
"peerDependencies": {
|
|
47
|
-
"@sveltejs/vite-plugin-svelte": "^7.0.0",
|
|
48
49
|
"@opentelemetry/api": "^1.0.0",
|
|
49
|
-
"svelte": "^
|
|
50
|
+
"@sveltejs/vite-plugin-svelte": "^7.0.0",
|
|
51
|
+
"svelte": "^5.56.4",
|
|
50
52
|
"typescript": "^6.0.0",
|
|
51
|
-
"vite": "^8.0.
|
|
53
|
+
"vite": "^8.0.12"
|
|
52
54
|
},
|
|
53
55
|
"peerDependenciesMeta": {
|
|
54
56
|
"@opentelemetry/api": {
|
|
@@ -70,13 +72,24 @@
|
|
|
70
72
|
"svelte-kit.js"
|
|
71
73
|
],
|
|
72
74
|
"imports": {
|
|
75
|
+
"#app/internal/transport": {
|
|
76
|
+
"default": "./src/runtime/app/internal/transport.js"
|
|
77
|
+
},
|
|
73
78
|
"#app/paths": {
|
|
79
|
+
"types": "./src/runtime/app/paths/internal.d.ts",
|
|
80
|
+
"workerd": "./src/runtime/app/paths/server.js",
|
|
74
81
|
"browser": "./src/runtime/app/paths/client.js",
|
|
75
82
|
"default": "./src/runtime/app/paths/server.js"
|
|
76
83
|
},
|
|
77
84
|
"#app/env/public": {
|
|
85
|
+
"workerd": "./src/runtime/app/env/public/server.js",
|
|
78
86
|
"browser": "./src/runtime/app/env/public/client.js",
|
|
79
87
|
"default": "./src/runtime/app/env/public/server.js"
|
|
88
|
+
},
|
|
89
|
+
"#internal": {
|
|
90
|
+
"workerd": "./src/exports/internal/server/index.js",
|
|
91
|
+
"browser": "./src/exports/internal/client.js",
|
|
92
|
+
"default": "./src/exports/internal/server/index.js"
|
|
80
93
|
}
|
|
81
94
|
},
|
|
82
95
|
"exports": {
|
|
@@ -94,11 +107,11 @@
|
|
|
94
107
|
"import": "./src/exports/internal/env.js"
|
|
95
108
|
},
|
|
96
109
|
"./internal/types": {
|
|
97
|
-
"
|
|
110
|
+
"types": "./src/exports/internal/types.d.ts"
|
|
98
111
|
},
|
|
99
112
|
"./internal/server": {
|
|
100
113
|
"types": "./types/index.d.ts",
|
|
101
|
-
"import": "./src/exports/internal/server.js"
|
|
114
|
+
"import": "./src/exports/internal/server/index.js"
|
|
102
115
|
},
|
|
103
116
|
"./node": {
|
|
104
117
|
"types": "./types/index.d.ts",
|
|
@@ -108,6 +121,18 @@
|
|
|
108
121
|
"types": "./types/index.d.ts",
|
|
109
122
|
"import": "./src/exports/hooks/index.js"
|
|
110
123
|
},
|
|
124
|
+
"./env": {
|
|
125
|
+
"types": "./types/index.d.ts",
|
|
126
|
+
"import": "./src/exports/env/index.js"
|
|
127
|
+
},
|
|
128
|
+
"./params": {
|
|
129
|
+
"types": "./types/index.d.ts",
|
|
130
|
+
"import": "./src/exports/params/index.js"
|
|
131
|
+
},
|
|
132
|
+
"./remote": {
|
|
133
|
+
"types": "./types/index.d.ts",
|
|
134
|
+
"import": "./src/exports/remote/index.js"
|
|
135
|
+
},
|
|
111
136
|
"./vite": {
|
|
112
137
|
"types": "./types/index.d.ts",
|
|
113
138
|
"import": "./src/exports/vite/index.js"
|
|
@@ -115,24 +140,25 @@
|
|
|
115
140
|
},
|
|
116
141
|
"types": "types/index.d.ts",
|
|
117
142
|
"engines": {
|
|
118
|
-
"node": ">=22"
|
|
143
|
+
"node": ">=22.17"
|
|
119
144
|
},
|
|
120
145
|
"scripts": {
|
|
121
|
-
"lint": "
|
|
122
|
-
"check": "tsc &&
|
|
123
|
-
"check:all": "tsc && pnpm -r --filter=\"./**\" check",
|
|
124
|
-
"format": "
|
|
146
|
+
"lint": "oxfmt --check .",
|
|
147
|
+
"check": "pnpm tsc-native && pnpm tsc-native --project test/types/tsconfig.json && pnpm tsc-native --project test/types/app-error-enhanced/tsconfig.json",
|
|
148
|
+
"check:all": "pnpm tsc-native && pnpm -r --filter=\"./**\" check",
|
|
149
|
+
"format": "oxfmt --write .",
|
|
125
150
|
"test": "pnpm test:unit && pnpm test:integration",
|
|
126
151
|
"test:integration": "pnpm -r --workspace-concurrency 1 --filter=\"./test/**\" test",
|
|
127
|
-
"test:
|
|
128
|
-
"test:
|
|
152
|
+
"test:dev": "pnpm -r --workspace-concurrency 1 --filter=\"./test/**\" test:dev",
|
|
153
|
+
"test:build": "pnpm -r --workspace-concurrency 1 --filter=\"./test/**\" test:build",
|
|
154
|
+
"test:cross-platform:dev": "pnpm test:unit && pnpm -r --workspace-concurrency 1 --filter=\"./test/**\" test:cross-platform:dev",
|
|
155
|
+
"test:cross-platform:build": "pnpm -r --workspace-concurrency 1 --filter=\"./test/**\" test:cross-platform:build",
|
|
129
156
|
"test:server-side-route-resolution:dev": "pnpm -r --workspace-concurrency 1 --filter=\"./test/**\" test:server-side-route-resolution:dev",
|
|
130
|
-
"test:server-side-route-resolution:build": "pnpm
|
|
157
|
+
"test:server-side-route-resolution:build": "pnpm -r --workspace-concurrency 1 --filter=\"./test/**\" test:server-side-route-resolution:build",
|
|
131
158
|
"test:svelte-async:dev": "pnpm -r --workspace-concurrency 1 --filter=\"./test/**\" test:svelte-async:dev",
|
|
132
|
-
"test:svelte-async:build": "pnpm
|
|
133
|
-
"test:unit
|
|
134
|
-
"
|
|
135
|
-
"test:unit": "pnpm test:unit:dev && pnpm test:unit:prod",
|
|
159
|
+
"test:svelte-async:build": "pnpm -r --workspace-concurrency 1 --filter=\"./test/**\" test:svelte-async:build",
|
|
160
|
+
"test:unit": "vitest run -c vitest.kit.config.js",
|
|
161
|
+
"tsc-native": "node node_modules/@typescript/native/bin/tsc",
|
|
136
162
|
"generate:version": "node scripts/generate-version.js",
|
|
137
163
|
"generate:types": "node scripts/generate-dts.js"
|
|
138
164
|
}
|
package/src/cli.js
CHANGED
|
@@ -2,8 +2,9 @@ import fs from 'node:fs';
|
|
|
2
2
|
import process from 'node:process';
|
|
3
3
|
import { parseArgs, styleText } from 'node:util';
|
|
4
4
|
import { extract_svelte_config, load_vite_config } from './core/config/index.js';
|
|
5
|
-
import { coalesce_to_error } from './utils/error.js';
|
|
6
5
|
import { resolve_explicit_env_entry } from './core/env.js';
|
|
6
|
+
import { coalesce_to_error } from './utils/error.js';
|
|
7
|
+
import { import_peer } from './utils/import.js';
|
|
7
8
|
|
|
8
9
|
/** @param {unknown} e */
|
|
9
10
|
function handle_error(e) {
|
|
@@ -75,19 +76,19 @@ if (!command) {
|
|
|
75
76
|
}
|
|
76
77
|
|
|
77
78
|
if (command === 'sync') {
|
|
78
|
-
// create placeholder
|
|
79
|
+
// create placeholder node_modules/$app/tsconfig.json if necessary, to squelch warnings.
|
|
79
80
|
// this isn't bulletproof — if someone has some esoteric config, it will continue
|
|
80
81
|
// to harmlessly warn — but we handle the 90% case and clean up after ourselves
|
|
81
|
-
const
|
|
82
|
-
const base_tsconfig = `${
|
|
82
|
+
const dir = 'node_modules/$app';
|
|
83
|
+
const base_tsconfig = `${dir}/tsconfig.json`;
|
|
83
84
|
const base_tsconfig_json = '{}';
|
|
84
85
|
|
|
85
|
-
const sveltekit_dir_exists = fs.existsSync(
|
|
86
|
+
const sveltekit_dir_exists = fs.existsSync(dir);
|
|
86
87
|
const base_tsconfig_exists = fs.existsSync(base_tsconfig);
|
|
87
88
|
|
|
88
89
|
if (!base_tsconfig_exists) {
|
|
89
90
|
try {
|
|
90
|
-
fs.mkdirSync(
|
|
91
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
91
92
|
} catch {
|
|
92
93
|
// ignore
|
|
93
94
|
}
|
|
@@ -96,14 +97,16 @@ if (command === 'sync') {
|
|
|
96
97
|
}
|
|
97
98
|
|
|
98
99
|
try {
|
|
99
|
-
const
|
|
100
|
+
const vite = /** @type {typeof import('vite')} */ (await import_peer('vite', process.cwd()));
|
|
101
|
+
|
|
102
|
+
const vite_config = await load_vite_config(values.config, vite);
|
|
100
103
|
const sveltekit_config = extract_svelte_config(vite_config);
|
|
101
104
|
|
|
102
105
|
const sync = await import('./core/sync/sync.js');
|
|
103
|
-
sync.all_types(sveltekit_config);
|
|
106
|
+
sync.all_types(sveltekit_config, vite_config.root);
|
|
104
107
|
|
|
105
|
-
const explicit_env_entry = resolve_explicit_env_entry(sveltekit_config
|
|
106
|
-
await sync.env(sveltekit_config
|
|
108
|
+
const explicit_env_entry = resolve_explicit_env_entry(sveltekit_config);
|
|
109
|
+
await sync.env(vite, sveltekit_config, explicit_env_entry, vite_config.root, values.mode);
|
|
107
110
|
} catch (error) {
|
|
108
111
|
handle_error(error);
|
|
109
112
|
} finally {
|
|
@@ -113,8 +116,8 @@ if (command === 'sync') {
|
|
|
113
116
|
fs.unlinkSync(base_tsconfig);
|
|
114
117
|
}
|
|
115
118
|
|
|
116
|
-
if (!sveltekit_dir_exists && fs.readdirSync(
|
|
117
|
-
fs.rmSync(
|
|
119
|
+
if (!sveltekit_dir_exists && fs.readdirSync(dir).length === 0) {
|
|
120
|
+
fs.rmSync(dir, { recursive: true });
|
|
118
121
|
}
|
|
119
122
|
}
|
|
120
123
|
} else {
|
package/src/constants.js
CHANGED
|
@@ -4,10 +4,15 @@
|
|
|
4
4
|
*/
|
|
5
5
|
export const SVELTE_KIT_ASSETS = '/_svelte_kit_assets';
|
|
6
6
|
|
|
7
|
-
export const GENERATED_COMMENT = '// this file is generated — do not edit it
|
|
7
|
+
export const GENERATED_COMMENT = '// this file is generated — do not edit it';
|
|
8
8
|
|
|
9
9
|
export const ENDPOINT_METHODS = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS', 'HEAD'];
|
|
10
10
|
|
|
11
11
|
export const MUTATIVE_METHODS = ['POST', 'PUT', 'PATCH', 'DELETE'];
|
|
12
12
|
|
|
13
13
|
export const PAGE_METHODS = ['GET', 'POST', 'HEAD'];
|
|
14
|
+
|
|
15
|
+
export const SRC_ROOT = import.meta.dirname;
|
|
16
|
+
|
|
17
|
+
// eslint-disable-next-line n/prefer-global/process
|
|
18
|
+
export const IN_WEBCONTAINER = !!globalThis.process?.versions?.webcontainer;
|
|
@@ -1,16 +1,24 @@
|
|
|
1
1
|
/** @import { StandardSchemaV1 } from '@standard-schema/spec' */
|
|
2
2
|
/** @import { Builder } from '@sveltejs/kit' */
|
|
3
3
|
/** @import { ResolvedConfig } from 'vite' */
|
|
4
|
-
/** @import { RouteDefinition
|
|
4
|
+
/** @import { RouteDefinition } from '@sveltejs/kit' */
|
|
5
|
+
/** @import { EnvVarConfig } from '@sveltejs/kit/env' */
|
|
5
6
|
/** @import { RouteData, ValidatedConfig, BuildData, ServerMetadata, ServerMetadataRoute, Prerendered, PrerenderMap, Logger, RemoteChunk } from 'types' */
|
|
6
7
|
import { loadEnv } from 'vite';
|
|
7
8
|
import * as devalue from 'devalue';
|
|
8
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
createReadStream,
|
|
11
|
+
createWriteStream,
|
|
12
|
+
existsSync,
|
|
13
|
+
mkdirSync,
|
|
14
|
+
rmSync,
|
|
15
|
+
statSync
|
|
16
|
+
} from 'node:fs';
|
|
9
17
|
import { extname, resolve, join, dirname, relative } from 'node:path';
|
|
10
18
|
import { pipeline } from 'node:stream';
|
|
11
|
-
import { promisify
|
|
19
|
+
import { promisify } from 'node:util';
|
|
12
20
|
import zlib from 'node:zlib';
|
|
13
|
-
import { copy
|
|
21
|
+
import { copy } from '../../utils/filesystem.js';
|
|
14
22
|
import { posixify } from '../../utils/os.js';
|
|
15
23
|
import { generate_manifest } from '../generate_manifest/index.js';
|
|
16
24
|
import { get_route_segments } from '../../utils/routing.js';
|
|
@@ -18,11 +26,23 @@ import generate_fallback from '../postbuild/fallback.js';
|
|
|
18
26
|
import { write } from '../sync/utils.js';
|
|
19
27
|
import { list_files } from '../utils.js';
|
|
20
28
|
import { find_server_assets } from '../generate_manifest/find_server_assets.js';
|
|
21
|
-
import {
|
|
29
|
+
import { create_exported_declarations } from '../env.js';
|
|
22
30
|
import { handle_issues, validate } from '../../exports/internal/env.js';
|
|
23
31
|
|
|
24
32
|
const pipe = promisify(pipeline);
|
|
25
|
-
const extensions = [
|
|
33
|
+
const extensions = [
|
|
34
|
+
'.html',
|
|
35
|
+
'.js',
|
|
36
|
+
'.mjs',
|
|
37
|
+
'.json',
|
|
38
|
+
'.css',
|
|
39
|
+
'.svg',
|
|
40
|
+
'.xml',
|
|
41
|
+
'.wasm',
|
|
42
|
+
'.txt',
|
|
43
|
+
'.md',
|
|
44
|
+
'.mdx'
|
|
45
|
+
];
|
|
26
46
|
|
|
27
47
|
/**
|
|
28
48
|
* Creates the Builder which is passed to adapters for building the application.
|
|
@@ -87,8 +107,8 @@ export function create_builder({
|
|
|
87
107
|
|
|
88
108
|
return {
|
|
89
109
|
log,
|
|
90
|
-
rimraf,
|
|
91
|
-
mkdirp,
|
|
110
|
+
rimraf: (dir) => rmSync(dir, { force: true, recursive: true }),
|
|
111
|
+
mkdirp: (dir) => mkdirSync(dir, { recursive: true }),
|
|
92
112
|
copy,
|
|
93
113
|
|
|
94
114
|
config,
|
|
@@ -97,16 +117,19 @@ export function create_builder({
|
|
|
97
117
|
|
|
98
118
|
async compress(directory) {
|
|
99
119
|
if (!existsSync(directory)) {
|
|
100
|
-
return;
|
|
120
|
+
return [];
|
|
101
121
|
}
|
|
102
122
|
|
|
103
|
-
const files = list_files(directory, (file) => extensions.includes(extname(file)))
|
|
104
|
-
(file) => resolve(directory, file)
|
|
105
|
-
);
|
|
123
|
+
const files = list_files(directory, (file) => extensions.includes(extname(file)));
|
|
106
124
|
|
|
107
125
|
await Promise.all(
|
|
108
|
-
files.flatMap((file) =>
|
|
126
|
+
files.flatMap((file) => {
|
|
127
|
+
const abs = resolve(directory, file);
|
|
128
|
+
return [compress_file(abs, 'gz'), compress_file(abs, 'br')];
|
|
129
|
+
})
|
|
109
130
|
);
|
|
131
|
+
|
|
132
|
+
return files;
|
|
110
133
|
},
|
|
111
134
|
|
|
112
135
|
findServerAssets(route_data) {
|
|
@@ -118,23 +141,20 @@ export function create_builder({
|
|
|
118
141
|
},
|
|
119
142
|
|
|
120
143
|
async generateFallback(dest) {
|
|
121
|
-
const manifest_path = `${config.
|
|
122
|
-
const env = loadEnv(vite_config.mode, config.
|
|
144
|
+
const manifest_path = `${config.outDir}/output/server/manifest-full.js`;
|
|
145
|
+
const env = loadEnv(vite_config.mode, config.env.dir, '');
|
|
123
146
|
|
|
124
147
|
const fallback = await generate_fallback({
|
|
125
148
|
manifest_path,
|
|
126
149
|
env,
|
|
127
|
-
out_dir: config.
|
|
128
|
-
origin: config.
|
|
129
|
-
assets: config.
|
|
150
|
+
out_dir: config.outDir,
|
|
151
|
+
origin: config.paths.origin || 'http://sveltekit-prerender',
|
|
152
|
+
assets: config.files.assets
|
|
130
153
|
});
|
|
131
154
|
|
|
132
155
|
if (existsSync(dest)) {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
['bold', 'yellow'],
|
|
136
|
-
`Overwriting ${dest} with fallback page. Consider using a different name for the fallback.`
|
|
137
|
-
)
|
|
156
|
+
log.warn(
|
|
157
|
+
`\nOverwriting ${dest} with fallback page. Consider using a different name for the fallback.\n`
|
|
138
158
|
);
|
|
139
159
|
}
|
|
140
160
|
|
|
@@ -144,8 +164,8 @@ export function create_builder({
|
|
|
144
164
|
generateEnvModule() {
|
|
145
165
|
if (!build_data.client?.uses_env_dynamic_public) return;
|
|
146
166
|
|
|
147
|
-
const dest = `${config.
|
|
148
|
-
const env = loadEnv(vite_config.mode, config.
|
|
167
|
+
const dest = `${config.outDir}/output/prerendered/dependencies/${config.appDir}`;
|
|
168
|
+
const env = loadEnv(vite_config.mode, config.env.dir, '');
|
|
149
169
|
|
|
150
170
|
/** @type {Record<string, any>} */
|
|
151
171
|
const values = {};
|
|
@@ -161,7 +181,9 @@ export function create_builder({
|
|
|
161
181
|
|
|
162
182
|
handle_issues(issues);
|
|
163
183
|
|
|
164
|
-
|
|
184
|
+
const payload = devalue.uneval(values);
|
|
185
|
+
|
|
186
|
+
write(`${dest}/env.js`, `export const env=${payload}`);
|
|
165
187
|
},
|
|
166
188
|
|
|
167
189
|
generateManifest({ relativePath, routes: subset }) {
|
|
@@ -178,15 +200,15 @@ export function create_builder({
|
|
|
178
200
|
},
|
|
179
201
|
|
|
180
202
|
getBuildDirectory(name) {
|
|
181
|
-
return `${config.
|
|
203
|
+
return `${config.outDir}/${name}`;
|
|
182
204
|
},
|
|
183
205
|
|
|
184
206
|
getClientDirectory() {
|
|
185
|
-
return `${config.
|
|
207
|
+
return `${config.outDir}/output/client`;
|
|
186
208
|
},
|
|
187
209
|
|
|
188
210
|
getServerDirectory() {
|
|
189
|
-
return `${config.
|
|
211
|
+
return `${config.outDir}/output/server`;
|
|
190
212
|
},
|
|
191
213
|
|
|
192
214
|
getAppPath() {
|
|
@@ -194,14 +216,14 @@ export function create_builder({
|
|
|
194
216
|
},
|
|
195
217
|
|
|
196
218
|
writeClient(dest) {
|
|
197
|
-
return copy(`${config.
|
|
219
|
+
return copy(`${config.outDir}/output/client`, dest, {
|
|
198
220
|
// avoid making vite build artefacts public
|
|
199
221
|
filter: (basename) => basename !== '.vite'
|
|
200
222
|
});
|
|
201
223
|
},
|
|
202
224
|
|
|
203
225
|
writePrerendered(dest) {
|
|
204
|
-
const source = `${config.
|
|
226
|
+
const source = `${config.outDir}/output/prerendered`;
|
|
205
227
|
|
|
206
228
|
return [
|
|
207
229
|
...copy(`${source}/pages`, dest),
|
|
@@ -211,11 +233,11 @@ export function create_builder({
|
|
|
211
233
|
},
|
|
212
234
|
|
|
213
235
|
writeServer(dest) {
|
|
214
|
-
return copy(`${config.
|
|
236
|
+
return copy(`${config.outDir}/output/server`, dest);
|
|
215
237
|
},
|
|
216
238
|
|
|
217
239
|
hasServerInstrumentationFile() {
|
|
218
|
-
return existsSync(`${config.
|
|
240
|
+
return existsSync(`${config.outDir}/output/server/instrumentation.server.js`);
|
|
219
241
|
},
|
|
220
242
|
|
|
221
243
|
instrument({
|
|
@@ -257,7 +279,7 @@ export function create_builder({
|
|
|
257
279
|
exports: module.exports
|
|
258
280
|
});
|
|
259
281
|
|
|
260
|
-
|
|
282
|
+
rmSync(entrypoint, { force: true, recursive: true });
|
|
261
283
|
write(entrypoint, facade);
|
|
262
284
|
}
|
|
263
285
|
};
|
|
@@ -291,53 +313,25 @@ async function compress_file(file, format = 'gz') {
|
|
|
291
313
|
* - Imports `exports` from the entrypoint (dynamically, if `tla` is true)
|
|
292
314
|
* - Re-exports `exports` from the entrypoint
|
|
293
315
|
*
|
|
294
|
-
* `default` receives special treatment: It will be imported as `default` and exported with `export default`.
|
|
295
|
-
*
|
|
296
316
|
* @param {{ instrumentation: string; start: string; exports: string[] }} opts
|
|
297
317
|
* @returns {string}
|
|
298
318
|
*/
|
|
299
319
|
function create_instrumentation_facade({ instrumentation, start, exports }) {
|
|
300
320
|
const import_instrumentation = `import './${instrumentation}';`;
|
|
301
321
|
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
* you can do evil things like `export { c as class }`.
|
|
308
|
-
* in order to import these, you need to alias them, and then un-alias them when re-exporting
|
|
309
|
-
* this map will allow us to generate the following:
|
|
310
|
-
* import { class as _1 } from 'entrypoint';
|
|
311
|
-
* export { _1 as class };
|
|
312
|
-
*/
|
|
313
|
-
let alias = `_${alias_index++}`;
|
|
314
|
-
while (exports.includes(alias)) {
|
|
315
|
-
alias = `_${alias_index++}`;
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
aliases.set(name, alias);
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
const import_statements = [];
|
|
322
|
-
const export_statements = [];
|
|
323
|
-
|
|
324
|
-
for (const name of exports) {
|
|
325
|
-
const alias = aliases.get(name);
|
|
326
|
-
if (alias) {
|
|
327
|
-
import_statements.push(`${name}: ${alias}`);
|
|
328
|
-
export_statements.push(`${alias} as ${name}`);
|
|
329
|
-
} else {
|
|
330
|
-
import_statements.push(`${name}`);
|
|
331
|
-
export_statements.push(`${name}`);
|
|
332
|
-
}
|
|
333
|
-
}
|
|
322
|
+
const { namespace, declarations, reexports } = create_exported_declarations(
|
|
323
|
+
exports,
|
|
324
|
+
(name, ns) => `${ns}.${name}`,
|
|
325
|
+
'__mod'
|
|
326
|
+
);
|
|
334
327
|
|
|
335
|
-
const
|
|
336
|
-
`const
|
|
337
|
-
|
|
328
|
+
const parts = [
|
|
329
|
+
`const ${namespace} = await import('./${start}');`,
|
|
330
|
+
declarations.join('\n'),
|
|
331
|
+
reexports.length > 0 ? `export { ${reexports.join(', ')} };` : ''
|
|
338
332
|
]
|
|
339
333
|
.filter(Boolean)
|
|
340
334
|
.join('\n');
|
|
341
335
|
|
|
342
|
-
return `${import_instrumentation}\n${
|
|
336
|
+
return `${import_instrumentation}\n${parts}`;
|
|
343
337
|
}
|
package/src/core/adapt/index.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
/** @import { Adapter } from '@sveltejs/kit' */
|
|
2
1
|
import { styleText } from 'node:util';
|
|
3
2
|
import { create_builder } from './builder.js';
|
|
4
3
|
|
|
5
4
|
/**
|
|
6
|
-
* @param {Adapter} adapter
|
|
7
5
|
* @param {import('types').ValidatedConfig} config
|
|
8
6
|
* @param {import('types').BuildData} build_data
|
|
9
7
|
* @param {import('types').ServerMetadata} server_metadata
|
|
@@ -12,10 +10,9 @@ import { create_builder } from './builder.js';
|
|
|
12
10
|
* @param {import('types').Logger} log
|
|
13
11
|
* @param {import('types').RemoteChunk[]} remotes
|
|
14
12
|
* @param {import('vite').ResolvedConfig} vite_config
|
|
15
|
-
* @param {Record<string, import('@sveltejs/kit').EnvVarConfig<any>> | null} explicit_env_config
|
|
13
|
+
* @param {Record<string, import('@sveltejs/kit/env').EnvVarConfig<any>> | null} explicit_env_config
|
|
16
14
|
*/
|
|
17
15
|
export async function adapt(
|
|
18
|
-
adapter,
|
|
19
16
|
config,
|
|
20
17
|
build_data,
|
|
21
18
|
server_metadata,
|
|
@@ -26,12 +23,26 @@ export async function adapt(
|
|
|
26
23
|
vite_config,
|
|
27
24
|
explicit_env_config
|
|
28
25
|
) {
|
|
29
|
-
const { name, adapt } = adapter;
|
|
26
|
+
const { name, adapt } = config.adapter;
|
|
30
27
|
|
|
31
28
|
console.log(styleText(['bold', 'cyan'], `\n> Using ${name}`));
|
|
32
29
|
|
|
30
|
+
let warned = false;
|
|
31
|
+
|
|
33
32
|
const builder = create_builder({
|
|
34
|
-
config
|
|
33
|
+
config: {
|
|
34
|
+
...config,
|
|
35
|
+
get kit() {
|
|
36
|
+
if (!warned) {
|
|
37
|
+
warned = true;
|
|
38
|
+
log.warn(
|
|
39
|
+
`Reading \`config.kit\` inside adapters is deprecated — it should access configuration on the \`config\` object directly. You may need to update your adapter`
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return config;
|
|
44
|
+
}
|
|
45
|
+
},
|
|
35
46
|
build_data,
|
|
36
47
|
server_metadata,
|
|
37
48
|
route_data: build_data.manifest_data.routes.filter((route) => route.page || route.endpoint),
|