From 9a6f65ac60dfe1254954cd81107f82bf26b75050 Mon Sep 17 00:00:00 2001 From: Josh Goebel Date: Thu, 19 Sep 2024 18:17:32 -0400 Subject: [PATCH] (enh) add example to rollup build against Node/esm modules --- test/builds/node_build_as_esm.mjs | 24 ++++++++++++++++++++ test/builds/rollup_import_node_build_esm.mjs | 16 +++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 test/builds/node_build_as_esm.mjs create mode 100644 test/builds/rollup_import_node_build_esm.mjs diff --git a/test/builds/node_build_as_esm.mjs b/test/builds/node_build_as_esm.mjs new file mode 100644 index 0000000000..9b26ab2a5d --- /dev/null +++ b/test/builds/node_build_as_esm.mjs @@ -0,0 +1,24 @@ +import hljs from "../../build/es/index.js"; + +const API = [ + "getLanguage", + "registerLanguage", + "highlight", + "highlightAuto", + "highlightAll", + "highlightElement", +]; + +const assert = (f, msg) => { + if (!f()) { + console.error(msg); + process.exit(1); + } +}; +const keys = Object.keys(hljs); + +API.forEach((n) => { + assert((_) => keys.includes(n), `API should include ${n}`); +}); + +console.log("Pass: browser build works with Node.js just fine."); diff --git a/test/builds/rollup_import_node_build_esm.mjs b/test/builds/rollup_import_node_build_esm.mjs new file mode 100644 index 0000000000..51476053e0 --- /dev/null +++ b/test/builds/rollup_import_node_build_esm.mjs @@ -0,0 +1,16 @@ +// rollup.config.js +import commonjs from "@rollup/plugin-commonjs"; + +export default { + input: "test/builds/node_build_as_esm.mjs", + output: { + file: "build/bundle.js", + format: "iife", + }, + plugins: [ + commonjs({ + include: "build/**", // Default: undefined + exclude: ["node_modules/**"], // Default: undefined + }), + ], +};