1- import fs from 'fs' ;
1+ import fs from 'fs' ;
2+
3+ import { HAS_LAZY_LOADED_TRANSLATORS } from './loaderFlags' ;
24
35//#region ESM to CJS support
4- /*
6+ if ( ! HAS_LAZY_LOADED_TRANSLATORS ) {
7+ /*
58 In order to import CJS files from ESM Node does some translating
69 internally[1]. This translator calls an unpatched `readFileSync`[2]
710 which itself calls an internal `tryStatSync`[3] which calls
@@ -16,34 +19,33 @@ import fs from 'fs';
1619 5: https://github.com/nodejs/node/pull/39513
1720*/
1821
19- const binding = ( process as any ) . binding ( `fs` ) as {
20- fstat : ( fd : number , useBigint : false , req : any , ctx : object ) => Float64Array ;
21- } ;
22- const originalfstat = binding . fstat ;
22+ const binding = ( process as any ) . binding ( `fs` ) as {
23+ fstat : ( fd : number , useBigint : false , req : any , ctx : object ) => Float64Array ;
24+ } ;
25+ const originalfstat = binding . fstat ;
2326
24- // Those values must be synced with packages/yarnpkg-fslib/sources/ZipOpenFS.ts
25- //
26- const ZIP_MASK = 0xff000000 ;
27- const ZIP_MAGIC = 0x2a000000 ;
27+ // Those values must be synced with packages/yarnpkg-fslib/sources/ZipOpenFS.ts
28+ const ZIP_MASK = 0xff000000 ;
29+ const ZIP_MAGIC = 0x2a000000 ;
2830
29- binding . fstat = function ( ...args ) {
30- const [ fd , useBigint , req ] = args ;
31- if ( ( fd & ZIP_MASK ) === ZIP_MAGIC && useBigint === false && req === undefined ) {
32- try {
33- const stats = fs . fstatSync ( fd ) ;
34- // The reverse of this internal util
35- // https://github.com/nodejs/node/blob/8886b63cf66c29d453fdc1ece2e489dace97ae9d/lib/internal/fs/utils.js#L542-L551
36- return new Float64Array ( [
37- stats . dev ,
38- stats . mode ,
39- stats . nlink ,
40- stats . uid ,
41- stats . gid ,
42- stats . rdev ,
43- stats . blksize ,
44- stats . ino ,
45- stats . size ,
46- stats . blocks ,
31+ binding . fstat = function ( ...args ) {
32+ const [ fd , useBigint , req ] = args ;
33+ if ( ( fd & ZIP_MASK ) === ZIP_MAGIC && useBigint === false && req === undefined ) {
34+ try {
35+ const stats = fs . fstatSync ( fd ) ;
36+ // The reverse of this internal util
37+ // https://github.com/nodejs/node/blob/8886b63cf66c29d453fdc1ece2e489dace97ae9d/lib/internal/fs/utils.js#L542-L551
38+ return new Float64Array ( [
39+ stats . dev ,
40+ stats . mode ,
41+ stats . nlink ,
42+ stats . uid ,
43+ stats . gid ,
44+ stats . rdev ,
45+ stats . blksize ,
46+ stats . ino ,
47+ stats . size ,
48+ stats . blocks ,
4749 // atime sec
4850 // atime ns
4951 // mtime sec
@@ -52,10 +54,11 @@ binding.fstat = function(...args) {
5254 // ctime ns
5355 // birthtime sec
5456 // birthtime ns
55- ] ) ;
56- } catch { }
57- }
57+ ] ) ;
58+ } catch { }
59+ }
5860
59- return originalfstat . apply ( this , args ) ;
60- } ;
61+ return originalfstat . apply ( this , args ) ;
62+ } ;
63+ }
6164//#endregion
0 commit comments