Skip to content

Commit 3f434f6

Browse files
Dobromir Hristovhaoqunjiang
Dobromir Hristov
authored andcommitted
fix(plugin api): fix generator dotfile rename for Windows. (#2427)
close #2424
1 parent 3247719 commit 3f434f6

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

packages/@vue/cli/__tests__/Generator.spec.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ fs.ensureDirSync(templateDir)
1212
fs.writeFileSync(path.resolve(templateDir, 'foo.js'), 'foo(<%- options.n %>)')
1313
fs.ensureDirSync(path.resolve(templateDir, 'bar'))
1414
fs.writeFileSync(path.resolve(templateDir, 'bar/bar.js'), 'bar(<%- m %>)')
15+
fs.writeFileSync(path.resolve(templateDir, 'bar/_bar.js'), '.bar(<%- m %>)')
1516
fs.writeFileSync(path.resolve(templateDir, 'entry.js'), `
1617
import foo from 'foo'
1718
@@ -347,6 +348,7 @@ test('api: render fs directory', async () => {
347348

348349
expect(fs.readFileSync('/foo.js', 'utf-8')).toMatch('foo(1)')
349350
expect(fs.readFileSync('/bar/bar.js', 'utf-8')).toMatch('bar(2)')
351+
expect(fs.readFileSync('/bar/.bar.js', 'utf-8')).toMatch('.bar(2)')
350352
expect(fs.readFileSync('/replace.js', 'utf-8')).toMatch('baz(2)')
351353
expect(fs.readFileSync('/multi-replace.js', 'utf-8')).toMatch('baz(1)\nqux(2)')
352354
expect(fs.readFileSync('/.gitignore', 'utf-8')).toMatch('foo')

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ class GeneratorAPI {
169169
const globby = require('globby')
170170
const _files = await globby(['**/*'], { cwd: source })
171171
for (const rawPath of _files) {
172-
const targetPath = rawPath.split(path.sep).map(filename => {
172+
const targetPath = rawPath.split('/').map(filename => {
173173
// dotfiles are ignored when published to npm, therefore in templates
174174
// we need to use underscore instead (e.g. "_gitignore")
175175
if (filename.charAt(0) === '_' && filename.charAt(1) !== '_') {
@@ -179,7 +179,7 @@ class GeneratorAPI {
179179
return `${filename.slice(1)}`
180180
}
181181
return filename
182-
}).join(path.sep)
182+
}).join('/')
183183
const sourcePath = path.resolve(source, rawPath)
184184
const content = renderFile(sourcePath, data, ejsOptions)
185185
// only set file if it's not all whitespace, or is a Buffer (binary files)

0 commit comments

Comments
 (0)