diff --git a/src/vendor/prism/index.js b/src/vendor/prism/index.js index ea65dbc..d971398 100755 --- a/src/vendor/prism/index.js +++ b/src/vendor/prism/index.js @@ -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 @@ -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!') + } } }) } @@ -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 => { @@ -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]) })