Skip to content

Commit ab8ea66

Browse files
authored
fix(publish): ignore unnecessary files when publishing to npm (#3024)
1 parent 7aaa702 commit ab8ea66

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

tools/publish.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,22 @@ const publisher = new Listr([
6060
return {
6161
title: `Publishing: ${chalk.cyan(`${name}@${version}`)} (beta=${isBeta ? chalk.green('true') : chalk.red('false')})`,
6262
task: async () => {
63+
const npmIgnorePath = path.join(dir, '.npmignore');
64+
let writtenNpmIgnore = false;
65+
6366
try {
67+
await fs.promises.writeFile(npmIgnorePath, ['*.ts', '!*.d.ts', '*.tsbuildinfo', 'tsconfig.json', '*.map', '/test'].join('\n'));
68+
writtenNpmIgnore = true;
69+
6470
await spawn('npm', ['publish', '--access=public', ...(isBeta ? ['--tag=beta'] : []), `--otp=${ctx.otp}`], {
6571
cwd: dir,
6672
});
6773
} catch (err) {
6874
throw new Error(`Failed to publish ${chalk.cyan(`${name}@${version}`)} \n${err.stderr.toString()}`);
75+
} finally {
76+
if (writtenNpmIgnore) {
77+
await fs.promises.rm(npmIgnorePath);
78+
}
6979
}
7080
},
7181
};

0 commit comments

Comments
 (0)