diff --git a/packages/@vue/cli/lib/GeneratorAPI.js b/packages/@vue/cli/lib/GeneratorAPI.js index e53021edbc..458b4a5b75 100644 --- a/packages/@vue/cli/lib/GeneratorAPI.js +++ b/packages/@vue/cli/lib/GeneratorAPI.js @@ -1,10 +1,9 @@ const fs = require('fs') const ejs = require('ejs') const path = require('path') -const walk = require('klaw-sync') +const globby = require('globby') const isBinary = require('isbinaryfile') const mergeDeps = require('./util/mergeDeps') -const errorParser = require('error-stack-parser') const isString = val => typeof val === 'string' const isFunction = val => typeof val === 'function' @@ -52,25 +51,22 @@ module.exports = class GeneratorAPI { const baseDir = extractCallDir() if (isString(fileDir)) { fileDir = path.resolve(baseDir, fileDir) - this.injectFileMiddleware(files => { + this.injectFileMiddleware(async (files) => { const data = Object.assign({ options: this.options, rootOptions: this.rootOptions }, additionalData) - const _files = walk(fileDir, { - nodir: true, - filter: file => path.basename(file.path) !== '.DS_Store' - }) - for (const file of _files) { - let filename = path.basename(file.path) + const _files = await globby(['**/*'], { cwd: fileDir }) + for (const rawPath of _files) { + let filename = path.basename(rawPath) // dotfiles are ignored when published to npm, therefore in templates // we need to use underscore instead (e.g. "_gitignore") if (filename.charAt(0) === '_') { filename = `.${filename.slice(1)}` } - const normalizedPath = path.join(path.dirname(file.path), filename) - const targetPath = path.relative(fileDir, normalizedPath) - const content = renderFile(file.path, data, ejsOptions) + const targetPath = path.join(path.dirname(rawPath), filename) + const sourcePath = path.resolve(fileDir, rawPath) + const content = renderFile(sourcePath, data, ejsOptions) // only set file if it's not all whitespace, or is a Buffer (binary files) if (Buffer.isBuffer(content) || /[^\s]/.test(content)) { files[targetPath] = content @@ -117,8 +113,9 @@ function extractCallDir () { // extract api.render() callsite file location using error stack const obj = {} Error.captureStackTrace(obj) - const stack = errorParser.parse(obj) - return path.dirname(stack[2].fileName) + const callSite = obj.stack.split('\n')[3] + const fileName = callSite.match(/\s\((.*):\d+:\d+\)$/)[1] + return path.dirname(fileName) } function renderFile (name, data, ejsOptions) { diff --git a/packages/@vue/cli/package.json b/packages/@vue/cli/package.json index 3822ba99bf..6a59bf6fde 100644 --- a/packages/@vue/cli/package.json +++ b/packages/@vue/cli/package.json @@ -32,8 +32,8 @@ "chalk": "^2.3.0", "commander": "^2.12.2", "ejs": "^2.5.7", - "error-stack-parser": "^2.0.1", "execa": "^0.8.0", + "globby": "^7.1.1", "import-global": "^0.1.0", "inquirer": "^4.0.1", "isbinaryfile": "^3.0.2", diff --git a/yarn.lock b/yarn.lock index e83209d597..4cab602a76 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3270,7 +3270,7 @@ error-ex@^1.2.0, error-ex@^1.3.1: dependencies: is-arrayish "^0.2.1" -error-stack-parser@^2.0.0, error-stack-parser@^2.0.1: +error-stack-parser@^2.0.0: version "2.0.1" resolved "https://registry.yarnpkg.com/error-stack-parser/-/error-stack-parser-2.0.1.tgz#a3202b8fb03114aa9b40a0e3669e48b2b65a010a" dependencies: