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