@sveltejs/vite-plugin-svelte 1.0.0-next.29 → 1.0.0-next.32
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/README.md +1 -0
- package/dist/index.cjs +83 -22
- package/dist/index.cjs.map +3 -3
- package/dist/index.js +81 -20
- package/dist/index.js.map +3 -3
- package/package.json +9 -9
- package/src/index.ts +12 -10
- package/src/utils/error.ts +92 -0
- package/src/utils/esbuild.ts +7 -2
- package/src/utils/log.ts +1 -1
- package/src/utils/options.ts +5 -1
- package/src/utils/resolve.ts +7 -1
- package/src/utils/watch.ts +7 -7
package/README.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -44,8 +44,8 @@ __export(exports, {
|
|
|
44
44
|
svelte: () => svelte
|
|
45
45
|
});
|
|
46
46
|
|
|
47
|
-
// ../../node_modules/.pnpm/tsup@5.
|
|
48
|
-
var importMetaUrlShim = typeof document === "undefined" ? new
|
|
47
|
+
// ../../node_modules/.pnpm/tsup@5.10.1_typescript@4.5.2/node_modules/tsup/assets/cjs_shims.js
|
|
48
|
+
var importMetaUrlShim = typeof document === "undefined" ? new URL("file:" + __filename).href : document.currentScript && document.currentScript.src || new URL("main.js", document.baseURI).href;
|
|
49
49
|
|
|
50
50
|
// src/index.ts
|
|
51
51
|
var import_fs6 = __toModule(require("fs"));
|
|
@@ -488,7 +488,7 @@ async function loadSvelteConfig(viteConfig, inlineOptions) {
|
|
|
488
488
|
}
|
|
489
489
|
if (!configFile.endsWith(".mjs")) {
|
|
490
490
|
try {
|
|
491
|
-
const _require = importMetaUrlShim ? esmRequire
|
|
491
|
+
const _require = importMetaUrlShim ? esmRequire ?? (esmRequire = (0, import_module.createRequire)(importMetaUrlShim)) : require;
|
|
492
492
|
delete _require.cache[_require.resolve(configFile)];
|
|
493
493
|
const result = _require(configFile);
|
|
494
494
|
if (result != null) {
|
|
@@ -705,18 +705,73 @@ var import_module3 = __toModule(require("module"));
|
|
|
705
705
|
// src/utils/esbuild.ts
|
|
706
706
|
var import_fs3 = __toModule(require("fs"));
|
|
707
707
|
var import_compiler2 = __toModule(require("svelte/compiler"));
|
|
708
|
+
|
|
709
|
+
// src/utils/error.ts
|
|
710
|
+
function toRollupError(error) {
|
|
711
|
+
const { filename, frame, start, code, name } = error;
|
|
712
|
+
const rollupError = {
|
|
713
|
+
name,
|
|
714
|
+
id: filename,
|
|
715
|
+
message: buildExtendedLogMessage(error),
|
|
716
|
+
frame: formatFrameForVite(frame),
|
|
717
|
+
code,
|
|
718
|
+
stack: ""
|
|
719
|
+
};
|
|
720
|
+
if (start) {
|
|
721
|
+
rollupError.loc = {
|
|
722
|
+
line: start.line,
|
|
723
|
+
column: start.column,
|
|
724
|
+
file: filename
|
|
725
|
+
};
|
|
726
|
+
}
|
|
727
|
+
return rollupError;
|
|
728
|
+
}
|
|
729
|
+
function toESBuildError(error) {
|
|
730
|
+
const { filename, frame, start } = error;
|
|
731
|
+
const partialMessage = {
|
|
732
|
+
text: buildExtendedLogMessage(error)
|
|
733
|
+
};
|
|
734
|
+
if (start) {
|
|
735
|
+
partialMessage.location = {
|
|
736
|
+
line: start.line,
|
|
737
|
+
column: start.column,
|
|
738
|
+
file: filename,
|
|
739
|
+
lineText: lineFromFrame(start.line, frame)
|
|
740
|
+
};
|
|
741
|
+
}
|
|
742
|
+
return partialMessage;
|
|
743
|
+
}
|
|
744
|
+
function lineFromFrame(lineNo, frame) {
|
|
745
|
+
if (!frame) {
|
|
746
|
+
return "";
|
|
747
|
+
}
|
|
748
|
+
const lines = frame.split("\n");
|
|
749
|
+
const errorLine = lines.find((line) => line.trimStart().startsWith(`${lineNo}: `));
|
|
750
|
+
return errorLine ? errorLine.substring(errorLine.indexOf(": ") + 3) : "";
|
|
751
|
+
}
|
|
752
|
+
function formatFrameForVite(frame) {
|
|
753
|
+
if (!frame) {
|
|
754
|
+
return "";
|
|
755
|
+
}
|
|
756
|
+
return frame.split("\n").map((line) => line.match(/^\s+\^/) ? " " + line : " " + line.replace(":", " | ")).join("\n");
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
// src/utils/esbuild.ts
|
|
708
760
|
function esbuildSveltePlugin(options) {
|
|
709
761
|
return {
|
|
710
762
|
name: "vite-plugin-svelte:optimize-svelte",
|
|
711
763
|
setup(build) {
|
|
712
|
-
var _a;
|
|
713
764
|
disableVitePrebundleSvelte(build);
|
|
714
|
-
const svelteExtensions = (
|
|
765
|
+
const svelteExtensions = (options.extensions ?? [".svelte"]).map((ext) => ext.slice(1));
|
|
715
766
|
const svelteFilter = new RegExp(`\\.(` + svelteExtensions.join("|") + `)(\\?.*)?$`);
|
|
716
767
|
build.onLoad({ filter: svelteFilter }, async ({ path: filename }) => {
|
|
717
768
|
const code = await import_fs3.promises.readFile(filename, "utf8");
|
|
718
|
-
|
|
719
|
-
|
|
769
|
+
try {
|
|
770
|
+
const contents = await compileSvelte(options, { filename, code });
|
|
771
|
+
return { contents };
|
|
772
|
+
} catch (e) {
|
|
773
|
+
return { errors: [toESBuildError(e)] };
|
|
774
|
+
}
|
|
720
775
|
});
|
|
721
776
|
}
|
|
722
777
|
};
|
|
@@ -853,7 +908,8 @@ function mergeOptions(defaultOptions, svelteConfig, inlineOptions, viteConfig, v
|
|
|
853
908
|
root: viteConfig.root,
|
|
854
909
|
isProduction: viteEnv.mode === "production",
|
|
855
910
|
isBuild: viteEnv.command === "build",
|
|
856
|
-
isServe: viteEnv.command === "serve"
|
|
911
|
+
isServe: viteEnv.command === "serve",
|
|
912
|
+
isSvelteKit: !!(svelteConfig == null ? void 0 : svelteConfig.kit)
|
|
857
913
|
});
|
|
858
914
|
if (svelteConfig == null ? void 0 : svelteConfig.configFile) {
|
|
859
915
|
merged.configFile = svelteConfig.configFile;
|
|
@@ -861,12 +917,11 @@ function mergeOptions(defaultOptions, svelteConfig, inlineOptions, viteConfig, v
|
|
|
861
917
|
return merged;
|
|
862
918
|
}
|
|
863
919
|
async function resolveOptions(inlineOptions = {}, viteConfig, viteEnv) {
|
|
864
|
-
var _a;
|
|
865
920
|
const viteConfigWithResolvedRoot = __spreadProps(__spreadValues({}, viteConfig), {
|
|
866
921
|
root: resolveViteRoot(viteConfig)
|
|
867
922
|
});
|
|
868
923
|
const svelteConfig = await loadSvelteConfig(viteConfigWithResolvedRoot, inlineOptions) || {};
|
|
869
|
-
const defaultOptions = buildDefaultOptions(viteEnv.mode === "production",
|
|
924
|
+
const defaultOptions = buildDefaultOptions(viteEnv.mode === "production", inlineOptions.emitCss ?? svelteConfig.emitCss);
|
|
870
925
|
const resolvedOptions = mergeOptions(defaultOptions, svelteConfig, inlineOptions, viteConfigWithResolvedRoot, viteEnv);
|
|
871
926
|
enforceOptionsForProduction(resolvedOptions);
|
|
872
927
|
enforceOptionsForHmr(resolvedOptions);
|
|
@@ -1036,7 +1091,7 @@ function setupWatchers(options, cache, requestParser) {
|
|
|
1036
1091
|
return;
|
|
1037
1092
|
}
|
|
1038
1093
|
const { watcher, ws } = server;
|
|
1039
|
-
const {
|
|
1094
|
+
const { root, server: serverConfig } = server.config;
|
|
1040
1095
|
const emitChangeEventOnDependants = (filename) => {
|
|
1041
1096
|
const dependants = cache.getDependants(filename);
|
|
1042
1097
|
dependants.forEach((dependant) => {
|
|
@@ -1056,16 +1111,17 @@ function setupWatchers(options, cache, requestParser) {
|
|
|
1056
1111
|
}
|
|
1057
1112
|
};
|
|
1058
1113
|
const triggerViteRestart = (filename) => {
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
watcher.emit("change", viteConfigFile);
|
|
1062
|
-
} else {
|
|
1114
|
+
var _a;
|
|
1115
|
+
if (serverConfig.middlewareMode || options.isSvelteKit) {
|
|
1063
1116
|
const message = "Svelte config change detected, restart your dev process to apply the changes.";
|
|
1064
1117
|
log.info(message, filename);
|
|
1065
1118
|
ws.send({
|
|
1066
1119
|
type: "error",
|
|
1067
1120
|
err: { message, stack: "", plugin: "vite-plugin-svelte", id: filename }
|
|
1068
1121
|
});
|
|
1122
|
+
} else {
|
|
1123
|
+
log.info(`svelte config changed: restarting vite server. - file: ${filename}`);
|
|
1124
|
+
server.restart(!!((_a = options.experimental) == null ? void 0 : _a.prebundleSvelteLibraries));
|
|
1069
1125
|
}
|
|
1070
1126
|
};
|
|
1071
1127
|
const possibleSvelteConfigs = knownSvelteConfigNames.map((cfg) => import_path4.default.join(root, cfg));
|
|
@@ -1116,7 +1172,7 @@ function resolveViaPackageJsonSvelte(importee, importer) {
|
|
|
1116
1172
|
}
|
|
1117
1173
|
}
|
|
1118
1174
|
function isBareImport(importee) {
|
|
1119
|
-
if (!importee || importee[0] === "." || importee[0] === "\0" || import_path5.default.isAbsolute(importee)) {
|
|
1175
|
+
if (!importee || importee[0] === "." || importee[0] === "\0" || importee.includes(":") || import_path5.default.isAbsolute(importee)) {
|
|
1120
1176
|
return false;
|
|
1121
1177
|
}
|
|
1122
1178
|
const parts = importee.split("/");
|
|
@@ -1413,9 +1469,9 @@ function svelte(inlineOptions) {
|
|
|
1413
1469
|
}
|
|
1414
1470
|
}
|
|
1415
1471
|
},
|
|
1416
|
-
async resolveId(importee, importer, opts
|
|
1417
|
-
const ssr =
|
|
1418
|
-
const svelteRequest = requestParser(importee,
|
|
1472
|
+
async resolveId(importee, importer, opts) {
|
|
1473
|
+
const ssr = !!(opts == null ? void 0 : opts.ssr);
|
|
1474
|
+
const svelteRequest = requestParser(importee, ssr);
|
|
1419
1475
|
if (svelteRequest == null ? void 0 : svelteRequest.query.svelte) {
|
|
1420
1476
|
if (svelteRequest.query.type === "style") {
|
|
1421
1477
|
log.debug(`resolveId resolved virtual css module ${svelteRequest.cssId}`);
|
|
@@ -1456,8 +1512,8 @@ function svelte(inlineOptions) {
|
|
|
1456
1512
|
},
|
|
1457
1513
|
async transform(code, id, opts) {
|
|
1458
1514
|
var _a;
|
|
1459
|
-
const ssr =
|
|
1460
|
-
const svelteRequest = requestParser(id,
|
|
1515
|
+
const ssr = !!(opts == null ? void 0 : opts.ssr);
|
|
1516
|
+
const svelteRequest = requestParser(id, ssr);
|
|
1461
1517
|
if (!svelteRequest) {
|
|
1462
1518
|
return;
|
|
1463
1519
|
}
|
|
@@ -1473,7 +1529,12 @@ function svelte(inlineOptions) {
|
|
|
1473
1529
|
log.error("failed to transform tagged svelte request", svelteRequest);
|
|
1474
1530
|
throw new Error(`failed to transform tagged svelte request for id ${id}`);
|
|
1475
1531
|
}
|
|
1476
|
-
|
|
1532
|
+
let compileData;
|
|
1533
|
+
try {
|
|
1534
|
+
compileData = await compileSvelte2(svelteRequest, code, options);
|
|
1535
|
+
} catch (e) {
|
|
1536
|
+
throw toRollupError(e);
|
|
1537
|
+
}
|
|
1477
1538
|
logCompilerWarnings(compileData.compiled.warnings, options);
|
|
1478
1539
|
cache.update(compileData);
|
|
1479
1540
|
if (((_a = compileData.dependencies) == null ? void 0 : _a.length) && options.server) {
|