diff --git a/__tests__/commands/pack.js b/__tests__/commands/pack.js index cd825c67b8..e81fd0a4d1 100644 --- a/__tests__/commands/pack.js +++ b/__tests__/commands/pack.js @@ -67,6 +67,18 @@ test.concurrent('pack should include all files listed in the files array', (): P }); }); +test.concurrent('pack should include files based from the package’s root', (): Promise => { + return runPack([], {}, 'files-include-from-root', async (config): Promise => { + const {cwd} = config; + const files = await getFilesFromArchive( + path.join(cwd, 'files-include-from-root-v1.0.0.tgz'), + path.join(cwd, 'files-include-from-root-v1.0.0'), + ); + expect(files.indexOf('index.js')).toBeGreaterThanOrEqual(0); + expect(files.indexOf('sub/index.js')).toEqual(-1); + }); +}); + test.concurrent('pack should included globbed files', (): Promise => { return runPack([], {}, 'files-glob', async (config): Promise => { const {cwd} = config; diff --git a/__tests__/fixtures/pack/files-include-from-root/index.js b/__tests__/fixtures/pack/files-include-from-root/index.js new file mode 100644 index 0000000000..452029d835 --- /dev/null +++ b/__tests__/fixtures/pack/files-include-from-root/index.js @@ -0,0 +1 @@ +console.log('included'); diff --git a/__tests__/fixtures/pack/files-include-from-root/package.json b/__tests__/fixtures/pack/files-include-from-root/package.json new file mode 100644 index 0000000000..94eca8baf3 --- /dev/null +++ b/__tests__/fixtures/pack/files-include-from-root/package.json @@ -0,0 +1,6 @@ +{ + "name": "files-include-from-root", + "version": "1.0.0", + "license": "MIT", + "files": ["index.js"] +} diff --git a/__tests__/fixtures/pack/files-include-from-root/sub/index.js b/__tests__/fixtures/pack/files-include-from-root/sub/index.js new file mode 100644 index 0000000000..14816cc323 --- /dev/null +++ b/__tests__/fixtures/pack/files-include-from-root/sub/index.js @@ -0,0 +1 @@ +console.log('not included'); diff --git a/src/cli/commands/pack.js b/src/cli/commands/pack.js index c84e107387..b6500751db 100644 --- a/src/cli/commands/pack.js +++ b/src/cli/commands/pack.js @@ -88,7 +88,7 @@ export async function packTarball( onlyFiles.map((filename: string): string => `!${filename}`), onlyFiles.map((filename: string): string => `!${path.join(filename, '**')}`), ); - const regexes = ignoreLinesToRegex(lines, '.'); + const regexes = ignoreLinesToRegex(lines, './'); filters = filters.concat(regexes); }