@sveltejs/vite-plugin-svelte 1.0.1 → 1.0.4
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/index.cjs +219 -73
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +214 -71
- package/dist/index.js.map +1 -1
- package/package.json +6 -7
- package/src/handle-hot-update.ts +1 -1
- package/src/ui/inspector/Inspector.svelte +2 -2
- package/src/ui/inspector/plugin.ts +8 -2
- package/src/ui/inspector/utils.ts +13 -0
- package/src/utils/options.ts +7 -7
package/dist/index.js
CHANGED
|
@@ -219,7 +219,9 @@ async function handleHotUpdate(compileSvelte2, ctx, svelteRequest, cache, option
|
|
|
219
219
|
ssrModulesToInvalidate.forEach((moduleNode) => server.moduleGraph.invalidateModule(moduleNode));
|
|
220
220
|
}
|
|
221
221
|
if (result.length > 0) {
|
|
222
|
-
log.debug(
|
|
222
|
+
log.debug(
|
|
223
|
+
`handleHotUpdate for ${svelteRequest.id} result: ${result.map((m) => m.id).join(", ")}`
|
|
224
|
+
);
|
|
223
225
|
}
|
|
224
226
|
return result;
|
|
225
227
|
}
|
|
@@ -235,7 +237,9 @@ function jsChanged(prev, next, filename) {
|
|
|
235
237
|
}
|
|
236
238
|
const isLooseEqual = isCodeEqual(normalizeJsCode(prevJs), normalizeJsCode(nextJs));
|
|
237
239
|
if (!isStrictEqual && isLooseEqual) {
|
|
238
|
-
log.warn(
|
|
240
|
+
log.warn(
|
|
241
|
+
`ignoring compiler output js change for ${filename} as it is equal to previous output after normalization`
|
|
242
|
+
);
|
|
239
243
|
}
|
|
240
244
|
return !isLooseEqual;
|
|
241
245
|
}
|
|
@@ -328,7 +332,9 @@ var _createCompileSvelte = (makeHot) => async function compileSvelte2(svelteRequ
|
|
|
328
332
|
compileOptions
|
|
329
333
|
}));
|
|
330
334
|
if (dynamicCompileOptions && log.debug.enabled) {
|
|
331
|
-
log.debug(
|
|
335
|
+
log.debug(
|
|
336
|
+
`dynamic compile options for ${filename}: ${JSON.stringify(dynamicCompileOptions)}`
|
|
337
|
+
);
|
|
332
338
|
}
|
|
333
339
|
const finalCompileOptions = dynamicCompileOptions ? {
|
|
334
340
|
...compileOptions,
|
|
@@ -473,7 +479,11 @@ var knownSvelteConfigNames = [
|
|
|
473
479
|
"svelte.config.cjs",
|
|
474
480
|
"svelte.config.mjs"
|
|
475
481
|
];
|
|
476
|
-
var dynamicImportDefault = new Function(
|
|
482
|
+
var dynamicImportDefault = new Function(
|
|
483
|
+
"path",
|
|
484
|
+
"timestamp",
|
|
485
|
+
'return import(path + "?t=" + timestamp).then(m => m.default)'
|
|
486
|
+
);
|
|
477
487
|
async function loadSvelteConfig(viteConfig, inlineOptions) {
|
|
478
488
|
if ((inlineOptions == null ? void 0 : inlineOptions.configFile) === false) {
|
|
479
489
|
return;
|
|
@@ -483,7 +493,10 @@ async function loadSvelteConfig(viteConfig, inlineOptions) {
|
|
|
483
493
|
let err;
|
|
484
494
|
if (configFile.endsWith(".js") || configFile.endsWith(".mjs")) {
|
|
485
495
|
try {
|
|
486
|
-
const result = await dynamicImportDefault(
|
|
496
|
+
const result = await dynamicImportDefault(
|
|
497
|
+
pathToFileURL(configFile).href,
|
|
498
|
+
fs2.statSync(configFile).mtimeMs
|
|
499
|
+
);
|
|
487
500
|
if (result != null) {
|
|
488
501
|
return {
|
|
489
502
|
...result,
|
|
@@ -534,7 +547,10 @@ function findConfigToLoad(viteConfig, inlineOptions) {
|
|
|
534
547
|
log.debug(`no svelte config found at ${root}`);
|
|
535
548
|
return;
|
|
536
549
|
} else if (existingKnownConfigFiles.length > 1) {
|
|
537
|
-
log.warn(
|
|
550
|
+
log.warn(
|
|
551
|
+
`found more than one svelte config file, using ${existingKnownConfigFiles[0]}. you should only have one!`,
|
|
552
|
+
existingKnownConfigFiles
|
|
553
|
+
);
|
|
538
554
|
}
|
|
539
555
|
return existingKnownConfigFiles[0];
|
|
540
556
|
}
|
|
@@ -603,7 +619,10 @@ function getSvelteDependencies(deps, pkgDir, path9 = []) {
|
|
|
603
619
|
let dependencyNames = Object.keys(pkg.dependencies);
|
|
604
620
|
const circular = dependencyNames.filter((name) => path9.includes(name));
|
|
605
621
|
if (circular.length > 0) {
|
|
606
|
-
log.warn.enabled && log.warn(
|
|
622
|
+
log.warn.enabled && log.warn(
|
|
623
|
+
`skipping circular svelte dependencies in automated vite optimizeDeps handling`,
|
|
624
|
+
circular.map((x) => path9.concat(x).join(">"))
|
|
625
|
+
);
|
|
607
626
|
dependencyNames = dependencyNames.filter((name) => !path9.includes(name));
|
|
608
627
|
}
|
|
609
628
|
if (path9.length === 3) {
|
|
@@ -705,7 +724,9 @@ var COMMON_PREFIXES_WITHOUT_SVELTE_FIELD = [
|
|
|
705
724
|
"vite-plugin-"
|
|
706
725
|
];
|
|
707
726
|
function is_common_without_svelte_field(dependency) {
|
|
708
|
-
return COMMON_DEPENDENCIES_WITHOUT_SVELTE_FIELD.includes(dependency) || COMMON_PREFIXES_WITHOUT_SVELTE_FIELD.some(
|
|
727
|
+
return COMMON_DEPENDENCIES_WITHOUT_SVELTE_FIELD.includes(dependency) || COMMON_PREFIXES_WITHOUT_SVELTE_FIELD.some(
|
|
728
|
+
(prefix2) => prefix2.startsWith("@") ? dependency.startsWith(prefix2) : dependency.substring(dependency.lastIndexOf("/") + 1).startsWith(prefix2)
|
|
729
|
+
);
|
|
709
730
|
}
|
|
710
731
|
function needsOptimization(dep, localRequire) {
|
|
711
732
|
const depData = resolveDependencyData(dep, localRequire);
|
|
@@ -865,7 +886,9 @@ async function buildMagicString(from, to, options) {
|
|
|
865
886
|
DIFF_INSERT = dmpPkg.DIFF_INSERT;
|
|
866
887
|
DIFF_DELETE = dmpPkg.DIFF_DELETE;
|
|
867
888
|
} catch (e) {
|
|
868
|
-
log.error.once(
|
|
889
|
+
log.error.once(
|
|
890
|
+
'Failed to import optional dependency "diff-match-patch". Please install it to enable generated sourcemaps.'
|
|
891
|
+
);
|
|
869
892
|
return null;
|
|
870
893
|
}
|
|
871
894
|
const dmp = new diff_match_patch();
|
|
@@ -941,7 +964,10 @@ function createViteStylePreprocessor(config) {
|
|
|
941
964
|
if (!supportedStyleLangs.includes(lang))
|
|
942
965
|
return;
|
|
943
966
|
const moduleId = `${filename}.${lang}`;
|
|
944
|
-
const transformResult = await pluginTransform(
|
|
967
|
+
const transformResult = await pluginTransform(
|
|
968
|
+
content,
|
|
969
|
+
moduleId
|
|
970
|
+
);
|
|
945
971
|
if (((_b = (_a = transformResult.map) == null ? void 0 : _a.sources) == null ? void 0 : _b[0]) === moduleId) {
|
|
946
972
|
transformResult.map.sources[0] = path3.basename(filename);
|
|
947
973
|
}
|
|
@@ -954,10 +980,14 @@ function createViteStylePreprocessor(config) {
|
|
|
954
980
|
function createVitePreprocessorGroup(config) {
|
|
955
981
|
return {
|
|
956
982
|
markup({ content, filename }) {
|
|
957
|
-
return preprocess3(
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
983
|
+
return preprocess3(
|
|
984
|
+
content,
|
|
985
|
+
{
|
|
986
|
+
script: createViteScriptPreprocessor(),
|
|
987
|
+
style: createViteStylePreprocessor(config)
|
|
988
|
+
},
|
|
989
|
+
{ filename }
|
|
990
|
+
);
|
|
961
991
|
}
|
|
962
992
|
};
|
|
963
993
|
}
|
|
@@ -986,7 +1016,9 @@ function buildExtraPreprocessors(options, config) {
|
|
|
986
1016
|
}
|
|
987
1017
|
const pluginsWithPreprocessorsDeprecated = config.plugins.filter((p) => p == null ? void 0 : p.sveltePreprocess);
|
|
988
1018
|
if (pluginsWithPreprocessorsDeprecated.length > 0) {
|
|
989
|
-
log.warn(
|
|
1019
|
+
log.warn(
|
|
1020
|
+
`The following plugins use the deprecated 'plugin.sveltePreprocess' field. Please contact their maintainers and ask them to move it to 'plugin.api.sveltePreprocess': ${pluginsWithPreprocessorsDeprecated.map((p) => p.name).join(", ")}`
|
|
1021
|
+
);
|
|
990
1022
|
pluginsWithPreprocessorsDeprecated.forEach((p) => {
|
|
991
1023
|
if (!p.api) {
|
|
992
1024
|
p.api = {};
|
|
@@ -994,7 +1026,9 @@ function buildExtraPreprocessors(options, config) {
|
|
|
994
1026
|
if (p.api.sveltePreprocess === void 0) {
|
|
995
1027
|
p.api.sveltePreprocess = p.sveltePreprocess;
|
|
996
1028
|
} else {
|
|
997
|
-
log.error(
|
|
1029
|
+
log.error(
|
|
1030
|
+
`ignoring plugin.sveltePreprocess of ${p.name} because it already defined plugin.api.sveltePreprocess.`
|
|
1031
|
+
);
|
|
998
1032
|
}
|
|
999
1033
|
});
|
|
1000
1034
|
}
|
|
@@ -1011,10 +1045,14 @@ function buildExtraPreprocessors(options, config) {
|
|
|
1011
1045
|
}
|
|
1012
1046
|
}
|
|
1013
1047
|
if (ignored.length > 0) {
|
|
1014
|
-
log.debug(
|
|
1048
|
+
log.debug(
|
|
1049
|
+
`Ignoring svelte preprocessors defined by these vite plugins: ${ignored.map((p) => p.name).join(", ")}`
|
|
1050
|
+
);
|
|
1015
1051
|
}
|
|
1016
1052
|
if (included.length > 0) {
|
|
1017
|
-
log.debug(
|
|
1053
|
+
log.debug(
|
|
1054
|
+
`Adding svelte preprocessors defined by these vite plugins: ${included.map((p) => p.name).join(", ")}`
|
|
1055
|
+
);
|
|
1018
1056
|
appendPreprocessors.push(...pluginsWithPreprocessors.map((p) => p.api.sveltePreprocess));
|
|
1019
1057
|
}
|
|
1020
1058
|
if (options.hot && options.emitCss) {
|
|
@@ -1050,24 +1088,32 @@ function validateSourceMapOutputWrapper(group, i) {
|
|
|
1050
1088
|
let invalidMap = false;
|
|
1051
1089
|
if (!result.map) {
|
|
1052
1090
|
invalidMap = true;
|
|
1053
|
-
log.warn.enabled && log.warn.once(
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1091
|
+
log.warn.enabled && log.warn.once(
|
|
1092
|
+
`preprocessor at index ${i} did not return a sourcemap for ${processorType} transform`,
|
|
1093
|
+
{
|
|
1094
|
+
filename: options.filename,
|
|
1095
|
+
type: processorType,
|
|
1096
|
+
processor: processorFn.toString()
|
|
1097
|
+
}
|
|
1098
|
+
);
|
|
1058
1099
|
} else if (((_a = result.map) == null ? void 0 : _a.mappings) === "") {
|
|
1059
1100
|
invalidMap = true;
|
|
1060
|
-
log.warn.enabled && log.warn.once(
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1101
|
+
log.warn.enabled && log.warn.once(
|
|
1102
|
+
`preprocessor at index ${i} returned an invalid empty sourcemap for ${processorType} transform`,
|
|
1103
|
+
{
|
|
1104
|
+
filename: options.filename,
|
|
1105
|
+
type: processorType,
|
|
1106
|
+
processor: processorFn.toString()
|
|
1107
|
+
}
|
|
1108
|
+
);
|
|
1065
1109
|
}
|
|
1066
1110
|
if (invalidMap) {
|
|
1067
1111
|
try {
|
|
1068
1112
|
const map = await buildSourceMap(options.content, result.code, options.filename);
|
|
1069
1113
|
if (map) {
|
|
1070
|
-
log.debug.enabled && log.debug(
|
|
1114
|
+
log.debug.enabled && log.debug(
|
|
1115
|
+
`adding generated sourcemap to preprocesor result for ${options.filename}`
|
|
1116
|
+
);
|
|
1071
1117
|
result.map = map;
|
|
1072
1118
|
}
|
|
1073
1119
|
} catch (e) {
|
|
@@ -1100,7 +1146,9 @@ var allowedInlineOptions = /* @__PURE__ */ new Set([
|
|
|
1100
1146
|
...knownRootOptions
|
|
1101
1147
|
]);
|
|
1102
1148
|
function validateInlineOptions(inlineOptions) {
|
|
1103
|
-
const invalidKeys = Object.keys(inlineOptions || {}).filter(
|
|
1149
|
+
const invalidKeys = Object.keys(inlineOptions || {}).filter(
|
|
1150
|
+
(key) => !allowedInlineOptions.has(key)
|
|
1151
|
+
);
|
|
1104
1152
|
if (invalidKeys.length) {
|
|
1105
1153
|
log.warn(`invalid plugin options "${invalidKeys.join(", ")}" in inline config`, inlineOptions);
|
|
1106
1154
|
}
|
|
@@ -1111,7 +1159,11 @@ function convertPluginOptions(config) {
|
|
|
1111
1159
|
}
|
|
1112
1160
|
const invalidRootOptions = Object.keys(config).filter((key) => allowedPluginOptions.has(key));
|
|
1113
1161
|
if (invalidRootOptions.length > 0) {
|
|
1114
|
-
throw new Error(
|
|
1162
|
+
throw new Error(
|
|
1163
|
+
`Invalid options in svelte config. Move the following options into 'vitePlugin:{...}': ${invalidRootOptions.join(
|
|
1164
|
+
", "
|
|
1165
|
+
)}`
|
|
1166
|
+
);
|
|
1115
1167
|
}
|
|
1116
1168
|
if (!config.vitePlugin) {
|
|
1117
1169
|
return config;
|
|
@@ -1120,15 +1172,29 @@ function convertPluginOptions(config) {
|
|
|
1120
1172
|
const pluginOptionKeys = Object.keys(pluginOptions);
|
|
1121
1173
|
const rootOptionsInPluginOptions = pluginOptionKeys.filter((key) => knownRootOptions.has(key));
|
|
1122
1174
|
if (rootOptionsInPluginOptions.length > 0) {
|
|
1123
|
-
throw new Error(
|
|
1124
|
-
|
|
1125
|
-
|
|
1175
|
+
throw new Error(
|
|
1176
|
+
`Invalid options in svelte config under vitePlugin:{...}', move them to the config root : ${rootOptionsInPluginOptions.join(
|
|
1177
|
+
", "
|
|
1178
|
+
)}`
|
|
1179
|
+
);
|
|
1180
|
+
}
|
|
1181
|
+
const duplicateOptions = pluginOptionKeys.filter(
|
|
1182
|
+
(key) => Object.prototype.hasOwnProperty.call(config, key)
|
|
1183
|
+
);
|
|
1126
1184
|
if (duplicateOptions.length > 0) {
|
|
1127
|
-
throw new Error(
|
|
1185
|
+
throw new Error(
|
|
1186
|
+
`Invalid duplicate options in svelte config under vitePlugin:{...}', they are defined in root too and must only exist once: ${duplicateOptions.join(
|
|
1187
|
+
", "
|
|
1188
|
+
)}`
|
|
1189
|
+
);
|
|
1128
1190
|
}
|
|
1129
1191
|
const unknownPluginOptions = pluginOptionKeys.filter((key) => !allowedPluginOptions.has(key));
|
|
1130
1192
|
if (unknownPluginOptions.length > 0) {
|
|
1131
|
-
log.warn(
|
|
1193
|
+
log.warn(
|
|
1194
|
+
`ignoring unknown plugin options in svelte config under vitePlugin:{...}: ${unknownPluginOptions.join(
|
|
1195
|
+
", "
|
|
1196
|
+
)}`
|
|
1197
|
+
);
|
|
1132
1198
|
unknownPluginOptions.forEach((unkownOption) => {
|
|
1133
1199
|
delete pluginOptions[unkownOption];
|
|
1134
1200
|
});
|
|
@@ -1149,14 +1215,21 @@ async function preResolveOptions(inlineOptions = {}, viteUserConfig, viteEnv) {
|
|
|
1149
1215
|
extensions: [".svelte"],
|
|
1150
1216
|
emitCss: true
|
|
1151
1217
|
};
|
|
1152
|
-
const svelteConfig = convertPluginOptions(
|
|
1218
|
+
const svelteConfig = convertPluginOptions(
|
|
1219
|
+
await loadSvelteConfig(viteConfigWithResolvedRoot, inlineOptions)
|
|
1220
|
+
);
|
|
1153
1221
|
const extraOptions = {
|
|
1154
1222
|
root: viteConfigWithResolvedRoot.root,
|
|
1155
1223
|
isBuild: viteEnv.command === "build",
|
|
1156
1224
|
isServe: viteEnv.command === "serve",
|
|
1157
1225
|
isDebug: process.env.DEBUG != null
|
|
1158
1226
|
};
|
|
1159
|
-
const merged = mergeConfigs(
|
|
1227
|
+
const merged = mergeConfigs(
|
|
1228
|
+
defaultOptions,
|
|
1229
|
+
svelteConfig,
|
|
1230
|
+
inlineOptions,
|
|
1231
|
+
extraOptions
|
|
1232
|
+
);
|
|
1160
1233
|
if (svelteConfig == null ? void 0 : svelteConfig.configFile) {
|
|
1161
1234
|
merged.configFile = svelteConfig.configFile;
|
|
1162
1235
|
}
|
|
@@ -1164,7 +1237,7 @@ async function preResolveOptions(inlineOptions = {}, viteUserConfig, viteEnv) {
|
|
|
1164
1237
|
}
|
|
1165
1238
|
function mergeConfigs(...configs) {
|
|
1166
1239
|
let result = {};
|
|
1167
|
-
for (const config of configs.filter(
|
|
1240
|
+
for (const config of configs.filter((x) => x != null)) {
|
|
1168
1241
|
result = deepmerge(result, config, {
|
|
1169
1242
|
arrayMerge: (target, source) => source ?? target
|
|
1170
1243
|
});
|
|
@@ -1203,12 +1276,16 @@ function enforceOptionsForHmr(options) {
|
|
|
1203
1276
|
options.hot.injectCss = false;
|
|
1204
1277
|
}
|
|
1205
1278
|
if (options.compilerOptions.css) {
|
|
1206
|
-
log.warn(
|
|
1279
|
+
log.warn(
|
|
1280
|
+
"hmr and emitCss are enabled but compilerOptions.css is true, forcing it to false"
|
|
1281
|
+
);
|
|
1207
1282
|
options.compilerOptions.css = false;
|
|
1208
1283
|
}
|
|
1209
1284
|
} else {
|
|
1210
1285
|
if (options.hot === true || !options.hot.injectCss) {
|
|
1211
|
-
log.warn(
|
|
1286
|
+
log.warn(
|
|
1287
|
+
"hmr with emitCss disabled requires option hot.injectCss to be enabled, forcing it to true"
|
|
1288
|
+
);
|
|
1212
1289
|
if (options.hot === true) {
|
|
1213
1290
|
options.hot = { injectCss: true };
|
|
1214
1291
|
} else {
|
|
@@ -1216,7 +1293,9 @@ function enforceOptionsForHmr(options) {
|
|
|
1216
1293
|
}
|
|
1217
1294
|
}
|
|
1218
1295
|
if (!options.compilerOptions.css) {
|
|
1219
|
-
log.warn(
|
|
1296
|
+
log.warn(
|
|
1297
|
+
"hmr with emitCss disabled requires compilerOptions.css to be enabled, forcing it to true"
|
|
1298
|
+
);
|
|
1220
1299
|
options.compilerOptions.css = true;
|
|
1221
1300
|
}
|
|
1222
1301
|
}
|
|
@@ -1229,7 +1308,9 @@ function enforceOptionsForProduction(options) {
|
|
|
1229
1308
|
options.hot = false;
|
|
1230
1309
|
}
|
|
1231
1310
|
if (options.compilerOptions.dev) {
|
|
1232
|
-
log.warn(
|
|
1311
|
+
log.warn(
|
|
1312
|
+
"you are building for production but compilerOptions.dev is true, forcing it to false"
|
|
1313
|
+
);
|
|
1233
1314
|
options.compilerOptions.dev = false;
|
|
1234
1315
|
}
|
|
1235
1316
|
}
|
|
@@ -1242,7 +1323,11 @@ function removeIgnoredOptions(options) {
|
|
|
1242
1323
|
const passedCompilerOptions = Object.keys(options.compilerOptions || {});
|
|
1243
1324
|
const passedIgnored = passedCompilerOptions.filter((o) => ignoredCompilerOptions.includes(o));
|
|
1244
1325
|
if (passedIgnored.length) {
|
|
1245
|
-
log.warn(
|
|
1326
|
+
log.warn(
|
|
1327
|
+
`The following Svelte compilerOptions are controlled by vite-plugin-svelte and essential to its functionality. User-specified values are ignored. Please remove them from your configuration: ${passedIgnored.join(
|
|
1328
|
+
", "
|
|
1329
|
+
)}`
|
|
1330
|
+
);
|
|
1246
1331
|
passedIgnored.forEach((ignored) => {
|
|
1247
1332
|
delete options.compilerOptions[ignored];
|
|
1248
1333
|
});
|
|
@@ -1254,7 +1339,9 @@ function addSvelteKitOptions(options) {
|
|
|
1254
1339
|
const kit_browser_hydrate = (_a = options.kit.browser) == null ? void 0 : _a.hydrate;
|
|
1255
1340
|
const hydratable = kit_browser_hydrate !== false;
|
|
1256
1341
|
if (options.compilerOptions.hydratable != null && options.compilerOptions.hydratable !== hydratable) {
|
|
1257
|
-
log.warn(
|
|
1342
|
+
log.warn(
|
|
1343
|
+
`Conflicting values "compilerOptions.hydratable: ${options.compilerOptions.hydratable}" and "kit.browser.hydrate: ${kit_browser_hydrate}" in your svelte config. You should remove "compilerOptions.hydratable".`
|
|
1344
|
+
);
|
|
1258
1345
|
}
|
|
1259
1346
|
log.debug(`Setting compilerOptions.hydratable: ${hydratable} for SvelteKit`);
|
|
1260
1347
|
options.compilerOptions.hydratable = hydratable;
|
|
@@ -1272,7 +1359,11 @@ function buildExtraViteConfig(options, config) {
|
|
|
1272
1359
|
dedupe: [...SVELTE_IMPORTS, ...SVELTE_HMR_IMPORTS]
|
|
1273
1360
|
}
|
|
1274
1361
|
};
|
|
1275
|
-
extraViteConfig.optimizeDeps = buildOptimizeDepsForSvelte(
|
|
1362
|
+
extraViteConfig.optimizeDeps = buildOptimizeDepsForSvelte(
|
|
1363
|
+
svelteDeps,
|
|
1364
|
+
options,
|
|
1365
|
+
config.optimizeDeps
|
|
1366
|
+
);
|
|
1276
1367
|
if ((_a = options.experimental) == null ? void 0 : _a.prebundleSvelteLibraries) {
|
|
1277
1368
|
extraViteConfig.optimizeDeps = {
|
|
1278
1369
|
...extraViteConfig.optimizeDeps,
|
|
@@ -1300,7 +1391,9 @@ function buildOptimizeDepsForSvelte(svelteDeps, options, optimizeDeps) {
|
|
|
1300
1391
|
};
|
|
1301
1392
|
if (!isExcluded("svelte")) {
|
|
1302
1393
|
const svelteImportsToInclude = SVELTE_IMPORTS.filter((x) => x !== "svelte/ssr");
|
|
1303
|
-
log.debug(
|
|
1394
|
+
log.debug(
|
|
1395
|
+
`adding bare svelte packages to optimizeDeps.include: ${svelteImportsToInclude.join(", ")} `
|
|
1396
|
+
);
|
|
1304
1397
|
include.push(...svelteImportsToInclude.filter((x) => !isIncluded(x)));
|
|
1305
1398
|
} else {
|
|
1306
1399
|
log.debug('"svelte" is excluded in optimizeDeps.exclude, skipped adding it to include.');
|
|
@@ -1309,7 +1402,9 @@ function buildOptimizeDepsForSvelte(svelteDeps, options, optimizeDeps) {
|
|
|
1309
1402
|
return { include, exclude };
|
|
1310
1403
|
}
|
|
1311
1404
|
svelteDeps = svelteDeps.filter((dep) => dep.type === "component-library");
|
|
1312
|
-
const svelteDepsToExclude = Array.from(new Set(svelteDeps.map((dep) => dep.name))).filter(
|
|
1405
|
+
const svelteDepsToExclude = Array.from(new Set(svelteDeps.map((dep) => dep.name))).filter(
|
|
1406
|
+
(dep) => !isIncluded(dep)
|
|
1407
|
+
);
|
|
1313
1408
|
log.debug(`automatically excluding found svelte dependencies: ${svelteDepsToExclude.join(", ")}`);
|
|
1314
1409
|
exclude.push(...svelteDepsToExclude.filter((x) => !isExcluded(x)));
|
|
1315
1410
|
if (options.disableDependencyReinclusion !== true) {
|
|
@@ -1321,7 +1416,10 @@ function buildOptimizeDepsForSvelte(svelteDeps, options, optimizeDeps) {
|
|
|
1321
1416
|
const localRequire = createRequire3(`${dep.dir}/package.json`);
|
|
1322
1417
|
return Object.keys(dep.pkg.dependencies || {}).filter((depOfDep) => !isExcluded(depOfDep) && needsOptimization(depOfDep, localRequire)).map((depOfDep) => dep.path.concat(dep.name, depOfDep).join(" > "));
|
|
1323
1418
|
});
|
|
1324
|
-
log.debug(
|
|
1419
|
+
log.debug(
|
|
1420
|
+
`reincluding transitive dependencies of excluded svelte dependencies`,
|
|
1421
|
+
transitiveDepsToInclude
|
|
1422
|
+
);
|
|
1325
1423
|
include.push(...transitiveDepsToInclude);
|
|
1326
1424
|
}
|
|
1327
1425
|
return { include, exclude };
|
|
@@ -1332,25 +1430,35 @@ function buildSSROptionsForSvelte(svelteDeps, options, config) {
|
|
|
1332
1430
|
if (!((_b = (_a = config.ssr) == null ? void 0 : _a.external) == null ? void 0 : _b.includes("svelte"))) {
|
|
1333
1431
|
noExternal.push("svelte", /^svelte\//);
|
|
1334
1432
|
}
|
|
1335
|
-
noExternal.push(
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1433
|
+
noExternal.push(
|
|
1434
|
+
...Array.from(new Set(svelteDeps.map((s) => s.name))).filter(
|
|
1435
|
+
(x) => {
|
|
1436
|
+
var _a2, _b2;
|
|
1437
|
+
return !((_b2 = (_a2 = config.ssr) == null ? void 0 : _a2.external) == null ? void 0 : _b2.includes(x));
|
|
1438
|
+
}
|
|
1439
|
+
)
|
|
1440
|
+
);
|
|
1339
1441
|
const ssr = {
|
|
1340
1442
|
noExternal,
|
|
1341
1443
|
external: []
|
|
1342
1444
|
};
|
|
1343
1445
|
if (options.isServe) {
|
|
1344
|
-
ssr.external = Array.from(
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1446
|
+
ssr.external = Array.from(
|
|
1447
|
+
new Set(svelteDeps.flatMap((dep) => Object.keys(dep.pkg.dependencies || {})))
|
|
1448
|
+
).filter(
|
|
1449
|
+
(dep) => {
|
|
1450
|
+
var _a2, _b2;
|
|
1451
|
+
return !ssr.noExternal.includes(dep) && !((_b2 = (_a2 = config.ssr) == null ? void 0 : _a2.external) == null ? void 0 : _b2.includes(dep));
|
|
1452
|
+
}
|
|
1453
|
+
);
|
|
1348
1454
|
}
|
|
1349
1455
|
return ssr;
|
|
1350
1456
|
}
|
|
1351
1457
|
function patchResolvedViteConfig(viteConfig, options) {
|
|
1352
1458
|
var _a, _b;
|
|
1353
|
-
const facadeEsbuildSveltePlugin = (_b = (_a = viteConfig.optimizeDeps.esbuildOptions) == null ? void 0 : _a.plugins) == null ? void 0 : _b.find(
|
|
1459
|
+
const facadeEsbuildSveltePlugin = (_b = (_a = viteConfig.optimizeDeps.esbuildOptions) == null ? void 0 : _a.plugins) == null ? void 0 : _b.find(
|
|
1460
|
+
(plugin) => plugin.name === facadeEsbuildSveltePluginName
|
|
1461
|
+
);
|
|
1354
1462
|
if (facadeEsbuildSveltePlugin) {
|
|
1355
1463
|
Object.assign(facadeEsbuildSveltePlugin, esbuildSveltePlugin(options));
|
|
1356
1464
|
}
|
|
@@ -1451,7 +1559,10 @@ var VitePluginSvelteCache = class {
|
|
|
1451
1559
|
return this._resolvedSvelteFields.get(this._getResolvedSvelteFieldKey(name, importer));
|
|
1452
1560
|
}
|
|
1453
1561
|
setResolvedSvelteField(importee, importer = void 0, resolvedSvelte) {
|
|
1454
|
-
this._resolvedSvelteFields.set(
|
|
1562
|
+
this._resolvedSvelteFields.set(
|
|
1563
|
+
this._getResolvedSvelteFieldKey(importee, importer),
|
|
1564
|
+
resolvedSvelte
|
|
1565
|
+
);
|
|
1455
1566
|
}
|
|
1456
1567
|
_getResolvedSvelteFieldKey(importee, importer) {
|
|
1457
1568
|
return importer ? `${importer} > ${importee}` : importee;
|
|
@@ -1472,7 +1583,9 @@ function setupWatchers(options, cache, requestParser) {
|
|
|
1472
1583
|
const dependants = cache.getDependants(filename);
|
|
1473
1584
|
dependants.forEach((dependant) => {
|
|
1474
1585
|
if (fs5.existsSync(dependant)) {
|
|
1475
|
-
log.debug(
|
|
1586
|
+
log.debug(
|
|
1587
|
+
`emitting virtual change event for "${dependant}" because depdendency "${filename}" changed`
|
|
1588
|
+
);
|
|
1476
1589
|
watcher.emit("change", dependant);
|
|
1477
1590
|
}
|
|
1478
1591
|
});
|
|
@@ -1613,6 +1726,20 @@ import { normalizePath as normalizePath3 } from "vite";
|
|
|
1613
1726
|
import path8 from "path";
|
|
1614
1727
|
import { fileURLToPath } from "url";
|
|
1615
1728
|
import fs7 from "fs";
|
|
1729
|
+
|
|
1730
|
+
// src/ui/inspector/utils.ts
|
|
1731
|
+
var FS_PREFIX = `/@fs/`;
|
|
1732
|
+
var IS_WINDOWS2 = process.platform === "win32";
|
|
1733
|
+
var queryRE = /\?.*$/s;
|
|
1734
|
+
var hashRE = /#.*$/s;
|
|
1735
|
+
function idToFile(id) {
|
|
1736
|
+
if (id.startsWith(FS_PREFIX)) {
|
|
1737
|
+
id = id = id.slice(IS_WINDOWS2 ? FS_PREFIX.length : FS_PREFIX.length - 1);
|
|
1738
|
+
}
|
|
1739
|
+
return id.replace(hashRE, "").replace(queryRE, "");
|
|
1740
|
+
}
|
|
1741
|
+
|
|
1742
|
+
// src/ui/inspector/plugin.ts
|
|
1616
1743
|
var defaultInspectorOptions = {
|
|
1617
1744
|
toggleKeyCombo: process.platform === "win32" ? "control-shift" : "meta-shift",
|
|
1618
1745
|
holdMode: false,
|
|
@@ -1649,7 +1776,7 @@ function svelteInspector() {
|
|
|
1649
1776
|
} else {
|
|
1650
1777
|
if (vps.api.options.kit && !inspectorOptions.appendTo) {
|
|
1651
1778
|
const out_dir = path8.basename(vps.api.options.kit.outDir || ".svelte-kit");
|
|
1652
|
-
inspectorOptions.appendTo = `${out_dir}/
|
|
1779
|
+
inspectorOptions.appendTo = `${out_dir}/generated/root.svelte`;
|
|
1653
1780
|
}
|
|
1654
1781
|
appendTo = inspectorOptions.appendTo;
|
|
1655
1782
|
}
|
|
@@ -1673,7 +1800,12 @@ function svelteInspector() {
|
|
|
1673
1800
|
if (id === "virtual:svelte-inspector-options") {
|
|
1674
1801
|
return `export default ${JSON.stringify(inspectorOptions ?? {})}`;
|
|
1675
1802
|
} else if (id.startsWith(inspectorPath)) {
|
|
1676
|
-
|
|
1803
|
+
const file = idToFile(id);
|
|
1804
|
+
if (fs7.existsSync(file)) {
|
|
1805
|
+
return await fs7.promises.readFile(file, "utf-8");
|
|
1806
|
+
} else {
|
|
1807
|
+
log.error(`failed to find file for svelte-inspector: ${file}, referenced by id ${id}.`);
|
|
1808
|
+
}
|
|
1677
1809
|
}
|
|
1678
1810
|
},
|
|
1679
1811
|
transform(code, id, options) {
|
|
@@ -1788,24 +1920,35 @@ function svelte(inlineOptions) {
|
|
|
1788
1920
|
}
|
|
1789
1921
|
if (ssr && importee === "svelte") {
|
|
1790
1922
|
if (!resolvedSvelteSSR) {
|
|
1791
|
-
resolvedSvelteSSR = this.resolve("svelte/ssr", void 0, { skipSelf: true }).then(
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1923
|
+
resolvedSvelteSSR = this.resolve("svelte/ssr", void 0, { skipSelf: true }).then(
|
|
1924
|
+
(svelteSSR) => {
|
|
1925
|
+
log.debug("resolved svelte to svelte/ssr");
|
|
1926
|
+
return svelteSSR;
|
|
1927
|
+
},
|
|
1928
|
+
(err) => {
|
|
1929
|
+
log.debug(
|
|
1930
|
+
"failed to resolve svelte to svelte/ssr. Update svelte to a version that exports it",
|
|
1931
|
+
err
|
|
1932
|
+
);
|
|
1933
|
+
return null;
|
|
1934
|
+
}
|
|
1935
|
+
);
|
|
1798
1936
|
}
|
|
1799
1937
|
return resolvedSvelteSSR;
|
|
1800
1938
|
}
|
|
1801
1939
|
try {
|
|
1802
1940
|
const resolved = resolveViaPackageJsonSvelte(importee, importer, cache);
|
|
1803
1941
|
if (resolved) {
|
|
1804
|
-
log.debug(
|
|
1942
|
+
log.debug(
|
|
1943
|
+
`resolveId resolved ${resolved} via package.json svelte field of ${importee}`
|
|
1944
|
+
);
|
|
1805
1945
|
return resolved;
|
|
1806
1946
|
}
|
|
1807
1947
|
} catch (e) {
|
|
1808
|
-
log.debug.once(
|
|
1948
|
+
log.debug.once(
|
|
1949
|
+
`error trying to resolve ${importee} from ${importer} via package.json svelte field `,
|
|
1950
|
+
e
|
|
1951
|
+
);
|
|
1809
1952
|
}
|
|
1810
1953
|
},
|
|
1811
1954
|
async transform(code, id, opts) {
|