Skip to content

Commit 52bae8e

Browse files
cexbrayathaoqunjiang
authored andcommitted
fix: do not generate empty file when use ts without router (vuejs#4374)
1 parent 95ca69c commit 52bae8e

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

packages/@vue/cli-plugin-typescript/__tests__/tsGenerator.spec.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ test('generate files', async () => {
1717
expect(files['src/main.ts']).toBeTruthy()
1818
expect(files['src/main.js']).toBeFalsy()
1919
expect(files['src/App.vue']).toMatch('<script lang="ts">')
20+
// checks that the Home.vue file has not been created, even empty
21+
expect(files.hasOwnProperty('src/views/Home.vue')).toBeFalsy()
2022
})
2123

2224
test('classComponent', async () => {
@@ -62,6 +64,22 @@ test('use with Babel', async () => {
6264
expect(files['tsconfig.json']).toMatch(`"target": "esnext"`)
6365
})
6466

67+
test('use with router', async () => {
68+
const { files } = await generateWithPlugin([
69+
{
70+
id: '@vue/cli-plugin-router',
71+
apply: require('@vue/cli-plugin-router/generator'),
72+
options: {}
73+
},
74+
{
75+
id: 'ts',
76+
apply: require('../generator'),
77+
options: {}
78+
}
79+
])
80+
expect(files['src/views/Home.vue']).toMatch('<div class=\"home\">')
81+
})
82+
6583
test('lint', async () => {
6684
const { pkg, files } = await generateWithPlugin([
6785
{

packages/@vue/cli/lib/GeneratorAPI.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ function renderFile (name, data, ejsOptions) {
429429
// if evaluated to falsy value, return early to avoid extra cost for extend expression
430430
const result = ejs.render(finalTemplate, data, ejsOptions)
431431
if (!result) {
432-
return
432+
return ''
433433
}
434434
}
435435

0 commit comments

Comments
 (0)