@@ -618,30 +618,30 @@ export async function main(args: string[], runfiles: Runfiles) {
618618 if ( packagePath ) {
619619 // sub-directory node_modules
620620 if ( await exists ( workspaceNodeModules ) ) {
621- let resolvedPackagePath ;
622- if ( await exists ( packagePath ) ) {
623- await symlinkWithUnlink ( workspaceNodeModules , `${ packagePath } /node_modules` ) ;
624- resolvedPackagePath = packagePath ;
625- }
621+ // in some cases packagePath may not exist in sandbox if there are no source deps
622+ // and only generated file deps. we create it so that we that we can link to
623+ // packagePath/node_modules since packagePathBin/node_modules is a symlink to
624+ // packagePath/node_modules and is unguarded in launcher.sh as we allow symlinks to fall
625+ // through to from output tree to source tree to prevent resolving the same npm package to
626+ // multiple locations on disk
627+ await mkdirp ( packagePath ) ;
628+ await symlinkWithUnlink ( workspaceNodeModules , `${ packagePath } /node_modules` ) ;
626629 if ( ! isExecroot ) {
627630 // Under runfiles, we symlink into the package in runfiles as well.
628631 // When inside the sandbox, the execroot location will not exist to symlink to.
629632 const runfilesPackagePath = `${ startCwd } /${ packagePath } ` ;
630633 if ( await exists ( runfilesPackagePath ) ) {
631- if ( resolvedPackagePath ) {
632- await symlinkWithUnlink (
633- `${ resolvedPackagePath } /node_modules` , `${ runfilesPackagePath } /node_modules` ) ;
634- } else {
635- await symlinkWithUnlink ( workspaceNodeModules , `${ runfilesPackagePath } /node_modules` ) ;
636- }
637- resolvedPackagePath = runfilesPackagePath ;
634+ await symlinkWithUnlink (
635+ `${ packagePath } /node_modules` , `${ runfilesPackagePath } /node_modules` ) ;
638636 }
639637 }
640638 const packagePathBin = `${ bin } /${ packagePath } ` ;
641- if ( resolvedPackagePath && await exists ( packagePathBin ) ) {
639+ if ( await exists ( packagePathBin ) ) {
642640 // if bin path exists, symlink bin/package/node_modules -> package/node_modules
643- await symlinkWithUnlink (
644- `${ resolvedPackagePath } /node_modules` , `${ packagePathBin } /node_modules` ) ;
641+ // NB: this location is unguarded in launcher.sh to allow symlinks to fall-throught
642+ // package/node_modules to prevent resolving the same npm package to multiple locations on
643+ // disk
644+ await symlinkWithUnlink ( `${ packagePath } /node_modules` , `${ packagePathBin } /node_modules` ) ;
645645 }
646646 }
647647 } else {
0 commit comments