@sveltejs/kit 1.0.0-next.405 → 1.0.0-next.406

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.
Files changed (99) hide show
  1. package/package.json +23 -25
  2. package/{dist → src}/cli.js +19 -18
  3. package/{dist/chunks/index3.js → src/core/adapt/builder.js} +6 -59
  4. package/src/core/adapt/index.js +19 -0
  5. package/src/core/config/index.js +86 -0
  6. package/{dist/chunks/index.js → src/core/config/options.js} +7 -194
  7. package/src/core/config/types.d.ts +1 -0
  8. package/src/core/constants.js +3 -0
  9. package/src/core/generate_manifest/index.js +99 -0
  10. package/src/core/prerender/crawl.js +194 -0
  11. package/src/core/prerender/prerender.js +378 -0
  12. package/src/core/prerender/queue.js +80 -0
  13. package/src/core/sync/create_manifest_data/index.js +492 -0
  14. package/src/core/sync/create_manifest_data/types.d.ts +40 -0
  15. package/src/core/sync/sync.js +59 -0
  16. package/src/core/sync/utils.js +97 -0
  17. package/src/core/sync/write_ambient.js +87 -0
  18. package/src/core/sync/write_client_manifest.js +82 -0
  19. package/src/core/sync/write_matchers.js +25 -0
  20. package/src/core/sync/write_root.js +88 -0
  21. package/{dist/chunks → src/core/sync}/write_tsconfig.js +24 -108
  22. package/src/core/sync/write_types.js +738 -0
  23. package/src/core/utils.js +58 -0
  24. package/{dist → src}/hooks.js +1 -3
  25. package/src/index/index.js +45 -0
  26. package/src/index/private.js +31 -0
  27. package/src/node/index.js +145 -0
  28. package/src/node/polyfills.js +40 -0
  29. package/src/packaging/index.js +218 -0
  30. package/src/packaging/types.d.ts +8 -0
  31. package/src/packaging/typescript.js +150 -0
  32. package/src/packaging/utils.js +138 -0
  33. package/{assets → src/runtime}/app/env.js +3 -5
  34. package/src/runtime/app/navigation.js +22 -0
  35. package/src/runtime/app/paths.js +1 -0
  36. package/{assets → src/runtime}/app/stores.js +6 -9
  37. package/src/runtime/client/ambient.d.ts +17 -0
  38. package/{assets/client/start.js → src/runtime/client/client.js} +302 -878
  39. package/src/runtime/client/fetcher.js +60 -0
  40. package/src/runtime/client/parse.js +36 -0
  41. package/{assets → src/runtime}/client/singletons.js +2 -4
  42. package/src/runtime/client/start.js +48 -0
  43. package/src/runtime/client/types.d.ts +106 -0
  44. package/src/runtime/client/utils.js +113 -0
  45. package/src/runtime/components/error.svelte +16 -0
  46. package/{assets → src/runtime}/components/layout.svelte +0 -0
  47. package/{assets → src/runtime}/env/dynamic/private.js +0 -0
  48. package/{assets → src/runtime}/env/dynamic/public.js +0 -0
  49. package/{assets → src/runtime}/env-private.js +2 -4
  50. package/{assets → src/runtime}/env-public.js +2 -4
  51. package/src/runtime/env.js +6 -0
  52. package/src/runtime/hash.js +16 -0
  53. package/{assets → src/runtime}/paths.js +3 -5
  54. package/src/runtime/server/endpoint.js +42 -0
  55. package/src/runtime/server/index.js +434 -0
  56. package/src/runtime/server/page/cookie.js +25 -0
  57. package/src/runtime/server/page/crypto.js +239 -0
  58. package/src/runtime/server/page/csp.js +249 -0
  59. package/src/runtime/server/page/fetch.js +265 -0
  60. package/src/runtime/server/page/index.js +423 -0
  61. package/src/runtime/server/page/load_data.js +94 -0
  62. package/src/runtime/server/page/render.js +357 -0
  63. package/src/runtime/server/page/respond_with_error.js +105 -0
  64. package/src/runtime/server/page/types.d.ts +44 -0
  65. package/src/runtime/server/utils.js +116 -0
  66. package/src/utils/error.js +22 -0
  67. package/src/utils/escape.js +104 -0
  68. package/{dist/chunks → src/utils}/filesystem.js +22 -24
  69. package/src/utils/http.js +55 -0
  70. package/src/utils/misc.js +1 -0
  71. package/src/utils/routing.js +107 -0
  72. package/src/utils/url.js +97 -0
  73. package/src/vite/build/build_server.js +333 -0
  74. package/src/vite/build/build_service_worker.js +90 -0
  75. package/src/vite/build/utils.js +152 -0
  76. package/src/vite/dev/index.js +565 -0
  77. package/src/vite/index.js +536 -0
  78. package/src/vite/preview/index.js +186 -0
  79. package/src/vite/types.d.ts +3 -0
  80. package/src/vite/utils.js +335 -0
  81. package/svelte-kit.js +1 -10
  82. package/types/ambient.d.ts +5 -12
  83. package/types/index.d.ts +86 -44
  84. package/types/internal.d.ts +50 -72
  85. package/types/private.d.ts +2 -1
  86. package/assets/app/navigation.js +0 -24
  87. package/assets/app/paths.js +0 -1
  88. package/assets/components/error.svelte +0 -29
  89. package/assets/env.js +0 -8
  90. package/assets/server/index.js +0 -3589
  91. package/dist/chunks/error.js +0 -12
  92. package/dist/chunks/index2.js +0 -15745
  93. package/dist/chunks/multipart-parser.js +0 -458
  94. package/dist/chunks/sync.js +0 -1366
  95. package/dist/chunks/utils.js +0 -66
  96. package/dist/node/polyfills.js +0 -17928
  97. package/dist/node.js +0 -348
  98. package/dist/prerender.js +0 -788
  99. package/dist/vite.js +0 -2513
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sveltejs/kit",
3
- "version": "1.0.0-next.405",
3
+ "version": "1.0.0-next.406",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/sveltejs/kit",
@@ -12,12 +12,20 @@
12
12
  "dependencies": {
13
13
  "@sveltejs/vite-plugin-svelte": "^1.0.1",
14
14
  "chokidar": "^3.5.3",
15
+ "cookie": "^0.5.0",
16
+ "devalue": "^2.0.1",
17
+ "kleur": "^4.1.4",
18
+ "magic-string": "^0.26.2",
19
+ "mime": "^3.0.0",
20
+ "node-fetch": "^3.2.4",
15
21
  "sade": "^1.8.1",
16
- "tiny-glob": "^0.2.9"
22
+ "set-cookie-parser": "^2.4.8",
23
+ "sirv": "^2.0.2",
24
+ "tiny-glob": "^0.2.9",
25
+ "undici": "^5.8.1"
17
26
  },
