@sveltejs/vite-plugin-svelte 2.0.3 → 2.1.0
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.d.ts +2 -2
- package/dist/index.js +174 -68
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
- package/src/__tests__/fixtures/preprocess/foo.scss +3 -0
- package/src/__tests__/preprocess.spec.ts +51 -0
- package/src/index.ts +55 -7
- package/src/preprocess.ts +18 -10
- package/src/utils/__tests__/compile.spec.ts +49 -0
- package/src/utils/__tests__/sourcemaps.spec.ts +79 -0
- package/src/utils/compile.ts +12 -4
- package/src/utils/constants.ts +3 -0
- package/src/utils/log.ts +19 -9
- package/src/utils/options.ts +8 -10
- package/src/utils/sourcemaps.ts +67 -14
- package/src/utils/vite-plugin-svelte-cache.ts +55 -0
- package/src/utils/vite-plugin-svelte-stats.ts +13 -35
package/dist/index.d.ts
CHANGED
|
@@ -158,11 +158,11 @@ interface ExperimentalOptions {
|
|
|
158
158
|
*/
|
|
159
159
|
sendWarningsToBrowser?: boolean;
|
|
160
160
|
/**
|
|
161
|
-
* disable svelte
|
|
161
|
+
* disable svelte field resolve warnings
|
|
162
162
|
*
|
|
163
163
|
* @default false
|
|
164
164
|
*/
|
|
165
|
-
|
|
165
|
+
disableSvelteResolveWarnings?: boolean;
|
|
166
166
|
}
|
|
167
167
|
interface InspectorOptions {
|
|
168
168
|
/**
|
package/dist/index.js
CHANGED
|
@@ -8,6 +8,10 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
8
8
|
|
|
9
9
|
// src/index.ts
|
|
10
10
|
import fs8 from "fs";
|
|
11
|
+
import { VERSION as svelteVersion } from "svelte/compiler";
|
|
12
|
+
import {
|
|
13
|
+
version as viteVersion
|
|
14
|
+
} from "vite";
|
|
11
15
|
import { isDepExcluded as isDepExcluded2 } from "vitefu";
|
|
12
16
|
|
|
13
17
|
// src/utils/log.ts
|
|
@@ -55,14 +59,19 @@ function setLevel(level) {
|
|
|
55
59
|
_log(loggers.error, `invalid log level: ${level} `);
|
|
56
60
|
}
|
|
57
61
|
}
|
|
58
|
-
function _log(logger, message, payload) {
|
|
62
|
+
function _log(logger, message, payload, namespace) {
|
|
59
63
|
if (!logger.enabled) {
|
|
60
64
|
return;
|
|
61
65
|
}
|
|
62
66
|
if (logger.isDebug) {
|
|
63
|
-
|
|
67
|
+
const log2 = namespace ? logger.log.extend(namespace) : logger.log;
|
|
68
|
+
payload !== void 0 ? log2(message, payload) : log2(message);
|
|
64
69
|
} else {
|
|
65
|
-
logger.log(
|
|
70
|
+
logger.log(
|
|
71
|
+
logger.color(
|
|
72
|
+
`${(/* @__PURE__ */ new Date()).toLocaleTimeString()} [${prefix}${namespace ? `:${namespace}` : ""}] ${message}`
|
|
73
|
+
)
|
|
74
|
+
);
|
|
66
75
|
if (payload) {
|
|
67
76
|
logger.log(payload);
|
|
68
77
|
}
|
|
@@ -72,12 +81,12 @@ function createLogger(level) {
|
|
|
72
81
|
const logger = loggers[level];
|
|
73
82
|
const logFn = _log.bind(null, logger);
|
|
74
83
|
const logged = /* @__PURE__ */ new Set();
|
|
75
|
-
const once = function(message, payload) {
|
|
76
|
-
if (logged.has(message)) {
|
|
84
|
+
const once = function(message, payload, namespace) {
|
|
85
|
+
if (!logger.enabled || logged.has(message)) {
|
|
77
86
|
return;
|
|
78
87
|
}
|
|
79
88
|
logged.add(message);
|
|
80
|
-
logFn.apply(null, [message, payload]);
|
|
89
|
+
logFn.apply(null, [message, payload, namespace]);
|
|
81
90
|
};
|
|
82
91
|
Object.defineProperty(logFn, "enabled", {
|
|
83
92
|
get() {
|
|
@@ -181,6 +190,9 @@ function buildExtendedLogMessage(w) {
|
|
|
181
190
|
}
|
|
182
191
|
return parts.join("");
|
|
183
192
|
}
|
|
193
|
+
function isDebugNamespaceEnabled(namespace) {
|
|
194
|
+
return debug.enabled(`vite:${prefix}:${namespace}`);
|
|
195
|
+
}
|
|
184
196
|
|
|
185
197
|
// src/utils/error.ts
|
|
186
198
|
function toRollupError(error, options) {
|
|
@@ -425,16 +437,48 @@ function addExtraPreprocessors(options, config) {
|
|
|
425
437
|
|
|
426
438
|
// src/utils/sourcemaps.ts
|
|
427
439
|
import path2 from "path";
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
440
|
+
var IS_WINDOWS = process.platform === "win32";
|
|
441
|
+
function mapToRelative(map, filename) {
|
|
442
|
+
if (!map) {
|
|
443
|
+
return;
|
|
444
|
+
}
|
|
445
|
+
const sourceRoot = map.sourceRoot;
|
|
446
|
+
const dirname2 = path2.dirname(filename);
|
|
447
|
+
const toRelative = (s) => {
|
|
448
|
+
if (!s) {
|
|
449
|
+
return s;
|
|
450
|
+
}
|
|
451
|
+
let sourcePath;
|
|
452
|
+
if (s.startsWith("file:///")) {
|
|
453
|
+
sourcePath = s.slice(IS_WINDOWS ? 8 : 7);
|
|
454
|
+
} else if (sourceRoot) {
|
|
455
|
+
const sep = sourceRoot[sourceRoot.length - 1] === "/" || s[0] === "/" ? "" : "/";
|
|
456
|
+
sourcePath = `${sourceRoot}${sep}${s}`;
|
|
457
|
+
} else {
|
|
458
|
+
sourcePath = s;
|
|
459
|
+
}
|
|
460
|
+
return path2.isAbsolute(sourcePath) ? path2.relative(dirname2, sourcePath) : sourcePath;
|
|
461
|
+
};
|
|
462
|
+
if (map.file) {
|
|
463
|
+
map.file = path2.basename(filename);
|
|
464
|
+
}
|
|
465
|
+
if (map.sources) {
|
|
466
|
+
map.sources = map.sources.map(toRelative);
|
|
467
|
+
}
|
|
468
|
+
if (map.sourceRoot) {
|
|
469
|
+
delete map.sourceRoot;
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
function removeLangSuffix(map, suffix) {
|
|
473
|
+
if (!map) {
|
|
474
|
+
return;
|
|
475
|
+
}
|
|
476
|
+
const removeSuffix = (s) => s?.endsWith(suffix) ? s.slice(0, -1 * suffix.length) : s;
|
|
477
|
+
if (map.file) {
|
|
478
|
+
map.file = removeSuffix(map.file);
|
|
479
|
+
}
|
|
480
|
+
if (map.sources) {
|
|
481
|
+
map.sources = map.sources.map(removeSuffix);
|
|
438
482
|
}
|
|
439
483
|
}
|
|
440
484
|
|
|
@@ -505,7 +549,7 @@ var _createCompileSvelte = (makeHot) => {
|
|
|
505
549
|
compileOptions.sourcemap = preprocessed.map;
|
|
506
550
|
}
|
|
507
551
|
if (typeof preprocessed?.map === "object") {
|
|
508
|
-
|
|
552
|
+
mapToRelative(preprocessed?.map, filename);
|
|
509
553
|
}
|
|
510
554
|
if (raw && svelteRequest.query.type === "preprocessed") {
|
|
511
555
|
return { preprocessed: preprocessed ?? { code } };
|
|
@@ -527,11 +571,15 @@ var _createCompileSvelte = (makeHot) => {
|
|
|
527
571
|
} : compileOptions;
|
|
528
572
|
const endStat = stats?.start(filename);
|
|
529
573
|
const compiled = compile(finalCode, finalCompileOptions);
|
|
574
|
+
compiled.js.code = compiled.js.code.replace(
|
|
575
|
+
/\/\* [@#]__PURE__ \*\/(\s*)$/gm,
|
|
576
|
+
" $1"
|
|
577
|
+
);
|
|
530
578
|
if (endStat) {
|
|
531
579
|
endStat();
|
|
532
580
|
}
|
|
533
|
-
|
|
534
|
-
|
|
581
|
+
mapToRelative(compiled.js?.map, filename);
|
|
582
|
+
mapToRelative(compiled.css?.map, filename);
|
|
535
583
|
if (!raw) {
|
|
536
584
|
const hasCss = compiled.css?.code?.trim().length > 0;
|
|
537
585
|
if (emitCss && hasCss) {
|
|
@@ -587,7 +635,7 @@ import { createFilter } from "vite";
|
|
|
587
635
|
import { normalizePath } from "vite";
|
|
588
636
|
import * as fs from "fs";
|
|
589
637
|
var VITE_FS_PREFIX = "/@fs/";
|
|
590
|
-
var
|
|
638
|
+
var IS_WINDOWS2 = process.platform === "win32";
|
|
591
639
|
var SUPPORTED_COMPILER_OPTIONS = [
|
|
592
640
|
"generate",
|
|
593
641
|
"dev",
|
|
@@ -632,7 +680,7 @@ function createVirtualImportId(filename, root, type) {
|
|
|
632
680
|
if (existsInRoot(filename, root)) {
|
|
633
681
|
filename = root + filename;
|
|
634
682
|
} else if (filename.startsWith(VITE_FS_PREFIX)) {
|
|
635
|
-
filename =
|
|
683
|
+
filename = IS_WINDOWS2 ? filename.slice(VITE_FS_PREFIX.length) : filename.slice(VITE_FS_PREFIX.length - 1);
|
|
636
684
|
}
|
|
637
685
|
return `${filename}?${parts.join("&")}`;
|
|
638
686
|
}
|
|
@@ -810,6 +858,7 @@ var SVELTE_HMR_IMPORTS = [
|
|
|
810
858
|
"svelte-hmr"
|
|
811
859
|
];
|
|
812
860
|
var SVELTE_EXPORT_CONDITIONS = ["svelte"];
|
|
861
|
+
var FAQ_LINK_CONFLICTS_IN_SVELTE_RESOLVE = "https://github.com/sveltejs/vite-plugin-svelte/blob/main/docs/faq.md#conflicts-in-svelte-resolve";
|
|
813
862
|
|
|
814
863
|
// src/utils/options.ts
|
|
815
864
|
import path5 from "path";
|
|
@@ -966,9 +1015,6 @@ function isCommonDepWithoutSvelteField(dependency) {
|
|
|
966
1015
|
}
|
|
967
1016
|
|
|
968
1017
|
// src/utils/vite-plugin-svelte-stats.ts
|
|
969
|
-
import { findClosestPkgJsonPath } from "vitefu";
|
|
970
|
-
import { readFileSync as readFileSync2 } from "fs";
|
|
971
|
-
import { dirname } from "path";
|
|
972
1018
|
import { performance } from "perf_hooks";
|
|
973
1019
|
import { normalizePath as normalizePath2 } from "vite";
|
|
974
1020
|
var defaultCollectionOptions = {
|
|
@@ -1010,24 +1056,10 @@ function formatPackageStats(pkgStats) {
|
|
|
1010
1056
|
).join("\n");
|
|
1011
1057
|
return table;
|
|
1012
1058
|
}
|
|
1013
|
-
async function getClosestNamedPackage(file) {
|
|
1014
|
-
let name = "$unknown";
|
|
1015
|
-
let path10 = await findClosestPkgJsonPath(file, (pkgPath) => {
|
|
1016
|
-
const pkg = JSON.parse(readFileSync2(pkgPath, "utf-8"));
|
|
1017
|
-
if (pkg.name != null) {
|
|
1018
|
-
name = pkg.name;
|
|
1019
|
-
return true;
|
|
1020
|
-
}
|
|
1021
|
-
return false;
|
|
1022
|
-
});
|
|
1023
|
-
path10 = normalizePath2(dirname(path10 ?? file)) + "/";
|
|
1024
|
-
return { name, path: path10 };
|
|
1025
|
-
}
|
|
1026
1059
|
var VitePluginSvelteStats = class {
|
|
1027
|
-
constructor() {
|
|
1028
|
-
// package directory -> package name
|
|
1029
|
-
this._packages = [];
|
|
1060
|
+
constructor(cache) {
|
|
1030
1061
|
this._collections = [];
|
|
1062
|
+
this._cache = cache;
|
|
1031
1063
|
}
|
|
1032
1064
|
startCollection(name, opts) {
|
|
1033
1065
|
const options = {
|
|
@@ -1057,7 +1089,7 @@ var VitePluginSvelteStats = class {
|
|
|
1057
1089
|
stats.push(stat);
|
|
1058
1090
|
if (!hasLoggedProgress && options.logInProgress(collection, now)) {
|
|
1059
1091
|
hasLoggedProgress = true;
|
|
1060
|
-
log.
|
|
1092
|
+
log.debug(`${name} in progress ...`, void 0, "stats");
|
|
1061
1093
|
}
|
|
1062
1094
|
};
|
|
1063
1095
|
},
|
|
@@ -1079,7 +1111,12 @@ var VitePluginSvelteStats = class {
|
|
|
1079
1111
|
const logResult = collection.options.logResult(collection);
|
|
1080
1112
|
if (logResult) {
|
|
1081
1113
|
await this._aggregateStatsResult(collection);
|
|
1082
|
-
log.
|
|
1114
|
+
log.debug(
|
|
1115
|
+
`${collection.name} done.
|
|
1116
|
+
${formatPackageStats(collection.packageStats)}`,
|
|
1117
|
+
void 0,
|
|
1118
|
+
"stats"
|
|
1119
|
+
);
|
|
1083
1120
|
}
|
|
1084
1121
|
const index = this._collections.indexOf(collection);
|
|
1085
1122
|
this._collections.splice(index, 1);
|
|
@@ -1094,18 +1131,14 @@ var VitePluginSvelteStats = class {
|
|
|
1094
1131
|
collection.finish = () => {
|
|
1095
1132
|
};
|
|
1096
1133
|
} catch (e) {
|
|
1097
|
-
log.debug.once(`failed to finish stats for ${collection.name}
|
|
1134
|
+
log.debug.once(`failed to finish stats for ${collection.name}
|
|
1135
|
+
`, e, "stats");
|
|
1098
1136
|
}
|
|
1099
1137
|
}
|
|
1100
1138
|
async _aggregateStatsResult(collection) {
|
|
1101
1139
|
const stats = collection.stats;
|
|
1102
1140
|
for (const stat of stats) {
|
|
1103
|
-
|
|
1104
|
-
if (!pkg) {
|
|
1105
|
-
pkg = await getClosestNamedPackage(stat.file);
|
|
1106
|
-
this._packages.push(pkg);
|
|
1107
|
-
}
|
|
1108
|
-
stat.pkg = pkg.name;
|
|
1141
|
+
stat.pkg = (await this._cache.getPackageInfo(stat.file)).name;
|
|
1109
1142
|
}
|
|
1110
1143
|
const grouped = {};
|
|
1111
1144
|
stats.forEach((stat) => {
|
|
@@ -1248,7 +1281,7 @@ function mergeConfigs(...configs) {
|
|
|
1248
1281
|
}
|
|
1249
1282
|
return result;
|
|
1250
1283
|
}
|
|
1251
|
-
function resolveOptions(preResolveOptions2, viteConfig) {
|
|
1284
|
+
function resolveOptions(preResolveOptions2, viteConfig, cache) {
|
|
1252
1285
|
const css = preResolveOptions2.emitCss ? "external" : "injected";
|
|
1253
1286
|
const defaultOptions = {
|
|
1254
1287
|
hot: viteConfig.isProduction ? false : {
|
|
@@ -1271,11 +1304,8 @@ function resolveOptions(preResolveOptions2, viteConfig) {
|
|
|
1271
1304
|
addExtraPreprocessors(merged, viteConfig);
|
|
1272
1305
|
enforceOptionsForHmr(merged);
|
|
1273
1306
|
enforceOptionsForProduction(merged);
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
const statsEnabled = disableCompileStats !== true && disableCompileStats !== (merged.isBuild ? "build" : "dev");
|
|
1277
|
-
if (statsEnabled && isLogLevelInfo) {
|
|
1278
|
-
merged.stats = new VitePluginSvelteStats();
|
|
1307
|
+
if (log.debug.enabled && isDebugNamespaceEnabled("stats")) {
|
|
1308
|
+
merged.stats = new VitePluginSvelteStats(cache);
|
|
1279
1309
|
}
|
|
1280
1310
|
return merged;
|
|
1281
1311
|
}
|
|
@@ -1722,12 +1752,12 @@ import fs6 from "fs";
|
|
|
1722
1752
|
|
|
1723
1753
|
// src/ui/inspector/utils.ts
|
|
1724
1754
|
var FS_PREFIX = `/@fs/`;
|
|
1725
|
-
var
|
|
1755
|
+
var IS_WINDOWS3 = process.platform === "win32";
|
|
1726
1756
|
var queryRE = /\?.*$/s;
|
|
1727
1757
|
var hashRE = /#.*$/s;
|
|
1728
1758
|
function idToFile(id) {
|
|
1729
1759
|
if (id.startsWith(FS_PREFIX)) {
|
|
1730
|
-
id = id = id.slice(
|
|
1760
|
+
id = id = id.slice(IS_WINDOWS3 ? FS_PREFIX.length : FS_PREFIX.length - 1);
|
|
1731
1761
|
}
|
|
1732
1762
|
return id.replace(hashRE, "").replace(queryRE, "");
|
|
1733
1763
|
}
|
|
@@ -1833,6 +1863,10 @@ import 'virtual:svelte-inspector-path:load-inspector.js'` };
|
|
|
1833
1863
|
}
|
|
1834
1864
|
|
|
1835
1865
|
// src/utils/vite-plugin-svelte-cache.ts
|
|
1866
|
+
import { readFileSync as readFileSync2 } from "fs";
|
|
1867
|
+
import { dirname } from "path";
|
|
1868
|
+
import { findClosestPkgJsonPath } from "vitefu";
|
|
1869
|
+
import { normalizePath as normalizePath5 } from "vite";
|
|
1836
1870
|
var VitePluginSvelteCache = class {
|
|
1837
1871
|
constructor() {
|
|
1838
1872
|
this._css = /* @__PURE__ */ new Map();
|
|
@@ -1841,6 +1875,7 @@ var VitePluginSvelteCache = class {
|
|
|
1841
1875
|
this._dependants = /* @__PURE__ */ new Map();
|
|
1842
1876
|
this._resolvedSvelteFields = /* @__PURE__ */ new Map();
|
|
1843
1877
|
this._errors = /* @__PURE__ */ new Map();
|
|
1878
|
+
this._packageInfos = [];
|
|
1844
1879
|
}
|
|
1845
1880
|
update(compileData) {
|
|
1846
1881
|
this._errors.delete(compileData.normalizedFilename);
|
|
@@ -1926,6 +1961,9 @@ var VitePluginSvelteCache = class {
|
|
|
1926
1961
|
getResolvedSvelteField(name, importer) {
|
|
1927
1962
|
return this._resolvedSvelteFields.get(this._getResolvedSvelteFieldKey(name, importer));
|
|
1928
1963
|
}
|
|
1964
|
+
hasResolvedSvelteField(name, importer) {
|
|
1965
|
+
return this._resolvedSvelteFields.has(this._getResolvedSvelteFieldKey(name, importer));
|
|
1966
|
+
}
|
|
1929
1967
|
setResolvedSvelteField(importee, importer = void 0, resolvedSvelte) {
|
|
1930
1968
|
this._resolvedSvelteFields.set(
|
|
1931
1969
|
this._getResolvedSvelteFieldKey(importee, importer),
|
|
@@ -1935,7 +1973,37 @@ var VitePluginSvelteCache = class {
|
|
|
1935
1973
|
_getResolvedSvelteFieldKey(importee, importer) {
|
|
1936
1974
|
return importer ? `${importer} > ${importee}` : importee;
|
|
1937
1975
|
}
|
|
1976
|
+
async getPackageInfo(file) {
|
|
1977
|
+
let info = this._packageInfos.find((pi) => file.startsWith(pi.path));
|
|
1978
|
+
if (!info) {
|
|
1979
|
+
info = await findPackageInfo(file);
|
|
1980
|
+
this._packageInfos.push(info);
|
|
1981
|
+
}
|
|
1982
|
+
return info;
|
|
1983
|
+
}
|
|
1938
1984
|
};
|
|
1985
|
+
async function findPackageInfo(file) {
|
|
1986
|
+
const info = {
|
|
1987
|
+
name: "$unknown",
|
|
1988
|
+
version: "0.0.0-unknown",
|
|
1989
|
+
path: "$unknown"
|
|
1990
|
+
};
|
|
1991
|
+
let path10 = await findClosestPkgJsonPath(file, (pkgPath) => {
|
|
1992
|
+
const pkg = JSON.parse(readFileSync2(pkgPath, "utf-8"));
|
|
1993
|
+
if (pkg.name != null) {
|
|
1994
|
+
info.name = pkg.name;
|
|
1995
|
+
if (pkg.version != null) {
|
|
1996
|
+
info.version = pkg.version;
|
|
1997
|
+
}
|
|
1998
|
+
info.svelte = pkg.svelte;
|
|
1999
|
+
return true;
|
|
2000
|
+
}
|
|
2001
|
+
return false;
|
|
2002
|
+
});
|
|
2003
|
+
path10 = normalizePath5(dirname(path10 ?? file)) + "/";
|
|
2004
|
+
info.path = path10;
|
|
2005
|
+
return info;
|
|
2006
|
+
}
|
|
1939
2007
|
|
|
1940
2008
|
// src/utils/load-raw.ts
|
|
1941
2009
|
import fs7 from "fs";
|
|
@@ -2033,6 +2101,7 @@ function toRawExports(object) {
|
|
|
2033
2101
|
import { preprocessCSS, resolveConfig, transformWithEsbuild } from "vite";
|
|
2034
2102
|
var supportedStyleLangs = ["css", "less", "sass", "scss", "styl", "stylus", "postcss", "sss"];
|
|
2035
2103
|
var supportedScriptLangs = ["ts"];
|
|
2104
|
+
var lang_sep = ".vite-preprocess.";
|
|
2036
2105
|
function vitePreprocess(opts) {
|
|
2037
2106
|
const preprocessor = {};
|
|
2038
2107
|
if (opts?.script !== false) {
|
|
@@ -2061,7 +2130,7 @@ function viteScript() {
|
|
|
2061
2130
|
}
|
|
2062
2131
|
}
|
|
2063
2132
|
});
|
|
2064
|
-
|
|
2133
|
+
mapToRelative(map, filename);
|
|
2065
2134
|
return {
|
|
2066
2135
|
code,
|
|
2067
2136
|
map
|
|
@@ -2089,12 +2158,16 @@ function viteStyle(config = {}) {
|
|
|
2089
2158
|
}
|
|
2090
2159
|
transform = getCssTransformFn(resolvedConfig);
|
|
2091
2160
|
}
|
|
2092
|
-
const
|
|
2093
|
-
const
|
|
2094
|
-
|
|
2161
|
+
const suffix = `${lang_sep}${lang}`;
|
|
2162
|
+
const moduleId = `${filename}${suffix}`;
|
|
2163
|
+
const { code, map, deps } = await transform(content, moduleId);
|
|
2164
|
+
removeLangSuffix(map, suffix);
|
|
2165
|
+
mapToRelative(map, filename);
|
|
2166
|
+
const dependencies = deps ? Array.from(deps).filter((d) => !d.endsWith(suffix)) : void 0;
|
|
2095
2167
|
return {
|
|
2096
2168
|
code,
|
|
2097
|
-
map: map ?? void 0
|
|
2169
|
+
map: map ?? void 0,
|
|
2170
|
+
dependencies
|
|
2098
2171
|
};
|
|
2099
2172
|
};
|
|
2100
2173
|
style.__resolvedConfig = null;
|
|
@@ -2110,6 +2183,8 @@ function isResolvedConfig(config) {
|
|
|
2110
2183
|
}
|
|
2111
2184
|
|
|
2112
2185
|
// src/index.ts
|
|
2186
|
+
var isVite4_0 = viteVersion.startsWith("4.0");
|
|
2187
|
+
var isSvelte3 = svelteVersion.startsWith("3");
|
|
2113
2188
|
function svelte(inlineOptions) {
|
|
2114
2189
|
if (process.env.DEBUG != null) {
|
|
2115
2190
|
log.setLevel("debug");
|
|
@@ -2121,6 +2196,7 @@ function svelte(inlineOptions) {
|
|
|
2121
2196
|
let viteConfig;
|
|
2122
2197
|
let compileSvelte2;
|
|
2123
2198
|
let resolvedSvelteSSR;
|
|
2199
|
+
let packagesWithResolveWarnings;
|
|
2124
2200
|
const api = {};
|
|
2125
2201
|
const plugins = [
|
|
2126
2202
|
{
|
|
@@ -2140,7 +2216,7 @@ function svelte(inlineOptions) {
|
|
|
2140
2216
|
return extraViteConfig;
|
|
2141
2217
|
},
|
|
2142
2218
|
async configResolved(config) {
|
|
2143
|
-
options = resolveOptions(options, config);
|
|
2219
|
+
options = resolveOptions(options, config, cache);
|
|
2144
2220
|
patchResolvedViteConfig(config, options);
|
|
2145
2221
|
requestParser = buildIdParser(options);
|
|
2146
2222
|
compileSvelte2 = createCompileSvelte(options);
|
|
@@ -2149,6 +2225,7 @@ function svelte(inlineOptions) {
|
|
|
2149
2225
|
log.debug("resolved options", options);
|
|
2150
2226
|
},
|
|
2151
2227
|
async buildStart() {
|
|
2228
|
+
packagesWithResolveWarnings = /* @__PURE__ */ new Set();
|
|
2152
2229
|
if (!options.prebundleSvelteLibraries)
|
|
2153
2230
|
return;
|
|
2154
2231
|
const isSvelteMetadataChanged = await saveSvelteMetadata(viteConfig.cacheDir, options);
|
|
@@ -2191,7 +2268,7 @@ function svelte(inlineOptions) {
|
|
|
2191
2268
|
return svelteRequest.cssId;
|
|
2192
2269
|
}
|
|
2193
2270
|
}
|
|
2194
|
-
if (ssr && importee === "svelte") {
|
|
2271
|
+
if (isVite4_0 && isSvelte3 && ssr && importee === "svelte") {
|
|
2195
2272
|
if (!resolvedSvelteSSR) {
|
|
2196
2273
|
resolvedSvelteSSR = this.resolve("svelte/ssr", void 0, { skipSelf: true }).then(
|
|
2197
2274
|
(svelteSSR) => {
|
|
@@ -2213,13 +2290,31 @@ function svelte(inlineOptions) {
|
|
|
2213
2290
|
const isPrebundled = options.prebundleSvelteLibraries && viteConfig.optimizeDeps?.disabled !== true && viteConfig.optimizeDeps?.disabled !== (options.isBuild ? "build" : "dev") && !isDepExcluded2(importee, viteConfig.optimizeDeps?.exclude ?? []);
|
|
2214
2291
|
if (ssr || scan || !isPrebundled) {
|
|
2215
2292
|
try {
|
|
2293
|
+
const isFirstResolve = !cache.hasResolvedSvelteField(importee, importer);
|
|
2216
2294
|
const resolved = await resolveViaPackageJsonSvelte(importee, importer, cache);
|
|
2217
|
-
if (resolved) {
|
|
2218
|
-
|
|
2219
|
-
|
|
2295
|
+
if (isFirstResolve && resolved) {
|
|
2296
|
+
const packageInfo = await cache.getPackageInfo(resolved);
|
|
2297
|
+
const packageVersion = `${packageInfo.name}@${packageInfo.version}`;
|
|
2298
|
+
log.debug.once(
|
|
2299
|
+
`resolveId resolved ${importee} to ${resolved} via package.json svelte field of ${packageVersion}`
|
|
2220
2300
|
);
|
|
2221
|
-
|
|
2301
|
+
try {
|
|
2302
|
+
const viteResolved = (await this.resolve(importee, importer, { ...opts, skipSelf: true }))?.id;
|
|
2303
|
+
if (resolved !== viteResolved) {
|
|
2304
|
+
packagesWithResolveWarnings.add(packageVersion);
|
|
2305
|
+
log.debug.enabled && log.debug.once(
|
|
2306
|
+
`resolve difference for ${packageVersion} ${importee} - svelte: "${resolved}", vite: "${viteResolved}"`
|
|
2307
|
+
);
|
|
2308
|
+
}
|
|
2309
|
+
} catch (e) {
|
|
2310
|
+
packagesWithResolveWarnings.add(packageVersion);
|
|
2311
|
+
log.debug.enabled && log.debug.once(
|
|
2312
|
+
`resolve error for ${packageVersion} ${importee} - svelte: "${resolved}", vite: ERROR`,
|
|
2313
|
+
e
|
|
2314
|
+
);
|
|
2315
|
+
}
|
|
2222
2316
|
}
|
|
2317
|
+
return resolved;
|
|
2223
2318
|
} catch (e) {
|
|
2224
2319
|
log.debug.once(
|
|
2225
2320
|
`error trying to resolve ${importee} from ${importer} via package.json svelte field `,
|
|
@@ -2269,6 +2364,17 @@ function svelte(inlineOptions) {
|
|
|
2269
2364
|
},
|
|
2270
2365
|
async buildEnd() {
|
|
2271
2366
|
await options.stats?.finishAll();
|
|
2367
|
+
if (!options.experimental?.disableSvelteResolveWarnings && packagesWithResolveWarnings?.size > 0) {
|
|
2368
|
+
log.warn(
|
|
2369
|
+
`WARNING: The following packages use a svelte resolve configuration in package.json that has conflicting results and is going to cause problems future.
|
|
2370
|
+
|
|
2371
|
+
${[
|
|
2372
|
+
...packagesWithResolveWarnings
|
|
2373
|
+
].join("\n")}
|
|
2374
|
+
|
|
2375
|
+
Please see ${FAQ_LINK_CONFLICTS_IN_SVELTE_RESOLVE} for details.`
|
|
2376
|
+
);
|
|
2377
|
+
}
|
|
2272
2378
|
}
|
|
2273
2379
|
}
|
|
2274
2380
|
];
|