Skip to content

Commit

Permalink
feat: respect existing package.json
Browse files Browse the repository at this point in the history
  • Loading branch information
zyy7259 committed Dec 19, 2019
1 parent 00acca5 commit 14ea723
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 13 deletions.
18 changes: 7 additions & 11 deletions packages/@vue/cli-service/lib/Service.js
@@ -1,14 +1,13 @@
const fs = require('fs')
const path = require('path')
const debug = require('debug')
const readPkg = require('read-pkg')
const merge = require('webpack-merge')
const Config = require('webpack-chain')
const PluginAPI = require('./PluginAPI')
const dotenv = require('dotenv')
const dotenvExpand = require('dotenv-expand')
const defaultsDeep = require('lodash.defaultsdeep')
const { chalk, warn, error, isPlugin, resolvePluginId, loadModule } = require('@vue/cli-shared-utils')
const { chalk, warn, error, isPlugin, resolvePluginId, loadModule, resolvePkg } = require('@vue/cli-shared-utils')

const { defaults, validate } = require('./options')

Expand Down Expand Up @@ -44,16 +43,13 @@ module.exports = class Service {
resolvePkg (inlinePkg, context = this.context) {
if (inlinePkg) {
return inlinePkg
} else if (fs.existsSync(path.join(context, 'package.json'))) {
const pkg = readPkg.sync({ cwd: context })
if (pkg.vuePlugins && pkg.vuePlugins.resolveFrom) {
this.pkgContext = path.resolve(context, pkg.vuePlugins.resolveFrom)
return this.resolvePkg(null, this.pkgContext)
}
return pkg
} else {
return {}
}
const pkg = resolvePkg(context)
if (pkg.vuePlugins && pkg.vuePlugins.resolveFrom) {
this.pkgContext = path.resolve(context, pkg.vuePlugins.resolveFrom)
return this.resolvePkg(null, this.pkgContext)
}
return pkg
}

init (mode = process.env.VUE_CLI_MODE) {
Expand Down
1 change: 0 additions & 1 deletion packages/@vue/cli-service/package.json
Expand Up @@ -63,7 +63,6 @@
"minimist": "^1.2.0",
"portfinder": "^1.0.25",
"postcss-loader": "^3.0.0",
"read-pkg": "^5.1.1",
"ssri": "^7.1.0",
"terser-webpack-plugin": "^2.2.1",
"thread-loader": "^2.1.3",
Expand Down
1 change: 1 addition & 0 deletions packages/@vue/cli-shared-utils/index.js
Expand Up @@ -6,6 +6,7 @@
'module',
'object',
'openBrowser',
'pkg',
'pluginResolution',
'launch',
'request',
Expand Down
10 changes: 10 additions & 0 deletions packages/@vue/cli-shared-utils/lib/pkg.js
@@ -0,0 +1,10 @@
const fs = require('fs')
const path = require('path')
const readPkg = require('read-pkg')

exports.resolvePkg = function (context) {
if (fs.existsSync(path.join(context, 'package.json'))) {
return readPkg.sync({ cwd: context })
}
return {}
}
1 change: 1 addition & 0 deletions packages/@vue/cli-shared-utils/package.json
Expand Up @@ -28,6 +28,7 @@
"node-ipc": "^9.1.1",
"open": "^6.3.0",
"ora": "^3.4.0",
"read-pkg": "^5.1.1",
"request": "^2.87.0",
"request-promise-native": "^1.0.8",
"semver": "^6.1.0",
Expand Down
4 changes: 3 additions & 1 deletion packages/@vue/cli/lib/Creator.js
Expand Up @@ -14,6 +14,7 @@ const { formatFeatures } = require('./util/features')
const loadLocalPreset = require('./util/loadLocalPreset')
const loadRemotePreset = require('./util/loadRemotePreset')
const generateReadme = require('./util/generateReadme')
const { resolvePkg } = require('@vue/cli-shared-utils')

const {
defaults,
Expand Down Expand Up @@ -146,7 +147,8 @@ module.exports = class Creator extends EventEmitter {
name,
version: '0.1.0',
private: true,
devDependencies: {}
devDependencies: {},
...resolvePkg(context)
}
const deps = Object.keys(preset.plugins)
deps.forEach(dep => {
Expand Down

0 comments on commit 14ea723

Please sign in to comment.