Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: extendPackage object values should be string #5038

Merged
merged 1 commit into from Jan 13, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 24 additions & 0 deletions packages/@vue/cli/__tests__/Generator.spec.js
Expand Up @@ -280,6 +280,30 @@ test('api: warn invalid dep range', async () => {
})).toBe(true)
})

test('api: warn invalid dep range when non-string', async () => {
const generator = new Generator('/', { plugins: [
{
id: 'test1',
apply: api => {
api.extendPackage({
dependencies: {
foo: null
}
})
}
}
] })

await generator.generate()

expect(logs.warn.some(([msg]) => {
return (
msg.match(/invalid version range for dependency "foo"/) &&
msg.match(/injected by generator "test1"/)
)
})).toBe(true)
})

test('api: extendPackage dependencies conflict', async () => {
const generator = new Generator('/', { plugins: [
{
Expand Down
5 changes: 3 additions & 2 deletions packages/@vue/cli/lib/util/mergeDeps.js
Expand Up @@ -10,9 +10,10 @@ module.exports = function resolveDeps (generatorId, to, from, sources, forceNewV
for (const name in from) {
const r1 = to[name]
const r2 = from[name]
const r2IsString = typeof r2 === 'string'
const sourceGeneratorId = sources[name]
const isValidURI = r2.match(/^(?:file|git|git\+ssh|git\+http|git\+https|git\+file|https?):/) != null
const isValidGitHub = r2.match(/^[^/]+\/[^/]+/) != null
const isValidURI = r2IsString && r2.match(/^(?:file|git|git\+ssh|git\+http|git\+https|git\+file|https?):/) != null
const isValidGitHub = r2IsString && r2.match(/^[^/]+\/[^/]+/) != null

// if they are the same, do nothing. Helps when non semver type deps are used
if (r1 === r2) continue
Expand Down