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

Conversation

ahmedelgabri
Copy link
Contributor

@ahmedelgabri ahmedelgabri commented Sep 15, 2017

Summary

Fixes #4343. Currently there is no way to remove the package prefix inside .yarnrc file, this PR add support for save-exact in .yarnrc as discussed in #4343. Full credit goes to @jambonrose

save-exact true

One small thing, should yarn be backwards compatible with the old behavior which is save-prefix ''? We can just add an extra check here for do this. What do you think @BYK?

} else if (exact || Boolean(this.config.getOption('save-exact')) || Boolean(this.config.getOption('save-prefix'))) {

Test plan

New unit test.

@StefanoMagrassi
Copy link

This should be so obvious: if I set save-exact to true the prefix must be automatically set to an empty string (otherwise there is some kind of inconsistency).

The yarn parser should also allow to set save-prefix key to an empty string. Now it throwns an error ("Invalid value type in .yarnrc").

@BYK
Copy link
Member

BYK commented Sep 15, 2017

This should be so obvious: if I set save-exact to true the prefix must be automatically set to an empty string (otherwise there is some kind of inconsistency).

Agreed.

The yarn parser should also allow to set save-prefix key to an empty string. Now it throwns an error ("Invalid value type in .yarnrc").

This is not true. You can set it to an empty string.

@BYK
Copy link
Member

BYK commented Sep 15, 2017

One small thing, should yarn be backwards compatible with the old behavior which is save-prefix ''? We can just add an extra check here for do this. What do you think @BYK?

It should definitely be backwards compatible, otherwise this change would require a major version upgrade.

Copy link
Member

@BYK BYK left a comment

Choose a reason for hiding this comment

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

Thanks for the PR!

Tests are passing.

This is not enough :) You also need to add a new test(s) to test the new behavior.

@@ -83,7 +83,7 @@ export class Add extends Install {
let prefix;
if (tilde) {
prefix = '~';
} else if (exact) {
} else if (exact || Boolean(this.config.getOption('save-exact'))) {
Copy link
Member

Choose a reason for hiding this comment

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

I think it is better to do

const exact = this.flags.exact || Boolean(this.config.getOption('save-exact'));
const tilde = this.flags.tilde;

above. save-exact should take precedence over save-prefix option.

@StefanoMagrassi
Copy link

This is not true. You can set it to an empty string.

Really? My colleague got that error when tried to set save-prefix to an empty string (yarn version 1.0.2).

Maybe it was his fault or caused by some kind of other wrong configuration... In this case 👍

@ahmedelgabri
Copy link
Contributor Author

ahmedelgabri commented Sep 15, 2017

This is not enough :) You also need to add a new test(s) to test the new behavior.

@BYK True :) I might need some pointers on how to test the .yarnrc, a quick look at https://github.com/yarnpkg/yarn/blob/master/__tests__/commands/add.js & I can't seem to find anything related to testing .yarnrc, I might be wrong.

@ahmedelgabri ahmedelgabri force-pushed the add-save-exact-option branch 5 times, most recently from 9b3e035 to e0f3cab Compare September 15, 2017 18:23
@ahmedelgabri
Copy link
Contributor Author

I added a test & changed the logic to be backward compatible.

const exact =
      this.flags.exact ||
      Boolean(this.config.getOption('save-exact')) ||
      String(this.config.getOption('save-prefix')) === ''; 

The save-prefix check can't be Boolean(this.config.getOption('save-prefix')) becasue it will always return true for non-empty strings.

Copy link
Member

@BYK BYK left a comment

Choose a reason for hiding this comment

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

Nice, thanks a lot! Also, sorry for the late response. The patch looks good but tests need some small improvements and using a variable for the config value would be great.

After those, I don't see any reason to not merge this.

@@ -0,0 +1 @@
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.

Why a separate file? Let's move this into .yarnrc below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Honestly, I just copied install-no-strict-all and just added .yarnrc :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe actually this is not needed at all?

@@ -0,0 +1,5 @@
{
"dependencies": {
"mime-types": "^2.0.0"
Copy link
Member

Choose a reason for hiding this comment

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

I don't think you need this at all since you already do yarn add left-pad in the test

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I can remove package.json & mirror-for-offline folder too then?

const exact =
this.flags.exact ||
Boolean(this.config.getOption('save-exact')) ||
String(this.config.getOption('save-prefix')) === '';
Copy link
Member

Choose a reason for hiding this comment

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

Assigning this to a variable like configPrefix might be good since it is now used here and also below.

@buildsize
Copy link

buildsize bot commented Sep 16, 2017

This change will decrease the build size from 9.69 MB to 9.69 MB, a decrease of 1.75 KB (0%)

File name Previous Size New Size Change
yarn-[version].noarch.rpm 834.67 KB 834.47 KB -203 bytes (0%)
yarn-[version].js 3.69 MB 3.69 MB -552 bytes (0%)
yarn-legacy-[version].js 3.74 MB 3.74 MB -680 bytes (0%)
yarn-v[version].tar.gz 838.74 KB 838.55 KB -201 bytes (0%)
yarn_[version]all.deb 634.81 KB 634.66 KB -160 bytes (0%)

1 similar comment
@buildsize
Copy link

buildsize bot commented Sep 16, 2017

This change will decrease the build size from 9.69 MB to 9.69 MB, a decrease of 1.75 KB (0%)

File name Previous Size New Size Change
yarn-[version].noarch.rpm 834.67 KB 834.47 KB -203 bytes (0%)
yarn-[version].js 3.69 MB 3.69 MB -552 bytes (0%)
yarn-legacy-[version].js 3.74 MB 3.74 MB -680 bytes (0%)
yarn-v[version].tar.gz 838.74 KB 838.55 KB -201 bytes (0%)
yarn_[version]all.deb 634.81 KB 634.66 KB -160 bytes (0%)

@ahmedelgabri
Copy link
Contributor Author

@BYK can you have a look at travis, I think it's failing because of disk/memory issues or something.

all the errors are like this

Error: ENOSPC: no space left on device, mkdir <some path>

@@ -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.

@BYK
Copy link
Member

BYK commented Sep 17, 2017

@BYK can you have a look at travis, I think it's failing because of disk/memory issues or something.

This is probably due to the RAMDISK on OS X builds. If it fails again, I'll edit your patch and increase the size.

@BYK BYK merged commit 0e16ee9 into yarnpkg:master Sep 17, 2017
@BYK
Copy link
Member

BYK commented Sep 17, 2017

Merged! Thanks a lot for helping us with this ❤️

@ahmedelgabri
Copy link
Contributor Author

Thanks @BYK 😊

joaolucasl pushed a commit to joaolucasl/yarn that referenced this pull request Oct 27, 2017
**Summary**

Fixes yarnpkg#4343. Currently there is no way to remove the package prefix inside `.yarnrc` file, this PR add support for `save-exact` in `.yarnrc` as discussed in yarnpkg#4343. Full credit goes to @jambonrose

```
save-exact true
```

One small thing, should `yarn` be backwards compatible with the old behavior which is `save-prefix ''`? We can just add an extra check here for do this. What do you think @BYK?


```js
} else if (exact || Boolean(this.config.getOption('save-exact')) || Boolean(this.config.getOption('save-prefix'))) {

```

**Test plan**

New unit test.
chabou added a commit to chabou/hyper that referenced this pull request Nov 5, 2017
chabou added a commit to chabou/hyper-pane that referenced this pull request Nov 5, 2017
timothyis pushed a commit to vercel/hyper that referenced this pull request Nov 5, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Yarn save-prefix option changed/ignored
3 participants