From 553fad9d03cd41e1394b14c35dbbc86e650b5be3 Mon Sep 17 00:00:00 2001 From: Josh Goebel Date: Sun, 15 Aug 2021 01:31:38 -0400 Subject: [PATCH 1/6] (chore) export named `hljs` export in Node packages --- tools/build_node.js | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/build_node.js b/tools/build_node.js index 6e8117e664..67210fa68f 100644 --- a/tools/build_node.js +++ b/tools/build_node.js @@ -13,6 +13,7 @@ async function buildESMStub(name) { const code = `// https://nodejs.org/api/packages.html#packages_writing_dual_packages_while_avoiding_or_minimizing_hazards\n` + `import hljs from '../lib/${name}.js';\n` + + `export { hljs };\n` + `export default hljs;\n`; await fs.writeFile(`${process.env.BUILD_DIR}/es/${name}.js`, code); } From 507a1ee1ef059b16b0934bd906823f1389ff554a Mon Sep 17 00:00:00 2001 From: Josh Goebel Date: Thu, 19 Aug 2021 17:44:52 -0400 Subject: [PATCH 2/6] CJS also --- tools/build_config.js | 7 ++++++- tools/build_node.js | 3 ++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/tools/build_config.js b/tools/build_config.js index 6d6557f4ab..f61b697c66 100644 --- a/tools/build_config.js +++ b/tools/build_config.js @@ -28,7 +28,12 @@ module.exports = { } }, node: { - output: { format: "cjs", strict: false, exports: "auto" } + output: { + format: "cjs", + strict: false, + exports: "auto", + footer: "highlight.hljs = highlight;" + } }, browser_iife: { input: { diff --git a/tools/build_node.js b/tools/build_node.js index 67210fa68f..8b51ab10d6 100644 --- a/tools/build_node.js +++ b/tools/build_node.js @@ -20,7 +20,8 @@ async function buildESMStub(name) { async function buildCJSIndex(name, languages) { const header = "var hljs = require('./core');"; - const footer = "module.exports = hljs;"; + const footer = `hljs.hljs = hljs\n` + + `module.exports = hljs;`; const registration = languages.map((lang) => { const require = `require('./languages/${lang.name}')`; From ffb7cd18be28bab94d5387a841fae947badb24a4 Mon Sep 17 00:00:00 2001 From: Josh Goebel Date: Wed, 29 Sep 2021 19:14:28 -0400 Subject: [PATCH 3/6] export exports.default as well for TS --- tools/build_config.js | 2 +- tools/build_node.js | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/tools/build_config.js b/tools/build_config.js index f61b697c66..b66d935238 100644 --- a/tools/build_config.js +++ b/tools/build_config.js @@ -32,7 +32,7 @@ module.exports = { format: "cjs", strict: false, exports: "auto", - footer: "highlight.hljs = highlight;" + footer: "highlight.hljs = highlight;\nhighlight.default = highlight;" } }, browser_iife: { diff --git a/tools/build_node.js b/tools/build_node.js index 8b51ab10d6..bec9703ce9 100644 --- a/tools/build_node.js +++ b/tools/build_node.js @@ -20,7 +20,9 @@ async function buildESMStub(name) { async function buildCJSIndex(name, languages) { const header = "var hljs = require('./core');"; - const footer = `hljs.hljs = hljs\n` + + const footer = + `hljs.hljs = hljs\n` + + `hljs.default = hljs\n` + `module.exports = hljs;`; const registration = languages.map((lang) => { From 29c25561247f6eb13558303a7f92c6fdf87588cc Mon Sep 17 00:00:00 2001 From: Josh Goebel Date: Wed, 29 Sep 2021 19:19:37 -0400 Subject: [PATCH 4/6] footer for cjs node main build only --- tools/build_config.js | 2 +- tools/build_node.js | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/build_config.js b/tools/build_config.js index b66d935238..02f91373ad 100644 --- a/tools/build_config.js +++ b/tools/build_config.js @@ -32,7 +32,7 @@ module.exports = { format: "cjs", strict: false, exports: "auto", - footer: "highlight.hljs = highlight;\nhighlight.default = highlight;" + footer: "" } }, browser_iife: { diff --git a/tools/build_node.js b/tools/build_node.js index bec9703ce9..cc08d45ed4 100644 --- a/tools/build_node.js +++ b/tools/build_node.js @@ -86,6 +86,7 @@ async function buildESMUtils() { async function buildNodeHighlightJS(options) { const input = { ...config.rollup.core.input, input: `src/highlight.js` }; const output = { ...config.rollup.node.output, file: `${process.env.BUILD_DIR}/lib/core.js` }; + output.footer = "highlight.hljs = highlight;\nhighlight.default = highlight;"; await rollupWrite(input, output); if (options.esm) { buildESMStub("core"); From 69279576df277bef8f09a94d32d368da5f977e97 Mon Sep 17 00:00:00 2001 From: Josh Goebel Date: Sun, 17 Oct 2021 08:53:32 -0400 Subject: [PATCH 5/6] have our rollup build test our HighlightJS export --- test/builds/package.js | 7 +++++-- tools/build_node.js | 10 +++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/test/builds/package.js b/test/builds/package.js index 49376f43b2..eaff262ce0 100644 --- a/test/builds/package.js +++ b/test/builds/package.js @@ -6,6 +6,9 @@ See .travis.yml */ import hljs from '../../build/lib/index.js'; +import { HighlightJS } from '../../build/lib/index.js' -hljs.highlight("cpp","/* test */") -console.log("Rollup built package works.") +const language = "cpp"; +hljs.highlight("/* test */", {language}); +HighlightJS.highlight("/* test */", {language}); +console.log("Rollup built package works."); diff --git a/tools/build_node.js b/tools/build_node.js index cc08d45ed4..9dcc8579b5 100644 --- a/tools/build_node.js +++ b/tools/build_node.js @@ -12,16 +12,16 @@ const log = (...args) => console.log(...args); async function buildESMStub(name) { const code = `// https://nodejs.org/api/packages.html#packages_writing_dual_packages_while_avoiding_or_minimizing_hazards\n` + - `import hljs from '../lib/${name}.js';\n` + - `export { hljs };\n` + - `export default hljs;\n`; + `import HighlightJS from '../lib/${name}.js';\n` + + `export { HighlightJS };\n` + + `export default HighlightJS;\n`; await fs.writeFile(`${process.env.BUILD_DIR}/es/${name}.js`, code); } async function buildCJSIndex(name, languages) { const header = "var hljs = require('./core');"; const footer = - `hljs.hljs = hljs\n` + + `hljs.HighlightJS = hljs\n` + `hljs.default = hljs\n` + `module.exports = hljs;`; @@ -86,7 +86,7 @@ async function buildESMUtils() { async function buildNodeHighlightJS(options) { const input = { ...config.rollup.core.input, input: `src/highlight.js` }; const output = { ...config.rollup.node.output, file: `${process.env.BUILD_DIR}/lib/core.js` }; - output.footer = "highlight.hljs = highlight;\nhighlight.default = highlight;"; + output.footer = "highlight.HighlightJS = highlight;\nhighlight.default = highlight;"; await rollupWrite(input, output); if (options.esm) { buildESMStub("core"); From d79bc6ffd91a4c286c2c6e5ab2819a7ddd31f47a Mon Sep 17 00:00:00 2001 From: Josh Goebel Date: Sun, 17 Oct 2021 08:58:40 -0400 Subject: [PATCH 6/6] add changelog --- CHANGES.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index f906cad1ec..ac98114f38 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,10 @@ ## Version 11.3.0 (most likely) +Build: + +- add `HighlightJS` named export (#3295) [Josh Goebel][] +- add `.default` named export to CJS builds (#3333) [Josh Goebel][] + Parser: - add first rough performance testing script (#3280) [Austin Schick][]