@@ -276,15 +276,19 @@ function resolveManifestDirectory(res) {
276276
277277function resolveRunfiles ( parent , ...pathSegments ) {
278278 // Remove any empty strings from pathSegments
279- pathSegments = pathSegments . filter ( segment => segment ) ;
279+ // Normalize to forward slash, because even on Windows the runfiles_manifest file
280+ // is written with forward slash.
281+ let runfilesEntry = pathSegments . filter ( segment => segment ) . join ( '/' ) . replace ( / \\ / g, '/' ) ;
282+
283+ // Trim `${USER_WORKSPACE_NAME}/external/` from start of runfilesEntry
284+ const externalWorkspacePrefix = `${ USER_WORKSPACE_NAME } /external/` ;
285+ if ( runfilesEntry . startsWith ( externalWorkspacePrefix ) ) {
286+ runfilesEntry = runfilesEntry . slice ( externalWorkspacePrefix . length ) ;
287+ }
280288
281- const defaultPath = path . join ( process . env . RUNFILES , ... pathSegments ) ;
289+ const runfilesPath = path . join ( process . env . RUNFILES , runfilesEntry ) ;
282290
283291 if ( runfilesManifest ) {
284- // Normalize to forward slash, because even on Windows the runfiles_manifest file
285- // is written with forward slash.
286- let runfilesEntry = pathSegments . join ( '/' ) . replace ( / \\ / g, '/' ) ;
287-
288292 if ( parent && runfilesEntry . startsWith ( '.' ) ) {
289293 // Resolve relative paths from manifest files.
290294 const normalizedParent = parent . replace ( / \\ / g, '/' ) ;
@@ -321,29 +325,28 @@ function resolveRunfiles(parent, ...pathSegments) {
321325 return maybe ;
322326 }
323327 } else {
324- if ( DEBUG ) console . error ( 'node_loader: try to resolve in runfiles' , defaultPath ) ;
328+ if ( DEBUG ) console . error ( 'node_loader: try to resolve in runfiles' , runfilesPath ) ;
325329
326- let maybe = loadAsFileSync ( defaultPath ) ;
330+ let maybe = loadAsFileSync ( runfilesPath ) ;
327331 if ( maybe ) {
328332 if ( DEBUG ) console . error ( 'node_loader: resolved file' , maybe ) ;
329333 return maybe ;
330334 }
331335
332- maybe = loadAsDirectorySync ( defaultPath ) ;
336+ maybe = loadAsDirectorySync ( runfilesPath ) ;
333337 if ( maybe ) {
334338 if ( DEBUG ) console . error ( 'node_loader: resolved via directory' , maybe ) ;
335339 return maybe ;
336340 }
337341 }
338342
339- return defaultPath ;
343+ return runfilesPath ;
340344}
341345
342346var originalResolveFilename = module . constructor . _resolveFilename ;
343347module . constructor . _resolveFilename = function ( request , parent , isMain , options ) {
344348 const parentFilename = ( parent && parent . filename ) ? parent . filename : undefined ;
345- if ( DEBUG )
346- console . error ( `node_loader: resolve ${ request } from ${ parentFilename } ` ) ;
349+ if ( DEBUG ) console . error ( `\n\nnode_loader: resolve ${ request } from ${ parentFilename } ` ) ;
347350
348351 const failedResolutions = [ ] ;
349352
0 commit comments