-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbabel-plugin-inline-runtime.cjs
More file actions
34 lines (31 loc) · 994 Bytes
/
Copy pathbabel-plugin-inline-runtime.cjs
File metadata and controls
34 lines (31 loc) · 994 Bytes
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
const { readFileSync } = require("fs");
const { join } = require("path");
const babel = require("@babel/core");
const { stripTypeScriptTypes } = require("node:module");
module.exports = function inlineRuntimePlugin({ types: t }) {
const rawContent = readFileSync(join(__dirname, "./src/runtime.ts"), "utf-8");
const runtimeContent = stripTypeScriptTypes(rawContent);
return {
name: "inline-runtime",
visitor: {
VariableDeclarator(path) {
if (
path.node.id?.name === "readVMRuntimeFile" &&
(path.node.init?.type === "ArrowFunctionExpression" ||
path.node.init?.type === "FunctionExpression")
) {
path.node.init = t.arrowFunctionExpression(
[],
t.stringLiteral(runtimeContent),
);
}
},
ImportDeclaration(path) {
const src = path.node.source.value;
if (src === "fs" || src === "path") {
path.remove();
}
},
},
};
};