Skip to content

Commit

Permalink
Do not save lockfile when no dependencies (#3395)
Browse files Browse the repository at this point in the history
  • Loading branch information
g-plane authored and bestander committed Jul 1, 2017
1 parent 4d5dcc6 commit e0e119e
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 8 deletions.
8 changes: 3 additions & 5 deletions __tests__/commands/install/lockfiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,13 @@ test.concurrent("writes new lockfile if existing one isn't satisfied", async ():
});
});

test.concurrent('writes a lockfile even when there are no dependencies', (): Promise<void> => {
// https://github.com/yarnpkg/yarn/issues/679
test.concurrent("doesn't write a lockfile when there are no dependencies", (): Promise<void> => {
return runInstall({}, 'install-without-dependencies', async config => {
const lockfileExists = await fs.exists(path.join(config.cwd, 'yarn.lock'));
const installedDepFiles = await fs.walk(path.join(config.cwd, 'node_modules'));

expect(lockfileExists).toEqual(true);
// 1 for integrity file (located in node_modules)
expect(installedDepFiles).toHaveLength(1);
expect(lockfileExists).toEqual(false);
expect(installedDepFiles).toHaveLength(0);
});
});

Expand Down
2 changes: 1 addition & 1 deletion __tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ test.concurrent('should install if no args', async () => {

test.concurrent('should install if first arg looks like a flag', async () => {
const stdout = await execCommand('--json', [], 'run-add', true);
expect(stdout[stdout.length - 1]).toEqual('{"type":"success","data":"Saved lockfile."}');
expect(stdout[stdout.length - 1]).toEqual('{"type":"info","data":"Lockfile not saved, no dependencies."}');
});

test.concurrent('should not output JSON activity/progress if given --no-progress option', async () => {
Expand Down
7 changes: 6 additions & 1 deletion src/cli/commands/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,12 @@ export class Install {
}

// fin!
await this.saveLockfileAndIntegrity(topLevelPatterns, workspaceLayout);
// The second condition is to make sure lockfile can be updated when running `remove` command.
if (topLevelPatterns.length || (await fs.exists(path.join(this.config.cwd, constants.LOCKFILE_FILENAME)))) {
await this.saveLockfileAndIntegrity(topLevelPatterns, workspaceLayout);
} else {
this.reporter.info(this.reporter.lang('notSavedLockfileNoDependencies'));
}
this.maybeOutputUpdate();
this.config.requestManager.clearCache();
return flattenedTopLevelPatterns;
Expand Down
2 changes: 1 addition & 1 deletion src/cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const args = process.argv.slice(2, doubleDashIndex === -1 ? process.argv.length
const endArgs = doubleDashIndex === -1 ? [] : process.argv.slice(doubleDashIndex + 1, process.argv.length);

// set global options
commander.version(version);
commander.version(version, '--version');
commander.usage('[command] [flags]');
commander.option('--verbose', 'output verbose messages on internal operations');
commander.option('--offline', 'trigger an error if any required dependencies are not available in local cache');
Expand Down
2 changes: 2 additions & 0 deletions src/reporters/lang/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ const messages = {
foundWarnings: 'Found $0 warnings.',
foundErrors: 'Found $0 errors.',

notSavedLockfileNoDependencies: 'Lockfile not saved, no dependencies.',

savedLockfile: 'Saved lockfile.',
noRequiredLockfile: 'No lockfile in this directory. Run `yarn install` to generate one.',
noLockfileFound: 'No lockfile found.',
Expand Down

0 comments on commit e0e119e

Please sign in to comment.