@sveltejs/kit 1.0.0-next.21 → 1.0.0-next.210
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/README.md +12 -9
- package/assets/components/error.svelte +19 -3
- package/assets/kit.js +1912 -0
- package/assets/runtime/app/env.js +20 -0
- package/assets/runtime/app/navigation.js +45 -13
- package/assets/runtime/app/paths.js +1 -2
- package/assets/runtime/app/stores.js +15 -9
- package/assets/runtime/chunks/utils.js +13 -0
- package/assets/runtime/env.js +8 -0
- package/assets/runtime/internal/singletons.js +5 -11
- package/assets/runtime/internal/start.js +979 -355
- package/assets/runtime/paths.js +13 -0
- package/dist/chunks/cert.js +29255 -0
- package/dist/chunks/constants.js +8 -0
- package/dist/chunks/error.js +21 -0
- package/dist/chunks/index.js +4732 -0
- package/dist/chunks/index2.js +812 -0
- package/dist/chunks/index3.js +624 -0
- package/dist/chunks/index4.js +109 -0
- package/dist/chunks/index5.js +628 -0
- package/dist/chunks/index6.js +827 -0
- package/dist/chunks/index7.js +15575 -0
- package/dist/chunks/misc.js +3 -0
- package/dist/chunks/multipart-parser.js +449 -0
- package/dist/chunks/url.js +62 -0
- package/dist/cli.js +1012 -67
- package/dist/hooks.js +28 -0
- package/dist/install-fetch.js +6514 -0
- package/dist/node.js +51 -0
- package/dist/ssr.js +1842 -0
- package/package.json +90 -54
- package/svelte-kit.js +2 -0
- package/types/ambient-modules.d.ts +181 -0
- package/types/app.d.ts +45 -0
- package/types/config.d.ts +163 -0
- package/types/endpoint.d.ts +18 -0
- package/types/helper.d.ts +41 -0
- package/types/hooks.d.ts +48 -0
- package/types/index.d.ts +17 -0
- package/types/internal.d.ts +231 -0
- package/types/page.d.ts +71 -0
- package/CHANGELOG.md +0 -282
- package/assets/runtime/app/navigation.js.map +0 -1
- package/assets/runtime/app/paths.js.map +0 -1
- package/assets/runtime/app/stores.js.map +0 -1
- package/assets/runtime/internal/singletons.js.map +0 -1
- package/assets/runtime/internal/start.js.map +0 -1
- package/assets/runtime/utils-85ebcc60.js +0 -18
- package/assets/runtime/utils-85ebcc60.js.map +0 -1
- package/dist/api.js +0 -44
- package/dist/api.js.map +0 -1
- package/dist/build.js +0 -246
- package/dist/build.js.map +0 -1
- package/dist/cli.js.map +0 -1
- package/dist/colors.js +0 -37
- package/dist/colors.js.map +0 -1
- package/dist/create_app.js +0 -578
- package/dist/create_app.js.map +0 -1
- package/dist/index.js +0 -12042
- package/dist/index.js.map +0 -1
- package/dist/index2.js +0 -544
- package/dist/index2.js.map +0 -1
- package/dist/index3.js +0 -71
- package/dist/index3.js.map +0 -1
- package/dist/index4.js +0 -466
- package/dist/index4.js.map +0 -1
- package/dist/index5.js +0 -729
- package/dist/index5.js.map +0 -1
- package/dist/index6.js +0 -713
- package/dist/index6.js.map +0 -1
- package/dist/logging.js +0 -43
- package/dist/logging.js.map +0 -1
- package/dist/package.js +0 -432
- package/dist/package.js.map +0 -1
- package/dist/renderer.js +0 -2391
- package/dist/renderer.js.map +0 -1
- package/dist/standard.js +0 -101
- package/dist/standard.js.map +0 -1
- package/dist/utils.js +0 -54
- package/dist/utils.js.map +0 -1
- package/svelte-kit +0 -3
package/dist/cli.js
CHANGED
|
@@ -1,79 +1,909 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
1
|
+
import fs__default, { existsSync } from 'fs';
|
|
2
|
+
import sade from 'sade';
|
|
3
|
+
import path__default, { relative } from 'path';
|
|
4
|
+
import { exec as exec$1 } from 'child_process';
|
|
5
|
+
import { createConnection, createServer } from 'net';
|
|
6
|
+
import * as url from 'url';
|
|
7
|
+
import { fileURLToPath } from 'url';
|
|
8
|
+
import { networkInterfaces, release } from 'os';
|
|
9
|
+
import { c as coalesce_to_error, h as has_error_code } from './chunks/error.js';
|
|
10
|
+
|
|
11
|
+
let FORCE_COLOR, NODE_DISABLE_COLORS, NO_COLOR, TERM, isTTY=true;
|
|
12
|
+
if (typeof process !== 'undefined') {
|
|
13
|
+
({ FORCE_COLOR, NODE_DISABLE_COLORS, NO_COLOR, TERM } = process.env);
|
|
14
|
+
isTTY = process.stdout && process.stdout.isTTY;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const $ = {
|
|
18
|
+
enabled: !NODE_DISABLE_COLORS && NO_COLOR == null && TERM !== 'dumb' && (
|
|
19
|
+
FORCE_COLOR != null && FORCE_COLOR !== '0' || isTTY
|
|
20
|
+
),
|
|
21
|
+
|
|
22
|
+
// modifiers
|
|
23
|
+
reset: init(0, 0),
|
|
24
|
+
bold: init(1, 22),
|
|
25
|
+
dim: init(2, 22),
|
|
26
|
+
italic: init(3, 23),
|
|
27
|
+
underline: init(4, 24),
|
|
28
|
+
inverse: init(7, 27),
|
|
29
|
+
hidden: init(8, 28),
|
|
30
|
+
strikethrough: init(9, 29),
|
|
31
|
+
|
|
32
|
+
// colors
|
|
33
|
+
black: init(30, 39),
|
|
34
|
+
red: init(31, 39),
|
|
35
|
+
green: init(32, 39),
|
|
36
|
+
yellow: init(33, 39),
|
|
37
|
+
blue: init(34, 39),
|
|
38
|
+
magenta: init(35, 39),
|
|
39
|
+
cyan: init(36, 39),
|
|
40
|
+
white: init(37, 39),
|
|
41
|
+
gray: init(90, 39),
|
|
42
|
+
grey: init(90, 39),
|
|
43
|
+
|
|
44
|
+
// background colors
|
|
45
|
+
bgBlack: init(40, 49),
|
|
46
|
+
bgRed: init(41, 49),
|
|
47
|
+
bgGreen: init(42, 49),
|
|
48
|
+
bgYellow: init(43, 49),
|
|
49
|
+
bgBlue: init(44, 49),
|
|
50
|
+
bgMagenta: init(45, 49),
|
|
51
|
+
bgCyan: init(46, 49),
|
|
52
|
+
bgWhite: init(47, 49)
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
function run(arr, str) {
|
|
56
|
+
let i=0, tmp, beg='', end='';
|
|
57
|
+
for (; i < arr.length; i++) {
|
|
58
|
+
tmp = arr[i];
|
|
59
|
+
beg += tmp.open;
|
|
60
|
+
end += tmp.close;
|
|
61
|
+
if (!!~str.indexOf(tmp.close)) {
|
|
62
|
+
str = str.replace(tmp.rgx, tmp.close + tmp.open);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return beg + str + end;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function chain(has, keys) {
|
|
69
|
+
let ctx = { has, keys };
|
|
70
|
+
|
|
71
|
+
ctx.reset = $.reset.bind(ctx);
|
|
72
|
+
ctx.bold = $.bold.bind(ctx);
|
|
73
|
+
ctx.dim = $.dim.bind(ctx);
|
|
74
|
+
ctx.italic = $.italic.bind(ctx);
|
|
75
|
+
ctx.underline = $.underline.bind(ctx);
|
|
76
|
+
ctx.inverse = $.inverse.bind(ctx);
|
|
77
|
+
ctx.hidden = $.hidden.bind(ctx);
|
|
78
|
+
ctx.strikethrough = $.strikethrough.bind(ctx);
|
|
79
|
+
|
|
80
|
+
ctx.black = $.black.bind(ctx);
|
|
81
|
+
ctx.red = $.red.bind(ctx);
|
|
82
|
+
ctx.green = $.green.bind(ctx);
|
|
83
|
+
ctx.yellow = $.yellow.bind(ctx);
|
|
84
|
+
ctx.blue = $.blue.bind(ctx);
|
|
85
|
+
ctx.magenta = $.magenta.bind(ctx);
|
|
86
|
+
ctx.cyan = $.cyan.bind(ctx);
|
|
87
|
+
ctx.white = $.white.bind(ctx);
|
|
88
|
+
ctx.gray = $.gray.bind(ctx);
|
|
89
|
+
ctx.grey = $.grey.bind(ctx);
|
|
90
|
+
|
|
91
|
+
ctx.bgBlack = $.bgBlack.bind(ctx);
|
|
92
|
+
ctx.bgRed = $.bgRed.bind(ctx);
|
|
93
|
+
ctx.bgGreen = $.bgGreen.bind(ctx);
|
|
94
|
+
ctx.bgYellow = $.bgYellow.bind(ctx);
|
|
95
|
+
ctx.bgBlue = $.bgBlue.bind(ctx);
|
|
96
|
+
ctx.bgMagenta = $.bgMagenta.bind(ctx);
|
|
97
|
+
ctx.bgCyan = $.bgCyan.bind(ctx);
|
|
98
|
+
ctx.bgWhite = $.bgWhite.bind(ctx);
|
|
99
|
+
|
|
100
|
+
return ctx;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function init(open, close) {
|
|
104
|
+
let blk = {
|
|
105
|
+
open: `\x1b[${open}m`,
|
|
106
|
+
close: `\x1b[${close}m`,
|
|
107
|
+
rgx: new RegExp(`\\x1b\\[${close}m`, 'g')
|
|
108
|
+
};
|
|
109
|
+
return function (txt) {
|
|
110
|
+
if (this !== void 0 && this.has !== void 0) {
|
|
111
|
+
!!~this.has.indexOf(open) || (this.has.push(open),this.keys.push(blk));
|
|
112
|
+
return txt === void 0 ? this : $.enabled ? run(this.keys, txt+'') : txt+'';
|
|
113
|
+
}
|
|
114
|
+
return txt === void 0 ? chain([open], [blk]) : $.enabled ? run([blk], txt+'') : txt+'';
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function exec(cmd) {
|
|
119
|
+
return new Promise((fulfil, reject) => {
|
|
120
|
+
exec$1(cmd, (error, stdout, stderr) => {
|
|
121
|
+
if (error) return reject(error);
|
|
122
|
+
fulfil({ stdout, stderr });
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
async function blame(port) {
|
|
128
|
+
try {
|
|
129
|
+
const { stdout } = await exec(`lsof -i :${port} -sTCP:LISTEN -Fp`);
|
|
130
|
+
|
|
131
|
+
if (!stdout) return null;
|
|
132
|
+
const pid = parseInt(stdout.slice(1), 10);
|
|
133
|
+
if (isNaN(pid)) throw new Error(`Invalid stdout ${stdout}`);
|
|
134
|
+
|
|
135
|
+
return pid;
|
|
136
|
+
} catch (error) {
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
let promise;
|
|
142
|
+
|
|
143
|
+
function weird() {
|
|
144
|
+
if (!promise) {
|
|
145
|
+
promise = get_weird(9000);
|
|
146
|
+
}
|
|
147
|
+
return promise;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function get_weird(port) {
|
|
151
|
+
return new Promise(fulfil => {
|
|
152
|
+
const server = createServer();
|
|
153
|
+
|
|
154
|
+
server.unref();
|
|
155
|
+
|
|
156
|
+
server.on('error', () => {
|
|
157
|
+
fulfil(get_weird(port + 1));
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
server.listen({ port }, () => {
|
|
161
|
+
const server2 = createServer();
|
|
162
|
+
|
|
163
|
+
server2.unref();
|
|
164
|
+
|
|
165
|
+
server2.on('error', () => {
|
|
166
|
+
server.close(() => {
|
|
167
|
+
fulfil(false);
|
|
168
|
+
});
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
server2.listen({ port }, () => {
|
|
172
|
+
server2.close(() => {
|
|
173
|
+
server.close(() => {
|
|
174
|
+
fulfil(true);
|
|
175
|
+
});
|
|
23
176
|
});
|
|
177
|
+
});
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function check(port) {
|
|
183
|
+
return weird().then(weird => {
|
|
184
|
+
if (weird) {
|
|
185
|
+
return check_weird(port);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
return new Promise(fulfil => {
|
|
189
|
+
const server = createServer();
|
|
190
|
+
|
|
191
|
+
server.unref();
|
|
192
|
+
|
|
193
|
+
server.on('error', () => {
|
|
194
|
+
fulfil(false);
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
server.listen({ port }, () => {
|
|
198
|
+
server.close(() => {
|
|
199
|
+
fulfil(true);
|
|
200
|
+
});
|
|
201
|
+
});
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function check_weird(port) {
|
|
207
|
+
return new Promise(fulfil => {
|
|
208
|
+
const client = createConnection({ port }, () => {
|
|
209
|
+
client.end();
|
|
210
|
+
fulfil(false);
|
|
211
|
+
})
|
|
212
|
+
.on('error', () => {
|
|
213
|
+
fulfil(true);
|
|
214
|
+
});
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/** @param {string} dir */
|
|
219
|
+
function mkdirp(dir) {
|
|
220
|
+
try {
|
|
221
|
+
fs__default.mkdirSync(dir, { recursive: true });
|
|
222
|
+
} catch (/** @type {any} */ e) {
|
|
223
|
+
if (e.code === 'EEXIST') return;
|
|
224
|
+
throw e;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/** @param {string} path */
|
|
229
|
+
function rimraf(path) {
|
|
230
|
+
(fs__default.rmSync || fs__default.rmdirSync)(path, { recursive: true, force: true });
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* @param {string} source
|
|
235
|
+
* @param {string} target
|
|
236
|
+
* @param {{
|
|
237
|
+
* filter?: (basename: string) => boolean;
|
|
238
|
+
* replace?: Record<string, string>;
|
|
239
|
+
* }} opts
|
|
240
|
+
*/
|
|
241
|
+
function copy(source, target, opts = {}) {
|
|
242
|
+
if (!fs__default.existsSync(source)) return [];
|
|
243
|
+
|
|
244
|
+
/** @type {string[]} */
|
|
245
|
+
const files = [];
|
|
246
|
+
|
|
247
|
+
const prefix = posixify(target) + '/';
|
|
248
|
+
|
|
249
|
+
const regex = opts.replace
|
|
250
|
+
? new RegExp(`\\b(${Object.keys(opts.replace).join('|')})\\b`, 'g')
|
|
251
|
+
: null;
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* @param {string} from
|
|
255
|
+
* @param {string} to
|
|
256
|
+
*/
|
|
257
|
+
function go(from, to) {
|
|
258
|
+
if (opts.filter && !opts.filter(path__default.basename(from))) return;
|
|
259
|
+
|
|
260
|
+
const stats = fs__default.statSync(from);
|
|
261
|
+
|
|
262
|
+
if (stats.isDirectory()) {
|
|
263
|
+
fs__default.readdirSync(from).forEach((file) => {
|
|
264
|
+
go(path__default.join(from, file), path__default.join(to, file));
|
|
265
|
+
});
|
|
266
|
+
} else {
|
|
267
|
+
mkdirp(path__default.dirname(to));
|
|
268
|
+
|
|
269
|
+
if (opts.replace) {
|
|
270
|
+
const data = fs__default.readFileSync(from, 'utf-8');
|
|
271
|
+
fs__default.writeFileSync(
|
|
272
|
+
to,
|
|
273
|
+
data.replace(
|
|
274
|
+
/** @type {RegExp} */ (regex),
|
|
275
|
+
(match, key) => /** @type {Record<string, string>} */ (opts.replace)[key]
|
|
276
|
+
)
|
|
277
|
+
);
|
|
278
|
+
} else {
|
|
279
|
+
fs__default.copyFileSync(from, to);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
files.push(to === target ? posixify(path__default.basename(to)) : posixify(to).replace(prefix, ''));
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
go(source, target);
|
|
287
|
+
|
|
288
|
+
return files;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* Get a list of all files in a directory
|
|
293
|
+
* @param {string} cwd - the directory to walk
|
|
294
|
+
* @param {boolean} [dirs] - whether to include directories in the result
|
|
295
|
+
*/
|
|
296
|
+
function walk(cwd, dirs = false) {
|
|
297
|
+
/** @type {string[]} */
|
|
298
|
+
const all_files = [];
|
|
299
|
+
|
|
300
|
+
/** @param {string} dir */
|
|
301
|
+
function walk_dir(dir) {
|
|
302
|
+
const files = fs__default.readdirSync(path__default.join(cwd, dir));
|
|
303
|
+
|
|
304
|
+
for (const file of files) {
|
|
305
|
+
const joined = path__default.join(dir, file);
|
|
306
|
+
const stats = fs__default.statSync(path__default.join(cwd, joined));
|
|
307
|
+
if (stats.isDirectory()) {
|
|
308
|
+
if (dirs) all_files.push(joined);
|
|
309
|
+
walk_dir(joined);
|
|
310
|
+
} else {
|
|
311
|
+
all_files.push(joined);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
return walk_dir(''), all_files;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
320
|
+
const __dirname = path__default.dirname(__filename);
|
|
321
|
+
|
|
322
|
+
/** @param {string} dest */
|
|
323
|
+
function copy_assets(dest) {
|
|
324
|
+
let prefix = '..';
|
|
325
|
+
do {
|
|
326
|
+
// we jump through these hoops so that this function
|
|
327
|
+
// works whether or not it's been bundled
|
|
328
|
+
const resolved = path__default.resolve(__dirname, `${prefix}/assets`);
|
|
329
|
+
|
|
330
|
+
if (fs__default.existsSync(resolved)) {
|
|
331
|
+
copy(resolved, dest);
|
|
332
|
+
return;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
prefix = `../${prefix}`;
|
|
336
|
+
} while (true); // eslint-disable-line
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
function noop() {}
|
|
340
|
+
|
|
341
|
+
/** @param {{ verbose: boolean }} opts */
|
|
342
|
+
function logger({ verbose }) {
|
|
343
|
+
/** @type {import('types/internal').Logger} */
|
|
344
|
+
const log = (msg) => console.log(msg.replace(/^/gm, ' '));
|
|
345
|
+
|
|
346
|
+
log.success = (msg) => log($.green(`✔ ${msg}`));
|
|
347
|
+
log.error = (msg) => log($.bold().red(msg));
|
|
348
|
+
log.warn = (msg) => log($.bold().yellow(msg));
|
|
349
|
+
|
|
350
|
+
log.minor = verbose ? (msg) => log($.grey(msg)) : noop;
|
|
351
|
+
log.info = verbose ? log : noop;
|
|
352
|
+
|
|
353
|
+
return log;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
/**
|
|
357
|
+
* Given an entry point like [cwd]/src/hooks, returns a filename like [cwd]/src/hooks.js or [cwd]/src/hooks/index.js
|
|
358
|
+
* @param {string} entry
|
|
359
|
+
* @returns {string|null}
|
|
360
|
+
*/
|
|
361
|
+
function resolve_entry(entry) {
|
|
362
|
+
if (fs__default.existsSync(entry)) {
|
|
363
|
+
const stats = fs__default.statSync(entry);
|
|
364
|
+
if (stats.isDirectory()) {
|
|
365
|
+
return resolve_entry(path__default.join(entry, 'index'));
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
return entry;
|
|
369
|
+
} else {
|
|
370
|
+
const dir = path__default.dirname(entry);
|
|
371
|
+
|
|
372
|
+
if (fs__default.existsSync(dir)) {
|
|
373
|
+
const base = path__default.basename(entry);
|
|
374
|
+
const files = fs__default.readdirSync(dir);
|
|
375
|
+
|
|
376
|
+
const found = files.find((file) => file.replace(/\.[^.]+$/, '') === base);
|
|
377
|
+
|
|
378
|
+
if (found) return path__default.join(dir, found);
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
return null;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
/** @param {string} str */
|
|
386
|
+
function posixify(str) {
|
|
387
|
+
return str.replace(/\\/g, '/');
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
/** @param {import('./create_app/index.js').ManifestData} manifest_data */
|
|
391
|
+
function get_mime_lookup(manifest_data) {
|
|
392
|
+
/** @type {Record<string, string>} */
|
|
393
|
+
const mime = {};
|
|
394
|
+
|
|
395
|
+
manifest_data.assets.forEach((asset) => {
|
|
396
|
+
if (asset.type) {
|
|
397
|
+
const ext = path__default.extname(asset.file);
|
|
398
|
+
mime[ext] = asset.type;
|
|
399
|
+
}
|
|
400
|
+
});
|
|
401
|
+
|
|
402
|
+
return mime;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
/** @typedef {import('./types').Validator} Validator */
|
|
406
|
+
|
|
407
|
+
/** @type {Validator} */
|
|
408
|
+
const options = object(
|
|
409
|
+
{
|
|
410
|
+
extensions: validate(['.svelte'], (input, keypath) => {
|
|
411
|
+
if (!Array.isArray(input) || !input.every((page) => typeof page === 'string')) {
|
|
412
|
+
throw new Error(`${keypath} must be an array of strings`);
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
input.forEach((extension) => {
|
|
416
|
+
if (extension[0] !== '.') {
|
|
417
|
+
throw new Error(`Each member of ${keypath} must start with '.' — saw '${extension}'`);
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
if (!/^(\.[a-z0-9]+)+$/i.test(extension)) {
|
|
421
|
+
throw new Error(`File extensions must be alphanumeric — saw '${extension}'`);
|
|
422
|
+
}
|
|
423
|
+
});
|
|
424
|
+
|
|
425
|
+
return input;
|
|
426
|
+
}),
|
|
427
|
+
|
|
428
|
+
kit: object({
|
|
429
|
+
adapter: validate(null, (input, keypath) => {
|
|
430
|
+
if (typeof input !== 'object' || !input.adapt) {
|
|
431
|
+
let message = `${keypath} should be an object with an "adapt" method`;
|
|
432
|
+
|
|
433
|
+
if (Array.isArray(input) || typeof input === 'string') {
|
|
434
|
+
// for the early adapter adopters
|
|
435
|
+
message += ', rather than the name of an adapter';
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
throw new Error(`${message}. See https://kit.svelte.dev/docs#adapters`);
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
return input;
|
|
442
|
+
}),
|
|
443
|
+
|
|
444
|
+
amp: boolean(false),
|
|
445
|
+
|
|
446
|
+
appDir: validate('_app', (input, keypath) => {
|
|
447
|
+
assert_string(input, keypath);
|
|
448
|
+
|
|
449
|
+
if (input) {
|
|
450
|
+
if (input.startsWith('/') || input.endsWith('/')) {
|
|
451
|
+
throw new Error(
|
|
452
|
+
"config.kit.appDir cannot start or end with '/'. See https://kit.svelte.dev/docs#configuration"
|
|
453
|
+
);
|
|
454
|
+
}
|
|
455
|
+
} else {
|
|
456
|
+
throw new Error(`${keypath} cannot be empty`);
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
return input;
|
|
460
|
+
}),
|
|
461
|
+
|
|
462
|
+
files: object({
|
|
463
|
+
assets: string('static'),
|
|
464
|
+
hooks: string('src/hooks'),
|
|
465
|
+
lib: string('src/lib'),
|
|
466
|
+
routes: string('src/routes'),
|
|
467
|
+
serviceWorker: string('src/service-worker'),
|
|
468
|
+
template: string('src/app.html')
|
|
469
|
+
}),
|
|
470
|
+
|
|
471
|
+
floc: boolean(false),
|
|
472
|
+
|
|
473
|
+
headers: object({
|
|
474
|
+
host: string(null),
|
|
475
|
+
protocol: string(null)
|
|
476
|
+
}),
|
|
477
|
+
|
|
478
|
+
host: string(null),
|
|
479
|
+
|
|
480
|
+
hydrate: boolean(true),
|
|
481
|
+
|
|
482
|
+
package: object({
|
|
483
|
+
dir: string('package'),
|
|
484
|
+
// excludes all .d.ts and filename starting with _
|
|
485
|
+
exports: fun((filepath) => !/^_|\/_|\.d\.ts$/.test(filepath)),
|
|
486
|
+
files: fun(() => true),
|
|
487
|
+
emitTypes: boolean(true)
|
|
488
|
+
}),
|
|
489
|
+
|
|
490
|
+
paths: object({
|
|
491
|
+
base: validate('', (input, keypath) => {
|
|
492
|
+
assert_string(input, keypath);
|
|
493
|
+
|
|
494
|
+
if (input !== '' && (input.endsWith('/') || !input.startsWith('/'))) {
|
|
495
|
+
throw new Error(
|
|
496
|
+
`${keypath} option must be a root-relative path that starts but doesn't end with '/'. See https://kit.svelte.dev/docs#configuration-paths`
|
|
497
|
+
);
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
return input;
|
|
501
|
+
}),
|
|
502
|
+
assets: validate('', (input, keypath) => {
|
|
503
|
+
assert_string(input, keypath);
|
|
504
|
+
|
|
505
|
+
if (input) {
|
|
506
|
+
if (!/^[a-z]+:\/\//.test(input)) {
|
|
507
|
+
throw new Error(
|
|
508
|
+
`${keypath} option must be an absolute path, if specified. See https://kit.svelte.dev/docs#configuration-paths`
|
|
509
|
+
);
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
if (input.endsWith('/')) {
|
|
513
|
+
throw new Error(
|
|
514
|
+
`${keypath} option must not end with '/'. See https://kit.svelte.dev/docs#configuration-paths`
|
|
515
|
+
);
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
return input;
|
|
520
|
+
})
|
|
521
|
+
}),
|
|
522
|
+
|
|
523
|
+
prerender: object({
|
|
524
|
+
concurrency: number(1),
|
|
525
|
+
crawl: boolean(true),
|
|
526
|
+
enabled: boolean(true),
|
|
527
|
+
entries: validate(['*'], (input, keypath) => {
|
|
528
|
+
if (!Array.isArray(input) || !input.every((page) => typeof page === 'string')) {
|
|
529
|
+
throw new Error(`${keypath} must be an array of strings`);
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
input.forEach((page) => {
|
|
533
|
+
if (page !== '*' && page[0] !== '/') {
|
|
534
|
+
throw new Error(
|
|
535
|
+
`Each member of ${keypath} must be either '*' or an absolute path beginning with '/' — saw '${page}'`
|
|
536
|
+
);
|
|
537
|
+
}
|
|
538
|
+
});
|
|
539
|
+
|
|
540
|
+
return input;
|
|
541
|
+
}),
|
|
542
|
+
// TODO: remove this for the 1.0 release
|
|
543
|
+
force: validate(undefined, (input, keypath) => {
|
|
544
|
+
if (typeof input !== undefined) {
|
|
545
|
+
const newSetting = input ? 'continue' : 'fail';
|
|
546
|
+
const needsSetting = newSetting === 'continue';
|
|
547
|
+
throw new Error(
|
|
548
|
+
`${keypath} has been removed in favor of \`onError\`. In your case, set \`onError\` to "${newSetting}"${
|
|
549
|
+
needsSetting ? '' : ' (or leave it undefined)'
|
|
550
|
+
} to get the same behavior as you would with \`force: ${JSON.stringify(input)}\``
|
|
551
|
+
);
|
|
552
|
+
}
|
|
553
|
+
}),
|
|
554
|
+
onError: validate('fail', (input, keypath) => {
|
|
555
|
+
if (typeof input === 'function') return input;
|
|
556
|
+
if (['continue', 'fail'].includes(input)) return input;
|
|
557
|
+
throw new Error(
|
|
558
|
+
`${keypath} should be either a custom function or one of "continue" or "fail"`
|
|
559
|
+
);
|
|
560
|
+
}),
|
|
561
|
+
// TODO: remove this for the 1.0 release
|
|
562
|
+
pages: validate(undefined, (input, keypath) => {
|
|
563
|
+
if (typeof input !== undefined) {
|
|
564
|
+
throw new Error(`${keypath} has been renamed to \`entries\`.`);
|
|
565
|
+
}
|
|
566
|
+
})
|
|
567
|
+
}),
|
|
568
|
+
|
|
569
|
+
protocol: string(null),
|
|
570
|
+
|
|
571
|
+
router: boolean(true),
|
|
572
|
+
|
|
573
|
+
serviceWorker: object({
|
|
574
|
+
register: boolean(true),
|
|
575
|
+
files: fun((filename) => !/\.DS_STORE/.test(filename))
|
|
576
|
+
}),
|
|
577
|
+
|
|
578
|
+
ssr: boolean(true),
|
|
579
|
+
|
|
580
|
+
target: string(null),
|
|
581
|
+
|
|
582
|
+
trailingSlash: list(['never', 'always', 'ignore']),
|
|
583
|
+
|
|
584
|
+
vite: validate(
|
|
585
|
+
() => ({}),
|
|
586
|
+
(input, keypath) => {
|
|
587
|
+
if (typeof input === 'object') {
|
|
588
|
+
const config = input;
|
|
589
|
+
input = () => config;
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
if (typeof input !== 'function') {
|
|
593
|
+
throw new Error(
|
|
594
|
+
`${keypath} must be a Vite config object (https://vitejs.dev/config) or a function that returns one`
|
|
595
|
+
);
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
return input;
|
|
599
|
+
}
|
|
600
|
+
)
|
|
601
|
+
})
|
|
602
|
+
},
|
|
603
|
+
true
|
|
604
|
+
);
|
|
605
|
+
|
|
606
|
+
/**
|
|
607
|
+
* @param {Record<string, Validator>} children
|
|
608
|
+
* @param {boolean} [allow_unknown]
|
|
609
|
+
* @returns {Validator}
|
|
610
|
+
*/
|
|
611
|
+
function object(children, allow_unknown = false) {
|
|
612
|
+
return (input, keypath) => {
|
|
613
|
+
/** @type {Record<string, any>} */
|
|
614
|
+
const output = {};
|
|
615
|
+
|
|
616
|
+
if ((input && typeof input !== 'object') || Array.isArray(input)) {
|
|
617
|
+
throw new Error(`${keypath} should be an object`);
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
for (const key in input) {
|
|
621
|
+
if (!(key in children)) {
|
|
622
|
+
if (allow_unknown) {
|
|
623
|
+
output[key] = input[key];
|
|
624
|
+
} else {
|
|
625
|
+
let message = `Unexpected option ${keypath}.${key}`;
|
|
626
|
+
|
|
627
|
+
// special case
|
|
628
|
+
if (keypath === 'config.kit' && key in options) {
|
|
629
|
+
message += ` (did you mean config.${key}?)`;
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
throw new Error(message);
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
for (const key in children) {
|
|
638
|
+
const validator = children[key];
|
|
639
|
+
output[key] = validator(input && input[key], `${keypath}.${key}`);
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
return output;
|
|
643
|
+
};
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
/**
|
|
647
|
+
* @param {any} fallback
|
|
648
|
+
* @param {(value: any, keypath: string) => any} fn
|
|
649
|
+
* @returns {Validator}
|
|
650
|
+
*/
|
|
651
|
+
function validate(fallback, fn) {
|
|
652
|
+
return (input, keypath) => {
|
|
653
|
+
return input === undefined ? fallback : fn(input, keypath);
|
|
654
|
+
};
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
/**
|
|
658
|
+
* @param {string | null} fallback
|
|
659
|
+
* @param {boolean} allow_empty
|
|
660
|
+
* @returns {Validator}
|
|
661
|
+
*/
|
|
662
|
+
function string(fallback, allow_empty = true) {
|
|
663
|
+
return validate(fallback, (input, keypath) => {
|
|
664
|
+
assert_string(input, keypath);
|
|
665
|
+
|
|
666
|
+
if (!allow_empty && input === '') {
|
|
667
|
+
throw new Error(`${keypath} cannot be empty`);
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
return input;
|
|
671
|
+
});
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
/**
|
|
675
|
+
* @param {number} fallback
|
|
676
|
+
* @returns {Validator}
|
|
677
|
+
*/
|
|
678
|
+
function number(fallback) {
|
|
679
|
+
return validate(fallback, (input, keypath) => {
|
|
680
|
+
if (typeof input !== 'number') {
|
|
681
|
+
throw new Error(`${keypath} should be a number, if specified`);
|
|
682
|
+
}
|
|
683
|
+
return input;
|
|
684
|
+
});
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
/**
|
|
688
|
+
* @param {boolean} fallback
|
|
689
|
+
* @returns {Validator}
|
|
690
|
+
*/
|
|
691
|
+
function boolean(fallback) {
|
|
692
|
+
return validate(fallback, (input, keypath) => {
|
|
693
|
+
if (typeof input !== 'boolean') {
|
|
694
|
+
throw new Error(`${keypath} should be true or false, if specified`);
|
|
695
|
+
}
|
|
696
|
+
return input;
|
|
697
|
+
});
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
/**
|
|
701
|
+
* @param {string[]} options
|
|
702
|
+
* @returns {Validator}
|
|
703
|
+
*/
|
|
704
|
+
function list(options, fallback = options[0]) {
|
|
705
|
+
return validate(fallback, (input, keypath) => {
|
|
706
|
+
if (!options.includes(input)) {
|
|
707
|
+
// prettier-ignore
|
|
708
|
+
const msg = options.length > 2
|
|
709
|
+
? `${keypath} should be one of ${options.slice(0, -1).map(input => `"${input}"`).join(', ')} or "${options[options.length - 1]}"`
|
|
710
|
+
: `${keypath} should be either "${options[0]}" or "${options[1]}"`;
|
|
711
|
+
|
|
712
|
+
throw new Error(msg);
|
|
713
|
+
}
|
|
714
|
+
return input;
|
|
715
|
+
});
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
/**
|
|
719
|
+
* @param {(filename: string) => boolean} fallback
|
|
720
|
+
* @returns {Validator}
|
|
721
|
+
*/
|
|
722
|
+
function fun(fallback) {
|
|
723
|
+
return validate(fallback, (input, keypath) => {
|
|
724
|
+
if (typeof input !== 'function') {
|
|
725
|
+
throw new Error(`${keypath} should be a function, if specified`);
|
|
726
|
+
}
|
|
727
|
+
return input;
|
|
728
|
+
});
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
/**
|
|
732
|
+
* @param {string} input
|
|
733
|
+
* @param {string} keypath
|
|
734
|
+
*/
|
|
735
|
+
function assert_string(input, keypath) {
|
|
736
|
+
if (typeof input !== 'string') {
|
|
737
|
+
throw new Error(`${keypath} should be a string, if specified`);
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
/**
|
|
742
|
+
* @param {string} cwd
|
|
743
|
+
* @param {import('types/config').ValidatedConfig} validated
|
|
744
|
+
*/
|
|
745
|
+
function validate_template(cwd, validated) {
|
|
746
|
+
const { template } = validated.kit.files;
|
|
747
|
+
const relative = path__default.relative(cwd, template);
|
|
748
|
+
|
|
749
|
+
if (fs__default.existsSync(template)) {
|
|
750
|
+
const contents = fs__default.readFileSync(template, 'utf8');
|
|
751
|
+
const expected_tags = ['%svelte.head%', '%svelte.body%'];
|
|
752
|
+
expected_tags.forEach((tag) => {
|
|
753
|
+
if (contents.indexOf(tag) === -1) {
|
|
754
|
+
throw new Error(`${relative} is missing ${tag}`);
|
|
24
755
|
}
|
|
25
756
|
});
|
|
757
|
+
} else {
|
|
758
|
+
throw new Error(`${relative} does not exist`);
|
|
26
759
|
}
|
|
27
|
-
n['default'] = e;
|
|
28
|
-
return Object.freeze(n);
|
|
29
760
|
}
|
|
30
761
|
|
|
31
|
-
|
|
762
|
+
async function load_config({ cwd = process.cwd() } = {}) {
|
|
763
|
+
const config_file_esm = path__default.join(cwd, 'svelte.config.js');
|
|
764
|
+
const config_file = fs__default.existsSync(config_file_esm)
|
|
765
|
+
? config_file_esm
|
|
766
|
+
: path__default.join(cwd, 'svelte.config.cjs');
|
|
767
|
+
const config = await import(url.pathToFileURL(config_file).href);
|
|
768
|
+
|
|
769
|
+
const validated = validate_config(config.default);
|
|
770
|
+
|
|
771
|
+
validated.kit.files.assets = path__default.resolve(cwd, validated.kit.files.assets);
|
|
772
|
+
validated.kit.files.hooks = path__default.resolve(cwd, validated.kit.files.hooks);
|
|
773
|
+
validated.kit.files.lib = path__default.resolve(cwd, validated.kit.files.lib);
|
|
774
|
+
validated.kit.files.routes = path__default.resolve(cwd, validated.kit.files.routes);
|
|
775
|
+
validated.kit.files.serviceWorker = path__default.resolve(cwd, validated.kit.files.serviceWorker);
|
|
776
|
+
validated.kit.files.template = path__default.resolve(cwd, validated.kit.files.template);
|
|
777
|
+
|
|
778
|
+
validate_template(cwd, validated);
|
|
779
|
+
|
|
780
|
+
// TODO check all the `files` exist when the config is loaded?
|
|
781
|
+
|
|
782
|
+
return validated;
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
/**
|
|
786
|
+
* @param {import('types/config').Config} config
|
|
787
|
+
* @returns {import('types/config').ValidatedConfig}
|
|
788
|
+
*/
|
|
789
|
+
function validate_config(config) {
|
|
790
|
+
const type = typeof config;
|
|
791
|
+
|
|
792
|
+
if (type === 'undefined') {
|
|
793
|
+
throw new Error(
|
|
794
|
+
'Your config is missing default exports. Make sure to include "export default config;"'
|
|
795
|
+
);
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
if (type !== 'object') {
|
|
799
|
+
throw new Error(
|
|
800
|
+
`Unexpected config type "${type}", make sure your default export is an object.`
|
|
801
|
+
);
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
return options(config, 'config');
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
/**
|
|
808
|
+
* @param {string[]} conflicts - array of conflicts in dotted notation
|
|
809
|
+
* @param {string=} pathPrefix - prepended in front of the path
|
|
810
|
+
* @param {string=} scope - used to prefix the whole error message
|
|
811
|
+
*/
|
|
812
|
+
function print_config_conflicts(conflicts, pathPrefix = '', scope) {
|
|
813
|
+
const prefix = scope ? scope + ': ' : '';
|
|
814
|
+
const log = logger({ verbose: false });
|
|
815
|
+
conflicts.forEach((conflict) => {
|
|
816
|
+
log.error(
|
|
817
|
+
`${prefix}The value for ${pathPrefix}${conflict} specified in svelte.config.js has been ignored. This option is controlled by SvelteKit.`
|
|
818
|
+
);
|
|
819
|
+
});
|
|
820
|
+
}
|
|
821
|
+
|
|
822
|
+
async function get_config() {
|
|
823
|
+
// TODO this is temporary, for the benefit of early adopters
|
|
824
|
+
if (existsSync('svelte.config.cjs')) {
|
|
825
|
+
// prettier-ignore
|
|
826
|
+
console.error($.bold().red(
|
|
827
|
+
'svelte.config.cjs should be renamed to svelte.config.js and converted to an ES module. See https://kit.svelte.dev/docs#configuration for an example'
|
|
828
|
+
));
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
if (existsSync('vite.config.js')) {
|
|
832
|
+
// prettier-ignore
|
|
833
|
+
console.error($.bold().red(
|
|
834
|
+
'Please remove vite.config.js and put Vite config in svelte.config.js: https://kit.svelte.dev/docs#configuration-vite'
|
|
835
|
+
));
|
|
836
|
+
}
|
|
32
837
|
|
|
33
|
-
function get_config() {
|
|
34
838
|
try {
|
|
35
|
-
return
|
|
36
|
-
} catch (
|
|
839
|
+
return await load_config();
|
|
840
|
+
} catch (err) {
|
|
841
|
+
const error = coalesce_to_error(err);
|
|
37
842
|
let message = error.message;
|
|
38
843
|
|
|
39
|
-
if (
|
|
844
|
+
if (
|
|
845
|
+
has_error_code(error, 'MODULE_NOT_FOUND') &&
|
|
846
|
+
/Cannot find module svelte\.config\./.test(error.message)
|
|
847
|
+
) {
|
|
40
848
|
message = 'Missing svelte.config.js';
|
|
41
849
|
} else if (error.name === 'SyntaxError') {
|
|
42
850
|
message = 'Malformed svelte.config.js';
|
|
43
851
|
}
|
|
44
852
|
|
|
45
|
-
console.error(
|
|
46
|
-
|
|
853
|
+
console.error($.bold().red(message));
|
|
854
|
+
if (error.stack) {
|
|
855
|
+
console.error($.grey(error.stack));
|
|
856
|
+
}
|
|
47
857
|
process.exit(1);
|
|
48
858
|
}
|
|
49
859
|
}
|
|
50
860
|
|
|
861
|
+
/** @param {unknown} error */
|
|
51
862
|
function handle_error(error) {
|
|
52
|
-
|
|
53
|
-
console.log(
|
|
863
|
+
const err = coalesce_to_error(error);
|
|
864
|
+
console.log($.bold().red(`> ${err.message}`));
|
|
865
|
+
if (err.stack) {
|
|
866
|
+
console.log($.gray(err.stack));
|
|
867
|
+
}
|
|
54
868
|
process.exit(1);
|
|
55
869
|
}
|
|
56
870
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
871
|
+
/**
|
|
872
|
+
* @param {number} port
|
|
873
|
+
* @param {boolean} https
|
|
874
|
+
*/
|
|
875
|
+
async function launch(port, https) {
|
|
876
|
+
const { exec } = await import('child_process');
|
|
877
|
+
let cmd = 'open';
|
|
878
|
+
if (process.platform == 'win32') {
|
|
879
|
+
cmd = 'start';
|
|
880
|
+
} else if (process.platform == 'linux') {
|
|
881
|
+
if (/microsoft/i.test(release())) {
|
|
882
|
+
cmd = 'cmd.exe /c start';
|
|
883
|
+
} else {
|
|
884
|
+
cmd = 'xdg-open';
|
|
885
|
+
}
|
|
886
|
+
}
|
|
887
|
+
exec(`${cmd} ${https ? 'https' : 'http'}://localhost:${port}`);
|
|
60
888
|
}
|
|
61
889
|
|
|
62
|
-
const prog =
|
|
890
|
+
const prog = sade('svelte-kit').version('1.0.0-next.210');
|
|
63
891
|
|
|
64
892
|
prog
|
|
65
893
|
.command('dev')
|
|
66
894
|
.describe('Start a development server')
|
|
67
|
-
.option('-p, --port', 'Port'
|
|
68
|
-
.option('-
|
|
69
|
-
.
|
|
70
|
-
|
|
71
|
-
|
|
895
|
+
.option('-p, --port', 'Port')
|
|
896
|
+
.option('-h, --host', 'Host (only use this on trusted networks)')
|
|
897
|
+
.option('-H, --https', 'Use self-signed HTTPS certificate')
|
|
898
|
+
.option('-o, --open', 'Open a browser tab')
|
|
899
|
+
.action(async ({ port, host, https, open }) => {
|
|
900
|
+
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
|
|
901
|
+
const config = await get_config();
|
|
72
902
|
|
|
73
|
-
const { dev } = await
|
|
903
|
+
const { dev } = await import('./chunks/index.js');
|
|
74
904
|
|
|
75
905
|
try {
|
|
76
|
-
const watcher = await dev({ port, config });
|
|
906
|
+
const watcher = await dev({ port, host, https, config });
|
|
77
907
|
|
|
78
908
|
watcher.on('stdout', (data) => {
|
|
79
909
|
process.stdout.write(data);
|
|
@@ -83,8 +913,28 @@ prog
|
|
|
83
913
|
process.stderr.write(data);
|
|
84
914
|
});
|
|
85
915
|
|
|
86
|
-
|
|
87
|
-
|
|
916
|
+
if (!watcher.vite || !watcher.vite.httpServer) {
|
|
917
|
+
throw Error('Could not find server');
|
|
918
|
+
}
|
|
919
|
+
// we never start the server on a socket path, so address will be of type AddressInfo
|
|
920
|
+
const address_info = /** @type {import('net').AddressInfo} */ (
|
|
921
|
+
watcher.vite.httpServer.address()
|
|
922
|
+
);
|
|
923
|
+
|
|
924
|
+
const vite_config = config.kit.vite();
|
|
925
|
+
|
|
926
|
+
https = https || !!vite_config.server?.https;
|
|
927
|
+
open = open || !!vite_config.server?.open;
|
|
928
|
+
|
|
929
|
+
welcome({
|
|
930
|
+
port: address_info.port,
|
|
931
|
+
host: address_info.address,
|
|
932
|
+
https,
|
|
933
|
+
open,
|
|
934
|
+
loose: vite_config.server?.fs?.strict === false,
|
|
935
|
+
allow: watcher.allowed_directories(),
|
|
936
|
+
cwd: watcher.cwd
|
|
937
|
+
});
|
|
88
938
|
} catch (error) {
|
|
89
939
|
handle_error(error);
|
|
90
940
|
}
|
|
@@ -93,55 +943,150 @@ prog
|
|
|
93
943
|
prog
|
|
94
944
|
.command('build')
|
|
95
945
|
.describe('Create a production build of your app')
|
|
96
|
-
.
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
const { build } = await Promise.resolve().then(function () { return require('./index2.js'); });
|
|
946
|
+
.option('--verbose', 'Log more stuff', false)
|
|
947
|
+
.action(async ({ verbose }) => {
|
|
948
|
+
process.env.NODE_ENV = process.env.NODE_ENV || 'production';
|
|
949
|
+
const config = await get_config();
|
|
101
950
|
|
|
102
951
|
try {
|
|
103
|
-
await
|
|
952
|
+
const { build } = await import('./chunks/index3.js');
|
|
953
|
+
const build_data = await build(config);
|
|
954
|
+
|
|
955
|
+
console.log(
|
|
956
|
+
`\nRun ${$.bold().cyan('npm run preview')} to preview your production build locally.`
|
|
957
|
+
);
|
|
958
|
+
|
|
959
|
+
if (config.kit.adapter) {
|
|
960
|
+
const { adapt } = await import('./chunks/index5.js');
|
|
961
|
+
await adapt(config, build_data, { verbose });
|
|
962
|
+
|
|
963
|
+
// this is necessary to close any open db connections, etc
|
|
964
|
+
process.exit(0);
|
|
965
|
+
}
|
|
966
|
+
|
|
967
|
+
console.log($.bold().yellow('\nNo adapter specified'));
|
|
968
|
+
|
|
969
|
+
// prettier-ignore
|
|
970
|
+
console.log(
|
|
971
|
+
`See ${$.bold().cyan('https://kit.svelte.dev/docs#adapters')} to learn how to configure your app to run on the platform of your choosing`
|
|
972
|
+
);
|
|
104
973
|
} catch (error) {
|
|
105
974
|
handle_error(error);
|
|
106
975
|
}
|
|
107
976
|
});
|
|
108
977
|
|
|
109
978
|
prog
|
|
110
|
-
.command('
|
|
979
|
+
.command('preview')
|
|
111
980
|
.describe('Serve an already-built app')
|
|
112
981
|
.option('-p, --port', 'Port', 3000)
|
|
982
|
+
.option('-h, --host', 'Host (only use this on trusted networks)', 'localhost')
|
|
983
|
+
.option('-H, --https', 'Use self-signed HTTPS certificate', false)
|
|
113
984
|
.option('-o, --open', 'Open a browser tab', false)
|
|
114
|
-
.action(async ({ port, open }) => {
|
|
115
|
-
|
|
116
|
-
const config = get_config();
|
|
985
|
+
.action(async ({ port, host, https, open }) => {
|
|
986
|
+
await check_port(port);
|
|
117
987
|
|
|
118
|
-
|
|
988
|
+
process.env.NODE_ENV = process.env.NODE_ENV || 'production';
|
|
989
|
+
const config = await get_config();
|
|
990
|
+
|
|
991
|
+
const { preview } = await import('./chunks/index6.js');
|
|
119
992
|
|
|
120
993
|
try {
|
|
121
|
-
await
|
|
994
|
+
await preview({ port, host, config, https });
|
|
122
995
|
|
|
123
|
-
|
|
124
|
-
if (open) if (open) launch(port);
|
|
996
|
+
welcome({ port, host, https, open });
|
|
125
997
|
} catch (error) {
|
|
126
998
|
handle_error(error);
|
|
127
999
|
}
|
|
128
1000
|
});
|
|
129
1001
|
|
|
130
1002
|
prog
|
|
131
|
-
.command('
|
|
132
|
-
.describe('
|
|
1003
|
+
.command('package')
|
|
1004
|
+
.describe('Create a package')
|
|
1005
|
+
.option('-d, --dir', 'Destination directory', 'package')
|
|
133
1006
|
.action(async () => {
|
|
134
|
-
|
|
135
|
-
const config = get_config();
|
|
1007
|
+
const config = await get_config();
|
|
136
1008
|
|
|
137
|
-
const {
|
|
1009
|
+
const { make_package } = await import('./chunks/index7.js');
|
|
138
1010
|
|
|
139
1011
|
try {
|
|
140
|
-
await
|
|
1012
|
+
await make_package(config);
|
|
141
1013
|
} catch (error) {
|
|
142
1014
|
handle_error(error);
|
|
143
1015
|
}
|
|
144
1016
|
});
|
|
145
1017
|
|
|
146
1018
|
prog.parse(process.argv, { unknown: (arg) => `Unknown option: ${arg}` });
|
|
147
|
-
|
|
1019
|
+
|
|
1020
|
+
/** @param {number} port */
|
|
1021
|
+
async function check_port(port) {
|
|
1022
|
+
if (await check(port)) {
|
|
1023
|
+
return;
|
|
1024
|
+
}
|
|
1025
|
+
console.log($.bold().red(`Port ${port} is occupied`));
|
|
1026
|
+
const n = await blame(port);
|
|
1027
|
+
if (n) {
|
|
1028
|
+
// prettier-ignore
|
|
1029
|
+
console.log(
|
|
1030
|
+
`Terminate process ${$.bold(n)} or specify a different port with ${$.bold('--port')}\n`
|
|
1031
|
+
);
|
|
1032
|
+
} else {
|
|
1033
|
+
// prettier-ignore
|
|
1034
|
+
console.log(
|
|
1035
|
+
`Terminate the process occupying the port or specify a different port with ${$.bold('--port')}\n`
|
|
1036
|
+
);
|
|
1037
|
+
}
|
|
1038
|
+
process.exit(1);
|
|
1039
|
+
}
|
|
1040
|
+
|
|
1041
|
+
/**
|
|
1042
|
+
* @param {{
|
|
1043
|
+
* open: boolean;
|
|
1044
|
+
* host: string;
|
|
1045
|
+
* https: boolean;
|
|
1046
|
+
* port: number;
|
|
1047
|
+
* loose?: boolean;
|
|
1048
|
+
* allow?: string[];
|
|
1049
|
+
* cwd?: string;
|
|
1050
|
+
* }} param0
|
|
1051
|
+
*/
|
|
1052
|
+
function welcome({ port, host, https, open, loose, allow, cwd }) {
|
|
1053
|
+
if (open) launch(port, https);
|
|
1054
|
+
|
|
1055
|
+
console.log($.bold().cyan(`\n SvelteKit v${'1.0.0-next.210'}\n`));
|
|
1056
|
+
|
|
1057
|
+
const protocol = https ? 'https:' : 'http:';
|
|
1058
|
+
const exposed = typeof host !== 'undefined' && host !== 'localhost' && host !== '127.0.0.1';
|
|
1059
|
+
|
|
1060
|
+
Object.values(networkInterfaces()).forEach((interfaces) => {
|
|
1061
|
+
if (!interfaces) return;
|
|
1062
|
+
interfaces.forEach((details) => {
|
|
1063
|
+
if (details.family !== 'IPv4') return;
|
|
1064
|
+
|
|
1065
|
+
// prettier-ignore
|
|
1066
|
+
if (details.internal) {
|
|
1067
|
+
console.log(` ${$.gray('local: ')} ${protocol}//${$.bold(`localhost:${port}`)}`);
|
|
1068
|
+
} else {
|
|
1069
|
+
if (details.mac === '00:00:00:00:00:00') return;
|
|
1070
|
+
|
|
1071
|
+
if (exposed) {
|
|
1072
|
+
console.log(` ${$.gray('network:')} ${protocol}//${$.bold(`${details.address}:${port}`)}`);
|
|
1073
|
+
if (loose) {
|
|
1074
|
+
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.')}`);
|
|
1075
|
+
} else if (allow?.length && cwd) {
|
|
1076
|
+
console.log(`\n ${$.yellow('Note that all files in the following directories will be accessible to anyone on your network: ' + allow.map(a => relative(cwd, a)).join(', '))}`);
|
|
1077
|
+
}
|
|
1078
|
+
} else {
|
|
1079
|
+
console.log(` ${$.gray('network: not exposed')}`);
|
|
1080
|
+
}
|
|
1081
|
+
}
|
|
1082
|
+
});
|
|
1083
|
+
});
|
|
1084
|
+
|
|
1085
|
+
if (!exposed) {
|
|
1086
|
+
console.log('\n Use --host to expose server to other devices on this network');
|
|
1087
|
+
}
|
|
1088
|
+
|
|
1089
|
+
console.log('\n');
|
|
1090
|
+
}
|
|
1091
|
+
|
|
1092
|
+
export { $, resolve_entry as a, posixify as b, copy_assets as c, copy as d, get_mime_lookup as g, logger as l, mkdirp as m, print_config_conflicts as p, rimraf as r, walk as w };
|