@sveltejs/kit 1.0.0-next.25 → 1.0.0-next.253
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 +18 -2
- package/assets/env.js +8 -0
- package/assets/paths.js +13 -0
- package/assets/server/index.js +2374 -0
- package/dist/chunks/amp_hook.js +56 -0
- package/dist/chunks/build.js +658 -0
- package/dist/chunks/cert.js +28154 -0
- package/dist/chunks/index.js +459 -0
- package/dist/chunks/index2.js +806 -0
- package/dist/chunks/index3.js +644 -0
- package/dist/chunks/index4.js +114 -0
- package/dist/chunks/index5.js +858 -0
- package/dist/chunks/index6.js +170 -0
- package/dist/chunks/index7.js +15582 -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/cli.js +1122 -84
- package/dist/hooks.js +28 -0
- package/dist/install-fetch.js +6518 -0
- package/dist/node.js +95 -0
- package/package.json +95 -54
- package/svelte-kit.js +2 -0
- package/types/ambient-modules.d.ts +195 -0
- package/types/app.d.ts +35 -0
- package/types/config.d.ts +173 -0
- package/types/csp.d.ts +115 -0
- package/types/endpoint.d.ts +24 -0
- package/types/helper.d.ts +32 -0
- package/types/hooks.d.ts +38 -0
- package/types/index.d.ts +10 -0
- package/types/internal.d.ts +252 -0
- package/types/page.d.ts +85 -0
- package/CHANGELOG.md +0 -306
- 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 -12043
- package/dist/index2.js.map +0 -1
- package/dist/index3.js +0 -550
- package/dist/index3.js.map +0 -1
- package/dist/index4.js +0 -74
- 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 -2403
- 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,1032 @@
|
|
|
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, { join, 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
|
+
}
|
|
34
101
|
|
|
35
|
-
function
|
|
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
|
+
}
|
|
116
|
+
|
|
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();
|
|
163
|
+
|
|
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);
|
|
185
|
+
}
|
|
186
|
+
|
|
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;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
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
|
+
}
|
|
40
280
|
|
|
41
|
-
|
|
42
|
-
message = 'Missing svelte.config.js';
|
|
43
|
-
} else if (error.name === 'SyntaxError') {
|
|
44
|
-
message = 'Malformed svelte.config.js';
|
|
281
|
+
files.push(to === target ? posixify(path__default.basename(to)) : posixify(to).replace(prefix, ''));
|
|
45
282
|
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
go(source, target);
|
|
286
|
+
|
|
287
|
+
return files;
|
|
288
|
+
}
|
|
46
289
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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
|
+
}
|
|
50
313
|
}
|
|
314
|
+
|
|
315
|
+
return walk_dir(''), all_files;
|
|
51
316
|
}
|
|
52
317
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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
|
+
browser: object({
|
|
494
|
+
hydrate: boolean(true),
|
|
495
|
+
router: boolean(true)
|
|
496
|
+
}),
|
|
497
|
+
|
|
498
|
+
csp: object({
|
|
499
|
+
mode: list(['auto', 'hash', 'nonce']),
|
|
500
|
+
directives: object({
|
|
501
|
+
'child-src': string_array(),
|
|
502
|
+
'default-src': string_array(),
|
|
503
|
+
'frame-src': string_array(),
|
|
504
|
+
'worker-src': string_array(),
|
|
505
|
+
'connect-src': string_array(),
|
|
506
|
+
'font-src': string_array(),
|
|
507
|
+
'img-src': string_array(),
|
|
508
|
+
'manifest-src': string_array(),
|
|
509
|
+
'media-src': string_array(),
|
|
510
|
+
'object-src': string_array(),
|
|
511
|
+
'prefetch-src': string_array(),
|
|
512
|
+
'script-src': string_array(),
|
|
513
|
+
'script-src-elem': string_array(),
|
|
514
|
+
'script-src-attr': string_array(),
|
|
515
|
+
'style-src': string_array(),
|
|
516
|
+
'style-src-elem': string_array(),
|
|
517
|
+
'style-src-attr': string_array(),
|
|
518
|
+
'base-uri': string_array(),
|
|
519
|
+
sandbox: string_array(),
|
|
520
|
+
'form-action': string_array(),
|
|
521
|
+
'frame-ancestors': string_array(),
|
|
522
|
+
'navigate-to': string_array(),
|
|
523
|
+
'report-uri': string_array(),
|
|
524
|
+
'report-to': string_array(),
|
|
525
|
+
'require-trusted-types-for': string_array(),
|
|
526
|
+
'trusted-types': string_array(),
|
|
527
|
+
'upgrade-insecure-requests': boolean(false),
|
|
528
|
+
'require-sri-for': string_array(),
|
|
529
|
+
'block-all-mixed-content': boolean(false),
|
|
530
|
+
'plugin-types': string_array(),
|
|
531
|
+
referrer: string_array()
|
|
532
|
+
})
|
|
533
|
+
}),
|
|
534
|
+
|
|
535
|
+
files: object({
|
|
536
|
+
assets: string('static'),
|
|
537
|
+
hooks: string(join('src', 'hooks')),
|
|
538
|
+
lib: string(join('src', 'lib')),
|
|
539
|
+
routes: string(join('src', 'routes')),
|
|
540
|
+
serviceWorker: string(join('src', 'service-worker')),
|
|
541
|
+
template: string(join('src', 'app.html'))
|
|
542
|
+
}),
|
|
543
|
+
|
|
544
|
+
floc: boolean(false),
|
|
545
|
+
|
|
546
|
+
// TODO: remove this for the 1.0 release
|
|
547
|
+
headers: error(
|
|
548
|
+
(keypath) =>
|
|
549
|
+
`${keypath} has been removed. See https://github.com/sveltejs/kit/pull/3384 for details`
|
|
550
|
+
),
|
|
551
|
+
|
|
552
|
+
// TODO: remove this for the 1.0 release
|
|
553
|
+
host: error(
|
|
554
|
+
(keypath) =>
|
|
555
|
+
`${keypath} has been removed. See https://github.com/sveltejs/kit/pull/3384 for details`
|
|
556
|
+
),
|
|
557
|
+
|
|
558
|
+
// TODO remove for 1.0
|
|
559
|
+
hydrate: error((keypath) => `${keypath} has been moved to config.kit.browser.hydrate`),
|
|
560
|
+
|
|
561
|
+
inlineStyleThreshold: number(0),
|
|
562
|
+
|
|
563
|
+
methodOverride: object({
|
|
564
|
+
parameter: string('_method'),
|
|
565
|
+
allowed: validate([], (input, keypath) => {
|
|
566
|
+
if (!Array.isArray(input) || !input.every((method) => typeof method === 'string')) {
|
|
567
|
+
throw new Error(`${keypath} must be an array of strings`);
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
if (input.map((i) => i.toUpperCase()).includes('GET')) {
|
|
571
|
+
throw new Error(`${keypath} cannot contain "GET"`);
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
return input;
|
|
575
|
+
})
|
|
576
|
+
}),
|
|
577
|
+
|
|
578
|
+
package: object({
|
|
579
|
+
dir: string('package'),
|
|
580
|
+
// excludes all .d.ts and filename starting with _
|
|
581
|
+
exports: fun((filepath) => !/^_|\/_|\.d\.ts$/.test(filepath)),
|
|
582
|
+
files: fun(() => true),
|
|
583
|
+
emitTypes: boolean(true)
|
|
584
|
+
}),
|
|
585
|
+
|
|
586
|
+
paths: object({
|
|
587
|
+
base: validate('', (input, keypath) => {
|
|
588
|
+
assert_string(input, keypath);
|
|
589
|
+
|
|
590
|
+
if (input !== '' && (input.endsWith('/') || !input.startsWith('/'))) {
|
|
591
|
+
throw new Error(
|
|
592
|
+
`${keypath} option must be a root-relative path that starts but doesn't end with '/'. See https://kit.svelte.dev/docs#configuration-paths`
|
|
593
|
+
);
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
return input;
|
|
597
|
+
}),
|
|
598
|
+
assets: validate('', (input, keypath) => {
|
|
599
|
+
assert_string(input, keypath);
|
|
600
|
+
|
|
601
|
+
if (input) {
|
|
602
|
+
if (!/^[a-z]+:\/\//.test(input)) {
|
|
603
|
+
throw new Error(
|
|
604
|
+
`${keypath} option must be an absolute path, if specified. See https://kit.svelte.dev/docs#configuration-paths`
|
|
605
|
+
);
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
if (input.endsWith('/')) {
|
|
609
|
+
throw new Error(
|
|
610
|
+
`${keypath} option must not end with '/'. See https://kit.svelte.dev/docs#configuration-paths`
|
|
611
|
+
);
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
return input;
|
|
616
|
+
})
|
|
617
|
+
}),
|
|
618
|
+
|
|
619
|
+
prerender: object({
|
|
620
|
+
concurrency: number(1),
|
|
621
|
+
crawl: boolean(true),
|
|
622
|
+
createIndexFiles: boolean(true),
|
|
623
|
+
enabled: boolean(true),
|
|
624
|
+
entries: validate(['*'], (input, keypath) => {
|
|
625
|
+
if (!Array.isArray(input) || !input.every((page) => typeof page === 'string')) {
|
|
626
|
+
throw new Error(`${keypath} must be an array of strings`);
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
input.forEach((page) => {
|
|
630
|
+
if (page !== '*' && page[0] !== '/') {
|
|
631
|
+
throw new Error(
|
|
632
|
+
`Each member of ${keypath} must be either '*' or an absolute path beginning with '/' — saw '${page}'`
|
|
633
|
+
);
|
|
634
|
+
}
|
|
635
|
+
});
|
|
636
|
+
|
|
637
|
+
return input;
|
|
638
|
+
}),
|
|
639
|
+
|
|
640
|
+
// TODO: remove this for the 1.0 release
|
|
641
|
+
force: validate(undefined, (input, keypath) => {
|
|
642
|
+
if (typeof input !== undefined) {
|
|
643
|
+
const newSetting = input ? 'continue' : 'fail';
|
|
644
|
+
const needsSetting = newSetting === 'continue';
|
|
645
|
+
throw new Error(
|
|
646
|
+
`${keypath} has been removed in favor of \`onError\`. In your case, set \`onError\` to "${newSetting}"${
|
|
647
|
+
needsSetting ? '' : ' (or leave it undefined)'
|
|
648
|
+
} to get the same behavior as you would with \`force: ${JSON.stringify(input)}\``
|
|
649
|
+
);
|
|
650
|
+
}
|
|
651
|
+
}),
|
|
652
|
+
|
|
653
|
+
onError: validate('fail', (input, keypath) => {
|
|
654
|
+
if (typeof input === 'function') return input;
|
|
655
|
+
if (['continue', 'fail'].includes(input)) return input;
|
|
656
|
+
throw new Error(
|
|
657
|
+
`${keypath} should be either a custom function or one of "continue" or "fail"`
|
|
658
|
+
);
|
|
659
|
+
}),
|
|
660
|
+
|
|
661
|
+
// TODO: remove this for the 1.0 release
|
|
662
|
+
pages: error((keypath) => `${keypath} has been renamed to \`entries\`.`)
|
|
663
|
+
}),
|
|
664
|
+
|
|
665
|
+
// TODO: remove this for the 1.0 release
|
|
666
|
+
protocol: error(
|
|
667
|
+
(keypath) =>
|
|
668
|
+
`${keypath} has been removed. See https://github.com/sveltejs/kit/pull/3384 for details`
|
|
669
|
+
),
|
|
670
|
+
|
|
671
|
+
// TODO remove for 1.0
|
|
672
|
+
router: error((keypath) => `${keypath} has been moved to config.kit.browser.router`),
|
|
673
|
+
|
|
674
|
+
routes: fun((filepath) => !/(?:(?:^_|\/_)|(?:^\.|\/\.)(?!well-known))/.test(filepath)),
|
|
675
|
+
|
|
676
|
+
serviceWorker: object({
|
|
677
|
+
register: boolean(true),
|
|
678
|
+
files: fun((filename) => !/\.DS_STORE/.test(filename))
|
|
679
|
+
}),
|
|
680
|
+
|
|
681
|
+
// TODO remove this for 1.0
|
|
682
|
+
ssr: error(
|
|
683
|
+
(keypath) =>
|
|
684
|
+
`${keypath} has been removed — use the handle hook instead: https://kit.svelte.dev/docs#hooks-handle'`
|
|
685
|
+
),
|
|
686
|
+
|
|
687
|
+
target: string(null),
|
|
688
|
+
|
|
689
|
+
trailingSlash: list(['never', 'always', 'ignore']),
|
|
690
|
+
|
|
691
|
+
vite: validate(
|
|
692
|
+
() => ({}),
|
|
693
|
+
(input, keypath) => {
|
|
694
|
+
if (typeof input === 'object') {
|
|
695
|
+
const config = input;
|
|
696
|
+
input = () => config;
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
if (typeof input !== 'function') {
|
|
700
|
+
throw new Error(
|
|
701
|
+
`${keypath} must be a Vite config object (https://vitejs.dev/config) or a function that returns one`
|
|
702
|
+
);
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
return input;
|
|
706
|
+
}
|
|
707
|
+
)
|
|
708
|
+
})
|
|
709
|
+
},
|
|
710
|
+
true
|
|
711
|
+
);
|
|
712
|
+
|
|
713
|
+
/**
|
|
714
|
+
* @param {Record<string, Validator>} children
|
|
715
|
+
* @param {boolean} [allow_unknown]
|
|
716
|
+
* @returns {Validator}
|
|
717
|
+
*/
|
|
718
|
+
function object(children, allow_unknown = false) {
|
|
719
|
+
return (input, keypath) => {
|
|
720
|
+
/** @type {Record<string, any>} */
|
|
721
|
+
const output = {};
|
|
722
|
+
|
|
723
|
+
if ((input && typeof input !== 'object') || Array.isArray(input)) {
|
|
724
|
+
throw new Error(`${keypath} should be an object`);
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
for (const key in input) {
|
|
728
|
+
if (!(key in children)) {
|
|
729
|
+
if (allow_unknown) {
|
|
730
|
+
output[key] = input[key];
|
|
731
|
+
} else {
|
|
732
|
+
let message = `Unexpected option ${keypath}.${key}`;
|
|
733
|
+
|
|
734
|
+
// special case
|
|
735
|
+
if (keypath === 'config.kit' && key in options) {
|
|
736
|
+
message += ` (did you mean config.${key}?)`;
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
throw new Error(message);
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
for (const key in children) {
|
|
745
|
+
const validator = children[key];
|
|
746
|
+
output[key] = validator(input && input[key], `${keypath}.${key}`);
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
return output;
|
|
750
|
+
};
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
/**
|
|
754
|
+
* @param {any} fallback
|
|
755
|
+
* @param {(value: any, keypath: string) => any} fn
|
|
756
|
+
* @returns {Validator}
|
|
757
|
+
*/
|
|
758
|
+
function validate(fallback, fn) {
|
|
759
|
+
return (input, keypath) => {
|
|
760
|
+
return input === undefined ? fallback : fn(input, keypath);
|
|
761
|
+
};
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
/**
|
|
765
|
+
* @param {string | null} fallback
|
|
766
|
+
* @param {boolean} allow_empty
|
|
767
|
+
* @returns {Validator}
|
|
768
|
+
*/
|
|
769
|
+
function string(fallback, allow_empty = true) {
|
|
770
|
+
return validate(fallback, (input, keypath) => {
|
|
771
|
+
assert_string(input, keypath);
|
|
772
|
+
|
|
773
|
+
if (!allow_empty && input === '') {
|
|
774
|
+
throw new Error(`${keypath} cannot be empty`);
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
return input;
|
|
778
|
+
});
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
/**
|
|
782
|
+
* @param {string[] | undefined} [fallback]
|
|
783
|
+
* @returns {Validator}
|
|
784
|
+
*/
|
|
785
|
+
function string_array(fallback) {
|
|
786
|
+
return validate(fallback, (input, keypath) => {
|
|
787
|
+
if (input === undefined) return input;
|
|
788
|
+
|
|
789
|
+
if (!Array.isArray(input) || input.some((value) => typeof value !== 'string')) {
|
|
790
|
+
throw new Error(`${keypath} must be an array of strings, if specified`);
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
return input;
|
|
794
|
+
});
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
/**
|
|
798
|
+
* @param {number} fallback
|
|
799
|
+
* @returns {Validator}
|
|
800
|
+
*/
|
|
801
|
+
function number(fallback) {
|
|
802
|
+
return validate(fallback, (input, keypath) => {
|
|
803
|
+
if (typeof input !== 'number') {
|
|
804
|
+
throw new Error(`${keypath} should be a number, if specified`);
|
|
805
|
+
}
|
|
806
|
+
return input;
|
|
807
|
+
});
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
/**
|
|
811
|
+
* @param {boolean} fallback
|
|
812
|
+
* @returns {Validator}
|
|
813
|
+
*/
|
|
814
|
+
function boolean(fallback) {
|
|
815
|
+
return validate(fallback, (input, keypath) => {
|
|
816
|
+
if (typeof input !== 'boolean') {
|
|
817
|
+
throw new Error(`${keypath} should be true or false, if specified`);
|
|
818
|
+
}
|
|
819
|
+
return input;
|
|
820
|
+
});
|
|
821
|
+
}
|
|
822
|
+
|
|
823
|
+
/**
|
|
824
|
+
* @param {string[]} options
|
|
825
|
+
* @returns {Validator}
|
|
826
|
+
*/
|
|
827
|
+
function list(options, fallback = options[0]) {
|
|
828
|
+
return validate(fallback, (input, keypath) => {
|
|
829
|
+
if (!options.includes(input)) {
|
|
830
|
+
// prettier-ignore
|
|
831
|
+
const msg = options.length > 2
|
|
832
|
+
? `${keypath} should be one of ${options.slice(0, -1).map(input => `"${input}"`).join(', ')} or "${options[options.length - 1]}"`
|
|
833
|
+
: `${keypath} should be either "${options[0]}" or "${options[1]}"`;
|
|
834
|
+
|
|
835
|
+
throw new Error(msg);
|
|
836
|
+
}
|
|
837
|
+
return input;
|
|
838
|
+
});
|
|
839
|
+
}
|
|
840
|
+
|
|
841
|
+
/**
|
|
842
|
+
* @param {(filename: string) => boolean} fallback
|
|
843
|
+
* @returns {Validator}
|
|
844
|
+
*/
|
|
845
|
+
function fun(fallback) {
|
|
846
|
+
return validate(fallback, (input, keypath) => {
|
|
847
|
+
if (typeof input !== 'function') {
|
|
848
|
+
throw new Error(`${keypath} should be a function, if specified`);
|
|
849
|
+
}
|
|
850
|
+
return input;
|
|
851
|
+
});
|
|
852
|
+
}
|
|
853
|
+
|
|
854
|
+
/**
|
|
855
|
+
* @param {string} input
|
|
856
|
+
* @param {string} keypath
|
|
857
|
+
*/
|
|
858
|
+
function assert_string(input, keypath) {
|
|
859
|
+
if (typeof input !== 'string') {
|
|
860
|
+
throw new Error(`${keypath} should be a string, if specified`);
|
|
861
|
+
}
|
|
862
|
+
}
|
|
863
|
+
|
|
864
|
+
/** @param {(keypath?: string) => string} fn */
|
|
865
|
+
function error(fn) {
|
|
866
|
+
return validate(undefined, (input, keypath) => {
|
|
867
|
+
if (input !== undefined) {
|
|
868
|
+
throw new Error(fn(keypath));
|
|
869
|
+
}
|
|
870
|
+
});
|
|
871
|
+
}
|
|
872
|
+
|
|
873
|
+
/**
|
|
874
|
+
* @param {string} cwd
|
|
875
|
+
* @param {import('types/config').ValidatedConfig} config
|
|
876
|
+
*/
|
|
877
|
+
function load_template(cwd, config) {
|
|
878
|
+
const { template } = config.kit.files;
|
|
879
|
+
const relative = path__default.relative(cwd, template);
|
|
880
|
+
|
|
881
|
+
if (fs__default.existsSync(template)) {
|
|
882
|
+
const contents = fs__default.readFileSync(template, 'utf8');
|
|
883
|
+
const expected_tags = ['%svelte.head%', '%svelte.body%'];
|
|
884
|
+
expected_tags.forEach((tag) => {
|
|
885
|
+
if (contents.indexOf(tag) === -1) {
|
|
886
|
+
throw new Error(`${relative} is missing ${tag}`);
|
|
887
|
+
}
|
|
888
|
+
});
|
|
889
|
+
} else {
|
|
890
|
+
throw new Error(`${relative} does not exist`);
|
|
891
|
+
}
|
|
892
|
+
|
|
893
|
+
return fs__default.readFileSync(template, 'utf-8');
|
|
894
|
+
}
|
|
895
|
+
|
|
896
|
+
async function load_config({ cwd = process.cwd() } = {}) {
|
|
897
|
+
const config_file = path__default.join(cwd, 'svelte.config.js');
|
|
898
|
+
|
|
899
|
+
if (!fs__default.existsSync(config_file)) {
|
|
900
|
+
throw new Error(
|
|
901
|
+
'You need to create a svelte.config.js file. See https://kit.svelte.dev/docs#configuration'
|
|
902
|
+
);
|
|
903
|
+
}
|
|
904
|
+
|
|
905
|
+
const config = await import(url.pathToFileURL(config_file).href);
|
|
906
|
+
|
|
907
|
+
const validated = validate_config(config.default);
|
|
908
|
+
|
|
909
|
+
validated.kit.files.assets = path__default.resolve(cwd, validated.kit.files.assets);
|
|
910
|
+
validated.kit.files.hooks = path__default.resolve(cwd, validated.kit.files.hooks);
|
|
911
|
+
validated.kit.files.lib = path__default.resolve(cwd, validated.kit.files.lib);
|
|
912
|
+
validated.kit.files.routes = path__default.resolve(cwd, validated.kit.files.routes);
|
|
913
|
+
validated.kit.files.serviceWorker = path__default.resolve(cwd, validated.kit.files.serviceWorker);
|
|
914
|
+
validated.kit.files.template = path__default.resolve(cwd, validated.kit.files.template);
|
|
915
|
+
|
|
916
|
+
return validated;
|
|
917
|
+
}
|
|
918
|
+
|
|
919
|
+
/**
|
|
920
|
+
* @param {import('types/config').Config} config
|
|
921
|
+
* @returns {import('types/config').ValidatedConfig}
|
|
922
|
+
*/
|
|
923
|
+
function validate_config(config) {
|
|
924
|
+
if (typeof config !== 'object') {
|
|
925
|
+
throw new Error(
|
|
926
|
+
'svelte.config.js must have a configuration object as its default export. See https://kit.svelte.dev/docs#configuration'
|
|
927
|
+
);
|
|
928
|
+
}
|
|
929
|
+
|
|
930
|
+
return options(config, 'config');
|
|
931
|
+
}
|
|
932
|
+
|
|
933
|
+
/**
|
|
934
|
+
* @param {string[]} conflicts - array of conflicts in dotted notation
|
|
935
|
+
* @param {string=} pathPrefix - prepended in front of the path
|
|
936
|
+
* @param {string=} scope - used to prefix the whole error message
|
|
937
|
+
*/
|
|
938
|
+
function print_config_conflicts(conflicts, pathPrefix = '', scope) {
|
|
939
|
+
const prefix = scope ? scope + ': ' : '';
|
|
940
|
+
const log = logger({ verbose: false });
|
|
941
|
+
conflicts.forEach((conflict) => {
|
|
942
|
+
log.error(
|
|
943
|
+
`${prefix}The value for ${pathPrefix}${conflict} specified in svelte.config.js has been ignored. This option is controlled by SvelteKit.`
|
|
944
|
+
);
|
|
945
|
+
});
|
|
946
|
+
}
|
|
947
|
+
|
|
948
|
+
/**
|
|
949
|
+
* @param {unknown} err
|
|
950
|
+
* @return {Error}
|
|
951
|
+
*/
|
|
952
|
+
function coalesce_to_error(err) {
|
|
953
|
+
return err instanceof Error ||
|
|
954
|
+
(err && /** @type {any} */ (err).name && /** @type {any} */ (err).message)
|
|
955
|
+
? /** @type {Error} */ (err)
|
|
956
|
+
: new Error(JSON.stringify(err));
|
|
957
|
+
}
|
|
958
|
+
|
|
959
|
+
/** @param {unknown} e */
|
|
960
|
+
function handle_error(e) {
|
|
961
|
+
const error = coalesce_to_error(e);
|
|
962
|
+
|
|
963
|
+
if (error.name === 'SyntaxError') throw error;
|
|
964
|
+
|
|
965
|
+
console.error($.bold().red(`> ${error.message}`));
|
|
966
|
+
if (error.stack) {
|
|
967
|
+
console.error($.gray(error.stack.split('\n').slice(1).join('\n')));
|
|
968
|
+
}
|
|
969
|
+
|
|
56
970
|
process.exit(1);
|
|
57
971
|
}
|
|
58
972
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
973
|
+
/**
|
|
974
|
+
* @param {number} port
|
|
975
|
+
* @param {boolean} https
|
|
976
|
+
*/
|
|
977
|
+
async function launch(port, https) {
|
|
978
|
+
const { exec } = await import('child_process');
|
|
979
|
+
let cmd = 'open';
|
|
980
|
+
if (process.platform == 'win32') {
|
|
981
|
+
cmd = 'start';
|
|
982
|
+
} else if (process.platform == 'linux') {
|
|
983
|
+
if (/microsoft/i.test(release())) {
|
|
984
|
+
cmd = 'cmd.exe /c start';
|
|
985
|
+
} else {
|
|
986
|
+
cmd = 'xdg-open';
|
|
987
|
+
}
|
|
988
|
+
}
|
|
989
|
+
exec(`${cmd} ${https ? 'https' : 'http'}://localhost:${port}`);
|
|
62
990
|
}
|
|
63
991
|
|
|
64
|
-
const prog =
|
|
992
|
+
const prog = sade('svelte-kit').version('1.0.0-next.253');
|
|
65
993
|
|
|
66
994
|
prog
|
|
67
995
|
.command('dev')
|
|
68
996
|
.describe('Start a development server')
|
|
69
|
-
.option('-p, --port', 'Port'
|
|
70
|
-
.option('-o, --open', 'Open a browser tab'
|
|
71
|
-
.
|
|
72
|
-
|
|
73
|
-
|
|
997
|
+
.option('-p, --port', 'Port')
|
|
998
|
+
.option('-o, --open', 'Open a browser tab')
|
|
999
|
+
.option('--host', 'Host (only use this on trusted networks)')
|
|
1000
|
+
.option('--https', 'Use self-signed HTTPS certificate')
|
|
1001
|
+
.option('-H', 'no longer supported, use --https instead') // TODO remove for 1.0
|
|
1002
|
+
.action(async ({ port, host, https, open, H }) => {
|
|
1003
|
+
try {
|
|
1004
|
+
if (H) throw new Error('-H is no longer supported — use --https instead');
|
|
74
1005
|
|
|
75
|
-
|
|
1006
|
+
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
|
|
1007
|
+
const config = await load_config();
|
|
76
1008
|
|
|
77
|
-
|
|
78
|
-
const watcher = await dev({ port, config });
|
|
1009
|
+
const { dev } = await import('./chunks/index.js');
|
|
79
1010
|
|
|
80
|
-
|
|
81
|
-
process.stdout.write(data);
|
|
82
|
-
});
|
|
1011
|
+
const cwd = process.cwd();
|
|
83
1012
|
|
|
84
|
-
|
|
85
|
-
|
|
1013
|
+
const { address_info, server_config } = await dev({
|
|
1014
|
+
cwd,
|
|
1015
|
+
port,
|
|
1016
|
+
host,
|
|
1017
|
+
https,
|
|
1018
|
+
config
|
|
86
1019
|
});
|
|
87
1020
|
|
|
88
|
-
|
|
89
|
-
|
|
1021
|
+
welcome({
|
|
1022
|
+
port: address_info.port,
|
|
1023
|
+
host: address_info.address,
|
|
1024
|
+
https: !!(https || server_config.https),
|
|
1025
|
+
open: open || !!server_config.open,
|
|
1026
|
+
loose: server_config.fs.strict === false,
|
|
1027
|
+
allow: server_config.fs.allow,
|
|
1028
|
+
cwd
|
|
1029
|
+
});
|
|
90
1030
|
} catch (error) {
|
|
91
1031
|
handle_error(error);
|
|
92
1032
|
}
|
|
@@ -95,55 +1035,153 @@ prog
|
|
|
95
1035
|
prog
|
|
96
1036
|
.command('build')
|
|
97
1037
|
.describe('Create a production build of your app')
|
|
98
|
-
.
|
|
99
|
-
|
|
100
|
-
|
|
1038
|
+
.option('--verbose', 'Log more stuff', false)
|
|
1039
|
+
.action(async ({ verbose }) => {
|
|
1040
|
+
try {
|
|
1041
|
+
process.env.NODE_ENV = process.env.NODE_ENV || 'production';
|
|
1042
|
+
const config = await load_config();
|
|
101
1043
|
|
|
102
|
-
|
|
1044
|
+
const { build } = await import('./chunks/index3.js');
|
|
1045
|
+
const build_data = await build(config);
|
|
103
1046
|
|
|
104
|
-
|
|
105
|
-
|
|
1047
|
+
console.log(
|
|
1048
|
+
`\nRun ${$.bold().cyan('npm run preview')} to preview your production build locally.`
|
|
1049
|
+
);
|
|
1050
|
+
|
|
1051
|
+
if (config.kit.adapter) {
|
|
1052
|
+
const { adapt } = await import('./chunks/index5.js');
|
|
1053
|
+
await adapt(config, build_data, { verbose });
|
|
1054
|
+
|
|
1055
|
+
// this is necessary to close any open db connections, etc
|
|
1056
|
+
process.exit(0);
|
|
1057
|
+
}
|
|
1058
|
+
|
|
1059
|
+
console.log($.bold().yellow('\nNo adapter specified'));
|
|
1060
|
+
|
|
1061
|
+
// prettier-ignore
|
|
1062
|
+
console.log(
|
|
1063
|
+
`See ${$.bold().cyan('https://kit.svelte.dev/docs#adapters')} to learn how to configure your app to run on the platform of your choosing`
|
|
1064
|
+
);
|
|
106
1065
|
} catch (error) {
|
|
107
1066
|
handle_error(error);
|
|
108
1067
|
}
|
|
109
1068
|
});
|
|
110
1069
|
|
|
111
1070
|
prog
|
|
112
|
-
.command('
|
|
1071
|
+
.command('preview')
|
|
113
1072
|
.describe('Serve an already-built app')
|
|
114
1073
|
.option('-p, --port', 'Port', 3000)
|
|
115
1074
|
.option('-o, --open', 'Open a browser tab', false)
|
|
116
|
-
.
|
|
117
|
-
|
|
118
|
-
|
|
1075
|
+
.option('--host', 'Host (only use this on trusted networks)', 'localhost')
|
|
1076
|
+
.option('--https', 'Use self-signed HTTPS certificate', false)
|
|
1077
|
+
.option('-H', 'no longer supported, use --https instead') // TODO remove for 1.0
|
|
1078
|
+
.action(async ({ port, host, https, open, H }) => {
|
|
1079
|
+
try {
|
|
1080
|
+
if (H) throw new Error('-H is no longer supported — use --https instead');
|
|
119
1081
|
|
|
120
|
-
|
|
1082
|
+
await check_port(port);
|
|
121
1083
|
|
|
122
|
-
|
|
123
|
-
|
|
1084
|
+
process.env.NODE_ENV = process.env.NODE_ENV || 'production';
|
|
1085
|
+
const config = await load_config();
|
|
1086
|
+
|
|
1087
|
+
const { preview } = await import('./chunks/index6.js');
|
|
124
1088
|
|
|
125
|
-
|
|
126
|
-
|
|
1089
|
+
await preview({ port, host, config, https });
|
|
1090
|
+
|
|
1091
|
+
welcome({ port, host, https, open });
|
|
127
1092
|
} catch (error) {
|
|
128
1093
|
handle_error(error);
|
|
129
1094
|
}
|
|
130
1095
|
});
|
|
131
1096
|
|
|
132
1097
|
prog
|
|
133
|
-
.command('
|
|
134
|
-
.describe('
|
|
1098
|
+
.command('package')
|
|
1099
|
+
.describe('Create a package')
|
|
1100
|
+
.option('-d, --dir', 'Destination directory', 'package')
|
|
135
1101
|
.action(async () => {
|
|
136
|
-
|
|
137
|
-
|
|
1102
|
+
try {
|
|
1103
|
+
const config = await load_config();
|
|
138
1104
|
|
|
139
|
-
|
|
1105
|
+
const { make_package } = await import('./chunks/index7.js');
|
|
140
1106
|
|
|
141
|
-
|
|
142
|
-
await adapt(config);
|
|
1107
|
+
await make_package(config);
|
|
143
1108
|
} catch (error) {
|
|
144
1109
|
handle_error(error);
|
|
145
1110
|
}
|
|
146
1111
|
});
|
|
147
1112
|
|
|
148
1113
|
prog.parse(process.argv, { unknown: (arg) => `Unknown option: ${arg}` });
|
|
149
|
-
|
|
1114
|
+
|
|
1115
|
+
/** @param {number} port */
|
|
1116
|
+
async function check_port(port) {
|
|
1117
|
+
if (await check(port)) {
|
|
1118
|
+
return;
|
|
1119
|
+
}
|
|
1120
|
+
console.error($.bold().red(`Port ${port} is occupied`));
|
|
1121
|
+
const n = await blame(port);
|
|
1122
|
+
if (n) {
|
|
1123
|
+
// prettier-ignore
|
|
1124
|
+
console.error(
|
|
1125
|
+
`Terminate process ${$.bold(n)} or specify a different port with ${$.bold('--port')}\n`
|
|
1126
|
+
);
|
|
1127
|
+
} else {
|
|
1128
|
+
// prettier-ignore
|
|
1129
|
+
console.error(
|
|
1130
|
+
`Terminate the process occupying the port or specify a different port with ${$.bold('--port')}\n`
|
|
1131
|
+
);
|
|
1132
|
+
}
|
|
1133
|
+
process.exit(1);
|
|
1134
|
+
}
|
|
1135
|
+
|
|
1136
|
+
/**
|
|
1137
|
+
* @param {{
|
|
1138
|
+
* open: boolean;
|
|
1139
|
+
* host: string;
|
|
1140
|
+
* https: boolean;
|
|
1141
|
+
* port: number;
|
|
1142
|
+
* loose?: boolean;
|
|
1143
|
+
* allow?: string[];
|
|
1144
|
+
* cwd?: string;
|
|
1145
|
+
* }} param0
|
|
1146
|
+
*/
|
|
1147
|
+
function welcome({ port, host, https, open, loose, allow, cwd }) {
|
|
1148
|
+
if (open) launch(port, https);
|
|
1149
|
+
|
|
1150
|
+
console.log($.bold().cyan(`\n SvelteKit v${'1.0.0-next.253'}\n`));
|
|
1151
|
+
|
|
1152
|
+
const protocol = https ? 'https:' : 'http:';
|
|
1153
|
+
const exposed = typeof host !== 'undefined' && host !== 'localhost' && host !== '127.0.0.1';
|
|
1154
|
+
|
|
1155
|
+
Object.values(networkInterfaces()).forEach((interfaces) => {
|
|
1156
|
+
if (!interfaces) return;
|
|
1157
|
+
interfaces.forEach((details) => {
|
|
1158
|
+
if (details.family !== 'IPv4') return;
|
|
1159
|
+
|
|
1160
|
+
// prettier-ignore
|
|
1161
|
+
if (details.internal) {
|
|
1162
|
+
console.log(` ${$.gray('local: ')} ${protocol}//${$.bold(`localhost:${port}`)}`);
|
|
1163
|
+
} else {
|
|
1164
|
+
if (details.mac === '00:00:00:00:00:00') return;
|
|
1165
|
+
|
|
1166
|
+
if (exposed) {
|
|
1167
|
+
console.log(` ${$.gray('network:')} ${protocol}//${$.bold(`${details.address}:${port}`)}`);
|
|
1168
|
+
if (loose) {
|
|
1169
|
+
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.')}`);
|
|
1170
|
+
} else if (allow?.length && cwd) {
|
|
1171
|
+
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(', '))}`);
|
|
1172
|
+
}
|
|
1173
|
+
} else {
|
|
1174
|
+
console.log(` ${$.gray('network: not exposed')}`);
|
|
1175
|
+
}
|
|
1176
|
+
}
|
|
1177
|
+
});
|
|
1178
|
+
});
|
|
1179
|
+
|
|
1180
|
+
if (!exposed) {
|
|
1181
|
+
console.log('\n Use --host to expose server to other devices on this network');
|
|
1182
|
+
}
|
|
1183
|
+
|
|
1184
|
+
console.log('\n');
|
|
1185
|
+
}
|
|
1186
|
+
|
|
1187
|
+
export { $, SVELTE_KIT_ASSETS as S, resolve_entry as a, SVELTE_KIT 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, runtime as r, walk as w };
|