forked from SparkDevNetwork/Rock
-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathrollup-mt-worker.js
More file actions
97 lines (81 loc) · 2.57 KB
/
rollup-mt-worker.js
File metadata and controls
97 lines (81 loc) · 2.57 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
const { loadConfigFile } = require("rollup/loadConfigFile");
const rollup = require("rollup");
/**
* @typedef CompileResult
* @param source {string} The source filename that was compiled.
* @param outputs {string[]} The output filename.
* @param duration {number} The number of milliseconds the operation took.
* @param errors {string[]} Any errors during compilation.
*/
/**
* Compiles a single options bundle.
*
* @param {import("rollup").RollupOptions} option
*
* @returns {CompileResult} The result of the compile operation.
*/
async function compile(option) {
const compileStartTime = performance.now();
try {
const bundle = await rollup.rollup(option);
const writeResult = await bundle.write(option.output[0]);
await bundle.close();
const duration = Math.floor(performance.now() - compileStartTime);
return {
source: option.input,
outputs: writeResult.output.filter(c => c.type === "chunk").map(c => c.fileName),
duration,
errors: []
};
}
catch (error) {
let message = error instanceof Error ? error.message : `${error}`;
const duration = Math.floor(performance.now() - compileStartTime);
return {
source: option.input,
outputs: [],
duration,
errors: [message]
};
}
}
async function main() {
const config = await loadConfigFile(process.argv[2]);
config.warnings.flush();
/** @type {import("rollup").RollupOptions[]} */
const options = config.options
.filter(o => typeof o.input === "string" && o.output && o.output.length === 1);
process.on("message", command => {
if (command.type === "exit") {
process.exit(0);
}
else if (command.type === "compile") {
compileFile(command.data);
}
});
process.send({ type: "ready" });
async function compileFile(file) {
const option = options.find(o => o.input === file);
if (!option) {
process.send({
type: "result",
data: {
source: file,
outputs: [],
duraiton: 0,
errors: ["File was not found."]
}
});
process.send({ type: "ready" });
}
else {
const result = await compile(option);
process.send({
type: "result",
data: result
});
process.send({ type: "ready" });
}
}
}
main();