Skip to content

Commit 1ee00e6

Browse files
gregmagolanalexeagle
authored andcommitted
feat(typescript): add direct_sources field to JSEcmaScriptModuleInfo
Some consumers may only be interested in the javascript sources that are produced directly by the dep and not in the sources produced by transitive deps. This change allows those consumers to select only those sources. BREAKING CHANGES: Helper function `transitive_js_ecma_script_module_info` in `//:providers.bzl` renamed to `js_ecma_script_module_info`. It now returns a JSEcmaScriptModule info with both `sources` and `direct_sources` fields populated.
1 parent f01c3f5 commit 1ee00e6

File tree

3 files changed

+12
-26
lines changed

3 files changed

+12
-26
lines changed

examples/angular/patches/@angular+bazel+9.0.0-next.8.patch

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ index 9b88fbb..68217d0 100755
3232
"ts_providers_dict_to_struct",
3333
"tsc_wrapped_tsconfig",
3434
)
35-
+load("@build_bazel_rules_nodejs//:providers.bzl", "transitive_js_ecma_script_module_info")
35+
+load("@build_bazel_rules_nodejs//:providers.bzl", "js_ecma_script_module_info")
3636

3737
_FLAT_DTS_FILE_SUFFIX = ".bundle.d.ts"
3838
_R3_SYMBOLS_DTS_FILE = "src/r3_symbols.d.ts"
@@ -63,7 +63,7 @@ index 9b88fbb..68217d0 100755
6363
+
6464
+ # Add in new JS providers
6565
+ ts_providers["providers"].extend([
66-
+ transitive_js_ecma_script_module_info(
66+
+ js_ecma_script_module_info(
6767
+ sources = ts_providers["typescript"]["es6_sources"],
6868
+ deps = ctx.attr.deps,
6969
+ ),

packages/typescript/src/internal/build_defs.bzl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
"TypeScript compilation"
1616

17-
load("@build_bazel_rules_nodejs//:providers.bzl", "transitive_js_ecma_script_module_info")
17+
load("@build_bazel_rules_nodejs//:providers.bzl", "js_ecma_script_module_info")
1818
load("@build_bazel_rules_nodejs//internal/common:node_module_info.bzl", "NodeModuleSources", "collect_node_modules_aspect")
1919

2020
# pylint: disable=unused-argument
@@ -275,7 +275,7 @@ def _ts_library_impl(ctx):
275275
# See design doc https://docs.google.com/document/d/1ggkY5RqUkVL4aQLYm7esRW978LgX3GUCnQirrk5E1C0/edit#
276276
# and issue https://github.com/bazelbuild/rules_nodejs/issues/57 for more details.
277277
ts_providers["providers"].extend([
278-
transitive_js_ecma_script_module_info(
278+
js_ecma_script_module_info(
279279
sources = ts_providers["typescript"]["es6_sources"],
280280
deps = ctx.attr.deps,
281281
),

providers.bzl

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -31,36 +31,22 @@ TODO: should we require that?
3131
3232
Historical note: this was the typescript.es6_sources output""",
3333
fields = {
34+
"direct_sources": "depset of direct JavaScript files and sourcemaps",
3435
"sources": "depset of direct and transitive JavaScript files and sourcemaps",
3536
},
3637
)
3738

38-
def transitive_js_ecma_script_module_info(sources, deps = []):
39+
def js_ecma_script_module_info(sources, deps = []):
3940
"""Constructs a JSEcmaScriptModuleInfo including all transitive sources from JSEcmaScriptModuleInfo providers in a list of deps.
4041
4142
Returns a single JSEcmaScriptModuleInfo.
4243
"""
43-
return combine_js_ecma_script_module_info([JSEcmaScriptModuleInfo(sources = sources)] + collect_js_ecma_script_module_infos(deps))
44-
45-
def combine_js_ecma_script_module_info(modules):
46-
"""Combines all JavaScript sources and sourcemaps from a list of JSEcmaScriptModuleInfo providers.
44+
transitive_depsets = [sources]
45+
for dep in deps:
46+
if JSEcmaScriptModuleInfo in dep:
47+
transitive_depsets.append(dep[JSEcmaScriptModuleInfo].sources)
4748

48-
Returns a single JSEcmaScriptModuleInfo.
49-
"""
50-
sources_depsets = []
51-
for module in modules:
52-
sources_depsets.extend([module.sources])
5349
return JSEcmaScriptModuleInfo(
54-
sources = depset(transitive = sources_depsets),
50+
direct_sources = sources,
51+
sources = depset(transitive = transitive_depsets),
5552
)
56-
57-
def collect_js_ecma_script_module_infos(deps):
58-
"""Collects all JSEcmaScriptModuleInfo providers from a list of deps.
59-
60-
Returns a list of JSEcmaScriptModuleInfo providers.
61-
"""
62-
modules = []
63-
for dep in deps:
64-
if JSEcmaScriptModuleInfo in dep:
65-
modules.extend([dep[JSEcmaScriptModuleInfo]])
66-
return modules

0 commit comments

Comments
 (0)