Skip to content

Commit eddbcd0

Browse files
authored
feat: better error tracing for vue block loader (#29)
1 parent 8c16401 commit eddbcd0

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/utils/mkdist.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,10 @@ function defineVueLoader(options?: DefineVueLoaderOptions): Loader {
100100
rawInput: input,
101101
addOutput,
102102
requireTranspileTemplate: isTs,
103+
}).catch((cause) => {
104+
throw new Error(`[vue-sfc-transformer] Failed to load the ${data.type} block in ${input.srcPath}`, { cause })
103105
})
106+
104107
if (result) {
105108
modified = true
106109
}

test/mkdist.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,16 @@ describe('transform typescript script setup', () => {
400400
expect(result).toBeUndefined()
401401
})
402402

403+
it('throws error when block loader fails', async () => {
404+
const src = `
405+
<script setup lang="ts">
406+
const props =
407+
</script>
408+
`
409+
410+
await expect(fixture(src)).rejects.toThrow('[vue-sfc-transformer] Failed to load the script block in')
411+
})
412+
403413
async function fixture(src: string): Promise<string> {
404414
await rm(tmpDir, { force: true, recursive: true })
405415
await mkdir(join(tmpDir, 'src'), { recursive: true })

0 commit comments

Comments
 (0)