Skip to content

Commit

Permalink
Enabled skip-integrity-check flag for install command (#2765)
Browse files Browse the repository at this point in the history
* Enabled skip-integrity-check flag for install command

Sometimes you need to run full install even if integrity check returns OK.

* added test to --skip-integrity-checl
  • Loading branch information
bestander authored Feb 23, 2017
1 parent b7ba346 commit bd8e326
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 7 deletions.
44 changes: 44 additions & 0 deletions __tests__/commands/install/integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -868,3 +868,47 @@ test.concurrent('a allows dependency with [] in os cpu requirements',
assert(await fs.exists(path.join(config.cwd, 'node_modules', 'feed')));
});
});

test.concurrent('should skip integrity check and do install when --skip-integrity-check flag is passed',
(): Promise<void> => {
return runInstall({}, 'skip-integrity-check', async (config, reporter) => {
assert.equal(await fs.exists(path.join(config.cwd, 'node_modules', 'sub-dep')), true);
await fs.unlink(path.join(config.cwd, 'node_modules', 'sub-dep'));

let lockContent = await fs.readFile(
path.join(config.cwd, 'yarn.lock'),
);
lockContent += `
# changed the file, integrity should be fine
`;
await fs.writeFile(
path.join(config.cwd, 'yarn.lock'),
lockContent,
);

let reinstall = new Install({}, config, reporter, await Lockfile.fromDirectory(config.cwd));
await reinstall.init();

// reinstall will be successful but it won't reinstall anything
assert.equal(await fs.exists(path.join(config.cwd, 'node_modules', 'sub-dep')), false);

reinstall = new Install({skipIntegrityCheck: true}, config, reporter, await Lockfile.fromDirectory(config.cwd));
await reinstall.init();
// reinstall will reinstall deps
assert.equal(await fs.exists(path.join(config.cwd, 'node_modules', 'sub-dep')), true);

let newLockContent = await fs.readFile(
path.join(config.cwd, 'yarn.lock'),
);
assert.equal(lockContent, newLockContent);

reinstall = new Install({force: true}, config, reporter, await Lockfile.fromDirectory(config.cwd));
await reinstall.init();
// force rewrites lockfile
newLockContent = await fs.readFile(
path.join(config.cwd, 'yarn.lock'),
);
assert.notEqual(lockContent, newLockContent);

});
});
5 changes: 5 additions & 0 deletions __tests__/fixtures/install/skip-integrity-check/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"dependencies": {
"sub-dep": "file:sub-dep"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
process.exit(0);
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "sub-dep",
"version": "1.0.0"
}
15 changes: 9 additions & 6 deletions src/cli/commands/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ type Flags = {
flat: boolean,
lockfile: boolean,
pureLockfile: boolean,
skipIntegrity: boolean,
skipIntegrityCheck: boolean,

// add
peer: boolean,
Expand Down Expand Up @@ -127,7 +127,7 @@ function normalizeFlags(config: Config, rawFlags: Object): Flags {
flat: !!rawFlags.flat,
lockfile: rawFlags.lockfile !== false,
pureLockfile: !!rawFlags.pureLockfile,
skipIntegrity: !!rawFlags.skipIntegrity,
skipIntegrityCheck: !!rawFlags.skipIntegrityCheck,
frozenLockfile: !!rawFlags.frozenLockfile,
linkDuplicates: !!rawFlags.linkDuplicates,

Expand Down Expand Up @@ -301,14 +301,17 @@ export class Install {
async bailout(
patterns: Array<string>,
): Promise<boolean> {
const match = await this.matchesIntegrityHash(patterns);
const haveLockfile = await fs.exists(path.join(this.config.cwd, constants.LOCKFILE_FILENAME));

if (this.flags.frozenLockfile && !this.lockFileInSync(patterns)) {
throw new MessageError(this.reporter.lang('frozenLockfileError'));
}
if (this.flags.skipIntegrityCheck || this.flags.force) {
return false;
}

const match = await this.matchesIntegrityHash(patterns);
const haveLockfile = await fs.exists(path.join(this.config.cwd, constants.LOCKFILE_FILENAME));

if (!this.flags.skipIntegrity && !this.flags.force && match.matches && haveLockfile) {
if (match.matches && haveLockfile) {
this.reporter.success(this.reporter.lang('upToDate'));
return true;
}
Expand Down
3 changes: 2 additions & 1 deletion src/cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ commander.option('--har', 'save HAR output of network traffic');
commander.option('--ignore-platform', 'ignore platform checks');
commander.option('--ignore-engines', 'ignore engines check');
commander.option('--ignore-optional', 'ignore optional dependencies');
commander.option('--force', 'ignore all caches');
commander.option('--force', 'install and build scripts even if they were built before, overwrite lockfile');
commander.option('--skip-integrity-check', 'run install without checking if node_modules is installed');
commander.option('--no-bin-links', "don't generate bin links when setting up packages");
commander.option('--flat', 'only allow one version of a package');
commander.option('--prod, --production [prod]', '');
Expand Down

0 comments on commit bd8e326

Please sign in to comment.