forked from babel/babel
/
executor.js
68 lines (53 loc) 路 1.78 KB
/
executor.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
const fs = require("fs");
const assert = require("assert");
const readline = require("readline");
// For Node.js <= 10
if (!assert.match) assert.match = (val, re) => assert(re.test(val));
const run = (async function* () {
let files = [yield, yield].sort();
assert.match(files[0], /src[\\/]index.js -> lib[\\/]index.js/);
assert.match(files[1], /src[\\/]main.js -> lib[\\/]main.js/);
assert.match(yield, /Successfully compiled 2 files with Babel \(\d+ms\)\./);
assert.equal(yield, "The watcher is ready.");
logFile("lib/index.js");
logFile("lib/main.js");
fs.writeFileSync("./file.txt", "Updated!");
files = [yield, yield].sort();
assert.match(files[0], /src[\\/]index.js -> lib[\\/]index.js/);
assert.match(files[1], /src[\\/]main.js -> lib[\\/]main.js/);
assert.match(yield, /Successfully compiled 2 files with Babel \(\d+ms\)\./);
logFile("lib/index.js");
logFile("lib/main.js");
})();
run.next();
const batchedStrings = [];
let batchId = 0;
const rl = readline.createInterface(process.stdin);
rl.on("line", async function listener(str) {
if (!str) return;
if (str.startsWith("src")) {
batchedStrings.push(str);
} else {
// "src/index.js -> lib/index.js"-like strings don't always come in order,
// so we need to collect and sort them before logging.
if (batchedStrings.length > 0) {
batchedStrings.sort();
for (const str of batchedStrings) {
console.log(`BATCHED(${batchId})`, str);
}
batchId++;
batchedStrings.length = 0;
}
console.log(str);
}
if ((await run.next(str)).done) {
process.exit(0);
}
});
function logFile(file) {
console.log("EXECUTOR", file, JSON.stringify(fs.readFileSync(file, "utf8")));
}
setTimeout(() => {
console.error("EXECUTOR TIMEOUT");
process.exit(1);
}, 5000);