Skip to content

Commit 8cc044f

Browse files
Alex Eaglealexeagle
authored andcommitted
fix(builtin): perform the ts-to-js entry_point rewrite
This was happening when the loader.js script is used (when --bazel_patch_module_resolver is on) but was not happening otherwise.
1 parent 355bb01 commit 8cc044f

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

internal/node/node.bzl

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -105,18 +105,26 @@ def _write_require_patch_script(ctx, node_modules_root):
105105
is_executable = True,
106106
)
107107

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.
111110
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
113113
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+
"""
116117
if entry_point_path.endswith(".ts"):
117-
entry_point_path = entry_point_path[:-3] + ".js"
118+
return entry_point_path[:-3] + ".js"
118119
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))
120128

121129
ctx.actions.expand_template(
122130
template = ctx.file._loader_template,
@@ -269,8 +277,8 @@ fi
269277
#else:
270278
# substitutions["TEMPLATED_script_path"] = "$(rlocation \"%s\")" % _to_manifest_path(ctx, ctx.file.entry_point)
271279
# 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))
274282

275283
ctx.actions.expand_template(
276284
template = ctx.file._launcher_template,

0 commit comments

Comments
 (0)