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

Make install pure by default #1313

Closed
wants to merge 1 commit into from
Closed
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
21 changes: 12 additions & 9 deletions __tests__/commands/install.js
Original file line number Diff line number Diff line change
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> => {
// [email protected] is saved in local mirror and gets updated to [email protected] via
// a change in package.json,
Expand Down
2 changes: 1 addition & 1 deletion scripts/check-lockfile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ cp -r scripts $DIR/scripts
cd $DIR

# install with yarn and run check
../bin/yarn.js install --pure-lockfile
../bin/yarn.js install
../bin/yarn.js check

# cleanup
Expand Down
1 change: 1 addition & 0 deletions src/cli/commands/add.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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