@@ -105,18 +105,26 @@ def _write_require_patch_script(ctx, node_modules_root):
105
105
is_executable = True ,
106
106
)
107
107
108
- def _write_loader_script (ctx ):
109
- if len (ctx .attr .entry_point .files .to_list ()) != 1 :
110
- fail ("labels in entry_point must contain exactly one file" )
108
+ def _ts_to_js (entry_point_path ):
109
+ """If the entry point specified is a typescript file then set it to .js.
111
110
112
- entry_point_path = _to_manifest_path (ctx , ctx .file .entry_point )
111
+ Workaround for #1974
112
+ ts_library doesn't give labels for its .js outputs so users are forced to give .ts labels
113
113
114
- # If the entry point specified is a typescript file then set the entry
115
- # point to the corresponding .js file
114
+ Args:
115
+ entry_point_path: a file path
116
+ """
116
117
if entry_point_path .endswith (".ts" ):
117
- entry_point_path = entry_point_path [:- 3 ] + ".js"
118
+ return entry_point_path [:- 3 ] + ".js"
118
119
elif entry_point_path .endswith (".tsx" ):
119
- entry_point_path = entry_point_path [:- 4 ] + ".js"
120
+ return entry_point_path [:- 4 ] + ".js"
121
+ return entry_point_path
122
+
123
+ def _write_loader_script (ctx ):
124
+ if len (ctx .attr .entry_point .files .to_list ()) != 1 :
125
+ fail ("labels in entry_point must contain exactly one file" )
126
+
127
+ entry_point_path = _ts_to_js (_to_manifest_path (ctx , ctx .file .entry_point ))
120
128
121
129
ctx .actions .expand_template (
122
130
template = ctx .file ._loader_template ,
269
277
#else:
270
278
# substitutions["TEMPLATED_script_path"] = "$(rlocation \"%s\")" % _to_manifest_path(ctx, ctx.file.entry_point)
271
279
# For now we need to look in both places
272
- substitutions ["TEMPLATED_entry_point_execroot_path" ] = "\" %s\" " % _to_execroot_path (ctx , ctx .file .entry_point )
273
- substitutions ["TEMPLATED_entry_point_manifest_path" ] = "$(rlocation \" %s\" )" % _to_manifest_path (ctx , ctx .file .entry_point )
280
+ substitutions ["TEMPLATED_entry_point_execroot_path" ] = "\" %s\" " % _ts_to_js ( _to_execroot_path (ctx , ctx .file .entry_point ) )
281
+ substitutions ["TEMPLATED_entry_point_manifest_path" ] = "$(rlocation \" %s\" )" % _ts_to_js ( _to_manifest_path (ctx , ctx .file .entry_point ) )
274
282
275
283
ctx .actions .expand_template (
276
284
template = ctx .file ._launcher_template ,
0 commit comments