Skip to content

Commit 61b779d

Browse files
committed
Anchor files to the package’s root
npm pack bases paths from the `files` array from the package’s root. This updates yarn pack to behave in the same way.
1 parent aa4e713 commit 61b779d

File tree

5 files changed

+22
-2
lines changed

5 files changed

+22
-2
lines changed

__tests__/commands/pack.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,18 @@ test.concurrent('pack should include all files listed in the files array', (): P
6767
});
6868
});
6969

70+
test.concurrent('pack should include files based from the package’s root', (): Promise<void> => {
71+
return runPack([], {}, 'files-include-from-root', async (config): Promise<void> => {
72+
const {cwd} = config;
73+
const files = await getFilesFromArchive(
74+
path.join(cwd, 'files-include-from-root-v1.0.0.tgz'),
75+
path.join(cwd, 'files-include-from-root-v1.0.0'),
76+
);
77+
expect(files.indexOf('index.js')).toBeGreaterThanOrEqual(0);
78+
expect(files.indexOf('sub/index.js')).toEqual(-1);
79+
});
80+
});
81+
7082
test.concurrent('pack should included globbed files', (): Promise<void> => {
7183
return runPack([], {}, 'files-glob', async (config): Promise<void> => {
7284
const {cwd} = config;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log('included');
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"name": "files-include-from-root",
3+
"version": "1.0.0",
4+
"license": "MIT",
5+
"files": ["index.js"]
6+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log('not included');

src/cli/commands/pack.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ export async function packTarball(
8585
'*', // ignore all files except those that are explicitly included with a negation filter
8686
];
8787
lines = lines.concat(
88-
onlyFiles.map((filename: string): string => `!${filename}`),
89-
onlyFiles.map((filename: string): string => `!${path.join(filename, '**')}`),
88+
onlyFiles.map((filename: string): string => `!${path.join('/', filename)}`),
89+
onlyFiles.map((filename: string): string => `!${path.join('/', filename, '**')}`),
9090
);
9191
const regexes = ignoreLinesToRegex(lines, '.');
9292
filters = filters.concat(regexes);

0 commit comments

Comments
 (0)