forked from rollup/rollup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
_config.js
27 lines (25 loc) · 805 Bytes
/
_config.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
const { unlinkSync, writeFileSync } = require('node:fs');
const path = require('node:path');
const { atomicWriteFileSync } = require('../../../../utils');
let mainFile;
module.exports = {
description: 'recovers from errors during bundling',
command: 'rollup -cw --bundleConfigAsCjs',
before() {
mainFile = path.resolve(__dirname, 'main.js');
writeFileSync(mainFile, '<=>');
},
after() {
// synchronous sometimes does not seem to work, probably because the watch is not yet removed properly
setTimeout(() => unlinkSync(mainFile), 300);
},
abortOnStderr(data) {
if (data.includes('[!] RollupError: Unexpected token')) {
setTimeout(() => atomicWriteFileSync(mainFile, 'export default 42;'), 500);
return false;
}
if (data.includes('created _actual')) {
return true;
}
}
};