From 48a899f7a90db8d2e9d5443dd8aa8b08613a4c12 Mon Sep 17 00:00:00 2001 From: Alois Klink Date: Sat, 10 Sep 2022 02:22:03 +0100 Subject: [PATCH] build: remove main function from `.jison` files When converting a `.jison` file into a CommonJS module, jison by default adds a main() function that calls `require("fs");` Even though the main function is never used in the browser, because `fs` is a Node.JS only module, this causes some esbuild issues. To disable this, we can just set an empty main to the jison generator. --- .esbuild/util.cjs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.esbuild/util.cjs b/.esbuild/util.cjs index 6b462ff4e..f22186fc2 100644 --- a/.esbuild/util.cjs +++ b/.esbuild/util.cjs @@ -61,7 +61,9 @@ const jisonPlugin = { build.onLoad({ filter: /\.jison$/ }, async (args) => { // Load the file from the file system const source = await fs.promises.readFile(args.path, 'utf8'); - const contents = new Generator(source, { 'token-stack': true }).generate(); + const contents = new Generator(source, { 'token-stack': true }).generate({ + moduleMain: '() => {}', // disable moduleMain (default one requires Node.JS modules) + }); return { contents, warnings: [] }; }); },