@@ -25,6 +25,7 @@ load("//internal/common:expand_into_runfiles.bzl", "expand_location_into_runfile
2525load ("//internal/common:module_mappings.bzl" , "module_mappings_runtime_aspect" )
2626load ("//internal/common:path_utils.bzl" , "strip_external" )
2727load ("//internal/common:windows_utils.bzl" , "create_windows_native_launcher_script" , "is_windows" )
28+ load ("//internal/linker:link_node_modules.bzl" , "write_node_modules_manifest" )
2829load ("//internal/node:node_repositories.bzl" , "BUILT_IN_NODE_PLATFORMS" )
2930
3031def _trim_package_node_modules (package_name ):
@@ -132,18 +133,15 @@ def _to_manifest_path(ctx, file):
132133def _to_execroot_path (ctx , file ):
133134 parts = file .path .split ("/" )
134135
135- #print("_to_execroot", file.path, file.is_source)
136136 if parts [0 ] == "external" :
137137 if parts [2 ] == "node_modules" :
138138 # external/npm/node_modules -> node_modules/foo
139139 # the linker will make sure we can resolve node_modules from npm
140140 return "/" .join (parts [2 :])
141- if file .is_source :
142- return file .path
143-
144- return ("<ERROR> _to_execroot_path not yet implemented for " + file .path )
141+ return file .path
145142
146143def _nodejs_binary_impl (ctx ):
144+ node_modules_manifest = write_node_modules_manifest (ctx )
147145 node_modules = depset (ctx .files .node_modules )
148146
149147 # Also include files from npm fine grained deps as inputs.
@@ -155,14 +153,15 @@ def _nodejs_binary_impl(ctx):
155153 # Using a depset will allow us to avoid flattening files and sources
156154 # inside this loop. This should reduce the performances hits,
157155 # since we don't need to call .to_list()
158- sources = depset ()
156+ sources_sets = []
159157
160158 for d in ctx .attr .data :
161159 # TODO: switch to JSModuleInfo when it is available
162160 if JSNamedModuleInfo in d :
163- sources = depset ( transitive = [ sources , d [JSNamedModuleInfo ].sources ] )
161+ sources_sets . append ( d [JSNamedModuleInfo ].sources )
164162 if hasattr (d , "files" ):
165- sources = depset (transitive = [sources , d .files ])
163+ sources_sets .append (d .files )
164+ sources = depset (transitive = sources_sets )
166165
167166 _write_loader_script (ctx )
168167
@@ -198,6 +197,7 @@ def _nodejs_binary_impl(ctx):
198197
199198 node_tool_files .append (ctx .file ._link_modules_script )
200199 node_tool_files .append (ctx .file ._bazel_require_script )
200+ node_tool_files .append (node_modules_manifest )
201201
202202 if not ctx .outputs .templated_args_file :
203203 templated_args = ctx .attr .templated_args
@@ -236,6 +236,7 @@ def _nodejs_binary_impl(ctx):
236236 "TEMPLATED_expected_exit_code" : str (expected_exit_code ),
237237 "TEMPLATED_link_modules_script" : _to_manifest_path (ctx , ctx .file ._link_modules_script ),
238238 "TEMPLATED_loader_path" : script_path ,
239+ "TEMPLATED_modules_manifest" : _to_manifest_path (ctx , node_modules_manifest ),
239240 "TEMPLATED_repository_args" : _to_manifest_path (ctx , ctx .file ._repository_args ),
240241 "TEMPLATED_script_path" : _to_execroot_path (ctx , ctx .file .entry_point ),
241242 "TEMPLATED_vendored_node" : "" if is_builtin else strip_external (ctx .file ._node .path ),
0 commit comments