Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add CJS bundle highlight.js/compat #3

Open
wants to merge 1 commit into
base: esm-tests-more-work
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"types": "./types/index.d.ts",
"imports": {
"#hljs": "./build/lib/index.js",
"#hljs/compat": "./build/compat.cjs",
"#tools/*": "./tools/lib/*.js"
},
"type": "module",
Expand Down
5 changes: 3 additions & 2 deletions test/api/highlight.cjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

const hljs = require('#hljs');

const hljs = require('#hljs/compat');


describe('.highlight()', () => {
it('should works without continuation', () => {
Expand Down
9 changes: 9 additions & 0 deletions tools/build_node.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ async function buildNodeLanguage(language) {
await rollupWrite(input, output);
}

async function buildNodeBundle() {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't buildNodeLanguage also have to be updated/suplimented to build all the individual languages in CJS?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It depends, we could decide that we supply only a bundle CJS file – or we can go the dual module package way and provide a CJS module for each language, but I thought you said that was not acceptable?

const input = { ...config.rollup.node.input, input: `${process.env.BUILD_DIR}/lib/index.js` };
const output = { ...config.rollup.node.output, file: `${process.env.BUILD_DIR}/compat.cjs`, format: 'cjs' };
await rollupWrite(input, output);
}

async function buildNodeHighlightJS() {
const input = { ...config.rollup.node.input, input: `src/highlight.js` };
const output = { ...config.rollup.node.output, file: `${process.env.BUILD_DIR}/lib/core.js` };
Expand Down Expand Up @@ -83,6 +89,9 @@ async function buildNode(options) {

log("Writing highlight.js");
await buildNodeHighlightJS();

log("Writing compat.cjs");
await buildNodeBundle();
}

module.exports.build = buildNode;
Expand Down