Skip to content

Commit

Permalink
Add back support for CJS extra languages
Browse files Browse the repository at this point in the history
  • Loading branch information
aduh95 committed Jun 26, 2021
1 parent b046620 commit 13b4ea1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
9 changes: 3 additions & 6 deletions tools/lib/external_language.js
Expand Up @@ -107,17 +107,14 @@ class LanguagePackage {

// third party language modules are dropped into the `highlight-js/extra`
// folder and will be auto-detected by the build system
async function getThirdPartyPackages() {
const packages = [];
async function* getThirdPartyPackages() {
const otherPackages = await glob("./extra/*");
for (const packageDir of otherPackages) {
const thirdPartyPackage = new LanguagePackage(packageDir);
const valid = await thirdPartyPackage.valid();
if (valid) {
packages.push(thirdPartyPackage);
if(await thirdPartyPackage.valid()){
yield thirdPartyPackage;
}
}
return packages;
}

module.exports = { LanguagePackage, getThirdPartyPackages };
15 changes: 8 additions & 7 deletions tools/lib/language.js
Expand Up @@ -83,7 +83,9 @@ async function compileLanguage (language, options) {

// TODO: cant we use the source we already have?
const input = { ...build_config.rollup.browser.input, input: language.path };
const output = { ...build_config.rollup.browser.output, name: `dummyName`, file: "out.js" };
if(language.type === 'npm-cjs') input.plugins = build_config.rollup.browser_iife.input.plugins;

const output = { ...build_config.rollup.browser.output, file: "out.js" };

const esm = await rollupCode(input, output);
const iife = `hljs.registerLanguage('${language.name}', function (){"use strict";` + esm.replace(EXPORT_REGEX, 'return $1') + '})';
Expand All @@ -96,17 +98,16 @@ async function compileLanguage (language, options) {
}

async function getLanguages() {
let languages = [];
glob.sync("./src/languages/*.js").forEach((file) => {
languages.push(Language.fromFile(file));
});
let extraPackages = await getThirdPartyPackages();
for (let ext of extraPackages) {
let languages = glob.sync("./src/languages/*.js").map((file) =>
Language.fromFile(file)
);
for await (const ext of await getThirdPartyPackages()) {
for (let file of ext.files) {
let l = Language.fromFile(file);
l.loader = ext.loader;
l.third_party = true;
l.moduleDir = ext.dir;
l.type = ext.type;
languages.push(l);
}
}
Expand Down

0 comments on commit 13b4ea1

Please sign in to comment.