Skip to content

Commit 20a64a1

Browse files
Add forceExit CLI flag (#5195)
* add forceExit flag * reword forceExit docs * add forceExit test --------- Co-authored-by: Lukas Taegert-Atkinson <[email protected]>
1 parent d255414 commit 20a64a1

File tree

6 files changed

+34
-1
lines changed

6 files changed

+34
-1
lines changed

cli/cli.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,9 @@ if (command.help || (process.argv.length <= 2 && process.stdin.isTTY)) {
2323
// do nothing
2424
}
2525

26-
run(command);
26+
const promise = run(command);
27+
if (command.forceExit) {
28+
// eslint-disable-next-line unicorn/no-process-exit
29+
promise.then(() => process.exit());
30+
}
2731
}

cli/help.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ Basic options:
4040
--failAfterWarnings Exit with an error if the build produced warnings
4141
--filterLogs <filter> Filter log messages
4242
--footer <text> Code to insert at end of bundle (outside wrapper)
43+
--forceExit Force exit the process when done
4344
--no-freeze Do not freeze namespace objects
4445
--generatedCode <preset> Which code features to use (es5/es2015)
4546
--generatedCode.arrowFunctions Use arrow functions in generated code

docs/command-line-interface/index.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,7 @@ Many options have command line equivalents. In those cases, any arguments passed
390390
--failAfterWarnings Exit with an error if the build produced warnings
391391
--filterLogs <filter> Filter log messages
392392
--footer <text> Code to insert at end of bundle (outside wrapper)
393+
--forceExit Force exit the process when done
393394
--no-freeze Do not freeze namespace objects
394395
--generatedCode <preset> Which code features to use (es5/es2015)
395396
--generatedCode.arrowFunctions Use arrow functions in generated code
@@ -556,6 +557,12 @@ There is also some advanced syntax available for more complex filters.
556557

557558
will only display logs where the property `log.foo.bar` has the value `"value"`.
558559

560+
### `--forceExit`
561+
562+
Force exit the process when done. In some cases plugins or their dependencies might not cleanup properly and prevent the CLI process from exiting. The root cause can be hard to diagnose and this flag provides an escape hatch until it can be identified and resolved.
563+
564+
Note that this might break certain workflows and won't always work properly.
565+
559566
### `-h`/`--help`
560567
561568
Print the help document.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = defineTest({
2+
description: 'force exits even with open handles',
3+
command: 'rollup --config rollup.config.js --forceExit',
4+
execute: true
5+
});

test/cli/samples/force-exit/main.js

Whitespace-only changes.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
module.exports = {
2+
input: 'main.js',
3+
output: {
4+
format: 'cjs'
5+
},
6+
plugins: [
7+
{
8+
name: 'open-handles',
9+
buildStart() {
10+
setInterval(() => {
11+
// hang forever
12+
}, 2 ** 24);
13+
}
14+
}
15+
]
16+
};

0 commit comments

Comments
 (0)