diff --git a/__tests__/commands/pack.js b/__tests__/commands/pack.js index d4e19250b9..e5a4564a94 100644 --- a/__tests__/commands/pack.js +++ b/__tests__/commands/pack.js @@ -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); }); diff --git a/__tests__/fixtures/pack/files-include-mandatory/package.json b/__tests__/fixtures/pack/files-include-mandatory/package.json index 8747fee14b..fe7f6fe41e 100644 --- a/__tests__/fixtures/pack/files-include-mandatory/package.json +++ b/__tests__/fixtures/pack/files-include-mandatory/package.json @@ -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"] } diff --git a/src/cli/commands/pack.js b/src/cli/commands/pack.js index 6bb2cec991..2cf3d8f4c0 100644 --- a/src/cli/commands/pack.js +++ b/src/cli/commands/pack.js @@ -68,7 +68,7 @@ function addEntry(packer: any, entry: Object, buffer?: ?Buffer): Promise { export async function pack(config: Config, dir: string): Promise { const pkg = await config.readRootManifest(); - const {bundledDependencies, files: onlyFiles} = pkg; + const {bundledDependencies, main, files: onlyFiles} = pkg; // inlude required files let filters: Array = NEVER_IGNORE.slice(); @@ -76,6 +76,9 @@ export async function pack(config: Config, dir: string): Promise if (!onlyFiles) { filters = filters.concat(DEFAULT_IGNORE); } + if (main) { + filters = filters.concat(ignoreLinesToRegex(['!/' + main])); + } // include bundledDependencies if (bundledDependencies) { diff --git a/src/types.js b/src/types.js index f28febdb90..a02b2c1e0d 100644 --- a/src/types.js +++ b/src/types.js @@ -120,6 +120,7 @@ export type Manifest = { deprecated?: string, files?: Array, + main?: string, }; //