@sveltejs/kit 1.0.0-next.399 → 1.0.0-next.400
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/dist/chunks/sync.js +33 -13
- package/dist/chunks/write_tsconfig.js +77 -21
- package/dist/cli.js +1 -1
- package/package.json +1 -1
package/dist/chunks/sync.js
CHANGED
|
@@ -1003,25 +1003,45 @@ function merge_into(a, b) {
|
|
|
1003
1003
|
}
|
|
1004
1004
|
}
|
|
1005
1005
|
|
|
1006
|
-
/**
|
|
1006
|
+
/**
|
|
1007
|
+
* Transforms kit.alias to a valid vite.resolve.alias array.
|
|
1008
|
+
* Related to tsconfig path alias creation.
|
|
1009
|
+
*
|
|
1010
|
+
* @param {import('types').ValidatedKitConfig} config
|
|
1011
|
+
* */
|
|
1007
1012
|
function get_aliases(config) {
|
|
1008
|
-
/** @type {
|
|
1009
|
-
const alias =
|
|
1010
|
-
__GENERATED__: path__default.posix.join(config.outDir, 'generated'),
|
|
1011
|
-
|
|
1012
|
-
$app: `${get_runtime_directory(config)}/app`,
|
|
1013
|
-
|
|
1013
|
+
/** @type {import('vite').Alias[]} */
|
|
1014
|
+
const alias = [
|
|
1015
|
+
{ find: '__GENERATED__', replacement: path__default.posix.join(config.outDir, 'generated') },
|
|
1016
|
+
{ find: '$app', replacement: `${get_runtime_directory(config)}/app` },
|
|
1014
1017
|
// For now, we handle `$lib` specially here rather than make it a default value for
|
|
1015
1018
|
// `config.kit.alias` since it has special meaning for packaging, etc.
|
|
1016
|
-
$lib: config.files.lib
|
|
1017
|
-
|
|
1019
|
+
{ find: '$lib', replacement: config.files.lib }
|
|
1020
|
+
];
|
|
1018
1021
|
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1022
|
+
for (let [key, value] of Object.entries(config.alias)) {
|
|
1023
|
+
if (value.endsWith('/*')) {
|
|
1024
|
+
value = value.slice(0, -2);
|
|
1025
|
+
}
|
|
1026
|
+
if (key.endsWith('/*')) {
|
|
1027
|
+
// Doing just `{ find: key.slice(0, -2) ,..}` would mean `import .. from "key"` would also be matched, which we don't want
|
|
1028
|
+
alias.push({
|
|
1029
|
+
find: new RegExp(`^${key.slice(0, -2)}\\/(.+)$`),
|
|
1030
|
+
replacement: `${path__default.resolve(value)}/$1`
|
|
1031
|
+
});
|
|
1032
|
+
} else if (key + '/*' in config.alias) {
|
|
1033
|
+
// key and key/* both exist -> the replacement for key needs to happen _only_ on import .. from "key"
|
|
1034
|
+
alias.push({ find: new RegExp(`^${key}$`), replacement: path__default.resolve(value) });
|
|
1035
|
+
} else {
|
|
1036
|
+
alias.push({ find: key, replacement: path__default.resolve(value) });
|
|
1037
|
+
}
|
|
1023
1038
|
}
|
|
1024
1039
|
|
|
1040
|
+
alias.push({
|
|
1041
|
+
find: '$env',
|
|
1042
|
+
replacement: `${get_runtime_directory(config)}/env`
|
|
1043
|
+
});
|
|
1044
|
+
|
|
1025
1045
|
return alias;
|
|
1026
1046
|
}
|
|
1027
1047
|
|
|
@@ -86,8 +86,34 @@ const reserved = new Set([
|
|
|
86
86
|
|
|
87
87
|
const valid_identifier = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/;
|
|
88
88
|
|
|
89
|
-
/**
|
|
90
|
-
|
|
89
|
+
/**
|
|
90
|
+
* @param {string} cwd
|
|
91
|
+
* @param {string} file
|
|
92
|
+
*/
|
|
93
|
+
function maybe_file(cwd, file) {
|
|
94
|
+
const resolved = path__default.resolve(cwd, file);
|
|
95
|
+
if (fs__default.existsSync(resolved)) {
|
|
96
|
+
return resolved;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* @param {string} file
|
|
102
|
+
*/
|
|
103
|
+
function project_relative(file) {
|
|
104
|
+
return posixify(path__default.relative('.', file));
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* @param {string} file
|
|
109
|
+
*/
|
|
110
|
+
function remove_trailing_slashstar(file) {
|
|
111
|
+
if (file.endsWith('/*')) {
|
|
112
|
+
return file.slice(0, -2);
|
|
113
|
+
} else {
|
|
114
|
+
return file;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
91
117
|
|
|
92
118
|
/**
|
|
93
119
|
* Writes the tsconfig that the user's tsconfig inherits from.
|
|
@@ -95,14 +121,10 @@ const exists = (file) => fs__default.existsSync(file) && file;
|
|
|
95
121
|
*/
|
|
96
122
|
function write_tsconfig(config, cwd = process.cwd()) {
|
|
97
123
|
const out = path__default.join(config.outDir, 'tsconfig.json');
|
|
98
|
-
const user_file =
|
|
99
|
-
exists(path__default.resolve(cwd, 'tsconfig.json')) || exists(path__default.resolve(cwd, 'jsconfig.json'));
|
|
124
|
+
const user_file = maybe_file(cwd, 'tsconfig.json') || maybe_file(cwd, 'jsconfig.json');
|
|
100
125
|
|
|
101
126
|
if (user_file) validate(config, cwd, out, user_file);
|
|
102
127
|
|
|
103
|
-
/** @param {string} file */
|
|
104
|
-
const project_relative = (file) => posixify(path__default.relative('.', file));
|
|
105
|
-
|
|
106
128
|
/** @param {string} file */
|
|
107
129
|
const config_relative = (file) => posixify(path__default.relative(config.outDir, file));
|
|
108
130
|
|
|
@@ -114,19 +136,6 @@ function write_tsconfig(config, cwd = process.cwd()) {
|
|
|
114
136
|
include.push(config_relative(`${relative}/**/*.svelte`));
|
|
115
137
|
}
|
|
116
138
|
|
|
117
|
-
/** @type {Record<string, string[]>} */
|
|
118
|
-
const paths = {};
|
|
119
|
-
const alias = {
|
|
120
|
-
$lib: project_relative(config.files.lib),
|
|
121
|
-
...config.alias
|
|
122
|
-
};
|
|
123
|
-
for (const [key, value] of Object.entries(alias)) {
|
|
124
|
-
if (fs__default.existsSync(project_relative(value))) {
|
|
125
|
-
paths[key] = [project_relative(value)];
|
|
126
|
-
paths[key + '/*'] = [project_relative(value) + '/*'];
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
139
|
write_if_changed(
|
|
131
140
|
out,
|
|
132
141
|
JSON.stringify(
|
|
@@ -134,7 +143,7 @@ function write_tsconfig(config, cwd = process.cwd()) {
|
|
|
134
143
|
compilerOptions: {
|
|
135
144
|
// generated options
|
|
136
145
|
baseUrl: config_relative('.'),
|
|
137
|
-
paths,
|
|
146
|
+
paths: get_tsconfig_paths(config),
|
|
138
147
|
rootDirs: [config_relative('.'), './types'],
|
|
139
148
|
|
|
140
149
|
// essential options
|
|
@@ -214,4 +223,51 @@ function validate(config, cwd, out, user_file) {
|
|
|
214
223
|
}
|
|
215
224
|
}
|
|
216
225
|
|
|
226
|
+
// <something><optional /*>
|
|
227
|
+
const alias_regex = /^(.+?)(\/\*)?$/;
|
|
228
|
+
// <path><optional /* or .fileending>
|
|
229
|
+
const value_regex = /^(.*?)((\/\*)|(\.\w+))?$/;
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Generates tsconfig path aliases from kit's aliases.
|
|
233
|
+
* Related to vite alias creation.
|
|
234
|
+
*
|
|
235
|
+
* @param {import('types').ValidatedKitConfig} config
|
|
236
|
+
*/
|
|
237
|
+
function get_tsconfig_paths(config) {
|
|
238
|
+
const alias = {
|
|
239
|
+
...config.alias
|
|
240
|
+
};
|
|
241
|
+
if (fs__default.existsSync(project_relative(config.files.lib))) {
|
|
242
|
+
alias['$lib'] = project_relative(config.files.lib);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/** @type {Record<string, string[]>} */
|
|
246
|
+
const paths = {};
|
|
247
|
+
|
|
248
|
+
for (const [key, value] of Object.entries(alias)) {
|
|
249
|
+
const key_match = alias_regex.exec(key);
|
|
250
|
+
if (!key_match) throw new Error(`Invalid alias key: ${key}`);
|
|
251
|
+
|
|
252
|
+
const value_match = value_regex.exec(value);
|
|
253
|
+
if (!value_match) throw new Error(`Invalid alias value: ${value}`);
|
|
254
|
+
|
|
255
|
+
const rel_path = project_relative(remove_trailing_slashstar(value));
|
|
256
|
+
const slashstar = key_match[2];
|
|
257
|
+
|
|
258
|
+
if (slashstar) {
|
|
259
|
+
paths[key] = [rel_path + '/*'];
|
|
260
|
+
} else {
|
|
261
|
+
paths[key] = [rel_path];
|
|
262
|
+
const fileending = value_match[4];
|
|
263
|
+
|
|
264
|
+
if (!fileending && !(key + '/*' in alias)) {
|
|
265
|
+
paths[key + '/*'] = [rel_path + '/*'];
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
return paths;
|
|
271
|
+
}
|
|
272
|
+
|
|
217
273
|
export { write as a, write_tsconfig as b, reserved as r, trim as t, valid_identifier as v, write_if_changed as w };
|
package/dist/cli.js
CHANGED