From 4efd9b87ef82a3e157c8425f26fdc80779920bbc Mon Sep 17 00:00:00 2001 From: Jeremy Morrell Date: Thu, 31 May 2018 15:57:03 -0700 Subject: [PATCH 1/2] Warn the user if a package-lock.json exists --- src/cli/commands/install.js | 7 ++++++- src/constants.js | 1 + src/reporters/lang/en.js | 2 ++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/cli/commands/install.js b/src/cli/commands/install.js index 2b02503c16..066ecc2c4b 100644 --- a/src/cli/commands/install.js +++ b/src/cli/commands/install.js @@ -516,10 +516,15 @@ export class Install { this.checkUpdate(); // warn if we have a shrinkwrap - if (await fs.exists(path.join(this.config.lockfileFolder, 'npm-shrinkwrap.json'))) { + if (await fs.exists(path.join(this.config.lockfileFolder, constants.NPM_SHRINKWRAP_FILENAME))) { this.reporter.warn(this.reporter.lang('shrinkwrapWarning')); } + // warn if we have an npm lockfile + if (await fs.exists(path.join(this.config.lockfileFolder, constants.NPM_LOCK_FILENAME))) { + this.reporter.warn(this.reporter.lang('npmLockfileWarning')); + } + // running a focused install in a workspace root is not allowed if (this.flags.focus && (!this.config.workspaceRootFolder || this.config.cwd === this.config.workspaceRootFolder)) { throw new MessageError(this.reporter.lang('workspacesFocusRootCheck')); diff --git a/src/constants.js b/src/constants.js index f41f10784b..bbd0580432 100644 --- a/src/constants.js +++ b/src/constants.js @@ -86,6 +86,7 @@ export const TARBALL_FILENAME = '.yarn-tarball.tgz'; export const CLEAN_FILENAME = '.yarnclean'; export const NPM_LOCK_FILENAME = 'package-lock.json'; +export const NPM_SHRINKWRAP_FILENAME = 'npm-shrinkwrap.json'; export const DEFAULT_INDENT = ' '; export const SINGLE_INSTANCE_PORT = 31997; diff --git a/src/reporters/lang/en.js b/src/reporters/lang/en.js index 9a1e128f7c..6c8c527147 100644 --- a/src/reporters/lang/en.js +++ b/src/reporters/lang/en.js @@ -94,6 +94,8 @@ const messages = { couldntFindManifestIn: "Couldn't find manifest in $0.", shrinkwrapWarning: 'npm-shrinkwrap.json found. This will not be updated or respected. See https://yarnpkg.com/en/docs/migrating-from-npm for more information.', + npmLockfileWarning: + 'package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json.', lockfileOutdated: 'Outdated lockfile. Please run `yarn install` and try again.', lockfileMerged: 'Merge conflict detected in yarn.lock and successfully merged.', lockfileConflict: From 59f78815dd1351898bfbd0932cd8ccda1f859adc Mon Sep 17 00:00:00 2001 From: Jeremy Morrell Date: Thu, 31 May 2018 16:42:10 -0700 Subject: [PATCH 2/2] Add tests for warnings --- __tests__/commands/install/lockfiles.js | 16 ++++++++++++++++ .../npm-shrinkwrap.json | 11 +++++++++++ .../package.json | 5 +++++ .../package-lock.json | 11 +++++++++++ .../package.json | 5 +++++ 5 files changed, 48 insertions(+) create mode 100644 __tests__/fixtures/install/lockfile-conflict-npm-shrinkwrap-json/npm-shrinkwrap.json create mode 100644 __tests__/fixtures/install/lockfile-conflict-npm-shrinkwrap-json/package.json create mode 100644 __tests__/fixtures/install/lockfile-conflict-package-lock-json/package-lock.json create mode 100644 __tests__/fixtures/install/lockfile-conflict-package-lock-json/package.json diff --git a/__tests__/commands/install/lockfiles.js b/__tests__/commands/install/lockfiles.js index 2fb6df8aec..461eab56a1 100644 --- a/__tests__/commands/install/lockfiles.js +++ b/__tests__/commands/install/lockfiles.js @@ -326,3 +326,19 @@ test.concurrent("install should fix if lockfile patterns don't match resolved ve expect(lockContent).toContain('left-pad-1.1.2.tgz'); }); }); + +test.concurrent('install should warn if a conflicting npm package-lock.json exists', (): Promise => { + const fixture = 'lockfile-conflict-package-lock-json'; + + return runInstall({}, fixture, (config, reporter, install, getStdout) => { + expect(getStdout()).toContain('package-lock.json found'); + }); +}); + +test.concurrent('install should warn if a conflicting npm npm-shrinkwrap.json exists', (): Promise => { + const fixture = 'lockfile-conflict-npm-shrinkwrap-json'; + + return runInstall({}, fixture, (config, reporter, install, getStdout) => { + expect(getStdout()).toContain('npm-shrinkwrap.json found'); + }); +}); diff --git a/__tests__/fixtures/install/lockfile-conflict-npm-shrinkwrap-json/npm-shrinkwrap.json b/__tests__/fixtures/install/lockfile-conflict-npm-shrinkwrap-json/npm-shrinkwrap.json new file mode 100644 index 0000000000..57e1b1f1d6 --- /dev/null +++ b/__tests__/fixtures/install/lockfile-conflict-npm-shrinkwrap-json/npm-shrinkwrap.json @@ -0,0 +1,11 @@ +{ + "requires": true, + "lockfileVersion": 1, + "dependencies": { + "left-pad": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/left-pad/-/left-pad-1.3.0.tgz", + "integrity": "sha512-XI5MPzVNApjAyhQzphX8BkmKsKUxD4LdyK24iZeQGinBN9yTQT3bFlCBy/aVx2HrNcqQGsdot8ghrjyrvMCoEA==" + } + } +} diff --git a/__tests__/fixtures/install/lockfile-conflict-npm-shrinkwrap-json/package.json b/__tests__/fixtures/install/lockfile-conflict-npm-shrinkwrap-json/package.json new file mode 100644 index 0000000000..839f7608e6 --- /dev/null +++ b/__tests__/fixtures/install/lockfile-conflict-npm-shrinkwrap-json/package.json @@ -0,0 +1,5 @@ +{ + "dependencies": { + "left-pad": "^1.1.3" + } +} diff --git a/__tests__/fixtures/install/lockfile-conflict-package-lock-json/package-lock.json b/__tests__/fixtures/install/lockfile-conflict-package-lock-json/package-lock.json new file mode 100644 index 0000000000..57e1b1f1d6 --- /dev/null +++ b/__tests__/fixtures/install/lockfile-conflict-package-lock-json/package-lock.json @@ -0,0 +1,11 @@ +{ + "requires": true, + "lockfileVersion": 1, + "dependencies": { + "left-pad": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/left-pad/-/left-pad-1.3.0.tgz", + "integrity": "sha512-XI5MPzVNApjAyhQzphX8BkmKsKUxD4LdyK24iZeQGinBN9yTQT3bFlCBy/aVx2HrNcqQGsdot8ghrjyrvMCoEA==" + } + } +} diff --git a/__tests__/fixtures/install/lockfile-conflict-package-lock-json/package.json b/__tests__/fixtures/install/lockfile-conflict-package-lock-json/package.json new file mode 100644 index 0000000000..839f7608e6 --- /dev/null +++ b/__tests__/fixtures/install/lockfile-conflict-package-lock-json/package.json @@ -0,0 +1,5 @@ +{ + "dependencies": { + "left-pad": "^1.1.3" + } +}