1- import { createBrotliCompress , createGzip } from 'zlib' ;
21import Multistream from 'multistream' ;
32import assert from 'assert' ;
43import { execSync } from 'child_process' ;
@@ -13,7 +12,6 @@ import { log, wasReported } from './log';
1312import { fabricateTwice } from './fabricator' ;
1413import { platform , SymLinks , Target } from './types' ;
1514import { Stripe } from './packer' ;
16- import { CompressType } from './compress_type' ;
1715
1816interface NotFound {
1917 notFound : true ;
@@ -227,7 +225,8 @@ function nativePrebuildInstall(target: Target, nodeFile: string) {
227225 }
228226
229227 execSync (
230- `${ prebuild } -t ${ nodeVersion } --platform ${ platform [ target . platform ]
228+ `${ prebuild } -t ${ nodeVersion } --platform ${
229+ platform [ target . platform ]
231230 } --arch ${ target . arch } `,
232231 { cwd : dir }
233232 ) ;
@@ -243,34 +242,14 @@ interface ProducerOptions {
243242 slash : string ;
244243 target : Target ;
245244 symLinks : SymLinks ;
246- doCompress : CompressType ;
247245}
248246
249- const fileDictionary : { [ key : string ] : string } = { } ;
250- let counter = 0 ;
251- function replace ( k : string ) {
252- let existingKey = fileDictionary [ k ] ;
253- if ( ! existingKey ) {
254- const newkey = counter ;
255- counter += 1 ;
256- existingKey = newkey . toString ( 36 ) ;
257- fileDictionary [ k ] = existingKey ;
258- }
259- return existingKey ;
260- }
261- const separator = '$' ;
262-
263- function makeKey ( filename : string , slash : string ) : string {
264- const a = filename . split ( slash ) . map ( replace ) . join ( separator ) ;
265- return a ;
266- }
267247export default function producer ( {
268248 backpack,
269249 bakes,
270250 slash,
271251 target,
272252 symLinks,
273- doCompress
274253} : ProducerOptions ) {
275254 return new Promise < void > ( ( resolve , reject ) => {
276255 if ( ! Buffer . alloc ) {
@@ -289,17 +268,18 @@ export default function producer({
289268 for ( const stripe of stripes ) {
290269 let { snap } = stripe ;
291270 snap = snapshotify ( snap , slash ) ;
292- const vfsKey = makeKey ( snap , slash ) ;
293- if ( ! vfs [ vfsKey ] ) vfs [ vfsKey ] = { } ;
271+
272+ if ( ! vfs [ snap ] ) {
273+ vfs [ snap ] = { } ;
274+ }
294275 }
295276
296277 const snapshotSymLinks : SymLinks = { } ;
297278
298279 for ( const [ key , value ] of Object . entries ( symLinks ) ) {
299280 const k = snapshotify ( key , slash ) ;
300281 const v = snapshotify ( value , slash ) ;
301- const vfsKey = makeKey ( k , slash ) ;
302- snapshotSymLinks [ vfsKey ] = makeKey ( v , slash ) ;
282+ snapshotSymLinks [ k ] = v ;
303283 }
304284
305285 let meter : streamMeter . StreamMeter ;
@@ -309,15 +289,6 @@ export default function producer({
309289 meter = streamMeter ( ) ;
310290 return s . pipe ( meter ) ;
311291 }
312- function pipeMayCompressToNewMeter ( s : Readable ) : streamMeter . StreamMeter {
313- if ( doCompress === CompressType . GZip ) {
314- return pipeToNewMeter ( s . pipe ( createGzip ( ) ) ) ;
315- }
316- if ( doCompress === CompressType . Brotli ) {
317- return pipeToNewMeter ( s . pipe ( createBrotliCompress ( ) ) ) ;
318- }
319- return pipeToNewMeter ( s ) ;
320- }
321292
322293 function next ( s : Readable ) {
323294 count += 1 ;
@@ -350,8 +321,7 @@ export default function producer({
350321 const { store } = prevStripe ;
351322 let { snap } = prevStripe ;
352323 snap = snapshotify ( snap , slash ) ;
353- const vfsKey = makeKey ( snap , slash ) ;
354- vfs [ vfsKey ] [ store ] = [ track , meter . bytes ] ;
324+ vfs [ snap ] [ store ] = [ track , meter . bytes ] ;
355325 track += meter . bytes ;
356326 }
357327
@@ -377,14 +347,15 @@ export default function producer({
377347 return cb ( null , intoStream ( Buffer . alloc ( 0 ) ) ) ;
378348 }
379349
380- cb ( null , pipeMayCompressToNewMeter ( intoStream ( buffer || Buffer . from ( '' ) ) ) ) ;
350+ cb (
351+ null ,
352+ pipeToNewMeter ( intoStream ( buffer || Buffer . from ( '' ) ) )
353+ ) ;
381354 }
382355 ) ;
383356 }
384- return cb (
385- null ,
386- pipeMayCompressToNewMeter ( intoStream ( stripe . buffer ) )
387- ) ;
357+
358+ return cb ( null , pipeToNewMeter ( intoStream ( stripe . buffer ) ) ) ;
388359 }
389360
390361 if ( stripe . file ) {
@@ -407,17 +378,15 @@ export default function producer({
407378 if ( fs . existsSync ( platformFile ) ) {
408379 return cb (
409380 null ,
410- pipeMayCompressToNewMeter ( fs . createReadStream ( platformFile ) )
381+ pipeToNewMeter ( fs . createReadStream ( platformFile ) )
411382 ) ;
412383 }
413384 } catch ( err ) {
414385 log . debug ( `prebuild-install failed[${ stripe . file } ]:` , err ) ;
415386 }
416387 }
417- return cb (
418- null ,
419- pipeMayCompressToNewMeter ( fs . createReadStream ( stripe . file ) )
420- ) ;
388+
389+ return cb ( null , pipeToNewMeter ( fs . createReadStream ( stripe . file ) ) ) ;
421390 }
422391
423392 assert ( false , 'producer: bad stripe' ) ;
@@ -432,23 +401,15 @@ export default function producer({
432401 replaceDollarWise (
433402 replaceDollarWise (
434403 replaceDollarWise (
435- replaceDollarWise (
436- replaceDollarWise (
437- prelude ,
438- '%VIRTUAL_FILESYSTEM%' ,
439- JSON . stringify ( vfs )
440- ) ,
441- '%DEFAULT_ENTRYPOINT%' ,
442- JSON . stringify ( entrypoint )
443- ) ,
444- '%SYMLINKS%' ,
445- JSON . stringify ( snapshotSymLinks )
404+ prelude ,
405+ '%VIRTUAL_FILESYSTEM%' ,
406+ JSON . stringify ( vfs )
446407 ) ,
447- '%DICT %' ,
448- JSON . stringify ( fileDictionary )
408+ '%DEFAULT_ENTRYPOINT %' ,
409+ JSON . stringify ( entrypoint )
449410 ) ,
450- '%DOCOMPRESS %' ,
451- JSON . stringify ( doCompress )
411+ '%SYMLINKS %' ,
412+ JSON . stringify ( snapshotSymLinks )
452413 )
453414 )
454415 )
0 commit comments