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

Support save-exact true #4471

Merged
merged 2 commits into from
Sep 17, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions __tests__/commands/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,17 @@ test.concurrent('add save-prefix should not expand ~ to home dir', (): Promise<v
});
});

test.concurrent('add save-exact should make all package.json strict', (): Promise<void> => {
return runAdd(['left-pad'], {}, 'install-strict-all', async config => {
const lockfile = explodeLockfile(await fs.readFile(path.join(config.cwd, 'yarn.lock')));

expect(lockfile[0]).toMatch(/^left-pad@\d+\.\d+\.\d+:$/);
expect(JSON.parse(await fs.readFile(path.join(config.cwd, 'package.json'))).dependencies['left-pad']).toMatch(
/^\d+\.\d+\.\d+$/,
);
});
});

test.concurrent('add with new dependency should be deterministic 3', (): Promise<void> => {
return runAdd([], {}, 'install-should-cleanup-when-package-json-changed-3', async (config, reporter) => {
// expecting yarn check after installation not to fail
Expand Down
2 changes: 2 additions & 0 deletions __tests__/fixtures/add/install-strict-all/.yarnrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
yarn-offline-mirror "./mirror-for-offline"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Offline mirror is for not using the internet to install packages during test AFAIK.

save-exact true
6 changes: 4 additions & 2 deletions src/cli/commands/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ export class Add extends Install {
* returns version for a pattern based on Manifest
*/
getPatternVersion(pattern: string, pkg: Manifest): string {
const {exact, tilde} = this.flags;
const tilde = this.flags.tilde;
const configPrefix = String(this.config.getOption('save-prefix'));
const exact = this.flags.exact || Boolean(this.config.getOption('save-exact')) || configPrefix === '';
const {hasVersion, range} = normalizePattern(pattern);
let version;

Expand All @@ -86,7 +88,7 @@ export class Add extends Install {
} else if (exact) {
prefix = '';
} else {
prefix = String(this.config.getOption('save-prefix')) || '^';
prefix = configPrefix || '^';
}

version = `${prefix}${pkg.version}`;
Expand Down