diff --git a/lib/manager/npm/__fixtures__/inputs/01-glob.json b/lib/manager/npm/__fixtures__/inputs/01-glob.json index 9f31f8be60b46a49ec2ad8b196ebb6fe8775f967..1f74c17744143aa468b2a3f20f73c23fdc735f5d 100644 --- a/lib/manager/npm/__fixtures__/inputs/01-glob.json +++ b/lib/manager/npm/__fixtures__/inputs/01-glob.json @@ -25,6 +25,7 @@ "@angular/core": "4.0.0-beta.1" }, "resolutions": { + "//": ["This is a comment"], "**/config": "1.21.0" }, "homepage": "https://keylocation.sg", diff --git a/lib/manager/npm/extract/__snapshots__/index.spec.ts.snap b/lib/manager/npm/extract/__snapshots__/index.spec.ts.snap index 3c03ff5b1f764db592e3ca33d05dd53bafd30627..8f96b954679a76e2e652b91f5df571789cc987c8 100644 --- a/lib/manager/npm/extract/__snapshots__/index.spec.ts.snap +++ b/lib/manager/npm/extract/__snapshots__/index.spec.ts.snap @@ -1229,3 +1229,121 @@ Object { "yarnrc": undefined, } `; + +exports[`manager/npm/extract/index .extractPackageFile() returns an array of dependencies with resolution comments 1`] = ` +Object { + "constraints": Object {}, + "deps": Array [ + Object { + "currentValue": "6.5.0", + "datasource": "npm", + "depName": "autoprefixer", + "depType": "dependencies", + "prettyDepType": "dependency", + }, + Object { + "currentValue": "~1.6.0", + "datasource": "npm", + "depName": "bower", + "depType": "dependencies", + "prettyDepType": "dependency", + }, + Object { + "currentValue": "13.1.0", + "datasource": "npm", + "depName": "browserify", + "depType": "dependencies", + "prettyDepType": "dependency", + }, + Object { + "currentValue": "0.9.2", + "datasource": "npm", + "depName": "browserify-css", + "depType": "dependencies", + "prettyDepType": "dependency", + }, + Object { + "currentValue": "=0.22.0", + "datasource": "npm", + "depName": "cheerio", + "depType": "dependencies", + "prettyDepType": "dependency", + }, + Object { + "currentValue": "1.21.0", + "datasource": "npm", + "depName": "config", + "depType": "dependencies", + "prettyDepType": "dependency", + }, + Object { + "depName": "enabled", + "depType": "devDependencies", + "prettyDepType": "devDependency", + "skipReason": "invalid-value", + }, + Object { + "currentValue": "^1.5.8", + "datasource": "npm", + "depName": "angular", + "depType": "devDependencies", + "prettyDepType": "devDependency", + }, + Object { + "currentValue": "1.5.8", + "datasource": "npm", + "depName": "angular-touch", + "depType": "devDependencies", + "prettyDepType": "devDependency", + }, + Object { + "currentValue": "1.5.8", + "datasource": "npm", + "depName": "angular-sanitize", + "depType": "devDependencies", + "prettyDepType": "devDependency", + }, + Object { + "currentValue": "4.0.0-beta.1", + "datasource": "npm", + "depName": "@angular/core", + "depType": "devDependencies", + "prettyDepType": "devDependency", + }, + Object { + "depName": undefined, + "depType": "resolutions", + "managerData": Object { + "key": "//", + }, + "prettyDepType": "resolutions", + "skipReason": "invalid-name", + }, + Object { + "currentValue": "1.21.0", + "datasource": "npm", + "depName": "config", + "depType": "resolutions", + "managerData": Object { + "key": "**/config", + }, + "prettyDepType": "resolutions", + }, + ], + "lernaClient": undefined, + "lernaPackages": undefined, + "managerData": Object { + "lernaJsonFile": undefined, + }, + "npmLock": undefined, + "npmrc": undefined, + "packageFileVersion": "1.0.0", + "packageJsonName": "renovate", + "packageJsonType": "app", + "pnpmShrinkwrap": undefined, + "skipInstalls": true, + "yarnLock": undefined, + "yarnWorkspacesPackages": Array [], + "yarnrc": undefined, +} +`; diff --git a/lib/manager/npm/extract/index.spec.ts b/lib/manager/npm/extract/index.spec.ts index 1252a2dfa7adda922b4264a360fe854f8c512fc6..83a3a08b5a639a2fb1d6bb96136da89c52b3667f 100644 --- a/lib/manager/npm/extract/index.spec.ts +++ b/lib/manager/npm/extract/index.spec.ts @@ -9,6 +9,7 @@ const fs: any = _fs; const defaultConfig = getConfig(); const input01Content = loadFixture('inputs/01.json', '..'); +const input01GlobContent = loadFixture('inputs/01-glob.json', '..'); const workspacesContent = loadFixture('inputs/workspaces.json', '..'); const workspacesSimpleContent = loadFixture( 'inputs/workspaces-simple.json', @@ -79,6 +80,15 @@ describe(getName(), () => { ); expect(res).toMatchSnapshot(); }); + it('returns an array of dependencies with resolution comments', async () => { + const res = await npmExtract.extractPackageFile( + input01GlobContent, + 'package.json', + defaultConfig + ); + expect(res?.deps).toHaveLength(13); + expect(res).toMatchSnapshot(); + }); it('finds a lock file', async () => { fs.readLocalFile = jest.fn((fileName) => { if (fileName === 'yarn.lock') { diff --git a/lib/manager/npm/extract/index.ts b/lib/manager/npm/extract/index.ts index a0f402a50168a01e8a0e93691de03b9d54db759f..56f0552712a705e028ed3df1c958eeb6f997eea0 100644 --- a/lib/manager/npm/extract/index.ts +++ b/lib/manager/npm/extract/index.ts @@ -25,7 +25,7 @@ function parseDepName(depType: string, key: string): string { return key; } - const [, depName] = /((?:@[^/]+\/)?[^/@]+)$/.exec(key); + const [, depName] = /((?:@[^/]+\/)?[^/@]+)$/.exec(key) ?? []; return depName; }