1- const fs = require ( "fs" )
2- const fsProm = require ( "fs" ) . promises
3- const glob = require ( "glob-promise" )
4- const path = require ( "path" )
1+ const fs = require ( "fs" ) ;
2+ const fsProm = require ( "fs" ) . promises ;
3+ const glob = require ( "glob-promise" ) ;
4+ const path = require ( "path" ) ;
55
66const MODULE_DEFINER = / m o d u l e \. e x p o r t s \. d e f i n e r \s * = / ;
77
@@ -12,11 +12,11 @@ class LanguagePackage {
1212
1313 // check for language modules in /src/languages
1414 async trySrcLanguages ( ) {
15- let dir = path . join ( this . dir , "src/languages/*" ) ;
16- let languages = await glob ( dir ) ;
15+ const dir = path . join ( this . dir , "src/languages/*" ) ;
16+ const languages = await glob ( dir ) ;
1717 if ( languages . length > 0 ) {
1818 this . files = languages . map ( fn => `./${ fn } ` ) ;
19- this . names = this . files . map ( fn => path . basename ( fn , ".js" ) ) ;
19+ this . names = this . files . map ( fn => path . basename ( fn , ".js" ) ) ;
2020 this . _bundle = true ;
2121 this . _valid = true ;
2222 return true ;
@@ -41,14 +41,14 @@ class LanguagePackage {
4141
4242 // try to find a language module by probing package.json
4343 async tryPackageJSON ( ) {
44- let pack = path . join ( this . dir , "package.json" ) ;
44+ const pack = path . join ( this . dir , "package.json" ) ;
4545 if ( fs . existsSync ( pack ) ) {
46- let data = await fsProm . readFile ( pack ) ;
47- let json = JSON . parse ( data ) ;
46+ const data = await fsProm . readFile ( pack ) ;
47+ const json = JSON . parse ( data ) ;
4848 if ( json . main ) {
4949 this . type = "npm" ;
50- let file = path . join ( process . cwd ( ) , this . dir , json . main ) ;
51- let content = await fsProm . readFile ( file , { encoding : "utf8" } ) ;
50+ const file = path . join ( process . cwd ( ) , this . dir , json . main ) ;
51+ const content = await fsProm . readFile ( file , { encoding : "utf8" } ) ;
5252 // many existing languages seem to export a `definer` function rather than
5353 // simply export the language module directly. This checks for that and if
5454 // so allows those existing modules to work "as is" by allowing the build
@@ -58,7 +58,7 @@ class LanguagePackage {
5858 this . loader = "definer" ;
5959 }
6060 this . files = [ file ] ;
61- this . names = [ path . basename ( file , ".js" ) ] ;
61+ this . names = [ path . basename ( file , ".js" ) ] ;
6262 this . _valid = true ;
6363 return true ;
6464 }
@@ -71,17 +71,17 @@ class LanguagePackage {
7171 // any bundle with files in ROOT/src/languages/ will be considered a potential
7272 // multi language bundle and any files in that directy will be considered to be
7373 // language modules
74- await this . trySrcLanguages ( ) ||
74+ await this . trySrcLanguages ( )
7575 // otherwise we fall back to looking for a package.json and whatever it's
7676 // `main` entry point is that is the file we assume the language module is
7777 // defined in
78- await this . tryPackageJSON ( ) ;
78+ || await this . tryPackageJSON ( ) ;
7979 this . _detected = true ;
8080 }
8181
8282 async valid ( ) {
8383 if ( ! this . _detected ) {
84- await this . detect ( )
84+ await this . detect ( ) ;
8585 }
8686 return this . _valid ;
8787 }
@@ -90,16 +90,16 @@ class LanguagePackage {
9090// third party language modules are dropped into the `highlight-js/extra`
9191// folder and will be auto-detected by the build system
9292async function getThirdPartyPackages ( ) {
93- let packages = [ ] ;
94- let otherPackages = await glob ( "./extra/*" ) ;
95- for ( let packageDir of otherPackages ) {
96- let thirdPartyPackage = new LanguagePackage ( packageDir )
97- let valid = await thirdPartyPackage . valid ( ) ;
93+ const packages = [ ] ;
94+ const otherPackages = await glob ( "./extra/*" ) ;
95+ for ( const packageDir of otherPackages ) {
96+ const thirdPartyPackage = new LanguagePackage ( packageDir ) ;
97+ const valid = await thirdPartyPackage . valid ( ) ;
9898 if ( valid ) {
99- packages . push ( thirdPartyPackage )
99+ packages . push ( thirdPartyPackage ) ;
100100 }
101101 }
102102 return packages ;
103103}
104104
105- module . exports = { LanguagePackage, getThirdPartyPackages}
105+ module . exports = { LanguagePackage, getThirdPartyPackages } ;
0 commit comments