diff --git a/__tests__/commands/install.js b/__tests__/commands/install.js index d10eaaa0a9..298f13c17a 100644 --- a/__tests__/commands/install.js +++ b/__tests__/commands/install.js @@ -49,14 +49,18 @@ test.concurrent('flat arg is inherited from root manifest', async (): Promise => { - return runInstall({}, 'install-dont-write-lockfile-if-satisfied', async (config): Promise => { - const lockfile = await fs.readFile(path.join(config.cwd, 'yarn.lock')); - assert(lockfile.indexOf('foobar') >= 0); - }); + return runInstall( + {writeLockfile: true}, + 'install-dont-write-lockfile-if-satisfied', + async (config): Promise => { + const lockfile = await fs.readFile(path.join(config.cwd, 'yarn.lock')); + assert(lockfile.indexOf('foobar') >= 0); + }, + ); }); test.concurrent("writes new lockfile if existing one isn't satisfied", async (): Promise => { - await runInstall({}, 'install-write-lockfile-if-not-satisfied', async (config): Promise => { + await runInstall({writeLockfile: true}, 'install-write-lockfile-if-not-satisfied', async (config): Promise => { const lockfile = await fs.readFile(path.join(config.cwd, 'yarn.lock')); assert(lockfile.indexOf('foobar') === -1); }); @@ -393,7 +397,7 @@ test.concurrent( (): Promise => { const mirrorPath = 'mirror-for-offline'; - return runInstall({}, 'uninstall-should-clean', async (config, reporter) => { + return runInstall({writeLockfile: true}, 'uninstall-should-clean', async (config, reporter) => { assert.equal( await getPackageVersion(config, 'dep-a'), '1.0.0', @@ -557,9 +561,9 @@ test.concurrent('install should resolve circular dependencies 2', (): Promise => { - return runInstall({}, 'install-import-pr', async (config) => { + return runInstall({writeLockfile: true}, 'install-import-pr', async (config) => { assert.equal(await getPackageVersion(config, 'mime-types'), '2.0.0'); assert(semver.satisfies(await getPackageVersion(config, 'mime-db'), '~1.0.1')); assert.equal(await getPackageVersion(config, 'fake-yarn-dependency'), '1.0.1'); @@ -579,7 +583,6 @@ test.concurrent( }, ); - xit('install should update a dependency to yarn and mirror (PR import scenario 2)', (): Promise => { // mime-types@2.0.0 is saved in local mirror and gets updated to mime-types@2.1.11 via // a change in package.json, diff --git a/scripts/check-lockfile.sh b/scripts/check-lockfile.sh index 548851e5f2..c43fa234bc 100755 --- a/scripts/check-lockfile.sh +++ b/scripts/check-lockfile.sh @@ -15,7 +15,7 @@ cp -r scripts $DIR/scripts cd $DIR # install with yarn and run check -../bin/yarn.js install --pure-lockfile +../bin/yarn.js install ../bin/yarn.js check # cleanup diff --git a/src/cli/commands/add.js b/src/cli/commands/add.js index 41d4136c1a..c081d47f80 100644 --- a/src/cli/commands/add.js +++ b/src/cli/commands/add.js @@ -23,6 +23,7 @@ export class Add extends Install { ) { super(flags, config, reporter, lockfile); this.args = args; + this.flags.writeLockfile = true; } args: Array; diff --git a/src/cli/commands/install.js b/src/cli/commands/install.js index c09591ce06..0c6adeeafe 100644 --- a/src/cli/commands/install.js +++ b/src/cli/commands/install.js @@ -59,7 +59,7 @@ type Flags = { flat: boolean, production: boolean, lockfile: boolean, - pureLockfile: boolean, + writeLockfile: boolean, skipIntegrity: boolean, // add @@ -82,7 +82,7 @@ function normalizeFlags(config: Config, rawFlags: Object): Flags { flat: !!rawFlags.flat, production: !!rawFlags.production, lockfile: rawFlags.lockfile !== false, - pureLockfile: !!rawFlags.pureLockfile, + writeLockfile: !!rawFlags.writeLockfile, skipIntegrity: !!rawFlags.skipIntegrity, // add @@ -354,8 +354,12 @@ export class Install { await step(++currentStep, steps.length); } - // fin! - await this.saveLockfileAndIntegrity(rawPatterns); + // Write lockfile if none exist, or if flag given + const lockfileLoc = path.join(this.config.cwd, constants.LOCKFILE_FILENAME); + if (!(await fs.exists(lockfileLoc)) || this.flags.writeLockfile) { + await this.saveLockfileAndIntegrity(rawPatterns); + } + this.config.requestManager.clearCache(); return patterns; } @@ -472,8 +476,8 @@ export class Install { // write integrity hash await this.writeIntegrityHash(lockSource, patterns); - // --no-lockfile or --pure-lockfile flag - if (this.flags.lockfile === false || this.flags.pureLockfile) { + // --no-lockfile flag + if (this.flags.lockfile === false) { return; } @@ -653,7 +657,7 @@ export function _setFlags(commander: Object) { commander.option('--flat', 'only allow one version of a package'); commander.option('--prod, --production', ''); commander.option('--no-lockfile', "don't read or generate a lockfile"); - commander.option('--pure-lockfile', "don't generate a lockfile"); + commander.option('--write-lockfile', 'generate a lockfile'); } export function setFlags(commander: Object) { diff --git a/src/cli/commands/remove.js b/src/cli/commands/remove.js index a021c8fc5a..c4bf545121 100644 --- a/src/cli/commands/remove.js +++ b/src/cli/commands/remove.js @@ -76,7 +76,7 @@ export async function run( // reinstall so we can get the updated lockfile reporter.step(++step, totalSteps, reporter.lang('uninstallRegenerate')); - const reinstall = new Install({force: true, ...flags}, config, new NoopReporter(), lockfile); + const reinstall = new Install({force: true, writeLockfile: true, ...flags}, config, new NoopReporter(), lockfile); await reinstall.init(); //