From e23191441c6b361e961a9a20782f4bc7ebcacef4 Mon Sep 17 00:00:00 2001 From: jamsinclair Date: Wed, 16 Aug 2017 01:09:02 +1200 Subject: [PATCH 1/7] Add method to update force property --- src/package-install-scripts.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/package-install-scripts.js b/src/package-install-scripts.js index 948e920783..7b98d841be 100644 --- a/src/package-install-scripts.js +++ b/src/package-install-scripts.js @@ -34,6 +34,10 @@ export default class PackageInstallScripts { force: boolean; artifacts: InstallArtifacts; + setForce(force: boolean) { + this.force = force; + } + setArtifacts(artifacts: InstallArtifacts) { this.artifacts = artifacts; } From 6692e5e650d83d338217a028b585669691e8c0fe Mon Sep 17 00:00:00 2001 From: jamsinclair Date: Wed, 16 Aug 2017 01:13:55 +1200 Subject: [PATCH 2/7] Update install to force script installs when integrity file missing --- src/cli/commands/install.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/cli/commands/install.js b/src/cli/commands/install.js index 53dc1cd935..4558cfae70 100644 --- a/src/cli/commands/install.js +++ b/src/cli/commands/install.js @@ -359,6 +359,12 @@ export class Install { return true; } + if (match.integrityFileMissing && haveLockfile) { + // Integrity file missing, force script installations + this.scripts.setForce(true); + return false; + } + if (!patterns.length && !match.integrityFileMissing) { this.reporter.success(this.reporter.lang('nothingToInstall')); await this.createEmptyManifestFolders(); From 52bed25547340c713f79d1876f400366d0774b15 Mon Sep 17 00:00:00 2001 From: jamsinclair Date: Wed, 16 Aug 2017 01:15:17 +1200 Subject: [PATCH 3/7] Update add to force script installs when integrity file missing --- src/cli/commands/add.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/cli/commands/add.js b/src/cli/commands/add.js index 3e9b1bb49b..0e7dfd6ebe 100644 --- a/src/cli/commands/add.js +++ b/src/cli/commands/add.js @@ -7,12 +7,16 @@ import type Config from '../../config.js'; import type {ListOptions} from './list.js'; import Lockfile from '../../lockfile/wrapper.js'; import PackageRequest from '../../package-request.js'; +import WorkspaceLayout from '../../workspace-layout.js'; import {getExoticResolver} from '../../resolvers/index.js'; import {buildTree} from './list.js'; import {wrapLifecycle, Install} from './install.js'; import {MessageError} from '../../errors.js'; +import * as constants from '../../constants.js'; +import * as fs from '../../util/fs.js'; import invariant from 'invariant'; +import path from 'path'; import semver from 'semver'; export class Add extends Install { @@ -97,8 +101,18 @@ export class Add extends Install { return preparedPatterns; } - bailout(patterns: Array): Promise { - return Promise.resolve(false); + async bailout(patterns: Array, workspaceLayout: ?WorkspaceLayout): Promise { + const lockfileCache = this.lockfile.cache; + if (!lockfileCache) { + return false; + } + const match = await this.integrityChecker.check(patterns, lockfileCache, this.flags, workspaceLayout); + const haveLockfile = await fs.exists(path.join(this.config.lockfileFolder, constants.LOCKFILE_FILENAME)); + if (match.integrityFileMissing && haveLockfile) { + // Integrity file missing, force script installations + this.scripts.setForce(true); + } + return false; } /** From aca24f2f34f0ef1ff174d86c757625105a236042 Mon Sep 17 00:00:00 2001 From: jamsinclair Date: Wed, 16 Aug 2017 23:51:54 +1200 Subject: [PATCH 4/7] Add test case for retaining artifacts after add when missing integrity --- __tests__/commands/add.js | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/__tests__/commands/add.js b/__tests__/commands/add.js index 212f72efab..47b7a3e2e2 100644 --- a/__tests__/commands/add.js +++ b/__tests__/commands/add.js @@ -836,6 +836,37 @@ test.concurrent('should only refer to root to satisfy peer dependency', (): Prom ); }); +test.concurrent('should retain build artifacts after add when missing integrity file', (): Promise => { + return buildRun( + reporters.BufferReporter, + fixturesLoc, + async (args, flags, config, reporter): Promise => { + const lockfile = await createLockfile(config.cwd); + + const addA = new Add(args, flags, config, reporter, lockfile); + await addA.init(); + + const expectedArtifacts = ['foo.txt']; + const integrityLoc = path.join(config.cwd, 'node_modules', constants.INTEGRITY_FILENAME); + + const beforeIntegrity = await fs.readJson(integrityLoc); + expect(beforeIntegrity.artifacts['a@0.0.0']).toEqual(expectedArtifacts); + + await fs.unlink(integrityLoc); + + const lockfileAfterPreviousAdd = await Lockfile.fromDirectory(config.cwd); + const addB = new Add(['file:b'], flags, config, reporter, lockfileAfterPreviousAdd); + await addB.init(); + + const afterIntegrity = await fs.readJson(integrityLoc); + expect(afterIntegrity.artifacts['a@0.0.0']).toEqual(expectedArtifacts); + }, + ['file:a'], + {}, + 'retain-build-artifacts-missing-integrity', + ); +}); + test.concurrent('should retain build artifacts after add', (): Promise => { return buildRun( reporters.BufferReporter, From e87d463d23c5a863240d58505c53796f759c0624 Mon Sep 17 00:00:00 2001 From: jamsinclair Date: Wed, 16 Aug 2017 23:52:11 +1200 Subject: [PATCH 5/7] Add test case for retaining artifacts after install when missing integrity --- __tests__/commands/install/lockfiles.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/__tests__/commands/install/lockfiles.js b/__tests__/commands/install/lockfiles.js index 7302560cce..427bc427e3 100644 --- a/__tests__/commands/install/lockfiles.js +++ b/__tests__/commands/install/lockfiles.js @@ -195,6 +195,24 @@ test.concurrent('install should write and read integrity file based on lockfile }); }); +test.concurrent('install should retain artifacts when missing integrity file', (): Promise => { + return runInstall({}, 'install-should-retain-artifacts-when-missing-integrity', async (config, reporter) => { + const expectedArtifacts = ['foo.txt']; + const integrityLoc = path.join(config.cwd, 'node_modules', constants.INTEGRITY_FILENAME); + + const beforeIntegrity = await fs.readJson(integrityLoc); + expect(beforeIntegrity.artifacts['a@0.0.0']).toEqual(expectedArtifacts); + + await fs.unlink(integrityLoc); + + let reinstall = new Install({}, config, reporter, await Lockfile.fromDirectory(config.cwd)); + await reinstall.init(); + + const afterIntegrity = await fs.readJson(integrityLoc); + expect(afterIntegrity.artifacts['a@0.0.0']).toEqual(expectedArtifacts); + }); +}); + test.concurrent('install should not continue if integrity check passes', (): Promise => { return runInstall({}, 'lockfile-stability', async (config, reporter) => { await fs.writeFile(path.join(config.cwd, 'node_modules', 'yarn.test'), 'YARN TEST'); From 06421f7ff3ae05dd282cb3191c264fca63548a3e Mon Sep 17 00:00:00 2001 From: jamsinclair Date: Wed, 16 Aug 2017 23:52:43 +1200 Subject: [PATCH 6/7] Add test fixture data for missing integrity tests --- .../retain-build-artifacts-missing-integrity/a/install.js | 1 + .../a/package.json | 7 +++++++ .../b/package.json | 4 ++++ .../retain-build-artifacts-missing-integrity/package.json | 1 + .../a/install.js | 1 + .../a/package.json | 7 +++++++ .../package.json | 5 +++++ .../yarn.lock | 6 ++++++ 8 files changed, 32 insertions(+) create mode 100644 __tests__/fixtures/add/retain-build-artifacts-missing-integrity/a/install.js create mode 100644 __tests__/fixtures/add/retain-build-artifacts-missing-integrity/a/package.json create mode 100644 __tests__/fixtures/add/retain-build-artifacts-missing-integrity/b/package.json create mode 100644 __tests__/fixtures/add/retain-build-artifacts-missing-integrity/package.json create mode 100644 __tests__/fixtures/install/install-should-retain-artifacts-when-missing-integrity/a/install.js create mode 100644 __tests__/fixtures/install/install-should-retain-artifacts-when-missing-integrity/a/package.json create mode 100644 __tests__/fixtures/install/install-should-retain-artifacts-when-missing-integrity/package.json create mode 100644 __tests__/fixtures/install/install-should-retain-artifacts-when-missing-integrity/yarn.lock diff --git a/__tests__/fixtures/add/retain-build-artifacts-missing-integrity/a/install.js b/__tests__/fixtures/add/retain-build-artifacts-missing-integrity/a/install.js new file mode 100644 index 0000000000..899265a0eb --- /dev/null +++ b/__tests__/fixtures/add/retain-build-artifacts-missing-integrity/a/install.js @@ -0,0 +1 @@ +require('fs').writeFileSync('foo.txt', 'foobar'); diff --git a/__tests__/fixtures/add/retain-build-artifacts-missing-integrity/a/package.json b/__tests__/fixtures/add/retain-build-artifacts-missing-integrity/a/package.json new file mode 100644 index 0000000000..fcfc10796f --- /dev/null +++ b/__tests__/fixtures/add/retain-build-artifacts-missing-integrity/a/package.json @@ -0,0 +1,7 @@ +{ + "name": "a", + "version": "0.0.0", + "scripts": { + "postinstall": "node install.js" + } +} diff --git a/__tests__/fixtures/add/retain-build-artifacts-missing-integrity/b/package.json b/__tests__/fixtures/add/retain-build-artifacts-missing-integrity/b/package.json new file mode 100644 index 0000000000..1d02201279 --- /dev/null +++ b/__tests__/fixtures/add/retain-build-artifacts-missing-integrity/b/package.json @@ -0,0 +1,4 @@ +{ + "name": "b", + "version": "0.0.0" +} diff --git a/__tests__/fixtures/add/retain-build-artifacts-missing-integrity/package.json b/__tests__/fixtures/add/retain-build-artifacts-missing-integrity/package.json new file mode 100644 index 0000000000..0967ef424b --- /dev/null +++ b/__tests__/fixtures/add/retain-build-artifacts-missing-integrity/package.json @@ -0,0 +1 @@ +{} diff --git a/__tests__/fixtures/install/install-should-retain-artifacts-when-missing-integrity/a/install.js b/__tests__/fixtures/install/install-should-retain-artifacts-when-missing-integrity/a/install.js new file mode 100644 index 0000000000..899265a0eb --- /dev/null +++ b/__tests__/fixtures/install/install-should-retain-artifacts-when-missing-integrity/a/install.js @@ -0,0 +1 @@ +require('fs').writeFileSync('foo.txt', 'foobar'); diff --git a/__tests__/fixtures/install/install-should-retain-artifacts-when-missing-integrity/a/package.json b/__tests__/fixtures/install/install-should-retain-artifacts-when-missing-integrity/a/package.json new file mode 100644 index 0000000000..fcfc10796f --- /dev/null +++ b/__tests__/fixtures/install/install-should-retain-artifacts-when-missing-integrity/a/package.json @@ -0,0 +1,7 @@ +{ + "name": "a", + "version": "0.0.0", + "scripts": { + "postinstall": "node install.js" + } +} diff --git a/__tests__/fixtures/install/install-should-retain-artifacts-when-missing-integrity/package.json b/__tests__/fixtures/install/install-should-retain-artifacts-when-missing-integrity/package.json new file mode 100644 index 0000000000..4e3bb4400b --- /dev/null +++ b/__tests__/fixtures/install/install-should-retain-artifacts-when-missing-integrity/package.json @@ -0,0 +1,5 @@ +{ + "dependencies": { + "a": "file:a" + } +} diff --git a/__tests__/fixtures/install/install-should-retain-artifacts-when-missing-integrity/yarn.lock b/__tests__/fixtures/install/install-should-retain-artifacts-when-missing-integrity/yarn.lock new file mode 100644 index 0000000000..1bba7514a3 --- /dev/null +++ b/__tests__/fixtures/install/install-should-retain-artifacts-when-missing-integrity/yarn.lock @@ -0,0 +1,6 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + +"a@file:a": + version "0.0.0" From 41d28a9098a56ce65d6f2991049f032c48fa0566 Mon Sep 17 00:00:00 2001 From: jamsinclair Date: Wed, 16 Aug 2017 23:57:53 +1200 Subject: [PATCH 7/7] Fix lint errors --- __tests__/commands/install/lockfiles.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/__tests__/commands/install/lockfiles.js b/__tests__/commands/install/lockfiles.js index 427bc427e3..80ac964196 100644 --- a/__tests__/commands/install/lockfiles.js +++ b/__tests__/commands/install/lockfiles.js @@ -197,19 +197,19 @@ test.concurrent('install should write and read integrity file based on lockfile test.concurrent('install should retain artifacts when missing integrity file', (): Promise => { return runInstall({}, 'install-should-retain-artifacts-when-missing-integrity', async (config, reporter) => { - const expectedArtifacts = ['foo.txt']; - const integrityLoc = path.join(config.cwd, 'node_modules', constants.INTEGRITY_FILENAME); + const expectedArtifacts = ['foo.txt']; + const integrityLoc = path.join(config.cwd, 'node_modules', constants.INTEGRITY_FILENAME); - const beforeIntegrity = await fs.readJson(integrityLoc); - expect(beforeIntegrity.artifacts['a@0.0.0']).toEqual(expectedArtifacts); + const beforeIntegrity = await fs.readJson(integrityLoc); + expect(beforeIntegrity.artifacts['a@0.0.0']).toEqual(expectedArtifacts); - await fs.unlink(integrityLoc); + await fs.unlink(integrityLoc); - let reinstall = new Install({}, config, reporter, await Lockfile.fromDirectory(config.cwd)); - await reinstall.init(); + const reinstall = new Install({}, config, reporter, await Lockfile.fromDirectory(config.cwd)); + await reinstall.init(); - const afterIntegrity = await fs.readJson(integrityLoc); - expect(afterIntegrity.artifacts['a@0.0.0']).toEqual(expectedArtifacts); + const afterIntegrity = await fs.readJson(integrityLoc); + expect(afterIntegrity.artifacts['a@0.0.0']).toEqual(expectedArtifacts); }); });