Skip to content

Commit

Permalink
Anchor files to the package’s root
Browse files Browse the repository at this point in the history
npm pack bases paths from the `files` array from the package’s
root. This updates yarn pack to behave in the same way.
  • Loading branch information
tusbar committed Oct 21, 2018
1 parent aa4e713 commit 61b779d
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 2 deletions.
12 changes: 12 additions & 0 deletions __tests__/commands/pack.js
Expand Up @@ -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<void> => {
return runPack([], {}, 'files-include-from-root', async (config): Promise<void> => {
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<void> => {
return runPack([], {}, 'files-glob', async (config): Promise<void> => {
const {cwd} = config;
Expand Down
1 change: 1 addition & 0 deletions __tests__/fixtures/pack/files-include-from-root/index.js
@@ -0,0 +1 @@
console.log('included');
6 changes: 6 additions & 0 deletions __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"]
}
@@ -0,0 +1 @@
console.log('not included');
4 changes: 2 additions & 2 deletions src/cli/commands/pack.js
Expand Up @@ -85,8 +85,8 @@ export async function packTarball(
'*', // ignore all files except those that are explicitly included with a negation filter
];
lines = lines.concat(
onlyFiles.map((filename: string): string => `!${filename}`),
onlyFiles.map((filename: string): string => `!${path.join(filename, '**')}`),
onlyFiles.map((filename: string): string => `!${path.join('/', filename)}`),
onlyFiles.map((filename: string): string => `!${path.join('/', filename, '**')}`),
);
const regexes = ignoreLinesToRegex(lines, '.');
filters = filters.concat(regexes);
Expand Down

0 comments on commit 61b779d

Please sign in to comment.