@sveltejs/kit 1.0.0-next.366 → 1.0.0-next.369

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.
@@ -347,9 +347,14 @@ function parse_route_id(id) {
347
347
  .split(/\[(.+?)\]/)
348
348
  .map((content, i) => {
349
349
  if (i % 2) {
350
- const [, rest, name, type] = /** @type {RegExpMatchArray} */ (
351
- param_pattern.exec(content)
352
- );
350
+ const match = param_pattern.exec(content);
351
+ if (!match) {
352
+ throw new Error(
353
+ `Invalid param: ${content}. Params and matcher names can only have underscores and alphanumeric characters.`
354
+ );
355
+ }
356
+
357
+ const [, rest, name, type] = match;
353
358
  names.push(name);
354
359
  types.push(type);
355
360
  return rest ? '(.*?)' : '([^/]+?)';
@@ -1319,14 +1324,9 @@ function create_client({ target, session, base, trailing_slash }) {
1319
1324
  const params = route.exec(path);
1320
1325
 
1321
1326
  if (params) {
1327
+ const id = normalize_path(url.pathname, trailing_slash) + url.search;
1322
1328
  /** @type {import('./types').NavigationIntent} */
1323
- const intent = {
1324
- id: url.pathname + url.search,
1325
- route,
1326
- params,
1327
- url
1328
- };
1329
-
1329
+ const intent = { id, route, params, url };
1330
1330
  return intent;
1331
1331
  }
1332
1332
  }
@@ -190,9 +190,14 @@ function parse_route_id(id) {
190
190
  .split(/\[(.+?)\]/)
191
191
  .map((content, i) => {
192
192
  if (i % 2) {
193
- const [, rest, name, type] = /** @type {RegExpMatchArray} */ (
194
- param_pattern.exec(content)
195
- );
193
+ const match = param_pattern.exec(content);
194
+ if (!match) {
195
+ throw new Error(
196
+ `Invalid param: ${content}. Params and matcher names can only have underscores and alphanumeric characters.`
197
+ );
198
+ }
199
+
200
+ const [, rest, name, type] = match;
196
201
  names.push(name);
197
202
  types.push(type);
198
203
  return rest ? '(.*?)' : '([^/]+?)';
@@ -492,11 +497,18 @@ function create_manifest_data({
492
497
  if (!config.kit.moduleExtensions.includes(ext)) continue;
493
498
  const type = file.slice(0, -ext.length);
494
499
 
495
- if (/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(type)) {
496
- matchers[type] = path__default.join(params_base, file);
500
+ if (/^\w+$/.test(type)) {
501
+ const matcher_file = path__default.join(params_base, file);
502
+
503
+ // Disallow same matcher with different extensions
504
+ if (matchers[type]) {
505
+ throw new Error(`Duplicate matchers: ${matcher_file} and ${matchers[type]}`);
506
+ } else {
507
+ matchers[type] = matcher_file;
508
+ }
497
509
  } else {
498
510
  throw new Error(
499
- `Matcher names must match /^[a-zA-Z_][a-zA-Z0-9_]*$/ — "${file}" is invalid`
511
+ `Matcher names can only have underscores and alphanumeric characters — "${file}" is invalid`
500
512
  );
501
513
  }
502
514
  }
package/dist/cli.js CHANGED
@@ -18,7 +18,7 @@ function handle_error(e) {
18
18
  process.exit(1);
19
19
  }
20
20
 
21
- const prog = sade('svelte-kit').version('1.0.0-next.366');
21
+ const prog = sade('svelte-kit').version('1.0.0-next.369');
22
22
 
23
23
  prog
24
24
  .command('package')
package/dist/vite.js CHANGED
@@ -263,9 +263,9 @@ const get_default_config = function ({ config, input, ssr, outDir }) {
263
263
  input,
264
264
  output: {
265
265
  format: 'esm',
266
- entryFileNames: ssr ? '[name].js' : '[name]-[hash].js',
267
- chunkFileNames: 'chunks/[name]-[hash].js',
268
- assetFileNames: 'assets/[name]-[hash][extname]'
266
+ entryFileNames: ssr ? '[name].js' : 'immutable/[name]-[hash].js',
267
+ chunkFileNames: 'immutable/chunks/[name]-[hash].js',
268
+ assetFileNames: 'immutable/assets/[name]-[hash][extname]'
269
269
  },
270
270
  preserveEntrySignatures: 'strict'
271
271
  },
@@ -298,7 +298,7 @@ function assets_base(config) {
298
298
  // during `svelte-kit preview`, because we use a local asset path. This
299
299
  // may be fixed in Vite 3: https://github.com/vitejs/vite/issues/2009
300
300
  const { base, assets } = config.paths;
301
- return `${assets || base}/${config.appDir}/immutable/`;
301
+ return `${assets || base}/${config.appDir}/`;
302
302
  }
303
303
 
304
304
  /**
@@ -372,7 +372,7 @@ export class Server {
372
372
  manifest,
373
373
  method_override: ${s(config.kit.methodOverride)},
374
374
  paths: { base, assets },
375
- prefix: assets + '/${config.kit.appDir}/immutable/',
375
+ prefix: assets + '/${config.kit.appDir}/',
376
376
  prerender: {
377
377
  default: ${config.kit.prerender.default},
378
378
  enabled: ${config.kit.prerender.enabled}
@@ -692,7 +692,7 @@ async function build_service_worker(
692
692
 
693
693
  export const build = [
694
694
  ${Array.from(build)
695
- .map((file) => `${s(`${config.kit.paths.base}/${config.kit.appDir}/immutable/${file}`)}`)
695
+ .map((file) => `${s(`${config.kit.paths.base}/${config.kit.appDir}/${file}`)}`)
696
696
  .join(',\n\t\t\t\t')}
697
697
  ];
698
698
 
@@ -747,11 +747,13 @@ async function build_service_worker(
747
747
  await vite.build(merged_config);
748
748
  }
749
749
 
750
- /** @typedef {{
750
+ /**
751
+ * @typedef {{
751
752
  * fn: () => Promise<any>,
752
753
  * fulfil: (value: any) => void,
753
754
  * reject: (error: Error) => void
754
- * }} Task */
755
+ * }} Task
756
+ */
755
757
 
756
758
  /** @param {number} concurrency */
757
759
  function queue(concurrency) {
@@ -2850,6 +2852,15 @@ function kit() {
2850
2852
  /** @type {boolean} */
2851
2853
  let is_build;
2852
2854
 
2855
+ /** @type {import('types').Logger} */
2856
+ let log;
2857
+
2858
+ /** @type {import('types').Prerendered} */
2859
+ let prerendered;
2860
+
2861
+ /** @type {import('types').BuildData} */
2862
+ let build_data;
2863
+
2853
2864
  /**
2854
2865
  * @type {{
2855
2866
  * build_dir: string;
@@ -2862,6 +2873,8 @@ function kit() {
2862
2873
  function create_client_config() {
2863
2874
  /** @type {Record<string, string>} */
2864
2875
  const input = {
2876
+ // Put unchanging assets in immutable directory. We don't set that in the
2877
+ // outDir so that other plugins can add mutable assets to the bundle
2865
2878
  start: `${get_runtime_path(svelte_config.kit)}/client/start.js`
2866
2879
  };
2867
2880
 
@@ -2882,7 +2895,7 @@ function kit() {
2882
2895
  config: svelte_config,
2883
2896
  input,
2884
2897
  ssr: false,
2885
- outDir: `${paths.client_out_dir}/immutable`
2898
+ outDir: `${paths.client_out_dir}`
2886
2899
  });
2887
2900
  }
2888
2901
 
@@ -2968,7 +2981,7 @@ function kit() {
2968
2981
  },
2969
2982
 
2970
2983
  async writeBundle(_options, bundle) {
2971
- const log = logger({
2984
+ log = logger({
2972
2985
  verbose: vite_config.logLevel === 'info'
2973
2986
  });
2974
2987
 
@@ -2992,7 +3005,7 @@ function kit() {
2992
3005
 
2993
3006
  /** @type {import('vite').Manifest} */
2994
3007
  const vite_manifest = JSON.parse(
2995
- fs__default.readFileSync(`${paths.client_out_dir}/immutable/manifest.json`, 'utf-8')
3008
+ fs__default.readFileSync(`${paths.client_out_dir}/manifest.json`, 'utf-8')
2996
3009
  );
2997
3010
 
2998
3011
  const entry_id = posixify(
@@ -3024,7 +3037,7 @@ function kit() {
3024
3037
  process.env.SVELTEKIT_SERVER_BUILD_COMPLETED = 'true';
3025
3038
 
3026
3039
  /** @type {import('types').BuildData} */
3027
- const build_data = {
3040
+ build_data = {
3028
3041
  app_dir: svelte_config.kit.appDir,
3029
3042
  manifest_data,
3030
3043
  service_worker: options.service_worker_entry_file ? 'service-worker.js' : null, // TODO make file configurable?
@@ -3045,8 +3058,8 @@ function kit() {
3045
3058
 
3046
3059
  const files = new Set([
3047
3060
  ...static_files,
3048
- ...chunks.map((chunk) => `${svelte_config.kit.appDir}/immutable/${chunk.fileName}`),
3049
- ...assets.map((chunk) => `${svelte_config.kit.appDir}/immutable/${chunk.fileName}`)
3061
+ ...chunks.map((chunk) => `${svelte_config.kit.appDir}/${chunk.fileName}`),
3062
+ ...assets.map((chunk) => `${svelte_config.kit.appDir}/${chunk.fileName}`)
3050
3063
  ]);
3051
3064
 
3052
3065
  // TODO is this right?
@@ -3058,7 +3071,7 @@ function kit() {
3058
3071
 
3059
3072
  log.info('Prerendering');
3060
3073
 
3061
- const prerendered = await prerender({
3074
+ prerendered = await prerender({
3062
3075
  config: svelte_config.kit,
3063
3076
  entries: manifest_data.routes
3064
3077
  .map((route) => (route.type === 'page' ? route.path : ''))
@@ -3080,7 +3093,12 @@ function kit() {
3080
3093
  console.log(
3081
3094
  `\nRun ${$.bold().cyan('npm run preview')} to preview your production build locally.`
3082
3095
  );
3096
+ },
3083
3097
 
3098
+ async closeBundle() {
3099
+ if (!is_build) {
3100
+ return; // vite calls closeBundle when dev-server restarts, ignore that
3101
+ }
3084
3102
  if (svelte_config.kit.adapter) {
3085
3103
  const { adapt } = await import('./chunks/index2.js');
3086
3104
  await adapt(svelte_config, build_data, prerendered, { log });
@@ -3091,10 +3109,8 @@ function kit() {
3091
3109
  `See ${$.bold().cyan('https://kit.svelte.dev/docs/adapters')} to learn how to configure your app to run on the platform of your choosing`
3092
3110
  );
3093
3111
  }
3094
- },
3095
3112
 
3096
- closeBundle() {
3097
- if (is_build && svelte_config.kit.prerender.enabled) {
3113
+ if (svelte_config.kit.prerender.enabled) {
3098
3114
  // this is necessary to close any open db connections, etc.
3099
3115
  // TODO: prerender in a subprocess so we can exit in isolation
3100
3116
  // https://github.com/sveltejs/kit/issues/5306
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sveltejs/kit",
3
- "version": "1.0.0-next.366",
3
+ "version": "1.0.0-next.369",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/sveltejs/kit",
package/types/index.d.ts CHANGED
@@ -52,7 +52,6 @@ export interface Builder {
52
52
  */
53
53
  writeClient(dest: string): string[];
54
54
  /**
55
- *
56
55
  * @param dest
57
56
  */
58
57
  writePrerendered(