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