@sveltejs/vite-plugin-svelte 1.0.0-next.30 → 1.0.0-next.31
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 +69 -10
- package/dist/index.cjs.map +3 -3
- package/dist/index.js +67 -8
- package/dist/index.js.map +3 -3
- package/package.json +7 -7
- package/src/index.ts +7 -1
- package/src/utils/error.ts +92 -0
- package/src/utils/esbuild.ts +7 -2
- package/src/utils/log.ts +1 -1
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
|
};
|
|
@@ -861,12 +916,11 @@ function mergeOptions(defaultOptions, svelteConfig, inlineOptions, viteConfig, v
|
|
|
861
916
|
return merged;
|
|
862
917
|
}
|
|
863
918
|
async function resolveOptions(inlineOptions = {}, viteConfig, viteEnv) {
|
|
864
|
-
var _a;
|
|
865
919
|
const viteConfigWithResolvedRoot = __spreadProps(__spreadValues({}, viteConfig), {
|
|
866
920
|
root: resolveViteRoot(viteConfig)
|
|
867
921
|
});
|
|
868
922
|
const svelteConfig = await loadSvelteConfig(viteConfigWithResolvedRoot, inlineOptions) || {};
|
|
869
|
-
const defaultOptions = buildDefaultOptions(viteEnv.mode === "production",
|
|
923
|
+
const defaultOptions = buildDefaultOptions(viteEnv.mode === "production", inlineOptions.emitCss ?? svelteConfig.emitCss);
|
|
870
924
|
const resolvedOptions = mergeOptions(defaultOptions, svelteConfig, inlineOptions, viteConfigWithResolvedRoot, viteEnv);
|
|
871
925
|
enforceOptionsForProduction(resolvedOptions);
|
|
872
926
|
enforceOptionsForHmr(resolvedOptions);
|
|
@@ -1473,7 +1527,12 @@ function svelte(inlineOptions) {
|
|
|
1473
1527
|
log.error("failed to transform tagged svelte request", svelteRequest);
|
|
1474
1528
|
throw new Error(`failed to transform tagged svelte request for id ${id}`);
|
|
1475
1529
|
}
|
|
1476
|
-
|
|
1530
|
+
let compileData;
|
|
1531
|
+
try {
|
|
1532
|
+
compileData = await compileSvelte2(svelteRequest, code, options);
|
|
1533
|
+
} catch (e) {
|
|
1534
|
+
throw toRollupError(e);
|
|
1535
|
+
}
|
|
1477
1536
|
logCompilerWarnings(compileData.compiled.warnings, options);
|
|
1478
1537
|
cache.update(compileData);
|
|
1479
1538
|
if (((_a = compileData.dependencies) == null ? void 0 : _a.length) && options.server) {
|