8000 feat: respect existing package.json by zyy7259 · Pull Request #4827 · vuejs/vue-cli · GitHub
[go: up one dir, main page]

Skip to content

feat: respect existing package.json #4827

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions packages/@vue/cli-service/lib/Service.js
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7045,7 +7045,7 @@ errorhandler@^1.5.1:
accepts "~1.3.7"
escape-html "~1.0.3"

es-abstract@^1.12.0, es-abstract@^1.4.3, es-abstract@^1.5.1, es-abstract@^1.7.0:
es-abstract@^1.12.0, es-abstract@^1.5.1, es-abstract@^1.7.0:
version "1.16.2"
resolved "https://registry.yarnpkg.com/es-abstract/-/es-abstract-1.16.2.tgz#4e874331645e9925edef141e74fc4bd144669d34"
integrity sha512-jYo/J8XU2emLXl3OLwfwtuFfuF2w6DYPs+xy9ZfVyPkDcrauu6LYrw/q2TyCtrbc/KUdCiC5e9UajRhgNkVopA==
Expand Down Expand Up @@ -7257,7 +7257,7 @@ eslint-plugin-vue-libs@^4.0.0:
babel-eslint "^10.0.1"
eslint-plugin-vue "^5.1.0"

eslint-plugin-vue@^5.1.0, eslint-plugin-vue@^5.2.2:
eslint-plugin-vue@^5.0.0, eslint-plugin-vue@^5.1.0, eslint-plugin-vue@^5.2.2:
version "5.2.3"
resolved "https://registry.yarnpkg.com/eslint-plugin-vue/-/eslint-plugin-vue-5.2.3.tgz#3ee7597d823b5478804b2feba9863b1b74273961"
integrity sha512-mGwMqbbJf0+VvpGR5Lllq0PMxvTdrZ/ZPjmhkacrCHbubJeJOt+T6E3HUzAifa2Mxi7RSdJfC9HFpOeSYVMMIw==
Expand Down Expand Up @@ -8277,7 +8277,7 @@ ftp@~0.3.10:
readable-stream "1.1.x"
xregexp "2.0.0"

function-bind@^1.0.2, function-bind@^1.1.1:
function-bind@^1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/function-bind/-/function-bind-1.1.1.tgz#a56899d3ea3c9bab874bb9773b7c5ede92f4895d"
integrity sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==
Expand Down Expand Up @@ -14839,7 +14839,7 @@ request-promise@^4.2.4:
stealthy-require "^1.1.1"
tough-cookie "^2.3.3"

request@2.88.0, request@^2.67.0, request@^2.83.0, request@^2.87.0, request@^2.88.0:
request@2.88.0, request@^2.67.0, request@^2.87.0, request@^2.88.0:
version "2.88.0"
resolved "https://registry.yarnpkg.com/request/-/request-2.88.0.tgz#9c2fca4f7d35b592efe57c7f0a55e81052124fef"
integrity sha512-NAqBSrijGLZdM0WZNsInLJpkJokL72XYjUpnB0iwsRgxh7dB6COrHnTBNwN0E+lHDAJzu7kLAkDeY08z2/A0hg==
Expand Down
0