@sveltejs/kit 1.0.0-next.393 → 1.0.0-next.396
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/assets/client/start.js +1 -0
- package/assets/env/dynamic/private.js +1 -0
- package/assets/env/dynamic/public.js +1 -0
- package/assets/env-private.js +9 -0
- package/assets/env-public.js +9 -0
- package/assets/server/index.js +4 -1
- package/dist/chunks/error.js +1 -671
- package/dist/chunks/filesystem.js +110 -0
- package/dist/chunks/index.js +574 -15643
- package/dist/chunks/index2.js +15705 -177
- package/dist/chunks/index3.js +218 -0
- package/dist/chunks/sync.js +377 -70
- package/dist/chunks/utils.js +66 -0
- package/dist/chunks/write_tsconfig.js +64 -121
- package/dist/cli.js +8 -6
- package/dist/prerender.js +788 -0
- package/dist/vite.js +188 -973
- package/package.json +1 -1
- package/types/ambient.d.ts +59 -12
- package/types/index.d.ts +8 -0
- package/types/internal.d.ts +8 -0
package/dist/vite.js
CHANGED
|
@@ -1,16 +1,23 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import { a as load_template, $,
|
|
1
|
+
import { fork } from 'node:child_process';
|
|
2
|
+
import fs$1 from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { a as load_template, $, l as load_config } from './chunks/index.js';
|
|
5
5
|
import { svelte } from '@sveltejs/vite-plugin-svelte';
|
|
6
6
|
import * as vite from 'vite';
|
|
7
|
-
import {
|
|
8
|
-
import { p as posixify, m as mkdirp,
|
|
9
|
-
import { g as
|
|
10
|
-
import
|
|
11
|
-
import {
|
|
7
|
+
import { loadEnv } from 'vite';
|
|
8
|
+
import { p as posixify, m as mkdirp, r as rimraf } from './chunks/filesystem.js';
|
|
9
|
+
import { g as get_aliases, r as resolve_entry, s, m as merge_vite_configs, a as get_vite_config, i as init, b as get_env, u as update, p as prevent_illegal_vite_imports, c as parse_route_id, d as all, e as prevent_illegal_rollup_imports } from './chunks/sync.js';
|
|
10
|
+
import * as fs from 'fs';
|
|
11
|
+
import fs__default, { readdirSync, statSync } from 'fs';
|
|
12
|
+
import path__default, { resolve, join, normalize } from 'path';
|
|
13
|
+
import { g as get_runtime_directory, a as get_runtime_prefix, b as get_mime_lookup, l as logger } from './chunks/utils.js';
|
|
12
14
|
import * as qs from 'querystring';
|
|
15
|
+
import { URL as URL$1, pathToFileURL } from 'url';
|
|
13
16
|
import { getRequest, setResponse } from './node.js';
|
|
17
|
+
import { installPolyfills } from './node/polyfills.js';
|
|
18
|
+
import { c as coalesce_to_error } from './chunks/error.js';
|
|
19
|
+
import { fileURLToPath } from 'node:url';
|
|
20
|
+
import './chunks/write_tsconfig.js';
|
|
14
21
|
import 'assert';
|
|
15
22
|
import 'net';
|
|
16
23
|
import 'http';
|
|
@@ -31,151 +38,9 @@ import 'node:zlib';
|
|
|
31
38
|
import 'node:stream';
|
|
32
39
|
import 'node:buffer';
|
|
33
40
|
import 'node:util';
|
|
34
|
-
import 'node:url';
|
|
35
41
|
import 'node:net';
|
|
36
|
-
import 'node:fs';
|
|
37
|
-
import 'node:path';
|
|
38
42
|
import 'crypto';
|
|
39
43
|
|
|
40
|
-
/**
|
|
41
|
-
* @param {import('vite').ResolvedConfig} config
|
|
42
|
-
* @param {import('vite').ConfigEnv} config_env
|
|
43
|
-
* @return {Promise<import('vite').UserConfig>}
|
|
44
|
-
*/
|
|
45
|
-
async function get_vite_config(config, config_env) {
|
|
46
|
-
const loaded = await loadConfigFromFile(
|
|
47
|
-
config_env,
|
|
48
|
-
config.configFile,
|
|
49
|
-
undefined,
|
|
50
|
-
config.logLevel
|
|
51
|
-
);
|
|
52
|
-
|
|
53
|
-
if (!loaded) {
|
|
54
|
-
throw new Error('Could not load Vite config');
|
|
55
|
-
}
|
|
56
|
-
return { ...loaded.config, mode: config_env.mode };
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* @param {...import('vite').UserConfig} configs
|
|
61
|
-
* @returns {import('vite').UserConfig}
|
|
62
|
-
*/
|
|
63
|
-
function merge_vite_configs(...configs) {
|
|
64
|
-
return deep_merge(
|
|
65
|
-
...configs.map((config) => ({
|
|
66
|
-
...config,
|
|
67
|
-
resolve: {
|
|
68
|
-
...config.resolve,
|
|
69
|
-
alias: normalize_alias(config.resolve?.alias || {})
|
|
70
|
-
}
|
|
71
|
-
}))
|
|
72
|
-
);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Takes zero or more objects and returns a new object that has all the values
|
|
77
|
-
* deeply merged together. None of the original objects will be mutated at any
|
|
78
|
-
* level, and the returned object will have no references to the original
|
|
79
|
-
* objects at any depth. If there's a conflict the last one wins, except for
|
|
80
|
-
* arrays which will be combined.
|
|
81
|
-
* @param {...Object} objects
|
|
82
|
-
* @returns {Record<string, any>} the merged object
|
|
83
|
-
*/
|
|
84
|
-
function deep_merge(...objects) {
|
|
85
|
-
const result = {};
|
|
86
|
-
/** @type {string[]} */
|
|
87
|
-
objects.forEach((o) => merge_into(result, o));
|
|
88
|
-
return result;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* normalize kit.vite.resolve.alias as an array
|
|
93
|
-
* @param {import('vite').AliasOptions} o
|
|
94
|
-
* @returns {import('vite').Alias[]}
|
|
95
|
-
*/
|
|
96
|
-
function normalize_alias(o) {
|
|
97
|
-
if (Array.isArray(o)) return o;
|
|
98
|
-
return Object.entries(o).map(([find, replacement]) => ({ find, replacement }));
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Merges b into a, recursively, mutating a.
|
|
103
|
-
* @param {Record<string, any>} a
|
|
104
|
-
* @param {Record<string, any>} b
|
|
105
|
-
*/
|
|
106
|
-
function merge_into(a, b) {
|
|
107
|
-
/**
|
|
108
|
-
* Checks for "plain old Javascript object", typically made as an object
|
|
109
|
-
* literal. Excludes Arrays and built-in types like Buffer.
|
|
110
|
-
* @param {any} x
|
|
111
|
-
*/
|
|
112
|
-
const is_plain_object = (x) => typeof x === 'object' && x.constructor === Object;
|
|
113
|
-
|
|
114
|
-
for (const prop in b) {
|
|
115
|
-
if (is_plain_object(b[prop])) {
|
|
116
|
-
if (!is_plain_object(a[prop])) {
|
|
117
|
-
a[prop] = {};
|
|
118
|
-
}
|
|
119
|
-
merge_into(a[prop], b[prop]);
|
|
120
|
-
} else if (Array.isArray(b[prop])) {
|
|
121
|
-
if (!Array.isArray(a[prop])) {
|
|
122
|
-
a[prop] = [];
|
|
123
|
-
}
|
|
124
|
-
a[prop].push(...b[prop]);
|
|
125
|
-
} else {
|
|
126
|
-
a[prop] = b[prop];
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
/** @param {import('types').ValidatedKitConfig} config */
|
|
132
|
-
function get_aliases(config) {
|
|
133
|
-
/** @type {Record<string, string>} */
|
|
134
|
-
const alias = {
|
|
135
|
-
__GENERATED__: path__default.posix.join(config.outDir, 'generated'),
|
|
136
|
-
$app: `${get_runtime_directory(config)}/app`,
|
|
137
|
-
|
|
138
|
-
// For now, we handle `$lib` specially here rather than make it a default value for
|
|
139
|
-
// `config.kit.alias` since it has special meaning for packaging, etc.
|
|
140
|
-
$lib: config.files.lib
|
|
141
|
-
};
|
|
142
|
-
|
|
143
|
-
for (const [key, value] of Object.entries(config.alias)) {
|
|
144
|
-
alias[key] = path__default.resolve(value);
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
return alias;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
/**
|
|
151
|
-
* Given an entry point like [cwd]/src/hooks, returns a filename like [cwd]/src/hooks.js or [cwd]/src/hooks/index.js
|
|
152
|
-
* @param {string} entry
|
|
153
|
-
* @returns {string|null}
|
|
154
|
-
*/
|
|
155
|
-
function resolve_entry(entry) {
|
|
156
|
-
if (fs__default.existsSync(entry)) {
|
|
157
|
-
const stats = fs__default.statSync(entry);
|
|
158
|
-
if (stats.isDirectory()) {
|
|
159
|
-
return resolve_entry(path__default.join(entry, 'index'));
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
return entry;
|
|
163
|
-
} else {
|
|
164
|
-
const dir = path__default.dirname(entry);
|
|
165
|
-
|
|
166
|
-
if (fs__default.existsSync(dir)) {
|
|
167
|
-
const base = path__default.basename(entry);
|
|
168
|
-
const files = fs__default.readdirSync(dir);
|
|
169
|
-
|
|
170
|
-
const found = files.find((file) => file.replace(/\.[^.]+$/, '') === base);
|
|
171
|
-
|
|
172
|
-
if (found) return path__default.join(dir, found);
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
return null;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
44
|
/**
|
|
180
45
|
* @typedef {import('rollup').RollupOutput} RollupOutput
|
|
181
46
|
* @typedef {import('rollup').OutputChunk} OutputChunk
|
|
@@ -291,9 +156,7 @@ const get_default_config = function ({ config, input, ssr, outDir }) {
|
|
|
291
156
|
__SVELTEKIT_APP_VERSION_POLL_INTERVAL__: JSON.stringify(config.kit.version.pollInterval),
|
|
292
157
|
__SVELTEKIT_DEV__: 'false'
|
|
293
158
|
},
|
|
294
|
-
|
|
295
|
-
// if it happens to be 'public' instead of 'static'
|
|
296
|
-
publicDir: false,
|
|
159
|
+
publicDir: ssr ? false : config.kit.files.assets,
|
|
297
160
|
resolve: {
|
|
298
161
|
alias: get_aliases(config.kit)
|
|
299
162
|
},
|
|
@@ -358,6 +221,8 @@ import root from '__GENERATED__/root.svelte';
|
|
|
358
221
|
import { respond } from '${runtime}/server/index.js';
|
|
359
222
|
import { set_paths, assets, base } from '${runtime}/paths.js';
|
|
360
223
|
import { set_prerendering } from '${runtime}/env.js';
|
|
224
|
+
import { set_private_env } from '${runtime}/env-private.js';
|
|
225
|
+
import { set_public_env } from '${runtime}/env-public.js';
|
|
361
226
|
|
|
362
227
|
const template = ({ head, body, assets, nonce }) => ${s(template)
|
|
363
228
|
.replace('%sveltekit.head%', '" + head + "')
|
|
@@ -409,6 +274,7 @@ export class Server {
|
|
|
409
274
|
default: ${config.kit.prerender.default},
|
|
410
275
|
enabled: ${config.kit.prerender.enabled}
|
|
411
276
|
},
|
|
277
|
+
public_env: {},
|
|
412
278
|
read,
|
|
413
279
|
root,
|
|
414
280
|
service_worker: ${has_service_worker ? "base + '/service-worker.js'" : 'null'},
|
|
@@ -419,6 +285,23 @@ export class Server {
|
|
|
419
285
|
};
|
|
420
286
|
}
|
|
421
287
|
|
|
288
|
+
init({ env }) {
|
|
289
|
+
const entries = Object.entries(env);
|
|
290
|
+
|
|
291
|
+
const prv = Object.fromEntries(Object.entries(env).filter(([k]) => !k.startsWith('${
|
|
292
|
+
config.kit.env.publicPrefix
|
|
293
|
+
}')));
|
|
294
|
+
|
|
295
|
+
const pub = Object.fromEntries(Object.entries(env).filter(([k]) => k.startsWith('${
|
|
296
|
+
config.kit.env.publicPrefix
|
|
297
|
+
}')));
|
|
298
|
+
|
|
299
|
+
set_private_env(prv);
|
|
300
|
+
set_public_env(pub);
|
|
301
|
+
|
|
302
|
+
this.options.public_env = pub;
|
|
303
|
+
}
|
|
304
|
+
|
|
422
305
|
async respond(request, options = {}) {
|
|
423
306
|
if (!(request instanceof Request)) {
|
|
424
307
|
throw new Error('The first argument to server.respond must be a Request object. See https://github.com/sveltejs/kit/pull/3384 for details');
|
|
@@ -708,747 +591,8 @@ async function build_service_worker(
|
|
|
708
591
|
await vite.build(merged_config);
|
|
709
592
|
}
|
|
710
593
|
|
|
711
|
-
const absolute = /^([a-z]+:)?\/?\//;
|
|
712
|
-
const scheme = /^[a-z]+:/;
|
|
713
|
-
|
|
714
|
-
/**
|
|
715
|
-
* @param {string} base
|
|
716
|
-
* @param {string} path
|
|
717
|
-
*/
|
|
718
|
-
function resolve(base, path) {
|
|
719
|
-
if (scheme.test(path)) return path;
|
|
720
|
-
|
|
721
|
-
const base_match = absolute.exec(base);
|
|
722
|
-
const path_match = absolute.exec(path);
|
|
723
|
-
|
|
724
|
-
if (!base_match) {
|
|
725
|
-
throw new Error(`bad base path: "${base}"`);
|
|
726
|
-
}
|
|
727
|
-
|
|
728
|
-
const baseparts = path_match ? [] : base.slice(base_match[0].length).split('/');
|
|
729
|
-
const pathparts = path_match ? path.slice(path_match[0].length).split('/') : path.split('/');
|
|
730
|
-
|
|
731
|
-
baseparts.pop();
|
|
732
|
-
|
|
733
|
-
for (let i = 0; i < pathparts.length; i += 1) {
|
|
734
|
-
const part = pathparts[i];
|
|
735
|
-
if (part === '.') continue;
|
|
736
|
-
else if (part === '..') baseparts.pop();
|
|
737
|
-
else baseparts.push(part);
|
|
738
|
-
}
|
|
739
|
-
|
|
740
|
-
const prefix = (path_match && path_match[0]) || (base_match && base_match[0]) || '';
|
|
741
|
-
|
|
742
|
-
return `${prefix}${baseparts.join('/')}`;
|
|
743
|
-
}
|
|
744
|
-
|
|
745
|
-
/** @param {string} path */
|
|
746
|
-
function is_root_relative(path) {
|
|
747
|
-
return path[0] === '/' && path[1] !== '/';
|
|
748
|
-
}
|
|
749
|
-
|
|
750
|
-
/**
|
|
751
|
-
* @typedef {{
|
|
752
|
-
* fn: () => Promise<any>,
|
|
753
|
-
* fulfil: (value: any) => void,
|
|
754
|
-
* reject: (error: Error) => void
|
|
755
|
-
* }} Task
|
|
756
|
-
*/
|
|
757
|
-
|
|
758
|
-
/** @param {number} concurrency */
|
|
759
|
-
function queue(concurrency) {
|
|
760
|
-
/** @type {Task[]} */
|
|
761
|
-
const tasks = [];
|
|
762
|
-
|
|
763
|
-
let current = 0;
|
|
764
|
-
|
|
765
|
-
/** @type {(value?: any) => void} */
|
|
766
|
-
let fulfil;
|
|
767
|
-
|
|
768
|
-
/** @type {(error: Error) => void} */
|
|
769
|
-
let reject;
|
|
770
|
-
|
|
771
|
-
let closed = false;
|
|
772
|
-
|
|
773
|
-
const done = new Promise((f, r) => {
|
|
774
|
-
fulfil = f;
|
|
775
|
-
reject = r;
|
|
776
|
-
});
|
|
777
|
-
|
|
778
|
-
done.catch(() => {
|
|
779
|
-
// this is necessary in case a catch handler is never added
|
|
780
|
-
// to the done promise by the user
|
|
781
|
-
});
|
|
782
|
-
|
|
783
|
-
function dequeue() {
|
|
784
|
-
if (current < concurrency) {
|
|
785
|
-
const task = tasks.shift();
|
|
786
|
-
|
|
787
|
-
if (task) {
|
|
788
|
-
current += 1;
|
|
789
|
-
const promise = Promise.resolve(task.fn());
|
|
790
|
-
|
|
791
|
-
promise
|
|
792
|
-
.then(task.fulfil, (err) => {
|
|
793
|
-
task.reject(err);
|
|
794
|
-
reject(err);
|
|
795
|
-
})
|
|
796
|
-
.then(() => {
|
|
797
|
-
current -= 1;
|
|
798
|
-
dequeue();
|
|
799
|
-
});
|
|
800
|
-
} else if (current === 0) {
|
|
801
|
-
closed = true;
|
|
802
|
-
fulfil();
|
|
803
|
-
}
|
|
804
|
-
}
|
|
805
|
-
}
|
|
806
|
-
|
|
807
|
-
return {
|
|
808
|
-
/** @param {() => any} fn */
|
|
809
|
-
add: (fn) => {
|
|
810
|
-
if (closed) throw new Error('Cannot add tasks to a queue that has ended');
|
|
811
|
-
|
|
812
|
-
const promise = new Promise((fulfil, reject) => {
|
|
813
|
-
tasks.push({ fn, fulfil, reject });
|
|
814
|
-
});
|
|
815
|
-
|
|
816
|
-
dequeue();
|
|
817
|
-
return promise;
|
|
818
|
-
},
|
|
819
|
-
|
|
820
|
-
done: () => {
|
|
821
|
-
if (current === 0) {
|
|
822
|
-
closed = true;
|
|
823
|
-
fulfil();
|
|
824
|
-
}
|
|
825
|
-
|
|
826
|
-
return done;
|
|
827
|
-
}
|
|
828
|
-
};
|
|
829
|
-
}
|
|
830
|
-
|
|
831
|
-
const DOCTYPE = 'DOCTYPE';
|
|
832
|
-
const CDATA_OPEN = '[CDATA[';
|
|
833
|
-
const CDATA_CLOSE = ']]>';
|
|
834
|
-
const COMMENT_OPEN = '--';
|
|
835
|
-
const COMMENT_CLOSE = '-->';
|
|
836
|
-
|
|
837
|
-
const TAG_OPEN = /[a-zA-Z]/;
|
|
838
|
-
const TAG_CHAR = /[a-zA-Z0-9]/;
|
|
839
|
-
const ATTRIBUTE_NAME = /[^\t\n\f />"'=]/;
|
|
840
|
-
|
|
841
|
-
const WHITESPACE = /[\s\n\r]/;
|
|
842
|
-
|
|
843
|
-
/** @param {string} html */
|
|
844
|
-
function crawl(html) {
|
|
845
|
-
/** @type {string[]} */
|
|
846
|
-
const hrefs = [];
|
|
847
|
-
|
|
848
|
-
let i = 0;
|
|
849
|
-
main: while (i < html.length) {
|
|
850
|
-
const char = html[i];
|
|
851
|
-
|
|
852
|
-
if (char === '<') {
|
|
853
|
-
if (html[i + 1] === '!') {
|
|
854
|
-
i += 2;
|
|
855
|
-
|
|
856
|
-
if (html.slice(i, i + DOCTYPE.length).toUpperCase() === DOCTYPE) {
|
|
857
|
-
i += DOCTYPE.length;
|
|
858
|
-
while (i < html.length) {
|
|
859
|
-
if (html[i++] === '>') {
|
|
860
|
-
continue main;
|
|
861
|
-
}
|
|
862
|
-
}
|
|
863
|
-
}
|
|
864
|
-
|
|
865
|
-
// skip cdata
|
|
866
|
-
if (html.slice(i, i + CDATA_OPEN.length) === CDATA_OPEN) {
|
|
867
|
-
i += CDATA_OPEN.length;
|
|
868
|
-
while (i < html.length) {
|
|
869
|
-
if (html.slice(i, i + CDATA_CLOSE.length) === CDATA_CLOSE) {
|
|
870
|
-
i += CDATA_CLOSE.length;
|
|
871
|
-
continue main;
|
|
872
|
-
}
|
|
873
|
-
|
|
874
|
-
i += 1;
|
|
875
|
-
}
|
|
876
|
-
}
|
|
877
|
-
|
|
878
|
-
// skip comments
|
|
879
|
-
if (html.slice(i, i + COMMENT_OPEN.length) === COMMENT_OPEN) {
|
|
880
|
-
i += COMMENT_OPEN.length;
|
|
881
|
-
while (i < html.length) {
|
|
882
|
-
if (html.slice(i, i + COMMENT_CLOSE.length) === COMMENT_CLOSE) {
|
|
883
|
-
i += COMMENT_CLOSE.length;
|
|
884
|
-
continue main;
|
|
885
|
-
}
|
|
886
|
-
|
|
887
|
-
i += 1;
|
|
888
|
-
}
|
|
889
|
-
}
|
|
890
|
-
}
|
|
891
|
-
|
|
892
|
-
// parse opening tags
|
|
893
|
-
const start = ++i;
|
|
894
|
-
if (TAG_OPEN.test(html[start])) {
|
|
895
|
-
while (i < html.length) {
|
|
896
|
-
if (!TAG_CHAR.test(html[i])) {
|
|
897
|
-
break;
|
|
898
|
-
}
|
|
899
|
-
|
|
900
|
-
i += 1;
|
|
901
|
-
}
|
|
902
|
-
|
|
903
|
-
const tag = html.slice(start, i).toUpperCase();
|
|
904
|
-
|
|
905
|
-
if (tag === 'SCRIPT' || tag === 'STYLE') {
|
|
906
|
-
while (i < html.length) {
|
|
907
|
-
if (
|
|
908
|
-
html[i] === '<' &&
|
|
909
|
-
html[i + 1] === '/' &&
|
|
910
|
-
html.slice(i + 2, i + 2 + tag.length).toUpperCase() === tag
|
|
911
|
-
) {
|
|
912
|
-
continue main;
|
|
913
|
-
}
|
|
914
|
-
|
|
915
|
-
i += 1;
|
|
916
|
-
}
|
|
917
|
-
}
|
|
918
|
-
|
|
919
|
-
let href = '';
|
|
920
|
-
let rel = '';
|
|
921
|
-
|
|
922
|
-
while (i < html.length) {
|
|
923
|
-
const start = i;
|
|
924
|
-
|
|
925
|
-
const char = html[start];
|
|
926
|
-
if (char === '>') break;
|
|
927
|
-
|
|
928
|
-
if (ATTRIBUTE_NAME.test(char)) {
|
|
929
|
-
i += 1;
|
|
930
|
-
|
|
931
|
-
while (i < html.length) {
|
|
932
|
-
if (!ATTRIBUTE_NAME.test(html[i])) {
|
|
933
|
-
break;
|
|
934
|
-
}
|
|
935
|
-
|
|
936
|
-
i += 1;
|
|
937
|
-
}
|
|
938
|
-
|
|
939
|
-
const name = html.slice(start, i).toLowerCase();
|
|
940
|
-
|
|
941
|
-
while (WHITESPACE.test(html[i])) i += 1;
|
|
942
|
-
|
|
943
|
-
if (html[i] === '=') {
|
|
944
|
-
i += 1;
|
|
945
|
-
while (WHITESPACE.test(html[i])) i += 1;
|
|
946
|
-
|
|
947
|
-
let value;
|
|
948
|
-
|
|
949
|
-
if (html[i] === "'" || html[i] === '"') {
|
|
950
|
-
const quote = html[i++];
|
|
951
|
-
|
|
952
|
-
const start = i;
|
|
953
|
-
let escaped = false;
|
|
954
|
-
|
|
955
|
-
while (i < html.length) {
|
|
956
|
-
if (!escaped) {
|
|
957
|
-
const char = html[i];
|
|
958
|
-
|
|
959
|
-
if (html[i] === quote) {
|
|
960
|
-
break;
|
|
961
|
-
}
|
|
962
|
-
|
|
963
|
-
if (char === '\\') {
|
|
964
|
-
escaped = true;
|
|
965
|
-
}
|
|
966
|
-
}
|
|
967
|
-
|
|
968
|
-
i += 1;
|
|
969
|
-
}
|
|
970
|
-
|
|
971
|
-
value = html.slice(start, i);
|
|
972
|
-
} else {
|
|
973
|
-
const start = i;
|
|
974
|
-
while (html[i] !== '>' && !WHITESPACE.test(html[i])) i += 1;
|
|
975
|
-
value = html.slice(start, i);
|
|
976
|
-
|
|
977
|
-
i -= 1;
|
|
978
|
-
}
|
|
979
|
-
|
|
980
|
-
if (name === 'href') {
|
|
981
|
-
href = value;
|
|
982
|
-
} else if (name === 'rel') {
|
|
983
|
-
rel = value;
|
|
984
|
-
} else if (name === 'src') {
|
|
985
|
-
hrefs.push(value);
|
|
986
|
-
} else if (name === 'srcset') {
|
|
987
|
-
const candidates = [];
|
|
988
|
-
let insideURL = true;
|
|
989
|
-
value = value.trim();
|
|
990
|
-
for (let i = 0; i < value.length; i++) {
|
|
991
|
-
if (value[i] === ',' && (!insideURL || (insideURL && value[i + 1] === ' '))) {
|
|
992
|
-
candidates.push(value.slice(0, i));
|
|
993
|
-
value = value.substring(i + 1).trim();
|
|
994
|
-
i = 0;
|
|
995
|
-
insideURL = true;
|
|
996
|
-
} else if (value[i] === ' ') {
|
|
997
|
-
insideURL = false;
|
|
998
|
-
}
|
|
999
|
-
}
|
|
1000
|
-
candidates.push(value);
|
|
1001
|
-
for (const candidate of candidates) {
|
|
1002
|
-
const src = candidate.split(WHITESPACE)[0];
|
|
1003
|
-
hrefs.push(src);
|
|
1004
|
-
}
|
|
1005
|
-
}
|
|
1006
|
-
} else {
|
|
1007
|
-
i -= 1;
|
|
1008
|
-
}
|
|
1009
|
-
}
|
|
1010
|
-
|
|
1011
|
-
i += 1;
|
|
1012
|
-
}
|
|
1013
|
-
|
|
1014
|
-
if (href && !/\bexternal\b/i.test(rel)) {
|
|
1015
|
-
hrefs.push(href);
|
|
1016
|
-
}
|
|
1017
|
-
}
|
|
1018
|
-
}
|
|
1019
|
-
|
|
1020
|
-
i += 1;
|
|
1021
|
-
}
|
|
1022
|
-
|
|
1023
|
-
return hrefs;
|
|
1024
|
-
}
|
|
1025
|
-
|
|
1026
|
-
/**
|
|
1027
|
-
* Inside a script element, only `</script` and `<!--` hold special meaning to the HTML parser.
|
|
1028
|
-
*
|
|
1029
|
-
* The first closes the script element, so everything after is treated as raw HTML.
|
|
1030
|
-
* The second disables further parsing until `-->`, so the script element might be unexpectedly
|
|
1031
|
-
* kept open until until an unrelated HTML comment in the page.
|
|
1032
|
-
*
|
|
1033
|
-
* U+2028 LINE SEPARATOR and U+2029 PARAGRAPH SEPARATOR are escaped for the sake of pre-2018
|
|
1034
|
-
* browsers.
|
|
1035
|
-
*
|
|
1036
|
-
* @see tests for unsafe parsing examples.
|
|
1037
|
-
* @see https://html.spec.whatwg.org/multipage/scripting.html#restrictions-for-contents-of-script-elements
|
|
1038
|
-
* @see https://html.spec.whatwg.org/multipage/syntax.html#cdata-rcdata-restrictions
|
|
1039
|
-
* @see https://html.spec.whatwg.org/multipage/parsing.html#script-data-state
|
|
1040
|
-
* @see https://html.spec.whatwg.org/multipage/parsing.html#script-data-double-escaped-state
|
|
1041
|
-
* @see https://github.com/tc39/proposal-json-superset
|
|
1042
|
-
* @type {Record<string, string>}
|
|
1043
|
-
*/
|
|
1044
|
-
const render_json_payload_script_dict = {
|
|
1045
|
-
'<': '\\u003C',
|
|
1046
|
-
'\u2028': '\\u2028',
|
|
1047
|
-
'\u2029': '\\u2029'
|
|
1048
|
-
};
|
|
1049
|
-
|
|
1050
|
-
new RegExp(
|
|
1051
|
-
`[${Object.keys(render_json_payload_script_dict).join('')}]`,
|
|
1052
|
-
'g'
|
|
1053
|
-
);
|
|
1054
|
-
|
|
1055
|
-
/**
|
|
1056
|
-
* When inside a double-quoted attribute value, only `&` and `"` hold special meaning.
|
|
1057
|
-
* @see https://html.spec.whatwg.org/multipage/parsing.html#attribute-value-(double-quoted)-state
|
|
1058
|
-
* @type {Record<string, string>}
|
|
1059
|
-
*/
|
|
1060
|
-
const escape_html_attr_dict = {
|
|
1061
|
-
'&': '&',
|
|
1062
|
-
'"': '"'
|
|
1063
|
-
};
|
|
1064
|
-
|
|
1065
|
-
const escape_html_attr_regex = new RegExp(
|
|
1066
|
-
// special characters
|
|
1067
|
-
`[${Object.keys(escape_html_attr_dict).join('')}]|` +
|
|
1068
|
-
// high surrogate without paired low surrogate
|
|
1069
|
-
'[\\ud800-\\udbff](?![\\udc00-\\udfff])|' +
|
|
1070
|
-
// a valid surrogate pair, the only match with 2 code units
|
|
1071
|
-
// we match it so that we can match unpaired low surrogates in the same pass
|
|
1072
|
-
// TODO: use lookbehind assertions once they are widely supported: (?<![\ud800-udbff])[\udc00-\udfff]
|
|
1073
|
-
'[\\ud800-\\udbff][\\udc00-\\udfff]|' +
|
|
1074
|
-
// unpaired low surrogate (see previous match)
|
|
1075
|
-
'[\\udc00-\\udfff]',
|
|
1076
|
-
'g'
|
|
1077
|
-
);
|
|
1078
|
-
|
|
1079
|
-
/**
|
|
1080
|
-
* Formats a string to be used as an attribute's value in raw HTML.
|
|
1081
|
-
*
|
|
1082
|
-
* It escapes unpaired surrogates (which are allowed in js strings but invalid in HTML), escapes
|
|
1083
|
-
* characters that are special in attributes, and surrounds the whole string in double-quotes.
|
|
1084
|
-
*
|
|
1085
|
-
* @param {string} str
|
|
1086
|
-
* @returns {string} Escaped string surrounded by double-quotes.
|
|
1087
|
-
* @example const html = `<tag data-value=${escape_html_attr('value')}>...</tag>`;
|
|
1088
|
-
*/
|
|
1089
|
-
function escape_html_attr(str) {
|
|
1090
|
-
const escaped_str = str.replace(escape_html_attr_regex, (match) => {
|
|
1091
|
-
if (match.length === 2) {
|
|
1092
|
-
// valid surrogate pair
|
|
1093
|
-
return match;
|
|
1094
|
-
}
|
|
1095
|
-
|
|
1096
|
-
return escape_html_attr_dict[match] ?? `&#${match.charCodeAt(0)};`;
|
|
1097
|
-
});
|
|
1098
|
-
|
|
1099
|
-
return `"${escaped_str}"`;
|
|
1100
|
-
}
|
|
1101
|
-
|
|
1102
|
-
/**
|
|
1103
|
-
* @typedef {import('types').PrerenderErrorHandler} PrerenderErrorHandler
|
|
1104
|
-
* @typedef {import('types').Logger} Logger
|
|
1105
|
-
*/
|
|
1106
|
-
|
|
1107
|
-
/**
|
|
1108
|
-
* @param {Parameters<PrerenderErrorHandler>[0]} details
|
|
1109
|
-
* @param {import('types').ValidatedKitConfig} config
|
|
1110
|
-
*/
|
|
1111
|
-
function format_error({ status, path, referrer, referenceType }, config) {
|
|
1112
|
-
const message =
|
|
1113
|
-
status === 404 && !path.startsWith(config.paths.base)
|
|
1114
|
-
? `${path} does not begin with \`base\`, which is configured in \`paths.base\` and can be imported from \`$app/paths\``
|
|
1115
|
-
: path;
|
|
1116
|
-
|
|
1117
|
-
return `${status} ${message}${referrer ? ` (${referenceType} from ${referrer})` : ''}`;
|
|
1118
|
-
}
|
|
1119
|
-
|
|
1120
|
-
/**
|
|
1121
|
-
* @param {Logger} log
|
|
1122
|
-
* @param {import('types').ValidatedKitConfig} config
|
|
1123
|
-
* @returns {PrerenderErrorHandler}
|
|
1124
|
-
*/
|
|
1125
|
-
function normalise_error_handler(log, config) {
|
|
1126
|
-
switch (config.prerender.onError) {
|
|
1127
|
-
case 'continue':
|
|
1128
|
-
return (details) => {
|
|
1129
|
-
log.error(format_error(details, config));
|
|
1130
|
-
};
|
|
1131
|
-
case 'fail':
|
|
1132
|
-
return (details) => {
|
|
1133
|
-
throw new Error(format_error(details, config));
|
|
1134
|
-
};
|
|
1135
|
-
default:
|
|
1136
|
-
return config.prerender.onError;
|
|
1137
|
-
}
|
|
1138
|
-
}
|
|
1139
|
-
|
|
1140
|
-
const OK = 2;
|
|
1141
|
-
const REDIRECT = 3;
|
|
1142
|
-
|
|
1143
|
-
/**
|
|
1144
|
-
* @param {{
|
|
1145
|
-
* config: import('types').ValidatedKitConfig;
|
|
1146
|
-
* client_out_dir: string;
|
|
1147
|
-
* manifest_path: string;
|
|
1148
|
-
* log: Logger;
|
|
1149
|
-
* }} opts
|
|
1150
|
-
*/
|
|
1151
|
-
async function prerender({ config, client_out_dir, manifest_path, log }) {
|
|
1152
|
-
/** @type {import('types').Prerendered} */
|
|
1153
|
-
const prerendered = {
|
|
1154
|
-
pages: new Map(),
|
|
1155
|
-
assets: new Map(),
|
|
1156
|
-
redirects: new Map(),
|
|
1157
|
-
paths: []
|
|
1158
|
-
};
|
|
1159
|
-
|
|
1160
|
-
if (!config.prerender.enabled) {
|
|
1161
|
-
return prerendered;
|
|
1162
|
-
}
|
|
1163
|
-
|
|
1164
|
-
installPolyfills();
|
|
1165
|
-
const { fetch } = globalThis;
|
|
1166
|
-
globalThis.fetch = async (info, init) => {
|
|
1167
|
-
/** @type {string} */
|
|
1168
|
-
let url;
|
|
1169
|
-
|
|
1170
|
-
/** @type {RequestInit} */
|
|
1171
|
-
let opts = {};
|
|
1172
|
-
|
|
1173
|
-
if (info instanceof Request) {
|
|
1174
|
-
url = info.url;
|
|
1175
|
-
|
|
1176
|
-
opts = {
|
|
1177
|
-
method: info.method,
|
|
1178
|
-
headers: info.headers,
|
|
1179
|
-
body: info.body,
|
|
1180
|
-
mode: info.mode,
|
|
1181
|
-
credentials: info.credentials,
|
|
1182
|
-
cache: info.cache,
|
|
1183
|
-
redirect: info.redirect,
|
|
1184
|
-
referrer: info.referrer,
|
|
1185
|
-
integrity: info.integrity
|
|
1186
|
-
};
|
|
1187
|
-
} else {
|
|
1188
|
-
url = info.toString();
|
|
1189
|
-
}
|
|
1190
|
-
|
|
1191
|
-
if (url.startsWith(config.prerender.origin + '/')) {
|
|
1192
|
-
const request = new Request(url, opts);
|
|
1193
|
-
const response = await server.respond(request, {
|
|
1194
|
-
getClientAddress,
|
|
1195
|
-
prerendering: {
|
|
1196
|
-
dependencies: new Map()
|
|
1197
|
-
}
|
|
1198
|
-
});
|
|
1199
|
-
|
|
1200
|
-
const decoded = new URL$1(url).pathname;
|
|
1201
|
-
|
|
1202
|
-
save(
|
|
1203
|
-
'dependencies',
|
|
1204
|
-
response,
|
|
1205
|
-
Buffer.from(await response.clone().arrayBuffer()),
|
|
1206
|
-
decoded,
|
|
1207
|
-
encodeURI(decoded),
|
|
1208
|
-
null,
|
|
1209
|
-
'fetched'
|
|
1210
|
-
);
|
|
1211
|
-
|
|
1212
|
-
return response;
|
|
1213
|
-
}
|
|
1214
|
-
|
|
1215
|
-
return fetch(info, init);
|
|
1216
|
-
};
|
|
1217
|
-
|
|
1218
|
-
const server_root = join(config.outDir, 'output');
|
|
1219
|
-
|
|
1220
|
-
/** @type {import('types').ServerModule} */
|
|
1221
|
-
const { Server, override } = await import(pathToFileURL(`${server_root}/server/index.js`).href);
|
|
1222
|
-
|
|
1223
|
-
/** @type {import('types').SSRManifest} */
|
|
1224
|
-
const manifest = (await import(pathToFileURL(`${server_root}/server/manifest.js`).href)).manifest;
|
|
1225
|
-
|
|
1226
|
-
override({
|
|
1227
|
-
paths: config.paths,
|
|
1228
|
-
prerendering: true,
|
|
1229
|
-
read: (file) => readFileSync(join(config.files.assets, file))
|
|
1230
|
-
});
|
|
1231
|
-
|
|
1232
|
-
const server = new Server(manifest);
|
|
1233
|
-
|
|
1234
|
-
const error = normalise_error_handler(log, config);
|
|
1235
|
-
|
|
1236
|
-
const q = queue(config.prerender.concurrency);
|
|
1237
|
-
|
|
1238
|
-
/**
|
|
1239
|
-
* @param {string} path
|
|
1240
|
-
* @param {boolean} is_html
|
|
1241
|
-
*/
|
|
1242
|
-
function output_filename(path, is_html) {
|
|
1243
|
-
const file = path.slice(config.paths.base.length + 1) || 'index.html';
|
|
1244
|
-
|
|
1245
|
-
if (is_html && !file.endsWith('.html')) {
|
|
1246
|
-
return file + (file.endsWith('/') ? 'index.html' : '.html');
|
|
1247
|
-
}
|
|
1248
|
-
|
|
1249
|
-
return file;
|
|
1250
|
-
}
|
|
1251
|
-
|
|
1252
|
-
const files = new Set([
|
|
1253
|
-
...walk(client_out_dir).map(posixify),
|
|
1254
|
-
...(existsSync(config.files.assets) ? walk(config.files.assets).map(posixify) : []) // TODO remove this if we use Vite publicDir option
|
|
1255
|
-
]);
|
|
1256
|
-
const seen = new Set();
|
|
1257
|
-
const written = new Set();
|
|
1258
|
-
|
|
1259
|
-
/**
|
|
1260
|
-
* @param {string | null} referrer
|
|
1261
|
-
* @param {string} decoded
|
|
1262
|
-
* @param {string} [encoded]
|
|
1263
|
-
*/
|
|
1264
|
-
function enqueue(referrer, decoded, encoded) {
|
|
1265
|
-
if (seen.has(decoded)) return;
|
|
1266
|
-
seen.add(decoded);
|
|
1267
|
-
|
|
1268
|
-
const file = decoded.slice(config.paths.base.length + 1);
|
|
1269
|
-
if (files.has(file)) return;
|
|
1270
|
-
|
|
1271
|
-
return q.add(() => visit(decoded, encoded || encodeURI(decoded), referrer));
|
|
1272
|
-
}
|
|
1273
|
-
|
|
1274
|
-
/**
|
|
1275
|
-
* @param {string} decoded
|
|
1276
|
-
* @param {string} encoded
|
|
1277
|
-
* @param {string?} referrer
|
|
1278
|
-
*/
|
|
1279
|
-
async function visit(decoded, encoded, referrer) {
|
|
1280
|
-
if (!decoded.startsWith(config.paths.base)) {
|
|
1281
|
-
error({ status: 404, path: decoded, referrer, referenceType: 'linked' });
|
|
1282
|
-
return;
|
|
1283
|
-
}
|
|
1284
|
-
|
|
1285
|
-
/** @type {Map<string, import('types').PrerenderDependency>} */
|
|
1286
|
-
const dependencies = new Map();
|
|
1287
|
-
|
|
1288
|
-
const response = await server.respond(new Request(config.prerender.origin + encoded), {
|
|
1289
|
-
getClientAddress,
|
|
1290
|
-
prerendering: {
|
|
1291
|
-
dependencies
|
|
1292
|
-
}
|
|
1293
|
-
});
|
|
1294
|
-
|
|
1295
|
-
const body = Buffer.from(await response.arrayBuffer());
|
|
1296
|
-
|
|
1297
|
-
save('pages', response, body, decoded, encoded, referrer, 'linked');
|
|
1298
|
-
|
|
1299
|
-
for (const [dependency_path, result] of dependencies) {
|
|
1300
|
-
// this seems circuitous, but using new URL allows us to not care
|
|
1301
|
-
// whether dependency_path is encoded or not
|
|
1302
|
-
const encoded_dependency_path = new URL$1(dependency_path, 'http://localhost').pathname;
|
|
1303
|
-
const decoded_dependency_path = decodeURI(encoded_dependency_path);
|
|
1304
|
-
|
|
1305
|
-
const body = result.body ?? new Uint8Array(await result.response.arrayBuffer());
|
|
1306
|
-
save(
|
|
1307
|
-
'dependencies',
|
|
1308
|
-
result.response,
|
|
1309
|
-
body,
|
|
1310
|
-
decoded_dependency_path,
|
|
1311
|
-
encoded_dependency_path,
|
|
1312
|
-
decoded,
|
|
1313
|
-
'fetched'
|
|
1314
|
-
);
|
|
1315
|
-
}
|
|
1316
|
-
|
|
1317
|
-
if (config.prerender.crawl && response.headers.get('content-type') === 'text/html') {
|
|
1318
|
-
for (const href of crawl(body.toString())) {
|
|
1319
|
-
if (href.startsWith('data:') || href.startsWith('#')) continue;
|
|
1320
|
-
|
|
1321
|
-
const resolved = resolve(encoded, href);
|
|
1322
|
-
if (!is_root_relative(resolved)) continue;
|
|
1323
|
-
|
|
1324
|
-
const { pathname, search } = new URL$1(resolved, 'http://localhost');
|
|
1325
|
-
|
|
1326
|
-
enqueue(decoded, decodeURI(pathname), pathname);
|
|
1327
|
-
}
|
|
1328
|
-
}
|
|
1329
|
-
}
|
|
1330
|
-
|
|
1331
|
-
/**
|
|
1332
|
-
* @param {'pages' | 'dependencies'} category
|
|
1333
|
-
* @param {Response} response
|
|
1334
|
-
* @param {string | Uint8Array} body
|
|
1335
|
-
* @param {string} decoded
|
|
1336
|
-
* @param {string} encoded
|
|
1337
|
-
* @param {string | null} referrer
|
|
1338
|
-
* @param {'linked' | 'fetched'} referenceType
|
|
1339
|
-
*/
|
|
1340
|
-
function save(category, response, body, decoded, encoded, referrer, referenceType) {
|
|
1341
|
-
const response_type = Math.floor(response.status / 100);
|
|
1342
|
-
const type = /** @type {string} */ (response.headers.get('content-type'));
|
|
1343
|
-
const is_html = response_type === REDIRECT || type === 'text/html';
|
|
1344
|
-
|
|
1345
|
-
const file = output_filename(decoded, is_html);
|
|
1346
|
-
const dest = `${config.outDir}/output/prerendered/${category}/${file}`;
|
|
1347
|
-
|
|
1348
|
-
if (written.has(file)) return;
|
|
1349
|
-
|
|
1350
|
-
if (response_type === REDIRECT) {
|
|
1351
|
-
const location = response.headers.get('location');
|
|
1352
|
-
|
|
1353
|
-
if (location) {
|
|
1354
|
-
const resolved = resolve(encoded, location);
|
|
1355
|
-
if (is_root_relative(resolved)) {
|
|
1356
|
-
enqueue(decoded, decodeURI(resolved), resolved);
|
|
1357
|
-
}
|
|
1358
|
-
|
|
1359
|
-
if (!response.headers.get('x-sveltekit-normalize')) {
|
|
1360
|
-
mkdirp(dirname(dest));
|
|
1361
|
-
|
|
1362
|
-
log.warn(`${response.status} ${decoded} -> ${location}`);
|
|
1363
|
-
|
|
1364
|
-
writeFileSync(
|
|
1365
|
-
dest,
|
|
1366
|
-
`<meta http-equiv="refresh" content=${escape_html_attr(`0;url=${location}`)}>`
|
|
1367
|
-
);
|
|
1368
|
-
|
|
1369
|
-
written.add(file);
|
|
1370
|
-
|
|
1371
|
-
if (!prerendered.redirects.has(decoded)) {
|
|
1372
|
-
prerendered.redirects.set(decoded, {
|
|
1373
|
-
status: response.status,
|
|
1374
|
-
location: resolved
|
|
1375
|
-
});
|
|
1376
|
-
|
|
1377
|
-
prerendered.paths.push(decoded);
|
|
1378
|
-
}
|
|
1379
|
-
}
|
|
1380
|
-
} else {
|
|
1381
|
-
log.warn(`location header missing on redirect received from ${decoded}`);
|
|
1382
|
-
}
|
|
1383
|
-
|
|
1384
|
-
return;
|
|
1385
|
-
}
|
|
1386
|
-
|
|
1387
|
-
if (response.status === 200) {
|
|
1388
|
-
mkdirp(dirname(dest));
|
|
1389
|
-
|
|
1390
|
-
log.info(`${response.status} ${decoded}`);
|
|
1391
|
-
writeFileSync(dest, body);
|
|
1392
|
-
written.add(file);
|
|
1393
|
-
|
|
1394
|
-
if (is_html) {
|
|
1395
|
-
prerendered.pages.set(decoded, {
|
|
1396
|
-
file
|
|
1397
|
-
});
|
|
1398
|
-
} else {
|
|
1399
|
-
prerendered.assets.set(decoded, {
|
|
1400
|
-
type
|
|
1401
|
-
});
|
|
1402
|
-
}
|
|
1403
|
-
|
|
1404
|
-
prerendered.paths.push(decoded);
|
|
1405
|
-
} else if (response_type !== OK) {
|
|
1406
|
-
error({ status: response.status, path: decoded, referrer, referenceType });
|
|
1407
|
-
}
|
|
1408
|
-
}
|
|
1409
|
-
|
|
1410
|
-
if (config.prerender.enabled) {
|
|
1411
|
-
for (const entry of config.prerender.entries) {
|
|
1412
|
-
if (entry === '*') {
|
|
1413
|
-
/** @type {import('types').ManifestData} */
|
|
1414
|
-
const { routes } = (await import(pathToFileURL(manifest_path).href)).manifest._;
|
|
1415
|
-
const entries = routes
|
|
1416
|
-
.map((route) => (route.type === 'page' ? route.path : ''))
|
|
1417
|
-
.filter(Boolean);
|
|
1418
|
-
|
|
1419
|
-
for (const entry of entries) {
|
|
1420
|
-
enqueue(null, config.paths.base + entry); // TODO can we pre-normalize these?
|
|
1421
|
-
}
|
|
1422
|
-
} else {
|
|
1423
|
-
enqueue(null, config.paths.base + entry);
|
|
1424
|
-
}
|
|
1425
|
-
}
|
|
1426
|
-
|
|
1427
|
-
await q.done();
|
|
1428
|
-
}
|
|
1429
|
-
|
|
1430
|
-
const rendered = await server.respond(new Request(config.prerender.origin + '/[fallback]'), {
|
|
1431
|
-
getClientAddress,
|
|
1432
|
-
prerendering: {
|
|
1433
|
-
fallback: true,
|
|
1434
|
-
dependencies: new Map()
|
|
1435
|
-
}
|
|
1436
|
-
});
|
|
1437
|
-
|
|
1438
|
-
const file = `${config.outDir}/output/prerendered/fallback.html`;
|
|
1439
|
-
mkdirp(dirname(file));
|
|
1440
|
-
writeFileSync(file, await rendered.text());
|
|
1441
|
-
|
|
1442
|
-
return prerendered;
|
|
1443
|
-
}
|
|
1444
|
-
|
|
1445
|
-
/** @return {string} */
|
|
1446
|
-
function getClientAddress() {
|
|
1447
|
-
throw new Error('Cannot read clientAddress during prerendering');
|
|
1448
|
-
}
|
|
1449
|
-
|
|
1450
594
|
function totalist(dir, callback, pre='') {
|
|
1451
|
-
dir = resolve
|
|
595
|
+
dir = resolve('.', dir);
|
|
1452
596
|
let arr = readdirSync(dir);
|
|
1453
597
|
let i=0, abs, stats;
|
|
1454
598
|
for (; i < arr.length; i++) {
|
|
@@ -2022,7 +1166,7 @@ function toHeaders(name, stats, isEtag) {
|
|
|
2022
1166
|
}
|
|
2023
1167
|
|
|
2024
1168
|
function sirv (dir, opts={}) {
|
|
2025
|
-
dir = resolve
|
|
1169
|
+
dir = resolve(dir || '.');
|
|
2026
1170
|
|
|
2027
1171
|
let isNotFound = opts.onNoMatch || is404;
|
|
2028
1172
|
let setHeaders = opts.setHeaders || noop;
|
|
@@ -2113,12 +1257,13 @@ const cwd$1 = process.cwd();
|
|
|
2113
1257
|
* @param {import('vite').ViteDevServer} vite
|
|
2114
1258
|
* @param {import('vite').ResolvedConfig} vite_config
|
|
2115
1259
|
* @param {import('types').ValidatedConfig} svelte_config
|
|
1260
|
+
* @param {Set<string>} illegal_imports
|
|
2116
1261
|
* @return {Promise<Promise<() => void>>}
|
|
2117
1262
|
*/
|
|
2118
|
-
async function dev(vite, vite_config, svelte_config) {
|
|
1263
|
+
async function dev(vite, vite_config, svelte_config, illegal_imports) {
|
|
2119
1264
|
installPolyfills();
|
|
2120
1265
|
|
|
2121
|
-
init(svelte_config);
|
|
1266
|
+
init(svelte_config, vite_config.mode);
|
|
2122
1267
|
|
|
2123
1268
|
const runtime = get_runtime_prefix(svelte_config.kit);
|
|
2124
1269
|
|
|
@@ -2149,6 +1294,11 @@ async function dev(vite, vite_config, svelte_config) {
|
|
|
2149
1294
|
await vite.ssrLoadModule(url)
|
|
2150
1295
|
);
|
|
2151
1296
|
|
|
1297
|
+
const node = await vite.moduleGraph.getModuleByUrl(url);
|
|
1298
|
+
if (!node) throw new Error(`Could not find node for ${url}`);
|
|
1299
|
+
|
|
1300
|
+
prevent_illegal_vite_imports(node, illegal_imports, svelte_config.kit.outDir);
|
|
1301
|
+
|
|
2152
1302
|
return {
|
|
2153
1303
|
module,
|
|
2154
1304
|
index,
|
|
@@ -2157,10 +1307,6 @@ async function dev(vite, vite_config, svelte_config) {
|
|
|
2157
1307
|
stylesheets: [],
|
|
2158
1308
|
// in dev we inline all styles to avoid FOUC
|
|
2159
1309
|
inline_styles: async () => {
|
|
2160
|
-
const node = await vite.moduleGraph.getModuleByUrl(url);
|
|
2161
|
-
|
|
2162
|
-
if (!node) throw new Error(`Could not find node for ${url}`);
|
|
2163
|
-
|
|
2164
1310
|
const deps = new Set();
|
|
2165
1311
|
await find_deps(vite, node, deps);
|
|
2166
1312
|
|
|
@@ -2269,37 +1415,50 @@ async function dev(vite, vite_config, svelte_config) {
|
|
|
2269
1415
|
extensions: []
|
|
2270
1416
|
});
|
|
2271
1417
|
|
|
1418
|
+
vite.middlewares.use(async (req, res, next) => {
|
|
1419
|
+
try {
|
|
1420
|
+
const base = `${vite.config.server.https ? 'https' : 'http'}://${
|
|
1421
|
+
req.headers[':authority'] || req.headers.host
|
|
1422
|
+
}`;
|
|
1423
|
+
|
|
1424
|
+
const decoded = decodeURI(new URL$1(base + req.url).pathname);
|
|
1425
|
+
|
|
1426
|
+
if (decoded.startsWith(assets)) {
|
|
1427
|
+
const pathname = decoded.slice(assets.length);
|
|
1428
|
+
const file = svelte_config.kit.files.assets + pathname;
|
|
1429
|
+
|
|
1430
|
+
if (fs__default.existsSync(file) && !fs__default.statSync(file).isDirectory()) {
|
|
1431
|
+
if (has_correct_case(file, svelte_config.kit.files.assets)) {
|
|
1432
|
+
req.url = encodeURI(pathname); // don't need query/hash
|
|
1433
|
+
asset_server(req, res);
|
|
1434
|
+
return;
|
|
1435
|
+
}
|
|
1436
|
+
}
|
|
1437
|
+
}
|
|
1438
|
+
|
|
1439
|
+
next();
|
|
1440
|
+
} catch (e) {
|
|
1441
|
+
const error = coalesce_to_error(e);
|
|
1442
|
+
res.statusCode = 500;
|
|
1443
|
+
res.end(fix_stack_trace(error));
|
|
1444
|
+
}
|
|
1445
|
+
});
|
|
1446
|
+
|
|
2272
1447
|
return () => {
|
|
2273
1448
|
const serve_static_middleware = vite.middlewares.stack.find(
|
|
2274
1449
|
(middleware) =>
|
|
2275
1450
|
/** @type {function} */ (middleware.handle).name === 'viteServeStaticMiddleware'
|
|
2276
1451
|
);
|
|
2277
1452
|
|
|
2278
|
-
|
|
1453
|
+
remove_static_middlewares(vite.middlewares);
|
|
2279
1454
|
|
|
2280
1455
|
vite.middlewares.use(async (req, res) => {
|
|
2281
1456
|
try {
|
|
2282
|
-
if (!req.url || !req.method) throw new Error('Incomplete request');
|
|
2283
|
-
|
|
2284
1457
|
const base = `${vite.config.server.https ? 'https' : 'http'}://${
|
|
2285
1458
|
req.headers[':authority'] || req.headers.host
|
|
2286
1459
|
}`;
|
|
2287
1460
|
|
|
2288
1461
|
const decoded = decodeURI(new URL$1(base + req.url).pathname);
|
|
2289
|
-
|
|
2290
|
-
if (decoded.startsWith(assets)) {
|
|
2291
|
-
const pathname = decoded.slice(assets.length);
|
|
2292
|
-
const file = svelte_config.kit.files.assets + pathname;
|
|
2293
|
-
|
|
2294
|
-
if (fs__default.existsSync(file) && !fs__default.statSync(file).isDirectory()) {
|
|
2295
|
-
if (has_correct_case(file, svelte_config.kit.files.assets)) {
|
|
2296
|
-
req.url = encodeURI(pathname); // don't need query/hash
|
|
2297
|
-
asset_server(req, res);
|
|
2298
|
-
return;
|
|
2299
|
-
}
|
|
2300
|
-
}
|
|
2301
|
-
}
|
|
2302
|
-
|
|
2303
1462
|
const file = posixify(path__default.resolve(decoded.slice(1)));
|
|
2304
1463
|
const is_file = fs__default.existsSync(file) && !fs__default.statSync(file).isDirectory();
|
|
2305
1464
|
const allowed =
|
|
@@ -2324,6 +1483,17 @@ async function dev(vite, vite_config, svelte_config) {
|
|
|
2324
1483
|
? await vite.ssrLoadModule(`/${svelte_config.kit.files.hooks}`)
|
|
2325
1484
|
: {};
|
|
2326
1485
|
|
|
1486
|
+
const runtime_base = true
|
|
1487
|
+
? `/${posixify(path__default.relative(cwd$1, `${svelte_config.kit.outDir}/runtime`))}`
|
|
1488
|
+
: `/@fs${runtime}`;
|
|
1489
|
+
|
|
1490
|
+
const { set_private_env } = await vite.ssrLoadModule(`${runtime_base}/env-private.js`);
|
|
1491
|
+
const { set_public_env } = await vite.ssrLoadModule(`${runtime_base}/env-public.js`);
|
|
1492
|
+
|
|
1493
|
+
const env = get_env(vite_config.mode, svelte_config.kit.env.publicPrefix);
|
|
1494
|
+
set_private_env(env.private);
|
|
1495
|
+
set_public_env(env.public);
|
|
1496
|
+
|
|
2327
1497
|
const handle = user_hooks.handle || (({ event, resolve }) => resolve(event));
|
|
2328
1498
|
|
|
2329
1499
|
/** @type {import('types').Hooks} */
|
|
@@ -2364,11 +1534,7 @@ async function dev(vite, vite_config, svelte_config) {
|
|
|
2364
1534
|
`/${posixify(path__default.relative(cwd$1, `${svelte_config.kit.outDir}/generated/root.svelte`))}`
|
|
2365
1535
|
);
|
|
2366
1536
|
|
|
2367
|
-
const paths = await vite.ssrLoadModule(
|
|
2368
|
-
true
|
|
2369
|
-
? `/${posixify(path__default.relative(cwd$1, `${svelte_config.kit.outDir}/runtime/paths.js`))}`
|
|
2370
|
-
: `/@fs${runtime}/paths.js`
|
|
2371
|
-
);
|
|
1537
|
+
const paths = await vite.ssrLoadModule(`${runtime_base}/paths.js`);
|
|
2372
1538
|
|
|
2373
1539
|
paths.set_paths({
|
|
2374
1540
|
base: svelte_config.kit.paths.base,
|
|
@@ -2427,6 +1593,7 @@ async function dev(vite, vite_config, svelte_config) {
|
|
|
2427
1593
|
default: svelte_config.kit.prerender.default,
|
|
2428
1594
|
enabled: svelte_config.kit.prerender.enabled
|
|
2429
1595
|
},
|
|
1596
|
+
public_env: env.public,
|
|
2430
1597
|
read: (file) => fs__default.readFileSync(path__default.join(svelte_config.kit.files.assets, file)),
|
|
2431
1598
|
root,
|
|
2432
1599
|
router: svelte_config.kit.browser.router,
|
|
@@ -2478,11 +1645,15 @@ function not_found(res, message = 'Not found') {
|
|
|
2478
1645
|
/**
|
|
2479
1646
|
* @param {import('connect').Server} server
|
|
2480
1647
|
*/
|
|
2481
|
-
function
|
|
2482
|
-
|
|
1648
|
+
function remove_static_middlewares(server) {
|
|
1649
|
+
// We don't use viteServePublicMiddleware because of the following issues:
|
|
1650
|
+
// https://github.com/vitejs/vite/issues/9260
|
|
1651
|
+
// https://github.com/vitejs/vite/issues/9236
|
|
1652
|
+
// https://github.com/vitejs/vite/issues/9234
|
|
1653
|
+
const static_middlewares = ['viteServePublicMiddleware', 'viteServeStaticMiddleware'];
|
|
2483
1654
|
for (let i = server.stack.length - 1; i > 0; i--) {
|
|
2484
|
-
// @ts-expect-error using internals
|
|
2485
|
-
if (
|
|
1655
|
+
// @ts-expect-error using internals
|
|
1656
|
+
if (static_middlewares.includes(server.stack[i].handle.name)) {
|
|
2486
1657
|
server.stack.splice(i, 1);
|
|
2487
1658
|
}
|
|
2488
1659
|
}
|
|
@@ -2677,20 +1848,22 @@ function generate_manifest({ build_data, relative_path, routes, format = 'esm' }
|
|
|
2677
1848
|
* middlewares: import('connect').Server;
|
|
2678
1849
|
* httpServer: import('http').Server;
|
|
2679
1850
|
* }} vite
|
|
2680
|
-
* @param {import('
|
|
2681
|
-
* @param {'
|
|
1851
|
+
* @param {import('vite').ResolvedConfig} vite_config
|
|
1852
|
+
* @param {import('types').ValidatedConfig} svelte_config
|
|
2682
1853
|
*/
|
|
2683
|
-
async function preview(vite,
|
|
1854
|
+
async function preview(vite, vite_config, svelte_config) {
|
|
2684
1855
|
installPolyfills();
|
|
2685
1856
|
|
|
2686
|
-
const { paths } =
|
|
1857
|
+
const { paths } = svelte_config.kit;
|
|
2687
1858
|
const base = paths.base;
|
|
2688
1859
|
const assets = paths.assets ? SVELTE_KIT_ASSETS : paths.base;
|
|
2689
1860
|
|
|
1861
|
+
const protocol = vite_config.preview.https ? 'https' : 'http';
|
|
1862
|
+
|
|
2690
1863
|
const etag = `"${Date.now()}"`;
|
|
2691
1864
|
|
|
2692
|
-
const index_file = join(
|
|
2693
|
-
const manifest_file = join(
|
|
1865
|
+
const index_file = join(svelte_config.kit.outDir, 'output/server/index.js');
|
|
1866
|
+
const manifest_file = join(svelte_config.kit.outDir, 'output/server/manifest.js');
|
|
2694
1867
|
|
|
2695
1868
|
/** @type {import('types').ServerModule} */
|
|
2696
1869
|
const { Server, override } = await import(pathToFileURL(index_file).href);
|
|
@@ -2700,23 +1873,23 @@ async function preview(vite, config, protocol) {
|
|
|
2700
1873
|
paths: { base, assets },
|
|
2701
1874
|
prerendering: false,
|
|
2702
1875
|
protocol,
|
|
2703
|
-
read: (file) => fs__default.readFileSync(join(
|
|
1876
|
+
read: (file) => fs__default.readFileSync(join(svelte_config.kit.files.assets, file))
|
|
2704
1877
|
});
|
|
2705
1878
|
|
|
2706
1879
|
const server = new Server(manifest);
|
|
1880
|
+
server.init({
|
|
1881
|
+
env: loadEnv(vite_config.mode, process.cwd(), '')
|
|
1882
|
+
});
|
|
2707
1883
|
|
|
2708
1884
|
return () => {
|
|
2709
|
-
//
|
|
2710
|
-
vite.middlewares.use(scoped(assets, mutable(config.kit.files.assets)));
|
|
2711
|
-
|
|
2712
|
-
// immutable generated client assets
|
|
1885
|
+
// generated client assets and the contents of `static`
|
|
2713
1886
|
vite.middlewares.use(
|
|
2714
1887
|
scoped(
|
|
2715
1888
|
assets,
|
|
2716
|
-
sirv(join(
|
|
1889
|
+
sirv(join(svelte_config.kit.outDir, 'output/client'), {
|
|
2717
1890
|
setHeaders: (res, pathname) => {
|
|
2718
|
-
// only apply to
|
|
2719
|
-
if (pathname.startsWith(`/${
|
|
1891
|
+
// only apply to immutable directory, not e.g. version.json
|
|
1892
|
+
if (pathname.startsWith(`/${svelte_config.kit.appDir}/immutable`)) {
|
|
2720
1893
|
res.setHeader('cache-control', 'public,max-age=31536000,immutable');
|
|
2721
1894
|
}
|
|
2722
1895
|
}
|
|
@@ -2738,7 +1911,7 @@ async function preview(vite, config, protocol) {
|
|
|
2738
1911
|
|
|
2739
1912
|
// prerendered dependencies
|
|
2740
1913
|
vite.middlewares.use(
|
|
2741
|
-
scoped(base, mutable(join(
|
|
1914
|
+
scoped(base, mutable(join(svelte_config.kit.outDir, 'output/prerendered/dependencies')))
|
|
2742
1915
|
);
|
|
2743
1916
|
|
|
2744
1917
|
// prerendered pages (we can't just use sirv because we need to
|
|
@@ -2762,7 +1935,7 @@ async function preview(vite, config, protocol) {
|
|
|
2762
1935
|
// only treat this as a page if it doesn't include an extension
|
|
2763
1936
|
if (pathname === '/' || /\/[^./]+\/?$/.test(pathname)) {
|
|
2764
1937
|
const file = join(
|
|
2765
|
-
|
|
1938
|
+
svelte_config.kit.outDir,
|
|
2766
1939
|
'output/prerendered/pages' +
|
|
2767
1940
|
pathname +
|
|
2768
1941
|
(pathname.endsWith('/') ? 'index.html' : '.html')
|
|
@@ -2820,7 +1993,7 @@ const mutable = (dir) =>
|
|
|
2820
1993
|
etag: true,
|
|
2821
1994
|
maxAge: 0
|
|
2822
1995
|
})
|
|
2823
|
-
: (
|
|
1996
|
+
: (_req, _res, next) => next();
|
|
2824
1997
|
|
|
2825
1998
|
/**
|
|
2826
1999
|
* @param {string} scope
|
|
@@ -2928,6 +2101,9 @@ function kit() {
|
|
|
2928
2101
|
/** @type {import('types').BuildData} */
|
|
2929
2102
|
let build_data;
|
|
2930
2103
|
|
|
2104
|
+
/** @type {Set<string>} */
|
|
2105
|
+
let illegal_imports;
|
|
2106
|
+
|
|
2931
2107
|
/** @type {string | undefined} */
|
|
2932
2108
|
let deferred_warning;
|
|
2933
2109
|
|
|
@@ -2954,12 +2130,12 @@ function kit() {
|
|
|
2954
2130
|
// for everything regardless — but it means that entry chunks reflect
|
|
2955
2131
|
// their location in the source code, which is helpful for debugging
|
|
2956
2132
|
manifest_data.components.forEach((file) => {
|
|
2957
|
-
const resolved =
|
|
2958
|
-
const relative = decodeURIComponent(
|
|
2133
|
+
const resolved = path.resolve(cwd, file);
|
|
2134
|
+
const relative = decodeURIComponent(path.relative(svelte_config.kit.files.routes, resolved));
|
|
2959
2135
|
|
|
2960
2136
|
const name = relative.startsWith('..')
|
|
2961
|
-
?
|
|
2962
|
-
: posixify(
|
|
2137
|
+
? path.basename(file)
|
|
2138
|
+
: posixify(path.join('pages', relative));
|
|
2963
2139
|
input[name] = resolved;
|
|
2964
2140
|
});
|
|
2965
2141
|
|
|
@@ -2978,11 +2154,11 @@ function kit() {
|
|
|
2978
2154
|
function client_build_info(assets, chunks) {
|
|
2979
2155
|
/** @type {import('vite').Manifest} */
|
|
2980
2156
|
const vite_manifest = JSON.parse(
|
|
2981
|
-
|
|
2157
|
+
fs$1.readFileSync(`${paths.client_out_dir}/manifest.json`, 'utf-8')
|
|
2982
2158
|
);
|
|
2983
2159
|
|
|
2984
2160
|
const entry_id = posixify(
|
|
2985
|
-
|
|
2161
|
+
path.relative(cwd, `${get_runtime_directory(svelte_config.kit)}/client/start.js`)
|
|
2986
2162
|
);
|
|
2987
2163
|
|
|
2988
2164
|
return {
|
|
@@ -3014,8 +2190,13 @@ function kit() {
|
|
|
3014
2190
|
client_out_dir: `${svelte_config.kit.outDir}/output/client/`
|
|
3015
2191
|
};
|
|
3016
2192
|
|
|
2193
|
+
illegal_imports = new Set([
|
|
2194
|
+
`${svelte_config.kit.outDir}/runtime/env/dynamic/private.js`,
|
|
2195
|
+
`${svelte_config.kit.outDir}/runtime/env/static/private.js`
|
|
2196
|
+
]);
|
|
2197
|
+
|
|
3017
2198
|
if (is_build) {
|
|
3018
|
-
manifest_data = all(svelte_config).manifest_data;
|
|
2199
|
+
manifest_data = all(svelte_config, config_env.mode).manifest_data;
|
|
3019
2200
|
|
|
3020
2201
|
const new_config = vite_client_build_config();
|
|
3021
2202
|
|
|
@@ -3041,6 +2222,7 @@ function kit() {
|
|
|
3041
2222
|
__SVELTEKIT_DEV__: 'true',
|
|
3042
2223
|
__SVELTEKIT_APP_VERSION_POLL_INTERVAL__: '0'
|
|
3043
2224
|
},
|
|
2225
|
+
publicDir: svelte_config.kit.files.assets,
|
|
3044
2226
|
resolve: {
|
|
3045
2227
|
alias: get_aliases(svelte_config.kit)
|
|
3046
2228
|
},
|
|
@@ -3052,9 +2234,9 @@ function kit() {
|
|
|
3052
2234
|
svelte_config.kit.files.lib,
|
|
3053
2235
|
svelte_config.kit.files.routes,
|
|
3054
2236
|
svelte_config.kit.outDir,
|
|
3055
|
-
|
|
3056
|
-
|
|
3057
|
-
|
|
2237
|
+
path.resolve(cwd, 'src'),
|
|
2238
|
+
path.resolve(cwd, 'node_modules'),
|
|
2239
|
+
path.resolve(vite.searchForWorkspaceRoot(cwd), 'node_modules')
|
|
3058
2240
|
])
|
|
3059
2241
|
]
|
|
3060
2242
|
},
|
|
@@ -3100,11 +2282,26 @@ function kit() {
|
|
|
3100
2282
|
* then use this hook to kick off builds for the server and service worker.
|
|
3101
2283
|
*/
|
|
3102
2284
|
async writeBundle(_options, bundle) {
|
|
2285
|
+
for (const file of manifest_data.components) {
|
|
2286
|
+
const id = path.resolve(file);
|
|
2287
|
+
const node = this.getModuleInfo(id);
|
|
2288
|
+
|
|
2289
|
+
if (node) {
|
|
2290
|
+
prevent_illegal_rollup_imports(
|
|
2291
|
+
this.getModuleInfo.bind(this),
|
|
2292
|
+
node,
|
|
2293
|
+
illegal_imports,
|
|
2294
|
+
svelte_config.kit.outDir
|
|
2295
|
+
);
|
|
2296
|
+
}
|
|
2297
|
+
}
|
|
2298
|
+
|
|
2299
|
+
const verbose = vite_config.logLevel === 'info';
|
|
3103
2300
|
log = logger({
|
|
3104
|
-
verbose
|
|
2301
|
+
verbose
|
|
3105
2302
|
});
|
|
3106
2303
|
|
|
3107
|
-
|
|
2304
|
+
fs$1.writeFileSync(
|
|
3108
2305
|
`${paths.client_out_dir}/${svelte_config.kit.appDir}/version.json`,
|
|
3109
2306
|
JSON.stringify({ version: svelte_config.kit.version.name })
|
|
3110
2307
|
);
|
|
@@ -3136,7 +2333,7 @@ function kit() {
|
|
|
3136
2333
|
};
|
|
3137
2334
|
|
|
3138
2335
|
const manifest_path = `${paths.output_dir}/server/manifest.js`;
|
|
3139
|
-
|
|
2336
|
+
fs$1.writeFileSync(
|
|
3140
2337
|
manifest_path,
|
|
3141
2338
|
`export const manifest = ${generate_manifest({
|
|
3142
2339
|
build_data,
|
|
@@ -3145,14 +2342,39 @@ function kit() {
|
|
|
3145
2342
|
})};\n`
|
|
3146
2343
|
);
|
|
3147
2344
|
|
|
3148
|
-
process.env.SVELTEKIT_SERVER_BUILD_COMPLETED = 'true';
|
|
3149
2345
|
log.info('Prerendering');
|
|
2346
|
+
await new Promise((fulfil, reject) => {
|
|
2347
|
+
const results_path = `${svelte_config.kit.outDir}/generated/prerendered.json`;
|
|
2348
|
+
|
|
2349
|
+
// do prerendering in a subprocess so any dangling stuff gets killed upon completion
|
|
2350
|
+
const script = fileURLToPath(
|
|
2351
|
+
new URL(
|
|
2352
|
+
'./prerender.js' ,
|
|
2353
|
+
import.meta.url
|
|
2354
|
+
)
|
|
2355
|
+
);
|
|
3150
2356
|
|
|
3151
|
-
|
|
3152
|
-
|
|
3153
|
-
|
|
3154
|
-
|
|
3155
|
-
|
|
2357
|
+
const child = fork(
|
|
2358
|
+
script,
|
|
2359
|
+
[vite_config.build.outDir, results_path, manifest_path, '' + verbose],
|
|
2360
|
+
{
|
|
2361
|
+
stdio: 'inherit'
|
|
2362
|
+
}
|
|
2363
|
+
);
|
|
2364
|
+
|
|
2365
|
+
child.on('exit', (code) => {
|
|
2366
|
+
if (code) {
|
|
2367
|
+
reject(new Error(`Prerendering failed with code ${code}`));
|
|
2368
|
+
} else {
|
|
2369
|
+
prerendered = JSON.parse(fs$1.readFileSync(results_path, 'utf8'), (key, value) => {
|
|
2370
|
+
if (key === 'pages' || key === 'assets' || key === 'redirects') {
|
|
2371
|
+
return new Map(value);
|
|
2372
|
+
}
|
|
2373
|
+
return value;
|
|
2374
|
+
});
|
|
2375
|
+
fulfil(undefined);
|
|
2376
|
+
}
|
|
2377
|
+
});
|
|
3156
2378
|
});
|
|
3157
2379
|
|
|
3158
2380
|
if (options.service_worker_entry_file) {
|
|
@@ -3183,7 +2405,7 @@ function kit() {
|
|
|
3183
2405
|
}
|
|
3184
2406
|
|
|
3185
2407
|
if (svelte_config.kit.adapter) {
|
|
3186
|
-
const { adapt } = await import('./chunks/
|
|
2408
|
+
const { adapt } = await import('./chunks/index3.js');
|
|
3187
2409
|
await adapt(svelte_config, build_data, prerendered, { log });
|
|
3188
2410
|
} else {
|
|
3189
2411
|
console.log($.bold().yellow('\nNo adapter specified'));
|
|
@@ -3192,13 +2414,6 @@ function kit() {
|
|
|
3192
2414
|
`See ${$.bold().cyan('https://kit.svelte.dev/docs/adapters')} to learn how to configure your app to run on the platform of your choosing`
|
|
3193
2415
|
);
|
|
3194
2416
|
}
|
|
3195
|
-
|
|
3196
|
-
if (svelte_config.kit.prerender.enabled) {
|
|
3197
|
-
// this is necessary to close any open db connections, etc.
|
|
3198
|
-
// TODO: prerender in a subprocess so we can exit in isolation and then remove this
|
|
3199
|
-
// https://github.com/sveltejs/kit/issues/5306
|
|
3200
|
-
process.exit(0);
|
|
3201
|
-
}
|
|
3202
2417
|
},
|
|
3203
2418
|
|
|
3204
2419
|
/**
|
|
@@ -3214,7 +2429,7 @@ function kit() {
|
|
|
3214
2429
|
if (deferred_warning) console.error('\n' + deferred_warning);
|
|
3215
2430
|
};
|
|
3216
2431
|
|
|
3217
|
-
return await dev(vite, vite_config, svelte_config);
|
|
2432
|
+
return await dev(vite, vite_config, svelte_config, illegal_imports);
|
|
3218
2433
|
},
|
|
3219
2434
|
|
|
3220
2435
|
/**
|
|
@@ -3222,7 +2437,7 @@ function kit() {
|
|
|
3222
2437
|
* @see https://vitejs.dev/guide/api-plugin.html#configurepreviewserver
|
|
3223
2438
|
*/
|
|
3224
2439
|
configurePreviewServer(vite) {
|
|
3225
|
-
return preview(vite,
|
|
2440
|
+
return preview(vite, vite_config, svelte_config);
|
|
3226
2441
|
}
|
|
3227
2442
|
};
|
|
3228
2443
|
}
|