@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/dist/index.js
CHANGED
|
@@ -470,7 +470,7 @@ async function loadSvelteConfig(viteConfig, inlineOptions) {
|
|
|
470
470
|
}
|
|
471
471
|
if (!configFile.endsWith(".mjs")) {
|
|
472
472
|
try {
|
|
473
|
-
const _require = import.meta.url ? esmRequire
|
|
473
|
+
const _require = import.meta.url ? esmRequire ?? (esmRequire = createRequire(import.meta.url)) : __require;
|
|
474
474
|
delete _require.cache[_require.resolve(configFile)];
|
|
475
475
|
const result = _require(configFile);
|
|
476
476
|
if (result != null) {
|
|
@@ -687,18 +687,73 @@ import { createRequire as createRequire3 } from "module";
|
|
|
687
687
|
// src/utils/esbuild.ts
|
|
688
688
|
import { promises as fs4 } from "fs";
|
|
689
689
|
import { compile as compile2, preprocess as preprocess2 } from "svelte/compiler";
|
|
690
|
+
|
|
691
|
+
// src/utils/error.ts
|
|
692
|
+
function toRollupError(error) {
|
|
693
|
+
const { filename, frame, start, code, name } = error;
|
|
694
|
+
const rollupError = {
|
|
695
|
+
name,
|
|
696
|
+
id: filename,
|
|
697
|
+
message: buildExtendedLogMessage(error),
|
|
698
|
+
frame: formatFrameForVite(frame),
|
|
699
|
+
code,
|
|
700
|
+
stack: ""
|
|
701
|
+
};
|
|
702
|
+
if (start) {
|
|
703
|
+
rollupError.loc = {
|
|
704
|
+
line: start.line,
|
|
705
|
+
column: start.column,
|
|
706
|
+
file: filename
|
|
707
|
+
};
|
|
708
|
+
}
|
|
709
|
+
return rollupError;
|
|
710
|
+
}
|
|
711
|
+
function toESBuildError(error) {
|
|
712
|
+
const { filename, frame, start } = error;
|
|
713
|
+
const partialMessage = {
|
|
714
|
+
text: buildExtendedLogMessage(error)
|
|
715
|
+
};
|
|
716
|
+
if (start) {
|
|
717
|
+
partialMessage.location = {
|
|
718
|
+
line: start.line,
|
|
719
|
+
column: start.column,
|
|
720
|
+
file: filename,
|
|
721
|
+
lineText: lineFromFrame(start.line, frame)
|
|
722
|
+
};
|
|
723
|
+
}
|
|
724
|
+
return partialMessage;
|
|
725
|
+
}
|
|
726
|
+
function lineFromFrame(lineNo, frame) {
|
|
727
|
+
if (!frame) {
|
|
728
|
+
return "";
|
|
729
|
+
}
|
|
730
|
+
const lines = frame.split("\n");
|
|
731
|
+
const errorLine = lines.find((line) => line.trimStart().startsWith(`${lineNo}: `));
|
|
732
|
+
return errorLine ? errorLine.substring(errorLine.indexOf(": ") + 3) : "";
|
|
733
|
+
}
|
|
734
|
+
function formatFrameForVite(frame) {
|
|
735
|
+
if (!frame) {
|
|
736
|
+
return "";
|
|
737
|
+
}
|
|
738
|
+
return frame.split("\n").map((line) => line.match(/^\s+\^/) ? " " + line : " " + line.replace(":", " | ")).join("\n");
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
// src/utils/esbuild.ts
|
|
690
742
|
function esbuildSveltePlugin(options) {
|
|
691
743
|
return {
|
|
692
744
|
name: "vite-plugin-svelte:optimize-svelte",
|
|
693
745
|
setup(build) {
|
|
694
|
-
var _a;
|
|
695
746
|
disableVitePrebundleSvelte(build);
|
|
696
|
-
const svelteExtensions = (
|
|
747
|
+
const svelteExtensions = (options.extensions ?? [".svelte"]).map((ext) => ext.slice(1));
|
|
697
748
|
const svelteFilter = new RegExp(`\\.(` + svelteExtensions.join("|") + `)(\\?.*)?$`);
|
|
698
749
|
build.onLoad({ filter: svelteFilter }, async ({ path: filename }) => {
|
|
699
750
|
const code = await fs4.readFile(filename, "utf8");
|
|
700
|
-
|
|
701
|
-
|
|
751
|
+
try {
|
|
752
|
+
const contents = await compileSvelte(options, { filename, code });
|
|
753
|
+
return { contents };
|
|
754
|
+
} catch (e) {
|
|
755
|
+
return { errors: [toESBuildError(e)] };
|
|
756
|
+
}
|
|
702
757
|
});
|
|
703
758
|
}
|
|
704
759
|
};
|
|
@@ -843,12 +898,11 @@ function mergeOptions(defaultOptions, svelteConfig, inlineOptions, viteConfig, v
|
|
|
843
898
|
return merged;
|
|
844
899
|
}
|
|
845
900
|
async function resolveOptions(inlineOptions = {}, viteConfig, viteEnv) {
|
|
846
|
-
var _a;
|
|
847
901
|
const viteConfigWithResolvedRoot = __spreadProps(__spreadValues({}, viteConfig), {
|
|
848
902
|
root: resolveViteRoot(viteConfig)
|
|
849
903
|
});
|
|
850
904
|
const svelteConfig = await loadSvelteConfig(viteConfigWithResolvedRoot, inlineOptions) || {};
|
|
851
|
-
const defaultOptions = buildDefaultOptions(viteEnv.mode === "production",
|
|
905
|
+
const defaultOptions = buildDefaultOptions(viteEnv.mode === "production", inlineOptions.emitCss ?? svelteConfig.emitCss);
|
|
852
906
|
const resolvedOptions = mergeOptions(defaultOptions, svelteConfig, inlineOptions, viteConfigWithResolvedRoot, viteEnv);
|
|
853
907
|
enforceOptionsForProduction(resolvedOptions);
|
|
854
908
|
enforceOptionsForHmr(resolvedOptions);
|
|
@@ -1457,7 +1511,12 @@ function svelte(inlineOptions) {
|
|
|
1457
1511
|
log.error("failed to transform tagged svelte request", svelteRequest);
|
|
1458
1512
|
throw new Error(`failed to transform tagged svelte request for id ${id}`);
|
|
1459
1513
|
}
|
|
1460
|
-
|
|
1514
|
+
let compileData;
|
|
1515
|
+
try {
|
|
1516
|
+
compileData = await compileSvelte2(svelteRequest, code, options);
|
|
1517
|
+
} catch (e) {
|
|
1518
|
+
throw toRollupError(e);
|
|
1519
|
+
}
|
|
1461
1520
|
logCompilerWarnings(compileData.compiled.warnings, options);
|
|
1462
1521
|
cache.update(compileData);
|
|
1463
1522
|
if (((_a = compileData.dependencies) == null ? void 0 : _a.length) && options.server) {
|