@@ -272,22 +272,25 @@ function createTar(dir: string, onError: (error: any) => void): NodeJS.ReadableS
272272 const dirSegments = resolve ( dir ) . split ( sep ) ;
273273 const parentDir = dirSegments . slice ( 0 , dirSegments . length - 1 ) . join ( sep ) ;
274274 const entryToAdd = dirSegments [ dirSegments . length - 1 ] ;
275- const packer = new Pack ( { cwd : parentDir , filter : addDirectoryExecutablePermission } ) ;
275+ const packer = new Pack ( { cwd : parentDir , filter : tarFilter } ) ;
276276 packer . on ( "error" , onError ) ;
277277 const stream = packer . add ( entryToAdd ) ;
278278 packer . end ( ) ;
279279 // Shady, but minipass is compatible enough with ReadableStream for this use.
280280 return stream as unknown as NodeJS . ReadableStream ;
281281}
282282
283- /**
284- * Work around a bug where directories bundled on Windows do not have executable permission when extracted on Linux.
285- * https://github.com/npm/node-tar/issues/7#issuecomment-17572926
286- */
287- function addDirectoryExecutablePermission ( _ : string , stat : ReadEntry | fs . Stats ) : boolean {
283+ const nodeModulesPattern = / (?: ^ | [ \\ / ] ) n o d e _ m o d u l e s (?: [ \\ / ] | $ ) / ;
284+
285+ function tarFilter ( path : string , stat : ReadEntry | fs . Stats ) : boolean {
288286 if ( stat instanceof ReadEntry ) {
289287 return true ; // never happens?
290288 }
289+ if ( nodeModulesPattern . test ( path ) ) {
290+ return false ;
291+ }
292+ // Work around a bug where directories bundled on Windows do not have executable permission when extracted on Linux.
293+ // https://github.com/npm/node-tar/issues/7#issuecomment-17572926
291294 if ( stat . isDirectory ( ) ) {
292295 stat . mode = addExecutePermissionsFromReadPermissions ( stat . mode ) ;
293296 }
0 commit comments