Skip to content

Commit 8cec4b3

Browse files
alexeaglemhevery
authored andcommitted
build: make api-extractor work in google3 (angular#28588)
PR Close angular#28588
1 parent 9e5d135 commit 8cec4b3

2 files changed

Lines changed: 14 additions & 12 deletions

File tree

.github/angular-robot.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ merge:
4141
exclude:
4242
- "packages/*"
4343
- "packages/bazel/*"
44+
- "packages/bazel/src/api-extractor/**"
4445
- "packages/bazel/src/builders/**"
4546
- "packages/bazel/src/ng_package/**"
4647
- "packages/bazel/src/protractor/**"

packages/bazel/src/ng_module.bzl

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@ load(
1212
"DEFAULT_NG_COMPILER",
1313
"DEFAULT_NG_XI18N",
1414
"DEPS_ASPECTS",
15-
"FLAT_DTS_FILE_SUFFIX",
1615
"NodeModuleInfo",
1716
"collect_node_modules_aspect",
1817
"compile_ts",
1918
"ts_providers_dict_to_struct",
2019
"tsc_wrapped_tsconfig",
2120
)
2221

22+
_FLAT_DTS_FILE_SUFFIX = ".bundle.d.ts"
23+
2324
def compile_strategy(ctx):
2425
"""Detect which strategy should be used to implement ng_module.
2526
@@ -138,7 +139,7 @@ def _should_produce_dts_bundle(ctx):
138139
# At the moment we cannot use this with ngtsc compiler since it emits
139140
# import * as ___ from local modules which is not supported
140141
# see: https://github.com/Microsoft/web-build-tools/issues/1029
141-
return _is_legacy_ngc(ctx) and ctx.attr.bundle_dts
142+
return _is_legacy_ngc(ctx) and hasattr(ctx.attr, "bundle_dts") and ctx.attr.bundle_dts
142143

143144
def _should_produce_flat_module_outs(ctx):
144145
"""Should we produce flat module outputs.
@@ -225,7 +226,7 @@ def _expected_outs(ctx):
225226
# The flat module dts out contains several other exports
226227
# https://github.com/angular/angular/blob/master/packages/compiler-cli/src/metadata/index_writer.ts#L18
227228
# the file name will be like 'core.bundle.d.ts'
228-
dts_bundle = ctx.actions.declare_file(ctx.label.name + FLAT_DTS_FILE_SUFFIX)
229+
dts_bundle = ctx.actions.declare_file(ctx.label.name + _FLAT_DTS_FILE_SUFFIX)
229230

230231
# We do this just when producing a flat module index for a publishable ng_module
231232
if _should_produce_flat_module_outs(ctx):
@@ -330,12 +331,12 @@ def ngc_compile_action(
330331
label,
331332
inputs,
332333
outputs,
333-
dts_bundle_out,
334334
messages_out,
335335
tsconfig_file,
336336
node_opts,
337337
locale = None,
338-
i18n_args = []):
338+
i18n_args = [],
339+
dts_bundle_out = None):
339340
"""Helper function to create the ngc action.
340341
341342
This is exposed for google3 to wire up i18n replay rules, and is not intended
@@ -346,12 +347,12 @@ def ngc_compile_action(
346347
label: the label of the ng_module being compiled
347348
inputs: passed to the ngc action's inputs
348349
outputs: passed to the ngc action's outputs
349-
dts_bundle_out: produced flattened dts file
350350
messages_out: produced xmb files
351351
tsconfig_file: tsconfig file with settings used for the compilation
352352
node_opts: list of strings, extra nodejs options.
353353
locale: i18n locale, or None
354354
i18n_args: additional command-line arguments to ngc
355+
dts_bundle_out: produced flattened dts file
355356
356357
Returns:
357358
the parameters of the compilation which will be used to replay the ngc action for i18N.
@@ -479,7 +480,7 @@ def _compile_action(ctx, inputs, outputs, dts_bundle_out, messages_out, tsconfig
479480
],
480481
)
481482

482-
return ngc_compile_action(ctx, ctx.label, action_inputs, outputs, dts_bundle_out, messages_out, tsconfig_file, node_opts)
483+
return ngc_compile_action(ctx, ctx.label, action_inputs, outputs, messages_out, tsconfig_file, node_opts, None, [], dts_bundle_out)
483484

484485
def _prodmode_compile_action(ctx, inputs, outputs, tsconfig_file, node_opts):
485486
outs = _expected_outs(ctx)
@@ -606,11 +607,6 @@ NG_MODULE_ATTRIBUTES = {
606607
executable = True,
607608
cfg = "host",
608609
),
609-
"_api_extractor": attr.label(
610-
default = Label("//packages/bazel/src/api-extractor:api_extractor"),
611-
executable = True,
612-
cfg = "host",
613-
),
614610
"_supports_workers": attr.bool(default = True),
615611
}
616612

@@ -691,6 +687,11 @@ NG_MODULE_RULE_ATTRS = dict(dict(COMMON_ATTRIBUTES, **NG_MODULE_ATTRIBUTES), **{
691687
# https://github.com/angular/angular/blob/master/packages/compiler-cli/src/transformers/api.ts
692688
"flat_module_out_file": attr.string(),
693689
"bundle_dts": attr.bool(default = False),
690+
"_api_extractor": attr.label(
691+
default = Label("//packages/bazel/src/api-extractor:api_extractor"),
692+
executable = True,
693+
cfg = "host",
694+
),
694695
})
695696

696697
ng_module = rule(

0 commit comments

Comments
 (0)