refactor: default skipInstalls to null

This allows users to control true/false explicitly via config.

Related: #2647
This commit is contained in:
Rhys Arkins 2018-10-12 20:00:49 +02:00
parent bf1be75077
commit 6fc40ad4f4
3 changed files with 24 additions and 11 deletions

View file

@ -251,6 +251,7 @@ const options = [
description: description:
'Skip installing modules/dependencies if lock file updating is possible alone', 'Skip installing modules/dependencies if lock file updating is possible alone',
type: 'boolean', type: 'boolean',
default: null,
admin: true, admin: true,
}, },
{ {

View file

@ -94,7 +94,7 @@ async function extractDependencies(content, fileName, config) {
let lernaDir; let lernaDir;
let lernaPackages; let lernaPackages;
let lernaClient; let lernaClient;
let skipInstalls = true; let hasFileRefs = false;
const lernaJson = JSON.parse( const lernaJson = JSON.parse(
await platform.getFile(upath.join(path.dirname(fileName), 'lerna.json')) await platform.getFile(upath.join(path.dirname(fileName), 'lerna.json'))
); );
@ -134,7 +134,7 @@ async function extractDependencies(content, fileName, config) {
} }
if (dep.currentValue.startsWith('file:')) { if (dep.currentValue.startsWith('file:')) {
dep.skipReason = 'file'; dep.skipReason = 'file';
skipInstalls = false; hasFileRefs = true;
return dep; return dep;
} }
if (semver.isValid(dep.currentValue)) { if (semver.isValid(dep.currentValue)) {
@ -237,6 +237,18 @@ async function extractDependencies(content, fileName, config) {
return null; return null;
} }
} }
let skipInstalls = config.skipInstalls;
if (skipInstalls === null) {
if (hasFileRefs) {
// https://npm.community/t/npm-i-package-lock-only-changes-lock-file-incorrectly-when-file-references-used-in-dependencies/1412
// Explanation:
// - npm install --package-lock-only is buggy for transitive deps in file: references
// - So we set skipInstalls to false if file: refs are found *and* the user hasn't explicitly set the value already
skipInstalls = false;
} else {
skipInstalls = true;
}
}
return { return {
deps, deps,
packageJsonName, packageJsonName,
@ -248,7 +260,7 @@ async function extractDependencies(content, fileName, config) {
lernaDir, lernaDir,
lernaClient, lernaClient,
lernaPackages, lernaPackages,
skipInstalls: config.skipInstalls && skipInstalls, skipInstalls,
yarnWorkspacesPackages, yarnWorkspacesPackages,
}; };
} }

View file

@ -77,7 +77,7 @@ Array [
"semanticCommits": null, "semanticCommits": null,
"separateMajorMinor": true, "separateMajorMinor": true,
"separateMinorPatch": false, "separateMinorPatch": false,
"skipInstalls": true, "skipInstalls": null,
"statusCheckVerify": false, "statusCheckVerify": false,
"timezone": null, "timezone": null,
"unpublishSafe": false, "unpublishSafe": false,
@ -168,7 +168,7 @@ Array [
"semanticCommits": null, "semanticCommits": null,
"separateMajorMinor": true, "separateMajorMinor": true,
"separateMinorPatch": false, "separateMinorPatch": false,
"skipInstalls": true, "skipInstalls": null,
"statusCheckVerify": false, "statusCheckVerify": false,
"timezone": null, "timezone": null,
"unpublishSafe": false, "unpublishSafe": false,
@ -258,7 +258,7 @@ Array [
"semanticCommits": null, "semanticCommits": null,
"separateMajorMinor": true, "separateMajorMinor": true,
"separateMinorPatch": false, "separateMinorPatch": false,
"skipInstalls": true, "skipInstalls": null,
"statusCheckVerify": false, "statusCheckVerify": false,
"timezone": null, "timezone": null,
"unpublishSafe": false, "unpublishSafe": false,
@ -350,7 +350,7 @@ Array [
"semanticCommits": null, "semanticCommits": null,
"separateMajorMinor": true, "separateMajorMinor": true,
"separateMinorPatch": false, "separateMinorPatch": false,
"skipInstalls": true, "skipInstalls": null,
"statusCheckVerify": false, "statusCheckVerify": false,
"timezone": null, "timezone": null,
"unpublishSafe": false, "unpublishSafe": false,
@ -440,7 +440,7 @@ Array [
"semanticCommits": null, "semanticCommits": null,
"separateMajorMinor": true, "separateMajorMinor": true,
"separateMinorPatch": false, "separateMinorPatch": false,
"skipInstalls": true, "skipInstalls": null,
"statusCheckVerify": false, "statusCheckVerify": false,
"timezone": null, "timezone": null,
"unpublishSafe": false, "unpublishSafe": false,
@ -532,7 +532,7 @@ Array [
"semanticCommits": null, "semanticCommits": null,
"separateMajorMinor": true, "separateMajorMinor": true,
"separateMinorPatch": false, "separateMinorPatch": false,
"skipInstalls": true, "skipInstalls": null,
"statusCheckVerify": false, "statusCheckVerify": false,
"timezone": null, "timezone": null,
"unpublishSafe": false, "unpublishSafe": false,
@ -623,7 +623,7 @@ Array [
"semanticCommits": null, "semanticCommits": null,
"separateMajorMinor": true, "separateMajorMinor": true,
"separateMinorPatch": false, "separateMinorPatch": false,
"skipInstalls": true, "skipInstalls": null,
"statusCheckVerify": false, "statusCheckVerify": false,
"timezone": null, "timezone": null,
"unpublishSafe": false, "unpublishSafe": false,
@ -714,7 +714,7 @@ Array [
"semanticCommits": null, "semanticCommits": null,
"separateMajorMinor": true, "separateMajorMinor": true,
"separateMinorPatch": false, "separateMinorPatch": false,
"skipInstalls": true, "skipInstalls": null,
"statusCheckVerify": false, "statusCheckVerify": false,
"timezone": null, "timezone": null,
"unpublishSafe": false, "unpublishSafe": false,