18
27
  "devDependencies": {
19
28
  "@playwright/test": "^1.23.4",
20
- "@rollup/plugin-replace": "^4.0.0",
21
29
  "@types/connect": "^3.4.35",
22
30
  "@types/cookie": "^0.5.1",
23
31
  "@types/marked": "^4.0.3",
@@ -25,25 +33,12 @@
25
33
  "@types/node": "^16.11.36",
26
34
  "@types/sade": "^1.7.4",
27
35
  "@types/set-cookie-parser": "^2.4.2",
28
- "cookie": "^0.5.0",
29
- "cross-env": "^7.0.3",
30
- "devalue": "^2.0.1",
31
- "kleur": "^4.1.4",
32
- "locate-character": "^2.0.5",
33
36
  "marked": "^4.0.16",
34
- "mime": "^3.0.0",
35
- "node-fetch": "^3.2.4",
36
37
  "rollup": "^2.75.7",
37
- "selfsigned": "^2.0.1",
38
- "set-cookie-parser": "^2.4.8",
39
- "sirv": "^2.0.2",
40
38
  "svelte": "^3.48.0",
41
- "svelte-check": "^2.7.1",
42
39
  "svelte-preprocess": "^4.10.6",
43
40
  "svelte2tsx": "~0.5.10",
44
- "tiny-glob": "^0.2.9",
45
41
  "typescript": "^4.7.4",
46
- "undici": "^5.8.1",
47
42
  "uvu": "^0.5.3",
48
43
  "vite": "^3.0.0"
49
44
  },
