waforth/scripts/esbuild/forth.js
2022-04-17 10:00:15 +02:00

35 lines
784 B
JavaScript

/* eslint-env node */
const fs = require("fs");
const path = require("path");
function forthPlugin() {
return {
name: "forth",
setup(build) {
build.onResolve({ filter: /.\.f$/ }, async (args) => {
if (args.resolveDir === "") {
return;
}
const filePath = path.isAbsolute(args.path)
? args.path
: path.join(args.resolveDir, args.path);
return {
path: filePath,
namespace: "forth",
watchFiles: [filePath],
};
});
build.onLoad({ filter: /.*/, namespace: "forth" }, async (args) => {
return {
contents: await fs.promises.readFile(args.path),
loader: "text",
};
});
},
};
}
module.exports = {
forthPlugin,
};