Skip to content

Commit

Permalink
have our rollup build test our HighlightJS export
Browse files Browse the repository at this point in the history
  • Loading branch information
joshgoebel committed Oct 17, 2021
1 parent 29c2556 commit 6927957
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
7 changes: 5 additions & 2 deletions test/builds/package.js
Expand Up @@ -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.");
10 changes: 5 additions & 5 deletions tools/build_node.js
Expand Up @@ -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;`;

Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit 6927957

Please sign in to comment.