Skip to content

Commit 5be05f3

Browse files
committed
fix: fix project creation when path contains spaces (fix #742)
1 parent b8f2487 commit 5be05f3

File tree

3 files changed

+13
-16
lines changed

3 files changed

+13
-16
lines changed

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

+11-14
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
const fs = require('fs')
22
const ejs = require('ejs')
33
const path = require('path')
4-
const walk = require('klaw-sync')
4+
const globby = require('globby')
55
const isBinary = require('isbinaryfile')
66
const mergeDeps = require('./util/mergeDeps')
7-
const errorParser = require('error-stack-parser')
87

98
const isString = val => typeof val === 'string'
109
const isFunction = val => typeof val === 'function'
@@ -52,25 +51,22 @@ module.exports = class GeneratorAPI {
5251
const baseDir = extractCallDir()
5352
if (isString(fileDir)) {
5453
fileDir = path.resolve(baseDir, fileDir)
55-
this.injectFileMiddleware(files => {
54+
this.injectFileMiddleware(async (files) => {
5655
const data = Object.assign({
5756
options: this.options,
5857
rootOptions: this.rootOptions
5958
}, additionalData)
60-
const _files = walk(fileDir, {
61-
nodir: true,
62-
filter: file => path.basename(file.path) !== '.DS_Store'
63-
})
64-
for (const file of _files) {
65-
let filename = path.basename(file.path)
59+
const _files = await globby(['**/*'], { cwd: fileDir })
60+
for (const rawPath of _files) {
61+
let filename = path.basename(rawPath)
6662
// dotfiles are ignored when published to npm, therefore in templates
6763
// we need to use underscore instead (e.g. "_gitignore")
6864
if (filename.charAt(0) === '_') {
6965
filename = `.${filename.slice(1)}`
7066
}
71-
const normalizedPath = path.join(path.dirname(file.path), filename)
72-
const targetPath = path.relative(fileDir, normalizedPath)
73-
const content = renderFile(file.path, data, ejsOptions)
67+
const targetPath = path.join(path.dirname(rawPath), filename)
68+
const sourcePath = path.resolve(fileDir, rawPath)
69+
const content = renderFile(sourcePath, data, ejsOptions)
7470
// only set file if it's not all whitespace, or is a Buffer (binary files)
7571
if (Buffer.isBuffer(content) || /[^\s]/.test(content)) {
7672
files[targetPath] = content
@@ -117,8 +113,9 @@ function extractCallDir () {
117113
// extract api.render() callsite file location using error stack
118114
const obj = {}
119115
Error.captureStackTrace(obj)
120-
const stack = errorParser.parse(obj)
121-
return path.dirname(stack[2].fileName)
116+
const callSite = obj.stack.split('\n')[3]
117+
const fileName = callSite.match(/\s\((.*):\d+:\d+\)$/)[1]
118+
return path.dirname(fileName)
122119
}
123120

124121
function renderFile (name, data, ejsOptions) {

packages/@vue/cli/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
"chalk": "^2.3.0",
3333
"commander": "^2.12.2",
3434
"ejs": "^2.5.7",
35-
"error-stack-parser": "^2.0.1",
3635
"execa": "^0.8.0",
36+
"globby": "^7.1.1",
3737
"import-global": "^0.1.0",
3838
"inquirer": "^4.0.1",
3939
"isbinaryfile": "^3.0.2",

yarn.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -3270,7 +3270,7 @@ error-ex@^1.2.0, error-ex@^1.3.1:
32703270
dependencies:
32713271
is-arrayish "^0.2.1"
32723272

3273-
error-stack-parser@^2.0.0, error-stack-parser@^2.0.1:
3273+
error-stack-parser@^2.0.0:
32743274
version "2.0.1"
32753275
resolved "https://registry.yarnpkg.com/error-stack-parser/-/error-stack-parser-2.0.1.tgz#a3202b8fb03114aa9b40a0e3669e48b2b65a010a"
32763276
dependencies:

0 commit comments

Comments
 (0)