@sveltejs/kit 1.0.0-next.358 → 1.0.0-next.359
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/dist/chunks/error.js +4 -19
- package/dist/chunks/index2.js +1 -1
- package/dist/chunks/multipart-parser.js +1 -1
- package/dist/chunks/sync.js +3 -3
- package/dist/cli.js +38 -247
- package/dist/node/polyfills.js +10332 -8967
- package/dist/node.js +4223 -4217
- package/dist/vite.js +80 -68
- package/package.json +8 -7
- package/types/ambient.d.ts +3 -3
- package/types/index.d.ts +3 -3
- package/types/internal.d.ts +2 -2
package/dist/chunks/error.js
CHANGED
|
@@ -4,7 +4,7 @@ import * as url from 'url';
|
|
|
4
4
|
|
|
5
5
|
let FORCE_COLOR, NODE_DISABLE_COLORS, NO_COLOR, TERM, isTTY=true;
|
|
6
6
|
if (typeof process !== 'undefined') {
|
|
7
|
-
({ FORCE_COLOR, NODE_DISABLE_COLORS, NO_COLOR, TERM } = process.env);
|
|
7
|
+
({ FORCE_COLOR, NODE_DISABLE_COLORS, NO_COLOR, TERM } = process.env || {});
|
|
8
8
|
isTTY = process.stdout && process.stdout.isTTY;
|
|
9
9
|
}
|
|
10
10
|
|
|
@@ -387,7 +387,7 @@ const options = object(
|
|
|
387
387
|
// TODO remove this for 1.0
|
|
388
388
|
ssr: error(
|
|
389
389
|
(keypath) =>
|
|
390
|
-
`${keypath} has been removed — use the handle hook instead: https://kit.svelte.dev/docs/hooks#handle
|
|
390
|
+
`${keypath} has been removed — use the handle hook instead: https://kit.svelte.dev/docs/hooks#handle`
|
|
391
391
|
),
|
|
392
392
|
|
|
393
393
|
// TODO remove this for 1.0
|
|
@@ -400,23 +400,8 @@ const options = object(
|
|
|
400
400
|
pollInterval: number(0)
|
|
401
401
|
}),
|
|
402
402
|
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
(input, keypath) => {
|
|
406
|
-
if (typeof input === 'object') {
|
|
407
|
-
const config = input;
|
|
408
|
-
input = () => config;
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
if (typeof input !== 'function') {
|
|
412
|
-
throw new Error(
|
|
413
|
-
`${keypath} must be a Vite config object (https://vitejs.dev/config) or a function that returns one`
|
|
414
|
-
);
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
return input;
|
|
418
|
-
}
|
|
419
|
-
)
|
|
403
|
+
// TODO remove this for 1.0
|
|
404
|
+
vite: error((keypath) => `${keypath} has been removed — use vite.config.js instead`)
|
|
420
405
|
})
|
|
421
406
|
},
|
|
422
407
|
true
|
package/dist/chunks/index2.js
CHANGED
package/dist/chunks/sync.js
CHANGED
|
@@ -681,8 +681,8 @@ function list_files(dir, path = '', files = []) {
|
|
|
681
681
|
return files;
|
|
682
682
|
}
|
|
683
683
|
|
|
684
|
-
const
|
|
685
|
-
const
|
|
684
|
+
const filename = fileURLToPath(import.meta.url);
|
|
685
|
+
const dirname = path__default.dirname(filename);
|
|
686
686
|
|
|
687
687
|
/** @param {string} dest */
|
|
688
688
|
function copy_assets(dest) {
|
|
@@ -690,7 +690,7 @@ function copy_assets(dest) {
|
|
|
690
690
|
do {
|
|
691
691
|
// we jump through these hoops so that this function
|
|
692
692
|
// works whether or not it's been bundled
|
|
693
|
-
const resolved = path__default.resolve(
|
|
693
|
+
const resolved = path__default.resolve(dirname, `${prefix}/assets`);
|
|
694
694
|
|
|
695
695
|
if (fs__default.existsSync(resolved)) {
|
|
696
696
|
copy(resolved, dest);
|
package/dist/cli.js
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
import chokidar from 'chokidar';
|
|
2
1
|
import fs__default from 'fs';
|
|
3
|
-
import path__default from 'path';
|
|
4
2
|
import { l as load_config, $, c as coalesce_to_error } from './chunks/error.js';
|
|
5
3
|
import sade from 'sade';
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import { pathToFileURL } from 'url';
|
|
4
|
+
import 'path';
|
|
5
|
+
import 'url';
|
|
9
6
|
|
|
10
7
|
/** @param {unknown} e */
|
|
11
8
|
function handle_error(e) {
|
|
@@ -21,176 +18,7 @@ function handle_error(e) {
|
|
|
21
18
|
process.exit(1);
|
|
22
19
|
}
|
|
23
20
|
|
|
24
|
-
|
|
25
|
-
* @param {number} port
|
|
26
|
-
* @param {boolean} https
|
|
27
|
-
* @param {string} base
|
|
28
|
-
*/
|
|
29
|
-
async function launch(port, https, base) {
|
|
30
|
-
const { exec } = await import('child_process');
|
|
31
|
-
let cmd = 'open';
|
|
32
|
-
if (process.platform == 'win32') {
|
|
33
|
-
cmd = 'start';
|
|
34
|
-
} else if (process.platform == 'linux') {
|
|
35
|
-
if (/microsoft/i.test(release())) {
|
|
36
|
-
cmd = 'cmd.exe /c start';
|
|
37
|
-
} else {
|
|
38
|
-
cmd = 'xdg-open';
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
exec(`${cmd} ${https ? 'https' : 'http'}://localhost:${port}${base}`);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const prog = sade('svelte-kit').version('1.0.0-next.358');
|
|
45
|
-
|
|
46
|
-
prog
|
|
47
|
-
.command('dev')
|
|
48
|
-
.describe('Start a development server')
|
|
49
|
-
.option('-p, --port', 'Port')
|
|
50
|
-
.option('-o, --open', 'Open a browser tab')
|
|
51
|
-
.option('--host', 'Host (only use this on trusted networks)')
|
|
52
|
-
.option('--https', 'Use self-signed HTTPS certificate')
|
|
53
|
-
.option('-H', 'no longer supported, use --https instead') // TODO remove for 1.0
|
|
54
|
-
.action(async ({ port, host, https, open, H }) => {
|
|
55
|
-
let first = true;
|
|
56
|
-
let relaunching = false;
|
|
57
|
-
let uid = 1;
|
|
58
|
-
|
|
59
|
-
/** @type {() => Promise<void>} */
|
|
60
|
-
let close;
|
|
61
|
-
|
|
62
|
-
async function start() {
|
|
63
|
-
const svelte_config = await load_config();
|
|
64
|
-
const config = await get_vite_config(svelte_config);
|
|
65
|
-
config.server = config.server || {};
|
|
66
|
-
|
|
67
|
-
// optional config from command-line flags
|
|
68
|
-
// these should take precedence, but not print conflict warnings
|
|
69
|
-
if (host) {
|
|
70
|
-
config.server.host = host;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// if https is already enabled then do nothing. it could be an object and we
|
|
74
|
-
// don't want to overwrite with a boolean
|
|
75
|
-
if (https && !config?.server?.https) {
|
|
76
|
-
config.server.https = https;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
if (port) {
|
|
80
|
-
config.server.port = port;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
const server = await vite.createServer(config);
|
|
84
|
-
await server.listen(port);
|
|
85
|
-
|
|
86
|
-
const address_info = /** @type {import('net').AddressInfo} */ (
|
|
87
|
-
/** @type {import('http').Server} */ (server.httpServer).address()
|
|
88
|
-
);
|
|
89
|
-
|
|
90
|
-
const resolved_config = server.config;
|
|
91
|
-
|
|
92
|
-
welcome({
|
|
93
|
-
port: address_info.port,
|
|
94
|
-
host: address_info.address,
|
|
95
|
-
https: !!(https || resolved_config.server.https),
|
|
96
|
-
open: first && (open || !!resolved_config.server.open),
|
|
97
|
-
base: svelte_config.kit.paths.base,
|
|
98
|
-
loose: resolved_config.server.fs.strict === false,
|
|
99
|
-
allow: resolved_config.server.fs.allow
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
first = false;
|
|
103
|
-
|
|
104
|
-
return server.close;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
// TODO: we should probably replace this with something like vite-plugin-restart
|
|
108
|
-
async function relaunch() {
|
|
109
|
-
const id = uid;
|
|
110
|
-
relaunching = true;
|
|
111
|
-
|
|
112
|
-
try {
|
|
113
|
-
await close();
|
|
114
|
-
close = await start();
|
|
115
|
-
|
|
116
|
-
if (id !== uid) relaunch();
|
|
117
|
-
} catch (e) {
|
|
118
|
-
const error = /** @type {Error} */ (e);
|
|
119
|
-
|
|
120
|
-
console.error($.bold().red(`> ${error.message}`));
|
|
121
|
-
if (error.stack) {
|
|
122
|
-
console.error($.gray(error.stack.split('\n').slice(1).join('\n')));
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
relaunching = false;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
try {
|
|
130
|
-
if (H) throw new Error('-H is no longer supported — use --https instead');
|
|
131
|
-
|
|
132
|
-
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
|
|
133
|
-
|
|
134
|
-
close = await start();
|
|
135
|
-
|
|
136
|
-
chokidar.watch('svelte.config.js', { ignoreInitial: true }).on('change', () => {
|
|
137
|
-
if (relaunching) uid += 1;
|
|
138
|
-
else relaunch();
|
|
139
|
-
});
|
|
140
|
-
} catch (error) {
|
|
141
|
-
handle_error(error);
|
|
142
|
-
}
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
prog
|
|
146
|
-
.command('build')
|
|
147
|
-
.describe('Create a production build of your app')
|
|
148
|
-
.option('--verbose', 'Log more stuff', false)
|
|
149
|
-
.action(async ({ verbose }) => {
|
|
150
|
-
try {
|
|
151
|
-
process.env.NODE_ENV = process.env.NODE_ENV || 'production';
|
|
152
|
-
process.env.VERBOSE = verbose;
|
|
153
|
-
|
|
154
|
-
const svelte_config = await load_config();
|
|
155
|
-
const vite_config = await get_vite_config(svelte_config);
|
|
156
|
-
await vite.build(vite_config); // TODO when we get rid of config.kit.vite, this can just be vite.build()
|
|
157
|
-
} catch (error) {
|
|
158
|
-
handle_error(error);
|
|
159
|
-
}
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
prog
|
|
163
|
-
.command('preview')
|
|
164
|
-
.describe('Serve an already-built app')
|
|
165
|
-
.option('-p, --port', 'Port', 3000)
|
|
166
|
-
.option('-o, --open', 'Open a browser tab', false)
|
|
167
|
-
.option('--host', 'Host (only use this on trusted networks)', 'localhost')
|
|
168
|
-
.option('--https', 'Use self-signed HTTPS certificate', false)
|
|
169
|
-
.option('-H', 'no longer supported, use --https instead') // TODO remove for 1.0
|
|
170
|
-
.action(async ({ port, host, https, open, H }) => {
|
|
171
|
-
try {
|
|
172
|
-
if (H) throw new Error('-H is no longer supported — use --https instead');
|
|
173
|
-
|
|
174
|
-
process.env.NODE_ENV = process.env.NODE_ENV || 'production';
|
|
175
|
-
|
|
176
|
-
const svelte_config = await load_config();
|
|
177
|
-
const vite_config = await get_vite_config(svelte_config);
|
|
178
|
-
|
|
179
|
-
vite_config.preview = vite_config.preview || {};
|
|
180
|
-
|
|
181
|
-
// optional config from command-line flags
|
|
182
|
-
// these should take precedence, but not print conflict warnings
|
|
183
|
-
if (host) vite_config.preview.host = host;
|
|
184
|
-
if (https) vite_config.preview.https = https;
|
|
185
|
-
if (port) vite_config.preview.port = port;
|
|
186
|
-
|
|
187
|
-
const preview_server = await vite.preview(vite_config);
|
|
188
|
-
|
|
189
|
-
welcome({ port, host, https, open, base: preview_server.config.base });
|
|
190
|
-
} catch (error) {
|
|
191
|
-
handle_error(error);
|
|
192
|
-
}
|
|
193
|
-
});
|
|
21
|
+
const prog = sade('svelte-kit').version('1.0.0-next.359');
|
|
194
22
|
|
|
195
23
|
prog
|
|
196
24
|
.command('package')
|
|
@@ -225,83 +53,46 @@ prog
|
|
|
225
53
|
}
|
|
226
54
|
});
|
|
227
55
|
|
|
228
|
-
|
|
56
|
+
// TODO remove for 1.0
|
|
57
|
+
replace('dev');
|
|
58
|
+
replace('build');
|
|
59
|
+
replace('preview');
|
|
229
60
|
|
|
230
|
-
|
|
231
|
-
* @param {{
|
|
232
|
-
* open: boolean;
|
|
233
|
-
* host: string;
|
|
234
|
-
* https: boolean;
|
|
235
|
-
* port: number;
|
|
236
|
-
* base: string;
|
|
237
|
-
* loose?: boolean;
|
|
238
|
-
* allow?: string[];
|
|
239
|
-
* cwd?: string;
|
|
240
|
-
* }} param0
|
|
241
|
-
*/
|
|
242
|
-
function welcome({ port, host, https, open, base, loose, allow, cwd }) {
|
|
243
|
-
if (open) launch(port, https, base);
|
|
61
|
+
prog.parse(process.argv, { unknown: (arg) => `Unknown option: ${arg}` });
|
|
244
62
|
|
|
245
|
-
|
|
63
|
+
/** @param {string} command */
|
|
64
|
+
function replace(command) {
|
|
65
|
+
prog
|
|
66
|
+
.command(command)
|
|
67
|
+
.describe(`No longer available — use vite ${command} instead`)
|
|
68
|
+
.action(async () => {
|
|
69
|
+
const message = `\n> svelte-kit ${command} is no longer available — use vite ${command} instead`;
|
|
70
|
+
console.error($.bold().red(message));
|
|
71
|
+
|
|
72
|
+
const steps = [
|
|
73
|
+
'Install vite as a devDependency with npm/pnpm/etc',
|
|
74
|
+
'Create a vite.config.js with the @sveltejs/kit/vite plugin (see below)',
|
|
75
|
+
`Update your package.json scripts to reference \`vite ${command}\` instead of \`svelte-kit ${command}\``
|
|
76
|
+
];
|
|
77
|
+
|
|
78
|
+
steps.forEach((step, i) => {
|
|
79
|
+
console.error(` ${i + 1}. ${$.cyan(step)}`);
|
|
80
|
+
});
|
|
246
81
|
|
|
247
|
-
|
|
248
|
-
|
|
82
|
+
console.error(
|
|
83
|
+
`
|
|
84
|
+
${$.grey('// vite.config.js')}
|
|
85
|
+
import { sveltekit } from '@sveltejs/kit/vite';
|
|
249
86
|
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
if (details.family !== 'IPv4' && details.family !== 4) return;
|
|
87
|
+
/** @type {import('vite').UserConfig} */
|
|
88
|
+
const config = {
|
|
89
|
+
plugins: [sveltekit()]
|
|
90
|
+
};
|
|
255
91
|
|
|
256
|
-
|
|
257
|
-
if (details.internal) {
|
|
258
|
-
console.log(` ${$.gray('local: ')} ${protocol}//${$.bold(`localhost:${port}`)}`);
|
|
259
|
-
} else {
|
|
260
|
-
if (details.mac === '00:00:00:00:00:00') return;
|
|
92
|
+
export default config;
|
|
261
93
|
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
console.log(`\n ${$.yellow('Serving with vite.server.fs.strict: false. Note that all files on your machine will be accessible to anyone on your network.')}`);
|
|
266
|
-
} else if (allow?.length && cwd) {
|
|
267
|
-
console.log(`\n ${$.yellow('Note that all files in the following directories will be accessible to anyone on your network: ' + allow.map(a => path__default.relative(cwd, a)).join(', '))}`);
|
|
268
|
-
}
|
|
269
|
-
} else {
|
|
270
|
-
console.log(` ${$.gray('network: not exposed')}`);
|
|
271
|
-
}
|
|
272
|
-
}
|
|
94
|
+
`.replace(/^\t{4}/gm, '')
|
|
95
|
+
);
|
|
96
|
+
process.exit(1);
|
|
273
97
|
});
|
|
274
|
-
});
|
|
275
|
-
|
|
276
|
-
if (!exposed) {
|
|
277
|
-
console.log('\n Use --host to expose server to other devices on this network');
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
console.log('\n');
|
|
281
98
|
}
|
|
282
|
-
|
|
283
|
-
/**
|
|
284
|
-
* @param {import('types').ValidatedConfig} svelte_config
|
|
285
|
-
* @return {Promise<import('vite').UserConfig>}
|
|
286
|
-
*/
|
|
287
|
-
async function get_vite_config(svelte_config) {
|
|
288
|
-
for (const file of ['vite.config.js', 'vite.config.mjs', 'vite.config.cjs']) {
|
|
289
|
-
if (fs__default.existsSync(file)) {
|
|
290
|
-
// TODO warn here if config.kit.vite was specified
|
|
291
|
-
const module = await import(pathToFileURL(file).toString());
|
|
292
|
-
return {
|
|
293
|
-
...module.default,
|
|
294
|
-
configFile: false
|
|
295
|
-
};
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
const { sveltekit } = await import('./vite.js').then(function (n) { return n.i; });
|
|
300
|
-
|
|
301
|
-
// TODO: stop reading Vite config from SvelteKit config or move to CLI
|
|
302
|
-
const vite_config = await svelte_config.kit.vite();
|
|
303
|
-
vite_config.plugins = [...(vite_config.plugins || []), ...sveltekit()];
|
|
304
|
-
return vite_config;
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
export { get_vite_config };
|