Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enabled skip-integrity-check flag for install command #2765

Merged
merged 2 commits into from
Feb 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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