@sveltejs/vite-plugin-svelte
Advanced tools
Comparing version 1.0.0-next.30 to 1.0.0-next.31
@@ -473,3 +473,3 @@ var __defProp = Object.defineProperty; | ||
try { | ||
const _require = import.meta.url ? esmRequire != null ? esmRequire : esmRequire = createRequire(import.meta.url) : __require; | ||
const _require = import.meta.url ? esmRequire ?? (esmRequire = createRequire(import.meta.url)) : __require; | ||
delete _require.cache[_require.resolve(configFile)]; | ||
@@ -691,2 +691,54 @@ const result = _require(configFile); | ||
import { compile as compile2, preprocess as preprocess2 } from "svelte/compiler"; | ||
// src/utils/error.ts | ||
function toRollupError(error) { | ||
const { filename, frame, start, code, name } = error; | ||
const rollupError = { | ||
name, | ||
id: filename, | ||
message: buildExtendedLogMessage(error), | ||
frame: formatFrameForVite(frame), | ||
code, | ||
stack: "" | ||
}; | ||
if (start) { | ||
rollupError.loc = { | ||
line: start.line, | ||
column: start.column, | ||
file: filename | ||
}; | ||
} | ||
return rollupError; | ||
} | ||
function toESBuildError(error) { | ||
const { filename, frame, start } = error; | ||
const partialMessage = { | ||
text: buildExtendedLogMessage(error) | ||
}; | ||
if (start) { | ||
partialMessage.location = { | ||
line: start.line, | ||
column: start.column, | ||
file: filename, | ||
lineText: lineFromFrame(start.line, frame) | ||
}; | ||
} | ||
return partialMessage; | ||
} | ||
function lineFromFrame(lineNo, frame) { | ||
if (!frame) { | ||
return ""; | ||
} | ||
const lines = frame.split("\n"); | ||
const errorLine = lines.find((line) => line.trimStart().startsWith(`${lineNo}: `)); | ||
return errorLine ? errorLine.substring(errorLine.indexOf(": ") + 3) : ""; | ||
} | ||
function formatFrameForVite(frame) { | ||
if (!frame) { | ||
return ""; | ||
} | ||
return frame.split("\n").map((line) => line.match(/^\s+\^/) ? " " + line : " " + line.replace(":", " | ")).join("\n"); | ||
} | ||
// src/utils/esbuild.ts | ||
function esbuildSveltePlugin(options) { | ||
@@ -696,10 +748,13 @@ return { | ||
setup(build) { | ||
var _a; | ||
disableVitePrebundleSvelte(build); | ||
const svelteExtensions = ((_a = options.extensions) != null ? _a : [".svelte"]).map((ext) => ext.slice(1)); | ||
const svelteExtensions = (options.extensions ?? [".svelte"]).map((ext) => ext.slice(1)); | ||
const svelteFilter = new RegExp(`\\.(` + svelteExtensions.join("|") + `)(\\?.*)?$`); | ||
build.onLoad({ filter: svelteFilter }, async ({ path: filename }) => { | ||
const code = await fs4.readFile(filename, "utf8"); | ||
const contents = await compileSvelte(options, { filename, code }); | ||
return { contents }; | ||
try { | ||
const contents = await compileSvelte(options, { filename, code }); | ||
return { contents }; | ||
} catch (e) { | ||
return { errors: [toESBuildError(e)] }; | ||
} | ||
}); | ||
@@ -849,3 +904,2 @@ } | ||
async function resolveOptions(inlineOptions = {}, viteConfig, viteEnv) { | ||
var _a; | ||
const viteConfigWithResolvedRoot = __spreadProps(__spreadValues({}, viteConfig), { | ||
@@ -855,3 +909,3 @@ root: resolveViteRoot(viteConfig) | ||
const svelteConfig = await loadSvelteConfig(viteConfigWithResolvedRoot, inlineOptions) || {}; | ||
const defaultOptions = buildDefaultOptions(viteEnv.mode === "production", (_a = inlineOptions.emitCss) != null ? _a : svelteConfig.emitCss); | ||
const defaultOptions = buildDefaultOptions(viteEnv.mode === "production", inlineOptions.emitCss ?? svelteConfig.emitCss); | ||
const resolvedOptions = mergeOptions(defaultOptions, svelteConfig, inlineOptions, viteConfigWithResolvedRoot, viteEnv); | ||
@@ -1465,3 +1519,8 @@ enforceOptionsForProduction(resolvedOptions); | ||
} | ||
const compileData = await compileSvelte2(svelteRequest, code, options); | ||
let compileData; | ||
try { | ||
compileData = await compileSvelte2(svelteRequest, code, options); | ||
} catch (e) { | ||
throw toRollupError(e); | ||
} | ||
logCompilerWarnings(compileData.compiled.warnings, options); | ||
@@ -1468,0 +1527,0 @@ cache.update(compileData); |
{ | ||
"name": "@sveltejs/vite-plugin-svelte", | ||
"version": "1.0.0-next.30", | ||
"version": "1.0.0-next.31", | ||
"license": "MIT", | ||
@@ -44,3 +44,3 @@ "author": "dominikg", | ||
"@rollup/pluginutils": "^4.1.1", | ||
"debug": "^4.3.2", | ||
"debug": "^4.3.3", | ||
"kleur": "^4.1.4", | ||
@@ -65,7 +65,7 @@ "magic-string": "^0.25.7", | ||
"diff-match-patch": "^1.0.5", | ||
"esbuild": "^0.13.8", | ||
"rollup": "^2.58.0", | ||
"svelte": "^3.44.0", | ||
"tsup": "^5.4.1", | ||
"vite": "^2.6.7" | ||
"esbuild": "^0.13.15", | ||
"rollup": "^2.60.2", | ||
"svelte": "^3.44.2", | ||
"tsup": "^5.10.1", | ||
"vite": "^2.6.14" | ||
}, | ||
@@ -72,0 +72,0 @@ "scripts": { |
@@ -9,2 +9,3 @@ # @sveltejs/vite-plugin-svelte | ||
// vite.config.js | ||
import { defineConfig } from 'vite'; | ||
import { svelte } from '@sveltejs/vite-plugin-svelte'; | ||
@@ -11,0 +12,0 @@ |
@@ -20,2 +20,3 @@ import fs from 'fs'; | ||
import { PartialResolvedId } from 'rollup'; | ||
import { toRollupError } from './utils/error'; | ||
@@ -173,3 +174,8 @@ export function svelte(inlineOptions?: Partial<Options>): Plugin { | ||
} | ||
const compileData = await compileSvelte(svelteRequest, code, options); | ||
let compileData; | ||
try { | ||
compileData = await compileSvelte(svelteRequest, code, options); | ||
} catch (e) { | ||
throw toRollupError(e); | ||
} | ||
logCompilerWarnings(compileData.compiled.warnings, options); | ||
@@ -176,0 +182,0 @@ cache.update(compileData); |
@@ -7,2 +7,3 @@ import { promises as fs } from 'fs'; | ||
import { CompileOptions, ResolvedOptions } from './options'; | ||
import { toESBuildError } from './error'; | ||
@@ -24,4 +25,8 @@ type EsbuildOptions = NonNullable<DepOptimizationOptions['esbuildOptions']>; | ||
const code = await fs.readFile(filename, 'utf8'); | ||
const contents = await compileSvelte(options, { filename, code }); | ||
return { contents }; | ||
try { | ||
const contents = await compileSvelte(options, { filename, code }); | ||
return { contents }; | ||
} catch (e) { | ||
return { errors: [toESBuildError(e)] }; | ||
} | ||
}); | ||
@@ -28,0 +33,0 @@ } |
@@ -158,3 +158,3 @@ /* eslint-disable no-unused-vars,no-console */ | ||
function buildExtendedLogMessage(w: Warning) { | ||
export function buildExtendedLogMessage(w: Warning) { | ||
const parts = []; | ||
@@ -161,0 +161,0 @@ if (w.filename) { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
409503
27
5460
29
Updateddebug@^4.3.3