@@ -55,27 +50,31 @@
55
50
  "svelte-kit": "svelte-kit.js"
56
51
  },
57
52
  "files": [
58
- "assets",
59
- "dist",
53
+ "src",
54
+ "!src/**/*.spec.js",
55
+ "!src/packaging/test",
56
+ "!src/core/**/fixtures",
57
+ "!src/core/sync/create_manifest_data/test",
60
58
  "types",
61
59
  "svelte-kit.js"
62
60
  ],
63
61
  "exports": {
64
62
  "./package.json": "./package.json",
65
63
  ".": {
64
+ "import": "./src/index/index.js",
66
65
  "types": "./types/index.d.ts"
67
66
  },
68
67
  "./node": {
69
- "import": "./dist/node.js"
68
+ "import": "./src/node/index.js"
70
69
  },
71
70
  "./node/polyfills": {
72
- "import": "./dist/node/polyfills.js"
71
+ "import": "./src/node/polyfills.js"
73
72
  },
74
73
  "./hooks": {
75
- "import": "./dist/hooks.js"
74
+ "import": "./src/hooks.js"
76
75
  },
77
76
  "./vite": {
78
- "import": "./dist/vite.js"
77
+ "import": "./src/vite/index.js"
79
78
  }
80
79
  },
81
80
  "types": "types/index.d.ts",
@@ -83,16 +82,15 @@
83
82
  "node": ">=16.9"
84
83
  },
