Skip to content

Commit

Permalink
Fix yarn pack to always include the file in the "main" field (#3092)
Browse files Browse the repository at this point in the history
* Test that `yarn pack` always includes the file in the "main" field

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

* Fix `yarn pack` to always include the file in the "main" field

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
  • Loading branch information
josephfrazier authored and bestander committed Apr 21, 2017
1 parent 9a6afe1 commit 4e48fd7
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion __tests__/commands/pack.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ test.concurrent('pack should include mandatory files not listed in files array i
path.join(cwd, 'files-include-mandatory-v1.0.0.tgz'),
path.join(cwd, 'files-include-mandatory-v1.0.0'),
);
const expected = ['package.json', 'readme.md', 'license', 'changelog'];
const expected = ['package.json', 'index.js', 'readme.md', 'license', 'changelog'];
expected.forEach((filename) => {
expect(files.indexOf(filename)).toBeGreaterThanOrEqual(0);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
}
5 changes: 4 additions & 1 deletion src/cli/commands/pack.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,17 @@ function addEntry(packer: any, entry: Object, buffer?: ?Buffer): Promise<void> {

export async function pack(config: Config, dir: string): Promise<stream$Duplex> {
const pkg = await config.readRootManifest();
const {bundledDependencies, files: onlyFiles} = pkg;
const {bundledDependencies, main, files: onlyFiles} = pkg;

// include 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) {
filters = filters.concat(ignoreLinesToRegex(['!/' + main]));
}

// include bundledDependencies
if (bundledDependencies) {
Expand Down
1 change: 1 addition & 0 deletions src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ export type Manifest = {

deprecated?: string,
files?: Array<string>,
main?: string,
};

//
Expand Down

0 comments on commit 4e48fd7

Please sign in to comment.