Skip to content

Commit

Permalink
account for optional dependencies in Prism vendor script
Browse files Browse the repository at this point in the history
  • Loading branch information
jpdriver committed May 16, 2022
1 parent dc57edd commit d488c19
Showing 1 changed file with 15 additions and 21 deletions.
36 changes: 15 additions & 21 deletions src/vendor/prism/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,10 @@ codegen`
const { languages } = require('prismjs/components')
const prismPath = dirname(require.resolve('prismjs'))
let output = '/* This content is auto-generated to include some prismjs language components: */\\n'
const toDependencies = arr => {
if (typeof arr === 'string') {
return [arr]
}
// This json defines which languages to include
const includedLangs = require('./includeLangs')
return arr;
};
let output = '/* This content is auto-generated to include some prismjs language components: */\\n'
const addLanguageToOutput = language => {
const pathToLanguage = 'components/prism-' + language
Expand All @@ -39,15 +34,17 @@ codegen`
visitedLanguages[language] = true
}
// Required dependencies come before the actual language
const required = toDependencies(langEntry.require)
if (Array.isArray(required)) {
required.forEach(x => {
if (languages[x]) {
visitLanguage(x, languages[x])
} else {
console.warn('[prismjs/components]: Language', x, 'does not exist!')
// Required + optional dependencies come before the actual language
const dependencies = [].concat(langEntry.require).concat(langEntry.optional).filter(f => f)
if (dependencies.length > 0) {
dependencies.forEach(x => {
if (includedLangs[x]) {
if (languages[x]) {
visitLanguage(x, languages[x])
} else {
console.warn('[prismjs/components]: Language', x, 'does not exist!')
}
}
})
}
Expand All @@ -56,7 +53,7 @@ codegen`
addLanguageToOutput(language)
// Peer dependencies come after the actual language
const peerDependencies = toDependencies(langEntry.peerDependencies)
const peerDependencies = [].concat(langEntry.peerDependencies).filter(f => f)
if (Array.isArray(peerDependencies)) {
peerDependencies.forEach(x => {
Expand All @@ -69,9 +66,6 @@ codegen`
}
};
// This json defines which languages to include
const includedLangs = require('./includeLangs')
Object.keys(includedLangs).forEach(language => {
visitLanguage(language, languages[language])
})
Expand Down

0 comments on commit d488c19

Please sign in to comment.