diff --git a/__tests__/commands/add.js b/__tests__/commands/add.js index 6eee488440..0f2f85427d 100644 --- a/__tests__/commands/add.js +++ b/__tests__/commands/add.js @@ -819,3 +819,15 @@ test.concurrent('should retain build artifacts after add', (): Promise => 'retain-build-artifacts-after-add', ); }); + +test.concurrent('installing with --pure-lockfile and then adding should keep build artifacts', (): Promise => { + const fixture = 'integrity-pure-lockfile'; + + return runInstall({pureLockfile: true}, path.join('..', 'add', fixture), async (config, reporter): Promise => { + expect(await fs.exists(path.join(config.cwd, 'node_modules', '.yarn-integrity'))).toBe(true); + expect(await fs.exists(path.join(config.cwd, 'node_modules', 'package-a', 'temp.txt'))).toBe(true); + const add = new Add(['left-pad@1.1.0'], {}, config, reporter, (await Lockfile.fromDirectory(config.cwd))); + await add.init(); + expect(await fs.exists(path.join(config.cwd, 'node_modules', 'package-a', 'temp.txt'))).toBe(true); + }); +}); diff --git a/__tests__/fixtures/add/integrity-pure-lockfile/package-a/package.json b/__tests__/fixtures/add/integrity-pure-lockfile/package-a/package.json new file mode 100644 index 0000000000..412a9bff20 --- /dev/null +++ b/__tests__/fixtures/add/integrity-pure-lockfile/package-a/package.json @@ -0,0 +1,7 @@ +{ + "name": "package-a", + "version": "1.0.0", + "scripts": { + "install": "node script.js" + } +} diff --git a/__tests__/fixtures/add/integrity-pure-lockfile/package-a/script.js b/__tests__/fixtures/add/integrity-pure-lockfile/package-a/script.js new file mode 100644 index 0000000000..95c23b47ae --- /dev/null +++ b/__tests__/fixtures/add/integrity-pure-lockfile/package-a/script.js @@ -0,0 +1,3 @@ +var fs = require('fs'); + +fs.writeFileSync('temp.txt', 'TEST'); diff --git a/__tests__/fixtures/add/integrity-pure-lockfile/package.json b/__tests__/fixtures/add/integrity-pure-lockfile/package.json new file mode 100644 index 0000000000..75f23ea074 --- /dev/null +++ b/__tests__/fixtures/add/integrity-pure-lockfile/package.json @@ -0,0 +1,6 @@ +{ + "private": true, + "dependencies": { + "package-a": "file:./package-a" + } +} diff --git a/__tests__/fixtures/add/integrity-pure-lockfile/yarn.lock b/__tests__/fixtures/add/integrity-pure-lockfile/yarn.lock new file mode 100644 index 0000000000..faf2895ca6 --- /dev/null +++ b/__tests__/fixtures/add/integrity-pure-lockfile/yarn.lock @@ -0,0 +1,6 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + +"package-a@file:./package-a": + version "1.0.0" diff --git a/src/cli/commands/install.js b/src/cli/commands/install.js index 0a3b2b0604..e4b821ab47 100644 --- a/src/cli/commands/install.js +++ b/src/cli/commands/install.js @@ -637,11 +637,6 @@ export class Install { */ async saveLockfileAndIntegrity(patterns: Array, workspaceLayout: ?WorkspaceLayout): Promise { - // --no-lockfile or --pure-lockfile flag - if (this.flags.lockfile === false || this.flags.pureLockfile) { - return; - } - const resolvedPatterns: {[packagePattern: string]: Manifest} = {}; Object.keys(this.resolver.patterns).forEach(pattern => { if (!workspaceLayout || !workspaceLayout.getManifestByPattern(pattern)) { @@ -667,6 +662,11 @@ export class Install { this.scripts.getArtifacts(), ); + // --no-lockfile or --pure-lockfile flag + if (this.flags.lockfile === false || this.flags.pureLockfile) { + return; + } + const lockFileHasAllPatterns = patterns.every(p => this.lockfile.getLocked(p)); const resolverPatternsAreSameAsInLockfile = Object.keys(lockfileBasedOnResolver).every(pattern => { const manifest = this.lockfile.getLocked(pattern); diff --git a/yarn.lock b/yarn.lock index 8b19dac747..5a6cddb59b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2712,14 +2712,10 @@ istanbul-api@^1.1.0-alpha.1: mkdirp "^0.5.1" once "^1.4.0" -istanbul-lib-coverage@^1.0.0, istanbul-lib-coverage@^1.1.1: +istanbul-lib-coverage@^1.0.0, istanbul-lib-coverage@^1.1.0, istanbul-lib-coverage@^1.1.1: version "1.1.1" resolved "https://registry.yarnpkg.com/istanbul-lib-coverage/-/istanbul-lib-coverage-1.1.1.tgz#73bfb998885299415c93d38a3e9adf784a77a9da" -istanbul-lib-coverage@^1.1.0: - version "1.1.0" - resolved "https://registry.yarnpkg.com/istanbul-lib-coverage/-/istanbul-lib-coverage-1.1.0.tgz#caca19decaef3525b5d6331d701f3f3b7ad48528" - istanbul-lib-hook@^1.0.7: version "1.0.7" resolved "https://registry.yarnpkg.com/istanbul-lib-hook/-/istanbul-lib-hook-1.0.7.tgz#dd6607f03076578fe7d6f2a630cf143b49bacddc"