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" ) ;
5
5
6
6
const MODULE_DEFINER = / m o d u l e \. e x p o r t s \. d e f i n e r \s * = / ;
7
7
@@ -12,11 +12,11 @@ class LanguagePackage {
12
12
13
13
// check for language modules in /src/languages
14
14
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 ) ;
17
17
if ( languages . length > 0 ) {
18
18
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" ) ) ;
20
20
this . _bundle = true ;
21
21
this . _valid = true ;
22
22
return true ;
@@ -41,14 +41,14 @@ class LanguagePackage {
41
41
42
42
// try to find a language module by probing package.json
43
43
async tryPackageJSON ( ) {
44
- let pack = path . join ( this . dir , "package.json" ) ;
44
+ const pack = path . join ( this . dir , "package.json" ) ;
45
45
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 ) ;
48
48
if ( json . main ) {
49
49
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" } ) ;
52
52
// many existing languages seem to export a `definer` function rather than
53
53
// simply export the language module directly. This checks for that and if
54
54
// so allows those existing modules to work "as is" by allowing the build
@@ -58,7 +58,7 @@ class LanguagePackage {
58
58
this . loader = "definer" ;
59
59
}
60
60
this . files = [ file ] ;
61
- this . names = [ path . basename ( file , ".js" ) ] ;
61
+ this . names = [ path . basename ( file , ".js" ) ] ;
62
62
this . _valid = true ;
63
63
return true ;
64
64
}
@@ -71,17 +71,17 @@ class LanguagePackage {
71
71
// any bundle with files in ROOT/src/languages/ will be considered a potential
72
72
// multi language bundle and any files in that directy will be considered to be
73
73
// language modules
74
- await this . trySrcLanguages ( ) ||
74
+ await this . trySrcLanguages ( )
75
75
// otherwise we fall back to looking for a package.json and whatever it's
76
76
// `main` entry point is that is the file we assume the language module is
77
77
// defined in
78
- await this . tryPackageJSON ( ) ;
78
+ || await this . tryPackageJSON ( ) ;
79
79
this . _detected = true ;
80
80
}
81
81
82
82
async valid ( ) {
83
83
if ( ! this . _detected ) {
84
- await this . detect ( )
84
+ await this . detect ( ) ;
85
85
}
86
86
return this . _valid ;
87
87
}
@@ -90,16 +90,16 @@ class LanguagePackage {
90
90
// third party language modules are dropped into the `highlight-js/extra`
91
91
// folder and will be auto-detected by the build system
92
92
async 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 ( ) ;
98
98
if ( valid ) {
99
- packages . push ( thirdPartyPackage )
99
+ packages . push ( thirdPartyPackage ) ;
100
100
}
101
101
}
102
102
return packages ;
103
103
}
104
104
105
- module . exports = { LanguagePackage, getThirdPartyPackages}
105
+ module . exports = { LanguagePackage, getThirdPartyPackages } ;
0 commit comments