Skip to content

Commit

Permalink
Issue yarnpkg#570 Make install pure by default
Browse files Browse the repository at this point in the history
  • Loading branch information
eliihen committed Oct 20, 2016
1 parent b17082d commit 8afe385
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 17 deletions.
21 changes: 12 additions & 9 deletions __tests__/commands/install.js
Expand Up @@ -49,14 +49,18 @@ test.concurrent('flat arg is inherited from root manifest', async (): Promise<vo


test.concurrent("doesn't write new lockfile if existing one satisfied", (): Promise<void> => {
return runInstall({}, 'install-dont-write-lockfile-if-satisfied', async (config): Promise<void> => {
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<void> => {
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<void> => {
await runInstall({}, 'install-write-lockfile-if-not-satisfied', async (config): Promise<void> => {
await runInstall({writeLockfile: true}, 'install-write-lockfile-if-not-satisfied', async (config): Promise<void> => {
const lockfile = await fs.readFile(path.join(config.cwd, 'yarn.lock'));
assert(lockfile.indexOf('foobar') === -1);
});
Expand Down Expand Up @@ -393,7 +397,7 @@ test.concurrent(
(): Promise<void> => {
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',
Expand Down Expand Up @@ -557,9 +561,9 @@ test.concurrent('install should resolve circular dependencies 2', (): Promise<vo
});

test.concurrent(
'install should add missing deps to yarn and mirror (PR import scenario)',
'install should add missing deps to yarn and mirror when given --write-lockfile (PR import scenario)',
(): Promise<void> => {
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');
Expand All @@ -579,7 +583,6 @@ test.concurrent(
},
);


xit('install should update a dependency to yarn and mirror (PR import scenario 2)', (): Promise<void> => {
// 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,
Expand Down
1 change: 1 addition & 0 deletions src/cli/commands/add.js
Expand Up @@ -23,6 +23,7 @@ export class Add extends Install {
) {
super(flags, config, reporter, lockfile);
this.args = args;
this.flags.writeLockfile = true;
}

args: Array<string>;
Expand Down
18 changes: 11 additions & 7 deletions src/cli/commands/install.js
Expand Up @@ -59,7 +59,7 @@ type Flags = {
flat: boolean,
production: boolean,
lockfile: boolean,
pureLockfile: boolean,
writeLockfile: boolean,
skipIntegrity: boolean,

// add
Expand All @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/cli/commands/remove.js
Expand Up @@ -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();

//
Expand Down

0 comments on commit 8afe385

Please sign in to comment.