@sveltejs/kit 1.0.0-next.301 → 1.0.0-next.304

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.
@@ -563,7 +563,11 @@ function create_client({ target, session, base, trailing_slash }) {
563
563
  const current_token = (token = {});
564
564
  let navigation_result = intent && (await load_route(intent, no_cache));
565
565
 
566
- if (!navigation_result && url.pathname === location.pathname) {
566
+ if (
567
+ !navigation_result &&
568
+ url.origin === location.origin &&
569
+ url.pathname === location.pathname
570
+ ) {
567
571
  // this could happen in SPA fallback mode if the user navigated to
568
572
  // `/non-existent-page`. if we fall back to reloading the page, it
569
573
  // will create an infinite loop. so whereas we normally handle
@@ -1021,7 +1025,7 @@ function create_client({ target, session, base, trailing_slash }) {
1021
1025
  // @ts-expect-error
1022
1026
  if (node.loaded.fallthrough) {
1023
1027
  throw new Error(
1024
- 'fallthrough is no longer supported. Use matchers instead: https://kit.svelte.dev/docs/routing#advanced-routing-validation'
1028
+ 'fallthrough is no longer supported. Use matchers instead: https://kit.svelte.dev/docs/routing#advanced-routing-matching'
1025
1029
  );
1026
1030
  }
1027
1031
 
@@ -2541,7 +2541,10 @@ async function respond(request, options, state) {
2541
2541
  return new Response(undefined, {
2542
2542
  status: 301,
2543
2543
  headers: {
2544
- location: normalized + (url.search === '?' ? '' : url.search)
2544
+ location:
2545
+ // ensure paths starting with '//' are not treated as protocol-relative
2546
+ (normalized.startsWith('//') ? url.origin + normalized : normalized) +
2547
+ (url.search === '?' ? '' : url.search)
2545
2548
  }
2546
2549
  });
2547
2550
  }
@@ -73,7 +73,7 @@ async function create_plugin(config, cwd) {
73
73
  const url = id.startsWith('..') ? `/@fs${path__default.posix.resolve(id)}` : `/${id}`;
74
74
 
75
75
  const module = /** @type {import('types').SSRComponent} */ (
76
- await vite.ssrLoadModule(url)
76
+ await vite.ssrLoadModule(url, { fixStacktrace: false })
77
77
  );
78
78
  const node = await vite.moduleGraph.getModuleByUrl(url);
79
79
 
@@ -95,7 +95,7 @@ async function create_plugin(config, cwd) {
95
95
  (query.has('svelte') && query.get('type') === 'style')
96
96
  ) {
97
97
  try {
98
- const mod = await vite.ssrLoadModule(dep.url);
98
+ const mod = await vite.ssrLoadModule(dep.url, { fixStacktrace: false });
99
99
  styles[dep.url] = mod.default;
100
100
  } catch {
101
101
  // this can happen with dynamically imported modules, I think
@@ -128,7 +128,7 @@ async function create_plugin(config, cwd) {
128
128
  shadow: route.shadow
129
129
  ? async () => {
130
130
  const url = path__default.resolve(cwd, /** @type {string} */ (route.shadow));
131
- return await vite.ssrLoadModule(url);
131
+ return await vite.ssrLoadModule(url, { fixStacktrace: false });
132
132
  }
133
133
  : null,
134
134
  a: route.a.map((id) => manifest_data.components.indexOf(id)),
@@ -144,7 +144,7 @@ async function create_plugin(config, cwd) {
144
144
  types,
145
145
  load: async () => {
146
146
  const url = path__default.resolve(cwd, route.file);
147
- return await vite.ssrLoadModule(url);
147
+ return await vite.ssrLoadModule(url, { fixStacktrace: false });
148
148
  }
149
149
  };
150
150
  }),
@@ -155,7 +155,7 @@ async function create_plugin(config, cwd) {
155
155
  for (const key in manifest_data.matchers) {
156
156
  const file = manifest_data.matchers[key];
157
157
  const url = path__default.resolve(cwd, file);
158
- const module = await vite.ssrLoadModule(url);
158
+ const module = await vite.ssrLoadModule(url, { fixStacktrace: false });
159
159
 
160
160
  if (module.match) {
161
161
  matchers[key] = module.match;
@@ -172,20 +172,7 @@ async function create_plugin(config, cwd) {
172
172
 
173
173
  /** @param {Error} error */
174
174
  function fix_stack_trace(error) {
175
- // TODO https://github.com/vitejs/vite/issues/7045
176
-
177
- // ideally vite would expose ssrRewriteStacktrace, but
178
- // in lieu of that, we can implement it ourselves. we
179
- // don't want to mutate the error object, because
180
- // the stack trace could be 'fixed' multiple times,
181
- // and Vite will fix stack traces before we even
182
- // see them if they occur during ssrLoadModule
183
- const original = error.stack;
184
- vite.ssrFixStacktrace(error);
185
- const fixed = error.stack;
186
- error.stack = original;
187
-
188
- return fixed;
175
+ return error.stack ? vite.ssrRewriteStacktrace(error.stack) : error.stack;
189
176
  }
190
177
 
191
178
  update_manifest();
@@ -231,7 +218,7 @@ async function create_plugin(config, cwd) {
231
218
 
232
219
  /** @type {Partial<import('types').Hooks>} */
233
220
  const user_hooks = resolve_entry(config.kit.files.hooks)
234
- ? await vite.ssrLoadModule(`/${config.kit.files.hooks}`)
221
+ ? await vite.ssrLoadModule(`/${config.kit.files.hooks}`, { fixStacktrace: false })
235
222
  : {};
236
223
 
237
224
  const handle = user_hooks.handle || (({ event, resolve }) => resolve(event));
@@ -271,13 +258,15 @@ async function create_plugin(config, cwd) {
271
258
  // can get loaded twice via different URLs, which causes failures. Might
272
259
  // require changes to Vite to fix
273
260
  const { default: root } = await vite.ssrLoadModule(
274
- `/${posixify(path__default.relative(cwd, `${config.kit.outDir}/generated/root.svelte`))}`
261
+ `/${posixify(path__default.relative(cwd, `${config.kit.outDir}/generated/root.svelte`))}`,
262
+ { fixStacktrace: false }
275
263
  );
276
264
 
277
265
  const paths = await vite.ssrLoadModule(
278
266
  true
279
267
  ? `/${posixify(path__default.relative(cwd, `${config.kit.outDir}/runtime/paths.js`))}`
280
- : `/@fs${runtime}/paths.js`
268
+ : `/@fs${runtime}/paths.js`,
269
+ { fixStacktrace: false }
281
270
  );
282
271
 
283
272
  paths.set_paths({
@@ -1003,10 +1003,6 @@ async function prerender({ config, entries, files, log }) {
1003
1003
  paths: []
1004
1004
  };
1005
1005
 
1006
- if (!config.kit.prerender.enabled) {
1007
- return prerendered;
1008
- }
1009
-
1010
1006
  installFetch();
1011
1007
 
1012
1008
  const server_root = join(config.kit.outDir, 'output');
@@ -1023,6 +1019,23 @@ async function prerender({ config, entries, files, log }) {
1023
1019
 
1024
1020
  const server = new Server(manifest);
1025
1021
 
1022
+ const rendered = await server.respond(new Request('http://sveltekit-prerender/[fallback]'), {
1023
+ getClientAddress,
1024
+ prerender: {
1025
+ fallback: true,
1026
+ default: false,
1027
+ dependencies: new Map()
1028
+ }
1029
+ });
1030
+
1031
+ const file = `${config.kit.outDir}/output/prerendered/fallback.html`;
1032
+ mkdirp(dirname(file));
1033
+ writeFileSync(file, await rendered.text());
1034
+
1035
+ if (!config.kit.prerender.enabled) {
1036
+ return prerendered;
1037
+ }
1038
+
1026
1039
  const error = normalise_error_handler(log, config.kit.prerender.onError);
1027
1040
 
1028
1041
  const q = queue(config.kit.prerender.concurrency);
@@ -1214,19 +1227,6 @@ async function prerender({ config, entries, files, log }) {
1214
1227
  await q.done();
1215
1228
  }
1216
1229
 
1217
- const rendered = await server.respond(new Request('http://sveltekit-prerender/[fallback]'), {
1218
- getClientAddress,
1219
- prerender: {
1220
- fallback: true,
1221
- default: false,
1222
- dependencies: new Map()
1223
- }
1224
- });
1225
-
1226
- const file = `${config.kit.outDir}/output/prerendered/fallback.html`;
1227
- mkdirp(dirname(file));
1228
- writeFileSync(file, await rendered.text());
1229
-
1230
1230
  return prerendered;
1231
1231
  }
1232
1232
 
@@ -132,7 +132,7 @@ var mime = new Mime(standard, other);
132
132
  * }} Item
133
133
  */
134
134
 
135
- const specials = new Set(['__layout', '__layout.reset', '__error']);
135
+ const specials = new Set(['__layout', '__layout.reset', '__error', '__tests__', '__test__']);
136
136
 
137
137
  /**
138
138
  * @param {{
@@ -328,7 +328,7 @@ function create_manifest_data({
328
328
  matchers[type] = path__default.join(params_base, file);
329
329
  } else {
330
330
  throw new Error(
331
- `Validator names must match /^[a-zA-Z_][a-zA-Z0-9_]*$/ — "${file}" is invalid`
331
+ `Matcher names must match /^[a-zA-Z_][a-zA-Z0-9_]*$/ — "${file}" is invalid`
332
332
  );
333
333
  }
334
334
  }
@@ -579,6 +579,28 @@ function write_manifest(manifest_data, base, output) {
579
579
  );
580
580
  }
581
581
 
582
+ /**
583
+ * @param {import('types').ManifestData} manifest_data
584
+ * @param {string} output
585
+ */
586
+ function write_matchers(manifest_data, output) {
587
+ const imports = [];
588
+ const matchers = [];
589
+
590
+ for (const key in manifest_data.matchers) {
591
+ const src = manifest_data.matchers[key];
592
+
593
+ imports.push(`import { match as ${key} } from ${s(path__default.relative(output, src))};`);
594
+ matchers.push(key);
595
+ }
596
+
597
+ const module = imports.length
598
+ ? `${imports.join('\n')}\n\nexport const matchers = { ${matchers.join(', ')} };`
599
+ : 'export const matchers = {};';
600
+
601
+ write_if_changed(`${output}/client-matchers.js`, module);
602
+ }
603
+
582
604
  /**
583
605
  * @param {import('types').ManifestData} manifest_data
584
606
  * @param {string} output
@@ -878,28 +900,6 @@ function write_types(config, manifest_data) {
878
900
  });
879
901
  }
880
902
 
881
- /**
882
- * @param {import('types').ManifestData} manifest_data
883
- * @param {string} output
884
- */
885
- function write_validators(manifest_data, output) {
886
- const imports = [];
887
- const matchers = [];
888
-
889
- for (const key in manifest_data.matchers) {
890
- const src = manifest_data.matchers[key];
891
-
892
- imports.push(`import { match as ${key} } from ${s(path__default.relative(output, src))};`);
893
- matchers.push(key);
894
- }
895
-
896
- const module = imports.length
897
- ? `${imports.join('\n')}\n\nexport const matchers = { ${matchers.join(', ')} };`
898
- : 'export const matchers = {};';
899
-
900
- write_if_changed(`${output}/client-matchers.js`, module);
901
- }
902
-
903
903
  /** @param {import('types').ValidatedConfig} config */
904
904
  function init(config) {
905
905
  copy_assets(path__default.join(config.kit.outDir, 'runtime'));
@@ -915,7 +915,7 @@ function update(config) {
915
915
 
916
916
  write_manifest(manifest_data, base, output);
917
917
  write_root(manifest_data, output);
918
- write_validators(manifest_data, output);
918
+ write_matchers(manifest_data, output);
919
919
  write_types(config, manifest_data);
920
920
 
921
921
  return { manifest_data };
package/dist/cli.js CHANGED
@@ -869,7 +869,7 @@ async function launch(port, https) {
869
869
  exec(`${cmd} ${https ? 'https' : 'http'}://localhost:${port}`);
870
870
  }
871
871
 
872
- const prog = sade('svelte-kit').version('1.0.0-next.301');
872
+ const prog = sade('svelte-kit').version('1.0.0-next.304');
873
873
 
874
874
  prog
875
875
  .command('dev')
@@ -1047,7 +1047,7 @@ async function check_port(port) {
1047
1047
  function welcome({ port, host, https, open, loose, allow, cwd }) {
1048
1048
  if (open) launch(port, https);
1049
1049
 
1050
- console.log($.bold().cyan(`\n SvelteKit v${'1.0.0-next.301'}\n`));
1050
+ console.log($.bold().cyan(`\n SvelteKit v${'1.0.0-next.304'}\n`));
1051
1051
 
1052
1052
  const protocol = https ? 'https:' : 'http:';
1053
1053
  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.301",
3
+ "version": "1.0.0-next.304",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/sveltejs/kit",
@@ -12,7 +12,7 @@
12
12
  "dependencies": {
13
13
  "@sveltejs/vite-plugin-svelte": "^1.0.0-next.32",
14
14
  "sade": "^1.7.4",
15
- "vite": "^2.8.0"
15
+ "vite": "^2.9.0"
16
16
  },
17
17
  "devDependencies": {
18
18
  "@playwright/test": "^1.19.1",
@@ -18,7 +18,6 @@ import {
18
18
  RequestOptions,
19
19
  ResolveOptions,
20
20
  ResponseHeaders,
21
- RouteSegment,
22
21
  TrailingSlash
23
22
  } from './private';
24
23
 
@@ -2,8 +2,6 @@
2
2
  // but which cannot be imported from `@sveltejs/kit`. Care should
3
3
  // be taken to avoid breaking changes when editing this file
4
4
 
5
- import { ValidatedConfig } from './internal';
6
-
7
5
  export interface AdapterEntry {
8
6
  /**
9
7
  * A string that uniquely identifies an HTTP service (e.g. serverless function) and is used for deduplication.
@@ -191,8 +189,6 @@ export interface Logger {
191
189
 
192
190
  export type MaybePromise<T> = T | Promise<T>;
193
191
 
194
- export type Only<T, U> = { [P in keyof T]: T[P] } & { [P in Exclude<keyof U, keyof T>]?: never };
195
-
196
192
  export interface Prerendered {
197
193
  pages: Map<
198
194
  string,