@@ -49,10 +49,10 @@ function init() {
49
49
return compile ( code , options )
50
50
} ,
51
51
from ( entry ) {
52
- const { cache, cachePath } = entry . package
52
+ const pkg = entry . package
53
+ const { cache } = pkg
53
54
const { cacheName } = entry
54
- const { map } = cache
55
- const meta = map [ cacheName ]
55
+ const meta = cache . meta . get ( cacheName )
56
56
57
57
if ( meta === void 0 ) {
58
58
return null
@@ -88,7 +88,7 @@ function init() {
88
88
let filename = meta [ 6 ]
89
89
90
90
if ( filename ) {
91
- filename = resolve ( cachePath , filename )
91
+ filename = resolve ( pkg . cachePath , filename )
92
92
}
93
93
94
94
result . filename = filename
@@ -113,7 +113,7 @@ function init() {
113
113
}
114
114
115
115
entry . compileData = result
116
- cache . compile [ cacheName ] = result
116
+ cache . compile . set ( cacheName , result )
117
117
118
118
return result
119
119
}
@@ -143,11 +143,15 @@ function init() {
143
143
144
144
const { pendingWrites } = shared
145
145
146
- if ( ! Reflect . has ( pendingWrites , cachePath ) ) {
147
- pendingWrites [ cachePath ] = { __proto__ : null }
146
+ let compileDatas = pendingWrites . get ( cachePath )
147
+
148
+ if ( compileDatas === void 0 ) {
149
+ compileDatas = new Map
150
+ pendingWrites . set ( cachePath , compileDatas )
148
151
}
149
152
150
- pendingWrites [ cachePath ] [ cacheName ] = result
153
+ compileDatas . set ( cacheName , result )
154
+
151
155
return result
152
156
}
153
157
@@ -157,12 +161,11 @@ function init() {
157
161
const { pendingScripts, pendingWrites } = shared
158
162
const { dir } = shared . package
159
163
160
- for ( const cachePath in dir ) {
164
+ dir . forEach ( ( cache , cachePath ) => {
161
165
if ( cachePath === "" ) {
162
- continue
166
+ return
163
167
}
164
168
165
- const cache = dir [ cachePath ]
166
169
const noCacheDir = ! mkdirp ( cachePath )
167
170
168
171
let { dirty } = cache
@@ -179,39 +182,37 @@ function init() {
179
182
180
183
if ( dirty ||
181
184
noCacheDir ) {
182
- Reflect . deleteProperty ( dir , cachePath )
183
- Reflect . deleteProperty ( pendingScripts , cachePath )
184
- Reflect . deleteProperty ( pendingWrites , cachePath )
185
+ dir . delete ( cachePath )
186
+ pendingScripts . delete ( cachePath )
187
+ pendingWrites . delete ( cachePath )
185
188
}
186
189
187
190
if ( noCacheDir ) {
188
- continue
191
+ return
189
192
}
190
193
191
194
if ( dirty ) {
192
195
writeMarker ( cachePath + sep + ".dirty" )
193
196
removeFile ( cachePath + sep + ".data.blob" )
194
197
removeFile ( cachePath + sep + ".data.json" )
195
198
196
- for ( const cacheName in cache . compile ) {
199
+ cache . compile . forEach ( ( compileData , cacheName ) => {
197
200
removeFile ( cachePath + sep + cacheName )
198
- }
201
+ } )
199
202
}
200
- }
203
+ } )
201
204
202
- const pendingScriptDatas = { __proto__ : null }
205
+ const pendingScriptDatas = new Map
203
206
const useCreateCachedData = shared . support . createCachedData
204
207
205
- for ( const cachePath in pendingScripts ) {
206
- const cache = dir [ cachePath ]
208
+ pendingScripts . forEach ( ( scripts , cachePath ) => {
209
+ const cache = dir . get ( cachePath )
207
210
const compileDatas = cache . compile
208
- const { map } = cache
209
- const scripts = pendingScripts [ cachePath ]
211
+ const metas = cache . meta
210
212
211
- for ( const cacheName in scripts ) {
212
- const compileData = compileDatas [ cacheName ]
213
- const cachedData = compileData ? compileData . scriptData : null
214
- const script = scripts [ cacheName ]
213
+ scripts . forEach ( ( script , cacheName ) => {
214
+ const compileData = compileDatas . get ( cacheName )
215
+ const cachedData = compileData != null ? compileData . scriptData : null
215
216
216
217
let scriptData
217
218
let changed = false
@@ -234,7 +235,7 @@ function init() {
234
235
script . cachedDataRejected ) {
235
236
changed = true
236
237
237
- const meta = map [ cacheName ]
238
+ const meta = metas . get ( cacheName )
238
239
239
240
if ( meta !== void 0 ) {
240
241
meta [ 0 ] = - 1
@@ -248,33 +249,35 @@ function init() {
248
249
249
250
if ( changed &&
250
251
cacheName !== "" ) {
251
- if ( ! Reflect . has ( pendingScriptDatas , cachePath ) ) {
252
- pendingScriptDatas [ cachePath ] = { __proto__ : null }
252
+ let scriptDatas = pendingScriptDatas . get ( cachePath )
253
+
254
+ if ( scriptDatas === void 0 ) {
255
+ scriptDatas = new Map
256
+ pendingScriptDatas . set ( cachePath , scriptDatas )
253
257
}
254
258
255
- pendingScriptDatas [ cachePath ] [ cacheName ] = scriptData
259
+ scriptDatas . set ( cacheName , scriptData )
256
260
}
257
- }
258
- }
261
+ } )
262
+ } )
259
263
260
- for ( const cachePath in pendingScriptDatas ) {
261
- const cache = dir [ cachePath ]
262
- const { buffer, map } = cache
264
+ pendingScriptDatas . forEach ( ( scriptDatas , cachePath ) => {
265
+ const cache = dir . get ( cachePath )
263
266
const compileDatas = cache . compile
264
- const scriptDatas = pendingScriptDatas [ cachePath ]
267
+ const metas = cache . meta
265
268
266
- for ( const cacheName in scriptDatas ) {
267
- let meta = map [ cacheName ]
269
+ scriptDatas . forEach ( ( scriptData , cacheName ) => {
270
+ let meta = metas . get ( cacheName )
268
271
269
272
if ( meta !== void 0 ) {
270
- continue
273
+ return
271
274
}
272
275
273
276
meta = [ - 1 , - 1 ]
274
277
275
- const compileData = compileDatas [ cacheName ]
278
+ const compileData = compileDatas . get ( cacheName )
276
279
277
- if ( compileData ) {
280
+ if ( compileData != null ) {
278
281
const {
279
282
filename,
280
283
firstAwaitOutsideFunction,
@@ -315,27 +318,23 @@ function init() {
315
318
}
316
319
}
317
320
318
- map [ cacheName ] = meta
319
- }
321
+ metas . set ( cacheName , meta )
322
+ } )
320
323
324
+ const { buffer } = cache
321
325
const buffers = [ ]
326
+ const jsonMeta = { }
322
327
323
328
let offset = 0
324
329
325
- for ( const cacheName in map ) {
326
- const meta = map [ cacheName ]
327
-
328
- if ( meta === void 0 ) {
329
- continue
330
- }
331
-
332
- const compileData = compileDatas [ cacheName ]
333
- const [ offsetStart , offsetEnd ] = meta
334
-
335
- let scriptData = scriptDatas [ cacheName ]
330
+ metas . forEach ( ( meta , cacheName ) => {
331
+ let scriptData = scriptDatas . get ( cacheName )
336
332
337
333
if ( scriptData === void 0 ) {
338
- if ( compileData ) {
334
+ const compileData = compileDatas . get ( cacheName )
335
+ const [ offsetStart , offsetEnd ] = meta
336
+
337
+ if ( compileData != null ) {
339
338
scriptData = compileData . scriptData
340
339
} else if ( offsetStart !== - 1 &&
341
340
offsetEnd !== - 1 ) {
@@ -348,40 +347,40 @@ function init() {
348
347
meta [ 1 ] = offset += scriptData . length
349
348
buffers . push ( scriptData )
350
349
}
351
- }
350
+
351
+ jsonMeta [ cacheName ] = meta
352
+ } )
352
353
353
354
writeFile ( cachePath + sep + ".data.blob" , GenericBuffer . concat ( buffers ) )
354
355
writeFile ( cachePath + sep + ".data.json" , JSON . stringify ( {
355
- map ,
356
+ meta : jsonMeta ,
356
357
version : PACKAGE_VERSION
357
358
} ) )
358
- }
359
-
360
- for ( const cachePath in pendingWrites ) {
361
- const contents = pendingWrites [ cachePath ]
362
-
363
- for ( const cacheName in contents ) {
364
- const { code } = contents [ cacheName ]
359
+ } )
365
360
361
+ pendingWrites . forEach ( ( compileDatas , cachePath ) => {
362
+ compileDatas . forEach ( ( { code } , cacheName ) => {
366
363
if ( writeFile ( cachePath + sep + cacheName , code ) ) {
367
364
removeExpired ( cachePath , cacheName )
368
365
}
369
- }
370
- }
366
+ } )
367
+ } )
371
368
}
372
369
373
370
function removeExpired ( cachePath , cacheName ) {
374
- const cache = shared . package . dir [ cachePath ]
371
+ const cache = shared . package . dir . get ( cachePath )
372
+ const compileDatas = cache . compile
373
+ const metas = cache . meta
375
374
const pathHash = getCachePathHash ( cacheName )
376
375
377
- for ( const otherCacheName in cache ) {
376
+ compileDatas . forEach ( ( compileData , otherCacheName ) => {
378
377
if ( otherCacheName !== cacheName &&
379
378
otherCacheName . startsWith ( pathHash ) ) {
380
- Reflect . deleteProperty ( cache . compile , otherCacheName )
381
- Reflect . deleteProperty ( cache . map , otherCacheName )
379
+ compileDatas . delete ( otherCacheName )
380
+ metas . delete ( otherCacheName )
382
381
removeFile ( cachePath + sep + otherCacheName )
383
382
}
384
- }
383
+ } )
385
384
}
386
385
387
386
function toCompileOptions ( options = { } ) {
0 commit comments