Skip to content

Commit

Permalink
fix(publish): ignore unnecessary files when publishing to npm (#3024)
Browse files Browse the repository at this point in the history
  • Loading branch information
erikian committed Oct 31, 2022
1 parent 7aaa702 commit ab8ea66
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions tools/publish.js
Expand Up @@ -60,12 +60,22 @@ const publisher = new Listr([
return {
title: `Publishing: ${chalk.cyan(`${name}@${version}`)} (beta=${isBeta ? chalk.green('true') : chalk.red('false')})`,
task: async () => {
const npmIgnorePath = path.join(dir, '.npmignore');
let writtenNpmIgnore = false;

try {
await fs.promises.writeFile(npmIgnorePath, ['*.ts', '!*.d.ts', '*.tsbuildinfo', 'tsconfig.json', '*.map', '/test'].join('\n'));
writtenNpmIgnore = true;

await spawn('npm', ['publish', '--access=public', ...(isBeta ? ['--tag=beta'] : []), `--otp=${ctx.otp}`], {
cwd: dir,
});
} catch (err) {
throw new Error(`Failed to publish ${chalk.cyan(`${name}@${version}`)} \n${err.stderr.toString()}`);
} finally {
if (writtenNpmIgnore) {
await fs.promises.rm(npmIgnorePath);
}
}
},
};
Expand Down

0 comments on commit ab8ea66

Please sign in to comment.