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

Fix yarn pack to always include the file in the "main" field #3092

Merged
merged 2 commits into from
Apr 21, 2017

Conversation

josephfrazier
Copy link
Contributor

Summary

This is for compatibility with npm, which specifies that:

Certain files are always included, regardless of settings:

  • package.json
  • README
  • CHANGES / CHANGELOG / HISTORY
  • LICENSE / LICENCE
  • NOTICE
  • The file in the "main" field

Test plan

I changed the files-include-mandatory test to exclude "index.js" from
files, and ensure that it still gets included, since it is the main
file.

@@ -3,5 +3,5 @@
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"files": ["index.js", "a.js", "b.js"]
"files": ["a.js", "b.js"]
Copy link
Member

Choose a reason for hiding this comment

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

could you add index.js to main filed?

Copy link
Member

@bestander bestander left a comment

Choose a reason for hiding this comment

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

Needs test coverage for the new field

@josephfrazier
Copy link
Contributor Author

Hi @bestander, thanks for the quick review! Could you elaborate on your comments? I'm not sure I understand what needs to be changed, as index.js is already in the main field of the test fixture (here), and it is tested to be present in the tarball here.


// inlude required files
let filters: Array<IgnoreFilter> = NEVER_IGNORE.slice();
// include default filters unless `files` is used
if (!onlyFiles) {
filters = filters.concat(DEFAULT_IGNORE);
}
if (main) {
Copy link
Member

Choose a reason for hiding this comment

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

sure, @josephfrazier.
You've added a new condition checking for main in package.json.
But have not added a test that covers this condition.
In __tests__/fixtures/pack/files-include-mandatory/package.json you probably wanted to add main field with index.js and not have it in files?

Copy link
Contributor Author

@josephfrazier josephfrazier Apr 11, 2017

Choose a reason for hiding this comment

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

Hmm, still not sure I understand. In __tests__/fixtures/pack/files-include-mandatory/package.json, the main field is already index.js. The point of this change is to make sure that index.js doesn't have to be in files in order for the packed tarball to contain index.js.

I split my changes into two commits - test first, fix second - which should help demonstrate how the new condition is covered by the test. If you run the following at each commit, you'll see how the tarball changes (this is also covered by yarn build && yarn test -- __tests__/commands/pack.js, but I pushed the two commits too quickly, and the CI for the first commit seems to have run against the changes in the second commit):

yarn build && cd __tests__/fixtures/pack/files-include-mandatory && ../../../../bin/yarn.js pack && tar tvf *tgz | grep index.js; cd -

This is for compatibility with npm, which [specifies] that:

> Certain files are always included, regardless of settings:
> * package.json
> * README
> * CHANGES / CHANGELOG / HISTORY
> * LICENSE / LICENCE
> * NOTICE
> * The file in the "main" field

[specifies]: https://docs.npmjs.com/files/package.json#files
This is for compatibility with npm, which [specifies] that:

> Certain files are always included, regardless of settings:
> * package.json
> * README
> * CHANGES / CHANGELOG / HISTORY
> * LICENSE / LICENCE
> * NOTICE
> * The file in the "main" field

[specifies]: https://docs.npmjs.com/files/package.json#files
@bestander bestander merged commit 4e48fd7 into yarnpkg:master Apr 21, 2017
@bestander
Copy link
Member

Thanks, looks great

This was referenced Apr 28, 2017
@josephfrazier josephfrazier deleted the pack-main branch May 23, 2017 18:08
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.

2 participants