Skip to content

Commit

Permalink
Add forceExit CLI flag (#5195)
Browse files Browse the repository at this point in the history
* add forceExit flag

* reword forceExit docs

* add forceExit test

---------

Co-authored-by: Lukas Taegert-Atkinson <lukastaegert@users.noreply.github.com>
  • Loading branch information
raphael-theriault-swi and lukastaegert committed Nov 3, 2023
1 parent d255414 commit 20a64a1
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 1 deletion.
6 changes: 5 additions & 1 deletion cli/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,9 @@ if (command.help || (process.argv.length <= 2 && process.stdin.isTTY)) {
// do nothing
}

run(command);
const promise = run(command);
if (command.forceExit) {
// eslint-disable-next-line unicorn/no-process-exit
promise.then(() => process.exit());
}
}
1 change: 1 addition & 0 deletions cli/help.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Basic options:
--failAfterWarnings Exit with an error if the build produced warnings
--filterLogs <filter> Filter log messages
--footer <text> Code to insert at end of bundle (outside wrapper)
--forceExit Force exit the process when done
--no-freeze Do not freeze namespace objects
--generatedCode <preset> Which code features to use (es5/es2015)
--generatedCode.arrowFunctions Use arrow functions in generated code
Expand Down
7 changes: 7 additions & 0 deletions docs/command-line-interface/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@ Many options have command line equivalents. In those cases, any arguments passed
--failAfterWarnings Exit with an error if the build produced warnings
--filterLogs <filter> Filter log messages
--footer <text> Code to insert at end of bundle (outside wrapper)
--forceExit Force exit the process when done
--no-freeze Do not freeze namespace objects
--generatedCode <preset> Which code features to use (es5/es2015)
--generatedCode.arrowFunctions Use arrow functions in generated code
Expand Down Expand Up @@ -556,6 +557,12 @@ There is also some advanced syntax available for more complex filters.

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

### `--forceExit`

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.

Note that this might break certain workflows and won't always work properly.
### `-h`/`--help`
Print the help document.
Expand Down
5 changes: 5 additions & 0 deletions test/cli/samples/force-exit/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = defineTest({
description: 'force exits even with open handles',
command: 'rollup --config rollup.config.js --forceExit',
execute: true
});
Empty file.
16 changes: 16 additions & 0 deletions test/cli/samples/force-exit/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module.exports = {
input: 'main.js',
output: {
format: 'cjs'
},
plugins: [
{
name: 'open-handles',
buildStart() {
setInterval(() => {
// hang forever
}, 2 ** 24);
}
}
]
};

0 comments on commit 20a64a1

Please sign in to comment.