@@ -133,11 +133,14 @@ export const materializeSource = async (params: MaterializeParams) => {
133133 onlyFiles : true ,
134134 followSymbolicLinks : false ,
135135 } ) ;
136- files . sort ( ( left , right ) =>
137- normalizePath ( left ) . localeCompare ( normalizePath ( right ) ) ,
138- ) ;
136+ const entries = files
137+ . map ( ( relativePath ) => ( {
138+ relativePath,
139+ normalized : normalizePath ( relativePath ) ,
140+ } ) )
141+ . sort ( ( left , right ) => left . normalized . localeCompare ( right . normalized ) ) ;
139142 const targetDirs = new Set < string > ( ) ;
140- for ( const relativePath of files ) {
143+ for ( const { relativePath } of entries ) {
141144 targetDirs . add ( path . dirname ( relativePath ) ) ;
142145 }
143146 await Promise . all (
@@ -149,7 +152,10 @@ export const materializeSource = async (params: MaterializeParams) => {
149152 let fileCount = 0 ;
150153 const concurrency = Math . max (
151154 1 ,
152- Math . min ( files . length , Math . max ( 8 , Math . min ( 128 , os . cpus ( ) . length * 8 ) ) ) ,
155+ Math . min (
156+ entries . length ,
157+ Math . max ( 8 , Math . min ( 128 , os . cpus ( ) . length * 8 ) ) ,
158+ ) ,
153159 ) ;
154160 const manifestPath = path . join ( tempDir , MANIFEST_FILENAME ) ;
155161 const manifestStream = createWriteStream ( manifestPath , {
@@ -177,12 +183,11 @@ export const materializeSource = async (params: MaterializeParams) => {
177183 } ) ;
178184 } ;
179185
180- for ( let i = 0 ; i < files . length ; i += concurrency ) {
181- const batch = files . slice ( i , i + concurrency ) ;
186+ for ( let i = 0 ; i < entries . length ; i += concurrency ) {
187+ const batch = entries . slice ( i , i + concurrency ) ;
182188 const results = await Promise . all (
183- batch . map ( async ( relativePath ) => {
184- const relNormalized = normalizePath ( relativePath ) ;
185- const filePath = path . join ( params . repoDir , relativePath ) ;
189+ batch . map ( async ( entry ) => {
190+ const filePath = path . join ( params . repoDir , entry . relativePath ) ;
186191 const fileHandle = await openFileNoFollow ( filePath ) ;
187192 if ( ! fileHandle ) {
188193 return null ;
@@ -192,7 +197,7 @@ export const materializeSource = async (params: MaterializeParams) => {
192197 if ( ! stats . isFile ( ) ) {
193198 return null ;
194199 }
195- const targetPath = path . join ( tempDir , relativePath ) ;
200+ const targetPath = path . join ( tempDir , entry . relativePath ) ;
196201 ensureSafePath ( tempDir , targetPath ) ;
197202 if ( stats . size >= STREAM_COPY_THRESHOLD_BYTES ) {
198203 const reader = createReadStream ( filePath , {
@@ -206,7 +211,7 @@ export const materializeSource = async (params: MaterializeParams) => {
206211 await writeFile ( targetPath , data ) ;
207212 }
208213 return {
209- path : relNormalized ,
214+ path : entry . normalized ,
210215 size : stats . size ,
211216 } ;
212217 } finally {
0 commit comments