fix(npm): fix detecting logic of npmClient (#4130)

fix(npm): fix detecting logic of npmClient
This commit is contained in:
azu 2019-07-20 16:46:47 +09:00 committed by Rhys Arkins
parent 689f86aa52
commit 6333646e6d
3 changed files with 224 additions and 1 deletions

View file

@ -131,7 +131,8 @@ async function extractPackageFile(content, fileName, config) {
if (lernaJson) {
lernaDir = path.dirname(fileName);
lernaPackages = lernaJson.packages;
lernaClient = lernaJson.npmClient || lockFiles.yarnLock ? 'yarn' : 'npm';
lernaClient =
lernaJson.npmClient === 'yarn' || lockFiles.yarnLock ? 'yarn' : 'npm';
}
const depTypes = {

View file

@ -337,6 +337,200 @@ Object {
}
`;
exports[`manager/npm/extract .extractPackageFile() finds "npmClient":"npm" in lerna.json 1`] = `
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",
},
],
"ignoreNpmrcFile": undefined,
"lernaClient": "npm",
"lernaDir": ".",
"lernaPackages": undefined,
"npmLock": undefined,
"npmrc": undefined,
"packageJsonName": "renovate",
"packageJsonType": "app",
"packageJsonVersion": "1.0.0",
"pnpmShrinkwrap": undefined,
"skipInstalls": true,
"yarnLock": undefined,
"yarnWorkspacesPackages": undefined,
"yarnrc": undefined,
}
`;
exports[`manager/npm/extract .extractPackageFile() finds "npmClient":"yarn" in lerna.json 1`] = `
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",
},
],
"ignoreNpmrcFile": undefined,
"lernaClient": "yarn",
"lernaDir": ".",
"lernaPackages": undefined,
"npmLock": undefined,
"npmrc": undefined,
"packageJsonName": "renovate",
"packageJsonType": "app",
"packageJsonVersion": "1.0.0",
"pnpmShrinkwrap": undefined,
"skipInstalls": true,
"yarnLock": undefined,
"yarnWorkspacesPackages": undefined,
"yarnrc": undefined,
}
`;
exports[`manager/npm/extract .extractPackageFile() finds a lock file 1`] = `
Object {
"deps": Array [

View file

@ -137,6 +137,34 @@ describe('manager/npm/extract', () => {
);
expect(res).toMatchSnapshot();
});
it('finds "npmClient":"npm" in lerna.json', async () => {
platform.getFile = jest.fn(fileName => {
if (fileName === 'lerna.json') {
return '{ "npmClient": "npm" }';
}
return null;
});
const res = await npmExtract.extractPackageFile(
input01Content,
'package.json',
defaultConfig
);
expect(res).toMatchSnapshot();
});
it('finds "npmClient":"yarn" in lerna.json', async () => {
platform.getFile = jest.fn(fileName => {
if (fileName === 'lerna.json') {
return '{ "npmClient": "yarn" }';
}
return null;
});
const res = await npmExtract.extractPackageFile(
input01Content,
'package.json',
defaultConfig
);
expect(res).toMatchSnapshot();
});
it('finds complex yarn workspaces', async () => {
platform.getFile = jest.fn(fileName => {
if (fileName === 'lerna.json') {