85
84
  "scripts": {
86
- "build": "rollup -c && node scripts/cp.js src/runtime/components assets/components && npm run types",
85
+ "build": "npm run types",
87
86
  "dev": "rollup -cw",
88
87
  "lint": "prettier --check . --config ../../.prettierrc --ignore-path .gitignore",
89
88
  "check": "tsc",
90
89
  "check:all": "tsc && pnpm -r --filter=\"./**\" check",
91
90
  "format": "npm run lint -- --write",
92
- "test": "npm run test:unit && npm run test:typings && npm run test:packaging && npm run test:integration",
91
+ "test": "npm run test:unit && npm run test:packaging && npm run test:integration",
93
92
  "test:integration": "pnpm run -r --workspace-concurrency 1 --filter=\"./test/**\" test",
94
93
  "test:unit": "uvu src \"(spec\\.js|test[\\\\/]index\\.js)\" -i packaging",
95
- "test:typings": "tsc --project test/typings",
96
94
  "test:packaging": "uvu src/packaging \"(spec\\.js|test[\\\\/]index\\.js)\"",
97
95
  "types": "node scripts/extract-types.js",
98
96
  "postinstall": "node svelte-kit.js sync"
@@ -1,9 +1,9 @@
1
- import fs__default from 'fs';
2
- import path__default from 'path';
3
- import { l as load_config, $ } from './chunks/index.js';
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ import colors from 'kleur';
4
4
  import sade from 'sade';
5
- import { c as coalesce_to_error } from './chunks/error.js';
6
- import 'url';
5
+ import { load_config } from './core/config/index.js';
6
+ import { coalesce_to_error } from './utils/error.js';
7
7
 
8
8
  /** @param {unknown} e */
9
9
  function handle_error(e) {
@@ -11,15 +11,16 @@ function handle_error(e) {
11
11
 
12
12
  if (error.name === 'SyntaxError') throw error;
13
13
 
14
- console.error($.bold().red(`> ${error.message}`));
14
+ console.error(colors.bold().red(`> ${error.message}`));
15
15
  if (error.stack) {
16
- console.error($.gray(error.stack.split('\n').slice(1).join('\n')));
16
+ console.error(colors.gray(error.stack.split('\n').slice(1).join('\n')));
17
17
  }
18
18
 
19
19
  process.exit(1);
20
20
  }
21
21
 
22
- const prog = sade('svelte-kit').version('1.0.0-next.405');
22
+ const pkg = JSON.parse(fs.readFileSync(new URL('../package.json', import.meta.url), 'utf-8'));
23
+ const prog = sade('svelte-kit').version(pkg.version);
23
24
 
24
25
  prog
25
26
  .command('package')
@@ -28,7 +29,7 @@ prog
28
29
  .action(async ({ watch }) => {
29
30
  try {
30
31
  const config = await load_config();
31
- const packaging = await import('./chunks/index2.js');
32
+ const packaging = await import('./packaging/index.js');
32
33
 
33
34
  await (watch ? packaging.watch(config) : packaging.build(config));
34
35
  } catch (error) {
@@ -45,13 +46,13 @@ prog
45
46
 
46
47
  // TODO remove for 1.0
47
48
  if (event === 'prepare') {
48
- const pkg = JSON.parse(fs__default.readFileSync('package.json', 'utf8'));
49
+ const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8'));
49
50
  const message =
50
51
  pkg.scripts.prepare === 'svelte-kit sync'
51
52
  ? `\`svelte-kit sync\` now runs on "postinstall" — please remove the "prepare" script from your package.json\n`
52
53
  : `\`svelte-kit sync\` now runs on "postinstall" — please remove it from your "prepare" script\n`;
53
54
 
54
- console.error($.bold().red(message));
55
+ console.error(colors.bold().red(message));
55
56
  return;
56
57
  }
57
58
 
@@ -59,15 +60,15 @@ prog
59
60
  process.chdir(process.env.INIT_CWD);
60
61
  }
61
62
 
62
- if (!fs__default.existsSync('svelte.config.js')) {
63
- console.warn(`Missing ${path__default.resolve('svelte.config.js')} — skipping`);
63
+ if (!fs.existsSync('svelte.config.js')) {
64
+ console.warn(`Missing ${path.resolve('svelte.config.js')} — skipping`);
64
65
  return;
65
66
  }
66
67
 
67
68
  try {
68
69
  const config = await load_config();
69
- const sync = await import('./chunks/sync.js').then(function (n) { return n.f; });
70
- sync.all(config, mode);
70
+ const sync = await import('./core/sync/sync.js');
71
+ await sync.all(config, mode);
71
72
  } catch (error) {
72
73
  handle_error(error);
73
74
  }
@@ -87,7 +88,7 @@ function replace(command) {
87
88
  .describe(`No longer available — use vite ${command} instead`)
88
89
  .action(async () => {
89
90
  const message = `\n> svelte-kit ${command} is no longer available — use vite ${command} instead`;
90
- console.error($.bold().red(message));
91
+ console.error(colors.bold().red(message));
91
92
 
92
93
  const steps = [
93
94
  'Install vite as a devDependency with npm/pnpm/etc',
@@ -96,12 +97,12 @@ function replace(command) {
96
97
  ];
97
98
 
98
99
  steps.forEach((step, i) => {
99
- console.error(` ${i + 1}. ${$.cyan(step)}`);
100
+ console.error(` ${i + 1}. ${colors.cyan(step)}`);
100
101
  });
101
102
 
102
103
  console.error(
103
104
  `
104
- ${$.grey('// vite.config.js')}
105
+ ${colors.grey('// vite.config.js')}
105
106
  import { sveltekit } from '@sveltejs/kit/vite';
106
107
 
107
108
  /** @type {import('vite').UserConfig} */
@@ -1,45 +1,10 @@
1
- import { $ } from './index.js';
2
1
  import glob from 'tiny-glob';
3
2
  import zlib from 'zlib';
4
3
  import { existsSync, statSync, createReadStream, createWriteStream } from 'fs';
5
4
  import { pipeline } from 'stream';
6
5
  import { promisify } from 'util';
7
- import { r as rimraf, m as mkdirp, c as copy } from './filesystem.js';
8
- import { g as generate_manifest } from '../vite.js';
9
- import 'path';
10
- import 'url';
11
- import 'node:child_process';
12
- import 'node:fs';
13
- import 'node:path';
14
- import '@sveltejs/vite-plugin-svelte';
15
- import 'vite';
16
- import './sync.js';
17
- import './utils.js';
18
- import './write_tsconfig.js';
19
- import 'querystring';
20
- import '../node.js';
21
- import '../node/polyfills.js';
22
- import 'assert';
23
- import 'net';
24
- import 'http';
25
- import 'buffer';
26
- import 'stream/web';
27
- import 'perf_hooks';
28
- import 'util/types';
29
- import 'events';
30
- import 'tls';
31
- import 'async_hooks';
32
- import 'console';
33
- import 'node:http';
34
- import 'node:https';
35
- import 'node:zlib';
36
- import 'node:stream';
37
- import 'node:buffer';
38
- import 'node:util';
39
- import 'node:url';
40
- import 'node:net';
41
- import 'crypto';
42
- import './error.js';
6
+ import { copy, rimraf, mkdirp } from '../../utils/filesystem.js';
7
+ import { generate_manifest } from '../generate_manifest/index.js';
43
8
 
44
9
  /**
45
10
  * Creates the Builder which is passed to adapters for building the application.
@@ -51,15 +16,16 @@ import './error.js';
51
16
  * }} opts
52
17
  * @returns {import('types').Builder}
53
18
  */
54
- function create_builder({ config, build_data, prerendered, log }) {
19
+ export function create_builder({ config, build_data, prerendered, log }) {
55
20
  /** @type {Set<string>} */
56
21
  const prerendered_paths = new Set(prerendered.paths);
57
22
 
58
23
  /** @param {import('types').RouteData} route */
59
24
  // TODO routes should come pre-filtered
60
25
  function not_prerendered(route) {
61
- if (route.type === 'page' && route.path) {
62
- return !prerendered_paths.has(route.path) && !prerendered_paths.has(route.path + '/');
26
+ const path = route.type === 'page' && !route.id.includes('[') && `/${route.id}`;
27
+ if (path) {
28
+ return !prerendered_paths.has(path) && !prerendered_paths.has(path + '/');
63
29
  }
64
30
 
65
31
  return true;
@@ -239,22 +205,3 @@ function create_builder({ config, build_data, prerendered, log }) {
239
205
  }
240
206
  };
241
207
  }
242
-
243
- /**
244
- * @param {import('types').ValidatedConfig} config
245
- * @param {import('types').BuildData} build_data
246
- * @param {import('types').Prerendered} prerendered
247
- * @param {{ log: import('types').Logger }} opts
248
- */
249
- async function adapt(config, build_data, prerendered, { log }) {
250
- const { name, adapt } = config.kit.adapter;
251
-
252
- console.log($.bold().cyan(`\n> Using ${name}`));
253
-
254
- const builder = create_builder({ config, build_data, prerendered, log });
255
- await adapt(builder);
256
-
257
- log.success('done');
258
- }
259
-
260
- export { adapt };
@@ -0,0 +1,19 @@
1
+ import colors from 'kleur';
2
+ import { create_builder } from './builder.js';
3
+
4
+ /**
5
+ * @param {import('types').ValidatedConfig} config
6
+ * @param {import('types').BuildData} build_data
7
+ * @param {import('types').Prerendered} prerendered
8
+ * @param {{ log: import('types').Logger }} opts
9
+ */
10
+ export async function adapt(config, build_data, prerendered, { log }) {
11
+ const { name, adapt } = config.kit.adapter;
12
+
13
+ console.log(colors.bold().cyan(`\n> Using ${name}`));
14
+
15
+ const builder = create_builder({ config, build_data, prerendered, log });
16
+ await adapt(builder);
17
+
18
+ log.success('done');
19
+ }
@@ -0,0 +1,86 @@
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ import * as url from 'url';
4
+ import options from './options.js';
5
+
6
+ /**
7
+ * Loads the template (src/app.html by default) and validates that it has the
8
+ * required content.
9
+ * @param {string} cwd
10
+ * @param {import('types').ValidatedConfig} config
11
+ */
12
+ export function load_template(cwd, config) {
13
+ const { template } = config.kit.files;
14
+ const relative = path.relative(cwd, template);
15
+
16
+ if (fs.existsSync(template)) {
17
+ const contents = fs.readFileSync(template, 'utf8');
18
+
19
+ // TODO remove this for 1.0
20
+ const match = /%svelte\.([a-z]+)%/.exec(contents);
21
+ if (match) {
22
+ throw new Error(
23
+ `%svelte.${match[1]}% in ${relative} should be replaced with %sveltekit.${match[1]}%`
24
+ );
25
+ }
26
+
27
+ const expected_tags = ['%sveltekit.head%', '%sveltekit.body%'];
28
+ expected_tags.forEach((tag) => {
29
+ if (contents.indexOf(tag) === -1) {
30
+ throw new Error(`${relative} is missing ${tag}`);
31
+ }
32
+ });
33
+ } else {
34
+ throw new Error(`${relative} does not exist`);
35
+ }
36
+
37
+ return fs.readFileSync(template, 'utf-8');
38
+ }
39
+
40
+ /**
41
+ * Loads and validates svelte.config.js
42
+ * @param {{ cwd?: string }} options
43
+ * @returns {Promise<import('types').ValidatedConfig>}
44
+ */
45
+ export async function load_config({ cwd = process.cwd() } = {}) {
46
+ const config_file = path.join(cwd, 'svelte.config.js');
47
+
48
+ if (!fs.existsSync(config_file)) {
49
+ return process_config({}, { cwd });
50
+ }
51
+
52
+ const config = await import(`${url.pathToFileURL(config_file).href}?ts=${Date.now()}`);
53
+
54
+ return process_config(config.default, { cwd });
55
+ }
56
+
57
+ /**
58
+ * @param {import('types').Config} config
59
+ * @returns {import('types').ValidatedConfig}
60
+ */
61
+ function process_config(config, { cwd = process.cwd() } = {}) {
62
+ const validated = validate_config(config);
63
+
64
+ validated.kit.outDir = path.resolve(cwd, validated.kit.outDir);
65
+
66
+ for (const key in validated.kit.files) {
67
+ // @ts-expect-error this is typescript at its stupidest
68
+ validated.kit.files[key] = path.resolve(cwd, validated.kit.files[key]);
69
+ }
70
+
71
+ return validated;
72
+ }
73
+
74
+ /**
75
+ * @param {import('types').Config} config
76
+ * @returns {import('types').ValidatedConfig}
77
+ */
78
+ export function validate_config(config) {
79
+ if (typeof config !== 'object') {
80
+ throw new Error(
81
+ 'svelte.config.js must have a configuration object as its default export. See https://kit.svelte.dev/docs/configuration'
82
+ );
83
+ }
84
+
85
+ return options(config, 'config');
86
+ }
@@ -1,113 +1,4 @@
1
- import fs__default from 'fs';
2
- import path__default, { join } from 'path';
3
- import * as url from 'url';
4
-
5
- let FORCE_COLOR, NODE_DISABLE_COLORS, NO_COLOR, TERM, isTTY=true;
6
- if (typeof process !== 'undefined') {
7
- ({ FORCE_COLOR, NODE_DISABLE_COLORS, NO_COLOR, TERM } = process.env || {});
8
- isTTY = process.stdout && process.stdout.isTTY;
9
- }
10
-
11
- const $ = {
12
- enabled: !NODE_DISABLE_COLORS && NO_COLOR == null && TERM !== 'dumb' && (
13
- FORCE_COLOR != null && FORCE_COLOR !== '0' || isTTY
14
- ),
15
-
16
- // modifiers
17
- reset: init(0, 0),
18
- bold: init(1, 22),
19
- dim: init(2, 22),
20
- italic: init(3, 23),
21
- underline: init(4, 24),
22
- inverse: init(7, 27),
23
- hidden: init(8, 28),
24
- strikethrough: init(9, 29),
25
-
26
- // colors
27
- black: init(30, 39),
28
- red: init(31, 39),
29
- green: init(32, 39),
30
- yellow: init(33, 39),
31
- blue: init(34, 39),
32
- magenta: init(35, 39),
33
- cyan: init(36, 39),
34
- white: init(37, 39),
35
- gray: init(90, 39),
36
- grey: init(90, 39),
37
-
38
- // background colors
39
- bgBlack: init(40, 49),
40
- bgRed: init(41, 49),
41
- bgGreen: init(42, 49),
42
- bgYellow: init(43, 49),
43
- bgBlue: init(44, 49),
44
- bgMagenta: init(45, 49),
45
- bgCyan: init(46, 49),
46
- bgWhite: init(47, 49)
47
- };
48
-
49
- function run(arr, str) {
50
- let i=0, tmp, beg='', end='';
51
- for (; i < arr.length; i++) {
52
- tmp = arr[i];
53
- beg += tmp.open;
54
- end += tmp.close;
55
- if (!!~str.indexOf(tmp.close)) {
56
- str = str.replace(tmp.rgx, tmp.close + tmp.open);
57
- }
58
- }
59
- return beg + str + end;
60
- }
61
-
62
- function chain(has, keys) {
63
- let ctx = { has, keys };
64
-
65
- ctx.reset = $.reset.bind(ctx);
66
- ctx.bold = $.bold.bind(ctx);
67
- ctx.dim = $.dim.bind(ctx);
68
- ctx.italic = $.italic.bind(ctx);
69
- ctx.underline = $.underline.bind(ctx);
70
- ctx.inverse = $.inverse.bind(ctx);
71
- ctx.hidden = $.hidden.bind(ctx);
72
- ctx.strikethrough = $.strikethrough.bind(ctx);
73
-
74
- ctx.black = $.black.bind(ctx);
75
- ctx.red = $.red.bind(ctx);
76
- ctx.green = $.green.bind(ctx);
77
- ctx.yellow = $.yellow.bind(ctx);
78
- ctx.blue = $.blue.bind(ctx);
79
- ctx.magenta = $.magenta.bind(ctx);
80
- ctx.cyan = $.cyan.bind(ctx);
81
- ctx.white = $.white.bind(ctx);
82
- ctx.gray = $.gray.bind(ctx);
83
- ctx.grey = $.grey.bind(ctx);
84
-
85
- ctx.bgBlack = $.bgBlack.bind(ctx);
86
- ctx.bgRed = $.bgRed.bind(ctx);
87
- ctx.bgGreen = $.bgGreen.bind(ctx);
88
- ctx.bgYellow = $.bgYellow.bind(ctx);
89
- ctx.bgBlue = $.bgBlue.bind(ctx);
90
- ctx.bgMagenta = $.bgMagenta.bind(ctx);
91
- ctx.bgCyan = $.bgCyan.bind(ctx);
92
- ctx.bgWhite = $.bgWhite.bind(ctx);
93
-
94
- return ctx;
95
- }
96
-
97
- function init(open, close) {
98
- let blk = {
99
- open: `\x1b[${open}m`,
100
- close: `\x1b[${close}m`,
101
- rgx: new RegExp(`\\x1b\\[${close}m`, 'g')
102
- };
103
- return function (txt) {
104
- if (this !== void 0 && this.has !== void 0) {
105
- !!~this.has.indexOf(open) || (this.has.push(open),this.keys.push(blk));
106
- return txt === void 0 ? this : $.enabled ? run(this.keys, txt+'') : txt+'';
107
- }
108
- return txt === void 0 ? chain([open], [blk]) : $.enabled ? run([blk], txt+'') : txt+'';
109
- };
110
- }
1
+ import { join } from 'path';
111
2
 
112
3
  /** @typedef {import('./types').Validator} Validator */
113
4
 
@@ -400,7 +291,11 @@ const options = object(
400
291
  // TODO remove for 1.0
401
292
  router: error((keypath) => `${keypath} has been moved to config.kit.browser.router`),
402
293
 
403
- routes: fun((filepath) => !/(?:(?:^_|\/_)|(?:^\.|\/\.)(?!well-known))/.test(filepath)),
294
+ // TODO remove for 1.0
295
+ routes: error(
296
+ (keypath) =>
297
+ `${keypath} has been removed. See https://github.com/sveltejs/kit/discussions/5774 for details`
298
+ ),
404
299
 
405
300
  serviceWorker: object({
406
301
  register: boolean(true),
@@ -590,86 +485,4 @@ function error(fn) {
590
485
  });
591
486
  }
592
487
 
593
- /**
594
- * Loads the template (src/app.html by default) and validates that it has the
595
- * required content.
596
- * @param {string} cwd
597
- * @param {import('types').ValidatedConfig} config
598
- */
599
- function load_template(cwd, config) {
600
- const { template } = config.kit.files;
601
- const relative = path__default.relative(cwd, template);
602
-
603
- if (fs__default.existsSync(template)) {
604
- const contents = fs__default.readFileSync(template, 'utf8');
605
-
606
- // TODO remove this for 1.0
607
- const match = /%svelte\.([a-z]+)%/.exec(contents);
608
- if (match) {
609
- throw new Error(
610
- `%svelte.${match[1]}% in ${relative} should be replaced with %sveltekit.${match[1]}%`
611
- );
612
- }
613
-
614
- const expected_tags = ['%sveltekit.head%', '%sveltekit.body%'];
615
- expected_tags.forEach((tag) => {
616
- if (contents.indexOf(tag) === -1) {
617
- throw new Error(`${relative} is missing ${tag}`);
618
- }
619
- });
620
- } else {
621
- throw new Error(`${relative} does not exist`);
622
- }
623
-
624
- return fs__default.readFileSync(template, 'utf-8');
625
- }
626
-
627
- /**
628
- * Loads and validates svelte.config.js
629
- * @param {{ cwd?: string }} options
630
- * @returns {Promise<import('types').ValidatedConfig>}
631
- */
632
- async function load_config({ cwd = process.cwd() } = {}) {
633
- const config_file = path__default.join(cwd, 'svelte.config.js');
634
-
635
- if (!fs__default.existsSync(config_file)) {
636
- return process_config({}, { cwd });
637
- }
638
-
639
- const config = await import(`${url.pathToFileURL(config_file).href}?ts=${Date.now()}`);
640
-
641
- return process_config(config.default, { cwd });
642
- }
643
-
644
- /**
645
- * @param {import('types').Config} config
646
- * @returns {import('types').ValidatedConfig}
647
- */
648
- function process_config(config, { cwd = process.cwd() } = {}) {
649
- const validated = validate_config(config);
650
-
651
- validated.kit.outDir = path__default.resolve(cwd, validated.kit.outDir);
652
-
653
- for (const key in validated.kit.files) {
654
- // @ts-expect-error this is typescript at its stupidest
655
- validated.kit.files[key] = path__default.resolve(cwd, validated.kit.files[key]);
656
- }
657
-
658
- return validated;
659
- }
660
-
661
- /**
662
- * @param {import('types').Config} config
663
- * @returns {import('types').ValidatedConfig}
664
- */
665
- function validate_config(config) {
666
- if (typeof config !== 'object') {
667
- throw new Error(
668
- 'svelte.config.js must have a configuration object as its default export. See https://kit.svelte.dev/docs/configuration'
669
- );
670
- }
671
-
672
- return options(config, 'config');
673
- }
674
-
675
- export { $, load_template as a, load_config as l };
488
+ export default options;
@@ -0,0 +1 @@
1
+ export type Validator<T = any> = (input: T, keypath: string) => T;
@@ -0,0 +1,3 @@
1
+ // in `vite dev` and `vite preview`, we use a fake asset path so that we can
2
+ // serve local assets while verifying that requests are correctly prefixed
3
+ export const SVELTE_KIT_ASSETS = '/_svelte_kit_assets';