Skip to content

Commit 8540ae2

Browse files
pksunkaramactanxin
authored andcommitted
fix: extendPackage object values should be string (vuejs#5038)
1 parent 8691daf commit 8540ae2

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

packages/@vue/cli/__tests__/Generator.spec.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,30 @@ test('api: warn invalid dep range', async () => {
280280
})).toBe(true)
281281
})
282282

283+
test('api: warn invalid dep range when non-string', async () => {
284+
const generator = new Generator('/', { plugins: [
285+
{
286+
id: 'test1',
287+
apply: api => {
288+
api.extendPackage({
289+
dependencies: {
290+
foo: null
291+
}
292+
})
293+
}
294+
}
295+
] })
296+
297+
await generator.generate()
298+
299+
expect(logs.warn.some(([msg]) => {
300+
return (
301+
msg.match(/invalid version range for dependency "foo"/) &&
302+
msg.match(/injected by generator "test1"/)
303+
)
304+
})).toBe(true)
305+
})
306+
283307
test('api: extendPackage dependencies conflict', async () => {
284308
const generator = new Generator('/', { plugins: [
285309
{

packages/@vue/cli/lib/util/mergeDeps.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ module.exports = function resolveDeps (generatorId, to, from, sources, forceNewV
1010
for (const name in from) {
1111
const r1 = to[name]
1212
const r2 = from[name]
13+
const r2IsString = typeof r2 === 'string'
1314
const sourceGeneratorId = sources[name]
14-
const isValidURI = r2.match(/^(?:file|git|git\+ssh|git\+http|git\+https|git\+file|https?):/) != null
15-
const isValidGitHub = r2.match(/^[^/]+\/[^/]+/) != null
15+
const isValidURI = r2IsString && r2.match(/^(?:file|git|git\+ssh|git\+http|git\+https|git\+file|https?):/) != null
16+
const isValidGitHub = r2IsString && r2.match(/^[^/]+\/[^/]+/) != null
1617

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

0 commit comments

Comments
 (0)