@sveltejs/kit 1.0.0-next.50 → 1.0.0-next.501
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/README.md +12 -9
- package/package.json +94 -67
- package/postinstall.js +38 -0
- package/scripts/special-types/$env+dynamic+private.md +10 -0
- package/scripts/special-types/$env+dynamic+public.md +8 -0
- package/scripts/special-types/$env+static+private.md +19 -0
- package/scripts/special-types/$env+static+public.md +7 -0
- package/scripts/special-types/$lib.md +5 -0
- package/src/cli.js +108 -0
- package/src/constants.js +7 -0
- package/src/core/adapt/builder.js +206 -0
- package/src/core/adapt/index.js +31 -0
- package/src/core/config/default-error.html +56 -0
- package/src/core/config/index.js +110 -0
- package/src/core/config/options.js +504 -0
- package/src/core/config/types.d.ts +1 -0
- package/src/core/env.js +121 -0
- package/src/core/generate_manifest/index.js +93 -0
- package/src/core/prerender/crawl.js +198 -0
- package/src/core/prerender/entities.js +2252 -0
- package/src/core/prerender/prerender.js +431 -0
- package/src/core/prerender/queue.js +80 -0
- package/src/core/sync/create_manifest_data/index.js +488 -0
- package/src/core/sync/create_manifest_data/types.d.ts +37 -0
- package/src/core/sync/sync.js +70 -0
- package/src/core/sync/utils.js +33 -0
- package/src/core/sync/write_ambient.js +53 -0
- package/src/core/sync/write_client_manifest.js +106 -0
- package/src/core/sync/write_matchers.js +25 -0
- package/src/core/sync/write_root.js +91 -0
- package/src/core/sync/write_tsconfig.js +195 -0
- package/src/core/sync/write_types/index.js +678 -0
- package/src/core/utils.js +70 -0
- package/src/exports/hooks/index.js +1 -0
- package/src/exports/hooks/sequence.js +44 -0
- package/src/exports/index.js +45 -0
- package/src/exports/node/index.js +173 -0
- package/src/exports/node/polyfills.js +41 -0
- package/src/exports/vite/build/build_server.js +378 -0
- package/src/exports/vite/build/build_service_worker.js +90 -0
- package/src/exports/vite/build/utils.js +180 -0
- package/src/exports/vite/dev/index.js +577 -0
- package/src/exports/vite/graph_analysis/index.js +277 -0
- package/src/exports/vite/graph_analysis/types.d.ts +5 -0
- package/src/exports/vite/graph_analysis/utils.js +30 -0
- package/src/exports/vite/index.js +598 -0
- package/src/exports/vite/preview/index.js +189 -0
- package/src/exports/vite/types.d.ts +3 -0
- package/src/exports/vite/utils.js +157 -0
- package/src/runtime/app/env.js +1 -0
- package/src/runtime/app/environment.js +11 -0
- package/src/runtime/app/forms.js +114 -0
- package/src/runtime/app/navigation.js +23 -0
- package/src/runtime/app/paths.js +1 -0
- package/src/runtime/app/stores.js +102 -0
- package/src/runtime/client/ambient.d.ts +30 -0
- package/src/runtime/client/client.js +1585 -0
- package/src/runtime/client/fetcher.js +107 -0
- package/src/runtime/client/parse.js +60 -0
- package/src/runtime/client/singletons.js +21 -0
- package/src/runtime/client/start.js +37 -0
- package/src/runtime/client/types.d.ts +84 -0
- package/src/runtime/client/utils.js +159 -0
- package/src/runtime/components/error.svelte +16 -0
- package/{assets → src/runtime}/components/layout.svelte +0 -0
- package/src/runtime/control.js +98 -0
- package/src/runtime/env/dynamic/private.js +1 -0
- package/src/runtime/env/dynamic/public.js +1 -0
- package/src/runtime/env-private.js +6 -0
- package/src/runtime/env-public.js +6 -0
- package/src/runtime/env.js +6 -0
- package/src/runtime/hash.js +16 -0
- package/src/runtime/paths.js +11 -0
- package/src/runtime/server/cookie.js +127 -0
- package/src/runtime/server/data/index.js +136 -0
- package/src/runtime/server/endpoint.js +90 -0
- package/src/runtime/server/index.js +340 -0
- package/src/runtime/server/page/actions.js +243 -0
- package/src/runtime/server/page/crypto.js +239 -0
- package/src/runtime/server/page/csp.js +250 -0
- package/src/runtime/server/page/fetch.js +301 -0
- package/src/runtime/server/page/index.js +304 -0
- package/src/runtime/server/page/load_data.js +112 -0
- package/src/runtime/server/page/render.js +342 -0
- package/src/runtime/server/page/respond_with_error.js +104 -0
- package/src/runtime/server/page/serialize_data.js +87 -0
- package/src/runtime/server/page/types.d.ts +41 -0
- package/src/runtime/server/utils.js +179 -0
- package/src/utils/array.js +9 -0
- package/src/utils/error.js +22 -0
- package/src/utils/escape.js +46 -0
- package/src/utils/filesystem.js +137 -0
- package/src/utils/functions.js +16 -0
- package/src/utils/http.js +55 -0
- package/src/utils/misc.js +1 -0
- package/src/utils/promises.js +17 -0
- package/src/utils/routing.js +117 -0
- package/src/utils/unit_test.js +11 -0
- package/src/utils/url.js +142 -0
- package/svelte-kit.js +1 -1
- package/types/ambient.d.ts +426 -0
- package/types/index.d.ts +444 -0
- package/types/internal.d.ts +378 -0
- package/types/private.d.ts +224 -0
- package/CHANGELOG.md +0 -484
- package/assets/components/error.svelte +0 -13
- package/assets/runtime/app/env.js +0 -5
- package/assets/runtime/app/navigation.js +0 -44
- package/assets/runtime/app/paths.js +0 -1
- package/assets/runtime/app/stores.js +0 -93
- package/assets/runtime/chunks/utils.js +0 -22
- package/assets/runtime/internal/singletons.js +0 -23
- package/assets/runtime/internal/start.js +0 -779
- package/assets/runtime/paths.js +0 -12
- package/dist/chunks/index.js +0 -3516
- package/dist/chunks/index2.js +0 -587
- package/dist/chunks/index3.js +0 -246
- package/dist/chunks/index4.js +0 -528
- package/dist/chunks/index5.js +0 -763
- package/dist/chunks/index6.js +0 -322
- package/dist/chunks/standard.js +0 -99
- package/dist/chunks/utils.js +0 -83
- package/dist/cli.js +0 -550
- package/dist/ssr.js +0 -2588
- package/types.d.ts +0 -89
- package/types.internal.d.ts +0 -191
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { relative } from 'path';
|
|
2
|
+
import { posixify, resolve_entry } from '../../utils/filesystem.js';
|
|
3
|
+
import { s } from '../../utils/misc.js';
|
|
4
|
+
import { trim, write_if_changed } from './utils.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Writes the client manifest to disk. The manifest is used to power the router. It contains the
|
|
8
|
+
* list of routes and corresponding Svelte components (i.e. pages and layouts).
|
|
9
|
+
* @param {import('types').ValidatedConfig} config
|
|
10
|
+
* @param {import('types').ManifestData} manifest_data
|
|
11
|
+
* @param {string} output
|
|
12
|
+
*/
|
|
13
|
+
export function write_client_manifest(config, manifest_data, output) {
|
|
14
|
+
/**
|
|
15
|
+
* Creates a module that exports a `CSRPageNode`
|
|
16
|
+
* @param {import('types').PageNode} node
|
|
17
|
+
*/
|
|
18
|
+
function generate_node(node) {
|
|
19
|
+
const declarations = [];
|
|
20
|
+
|
|
21
|
+
if (node.shared) {
|
|
22
|
+
declarations.push(
|
|
23
|
+
`import * as shared from ${s(relative(`${output}/nodes`, node.shared))};`,
|
|
24
|
+
`export { shared };`
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (node.component) {
|
|
29
|
+
declarations.push(
|
|
30
|
+
`export { default as component } from ${s(relative(`${output}/nodes`, node.component))};`
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (node.server) {
|
|
35
|
+
declarations.push(`export const server = true;`);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return declarations.join('\n');
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const nodes = manifest_data.nodes
|
|
42
|
+
.map((node, i) => {
|
|
43
|
+
write_if_changed(`${output}/nodes/${i}.js`, generate_node(node));
|
|
44
|
+
return `() => import('./nodes/${i}')`;
|
|
45
|
+
})
|
|
46
|
+
.join(',\n\t');
|
|
47
|
+
|
|
48
|
+
const layouts_with_server_load = new Set();
|
|
49
|
+
|
|
50
|
+
const dictionary = `{
|
|
51
|
+
${manifest_data.routes
|
|
52
|
+
.map((route) => {
|
|
53
|
+
if (route.page) {
|
|
54
|
+
const errors = route.page.errors.slice(1).map((n) => n ?? '');
|
|
55
|
+
const layouts = route.page.layouts.slice(1).map((n) => n ?? '');
|
|
56
|
+
|
|
57
|
+
while (layouts.at(-1) === '') layouts.pop();
|
|
58
|
+
while (errors.at(-1) === '') errors.pop();
|
|
59
|
+
|
|
60
|
+
// Encode whether or not the route uses server data
|
|
61
|
+
// using the ones' complement, to save space
|
|
62
|
+
const array = [`${route.leaf?.server ? '~' : ''}${route.page.leaf}`];
|
|
63
|
+
// Encode whether or not the layout uses server data.
|
|
64
|
+
// It's a different method compared to pages because layouts
|
|
65
|
+
// are reused across pages, so we safe space by doing it this way.
|
|
66
|
+
route.page.layouts.forEach((layout) => {
|
|
67
|
+
if (layout != undefined && manifest_data.nodes[layout].server) {
|
|
68
|
+
layouts_with_server_load.add(layout);
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
// only include non-root layout/error nodes if they exist
|
|
73
|
+
if (layouts.length > 0 || errors.length > 0) array.push(`[${layouts.join(',')}]`);
|
|
74
|
+
if (errors.length > 0) array.push(`[${errors.join(',')}]`);
|
|
75
|
+
|
|
76
|
+
return `${s(route.id)}: [${array.join(',')}]`;
|
|
77
|
+
}
|
|
78
|
+
})
|
|
79
|
+
.filter(Boolean)
|
|
80
|
+
.join(',\n\t\t')}
|
|
81
|
+
}`.replace(/^\t/gm, '');
|
|
82
|
+
|
|
83
|
+
const hooks_file = resolve_entry(config.kit.files.hooks.client);
|
|
84
|
+
|
|
85
|
+
// String representation of __GENERATED__/client-manifest.js
|
|
86
|
+
write_if_changed(
|
|
87
|
+
`${output}/client-manifest.js`,
|
|
88
|
+
trim(`
|
|
89
|
+
${hooks_file ? `import * as client_hooks from '${posixify(relative(output, hooks_file))}';` : ''}
|
|
90
|
+
|
|
91
|
+
export { matchers } from './client-matchers.js';
|
|
92
|
+
|
|
93
|
+
export const nodes = [${nodes}];
|
|
94
|
+
|
|
95
|
+
export const server_loads = [${[...layouts_with_server_load].join(',')}];
|
|
96
|
+
|
|
97
|
+
export const dictionary = ${dictionary};
|
|
98
|
+
|
|
99
|
+
export const hooks = {
|
|
100
|
+
handleError: ${
|
|
101
|
+
hooks_file ? 'client_hooks.handleError || ' : ''
|
|
102
|
+
}(({ error }) => { console.error(error) }),
|
|
103
|
+
};
|
|
104
|
+
`)
|
|
105
|
+
);
|
|
106
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { s } from '../../utils/misc.js';
|
|
3
|
+
import { write_if_changed } from './utils.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @param {import('types').ManifestData} manifest_data
|
|
7
|
+
* @param {string} output
|
|
8
|
+
*/
|
|
9
|
+
export function write_matchers(manifest_data, output) {
|
|
10
|
+
const imports = [];
|
|
11
|
+
const matchers = [];
|
|
12
|
+
|
|
13
|
+
for (const key in manifest_data.matchers) {
|
|
14
|
+
const src = manifest_data.matchers[key];
|
|
15
|
+
|
|
16
|
+
imports.push(`import { match as ${key} } from ${s(path.relative(output, src))};`);
|
|
17
|
+
matchers.push(key);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const module = imports.length
|
|
21
|
+
? `${imports.join('\n')}\n\nexport const matchers = { ${matchers.join(', ')} };`
|
|
22
|
+
: 'export const matchers = {};';
|
|
23
|
+
|
|
24
|
+
write_if_changed(`${output}/client-matchers.js`, module);
|
|
25
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { trim, write_if_changed } from './utils.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @param {import('types').ManifestData} manifest_data
|
|
5
|
+
* @param {string} output
|
|
6
|
+
*/
|
|
7
|
+
export function write_root(manifest_data, output) {
|
|
8
|
+
// TODO remove default layout altogether
|
|
9
|
+
|
|
10
|
+
const max_depth = Math.max(
|
|
11
|
+
...manifest_data.routes.map((route) =>
|
|
12
|
+
route.page ? route.page.layouts.filter(Boolean).length + 1 : 0
|
|
13
|
+
),
|
|
14
|
+
1
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
const levels = [];
|
|
18
|
+
for (let i = 0; i <= max_depth; i += 1) {
|
|
19
|
+
levels.push(i);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
let l = max_depth;
|
|
23
|
+
|
|
24
|
+
let pyramid = `<svelte:component this={components[${l}]} data={data_${l}} {form} />`;
|
|
25
|
+
|
|
26
|
+
while (l--) {
|
|
27
|
+
pyramid = `
|
|
28
|
+
{#if components[${l + 1}]}
|
|
29
|
+
<svelte:component this={components[${l}]} data={data_${l}}>
|
|
30
|
+
${pyramid.replace(/\n/g, '\n\t\t\t\t\t')}
|
|
31
|
+
</svelte:component>
|
|
32
|
+
{:else}
|
|
33
|
+
<svelte:component this={components[${l}]} data={data_${l}} {form} />
|
|
34
|
+
{/if}
|
|
35
|
+
`
|
|
36
|
+
.replace(/^\t\t\t/gm, '')
|
|
37
|
+
.trim();
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
write_if_changed(
|
|
41
|
+
`${output}/root.svelte`,
|
|
42
|
+
trim(`
|
|
43
|
+
<!-- This file is generated by @sveltejs/kit — do not edit it! -->
|
|
44
|
+
<script>
|
|
45
|
+
import { setContext, afterUpdate, onMount } from 'svelte';
|
|
46
|
+
import { browser } from '$app/environment';
|
|
47
|
+
|
|
48
|
+
// stores
|
|
49
|
+
export let stores;
|
|
50
|
+
export let page;
|
|
51
|
+
|
|
52
|
+
export let components;
|
|
53
|
+
export let form;
|
|
54
|
+
${levels.map((l) => `export let data_${l} = null;`).join('\n\t\t\t\t')}
|
|
55
|
+
|
|
56
|
+
if (!browser) {
|
|
57
|
+
setContext('__svelte__', stores);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
$: stores.page.set(page);
|
|
61
|
+
afterUpdate(stores.page.notify);
|
|
62
|
+
|
|
63
|
+
let mounted = false;
|
|
64
|
+
let navigated = false;
|
|
65
|
+
let title = null;
|
|
66
|
+
|
|
67
|
+
onMount(() => {
|
|
68
|
+
const unsubscribe = stores.page.subscribe(() => {
|
|
69
|
+
if (mounted) {
|
|
70
|
+
navigated = true;
|
|
71
|
+
title = document.title || 'untitled page';
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
mounted = true;
|
|
76
|
+
return unsubscribe;
|
|
77
|
+
});
|
|
78
|
+
</script>
|
|
79
|
+
|
|
80
|
+
${pyramid.replace(/\n/g, '\n\t\t\t')}
|
|
81
|
+
|
|
82
|
+
{#if mounted}
|
|
83
|
+
<div id="svelte-announcer" aria-live="assertive" aria-atomic="true" style="position: absolute; left: 0; top: 0; clip: rect(0 0 0 0); clip-path: inset(50%); overflow: hidden; white-space: nowrap; width: 1px; height: 1px">
|
|
84
|
+
{#if navigated}
|
|
85
|
+
{title}
|
|
86
|
+
{/if}
|
|
87
|
+
</div>
|
|
88
|
+
{/if}
|
|
89
|
+
`)
|
|
90
|
+
);
|
|
91
|
+
}
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import colors from 'kleur';
|
|
4
|
+
import { posixify } from '../../utils/filesystem.js';
|
|
5
|
+
import { write_if_changed } from './utils.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @param {string} cwd
|
|
9
|
+
* @param {string} file
|
|
10
|
+
*/
|
|
11
|
+
function maybe_file(cwd, file) {
|
|
12
|
+
const resolved = path.resolve(cwd, file);
|
|
13
|
+
if (fs.existsSync(resolved)) {
|
|
14
|
+
return resolved;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @param {string} file
|
|
20
|
+
*/
|
|
21
|
+
function project_relative(file) {
|
|
22
|
+
return posixify(path.relative('.', file));
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @param {string} file
|
|
27
|
+
*/
|
|
28
|
+
function remove_trailing_slashstar(file) {
|
|
29
|
+
if (file.endsWith('/*')) {
|
|
30
|
+
return file.slice(0, -2);
|
|
31
|
+
} else {
|
|
32
|
+
return file;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Writes the tsconfig that the user's tsconfig inherits from.
|
|
38
|
+
* @param {import('types').ValidatedKitConfig} config
|
|
39
|
+
*/
|
|
40
|
+
export function write_tsconfig(config, cwd = process.cwd()) {
|
|
41
|
+
const out = path.join(config.outDir, 'tsconfig.json');
|
|
42
|
+
const user_file = maybe_file(cwd, 'tsconfig.json') || maybe_file(cwd, 'jsconfig.json');
|
|
43
|
+
|
|
44
|
+
if (user_file) validate(config, cwd, out, user_file);
|
|
45
|
+
|
|
46
|
+
/** @param {string} file */
|
|
47
|
+
const config_relative = (file) => posixify(path.relative(config.outDir, file));
|
|
48
|
+
|
|
49
|
+
const include = ['ambient.d.ts', config_relative('vite.config.ts')];
|
|
50
|
+
for (const dir of [config.files.routes, config.files.lib]) {
|
|
51
|
+
const relative = project_relative(path.dirname(dir));
|
|
52
|
+
include.push(config_relative(`${relative}/**/*.js`));
|
|
53
|
+
include.push(config_relative(`${relative}/**/*.ts`));
|
|
54
|
+
include.push(config_relative(`${relative}/**/*.svelte`));
|
|
55
|
+
}
|
|
56
|
+
// Test folder is a special case - we advocate putting tests in a top-level test folder
|
|
57
|
+
// and it's not configurable (should we make it?)
|
|
58
|
+
const test_folder = project_relative('tests');
|
|
59
|
+
include.push(config_relative(`${test_folder}/**/*.js`));
|
|
60
|
+
include.push(config_relative(`${test_folder}/**/*.ts`));
|
|
61
|
+
include.push(config_relative(`${test_folder}/**/*.svelte`));
|
|
62
|
+
|
|
63
|
+
write_if_changed(
|
|
64
|
+
out,
|
|
65
|
+
JSON.stringify(
|
|
66
|
+
{
|
|
67
|
+
compilerOptions: {
|
|
68
|
+
// generated options
|
|
69
|
+
baseUrl: config_relative('.'),
|
|
70
|
+
paths: get_tsconfig_paths(config),
|
|
71
|
+
rootDirs: [config_relative('.'), './types'],
|
|
72
|
+
|
|
73
|
+
// essential options
|
|
74
|
+
// svelte-preprocess cannot figure out whether you have a value or a type, so tell TypeScript
|
|
75
|
+
// to enforce using \`import type\` instead of \`import\` for Types.
|
|
76
|
+
importsNotUsedAsValues: 'error',
|
|
77
|
+
// Vite compiles modules one at a time
|
|
78
|
+
isolatedModules: true,
|
|
79
|
+
// TypeScript doesn't know about import usages in the template because it only sees the
|
|
80
|
+
// script of a Svelte file. Therefore preserve all value imports. Requires TS 4.5 or higher.
|
|
81
|
+
preserveValueImports: true,
|
|
82
|
+
|
|
83
|
+
// This is required for svelte-package to work as expected
|
|
84
|
+
// Can be overwritten
|
|
85
|
+
lib: ['esnext', 'DOM', 'DOM.Iterable'],
|
|
86
|
+
moduleResolution: 'node',
|
|
87
|
+
module: 'esnext',
|
|
88
|
+
target: 'esnext'
|
|
89
|
+
},
|
|
90
|
+
include,
|
|
91
|
+
exclude: [config_relative('node_modules/**'), './[!ambient.d.ts]**']
|
|
92
|
+
},
|
|
93
|
+
null,
|
|
94
|
+
'\t'
|
|
95
|
+
)
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* @param {import('types').ValidatedKitConfig} config
|
|
101
|
+
* @param {string} cwd
|
|
102
|
+
* @param {string} out
|
|
103
|
+
* @param {string} user_file
|
|
104
|
+
*/
|
|
105
|
+
function validate(config, cwd, out, user_file) {
|
|
106
|
+
// we have to eval the file, since it's not parseable as JSON (contains comments)
|
|
107
|
+
const user_tsconfig_json = fs.readFileSync(user_file, 'utf-8');
|
|
108
|
+
const user_tsconfig = (0, eval)(`(${user_tsconfig_json})`);
|
|
109
|
+
|
|
110
|
+
// we need to check that the user's tsconfig extends the framework config
|
|
111
|
+
const extend = user_tsconfig.extends;
|
|
112
|
+
const extends_framework_config = extend && path.resolve(cwd, extend) === out;
|
|
113
|
+
|
|
114
|
+
const kind = path.basename(user_file);
|
|
115
|
+
|
|
116
|
+
if (extends_framework_config) {
|
|
117
|
+
const { paths: user_paths } = user_tsconfig.compilerOptions || {};
|
|
118
|
+
|
|
119
|
+
if (user_paths && fs.existsSync(config.files.lib)) {
|
|
120
|
+
/** @type {string[]} */
|
|
121
|
+
const lib = user_paths['$lib'] || [];
|
|
122
|
+
/** @type {string[]} */
|
|
123
|
+
const lib_ = user_paths['$lib/*'] || [];
|
|
124
|
+
|
|
125
|
+
const missing_lib_paths =
|
|
126
|
+
!lib.some((relative) => path.resolve(cwd, relative) === config.files.lib) ||
|
|
127
|
+
!lib_.some((relative) => path.resolve(cwd, relative) === path.join(config.files.lib, '/*'));
|
|
128
|
+
|
|
129
|
+
if (missing_lib_paths) {
|
|
130
|
+
console.warn(
|
|
131
|
+
colors
|
|
132
|
+
.bold()
|
|
133
|
+
.yellow(`Your compilerOptions.paths in ${kind} should include the following:`)
|
|
134
|
+
);
|
|
135
|
+
const relative = posixify(path.relative('.', config.files.lib));
|
|
136
|
+
console.warn(`{\n "$lib":["${relative}"],\n "$lib/*":["${relative}/*"]\n}`);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
} else {
|
|
140
|
+
let relative = posixify(path.relative('.', out));
|
|
141
|
+
if (!relative.startsWith('./')) relative = './' + relative;
|
|
142
|
+
|
|
143
|
+
console.warn(
|
|
144
|
+
colors.bold().yellow(`Your ${kind} should extend the configuration generated by SvelteKit:`)
|
|
145
|
+
);
|
|
146
|
+
console.warn(`{\n "extends": "${relative}"\n}`);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// <something><optional /*>
|
|
151
|
+
const alias_regex = /^(.+?)(\/\*)?$/;
|
|
152
|
+
// <path><optional /* or .fileending>
|
|
153
|
+
const value_regex = /^(.*?)((\/\*)|(\.\w+))?$/;
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Generates tsconfig path aliases from kit's aliases.
|
|
157
|
+
* Related to vite alias creation.
|
|
158
|
+
*
|
|
159
|
+
* @param {import('types').ValidatedKitConfig} config
|
|
160
|
+
*/
|
|
161
|
+
export function get_tsconfig_paths(config) {
|
|
162
|
+
const alias = {
|
|
163
|
+
...config.alias
|
|
164
|
+
};
|
|
165
|
+
if (fs.existsSync(project_relative(config.files.lib))) {
|
|
166
|
+
alias['$lib'] = project_relative(config.files.lib);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/** @type {Record<string, string[]>} */
|
|
170
|
+
const paths = {};
|
|
171
|
+
|
|
172
|
+
for (const [key, value] of Object.entries(alias)) {
|
|
173
|
+
const key_match = alias_regex.exec(key);
|
|
174
|
+
if (!key_match) throw new Error(`Invalid alias key: ${key}`);
|
|
175
|
+
|
|
176
|
+
const value_match = value_regex.exec(value);
|
|
177
|
+
if (!value_match) throw new Error(`Invalid alias value: ${value}`);
|
|
178
|
+
|
|
179
|
+
const rel_path = project_relative(remove_trailing_slashstar(value));
|
|
180
|
+
const slashstar = key_match[2];
|
|
181
|
+
|
|
182
|
+
if (slashstar) {
|
|
183
|
+
paths[key] = [rel_path + '/*'];
|
|
184
|
+
} else {
|
|
185
|
+
paths[key] = [rel_path];
|
|
186
|
+
const fileending = value_match[4];
|
|
187
|
+
|
|
188
|
+
if (!fileending && !(key + '/*' in alias)) {
|
|
189
|
+
paths[key + '/*'] = [rel_path + '/*'];
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
return paths;
|
|
195
|
+
}
|