@sveltejs/kit 1.0.0-next.428 → 1.0.0-next.429
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 +1 -1
- package/src/core/env.js +7 -1
- package/src/core/sync/write_tsconfig.js +1 -1
- package/src/core/utils.js +12 -0
- package/src/vite/dev/index.js +3 -20
- package/src/vite/index.js +13 -8
- package/src/vite/utils.js +26 -15
- package/types/index.d.ts +1 -1
package/package.json
CHANGED
package/src/core/env.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { GENERATED_COMMENT } from './constants.js';
|
|
2
|
+
import { runtime_base } from './utils.js';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* @param {string} id
|
|
5
6
|
* @param {Record<string, string>} env
|
|
6
7
|
* @returns {string}
|
|
7
8
|
*/
|
|
8
|
-
export function
|
|
9
|
+
export function create_static_module(id, env) {
|
|
9
10
|
/** @type {string[]} */
|
|
10
11
|
const declarations = [];
|
|
11
12
|
|
|
@@ -23,6 +24,11 @@ export function create_module(id, env) {
|
|
|
23
24
|
return GENERATED_COMMENT + declarations.join('\n\n');
|
|
24
25
|
}
|
|
25
26
|
|
|
27
|
+
/** @param {'public' | 'private'} type */
|
|
28
|
+
export function create_dynamic_module(type) {
|
|
29
|
+
return `export { env } from '${runtime_base}/env-${type}.js';`;
|
|
30
|
+
}
|
|
31
|
+
|
|
26
32
|
/**
|
|
27
33
|
* @param {string} id
|
|
28
34
|
* @param {Record<string, string>} env
|
|
@@ -46,7 +46,7 @@ export function write_tsconfig(config, cwd = process.cwd()) {
|
|
|
46
46
|
/** @param {string} file */
|
|
47
47
|
const config_relative = (file) => posixify(path.relative(config.outDir, file));
|
|
48
48
|
|
|
49
|
-
const include = ['ambient.d.ts'];
|
|
49
|
+
const include = ['ambient.d.ts', config_relative('vite.config.ts')];
|
|
50
50
|
for (const dir of [config.files.routes, config.files.lib]) {
|
|
51
51
|
const relative = project_relative(path.dirname(dir));
|
|
52
52
|
include.push(config_relative(`${relative}/**/*.js`));
|
package/src/core/utils.js
CHANGED
|
@@ -16,6 +16,18 @@ export const runtime_directory = posixify(fileURLToPath(new URL('../runtime', im
|
|
|
16
16
|
/** Prefix for the `runtime` directory, for use with import declarations */
|
|
17
17
|
export const runtime_prefix = posixify_path(runtime_directory);
|
|
18
18
|
|
|
19
|
+
/**
|
|
20
|
+
* This allows us to import SvelteKit internals that aren't exposed via `pkg.exports` in a
|
|
21
|
+
* way that works whether `@sveltejs/kit` is installed inside the project's `node_modules`
|
|
22
|
+
* or in a workspace root
|
|
23
|
+
*/
|
|
24
|
+
export const runtime_base = runtime_directory.startsWith(process.cwd())
|
|
25
|
+
? `/${path.relative('.', runtime_directory)}`
|
|
26
|
+
: `/@fs${
|
|
27
|
+
// Windows/Linux separation - Windows starts with a drive letter, we need a / in front there
|
|
28
|
+
runtime_directory.startsWith('/') ? '' : '/'
|
|
29
|
+
}${runtime_directory}`;
|
|
30
|
+
|
|
19
31
|
/** @param {string} str */
|
|
20
32
|
function posixify_path(str) {
|
|
21
33
|
const parsed = path.parse(str);
|
package/src/vite/dev/index.js
CHANGED
|
@@ -11,7 +11,7 @@ import { parse_route_id } from '../../utils/routing.js';
|
|
|
11
11
|
import { load_template } from '../../core/config/index.js';
|
|
12
12
|
import { SVELTE_KIT_ASSETS } from '../../core/constants.js';
|
|
13
13
|
import * as sync from '../../core/sync/sync.js';
|
|
14
|
-
import { get_mime_lookup,
|
|
14
|
+
import { get_mime_lookup, runtime_base, runtime_prefix } from '../../core/utils.js';
|
|
15
15
|
import { get_env, prevent_illegal_vite_imports, resolve_entry } from '../utils.js';
|
|
16
16
|
|
|
17
17
|
// Vite doesn't expose this so we just copy the list for now
|
|
@@ -90,12 +90,7 @@ export async function dev(vite, vite_config, svelte_config, illegal_imports) {
|
|
|
90
90
|
module_nodes.push(module_node);
|
|
91
91
|
result.file = url.endsWith('.svelte') ? url : url + '?import'; // TODO what is this for?
|
|
92
92
|
|
|
93
|
-
prevent_illegal_vite_imports(
|
|
94
|
-
module_node,
|
|
95
|
-
illegal_imports,
|
|
96
|
-
extensions,
|
|
97
|
-
svelte_config.kit.outDir
|
|
98
|
-
);
|
|
93
|
+
prevent_illegal_vite_imports(module_node, illegal_imports, extensions);
|
|
99
94
|
|
|
100
95
|
return module.default;
|
|
101
96
|
};
|
|
@@ -108,12 +103,7 @@ export async function dev(vite, vite_config, svelte_config, illegal_imports) {
|
|
|
108
103
|
|
|
109
104
|
result.shared = module;
|
|
110
105
|
|
|
111
|
-
prevent_illegal_vite_imports(
|
|
112
|
-
module_node,
|
|
113
|
-
illegal_imports,
|
|
114
|
-
extensions,
|
|
115
|
-
svelte_config.kit.outDir
|
|
116
|
-
);
|
|
106
|
+
prevent_illegal_vite_imports(module_node, illegal_imports, extensions);
|
|
117
107
|
}
|
|
118
108
|
|
|
119
109
|
if (node.server) {
|
|
@@ -287,13 +277,6 @@ export async function dev(vite, vite_config, svelte_config, illegal_imports) {
|
|
|
287
277
|
}
|
|
288
278
|
});
|
|
289
279
|
|
|
290
|
-
const runtime_base = runtime_directory.startsWith(process.cwd())
|
|
291
|
-
? `/${path.relative('.', runtime_directory)}`
|
|
292
|
-
: `/@fs${
|
|
293
|
-
// Windows/Linux separation - Windows starts with a drive letter, we need a / in front there
|
|
294
|
-
runtime_directory.startsWith('/') ? '' : '/'
|
|
295
|
-
}${runtime_directory}`;
|
|
296
|
-
|
|
297
280
|
const { set_private_env } = await vite.ssrLoadModule(`${runtime_base}/env-private.js`);
|
|
298
281
|
const { set_public_env } = await vite.ssrLoadModule(`${runtime_base}/env-public.js`);
|
|
299
282
|
|
package/src/vite/index.js
CHANGED
|
@@ -16,7 +16,7 @@ import { find_deps, get_default_build_config } from './build/utils.js';
|
|
|
16
16
|
import { preview } from './preview/index.js';
|
|
17
17
|
import { get_aliases, resolve_entry, prevent_illegal_rollup_imports, get_env } from './utils.js';
|
|
18
18
|
import { fileURLToPath } from 'node:url';
|
|
19
|
-
import {
|
|
19
|
+
import { create_static_module, create_dynamic_module } from '../core/env.js';
|
|
20
20
|
|
|
21
21
|
const cwd = process.cwd();
|
|
22
22
|
|
|
@@ -211,8 +211,10 @@ function kit() {
|
|
|
211
211
|
};
|
|
212
212
|
|
|
213
213
|
illegal_imports = new Set([
|
|
214
|
-
|
|
215
|
-
|
|
214
|
+
'/@id/__x00__$env/dynamic/private', //dev
|
|
215
|
+
'\0$env/dynamic/private', // prod
|
|
216
|
+
'/@id/__x00__$env/static/private', // dev
|
|
217
|
+
'\0$env/static/private' // prod
|
|
216
218
|
]);
|
|
217
219
|
|
|
218
220
|
if (is_build) {
|
|
@@ -285,15 +287,19 @@ function kit() {
|
|
|
285
287
|
|
|
286
288
|
async resolveId(id) {
|
|
287
289
|
// treat $env/static/[public|private] as virtual
|
|
288
|
-
if (id.startsWith('$env/
|
|
290
|
+
if (id.startsWith('$env/')) return `\0${id}`;
|
|
289
291
|
},
|
|
290
292
|
|
|
291
293
|
async load(id) {
|
|
292
294
|
switch (id) {
|
|
293
295
|
case '\0$env/static/private':
|
|
294
|
-
return
|
|
296
|
+
return create_static_module('$env/static/private', env.private);
|
|
295
297
|
case '\0$env/static/public':
|
|
296
|
-
return
|
|
298
|
+
return create_static_module('$env/static/public', env.public);
|
|
299
|
+
case '\0$env/dynamic/private':
|
|
300
|
+
return create_dynamic_module('private');
|
|
301
|
+
case '\0$env/dynamic/public':
|
|
302
|
+
return create_dynamic_module('public');
|
|
297
303
|
}
|
|
298
304
|
},
|
|
299
305
|
|
|
@@ -345,8 +351,7 @@ function kit() {
|
|
|
345
351
|
prevent_illegal_rollup_imports(
|
|
346
352
|
this.getModuleInfo.bind(this),
|
|
347
353
|
module_node,
|
|
348
|
-
illegal_imports
|
|
349
|
-
svelte_config.kit.outDir
|
|
354
|
+
illegal_imports
|
|
350
355
|
);
|
|
351
356
|
}
|
|
352
357
|
});
|
package/src/vite/utils.js
CHANGED
|
@@ -106,8 +106,6 @@ export function get_aliases(config) {
|
|
|
106
106
|
const alias = [
|
|
107
107
|
{ find: '__GENERATED__', replacement: path.posix.join(config.outDir, 'generated') },
|
|
108
108
|
{ find: '$app', replacement: `${runtime_directory}/app` },
|
|
109
|
-
{ find: '$env/dynamic/public', replacement: `${runtime_directory}/env/dynamic/public.js` },
|
|
110
|
-
{ find: '$env/dynamic/private', replacement: `${runtime_directory}/env/dynamic/private.js` },
|
|
111
109
|
// For now, we handle `$lib` specially here rather than make it a default value for
|
|
112
110
|
// `config.kit.alias` since it has special meaning for packaging, etc.
|
|
113
111
|
{ find: '$lib', replacement: config.files.lib }
|
|
@@ -185,13 +183,19 @@ function repeat(str, times) {
|
|
|
185
183
|
/**
|
|
186
184
|
* Create a formatted error for an illegal import.
|
|
187
185
|
* @param {Array<{name: string, dynamic: boolean}>} stack
|
|
188
|
-
* @param {string} out_dir The directory specified by config.kit.outDir
|
|
189
186
|
*/
|
|
190
|
-
function format_illegal_import_chain(stack
|
|
191
|
-
const
|
|
187
|
+
function format_illegal_import_chain(stack) {
|
|
188
|
+
const dev_virtual_prefix = '/@id/__x00__';
|
|
189
|
+
const prod_virtual_prefix = '\0';
|
|
192
190
|
|
|
193
191
|
stack = stack.map((file) => {
|
|
194
|
-
if (file.name.startsWith(
|
|
192
|
+
if (file.name.startsWith(dev_virtual_prefix)) {
|
|
193
|
+
return { ...file, name: file.name.replace(dev_virtual_prefix, '') };
|
|
194
|
+
}
|
|
195
|
+
if (file.name.startsWith(prod_virtual_prefix)) {
|
|
196
|
+
return { ...file, name: file.name.replace(prod_virtual_prefix, '') };
|
|
197
|
+
}
|
|
198
|
+
|
|
195
199
|
return { ...file, name: path.relative(process.cwd(), file.name) };
|
|
196
200
|
});
|
|
197
201
|
|
|
@@ -225,11 +229,17 @@ export function get_env(mode, prefix) {
|
|
|
225
229
|
* @param {(id: string) => import('rollup').ModuleInfo | null} node_getter
|
|
226
230
|
* @param {import('rollup').ModuleInfo} node
|
|
227
231
|
* @param {Set<string>} illegal_imports Illegal module IDs -- be sure to call vite.normalizePath!
|
|
228
|
-
* @param {string} out_dir The directory specified by config.kit.outDir
|
|
229
232
|
*/
|
|
230
|
-
export function prevent_illegal_rollup_imports(node_getter, node, illegal_imports
|
|
233
|
+
export function prevent_illegal_rollup_imports(node_getter, node, illegal_imports) {
|
|
231
234
|
const chain = find_illegal_rollup_imports(node_getter, node, false, illegal_imports);
|
|
232
|
-
if (chain) throw new Error(format_illegal_import_chain(chain
|
|
235
|
+
if (chain) throw new Error(format_illegal_import_chain(chain));
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
const query_pattern = /\?.*$/s;
|
|
239
|
+
|
|
240
|
+
/** @param {string} path */
|
|
241
|
+
function remove_query_from_path(path) {
|
|
242
|
+
return path.replace(query_pattern, '');
|
|
233
243
|
}
|
|
234
244
|
|
|
235
245
|
/**
|
|
@@ -247,7 +257,7 @@ const find_illegal_rollup_imports = (
|
|
|
247
257
|
illegal_imports,
|
|
248
258
|
seen = new Set()
|
|
249
259
|
) => {
|
|
250
|
-
const name = normalizePath(node.id);
|
|
260
|
+
const name = remove_query_from_path(normalizePath(node.id));
|
|
251
261
|
if (seen.has(name)) return null;
|
|
252
262
|
seen.add(name);
|
|
253
263
|
|
|
@@ -300,11 +310,10 @@ const get_module_types = (config_module_types) => {
|
|
|
300
310
|
* @param {import('vite').ModuleNode} node
|
|
301
311
|
* @param {Set<string>} illegal_imports Illegal module IDs -- be sure to call vite.normalizePath!
|
|
302
312
|
* @param {Iterable<string>} module_types File extensions to analyze in addition to the defaults: `.ts`, `.js`, etc.
|
|
303
|
-
* @param {string} out_dir The directory specified by config.kit.outDir
|
|
304
313
|
*/
|
|
305
|
-
export function prevent_illegal_vite_imports(node, illegal_imports, module_types
|
|
314
|
+
export function prevent_illegal_vite_imports(node, illegal_imports, module_types) {
|
|
306
315
|
const chain = find_illegal_vite_imports(node, illegal_imports, get_module_types(module_types));
|
|
307
|
-
if (chain) throw new Error(format_illegal_import_chain(chain
|
|
316
|
+
if (chain) throw new Error(format_illegal_import_chain(chain));
|
|
308
317
|
}
|
|
309
318
|
|
|
310
319
|
/**
|
|
@@ -316,9 +325,11 @@ export function prevent_illegal_vite_imports(node, illegal_imports, module_types
|
|
|
316
325
|
*/
|
|
317
326
|
function find_illegal_vite_imports(node, illegal_imports, module_types, seen = new Set()) {
|
|
318
327
|
if (!node.id) return null; // TODO when does this happen?
|
|
319
|
-
const name = normalizePath(node.id);
|
|
328
|
+
const name = remove_query_from_path(normalizePath(node.id));
|
|
320
329
|
|
|
321
|
-
if (seen.has(name) || !module_types.has(path.extname(name)))
|
|
330
|
+
if (path.extname(name) !== '' && (seen.has(name) || !module_types.has(path.extname(name)))) {
|
|
331
|
+
return null;
|
|
332
|
+
}
|
|
322
333
|
seen.add(name);
|
|
323
334
|
|
|
324
335
|
if (name && illegal_imports.has(name)) {
|
package/types/index.d.ts
CHANGED
|
@@ -248,7 +248,7 @@ export interface RequestEvent<
|
|
|
248
248
|
}
|
|
249
249
|
|
|
250
250
|
/**
|
|
251
|
-
* A `(event: RequestEvent) => Response` function exported from a
|
|
251
|
+
* A `(event: RequestEvent) => Response` function exported from a `+server.js` file that corresponds to an HTTP verb (`GET`, `PUT`, `PATCH`, etc) and handles requests with that method.
|
|
252
252
|
*
|
|
253
253
|
* It receives `Params` as the first generic argument, which you can skip by using [generated types](/docs/types#generated-types) instead.
|
|
254
254
|
*/
|