@@ -20,7 +20,7 @@ They support module mapping: any targets in the transitive dependencies with
20
20
a `module_name` attribute can be `require`d by that name.
21
21
"""
22
22
23
- load ("//:providers.bzl" , "ExternalNpmPackageInfo" , "JSModuleInfo" , "JSNamedModuleInfo" , "NodeRuntimeDepsInfo" , "node_modules_aspect" )
23
+ load ("//:providers.bzl" , "DirectoryFilePathInfo" , " ExternalNpmPackageInfo" , "JSModuleInfo" , "JSNamedModuleInfo" , "NodeRuntimeDepsInfo" , "node_modules_aspect" )
24
24
load ("//internal/common:expand_into_runfiles.bzl" , "expand_location_into_runfiles" )
25
25
load ("//internal/common:module_mappings.bzl" , "module_mappings_runtime_aspect" )
26
26
load ("//internal/common:path_utils.bzl" , "strip_external" )
@@ -106,11 +106,17 @@ def _ts_to_js(entry_point_path):
106
106
return entry_point_path [:- 4 ] + ".js"
107
107
return entry_point_path
108
108
109
- def _write_loader_script (ctx ):
110
- if len (ctx .attr .entry_point .files .to_list ()) != 1 :
109
+ def _get_entry_point_file (ctx ):
110
+ if len (ctx .attr .entry_point .files .to_list ()) > 1 :
111
111
fail ("labels in entry_point must contain exactly one file" )
112
+ if len (ctx .files .entry_point ) == 1 :
113
+ return ctx .files .entry_point [0 ]
114
+ if DirectoryFilePathInfo in ctx .attr .entry_point :
115
+ return ctx .attr .entry_point [DirectoryFilePathInfo ].directory
116
+ fail ("entry_point must either be a file, or provide DirectoryFilePathInfo" )
112
117
113
- entry_point_path = _ts_to_js (_to_manifest_path (ctx , ctx .file .entry_point ))
118
+ def _write_loader_script (ctx ):
119
+ entry_point_path = _ts_to_js (_to_manifest_path (ctx , _get_entry_point_file (ctx )))
114
120
115
121
ctx .actions .expand_template (
116
122
template = ctx .file ._loader_template ,
310
316
#else:
311
317
# substitutions["TEMPLATED_script_path"] = "$(rlocation \"%s\")" % _to_manifest_path(ctx, ctx.file.entry_point)
312
318
# For now we need to look in both places
313
- substitutions ["TEMPLATED_entry_point_execroot_path" ] = "\" %s\" " % _ts_to_js (_to_execroot_path (ctx , ctx .file .entry_point ))
314
- substitutions ["TEMPLATED_entry_point_manifest_path" ] = "$(rlocation \" %s\" )" % _ts_to_js (_to_manifest_path (ctx , ctx .file .entry_point ))
319
+ substitutions ["TEMPLATED_entry_point_execroot_path" ] = "\" %s\" " % _ts_to_js (_to_execroot_path (ctx , _get_entry_point_file (ctx )))
320
+ substitutions ["TEMPLATED_entry_point_manifest_path" ] = "$(rlocation \" %s\" )" % _ts_to_js (_to_manifest_path (ctx , _get_entry_point_file (ctx )))
321
+ if DirectoryFilePathInfo in ctx .attr .entry_point :
322
+ substitutions ["TEMPLATED_entry_point_main" ] = ctx .attr .entry_point [DirectoryFilePathInfo ].path
323
+ else :
324
+ substitutions ["TEMPLATED_entry_point_main" ] = ""
315
325
316
326
ctx .actions .expand_template (
317
327
template = ctx .file ._launcher_template ,
326
336
else :
327
337
executable = ctx .outputs .launcher_sh
328
338
339
+ # syntax sugar: allows you to avoid repeating the entry point in data
329
340
# entry point is only needed in runfiles if it is a .js file
330
- if ctx .file .entry_point .extension == "js" :
331
- runfiles .append (ctx .file .entry_point )
341
+ if len ( ctx .files .entry_point ) == 1 and ctx . files . entry_point [ 0 ] .extension == "js" :
342
+ runfiles .extend (ctx .files .entry_point )
332
343
333
344
return [
334
345
DefaultInfo (
351
362
# TODO(alexeagle): remove sources and node_modules from the runfiles
352
363
# when downstream usage is ready to rely on linker
353
364
NodeRuntimeDepsInfo (
354
- deps = depset ([ ctx .file .entry_point ] , transitive = [node_modules , sources ]),
365
+ deps = depset (ctx .files .entry_point , transitive = [node_modules , sources ]),
355
366
pkgs = ctx .attr .data ,
356
367
),
357
368
# indicates that the this binary should be instrumented by coverage
@@ -462,7 +473,7 @@ nodejs_binary(
462
473
```
463
474
""" ,
464
475
mandatory = True ,
465
- allow_single_file = True ,
476
+ allow_files = True ,
466
477
),
467
478
"env" : attr .string_dict (
468
479
doc = """Specifies additional environment variables to set when the target is executed, subject to location
0 commit comments