@sveltejs/kit 1.0.0-next.338 → 1.0.0-next.339

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.
@@ -962,11 +962,44 @@ function create_client({ target, session, base, trailing_slash }) {
962
962
  node.uses.stuff = true;
963
963
  return { ...stuff };
964
964
  },
965
- fetch(resource, info) {
966
- const requested = typeof resource === 'string' ? resource : resource.url;
967
- add_dependency(requested);
965
+ async fetch(resource, init) {
966
+ let requested;
967
+
968
+ if (typeof resource === 'string') {
969
+ requested = resource;
970
+ } else {
971
+ requested = resource.url;
972
+
973
+ // we're not allowed to modify the received `Request` object, so in order
974
+ // to fixup relative urls we create a new equivalent `init` object instead
975
+ init = {
976
+ // the request body must be consumed in memory until browsers
977
+ // implement streaming request bodies and/or the body getter
978
+ body:
979
+ resource.method === 'GET' || resource.method === 'HEAD'
980
+ ? undefined
981
+ : await resource.blob(),
982
+ cache: resource.cache,
983
+ credentials: resource.credentials,
984
+ headers: resource.headers,
985
+ integrity: resource.integrity,
986
+ keepalive: resource.keepalive,
987
+ method: resource.method,
988
+ mode: resource.mode,
989
+ redirect: resource.redirect,
990
+ referrer: resource.referrer,
991
+ referrerPolicy: resource.referrerPolicy,
992
+ signal: resource.signal,
993
+ ...init
994
+ };
995
+ }
996
+
997
+ // we must fixup relative urls so they are resolved from the target page
998
+ const normalized = new URL(requested, url).href;
999
+ add_dependency(normalized);
968
1000
 
969
- return started ? fetch$1(resource, info) : initial_fetch(resource, info);
1001
+ // prerendered pages may be served from any origin, so `initial_fetch` urls shouldn't be normalized
1002
+ return started ? fetch$1(normalized, init) : initial_fetch(requested, init);
970
1003
  },
971
1004
  status: status ?? null,
972
1005
  error: error ?? null
@@ -1130,7 +1130,7 @@ async function render_response({
1130
1130
  }
1131
1131
 
1132
1132
  if (options.template_contains_nonce) {
1133
- throw new Error('Cannot use prerendering if page template contains %svelte.nonce%');
1133
+ throw new Error('Cannot use prerendering if page template contains %sveltekit.nonce%');
1134
1134
  }
1135
1135
  }
1136
1136
 
@@ -335,14 +335,14 @@ async function create_plugin(config, cwd) {
335
335
  template: ({ head, body, assets, nonce }) => {
336
336
  return (
337
337
  template
338
- .replace(/%svelte\.assets%/g, assets)
339
- .replace(/%svelte\.nonce%/g, nonce)
340
- // head and body must be replaced last, in case someone tries to sneak in %svelte.assets% etc
341
- .replace('%svelte.head%', () => head)
342
- .replace('%svelte.body%', () => body)
338
+ .replace(/%sveltekit\.assets%/g, assets)
339
+ .replace(/%sveltekit\.nonce%/g, nonce)
340
+ // head and body must be replaced last, in case someone tries to sneak in %sveltekit.assets% etc
341
+ .replace('%sveltekit.head%', () => head)
342
+ .replace('%sveltekit.body%', () => body)
343
343
  );
344
344
  },
345
- template_contains_nonce: template.includes('%svelte.nonce%'),
345
+ template_contains_nonce: template.includes('%sveltekit.nonce%'),
346
346
  trailing_slash: config.kit.trailingSlash
347
347
  },
348
348
  {
@@ -342,10 +342,10 @@ import { set_paths, assets, base } from '${runtime}/paths.js';
342
342
  import { set_prerendering } from '${runtime}/env.js';
343
343
 
344
344
  const template = ({ head, body, assets, nonce }) => ${s(template)
345
- .replace('%svelte.head%', '" + head + "')
346
- .replace('%svelte.body%', '" + body + "')
347
- .replace(/%svelte\.assets%/g, '" + assets + "')
348
- .replace(/%svelte\.nonce%/g, '" + nonce + "')};
345
+ .replace('%sveltekit.head%', '" + head + "')
346
+ .replace('%sveltekit.body%', '" + body + "')
347
+ .replace(/%sveltekit\.assets%/g, '" + assets + "')
348
+ .replace(/%sveltekit\.nonce%/g, '" + nonce + "')};
349
349
 
350
350
  let read = null;
351
351
 
@@ -394,7 +394,7 @@ export class Server {
394
394
  service_worker: ${has_service_worker ? "base + '/service-worker.js'" : 'null'},
395
395
  router: ${s(config.kit.browser.router)},
396
396
  template,
397
- template_contains_nonce: ${template.includes('%svelte.nonce%')},
397
+ template_contains_nonce: ${template.includes('%sveltekit.nonce%')},
398
398
  trailing_slash: ${s(config.kit.trailingSlash)}
399
399
  };
400
400
  }
