@sveltejs/vite-plugin-svelte 1.0.0-next.46 → 1.0.0-next.49
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 +105 -34
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +24 -2
- package/dist/index.js +103 -33
- package/dist/index.js.map +1 -1
- package/package.json +7 -6
- package/src/handle-hot-update.ts +16 -10
- package/src/index.ts +11 -2
- package/src/utils/dependencies.ts +5 -1
- package/src/utils/load-svelte-config.ts +12 -8
- package/src/utils/log.ts +43 -5
- package/src/utils/options.ts +34 -4
- package/src/utils/vite-plugin-svelte-cache.ts +35 -11
package/dist/index.cjs
CHANGED
|
@@ -39,11 +39,12 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
39
39
|
// src/index.ts
|
|
40
40
|
var src_exports = {};
|
|
41
41
|
__export(src_exports, {
|
|
42
|
+
loadSvelteConfig: () => loadSvelteConfig,
|
|
42
43
|
svelte: () => svelte
|
|
43
44
|
});
|
|
44
45
|
module.exports = __toCommonJS(src_exports);
|
|
45
46
|
|
|
46
|
-
// ../../node_modules/.pnpm/tsup@
|
|
47
|
+
// ../../node_modules/.pnpm/tsup@6.1.0/node_modules/tsup/assets/cjs_shims.js
|
|
47
48
|
var getImportMetaUrl = () => typeof document === "undefined" ? new URL("file:" + __filename).href : document.currentScript && document.currentScript.src || new URL("main.js", document.baseURI).href;
|
|
48
49
|
var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
|
|
49
50
|
|
|
@@ -138,18 +139,42 @@ var log = {
|
|
|
138
139
|
error: createLogger("error"),
|
|
139
140
|
setLevel
|
|
140
141
|
};
|
|
141
|
-
function logCompilerWarnings(warnings, options) {
|
|
142
|
+
function logCompilerWarnings(svelteRequest, warnings, options) {
|
|
143
|
+
var _a, _b, _c;
|
|
142
144
|
const { emitCss, onwarn, isBuild } = options;
|
|
143
|
-
const
|
|
144
|
-
|
|
145
|
-
const
|
|
146
|
-
|
|
145
|
+
const sendViaWS = !isBuild && ((_a = options.experimental) == null ? void 0 : _a.sendWarningsToBrowser);
|
|
146
|
+
let warn = isBuild ? warnBuild : warnDev;
|
|
147
|
+
const handledByDefaultWarn = [];
|
|
148
|
+
const notIgnored = warnings == null ? void 0 : warnings.filter((w) => !ignoreCompilerWarning(w, isBuild, emitCss));
|
|
149
|
+
const extra = buildExtraWarnings(warnings, isBuild);
|
|
150
|
+
const allWarnings = [...notIgnored, ...extra];
|
|
151
|
+
if (sendViaWS) {
|
|
152
|
+
const _warn = warn;
|
|
153
|
+
warn = (w) => {
|
|
154
|
+
handledByDefaultWarn.push(w);
|
|
155
|
+
_warn(w);
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
allWarnings.forEach((warning) => {
|
|
147
159
|
if (onwarn) {
|
|
148
160
|
onwarn(warning, warn);
|
|
149
161
|
} else {
|
|
150
162
|
warn(warning);
|
|
151
163
|
}
|
|
152
164
|
});
|
|
165
|
+
if (sendViaWS) {
|
|
166
|
+
const message = {
|
|
167
|
+
id: svelteRequest.id,
|
|
168
|
+
filename: svelteRequest.filename,
|
|
169
|
+
normalizedFilename: svelteRequest.normalizedFilename,
|
|
170
|
+
timestamp: svelteRequest.timestamp,
|
|
171
|
+
warnings: handledByDefaultWarn,
|
|
172
|
+
allWarnings,
|
|
173
|
+
rawWarnings: warnings
|
|
174
|
+
};
|
|
175
|
+
log.debug(`sending svelte:warnings message for ${svelteRequest.normalizedFilename}`);
|
|
176
|
+
(_c = (_b = options.server) == null ? void 0 : _b.ws) == null ? void 0 : _c.send("svelte:warnings", message);
|
|
177
|
+
}
|
|
153
178
|
}
|
|
154
179
|
function ignoreCompilerWarning(warning, isBuild, emitCss) {
|
|
155
180
|
return !emitCss && warning.code === "css-unused-selector" || !isBuild && isNoScopableElementWarning(warning);
|
|
@@ -196,31 +221,37 @@ function buildExtendedLogMessage(w) {
|
|
|
196
221
|
|
|
197
222
|
// src/handle-hot-update.ts
|
|
198
223
|
async function handleHotUpdate(compileSvelte2, ctx, svelteRequest, cache, options) {
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
if (!cachedJS) {
|
|
202
|
-
log.debug(`handleHotUpdate first call ${svelteRequest.id}`);
|
|
224
|
+
if (!cache.has(svelteRequest)) {
|
|
225
|
+
log.debug(`handleHotUpdate called before initial transform for ${svelteRequest.id}`);
|
|
203
226
|
return;
|
|
204
227
|
}
|
|
228
|
+
const { read, server } = ctx;
|
|
229
|
+
const cachedJS = cache.getJS(svelteRequest);
|
|
205
230
|
const cachedCss = cache.getCSS(svelteRequest);
|
|
206
231
|
const content = await read();
|
|
207
|
-
|
|
208
|
-
|
|
232
|
+
let compileData;
|
|
233
|
+
try {
|
|
234
|
+
compileData = await compileSvelte2(svelteRequest, content, options);
|
|
235
|
+
cache.update(compileData);
|
|
236
|
+
} catch (e) {
|
|
237
|
+
cache.setError(svelteRequest, e);
|
|
238
|
+
throw e;
|
|
239
|
+
}
|
|
209
240
|
const affectedModules = /* @__PURE__ */ new Set();
|
|
210
241
|
const cssModule = server.moduleGraph.getModuleById(svelteRequest.cssId);
|
|
211
242
|
const mainModule = server.moduleGraph.getModuleById(svelteRequest.id);
|
|
212
243
|
const cssUpdated = cssModule && cssChanged(cachedCss, compileData.compiled.css);
|
|
213
244
|
if (cssUpdated) {
|
|
214
|
-
log.debug(
|
|
245
|
+
log.debug(`handleHotUpdate css changed for ${svelteRequest.cssId}`);
|
|
215
246
|
affectedModules.add(cssModule);
|
|
216
247
|
}
|
|
217
248
|
const jsUpdated = mainModule && jsChanged(cachedJS, compileData.compiled.js, svelteRequest.filename);
|
|
218
249
|
if (jsUpdated) {
|
|
219
|
-
log.debug(
|
|
250
|
+
log.debug(`handleHotUpdate js changed for ${svelteRequest.id}`);
|
|
220
251
|
affectedModules.add(mainModule);
|
|
221
252
|
}
|
|
222
253
|
if (!jsUpdated) {
|
|
223
|
-
logCompilerWarnings(compileData.compiled.warnings, options);
|
|
254
|
+
logCompilerWarnings(svelteRequest, compileData.compiled.warnings, options);
|
|
224
255
|
}
|
|
225
256
|
const result = [...affectedModules].filter(Boolean);
|
|
226
257
|
const ssrModulesToInvalidate = result.filter((m) => !!m.ssrTransformResult);
|
|
@@ -477,9 +508,9 @@ var knownSvelteConfigNames = [
|
|
|
477
508
|
"svelte.config.cjs",
|
|
478
509
|
"svelte.config.mjs"
|
|
479
510
|
];
|
|
480
|
-
var dynamicImportDefault = new Function("path", 'return import(path + "?t=" +
|
|
511
|
+
var dynamicImportDefault = new Function("path", "timestamp", 'return import(path + "?t=" + timestamp).then(m => m.default)');
|
|
481
512
|
async function loadSvelteConfig(viteConfig, inlineOptions) {
|
|
482
|
-
if (inlineOptions.configFile === false) {
|
|
513
|
+
if ((inlineOptions == null ? void 0 : inlineOptions.configFile) === false) {
|
|
483
514
|
return;
|
|
484
515
|
}
|
|
485
516
|
const configFile = findConfigToLoad(viteConfig, inlineOptions);
|
|
@@ -487,7 +518,7 @@ async function loadSvelteConfig(viteConfig, inlineOptions) {
|
|
|
487
518
|
let err;
|
|
488
519
|
if (configFile.endsWith(".js") || configFile.endsWith(".mjs")) {
|
|
489
520
|
try {
|
|
490
|
-
const result = await dynamicImportDefault((0, import_url.pathToFileURL)(configFile).href);
|
|
521
|
+
const result = await dynamicImportDefault((0, import_url.pathToFileURL)(configFile).href, import_fs.default.statSync(configFile).mtimeMs);
|
|
491
522
|
if (result != null) {
|
|
492
523
|
return __spreadProps(__spreadValues({}, result), {
|
|
493
524
|
configFile
|
|
@@ -523,8 +554,8 @@ async function loadSvelteConfig(viteConfig, inlineOptions) {
|
|
|
523
554
|
}
|
|
524
555
|
}
|
|
525
556
|
function findConfigToLoad(viteConfig, inlineOptions) {
|
|
526
|
-
const root = viteConfig.root || process.cwd();
|
|
527
|
-
if (inlineOptions.configFile) {
|
|
557
|
+
const root = (viteConfig == null ? void 0 : viteConfig.root) || process.cwd();
|
|
558
|
+
if (inlineOptions == null ? void 0 : inlineOptions.configFile) {
|
|
528
559
|
const abolutePath = import_path.default.isAbsolute(inlineOptions.configFile) ? inlineOptions.configFile : import_path.default.resolve(root, inlineOptions.configFile);
|
|
529
560
|
if (!import_fs.default.existsSync(abolutePath)) {
|
|
530
561
|
throw new Error(`failed to find svelte config file ${abolutePath}.`);
|
|
@@ -669,6 +700,7 @@ function isSvelteLib(pkg) {
|
|
|
669
700
|
}
|
|
670
701
|
var COMMON_DEPENDENCIES_WITHOUT_SVELTE_FIELD = [
|
|
671
702
|
"@lukeed/uuid",
|
|
703
|
+
"@playwright/test",
|
|
672
704
|
"@sveltejs/vite-plugin-svelte",
|
|
673
705
|
"@sveltejs/kit",
|
|
674
706
|
"autoprefixer",
|
|
@@ -678,6 +710,7 @@ var COMMON_DEPENDENCIES_WITHOUT_SVELTE_FIELD = [
|
|
|
678
710
|
"eslint",
|
|
679
711
|
"jest",
|
|
680
712
|
"mdsvex",
|
|
713
|
+
"playwright",
|
|
681
714
|
"postcss",
|
|
682
715
|
"prettier",
|
|
683
716
|
"svelte",
|
|
@@ -686,7 +719,9 @@ var COMMON_DEPENDENCIES_WITHOUT_SVELTE_FIELD = [
|
|
|
686
719
|
"svelte-preprocess",
|
|
687
720
|
"tslib",
|
|
688
721
|
"typescript",
|
|
689
|
-
"vite"
|
|
722
|
+
"vite",
|
|
723
|
+
"vitest",
|
|
724
|
+
"__vite-browser-external"
|
|
690
725
|
];
|
|
691
726
|
var COMMON_PREFIXES_WITHOUT_SVELTE_FIELD = [
|
|
692
727
|
"@fontsource/",
|
|
@@ -1140,6 +1175,7 @@ function resolveOptions(preResolveOptions2, viteConfig) {
|
|
|
1140
1175
|
};
|
|
1141
1176
|
const merged = mergeConfigs(defaultOptions, preResolveOptions2, extraOptions);
|
|
1142
1177
|
removeIgnoredOptions(merged);
|
|
1178
|
+
addSvelteKitOptions(merged);
|
|
1143
1179
|
addExtraPreprocessors(merged, viteConfig);
|
|
1144
1180
|
enforceOptionsForHmr(merged);
|
|
1145
1181
|
enforceOptionsForProduction(merged);
|
|
@@ -1202,6 +1238,17 @@ function removeIgnoredOptions(options) {
|
|
|
1202
1238
|
});
|
|
1203
1239
|
}
|
|
1204
1240
|
}
|
|
1241
|
+
function addSvelteKitOptions(options) {
|
|
1242
|
+
var _a, _b;
|
|
1243
|
+
if ((options == null ? void 0 : options.kit) != null) {
|
|
1244
|
+
const hydratable = ((_a = options.kit.browser) == null ? void 0 : _a.hydrate) !== false;
|
|
1245
|
+
if (options.compilerOptions.hydratable != null && options.compilerOptions.hydratable !== hydratable) {
|
|
1246
|
+
log.warn(`Conflicting values "compilerOptions.hydratable: ${options.compilerOptions.hydratable}" and "kit.browser.hydrate: ${(_b = options.kit.browser) == null ? void 0 : _b.hydrate}" in your svelte config. You should remove "compilerOptions.hydratable".`);
|
|
1247
|
+
}
|
|
1248
|
+
log.debug(`Setting compilerOptions.hydratable: ${hydratable} for SvelteKit`);
|
|
1249
|
+
options.compilerOptions.hydratable = hydratable;
|
|
1250
|
+
}
|
|
1251
|
+
}
|
|
1205
1252
|
function resolveViteRoot(viteConfig) {
|
|
1206
1253
|
return (0, import_vite3.normalizePath)(viteConfig.root ? import_path4.default.resolve(viteConfig.root) : process.cwd());
|
|
1207
1254
|
}
|
|
@@ -1310,12 +1357,22 @@ var VitePluginSvelteCache = class {
|
|
|
1310
1357
|
this._dependencies = /* @__PURE__ */ new Map();
|
|
1311
1358
|
this._dependants = /* @__PURE__ */ new Map();
|
|
1312
1359
|
this._resolvedSvelteFields = /* @__PURE__ */ new Map();
|
|
1360
|
+
this._errors = /* @__PURE__ */ new Map();
|
|
1313
1361
|
}
|
|
1314
1362
|
update(compileData) {
|
|
1363
|
+
this._errors.delete(compileData.normalizedFilename);
|
|
1315
1364
|
this.updateCSS(compileData);
|
|
1316
1365
|
this.updateJS(compileData);
|
|
1317
1366
|
this.updateDependencies(compileData);
|
|
1318
1367
|
}
|
|
1368
|
+
has(svelteRequest) {
|
|
1369
|
+
const id = svelteRequest.normalizedFilename;
|
|
1370
|
+
return this._errors.has(id) || this._js.has(id) || this._css.has(id);
|
|
1371
|
+
}
|
|
1372
|
+
setError(svelteRequest, error) {
|
|
1373
|
+
this.remove(svelteRequest, true);
|
|
1374
|
+
this._errors.set(svelteRequest.normalizedFilename, error);
|
|
1375
|
+
}
|
|
1319
1376
|
updateCSS(compileData) {
|
|
1320
1377
|
this._css.set(compileData.normalizedFilename, compileData.compiled.css);
|
|
1321
1378
|
}
|
|
@@ -1341,25 +1398,30 @@ var VitePluginSvelteCache = class {
|
|
|
1341
1398
|
this._dependants.get(d).delete(compileData.filename);
|
|
1342
1399
|
});
|
|
1343
1400
|
}
|
|
1344
|
-
remove(svelteRequest) {
|
|
1401
|
+
remove(svelteRequest, keepDependencies = false) {
|
|
1345
1402
|
const id = svelteRequest.normalizedFilename;
|
|
1346
1403
|
let removed = false;
|
|
1404
|
+
if (this._errors.delete(id)) {
|
|
1405
|
+
removed = true;
|
|
1406
|
+
}
|
|
1347
1407
|
if (this._js.delete(id)) {
|
|
1348
1408
|
removed = true;
|
|
1349
1409
|
}
|
|
1350
1410
|
if (this._css.delete(id)) {
|
|
1351
1411
|
removed = true;
|
|
1352
1412
|
}
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
dependants.
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1413
|
+
if (!keepDependencies) {
|
|
1414
|
+
const dependencies = this._dependencies.get(id);
|
|
1415
|
+
if (dependencies) {
|
|
1416
|
+
removed = true;
|
|
1417
|
+
dependencies.forEach((d) => {
|
|
1418
|
+
const dependants = this._dependants.get(d);
|
|
1419
|
+
if (dependants && dependants.has(svelteRequest.filename)) {
|
|
1420
|
+
dependants.delete(svelteRequest.filename);
|
|
1421
|
+
}
|
|
1422
|
+
});
|
|
1423
|
+
this._dependencies.delete(id);
|
|
1424
|
+
}
|
|
1363
1425
|
}
|
|
1364
1426
|
return removed;
|
|
1365
1427
|
}
|
|
@@ -1371,6 +1433,9 @@ var VitePluginSvelteCache = class {
|
|
|
1371
1433
|
return this._js.get(svelteRequest.normalizedFilename);
|
|
1372
1434
|
}
|
|
1373
1435
|
}
|
|
1436
|
+
getError(svelteRequest) {
|
|
1437
|
+
return this._errors.get(svelteRequest.normalizedFilename);
|
|
1438
|
+
}
|
|
1374
1439
|
getDependants(path9) {
|
|
1375
1440
|
const dependants = this._dependants.get(path9);
|
|
1376
1441
|
return dependants ? [...dependants] : [];
|
|
@@ -1744,9 +1809,10 @@ function svelte(inlineOptions) {
|
|
|
1744
1809
|
try {
|
|
1745
1810
|
compileData = await compileSvelte2(svelteRequest, code, options);
|
|
1746
1811
|
} catch (e) {
|
|
1812
|
+
cache.setError(svelteRequest, e);
|
|
1747
1813
|
throw toRollupError(e, options);
|
|
1748
1814
|
}
|
|
1749
|
-
logCompilerWarnings(compileData.compiled.warnings, options);
|
|
1815
|
+
logCompilerWarnings(svelteRequest, compileData.compiled.warnings, options);
|
|
1750
1816
|
cache.update(compileData);
|
|
1751
1817
|
if (((_a = compileData.dependencies) == null ? void 0 : _a.length) && options.server) {
|
|
1752
1818
|
compileData.dependencies.forEach((d) => {
|
|
@@ -1768,7 +1834,11 @@ function svelte(inlineOptions) {
|
|
|
1768
1834
|
}
|
|
1769
1835
|
const svelteRequest = requestParser(ctx.file, false, ctx.timestamp);
|
|
1770
1836
|
if (svelteRequest) {
|
|
1771
|
-
|
|
1837
|
+
try {
|
|
1838
|
+
return handleHotUpdate(compileSvelte2, ctx, svelteRequest, cache, options);
|
|
1839
|
+
} catch (e) {
|
|
1840
|
+
throw toRollupError(e, options);
|
|
1841
|
+
}
|
|
1772
1842
|
}
|
|
1773
1843
|
}
|
|
1774
1844
|
}
|
|
@@ -1778,6 +1848,7 @@ function svelte(inlineOptions) {
|
|
|
1778
1848
|
}
|
|
1779
1849
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1780
1850
|
0 && (module.exports = {
|
|
1851
|
+
loadSvelteConfig,
|
|
1781
1852
|
svelte
|
|
1782
1853
|
});
|
|
1783
1854
|
//# sourceMappingURL=index.cjs.map
|