@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.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { Plugin } from 'vite';
|
|
1
|
+
import { UserConfig, Plugin } from 'vite';
|
|
2
2
|
import { CompileOptions, Warning } from 'svelte/types/compiler/interfaces';
|
|
3
3
|
export { CompileOptions, Warning } from 'svelte/types/compiler/interfaces';
|
|
4
4
|
import { PreprocessorGroup } from 'svelte/types/compiler/preprocess';
|
|
5
5
|
export { MarkupPreprocessor, Preprocessor, PreprocessorGroup, Processed } from 'svelte/types/compiler/preprocess';
|
|
6
|
+
import { KitConfig } from '@sveltejs/kit';
|
|
6
7
|
|
|
7
8
|
interface Options {
|
|
8
9
|
/**
|
|
@@ -101,6 +102,10 @@ interface Options {
|
|
|
101
102
|
* These options are considered experimental and breaking changes to them can occur in any release
|
|
102
103
|
*/
|
|
103
104
|
experimental?: ExperimentalOptions;
|
|
105
|
+
/**
|
|
106
|
+
* Options for SvelteKit
|
|
107
|
+
*/
|
|
108
|
+
kit?: KitConfig;
|
|
104
109
|
}
|
|
105
110
|
/**
|
|
106
111
|
* These options are considered experimental and breaking changes to them can occur in any release
|
|
@@ -156,6 +161,11 @@ interface ExperimentalOptions {
|
|
|
156
161
|
* enable svelte inspector
|
|
157
162
|
*/
|
|
158
163
|
inspector?: InspectorOptions | boolean;
|
|
164
|
+
/**
|
|
165
|
+
* send a websocket message with svelte compiler warnings during dev
|
|
166
|
+
*
|
|
167
|
+
*/
|
|
168
|
+
sendWarningsToBrowser?: boolean;
|
|
159
169
|
}
|
|
160
170
|
interface InspectorOptions {
|
|
161
171
|
/**
|
|
@@ -200,6 +210,18 @@ declare type ModuleFormat = NonNullable<CompileOptions['format']>;
|
|
|
200
210
|
declare type CssHashGetter = NonNullable<CompileOptions['cssHash']>;
|
|
201
211
|
declare type Arrayable<T> = T | T[];
|
|
202
212
|
|
|
213
|
+
declare function loadSvelteConfig(viteConfig?: UserConfig, inlineOptions?: Partial<Options>): Promise<Partial<Options> | undefined>;
|
|
214
|
+
|
|
215
|
+
declare type SvelteWarningsMessage = {
|
|
216
|
+
id: string;
|
|
217
|
+
filename: string;
|
|
218
|
+
normalizedFilename: string;
|
|
219
|
+
timestamp: number;
|
|
220
|
+
warnings: Warning[];
|
|
221
|
+
allWarnings: Warning[];
|
|
222
|
+
rawWarnings: Warning[];
|
|
223
|
+
};
|
|
224
|
+
|
|
203
225
|
declare function svelte(inlineOptions?: Partial<Options>): Plugin[];
|
|
204
226
|
|
|
205
|
-
export { Arrayable, CssHashGetter, ModuleFormat, Options, svelte };
|
|
227
|
+
export { Arrayable, CssHashGetter, ModuleFormat, Options, SvelteWarningsMessage, loadSvelteConfig, svelte };
|
package/dist/index.js
CHANGED
|
@@ -116,18 +116,42 @@ var log = {
|
|
|
116
116
|
error: createLogger("error"),
|
|
117
117
|
setLevel
|
|
118
118
|
};
|
|
119
|
-
function logCompilerWarnings(warnings, options) {
|
|
119
|
+
function logCompilerWarnings(svelteRequest, warnings, options) {
|
|
120
|
+
var _a, _b, _c;
|
|
120
121
|
const { emitCss, onwarn, isBuild } = options;
|
|
121
|
-
const
|
|
122
|
-
|
|
123
|
-
const
|
|
124
|
-
|
|
122
|
+
const sendViaWS = !isBuild && ((_a = options.experimental) == null ? void 0 : _a.sendWarningsToBrowser);
|
|
123
|
+
let warn = isBuild ? warnBuild : warnDev;
|
|
124
|
+
const handledByDefaultWarn = [];
|
|
125
|
+
const notIgnored = warnings == null ? void 0 : warnings.filter((w) => !ignoreCompilerWarning(w, isBuild, emitCss));
|
|
126
|
+
const extra = buildExtraWarnings(warnings, isBuild);
|
|
127
|
+
const allWarnings = [...notIgnored, ...extra];
|
|
128
|
+
if (sendViaWS) {
|
|
129
|
+
const _warn = warn;
|
|
130
|
+
warn = (w) => {
|
|
131
|
+
handledByDefaultWarn.push(w);
|
|
132
|
+
_warn(w);
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
allWarnings.forEach((warning) => {
|
|
125
136
|
if (onwarn) {
|
|
126
137
|
onwarn(warning, warn);
|
|
127
138
|
} else {
|
|
128
139
|
warn(warning);
|
|
129
140
|
}
|
|
130
141
|
});
|
|
142
|
+
if (sendViaWS) {
|
|
143
|
+
const message = {
|
|
144
|
+
id: svelteRequest.id,
|
|
145
|
+
filename: svelteRequest.filename,
|
|
146
|
+
normalizedFilename: svelteRequest.normalizedFilename,
|
|
147
|
+
timestamp: svelteRequest.timestamp,
|
|
148
|
+
warnings: handledByDefaultWarn,
|
|
149
|
+
allWarnings,
|
|
150
|
+
rawWarnings: warnings
|
|
151
|
+
};
|
|
152
|
+
log.debug(`sending svelte:warnings message for ${svelteRequest.normalizedFilename}`);
|
|
153
|
+
(_c = (_b = options.server) == null ? void 0 : _b.ws) == null ? void 0 : _c.send("svelte:warnings", message);
|
|
154
|
+
}
|
|
131
155
|
}
|
|
132
156
|
function ignoreCompilerWarning(warning, isBuild, emitCss) {
|
|
133
157
|
return !emitCss && warning.code === "css-unused-selector" || !isBuild && isNoScopableElementWarning(warning);
|
|
@@ -174,31 +198,37 @@ function buildExtendedLogMessage(w) {
|
|
|
174
198
|
|
|
175
199
|
// src/handle-hot-update.ts
|
|
176
200
|
async function handleHotUpdate(compileSvelte2, ctx, svelteRequest, cache, options) {
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
if (!cachedJS) {
|
|
180
|
-
log.debug(`handleHotUpdate first call ${svelteRequest.id}`);
|
|
201
|
+
if (!cache.has(svelteRequest)) {
|
|
202
|
+
log.debug(`handleHotUpdate called before initial transform for ${svelteRequest.id}`);
|
|
181
203
|
return;
|
|
182
204
|
}
|
|
205
|
+
const { read, server } = ctx;
|
|
206
|
+
const cachedJS = cache.getJS(svelteRequest);
|
|
183
207
|
const cachedCss = cache.getCSS(svelteRequest);
|
|
184
208
|
const content = await read();
|
|
185
|
-
|
|
186
|
-
|
|
209
|
+
let compileData;
|
|
210
|
+
try {
|
|
211
|
+
compileData = await compileSvelte2(svelteRequest, content, options);
|
|
212
|
+
cache.update(compileData);
|
|
213
|
+
} catch (e) {
|
|
214
|
+
cache.setError(svelteRequest, e);
|
|
215
|
+
throw e;
|
|
216
|
+
}
|
|
187
217
|
const affectedModules = /* @__PURE__ */ new Set();
|
|
188
218
|
const cssModule = server.moduleGraph.getModuleById(svelteRequest.cssId);
|
|
189
219
|
const mainModule = server.moduleGraph.getModuleById(svelteRequest.id);
|
|
190
220
|
const cssUpdated = cssModule && cssChanged(cachedCss, compileData.compiled.css);
|
|
191
221
|
if (cssUpdated) {
|
|
192
|
-
log.debug(
|
|
222
|
+
log.debug(`handleHotUpdate css changed for ${svelteRequest.cssId}`);
|
|
193
223
|
affectedModules.add(cssModule);
|
|
194
224
|
}
|
|
195
225
|
const jsUpdated = mainModule && jsChanged(cachedJS, compileData.compiled.js, svelteRequest.filename);
|
|
196
226
|
if (jsUpdated) {
|
|
197
|
-
log.debug(
|
|
227
|
+
log.debug(`handleHotUpdate js changed for ${svelteRequest.id}`);
|
|
198
228
|
affectedModules.add(mainModule);
|
|
199
229
|
}
|
|
200
230
|
if (!jsUpdated) {
|
|
201
|
-
logCompilerWarnings(compileData.compiled.warnings, options);
|
|
231
|
+
logCompilerWarnings(svelteRequest, compileData.compiled.warnings, options);
|
|
202
232
|
}
|
|
203
233
|
const result = [...affectedModules].filter(Boolean);
|
|
204
234
|
const ssrModulesToInvalidate = result.filter((m) => !!m.ssrTransformResult);
|
|
@@ -457,9 +487,9 @@ var knownSvelteConfigNames = [
|
|
|
457
487
|
"svelte.config.cjs",
|
|
458
488
|
"svelte.config.mjs"
|
|
459
489
|
];
|
|
460
|
-
var dynamicImportDefault = new Function("path", 'return import(path + "?t=" +
|
|
490
|
+
var dynamicImportDefault = new Function("path", "timestamp", 'return import(path + "?t=" + timestamp).then(m => m.default)');
|
|
461
491
|
async function loadSvelteConfig(viteConfig, inlineOptions) {
|
|
462
|
-
if (inlineOptions.configFile === false) {
|
|
492
|
+
if ((inlineOptions == null ? void 0 : inlineOptions.configFile) === false) {
|
|
463
493
|
return;
|
|
464
494
|
}
|
|
465
495
|
const configFile = findConfigToLoad(viteConfig, inlineOptions);
|
|
@@ -467,7 +497,7 @@ async function loadSvelteConfig(viteConfig, inlineOptions) {
|
|
|
467
497
|
let err;
|
|
468
498
|
if (configFile.endsWith(".js") || configFile.endsWith(".mjs")) {
|
|
469
499
|
try {
|
|
470
|
-
const result = await dynamicImportDefault(pathToFileURL(configFile).href);
|
|
500
|
+
const result = await dynamicImportDefault(pathToFileURL(configFile).href, fs2.statSync(configFile).mtimeMs);
|
|
471
501
|
if (result != null) {
|
|
472
502
|
return __spreadProps(__spreadValues({}, result), {
|
|
473
503
|
configFile
|
|
@@ -503,8 +533,8 @@ async function loadSvelteConfig(viteConfig, inlineOptions) {
|
|
|
503
533
|
}
|
|
504
534
|
}
|
|
505
535
|
function findConfigToLoad(viteConfig, inlineOptions) {
|
|
506
|
-
const root = viteConfig.root || process.cwd();
|
|
507
|
-
if (inlineOptions.configFile) {
|
|
536
|
+
const root = (viteConfig == null ? void 0 : viteConfig.root) || process.cwd();
|
|
537
|
+
if (inlineOptions == null ? void 0 : inlineOptions.configFile) {
|
|
508
538
|
const abolutePath = path.isAbsolute(inlineOptions.configFile) ? inlineOptions.configFile : path.resolve(root, inlineOptions.configFile);
|
|
509
539
|
if (!fs2.existsSync(abolutePath)) {
|
|
510
540
|
throw new Error(`failed to find svelte config file ${abolutePath}.`);
|
|
@@ -649,6 +679,7 @@ function isSvelteLib(pkg) {
|
|
|
649
679
|
}
|
|
650
680
|
var COMMON_DEPENDENCIES_WITHOUT_SVELTE_FIELD = [
|
|
651
681
|
"@lukeed/uuid",
|
|
682
|
+
"@playwright/test",
|
|
652
683
|
"@sveltejs/vite-plugin-svelte",
|
|
653
684
|
"@sveltejs/kit",
|
|
654
685
|
"autoprefixer",
|
|
@@ -658,6 +689,7 @@ var COMMON_DEPENDENCIES_WITHOUT_SVELTE_FIELD = [
|
|
|
658
689
|
"eslint",
|
|
659
690
|
"jest",
|
|
660
691
|
"mdsvex",
|
|
692
|
+
"playwright",
|
|
661
693
|
"postcss",
|
|
662
694
|
"prettier",
|
|
663
695
|
"svelte",
|
|
@@ -666,7 +698,9 @@ var COMMON_DEPENDENCIES_WITHOUT_SVELTE_FIELD = [
|
|
|
666
698
|
"svelte-preprocess",
|
|
667
699
|
"tslib",
|
|
668
700
|
"typescript",
|
|
669
|
-
"vite"
|
|
701
|
+
"vite",
|
|
702
|
+
"vitest",
|
|
703
|
+
"__vite-browser-external"
|
|
670
704
|
];
|
|
671
705
|
var COMMON_PREFIXES_WITHOUT_SVELTE_FIELD = [
|
|
672
706
|
"@fontsource/",
|
|
@@ -1122,6 +1156,7 @@ function resolveOptions(preResolveOptions2, viteConfig) {
|
|
|
1122
1156
|
};
|
|
1123
1157
|
const merged = mergeConfigs(defaultOptions, preResolveOptions2, extraOptions);
|
|
1124
1158
|
removeIgnoredOptions(merged);
|
|
1159
|
+
addSvelteKitOptions(merged);
|
|
1125
1160
|
addExtraPreprocessors(merged, viteConfig);
|
|
1126
1161
|
enforceOptionsForHmr(merged);
|
|
1127
1162
|
enforceOptionsForProduction(merged);
|
|
@@ -1184,6 +1219,17 @@ function removeIgnoredOptions(options) {
|
|
|
1184
1219
|
});
|
|
1185
1220
|
}
|
|
1186
1221
|
}
|
|
1222
|
+
function addSvelteKitOptions(options) {
|
|
1223
|
+
var _a, _b;
|
|
1224
|
+
if ((options == null ? void 0 : options.kit) != null) {
|
|
1225
|
+
const hydratable = ((_a = options.kit.browser) == null ? void 0 : _a.hydrate) !== false;
|
|
1226
|
+
if (options.compilerOptions.hydratable != null && options.compilerOptions.hydratable !== hydratable) {
|
|
1227
|
+
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".`);
|
|
1228
|
+
}
|
|
1229
|
+
log.debug(`Setting compilerOptions.hydratable: ${hydratable} for SvelteKit`);
|
|
1230
|
+
options.compilerOptions.hydratable = hydratable;
|
|
1231
|
+
}
|
|
1232
|
+
}
|
|
1187
1233
|
function resolveViteRoot(viteConfig) {
|
|
1188
1234
|
return normalizePath2(viteConfig.root ? path4.resolve(viteConfig.root) : process.cwd());
|
|
1189
1235
|
}
|
|
@@ -1292,12 +1338,22 @@ var VitePluginSvelteCache = class {
|
|
|
1292
1338
|
this._dependencies = /* @__PURE__ */ new Map();
|
|
1293
1339
|
this._dependants = /* @__PURE__ */ new Map();
|
|
1294
1340
|
this._resolvedSvelteFields = /* @__PURE__ */ new Map();
|
|
1341
|
+
this._errors = /* @__PURE__ */ new Map();
|
|
1295
1342
|
}
|
|
1296
1343
|
update(compileData) {
|
|
1344
|
+
this._errors.delete(compileData.normalizedFilename);
|
|
1297
1345
|
this.updateCSS(compileData);
|
|
1298
1346
|
this.updateJS(compileData);
|
|
1299
1347
|
this.updateDependencies(compileData);
|
|
1300
1348
|
}
|
|
1349
|
+
has(svelteRequest) {
|
|
1350
|
+
const id = svelteRequest.normalizedFilename;
|
|
1351
|
+
return this._errors.has(id) || this._js.has(id) || this._css.has(id);
|
|
1352
|
+
}
|
|
1353
|
+
setError(svelteRequest, error) {
|
|
1354
|
+
this.remove(svelteRequest, true);
|
|
1355
|
+
this._errors.set(svelteRequest.normalizedFilename, error);
|
|
1356
|
+
}
|
|
1301
1357
|
updateCSS(compileData) {
|
|
1302
1358
|
this._css.set(compileData.normalizedFilename, compileData.compiled.css);
|
|
1303
1359
|
}
|
|
@@ -1323,25 +1379,30 @@ var VitePluginSvelteCache = class {
|
|
|
1323
1379
|
this._dependants.get(d).delete(compileData.filename);
|
|
1324
1380
|
});
|
|
1325
1381
|
}
|
|
1326
|
-
remove(svelteRequest) {
|
|
1382
|
+
remove(svelteRequest, keepDependencies = false) {
|
|
1327
1383
|
const id = svelteRequest.normalizedFilename;
|
|
1328
1384
|
let removed = false;
|
|
1385
|
+
if (this._errors.delete(id)) {
|
|
1386
|
+
removed = true;
|
|
1387
|
+
}
|
|
1329
1388
|
if (this._js.delete(id)) {
|
|
1330
1389
|
removed = true;
|
|
1331
1390
|
}
|
|
1332
1391
|
if (this._css.delete(id)) {
|
|
1333
1392
|
removed = true;
|
|
1334
1393
|
}
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
dependants.
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1394
|
+
if (!keepDependencies) {
|
|
1395
|
+
const dependencies = this._dependencies.get(id);
|
|
1396
|
+
if (dependencies) {
|
|
1397
|
+
removed = true;
|
|
1398
|
+
dependencies.forEach((d) => {
|
|
1399
|
+
const dependants = this._dependants.get(d);
|
|
1400
|
+
if (dependants && dependants.has(svelteRequest.filename)) {
|
|
1401
|
+
dependants.delete(svelteRequest.filename);
|
|
1402
|
+
}
|
|
1403
|
+
});
|
|
1404
|
+
this._dependencies.delete(id);
|
|
1405
|
+
}
|
|
1345
1406
|
}
|
|
1346
1407
|
return removed;
|
|
1347
1408
|
}
|
|
@@ -1353,6 +1414,9 @@ var VitePluginSvelteCache = class {
|
|
|
1353
1414
|
return this._js.get(svelteRequest.normalizedFilename);
|
|
1354
1415
|
}
|
|
1355
1416
|
}
|
|
1417
|
+
getError(svelteRequest) {
|
|
1418
|
+
return this._errors.get(svelteRequest.normalizedFilename);
|
|
1419
|
+
}
|
|
1356
1420
|
getDependants(path9) {
|
|
1357
1421
|
const dependants = this._dependants.get(path9);
|
|
1358
1422
|
return dependants ? [...dependants] : [];
|
|
@@ -1726,9 +1790,10 @@ function svelte(inlineOptions) {
|
|
|
1726
1790
|
try {
|
|
1727
1791
|
compileData = await compileSvelte2(svelteRequest, code, options);
|
|
1728
1792
|
} catch (e) {
|
|
1793
|
+
cache.setError(svelteRequest, e);
|
|
1729
1794
|
throw toRollupError(e, options);
|
|
1730
1795
|
}
|
|
1731
|
-
logCompilerWarnings(compileData.compiled.warnings, options);
|
|
1796
|
+
logCompilerWarnings(svelteRequest, compileData.compiled.warnings, options);
|
|
1732
1797
|
cache.update(compileData);
|
|
1733
1798
|
if (((_a = compileData.dependencies) == null ? void 0 : _a.length) && options.server) {
|
|
1734
1799
|
compileData.dependencies.forEach((d) => {
|
|
@@ -1750,7 +1815,11 @@ function svelte(inlineOptions) {
|
|
|
1750
1815
|
}
|
|
1751
1816
|
const svelteRequest = requestParser(ctx.file, false, ctx.timestamp);
|
|
1752
1817
|
if (svelteRequest) {
|
|
1753
|
-
|
|
1818
|
+
try {
|
|
1819
|
+
return handleHotUpdate(compileSvelte2, ctx, svelteRequest, cache, options);
|
|
1820
|
+
} catch (e) {
|
|
1821
|
+
throw toRollupError(e, options);
|
|
1822
|
+
}
|
|
1754
1823
|
}
|
|
1755
1824
|
}
|
|
1756
1825
|
}
|
|
@@ -1759,6 +1828,7 @@ function svelte(inlineOptions) {
|
|
|
1759
1828
|
return plugins.filter(Boolean);
|
|
1760
1829
|
}
|
|
1761
1830
|
export {
|
|
1831
|
+
loadSvelteConfig,
|
|
1762
1832
|
svelte
|
|
1763
1833
|
};
|
|
1764
1834
|
//# sourceMappingURL=index.js.map
|