Skip to content

Commit

Permalink
Automatically force close Rollup when done
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed May 1, 2023
1 parent 64870c3 commit b86ea21
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 20 deletions.
8 changes: 4 additions & 4 deletions cli/cli.ts
@@ -1,16 +1,16 @@
import process from 'node:process';
import { argv, exit, stdin } from 'node:process';
import help from 'help.md';
import { version } from 'package.json';
import argParser from 'yargs-parser';
import { commandAliases } from '../src/utils/options/mergeOptions';
import run from './run/index';

const command = argParser(process.argv.slice(2), {
const command = argParser(argv.slice(2), {
alias: commandAliases,
configuration: { 'camel-case-expansion': false }
});

if (command.help || (process.argv.length <= 2 && process.stdin.isTTY)) {
if (command.help || (argv.length <= 2 && stdin.isTTY)) {
console.log(`\n${help.replace('__VERSION__', version)}\n`);
} else if (command.version) {
console.log(`rollup v${version}`);
Expand All @@ -22,5 +22,5 @@ if (command.help || (process.argv.length <= 2 && process.stdin.isTTY)) {
// do nothing
}

run(command);
run(command).then(() => exit(0));
}
2 changes: 1 addition & 1 deletion cli/run/index.ts
Expand Up @@ -55,7 +55,7 @@ export default async function runRollup(command: Record<string, any>): Promise<v
if (isWatchEnabled(command.watch)) {
await loadFsEvents();
const { watch } = await import('./watch-cli');
watch(command);
await watch(command);
} else {
try {
const { options, warnings } = await getConfigs(command);
Expand Down
9 changes: 5 additions & 4 deletions cli/run/watch-cli.ts
Expand Up @@ -154,9 +154,10 @@ export async function watch(command: Record<string, any>): Promise<void> {
if (watcher) await watcher.close();
if (configWatcher) configWatcher.close();

if (code) {
// eslint-disable-next-line unicorn/no-process-exit
process.exit(code);
}
// eslint-disable-next-line unicorn/no-process-exit
process.exit(code || 0);
}

// return a promise that never resolves to keep the process running
return new Promise(() => {});
}
12 changes: 1 addition & 11 deletions rollup.config.ts
@@ -1,4 +1,3 @@
import { exit } from 'node:process';
import { fileURLToPath } from 'node:url';
import alias from '@rollup/plugin-alias';
import commonjs from '@rollup/plugin-commonjs';
Expand Down Expand Up @@ -138,16 +137,7 @@ export default async function (
terser({ module: true, output: { comments: 'some' } }),
collectLicensesBrowser(),
writeLicenseBrowser(),
cleanBeforeWrite('browser/dist'),
{
closeBundle() {
// On CI, MacOS runs sometimes do not close properly. This is a hack
// to fix this until the problem is understood.
console.log('Force quit.');
setTimeout(() => exit(0));
},
name: 'force-close'
}
cleanBeforeWrite('browser/dist')
],
strictDeprecations: true,
treeshake
Expand Down

0 comments on commit b86ea21

Please sign in to comment.