Skip to content

Commit 8067705

Browse files
committed
fix: emit error messages on webpack & esbuild
closes #149
1 parent b1f54c2 commit 8067705

File tree

5 files changed

+20
-24
lines changed

5 files changed

+20
-24
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
},
8686
"dependencies": {
8787
"debug": "^4.3.4",
88-
"unplugin": "~1.7.0",
88+
"unplugin": "~1.7.1",
8989
"vite": "^5.0.12"
9090
},
9191
"devDependencies": {

pnpm-lock.yaml

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/core/main.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import {
2626
} from './script'
2727
import { transformTemplateInMain } from './template'
2828
import { isEqualBlock, isOnlyTemplateChanged } from './handleHotUpdate'
29-
import { createRollupError } from './utils/error'
29+
import { createError } from './utils/error'
3030
import { EXPORT_HELPER_ID } from './helper'
3131
import type { SFCBlock, SFCDescriptor } from 'vue/compiler-sfc'
3232
import type { PluginContext } from 'rollup'
@@ -64,9 +64,7 @@ export async function transformMain(
6464
}
6565

6666
if (errors.length > 0) {
67-
errors.forEach((error) =>
68-
pluginContext.error(createRollupError(filename, error)),
69-
)
67+
errors.forEach((error) => pluginContext.error(createError(filename, error)))
7068
return null
7169
}
7270

src/core/template.ts

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import path from 'node:path'
22
import slash from 'slash'
33
import { getResolvedScript, resolveScript } from './script'
4-
import { createRollupError } from './utils/error'
4+
import { createError } from './utils/error'
55
import type {
66
CompilerOptions,
77
SFCDescriptor,
@@ -100,11 +100,7 @@ export function compile(
100100

101101
if (result.errors.length > 0) {
102102
result.errors.forEach((error) =>
103-
pluginContext.error(
104-
typeof error === 'string'
105-
? { id: filename, message: error }
106-
: createRollupError(filename, error),
107-
),
103+
pluginContext.error(createError(filename, error)),
108104
)
109105
}
110106

src/core/utils/error.ts

+11-9
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,28 @@
1+
import type { UnpluginMessage } from 'unplugin'
12
import type { CompilerError } from 'vue/compiler-sfc'
2-
import type { RollupError } from 'rollup'
33

4-
export function createRollupError(
4+
export function createError(
55
id: string,
6-
error: CompilerError | SyntaxError,
7-
): RollupError {
6+
error: CompilerError | SyntaxError | string,
7+
): UnpluginMessage | string {
8+
if (typeof error === 'string') {
9+
return error
10+
}
11+
812
const { message, name, stack } = error
9-
const rollupError: RollupError = {
13+
const unpluginMessage: UnpluginMessage = {
1014
id,
1115
plugin: 'vue',
1216
message,
1317
name,
1418
stack,
1519
}
16-
1720
if ('code' in error && error.loc) {
18-
rollupError.loc = {
21+
unpluginMessage.loc = {
1922
file: id,
2023
line: error.loc.start.line,
2124
column: error.loc.start.column,
2225
}
2326
}
24-
25-
return rollupError
27+
return unpluginMessage
2628
}

0 commit comments

Comments
 (0)