5
5
// Atom's compile-cache when installing or updating packages, using an older
6
6
// version of node.js
7
7
8
- var path = require ( 'path' ) ;
9
- var fs = require ( 'fs-plus' ) ;
10
- var sourceMapSupport = require ( '@atom/source-map-support' ) ;
8
+ const path = require ( 'path' ) ;
9
+ const fs = require ( 'fs-plus' ) ;
10
+ const sourceMapSupport = require ( '@atom/source-map-support' ) ;
11
11
12
- var PackageTranspilationRegistry = require ( './package-transpilation-registry' ) ;
13
- var CSON = null ;
12
+ const PackageTranspilationRegistry = require ( './package-transpilation-registry' ) ;
13
+ let CSON = null ;
14
14
15
- var packageTranspilationRegistry = new PackageTranspilationRegistry ( ) ;
15
+ const packageTranspilationRegistry = new PackageTranspilationRegistry ( ) ;
16
16
17
- var COMPILERS = {
17
+ const COMPILERS = {
18
18
'.js' : packageTranspilationRegistry . wrapTranspiler ( require ( './babel' ) ) ,
19
19
'.ts' : packageTranspilationRegistry . wrapTranspiler ( require ( './typescript' ) ) ,
20
20
'.tsx' : packageTranspilationRegistry . wrapTranspiler ( require ( './typescript' ) ) ,
@@ -43,11 +43,11 @@ exports.removeTranspilerConfigForPath = function(packagePath) {
43
43
packageTranspilationRegistry . removeTranspilerConfigForPath ( packagePath ) ;
44
44
} ;
45
45
46
- var cacheStats = { } ;
47
- var cacheDirectory = null ;
46
+ const cacheStats = { } ;
47
+ let cacheDirectory = null ;
48
48
49
49
exports . setAtomHomeDirectory = function ( atomHome ) {
50
- var cacheDir = path . join ( atomHome , 'compile-cache' ) ;
50
+ let cacheDir = path . join ( atomHome , 'compile-cache' ) ;
51
51
if (
52
52
process . env . USER === 'root' &&
53
53
process . env . SUDO_USER &&
@@ -68,7 +68,7 @@ exports.getCacheDirectory = function() {
68
68
69
69
exports . addPathToCache = function ( filePath , atomHome ) {
70
70
this . setAtomHomeDirectory ( atomHome ) ;
71
- var extension = path . extname ( filePath ) ;
71
+ const extension = path . extname ( filePath ) ;
72
72
73
73
if ( extension === '.cson' ) {
74
74
if ( ! CSON ) {
@@ -77,7 +77,7 @@ exports.addPathToCache = function(filePath, atomHome) {
77
77
}
78
78
return CSON . readFileSync ( filePath ) ;
79
79
} else {
80
- var compiler = COMPILERS [ extension ] ;
80
+ const compiler = COMPILERS [ extension ] ;
81
81
if ( compiler ) {
82
82
return compileFileAtPath ( compiler , filePath , extension ) ;
83
83
}
@@ -98,10 +98,10 @@ exports.resetCacheStats = function() {
98
98
} ;
99
99
100
100
function compileFileAtPath ( compiler , filePath , extension ) {
101
- var sourceCode = fs . readFileSync ( filePath , 'utf8' ) ;
101
+ const sourceCode = fs . readFileSync ( filePath , 'utf8' ) ;
102
102
if ( compiler . shouldCompile ( sourceCode , filePath ) ) {
103
- var cachePath = compiler . getCachePath ( sourceCode , filePath ) ;
104
- var compiledCode = readCachedJavaScript ( cachePath ) ;
103
+ const cachePath = compiler . getCachePath ( sourceCode , filePath ) ;
104
+ let compiledCode = readCachedJavaScript ( cachePath ) ;
105
105
if ( compiledCode != null ) {
106
106
cacheStats [ extension ] . hits ++ ;
107
107
} else {
@@ -115,7 +115,7 @@ function compileFileAtPath(compiler, filePath, extension) {
115
115
}
116
116
117
117
function readCachedJavaScript ( relativeCachePath ) {
118
- var cachePath = path . join ( cacheDirectory , relativeCachePath ) ;
118
+ const cachePath = path . join ( cacheDirectory , relativeCachePath ) ;
119
119
if ( fs . isFileSync ( cachePath ) ) {
120
120
try {
121
121
return fs . readFileSync ( cachePath , 'utf8' ) ;
@@ -125,11 +125,11 @@ function readCachedJavaScript(relativeCachePath) {
125
125
}
126
126
127
127
function writeCachedJavaScript ( relativeCachePath , code ) {
128
- var cachePath = path . join ( cacheDirectory , relativeCachePath ) ;
128
+ const cachePath = path . join ( cacheDirectory , relativeCachePath ) ;
129
129
fs . writeFileSync ( cachePath , code , 'utf8' ) ;
130
130
}
131
131
132
- var INLINE_SOURCE_MAP_REGEXP = / \/ \/ [ # @ ] \s * s o u r c e M a p p i n g U R L = ( [ ^ ' " \n ] + ) \s * $ / gm;
132
+ const INLINE_SOURCE_MAP_REGEXP = / \/ \/ [ # @ ] \s * s o u r c e M a p p i n g U R L = ( [ ^ ' " \n ] + ) \s * $ / gm;
133
133
134
134
exports . install = function ( resourcesPath , nodeRequire ) {
135
135
const snapshotSourceMapConsumer = {
@@ -166,7 +166,7 @@ exports.install = function(resourcesPath, nodeRequire) {
166
166
return null ;
167
167
}
168
168
169
- var compiler = COMPILERS [ path . extname ( filePath ) ] ;
169
+ let compiler = COMPILERS [ path . extname ( filePath ) ] ;
170
170
if ( ! compiler ) compiler = COMPILERS [ '.js' ] ;
171
171
172
172
try {
@@ -182,7 +182,7 @@ exports.install = function(resourcesPath, nodeRequire) {
182
182
return null ;
183
183
}
184
184
185
- var match , lastMatch ;
185
+ let match , lastMatch ;
186
186
INLINE_SOURCE_MAP_REGEXP . lastIndex = 0 ;
187
187
while ( ( match = INLINE_SOURCE_MAP_REGEXP . exec ( fileData ) ) ) {
188
188
lastMatch = match ;
@@ -191,8 +191,8 @@ exports.install = function(resourcesPath, nodeRequire) {
191
191
return null ;
192
192
}
193
193
194
- var sourceMappingURL = lastMatch [ 1 ] ;
195
- var rawData = sourceMappingURL . slice ( sourceMappingURL . indexOf ( ',' ) + 1 ) ;
194
+ const sourceMappingURL = lastMatch [ 1 ] ;
195
+ const rawData = sourceMappingURL . slice ( sourceMappingURL . indexOf ( ',' ) + 1 ) ;
196
196
197
197
try {
198
198
var sourceMap = JSON . parse ( Buffer . from ( rawData , 'base64' ) ) ;
@@ -208,7 +208,7 @@ exports.install = function(resourcesPath, nodeRequire) {
208
208
}
209
209
} ) ;
210
210
211
- var prepareStackTraceWithSourceMapping = Error . prepareStackTrace ;
211
+ const prepareStackTraceWithSourceMapping = Error . prepareStackTrace ;
212
212
var prepareStackTrace = prepareStackTraceWithSourceMapping ;
213
213
214
214
function prepareStackTraceWithRawStackAssignment ( error , frames ) {
@@ -245,13 +245,13 @@ exports.install = function(resourcesPath, nodeRequire) {
245
245
} ;
246
246
247
247
Object . keys ( COMPILERS ) . forEach ( function ( extension ) {
248
- var compiler = COMPILERS [ extension ] ;
248
+ const compiler = COMPILERS [ extension ] ;
249
249
250
250
Object . defineProperty ( nodeRequire . extensions , extension , {
251
251
enumerable : true ,
252
252
writable : false ,
253
253
value : function ( module , filePath ) {
254
- var code = compileFileAtPath ( compiler , filePath , extension ) ;
254
+ const code = compileFileAtPath ( compiler , filePath , extension ) ;
255
255
return module . _compile ( code , filePath ) ;
256
256
}
257
257
} ) ;
0 commit comments