-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup-exit-plugin.js
47 lines (43 loc) · 1.68 KB
/
rollup-exit-plugin.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import whyIsNodeRunning from 'why-is-node-running';
let runningBundles = 0;
/**
* @param {string} name
* @param {number} maxWaitTime Maximum number of seconds to wait for Rollup to exit before force-exiting
* @returns {{closeBundle(): void, buildStart(): void, name: string}}
*/
export const rollupForceExit = (name, maxWaitTime = 60) => {
return {
/** @this {import('rollup').PluginContext} */
buildStart() {
if (this.meta.watchMode) {
return;
}
runningBundles++;
this.info(`${name}: Starting build, ${runningBundles} build(s) running`);
},
/** @this {import('rollup').PluginContext} */
closeBundle() {
if (this.meta.watchMode) {
return;
}
runningBundles--;
const timeout = setTimeout(() => {
if (runningBundles === 0) {
this.info(
`${name}: Rollup is now done, but did not exit before ${maxWaitTime} seconds, force exiting...`,
);
whyIsNodeRunning();
setTimeout(() => process.exit(0));
} else {
this.info(
`${name}: Rollup is still working on another build process, waiting for ${runningBundles} running bundle(s) before force exit`,
);
}
}, maxWaitTime * 1000);
// Allow the NodeJS process to finish without waiting for the timeout, using it only as a fallback for
// otherwise hanging Rollup processes
timeout.unref();
},
name: 'force-close',
};
};