Skip to content

Commit ce33e1e

Browse files
danielroeTeages
andcommitted
fix: always emit declarations for vue files (#22)
Co-authored-by: Teages <[email protected]>
1 parent aa86468 commit ce33e1e

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/mkdist.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ function defineVueLoader(options?: DefineVueLoaderOptions): Loader {
109109
)
110110

111111
if (!modified) {
112-
return
112+
return output
113113
}
114114

115115
const contents = results

test/mkdist.test.ts

+10-3
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ describe('transform typescript script setup', () => {
216216
`)
217217
})
218218

219-
it('generates declaration', { timeout: 10000 }, async () => {
219+
it('generates declaration', { timeout: 50_000 }, async () => {
220220
const src = `
221221
<template>
222222
<div :data-test="toValue('hello')" />
@@ -241,6 +241,13 @@ describe('transform typescript script setup', () => {
241241
export default _default;
242242
"
243243
`)
244+
245+
expect(await fixture(`<template><div /></template>`)).toMatchInlineSnapshot(`"<template><div /></template>"`)
246+
expect(await declaration(`<template><div /></template>`)).toMatchInlineSnapshot(`
247+
"declare const _default: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
248+
export default _default;
249+
"
250+
`)
244251
})
245252

246253
async function fixture(src: string): Promise<string> {
@@ -256,11 +263,11 @@ describe('transform typescript script setup', () => {
256263
return await readFile(join(tmpDir, 'dist/index.vue'), 'utf-8')
257264
}
258265

259-
async function declaration(src: string): Promise<string> {
266+
async function declaration(src: string): Promise<string | undefined> {
260267
await rm(tmpDir, { force: true, recursive: true })
261268
await mkdir(join(tmpDir, 'src'), { recursive: true })
262269
await writeFile(join(tmpDir, 'src/index.vue'), src)
263270
await mkdist({ declaration: true, loaders: ['js', vueLoader], rootDir: tmpDir })
264-
return await readFile(join(tmpDir, 'dist/index.vue.d.ts'), 'utf-8')
271+
return await readFile(join(tmpDir, 'dist/index.vue.d.ts'), 'utf-8').catch(() => undefined)
265272
}
266273
})

0 commit comments

Comments
 (0)