/
_config.js
30 lines (28 loc) · 918 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
28
29
30
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')) {
console.log('TRIGGER WRITE FILE');
setTimeout(() => atomicWriteFileSync(mainFile, 'export default 42;'), 500);
return false;
} else if (data.includes('created _actual')) {
console.log('DONE');
return true;
} else {
console.log('NO TRIGGER:', data);
}
}
};