@@ -5950,14 +5950,14 @@ const flatten_properties = (array, target) => {
5950
5950
  * @param {any[]} nodes
5951
5951
  * @param {any[]} target
5952
5952
  */
5953
- const flatten = (nodes, target) => {
5953
+ const flatten$1 = (nodes, target) => {
5954
5954
  for (let i = 0; i < nodes.length; i += 1) {
5955
5955
  const node = nodes[i];
5956
5956
 
5957
5957
  if (node === EMPTY) continue;
5958
5958
 
5959
5959
  if (Array.isArray(node)) {
5960
- flatten(node, target);
5960
+ flatten$1(node, target);
5961
5961
  continue;
5962
5962
  }
5963
5963
 
@@ -6076,7 +6076,7 @@ const inject = (raw, node, values, comments) => {
6076
6076
  }
6077
6077
 
6078
6078
  if (node.type === 'ArrayExpression' || node.type === 'ArrayPattern') {
6079
- node.elements = flatten(node.elements, []);
6079
+ node.elements = flatten$1(node.elements, []);
6080
6080
  }
6081
6081
 
6082
6082
  if (
@@ -6084,18 +6084,18 @@ const inject = (raw, node, values, comments) => {
6084
6084
  node.type === 'FunctionDeclaration' ||
6085
6085
  node.type === 'ArrowFunctionExpression'
6086
6086
  ) {
6087
- node.params = flatten(node.params, []);
6087
+ node.params = flatten$1(node.params, []);
6088
6088
  }
6089
6089
 
6090
6090
  if (node.type === 'CallExpression' || node.type === 'NewExpression') {
6091
- node.arguments = flatten(node.arguments, []);
6091
+ node.arguments = flatten$1(node.arguments, []);
6092
6092
  }
6093
6093
 
6094
6094
  if (
6095
6095
  node.type === 'ImportDeclaration' ||
6096
6096
  node.type === 'ExportNamedDeclaration'
6097
6097
  ) {
6098
- node.specifiers = flatten(node.specifiers, []);
6098
+ node.specifiers = flatten$1(node.specifiers, []);
6099
6099
  }
6100
6100
 
6101
6101
  if (node.type === 'ForStatement') {
@@ -13813,7 +13813,7 @@ const meta_tags = new Map([
13813
13813
  ['svelte:window', 'Window'],
13814
13814
  ['svelte:body', 'Body']
13815
13815
  ]);
13816
- Array.from(meta_tags.keys()).concat('svelte:self', 'svelte:component', 'svelte:fragment');
13816
+ Array.from(meta_tags.keys()).concat('svelte:self', 'svelte:component', 'svelte:fragment', 'svelte:element');
13817
13817
 
13818
13818
  function getLocator(source, options) {
13819
13819
  if (options === void 0) { options = {}; }
@@ -13850,6 +13850,19 @@ function getLocator(source, options) {
13850
13850
  return locate;
13851
13851
  }
13852
13852
 
13853
+ /**
13854
+ * Pushes all `items` into `array` using `push`, therefore mutating the array.
13855
+ * We do this for memory and perf reasons, and because `array.push(...items)` would
13856
+ * run into a "max call stack size exceeded" error with too many items (~65k).
13857
+ * @param array
13858
+ * @param items
13859
+ */
13860
+ function push_array$1(array, items) {
13861
+ for (let i = 0; i < items.length; i++) {
13862
+ array.push(items[i]);
13863
+ }
13864
+ }
13865
+
13853
13866
  x `true`;
13854
13867
  x `false`;
13855
13868
 
@@ -14744,13 +14757,6 @@ function merge_tables(this_table, other_table) {
14744
14757
  }
14745
14758
  return [new_table, idx_map, val_changed, idx_changed];
14746
14759
  }
14747
- function pushArray(_this, other) {
14748
- // We use push to mutate in place for memory and perf reasons
14749
- // We use the for loop instead of _this.push(...other) to avoid the JS engine's function argument limit (65,535 in JavascriptCore)
14750
- for (let i = 0; i < other.length; i++) {
14751
- _this.push(other[i]);
14752
- }
14753
- }
14754
14760
  class MappedCode {
14755
14761
  constructor(string = '', map = null) {
14756
14762
  this.string = string;
@@ -14838,9 +14844,9 @@ class MappedCode {
14838
14844
  }
14839
14845
  }
14840
14846
  // combine last line + first line
14841
- pushArray(m1.mappings[m1.mappings.length - 1], m2.mappings.shift());
14847
+ push_array$1(m1.mappings[m1.mappings.length - 1], m2.mappings.shift());
14842
14848
  // append other lines
14843
- pushArray(m1.mappings, m2.mappings);
14849
+ push_array$1(m1.mappings, m2.mappings);
14844
14850
  return this;
14845
14851
  }
14846
14852
  static from_processed(string, map) {
@@ -193,118 +193,120 @@ function create_manifest_data({
193
193
  const routes_base = posixify(path__default.relative(cwd, config.kit.files.routes));
194
194
  const valid_extensions = [...config.extensions, ...config.kit.endpointExtensions];
195
195
 
196
- list_files(config.kit.files.routes).forEach((file) => {
197
- const extension = valid_extensions.find((ext) => file.endsWith(ext));
198
- if (!extension) return;
196
+ if (fs__default.existsSync(config.kit.files.routes)) {
197
+ list_files(config.kit.files.routes).forEach((file) => {
198
+ const extension = valid_extensions.find((ext) => file.endsWith(ext));
199
+ if (!extension) return;
199
200
 
200
- const id = file
201
- .slice(0, -extension.length)
202
- .replace(/(?:^|\/)index((?:@[a-zA-Z0-9_-]+)?(?:\.[a-z]+)?)?$/, '$1');
203
- const project_relative = `${routes_base}/${file}`;
201
+ const id = file
202
+ .slice(0, -extension.length)
203
+ .replace(/(?:^|\/)index((?:@[a-zA-Z0-9_-]+)?(?:\.[a-z]+)?)?$/, '$1');
204
+ const project_relative = `${routes_base}/${file}`;
204
205
 
205
- const segments = id.split('/');
206
- const name = /** @type {string} */ (segments.pop());
206
+ const segments = id.split('/');
207
+ const name = /** @type {string} */ (segments.pop());
207
208
 
208
- if (name === '__layout.reset') {
209
- throw new Error(
210
- '__layout.reset has been removed in favour of named layouts: https://kit.svelte.dev/docs/layouts#named-layouts'
211
- );
212
- }
209
+ if (name === '__layout.reset') {
210
+ throw new Error(
211
+ '__layout.reset has been removed in favour of named layouts: https://kit.svelte.dev/docs/layouts#named-layouts'
212
+ );
213
+ }
213
214
 
214
- if (name === '__error' || layout_pattern.test(name)) {
215
- const dir = segments.join('/');
215
+ if (name === '__error' || layout_pattern.test(name)) {
216
+ const dir = segments.join('/');
216
217
 
217
- if (!tree.has(dir)) {
218
- tree.set(dir, {
219
- error: undefined,
220
- layouts: {}
221
- });
222
- }
218
+ if (!tree.has(dir)) {
219
+ tree.set(dir, {
220
+ error: undefined,
221
+ layouts: {}
222
+ });
223
+ }
223
224
 
224
- const group = /** @type {Node} */ (tree.get(dir));
225
+ const group = /** @type {Node} */ (tree.get(dir));
225
226
 
226
- if (name === '__error') {
227
- group.error = project_relative;
228
- } else {
229
- const match = /** @type {RegExpMatchArray} */ (layout_pattern.exec(name));
227
+ if (name === '__error') {
228
+ group.error = project_relative;
229
+ } else {
230
+ const match = /** @type {RegExpMatchArray} */ (layout_pattern.exec(name));
230
231
 
231
- if (match[1] === DEFAULT) {
232
- throw new Error(`${project_relative} cannot use reserved "${DEFAULT}" name`);
233
- }
232
+ if (match[1] === DEFAULT) {
233
+ throw new Error(`${project_relative} cannot use reserved "${DEFAULT}" name`);
234
+ }
235
+
236
+ const layout_id = match[1] || DEFAULT;
234
237
 
235
- const layout_id = match[1] || DEFAULT;
238
+ const defined = group.layouts[layout_id];
239
+ if (defined && defined !== default_layout) {
240
+ throw new Error(
241
+ `Duplicate layout ${project_relative} already defined at ${defined.file}`
242
+ );
243
+ }
236
244
 
237
- const defined = group.layouts[layout_id];
238
- if (defined && defined !== default_layout) {
239
- throw new Error(
240
- `Duplicate layout ${project_relative} already defined at ${defined.file}`
241
- );
245
+ group.layouts[layout_id] = {
246
+ file: project_relative,
247
+ name
248
+ };
242
249
  }
243
250
 
244
- group.layouts[layout_id] = {
245
- file: project_relative,
246
- name
247
- };
251
+ return;
252
+ } else if (dunder_pattern.test(file)) {
253
+ throw new Error(
254
+ `Files and directories prefixed with __ are reserved (saw ${project_relative})`
255
+ );
248
256
  }
249
257
 
250
- return;
251
- } else if (dunder_pattern.test(file)) {
252
- throw new Error(
253
- `Files and directories prefixed with __ are reserved (saw ${project_relative})`
254
- );
255
- }
258
+ if (!config.kit.routes(file)) return;
256
259
 
257
- if (!config.kit.routes(file)) return;
258
-
259
- if (/\]\[/.test(id)) {
260
- throw new Error(`Invalid route ${project_relative} — parameters must be separated`);
261
- }
260
+ if (/\]\[/.test(id)) {
261
+ throw new Error(`Invalid route ${project_relative} — parameters must be separated`);
262
+ }
262
263
 
263
- if (count_occurrences('[', id) !== count_occurrences(']', id)) {
264
- throw new Error(`Invalid route ${project_relative} — brackets are unbalanced`);
265
- }
264
+ if (count_occurrences('[', id) !== count_occurrences(']', id)) {
265
+ throw new Error(`Invalid route ${project_relative} — brackets are unbalanced`);
266
+ }
266
267
 
267
- if (!units.has(id)) {
268
- units.set(id, {
269
- id,
270
- pattern: parse_route_id(id).pattern,
271
- segments: id
272
- .split('/')
273
- .filter(Boolean)
274
- .map((segment) => {
275
- /** @type {Part[]} */
276
- const parts = [];
277
- segment.split(/\[(.+?)\]/).map((content, i) => {
278
- const dynamic = !!(i % 2);
279
-
280
- if (!content) return;
281
-
282
- parts.push({
283
- content,
284
- dynamic,
285
- rest: dynamic && content.startsWith('...'),
286
- type: (dynamic && content.split('=')[1]) || null
268
+ if (!units.has(id)) {
269
+ units.set(id, {
270
+ id,
271
+ pattern: parse_route_id(id).pattern,
272
+ segments: id
273
+ .split('/')
274
+ .filter(Boolean)
275
+ .map((segment) => {
276
+ /** @type {Part[]} */
277
+ const parts = [];
278
+ segment.split(/\[(.+?)\]/).map((content, i) => {
279
+ const dynamic = !!(i % 2);
280
+
281
+ if (!content) return;
282
+
283
+ parts.push({
284
+ content,
285
+ dynamic,
286
+ rest: dynamic && content.startsWith('...'),
287
+ type: (dynamic && content.split('=')[1]) || null
288
+ });
287
289
  });
288
- });
289
- return parts;
290
- }),
291
- page: undefined,
292
- endpoint: undefined
293
- });
294
- }
290
+ return parts;
291
+ }),
292
+ page: undefined,
293
+ endpoint: undefined
294
+ });
295
+ }
295
296
 
296
- const unit = /** @type {Unit} */ (units.get(id));
297
+ const unit = /** @type {Unit} */ (units.get(id));
297
298
 
298
- if (config.extensions.find((ext) => file.endsWith(ext))) {
299
- const { layouts, errors } = trace(project_relative, file, tree, config.extensions);
300
- unit.page = {
301
- a: layouts.concat(project_relative),
302
- b: errors
303
- };
304
- } else {
305
- unit.endpoint = project_relative;
306
- }
307
- });
299
+ if (config.extensions.find((ext) => file.endsWith(ext))) {
300
+ const { layouts, errors } = trace(project_relative, file, tree, config.extensions);
301
+ unit.page = {
302
+ a: layouts.concat(project_relative),
303
+ b: errors
304
+ };
305
+ } else {
306
+ unit.endpoint = project_relative;
307
+ }
308
+ });
309
+ }
308
310
 
309
311
  /** @type {string[]} */
310
312
  const components = [];
package/dist/cli.js CHANGED
@@ -765,7 +765,16 @@ function load_template(cwd, config) {
765
765
 
766
766
  if (fs__default.existsSync(template)) {
767
767
  const contents = fs__default.readFileSync(template, 'utf8');
768
- const expected_tags = ['%svelte.head%', '%svelte.body%'];
768
+
769
+ // TODO remove this for 1.0
770
+ const match = /%svelte\.([a-z]+)%/.exec(contents);
771
+ if (match) {
772
+ throw new Error(
773
+ `%svelte.${match[1]}% in ${relative} should be replaced with %sveltekit.${match[1]}%`
774
+ );
775
+ }
776
+
777
+ const expected_tags = ['%sveltekit.head%', '%sveltekit.body%'];
769
778
  expected_tags.forEach((tag) => {
770
779
  if (contents.indexOf(tag) === -1) {
771
780
  throw new Error(`${relative} is missing ${tag}`);
@@ -875,7 +884,7 @@ async function launch(port, https, base) {
875
884
  exec(`${cmd} ${https ? 'https' : 'http'}://localhost:${port}${base}`);
876
885
  }
877
886
 
878
- const prog = sade('svelte-kit').version('1.0.0-next.338');
887
+ const prog = sade('svelte-kit').version('1.0.0-next.339');
879
888
 
880
889
  prog
881
890
  .command('dev')
@@ -1097,7 +1106,7 @@ async function check_port(port) {
1097
1106
  function welcome({ port, host, https, open, base, loose, allow, cwd }) {
1098
1107
  if (open) launch(port, https, base);
1099
1108
 
1100
- console.log($.bold().cyan(`\n SvelteKit v${'1.0.0-next.338'}\n`));
1109
+ console.log($.bold().cyan(`\n SvelteKit v${'1.0.0-next.339'}\n`));
1101
1110
 
1102
1111
  const protocol = https ? 'https:' : 'http:';
1103
1112
  const exposed = typeof host !== 'undefined' && host !== 'localhost' && host !== '127.0.0.1';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sveltejs/kit",
3
- "version": "1.0.0-next.338",
3
+ "version": "1.0.0-next.339",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/sveltejs/kit",
@@ -16,36 +16,21 @@
16
16
  "vite": "^2.9.9"
17
17
  },
18
18
  "devDependencies": {
19
- "@playwright/test": "^1.21.0",
20
- "@rollup/plugin-replace": "^4.0.0",
21
19
  "@types/connect": "^3.4.35",
22
20
  "@types/cookie": "^0.5.0",
23
21
  "@types/marked": "^4.0.1",
24
22
  "@types/mime": "^2.0.3",
25
- "@types/node": "^16.11.11",
26
23
  "@types/sade": "^1.7.3",
27
24
  "@types/set-cookie-parser": "^2.4.2",
28
25
  "cookie": "^0.5.0",
29
- "cross-env": "^7.0.3",
30
26
  "devalue": "^2.0.1",
31
- "eslint": "^8.3.0",
32
27
  "kleur": "^4.1.4",
33
28
  "locate-character": "^2.0.5",
34
- "marked": "^4.0.5",
35
29
  "mime": "^3.0.0",
36
30
  "node-fetch": "^3.1.0",
37
- "port-authority": "^1.1.2",
38
- "rollup": "^2.60.2",
39
31
  "selfsigned": "^2.0.0",
40
32
  "set-cookie-parser": "^2.4.8",
41
- "sirv": "^2.0.0",
42
- "svelte": "^3.44.2",
43
- "svelte-check": "^2.5.0",
44
- "svelte-preprocess": "^4.9.8",
45
- "svelte2tsx": "~0.5.0",
46
- "tiny-glob": "^0.2.9",
47
- "typescript": "^4.6.4",
48
- "uvu": "^0.5.2"
33
+ "svelte": "^3.48.0"
49
34
  },
50
35
  "peerDependencies": {
51
36
  "svelte": "^3.44.0"