style: reformat bzl files on patch branch to match master

This commit is contained in:
Alex Eagle 2018-09-18 14:43:05 -07:00
parent af785f9e91
commit e7c72ab556
15 changed files with 1253 additions and 1168 deletions

View File

@ -12,11 +12,13 @@ from source downstream. Alternately, this API is available from the
used in a downstream project. used in a downstream project.
""" """
load("//packages/bazel:index.bzl", load(
"//packages/bazel:index.bzl",
_ng_module = "ng_module", _ng_module = "ng_module",
_ng_package = "ng_package", _ng_package = "ng_package",
_protractor_web_test = "protractor_web_test", _protractor_web_test = "protractor_web_test",
_protractor_web_test_suite = "protractor_web_test_suite") _protractor_web_test_suite = "protractor_web_test_suite",
)
load("//tools:ng_setup_workspace.bzl", _ng_setup_workspace = "ng_setup_workspace") load("//tools:ng_setup_workspace.bzl", _ng_setup_workspace = "ng_setup_workspace")
ng_module = _ng_module ng_module = _ng_module

View File

@ -10,9 +10,11 @@ Users should not load files under "/src"
load("//packages/bazel/src:ng_module.bzl", _ng_module = "ng_module") load("//packages/bazel/src:ng_module.bzl", _ng_module = "ng_module")
load("//packages/bazel/src:ng_setup_workspace.bzl", _ng_setup_workspace = "ng_setup_workspace") load("//packages/bazel/src:ng_setup_workspace.bzl", _ng_setup_workspace = "ng_setup_workspace")
load("//packages/bazel/src/ng_package:ng_package.bzl", _ng_package = "ng_package") load("//packages/bazel/src/ng_package:ng_package.bzl", _ng_package = "ng_package")
load("//packages/bazel/src/protractor:protractor_web_test.bzl", load(
"//packages/bazel/src/protractor:protractor_web_test.bzl",
_protractor_web_test = "protractor_web_test", _protractor_web_test = "protractor_web_test",
_protractor_web_test_suite = "protractor_web_test_suite") _protractor_web_test_suite = "protractor_web_test_suite",
)
ng_module = _ng_module ng_module = _ng_module
ng_package = _ng_package ng_package = _ng_package

View File

@ -29,6 +29,7 @@ ESM5Info = provider(
def _map_closure_path(file): def _map_closure_path(file):
result = file.short_path[:-len(".closure.js")] result = file.short_path[:-len(".closure.js")]
# short_path is meant to be used when accessing runfiles in a binary, where # short_path is meant to be used when accessing runfiles in a binary, where
# the CWD is inside the current repo. Therefore files in external repo have a # the CWD is inside the current repo. Therefore files in external repo have a
# short_path of ../external/wkspc/path/to/package # short_path of ../external/wkspc/path/to/package
@ -61,9 +62,11 @@ def _esm5_outputs_aspect(target, ctx):
if workspace: if workspace:
out_dir = out_dir + "/" + workspace out_dir = out_dir + "/" + workspace
outputs = [ctx.actions.declare_file(_join([out_dir, _map_closure_path(f)])) outputs = [
ctx.actions.declare_file(_join([out_dir, _map_closure_path(f)]))
for f in target.typescript.replay_params.outputs for f in target.typescript.replay_params.outputs
if not f.short_path.endswith(".externs.js")] if not f.short_path.endswith(".externs.js")
]
ctx.actions.run( ctx.actions.run(
executable = ctx.executable._modify_tsconfig, executable = ctx.executable._modify_tsconfig,
@ -73,7 +76,7 @@ def _esm5_outputs_aspect(target, ctx):
target.typescript.replay_params.tsconfig.path, target.typescript.replay_params.tsconfig.path,
tsconfig.path, tsconfig.path,
_join([workspace, target.label.package, ctx.label.name + ".esm5"]), _join([workspace, target.label.package, ctx.label.name + ".esm5"]),
ctx.bin_dir.path ctx.bin_dir.path,
], ],
) )
@ -96,7 +99,7 @@ def _esm5_outputs_aspect(target, ctx):
ctx.label.name + ".esm5", ctx.label.name + ".esm5",
]) ])
transitive_output={root_dir: depset(outputs)} transitive_output = {root_dir: depset(outputs)}
for dep in ctx.rule.attr.deps: for dep in ctx.rule.attr.deps:
if ESM5Info in dep: if ESM5Info in dep:
transitive_output.update(dep[ESM5Info].transitive_output) transitive_output.update(dep[ESM5Info].transitive_output)
@ -111,12 +114,13 @@ def _esm5_outputs_aspect(target, ctx):
esm5_outputs_aspect = aspect( esm5_outputs_aspect = aspect(
implementation = _esm5_outputs_aspect, implementation = _esm5_outputs_aspect,
# Recurse to the deps of any target we visit # Recurse to the deps of any target we visit
attr_aspects = ['deps'], attr_aspects = ["deps"],
attrs = { attrs = {
"_modify_tsconfig": attr.label( "_modify_tsconfig": attr.label(
default = Label("//packages/bazel/src:modify_tsconfig"), default = Label("//packages/bazel/src:modify_tsconfig"),
executable = True, executable = True,
cfg = "host"), cfg = "host",
),
# We must list tsc_wrapped here to ensure it's built before the action runs # We must list tsc_wrapped here to ensure it's built before the action runs
# For some reason, having the compiler output as an input to the action above # For some reason, having the compiler output as an input to the action above
# is not sufficient. # is not sufficient.
@ -168,6 +172,7 @@ def flatten_esm5(ctx):
path = "external/" + path[3:] path = "external/" + path[3:]
rerooted_file = ctx.actions.declare_file("/".join([esm5_root_dir(ctx), path])) rerooted_file = ctx.actions.declare_file("/".join([esm5_root_dir(ctx), path]))
result.append(rerooted_file) result.append(rerooted_file)
# print("copy", f.short_path, "to", rerooted_file.short_path) # print("copy", f.short_path, "to", rerooted_file.short_path)
ctx.actions.expand_template( ctx.actions.expand_template(
output = rerooted_file, output = rerooted_file,

View File

@ -5,13 +5,14 @@
"""Implementation of the ng_module rule. """Implementation of the ng_module rule.
""" """
load(":rules_typescript.bzl", load(
"tsc_wrapped_tsconfig", ":rules_typescript.bzl",
"COMMON_ATTRIBUTES", "COMMON_ATTRIBUTES",
"COMMON_OUTPUTS", "COMMON_OUTPUTS",
"compile_ts",
"DEPS_ASPECTS", "DEPS_ASPECTS",
"compile_ts",
"ts_providers_dict_to_struct", "ts_providers_dict_to_struct",
"tsc_wrapped_tsconfig",
) )
def _compile_strategy(ctx): def _compile_strategy(ctx):
@ -28,15 +29,15 @@ def _compile_strategy(ctx):
one of 'legacy', 'local', 'jit', or 'global' depending on the configuration in ctx one of 'legacy', 'local', 'jit', or 'global' depending on the configuration in ctx
""" """
strategy = 'legacy' strategy = "legacy"
if 'compile' in ctx.var: if "compile" in ctx.var:
strategy = ctx.var['compile'] strategy = ctx.var["compile"]
if strategy not in ['legacy', 'local', 'jit']: if strategy not in ["legacy", "local", "jit"]:
fail("Unknown --define=compile value '%s'" % strategy) fail("Unknown --define=compile value '%s'" % strategy)
if strategy == 'legacy' and hasattr(ctx.attr, '_global_mode') and ctx.attr._global_mode: if strategy == "legacy" and hasattr(ctx.attr, "_global_mode") and ctx.attr._global_mode:
strategy = 'global' strategy = "global"
return strategy return strategy
@ -51,16 +52,16 @@ def _compiler_name(ctx):
""" """
strategy = _compile_strategy(ctx) strategy = _compile_strategy(ctx)
if strategy == 'legacy': if strategy == "legacy":
return 'ngc' return "ngc"
elif strategy == 'global': elif strategy == "global":
return 'ngc.ivy' return "ngc.ivy"
elif strategy == 'local': elif strategy == "local":
return 'ngtsc' return "ngtsc"
elif strategy == 'jit': elif strategy == "jit":
return 'tsc' return "tsc"
else: else:
fail('unreachable') fail("unreachable")
def _enable_ivy_value(ctx): def _enable_ivy_value(ctx):
"""Determines the value of the enableIvy option in the generated tsconfig. """Determines the value of the enableIvy option in the generated tsconfig.
@ -73,16 +74,16 @@ def _enable_ivy_value(ctx):
""" """
strategy = _compile_strategy(ctx) strategy = _compile_strategy(ctx)
if strategy == 'legacy': if strategy == "legacy":
return False return False
elif strategy == 'global': elif strategy == "global":
return True return True
elif strategy == 'local': elif strategy == "local":
return 'ngtsc' return "ngtsc"
elif strategy == 'jit': elif strategy == "jit":
return 'tsc' return "tsc"
else: else:
fail('unreachable') fail("unreachable")
def _include_ng_files(ctx): def _include_ng_files(ctx):
"""Determines whether Angular outputs will be produced by the current compilation strategy. """Determines whether Angular outputs will be produced by the current compilation strategy.
@ -96,7 +97,7 @@ def _include_ng_files(ctx):
""" """
strategy = _compile_strategy(ctx) strategy = _compile_strategy(ctx)
return strategy == 'legacy' or strategy == 'global' return strategy == "legacy" or strategy == "global"
def _basename_of(ctx, file): def _basename_of(ctx, file):
ext_len = len(".ts") ext_len = len(".ts")
@ -243,17 +244,18 @@ def _ngc_tsconfig(ctx, files, srcs, **kwargs):
"enableIvy": _enable_ivy_value(ctx), "enableIvy": _enable_ivy_value(ctx),
"fullTemplateTypeCheck": ctx.attr.type_check, "fullTemplateTypeCheck": ctx.attr.type_check,
# FIXME: wrong place to de-dupe # FIXME: wrong place to de-dupe
"expectedOut": depset([o.path for o in expected_outs]).to_list() "expectedOut": depset([o.path for o in expected_outs]).to_list(),
} }
if _should_produce_flat_module_outs(ctx): if _should_produce_flat_module_outs(ctx):
angular_compiler_options["flatModuleId"] = ctx.attr.module_name angular_compiler_options["flatModuleId"] = ctx.attr.module_name
angular_compiler_options["flatModuleOutFile"] = _flat_module_out_file(ctx) angular_compiler_options["flatModuleOutFile"] = _flat_module_out_file(ctx)
angular_compiler_options["flatModulePrivateSymbolPrefix"] = "_".join( angular_compiler_options["flatModulePrivateSymbolPrefix"] = "_".join(
[ctx.workspace_name] + ctx.label.package.split("/") + [ctx.label.name, ""]) [ctx.workspace_name] + ctx.label.package.split("/") + [ctx.label.name, ""],
)
return dict(tsc_wrapped_tsconfig(ctx, files, srcs, **kwargs), **{ return dict(tsc_wrapped_tsconfig(ctx, files, srcs, **kwargs), **{
"angularCompilerOptions": angular_compiler_options "angularCompilerOptions": angular_compiler_options,
}) })
def _collect_summaries_aspect_impl(target, ctx): def _collect_summaries_aspect_impl(target, ctx):
@ -278,11 +280,19 @@ _collect_summaries_aspect = aspect(
# Extra options passed to Node when running ngc. # Extra options passed to Node when running ngc.
_EXTRA_NODE_OPTIONS_FLAGS = [ _EXTRA_NODE_OPTIONS_FLAGS = [
# Expose the v8 garbage collection API to JS. # Expose the v8 garbage collection API to JS.
"--node_options=--expose-gc" "--node_options=--expose-gc",
] ]
def ngc_compile_action(ctx, label, inputs, outputs, messages_out, tsconfig_file, def ngc_compile_action(
node_opts, locale=None, i18n_args=[]): ctx,
label,
inputs,
outputs,
messages_out,
tsconfig_file,
node_opts,
locale = None,
i18n_args = []):
"""Helper function to create the ngc action. """Helper function to create the ngc action.
This is exposed for google3 to wire up i18n replay rules, and is not intended This is exposed for google3 to wire up i18n replay rules, and is not intended
@ -318,6 +328,7 @@ def ngc_compile_action(ctx, label, inputs, outputs, messages_out, tsconfig_file,
arguments = (list(_EXTRA_NODE_OPTIONS_FLAGS) + arguments = (list(_EXTRA_NODE_OPTIONS_FLAGS) +
["--node_options=%s" % opt for opt in node_opts]) ["--node_options=%s" % opt for opt in node_opts])
# One at-sign makes this a params-file, enabling the worker strategy. # One at-sign makes this a params-file, enabling the worker strategy.
# Two at-signs escapes the argument so it's passed through to ngc # Two at-signs escapes the argument so it's passed through to ngc
# rather than the contents getting expanded. # rather than the contents getting expanded.
@ -352,7 +363,8 @@ def ngc_compile_action(ctx, label, inputs, outputs, messages_out, tsconfig_file,
# point to genfiles/ to redirect the output. # point to genfiles/ to redirect the output.
["../genfiles/" + messages_out[0].short_path]), ["../genfiles/" + messages_out[0].short_path]),
progress_message = "Extracting Angular 2 messages (ng_xi18n)", progress_message = "Extracting Angular 2 messages (ng_xi18n)",
mnemonic = "Angular2MessageExtractor") mnemonic = "Angular2MessageExtractor",
)
if not locale and not ctx.attr.no_i18n: if not locale and not ctx.attr.no_i18n:
return struct( return struct(
@ -372,21 +384,28 @@ def _compile_action(ctx, inputs, outputs, messages_out, tsconfig_file, node_opts
# The compiler only needs to see TypeScript sources from the npm dependencies, # The compiler only needs to see TypeScript sources from the npm dependencies,
# but may need to look at package.json and ngsummary.json files as well. # but may need to look at package.json and ngsummary.json files as well.
if hasattr(ctx.attr, "node_modules"): if hasattr(ctx.attr, "node_modules"):
file_inputs += [f for f in ctx.files.node_modules file_inputs += [
if f.path.endswith(".ts") or f.path.endswith(".json")] f
for f in ctx.files.node_modules
if f.path.endswith(".ts") or f.path.endswith(".json")
]
# If the user supplies a tsconfig.json file, the Angular compiler needs to read it # If the user supplies a tsconfig.json file, the Angular compiler needs to read it
if hasattr(ctx.attr, "tsconfig") and ctx.file.tsconfig: if hasattr(ctx.attr, "tsconfig") and ctx.file.tsconfig:
file_inputs.append(ctx.file.tsconfig) file_inputs.append(ctx.file.tsconfig)
# Collect the inputs and summary files from our deps # Collect the inputs and summary files from our deps
action_inputs = depset(file_inputs, action_inputs = depset(
transitive = [inputs] + [dep.collect_summaries_aspect_result for dep in ctx.attr.deps file_inputs,
if hasattr(dep, "collect_summaries_aspect_result")]) transitive = [inputs] + [
dep.collect_summaries_aspect_result
for dep in ctx.attr.deps
if hasattr(dep, "collect_summaries_aspect_result")
],
)
return ngc_compile_action(ctx, ctx.label, action_inputs, outputs, messages_out, tsconfig_file, node_opts) return ngc_compile_action(ctx, ctx.label, action_inputs, outputs, messages_out, tsconfig_file, node_opts)
def _prodmode_compile_action(ctx, inputs, outputs, tsconfig_file, node_opts): def _prodmode_compile_action(ctx, inputs, outputs, tsconfig_file, node_opts):
outs = _expected_outs(ctx) outs = _expected_outs(ctx)
return _compile_action(ctx, inputs, outputs + outs.closure_js, outs.i18n_messages, tsconfig_file, node_opts) return _compile_action(ctx, inputs, outputs + outs.closure_js, outs.i18n_messages, tsconfig_file, node_opts)
@ -420,17 +439,20 @@ def ng_module_impl(ctx, ts_compile_actions):
include_ng_files = _include_ng_files(ctx) include_ng_files = _include_ng_files(ctx)
providers = ts_compile_actions( providers = ts_compile_actions(
ctx, is_library=True, compile_action=_prodmode_compile_action, ctx,
devmode_compile_action=_devmode_compile_action, is_library = True,
tsc_wrapped_tsconfig=_ngc_tsconfig, compile_action = _prodmode_compile_action,
outputs = _ts_expected_outs) devmode_compile_action = _devmode_compile_action,
tsc_wrapped_tsconfig = _ngc_tsconfig,
outputs = _ts_expected_outs,
)
outs = _expected_outs(ctx) outs = _expected_outs(ctx)
if include_ng_files: if include_ng_files:
providers["angular"] = { providers["angular"] = {
"summaries": outs.summaries, "summaries": outs.summaries,
"metadata": outs.metadata "metadata": outs.metadata,
} }
providers["ngc_messages"] = outs.i18n_messages providers["ngc_messages"] = outs.i18n_messages
@ -452,39 +474,30 @@ def _ng_module_impl(ctx):
NG_MODULE_ATTRIBUTES = { NG_MODULE_ATTRIBUTES = {
"srcs": attr.label_list(allow_files = [".ts"]), "srcs": attr.label_list(allow_files = [".ts"]),
"deps": attr.label_list(aspects = DEPS_ASPECTS + [_collect_summaries_aspect]), "deps": attr.label_list(aspects = DEPS_ASPECTS + [_collect_summaries_aspect]),
"assets": attr.label_list(allow_files = [ "assets": attr.label_list(allow_files = [
".css", ".css",
# TODO(alexeagle): change this to ".ng.html" when usages updated # TODO(alexeagle): change this to ".ng.html" when usages updated
".html", ".html",
]), ]),
"factories": attr.label_list( "factories": attr.label_list(
allow_files = [".ts", ".html"], allow_files = [".ts", ".html"],
mandatory = False), mandatory = False,
),
"filter_summaries": attr.bool(default = False), "filter_summaries": attr.bool(default = False),
"type_check": attr.bool(default = True), "type_check": attr.bool(default = True),
"inline_resources": attr.bool(default = True), "inline_resources": attr.bool(default = True),
"no_i18n": attr.bool(default = False), "no_i18n": attr.bool(default = False),
"compiler": attr.label( "compiler": attr.label(
default = Label("//packages/bazel/src/ngc-wrapped"), default = Label("//packages/bazel/src/ngc-wrapped"),
executable = True, executable = True,
cfg = "host", cfg = "host",
), ),
"_ng_xi18n": attr.label( "_ng_xi18n": attr.label(
default = Label("//packages/bazel/src/ngc-wrapped:xi18n"), default = Label("//packages/bazel/src/ngc-wrapped:xi18n"),
executable = True, executable = True,
cfg = "host", cfg = "host",
), ),
"_supports_workers": attr.bool(default = True), "_supports_workers": attr.bool(default = True),
} }
@ -495,9 +508,8 @@ NG_MODULE_RULE_ATTRS = dict(dict(COMMON_ATTRIBUTES, **NG_MODULE_ATTRIBUTES), **{
# The default assumes the user specified a target "node_modules" in their # The default assumes the user specified a target "node_modules" in their
# root BUILD file. # root BUILD file.
"node_modules": attr.label( "node_modules": attr.label(
default = Label("@//:node_modules") default = Label("@//:node_modules"),
), ),
"entry_point": attr.string(), "entry_point": attr.string(),
# Default is %{name}_public_index # Default is %{name}_public_index
@ -516,7 +528,6 @@ ng_module = rule(
outputs = COMMON_OUTPUTS, outputs = COMMON_OUTPUTS,
) )
# TODO(alxhub): this rule causes legacy ngc to produce Ivy outputs from global analysis information. # TODO(alxhub): this rule causes legacy ngc to produce Ivy outputs from global analysis information.
# It exists to facilitate testing of the Ivy runtime until ngtsc is mature enough to be used # It exists to facilitate testing of the Ivy runtime until ngtsc is mature enough to be used
# instead, and should be removed once ngtsc is capable of fulfilling the same requirements. # instead, and should be removed once ngtsc is capable of fulfilling the same requirements.

View File

@ -6,21 +6,26 @@
""" """
load("@build_bazel_rules_nodejs//:internal/collect_es6_sources.bzl", "collect_es6_sources") load("@build_bazel_rules_nodejs//:internal/collect_es6_sources.bzl", "collect_es6_sources")
load("@build_bazel_rules_nodejs//:internal/rollup/rollup_bundle.bzl", load(
"write_rollup_config", "@build_bazel_rules_nodejs//:internal/rollup/rollup_bundle.bzl",
"ROLLUP_ATTRS",
"rollup_module_mappings_aspect", "rollup_module_mappings_aspect",
"run_uglify", "run_uglify",
"ROLLUP_ATTRS") "write_rollup_config",
load("@build_bazel_rules_nodejs//:internal/npm_package/npm_package.bzl", )
load(
"@build_bazel_rules_nodejs//:internal/npm_package/npm_package.bzl",
"NPM_PACKAGE_ATTRS", "NPM_PACKAGE_ATTRS",
"NPM_PACKAGE_OUTPUTS", "NPM_PACKAGE_OUTPUTS",
"create_package") "create_package",
)
load("@build_bazel_rules_nodejs//:internal/node.bzl", "sources_aspect") load("@build_bazel_rules_nodejs//:internal/node.bzl", "sources_aspect")
load("//packages/bazel/src:esm5.bzl", "esm5_outputs_aspect", "flatten_esm5", "esm5_root_dir") load("//packages/bazel/src:esm5.bzl", "esm5_outputs_aspect", "esm5_root_dir", "flatten_esm5")
# Convert from some-dash-case to someCamelCase # Convert from some-dash-case to someCamelCase
def _convert_dash_case_to_camel_case(s): def _convert_dash_case_to_camel_case(s):
parts = s.split("-") parts = s.split("-")
# First letter in the result is always unchanged # First letter in the result is always unchanged
return s[0] + "".join([p.title() for p in parts])[1:] return s[0] + "".join([p.title() for p in parts])[1:]
@ -40,7 +45,7 @@ def _global_name(package_name):
result_parts.append(_convert_dash_case_to_camel_case(p)) result_parts.append(_convert_dash_case_to_camel_case(p))
return ".".join(result_parts) return ".".join(result_parts)
WELL_KNOWN_GLOBALS = { p: _global_name(p) for p in [ WELL_KNOWN_GLOBALS = {p: _global_name(p) for p in [
"@angular/upgrade", "@angular/upgrade",
"@angular/upgrade/static", "@angular/upgrade/static",
"@angular/forms", "@angular/forms",
@ -98,12 +103,13 @@ def _rollup(ctx, bundle_name, rollup_config, entry_point, inputs, js_output, for
external = globals.keys() external = globals.keys()
if not include_tslib: if not include_tslib:
external.append("tslib") external.append("tslib")
args.add_joined("--external", external, join_with=",") args.add_joined("--external", external, join_with = ",")
args.add_joined( args.add_joined(
"--globals", "--globals",
["%s:%s" % g for g in globals.items()], ["%s:%s" % g for g in globals.items()],
join_with=",") join_with = ",",
)
args.add("--silent") args.add("--silent")
@ -135,20 +141,17 @@ def _flatten_paths(directory):
result.append(f.map.path) result.append(f.map.path)
return result return result
# takes an depset of files and returns an array that doesn't contain any generated files by ngc # takes an depset of files and returns an array that doesn't contain any generated files by ngc
def _filter_out_generated_files(files): def _filter_out_generated_files(files):
result = [] result = []
for file in files: for file in files:
if (not(file.path.endswith(".ngfactory.js") or file.path.endswith(".ngsummary.js") or file.path.endswith(".ngstyle.js"))): if (not (file.path.endswith(".ngfactory.js") or file.path.endswith(".ngsummary.js") or file.path.endswith(".ngstyle.js"))):
result.append(file) result.append(file)
return depset(result) return depset(result)
def _esm2015_root_dir(ctx): def _esm2015_root_dir(ctx):
return ctx.label.name + ".es6" return ctx.label.name + ".es6"
# ng_package produces package that is npm-ready. # ng_package produces package that is npm-ready.
def _ng_package_impl(ctx): def _ng_package_impl(ctx):
npm_package_directory = ctx.actions.declare_directory("%s.ng_pkg" % ctx.label.name) npm_package_directory = ctx.actions.declare_directory("%s.ng_pkg" % ctx.label.name)
@ -178,6 +181,7 @@ def _ng_package_impl(ctx):
# - in this package or a subpackage # - in this package or a subpackage
# - those that have a module_name attribute (they produce flat module metadata) # - those that have a module_name attribute (they produce flat module metadata)
flat_module_metadata = [] flat_module_metadata = []
# Name given in the package.json name field, eg. @angular/core/testing # Name given in the package.json name field, eg. @angular/core/testing
package_name = "" package_name = ""
deps_in_package = [d for d in ctx.attr.deps if d.label.package.startswith(ctx.label.package)] deps_in_package = [d for d in ctx.attr.deps if d.label.package.startswith(ctx.label.package)]
@ -223,28 +227,45 @@ def _ng_package_impl(ctx):
umd_output = ctx.outputs.umd umd_output = ctx.outputs.umd
min_output = ctx.outputs.umd_min min_output = ctx.outputs.umd_min
esm2015_config = write_rollup_config(ctx, [], "/".join([ctx.bin_dir.path, ctx.label.package, _esm2015_root_dir(ctx)]), filename="_%s.rollup_esm2015.conf.js") esm2015_config = write_rollup_config(ctx, [], "/".join([ctx.bin_dir.path, ctx.label.package, _esm2015_root_dir(ctx)]), filename = "_%s.rollup_esm2015.conf.js")
esm5_config = write_rollup_config(ctx, [], "/".join([ctx.bin_dir.path, ctx.label.package, esm5_root_dir(ctx)]), filename="_%s.rollup_esm5.conf.js") esm5_config = write_rollup_config(ctx, [], "/".join([ctx.bin_dir.path, ctx.label.package, esm5_root_dir(ctx)]), filename = "_%s.rollup_esm5.conf.js")
fesm2015.append(_rollup(ctx, "fesm2015", esm2015_config, es2015_entry_point, esm_2015_files + ctx.files.node_modules, fesm2015_output)) fesm2015.append(_rollup(ctx, "fesm2015", esm2015_config, es2015_entry_point, esm_2015_files + ctx.files.node_modules, fesm2015_output))
fesm5.append(_rollup(ctx, "fesm5", esm5_config, es5_entry_point, esm5_sources + ctx.files.node_modules, fesm5_output)) fesm5.append(_rollup(ctx, "fesm5", esm5_config, es5_entry_point, esm5_sources + ctx.files.node_modules, fesm5_output))
bundles.append( bundles.append(
_rollup(ctx, "umd", esm5_config, es5_entry_point, esm5_sources + ctx.files.node_modules, umd_output, _rollup(
format = "umd", package_name = package_name, include_tslib = True)) ctx,
uglify_sourcemap = run_uglify(ctx, umd_output, min_output, "umd",
config_name = entry_point.replace("/", "_")) esm5_config,
es5_entry_point,
esm5_sources + ctx.files.node_modules,
umd_output,
format = "umd",
package_name = package_name,
include_tslib = True,
),
)
uglify_sourcemap = run_uglify(
ctx,
umd_output,
min_output,
config_name = entry_point.replace("/", "_"),
)
bundles.append(struct(js = min_output, map = uglify_sourcemap)) bundles.append(struct(js = min_output, map = uglify_sourcemap))
packager_inputs = ( packager_inputs = (
ctx.files.srcs + ctx.files.srcs +
ctx.files.data + ctx.files.data +
esm5_sources.to_list() + esm5_sources.to_list() +
depset(transitive = [d.typescript.transitive_declarations depset(transitive = [
d.typescript.transitive_declarations
for d in ctx.attr.deps for d in ctx.attr.deps
if hasattr(d, "typescript")]).to_list() + if hasattr(d, "typescript")
]).to_list() +
[f.js for f in fesm2015 + fesm5 + esm2015 + esm5 + bundles] + [f.js for f in fesm2015 + fesm5 + esm2015 + esm5 + bundles] +
[f.map for f in fesm2015 + fesm5 + esm2015 + esm5 + bundles if f.map]) [f.map for f in fesm2015 + fesm5 + esm2015 + esm5 + bundles if f.map]
)
packager_args = ctx.actions.args() packager_args = ctx.actions.args()
packager_args.use_param_file("%s", use_always = True) packager_args.use_param_file("%s", use_always = True)
@ -252,8 +273,8 @@ def _ng_package_impl(ctx):
# The order of arguments matters here, as they are read in order in packager.ts. # The order of arguments matters here, as they are read in order in packager.ts.
packager_args.add(npm_package_directory.path) packager_args.add(npm_package_directory.path)
packager_args.add(ctx.label.package) packager_args.add(ctx.label.package)
packager_args.add_joined([ctx.bin_dir.path, ctx.label.package], join_with="/") packager_args.add_joined([ctx.bin_dir.path, ctx.label.package], join_with = "/")
packager_args.add_joined([ctx.genfiles_dir.path, ctx.label.package], join_with="/") packager_args.add_joined([ctx.genfiles_dir.path, ctx.label.package], join_with = "/")
# Marshal the metadata into a JSON string so we can parse the data structure # Marshal the metadata into a JSON string so we can parse the data structure
# in the TypeScript program easily. # in the TypeScript program easily.
@ -274,15 +295,15 @@ def _ng_package_impl(ctx):
# placeholder # placeholder
packager_args.add("") packager_args.add("")
packager_args.add_joined(_flatten_paths(fesm2015), join_with=",") packager_args.add_joined(_flatten_paths(fesm2015), join_with = ",")
packager_args.add_joined(_flatten_paths(fesm5), join_with=",") packager_args.add_joined(_flatten_paths(fesm5), join_with = ",")
packager_args.add_joined(_flatten_paths(esm2015), join_with=",") packager_args.add_joined(_flatten_paths(esm2015), join_with = ",")
packager_args.add_joined(_flatten_paths(esm5), join_with=",") packager_args.add_joined(_flatten_paths(esm5), join_with = ",")
packager_args.add_joined(_flatten_paths(bundles), join_with=",") packager_args.add_joined(_flatten_paths(bundles), join_with = ",")
packager_args.add_joined([s.path for s in ctx.files.srcs], join_with=",") packager_args.add_joined([s.path for s in ctx.files.srcs], join_with = ",")
# TODO: figure out a better way to gather runfiles providers from the transitive closure. # TODO: figure out a better way to gather runfiles providers from the transitive closure.
packager_args.add_joined([d.path for d in ctx.files.data], join_with=",") packager_args.add_joined([d.path for d in ctx.files.data], join_with = ",")
if ctx.file.license_banner: if ctx.file.license_banner:
packager_inputs.append(ctx.file.license_banner) packager_inputs.append(ctx.file.license_banner)
@ -309,9 +330,10 @@ def _ng_package_impl(ctx):
package_dir = create_package( package_dir = create_package(
ctx, ctx,
devfiles.to_list(), devfiles.to_list(),
[npm_package_directory] + ctx.files.packages) [npm_package_directory] + ctx.files.packages,
)
return [DefaultInfo( return [DefaultInfo(
files = depset([package_dir]) files = depset([package_dir]),
)] )]
NG_PACKAGE_ATTRS = dict(NPM_PACKAGE_ATTRS, **dict(ROLLUP_ATTRS, **{ NG_PACKAGE_ATTRS = dict(NPM_PACKAGE_ATTRS, **dict(ROLLUP_ATTRS, **{
@ -327,22 +349,29 @@ NG_PACKAGE_ATTRS = dict(NPM_PACKAGE_ATTRS, **dict(ROLLUP_ATTRS, **{
), ),
"include_devmode_srcs": attr.bool(default = False), "include_devmode_srcs": attr.bool(default = False),
"readme_md": attr.label(allow_single_file = FileType([".md"])), "readme_md": attr.label(allow_single_file = FileType([".md"])),
"globals": attr.string_dict(default={}), "globals": attr.string_dict(default = {}),
"entry_point_name": attr.string( "entry_point_name": attr.string(
doc = "Name to use when generating bundle files for the primary entry-point.", doc = "Name to use when generating bundle files for the primary entry-point.",
), ),
"_ng_packager": attr.label( "_ng_packager": attr.label(
default=Label("//packages/bazel/src/ng_package:packager"), default = Label("//packages/bazel/src/ng_package:packager"),
executable=True, cfg="host"), executable = True,
cfg = "host",
),
"_rollup": attr.label( "_rollup": attr.label(
default=Label("@build_bazel_rules_nodejs//internal/rollup"), default = Label("@build_bazel_rules_nodejs//internal/rollup"),
executable=True, cfg="host"), executable = True,
cfg = "host",
),
"_rollup_config_tmpl": attr.label( "_rollup_config_tmpl": attr.label(
default=Label("@build_bazel_rules_nodejs//internal/rollup:rollup.config.js"), default = Label("@build_bazel_rules_nodejs//internal/rollup:rollup.config.js"),
allow_single_file=True), allow_single_file = True,
),
"_uglify": attr.label( "_uglify": attr.label(
default=Label("@build_bazel_rules_nodejs//internal/rollup:uglify"), default = Label("@build_bazel_rules_nodejs//internal/rollup:uglify"),
executable=True, cfg="host"), executable = True,
cfg = "host",
),
})) }))
# Angular wants these named after the entry_point, # Angular wants these named after the entry_point,

View File

@ -10,22 +10,25 @@
build-optimizer is hard-coded to look for and transform. build-optimizer is hard-coded to look for and transform.
""" """
load("@build_bazel_rules_nodejs//internal/rollup:rollup_bundle.bzl", load(
"rollup_module_mappings_aspect", "@build_bazel_rules_nodejs//internal/rollup:rollup_bundle.bzl",
"ROLLUP_ATTRS", "ROLLUP_ATTRS",
"ROLLUP_OUTPUTS", "ROLLUP_OUTPUTS",
"write_rollup_config", "rollup_module_mappings_aspect",
"run_rollup", "run_rollup",
"run_sourcemapexplorer",
"run_uglify", "run_uglify",
"run_sourcemapexplorer") "write_rollup_config",
)
load("@build_bazel_rules_nodejs//internal:collect_es6_sources.bzl", collect_es2015_sources = "collect_es6_sources") load("@build_bazel_rules_nodejs//internal:collect_es6_sources.bzl", collect_es2015_sources = "collect_es6_sources")
load(":esm5.bzl", "esm5_outputs_aspect", "flatten_esm5", "esm5_root_dir") load(":esm5.bzl", "esm5_outputs_aspect", "esm5_root_dir", "flatten_esm5")
PACKAGES=["packages/core/src", "packages/common/src", "packages/compiler/src", "external/rxjs"] PACKAGES = ["packages/core/src", "packages/common/src", "packages/compiler/src", "external/rxjs"]
PLUGIN_CONFIG="{sideEffectFreeModules: [\n%s]}" % ",\n".join( PLUGIN_CONFIG = "{sideEffectFreeModules: [\n%s]}" % ",\n".join(
[" '.esm5/{0}'".format(p) for p in PACKAGES]) [" '.esm5/{0}'".format(p) for p in PACKAGES],
BO_ROLLUP="angular_cli/packages/angular_devkit/build_optimizer/src/build-optimizer/rollup-plugin.js" )
BO_PLUGIN="require('%s').default(%s)" % (BO_ROLLUP, PLUGIN_CONFIG) BO_ROLLUP = "angular_cli/packages/angular_devkit/build_optimizer/src/build-optimizer/rollup-plugin.js"
BO_PLUGIN = "require('%s').default(%s)" % (BO_ROLLUP, PLUGIN_CONFIG)
def _use_plain_rollup(ctx): def _use_plain_rollup(ctx):
"""Determine whether to use the Angular or upstream versions of the rollup_bundle rule. """Determine whether to use the Angular or upstream versions of the rollup_bundle rule.
@ -43,12 +46,11 @@ def _use_plain_rollup(ctx):
true iff the Angular version of rollup with build optimizer should be used, false otherwise true iff the Angular version of rollup with build optimizer should be used, false otherwise
""" """
if 'compile' not in ctx.var: if "compile" not in ctx.var:
return False return False
strategy = ctx.var['compile'] strategy = ctx.var["compile"]
return strategy == 'jit' return strategy == "jit"
def run_brotli(ctx, input, output): def run_brotli(ctx, input, output):
ctx.actions.run( ctx.actions.run(
@ -70,7 +72,7 @@ def _run_tsc(ctx, input, output):
executable = ctx.executable._tsc, executable = ctx.executable._tsc,
inputs = [input], inputs = [input],
outputs = [output], outputs = [output],
arguments = [args] arguments = [args],
) )
# Borrowed from bazelbuild/rules_nodejs, with the addition of brotli compression output # Borrowed from bazelbuild/rules_nodejs, with the addition of brotli compression output
@ -104,15 +106,20 @@ def _ng_rollup_bundle(ctx):
rollup_config = write_rollup_config(ctx, [BO_PLUGIN], "/".join([ctx.bin_dir.path, ctx.label.package, esm5_root_dir(ctx)])) rollup_config = write_rollup_config(ctx, [BO_PLUGIN], "/".join([ctx.bin_dir.path, ctx.label.package, esm5_root_dir(ctx)]))
rollup_sourcemap = run_rollup(ctx, esm5_sources, rollup_config, ctx.outputs.build_es5) rollup_sourcemap = run_rollup(ctx, esm5_sources, rollup_config, ctx.outputs.build_es5)
sourcemap = run_uglify(ctx, sourcemap = run_uglify(
ctx,
ctx.outputs.build_es5, ctx.outputs.build_es5,
ctx.outputs.build_es5_min, ctx.outputs.build_es5_min,
comments = False, comments = False,
in_source_map = rollup_sourcemap) in_source_map = rollup_sourcemap,
run_uglify(ctx, )
run_uglify(
ctx,
ctx.outputs.build_es5, ctx.outputs.build_es5,
ctx.outputs.build_es5_min_debug, ctx.outputs.build_es5_min_debug,
debug = True, comments = False) debug = True,
comments = False,
)
umd_rollup_config = write_rollup_config(ctx, filename = "_%s_umd.rollup.conf.js", output_format = "umd") umd_rollup_config = write_rollup_config(ctx, filename = "_%s_umd.rollup.conf.js", output_format = "umd")
run_rollup(ctx, collect_es2015_sources(ctx), umd_rollup_config, ctx.outputs.build_umd) run_rollup(ctx, collect_es2015_sources(ctx), umd_rollup_config, ctx.outputs.build_umd)
@ -121,7 +128,7 @@ def _ng_rollup_bundle(ctx):
run_sourcemapexplorer(ctx, ctx.outputs.build_es5_min, sourcemap, ctx.outputs.explore_html) run_sourcemapexplorer(ctx, ctx.outputs.build_es5_min, sourcemap, ctx.outputs.explore_html)
return DefaultInfo(files=depset([ctx.outputs.build_es5_min, sourcemap])) return DefaultInfo(files = depset([ctx.outputs.build_es5_min, sourcemap]))
ng_rollup_bundle = rule( ng_rollup_bundle = rule(
implementation = _ng_rollup_bundle, implementation = _ng_rollup_bundle,
@ -133,11 +140,13 @@ ng_rollup_bundle = rule(
"_rollup": attr.label( "_rollup": attr.label(
executable = True, executable = True,
cfg = "host", cfg = "host",
default = Label("@angular//packages/bazel/src:rollup_with_build_optimizer")), default = Label("@angular//packages/bazel/src:rollup_with_build_optimizer"),
),
"_brotli": attr.label( "_brotli": attr.label(
executable = True, executable = True,
cfg = "host", cfg = "host",
default = Label("@org_brotli//:brotli")), default = Label("@org_brotli//:brotli"),
),
}), }),
outputs = dict(ROLLUP_OUTPUTS, **{ outputs = dict(ROLLUP_OUTPUTS, **{
"build_es5_min_compressed": "%{name}.min.js.br", "build_es5_min_compressed": "%{name}.min.js.br",

View File

@ -5,9 +5,10 @@
"""Implementation of the protractor_web_test and protractor_web_test_suite rules. """Implementation of the protractor_web_test and protractor_web_test_suite rules.
""" """
load("@build_bazel_rules_nodejs//internal:node.bzl", load(
"sources_aspect", "@build_bazel_rules_nodejs//internal:node.bzl",
"expand_path_into_runfiles", "expand_path_into_runfiles",
"sources_aspect",
) )
load("@io_bazel_rules_webtesting//web:web.bzl", "web_test_suite") load("@io_bazel_rules_webtesting//web:web.bzl", "web_test_suite")
load("@io_bazel_rules_webtesting//web/internal:constants.bzl", "DEFAULT_WRAPPED_TEST_TAGS") load("@io_bazel_rules_webtesting//web/internal:constants.bzl", "DEFAULT_WRAPPED_TEST_TAGS")
@ -18,7 +19,8 @@ _CONF_TMPL = "//packages/bazel/src/protractor:protractor.conf.js"
def _protractor_web_test_impl(ctx): def _protractor_web_test_impl(ctx):
configuration = ctx.actions.declare_file( configuration = ctx.actions.declare_file(
"%s.conf.js" % ctx.label.name, "%s.conf.js" % ctx.label.name,
sibling=ctx.outputs.executable) sibling = ctx.outputs.executable,
)
files = depset(ctx.files.srcs) files = depset(ctx.files.srcs)
for d in ctx.attr.deps: for d in ctx.attr.deps:
@ -53,13 +55,13 @@ def _protractor_web_test_impl(ctx):
on_prepare_file = ctx.attr.on_prepare.typescript.es5_sources.to_list()[0] on_prepare_file = ctx.attr.on_prepare.typescript.es5_sources.to_list()[0]
protractor_executable_path = ctx.executable.protractor.short_path protractor_executable_path = ctx.executable.protractor.short_path
if protractor_executable_path.startswith('..'): if protractor_executable_path.startswith(".."):
protractor_executable_path = "external" + protractor_executable_path[2:] protractor_executable_path = "external" + protractor_executable_path[2:]
server_executable_path = '' server_executable_path = ""
if ctx.executable.server: if ctx.executable.server:
server_executable_path = ctx.executable.server.short_path server_executable_path = ctx.executable.server.short_path
if server_executable_path.startswith('..'): if server_executable_path.startswith(".."):
server_executable_path = "external" + protractor_executable_path[2:] server_executable_path = "external" + protractor_executable_path[2:]
ctx.actions.expand_template( ctx.actions.expand_template(
@ -71,7 +73,8 @@ def _protractor_web_test_impl(ctx):
"TMPL_workspace": ctx.workspace_name, "TMPL_workspace": ctx.workspace_name,
"TMPL_server": server_executable_path, "TMPL_server": server_executable_path,
"TMPL_specs": "\n".join([" '%s'," % e for e in specs]), "TMPL_specs": "\n".join([" '%s'," % e for e in specs]),
}) },
)
runfiles = [configuration] + configuration_sources + on_prepare_sources runfiles = [configuration] + configuration_sources + on_prepare_sources
@ -101,8 +104,11 @@ echo "Protractor $PROTRACTOR_VERSION"
# Run the protractor binary # Run the protractor binary
$PROTRACTOR $CONF $PROTRACTOR $CONF
""".format(TMPL_protractor = protractor_executable_path, """.format(
TMPL_conf = configuration.short_path)) TMPL_protractor = protractor_executable_path,
TMPL_conf = configuration.short_path,
),
)
return [DefaultInfo( return [DefaultInfo(
files = depset([ctx.outputs.executable]), files = depset([ctx.outputs.executable]),
runfiles = ctx.runfiles( runfiles = ctx.runfiles(
@ -124,36 +130,43 @@ _protractor_web_test = rule(
doc = "Protractor configuration file", doc = "Protractor configuration file",
allow_single_file = True, allow_single_file = True,
cfg = "data", cfg = "data",
aspects = [sources_aspect]), aspects = [sources_aspect],
),
"srcs": attr.label_list( "srcs": attr.label_list(
doc = "A list of JavaScript test files", doc = "A list of JavaScript test files",
allow_files = [".js"]), allow_files = [".js"],
),
"on_prepare": attr.label( "on_prepare": attr.label(
doc = """A file with a node.js script to run once before all tests run. doc = """A file with a node.js script to run once before all tests run.
If the script exports a function which returns a promise, protractor If the script exports a function which returns a promise, protractor
will wait for the promise to resolve before beginning tests.""", will wait for the promise to resolve before beginning tests.""",
allow_single_file = True, allow_single_file = True,
cfg = "data", cfg = "data",
aspects = [sources_aspect]), aspects = [sources_aspect],
),
"deps": attr.label_list( "deps": attr.label_list(
doc = "Other targets which produce JavaScript such as `ts_library`", doc = "Other targets which produce JavaScript such as `ts_library`",
allow_files = True, allow_files = True,
aspects = [sources_aspect]), aspects = [sources_aspect],
),
"data": attr.label_list( "data": attr.label_list(
doc = "Runtime dependencies", doc = "Runtime dependencies",
cfg = "data"), cfg = "data",
),
"server": attr.label( "server": attr.label(
doc = "Optional server executable target", doc = "Optional server executable target",
executable = True, executable = True,
cfg = "data", cfg = "data",
single_file = False, single_file = False,
allow_files = True), allow_files = True,
),
"protractor": attr.label( "protractor": attr.label(
doc = "Protractor executable target (set by protractor_web_test macro)", doc = "Protractor executable target (set by protractor_web_test macro)",
executable = True, executable = True,
cfg = "data", cfg = "data",
single_file = False, single_file = False,
allow_files = True), allow_files = True,
),
"_conf_tmpl": attr.label( "_conf_tmpl": attr.label(
default = Label(_CONF_TMPL), default = Label(_CONF_TMPL),
allow_single_file = True, allow_single_file = True,
@ -207,7 +220,7 @@ def protractor_web_test(
_protractor_web_test( _protractor_web_test(
name = name, name = name,
configuration = configuration, configuration = configuration,
on_prepare=on_prepare, on_prepare = on_prepare,
srcs = srcs, srcs = srcs,
deps = deps, deps = deps,
data = web_test_data, data = web_test_data,
@ -217,7 +230,8 @@ def protractor_web_test(
# Users don't need to know that this tag is required to run under ibazel # Users don't need to know that this tag is required to run under ibazel
"ibazel_notify_changes", "ibazel_notify_changes",
], ],
**kwargs) **kwargs
)
def protractor_web_test_suite( def protractor_web_test_suite(
name, name,
@ -227,20 +241,20 @@ def protractor_web_test_suite(
deps = [], deps = [],
data = [], data = [],
server = None, server = None,
browsers=["@io_bazel_rules_webtesting//browsers:chromium-local"], browsers = ["@io_bazel_rules_webtesting//browsers:chromium-local"],
args=None, args = None,
browser_overrides=None, browser_overrides = None,
config=None, config = None,
flaky=None, flaky = None,
local=None, local = None,
shard_count=None, shard_count = None,
size=None, size = None,
tags = [], tags = [],
test_suite_tags=None, test_suite_tags = None,
timeout=None, timeout = None,
visibility=None, visibility = None,
web_test_data=[], web_test_data = [],
wrapped_test_tags=None, wrapped_test_tags = None,
**remaining_keyword_args): **remaining_keyword_args):
"""Defines a test_suite of web_test targets that wrap a protractor_web_test target. """Defines a test_suite of web_test targets that wrap a protractor_web_test target.
@ -276,6 +290,7 @@ def protractor_web_test_suite(
wrapped_test_tags: A list of test tag strings to use for the wrapped test wrapped_test_tags: A list of test tag strings to use for the wrapped test
**remaining_keyword_args: Arguments for the wrapped test target. **remaining_keyword_args: Arguments for the wrapped test target.
""" """
# Check explicitly for None so that users can set this to the empty list # Check explicitly for None so that users can set this to the empty list
if wrapped_test_tags == None: if wrapped_test_tags == None:
wrapped_test_tags = DEFAULT_WRAPPED_TEST_TAGS wrapped_test_tags = DEFAULT_WRAPPED_TEST_TAGS
@ -304,38 +319,40 @@ def protractor_web_test_suite(
web_test_data += [server] web_test_data += [server]
_protractor_web_test( _protractor_web_test(
name=wrapped_test_name, name = wrapped_test_name,
configuration=configuration, configuration = configuration,
on_prepare=on_prepare, on_prepare = on_prepare,
srcs=srcs, srcs = srcs,
deps=deps, deps = deps,
data=web_test_data, data = web_test_data,
server=server, server = server,
protractor=protractor_bin_name, protractor = protractor_bin_name,
args=args, args = args,
flaky=flaky, flaky = flaky,
local=local, local = local,
shard_count=shard_count, shard_count = shard_count,
size=size, size = size,
tags=wrapped_test_tags, tags = wrapped_test_tags,
timeout=timeout, timeout = timeout,
visibility=["//visibility:private"], visibility = ["//visibility:private"],
**remaining_keyword_args) **remaining_keyword_args
)
web_test_suite( web_test_suite(
name=name, name = name,
launcher=":"+wrapped_test_name, launcher = ":" + wrapped_test_name,
args=args, args = args,
browsers=browsers, browsers = browsers,
browser_overrides=browser_overrides, browser_overrides = browser_overrides,
config=config, config = config,
data=web_test_data, data = web_test_data,
flaky=flaky, flaky = flaky,
local=local, local = local,
shard_count=shard_count, shard_count = shard_count,
size=size, size = size,
tags=tags, tags = tags,
test=wrapped_test_name, test = wrapped_test_name,
test_suite_tags=test_suite_tags, test_suite_tags = test_suite_tags,
timeout=timeout, timeout = timeout,
visibility=visibility) visibility = visibility,
)

View File

@ -1,19 +1,20 @@
"""Allows different paths for these imports in google3. """Allows different paths for these imports in google3.
""" """
load("@build_bazel_rules_typescript//internal:build_defs.bzl", load(
"@build_bazel_rules_typescript//internal:build_defs.bzl",
_tsc_wrapped_tsconfig = "tsc_wrapped_tsconfig", _tsc_wrapped_tsconfig = "tsc_wrapped_tsconfig",
) )
load(
load("@build_bazel_rules_typescript//internal:common/compilation.bzl", "@build_bazel_rules_typescript//internal:common/compilation.bzl",
_COMMON_ATTRIBUTES = "COMMON_ATTRIBUTES", _COMMON_ATTRIBUTES = "COMMON_ATTRIBUTES",
_COMMON_OUTPUTS = "COMMON_OUTPUTS", _COMMON_OUTPUTS = "COMMON_OUTPUTS",
_compile_ts = "compile_ts",
_DEPS_ASPECTS = "DEPS_ASPECTS", _DEPS_ASPECTS = "DEPS_ASPECTS",
_compile_ts = "compile_ts",
_ts_providers_dict_to_struct = "ts_providers_dict_to_struct", _ts_providers_dict_to_struct = "ts_providers_dict_to_struct",
) )
load(
load("@build_bazel_rules_typescript//internal:common/json_marshal.bzl", "@build_bazel_rules_typescript//internal:common/json_marshal.bzl",
_json_marshal = "json_marshal", _json_marshal = "json_marshal",
) )

View File

@ -9,14 +9,15 @@ This allows editors and other tools to easily use the language service bundle
without having to provide all of the angular specific peer dependencies. without having to provide all of the angular specific peer dependencies.
""" """
load("@build_bazel_rules_nodejs//internal/rollup:rollup_bundle.bzl", load(
"@build_bazel_rules_nodejs//internal/rollup:rollup_bundle.bzl",
"ROLLUP_ATTRS", "ROLLUP_ATTRS",
"rollup_module_mappings_aspect", "rollup_module_mappings_aspect",
"write_rollup_config",
"run_rollup", "run_rollup",
"run_uglify" "run_uglify",
"write_rollup_config",
) )
load("//packages/bazel/src:esm5.bzl", "esm5_outputs_aspect", "flatten_esm5", "esm5_root_dir") load("//packages/bazel/src:esm5.bzl", "esm5_outputs_aspect", "esm5_root_dir", "flatten_esm5")
# Note: the file is called "umd.js" and "umd.min.js" because of historical # Note: the file is called "umd.js" and "umd.min.js" because of historical
# reasons. The format is actually amd and not umd, but we are afraid to rename # reasons. The format is actually amd and not umd, but we are afraid to rename
@ -29,12 +30,14 @@ _ROLLUP_OUTPUTS = {
def _ls_rollup_bundle(ctx): def _ls_rollup_bundle(ctx):
esm5_sources = flatten_esm5(ctx) esm5_sources = flatten_esm5(ctx)
rollup_config = write_rollup_config(ctx, rollup_config = write_rollup_config(
ctx,
root_dir = "/".join([ctx.bin_dir.path, ctx.label.package, esm5_root_dir(ctx)]), root_dir = "/".join([ctx.bin_dir.path, ctx.label.package, esm5_root_dir(ctx)]),
output_format = "amd") output_format = "amd",
)
run_rollup(ctx, esm5_sources, rollup_config, ctx.outputs.build_umd) run_rollup(ctx, esm5_sources, rollup_config, ctx.outputs.build_umd)
source_map = run_uglify(ctx, ctx.outputs.build_umd, ctx.outputs.build_umd_min) source_map = run_uglify(ctx, ctx.outputs.build_umd, ctx.outputs.build_umd_min)
return DefaultInfo(files=depset([ctx.outputs.build_umd, ctx.outputs.build_umd_min, source_map])) return DefaultInfo(files = depset([ctx.outputs.build_umd, ctx.outputs.build_umd_min, source_map]))
ls_rollup_bundle = rule( ls_rollup_bundle = rule(
implementation = _ls_rollup_bundle, implementation = _ls_rollup_bundle,

View File

@ -38,7 +38,7 @@ ANGULAR_SCOPED_PACKAGES = ["@angular/%s" % p for p in [
PKG_GROUP_REPLACEMENTS = { PKG_GROUP_REPLACEMENTS = {
"\"NG_UPDATE_PACKAGE_GROUP\"": """[ "\"NG_UPDATE_PACKAGE_GROUP\"": """[
%s %s
]""" % ",\n ".join(["\"%s\"" % s for s in ANGULAR_SCOPED_PACKAGES]) ]""" % ",\n ".join(["\"%s\"" % s for s in ANGULAR_SCOPED_PACKAGES]),
} }
def ts_library(tsconfig = None, node_modules = DEFAULT_NODE_MODULES, testonly = False, **kwargs): def ts_library(tsconfig = None, node_modules = DEFAULT_NODE_MODULES, testonly = False, **kwargs):
@ -91,7 +91,8 @@ def npm_package(name, replacements = {}, **kwargs):
_npm_package( _npm_package(
name = name, name = name,
replacements = dict(replacements, **PKG_GROUP_REPLACEMENTS), replacements = dict(replacements, **PKG_GROUP_REPLACEMENTS),
**kwargs) **kwargs
)
def ts_web_test_suite(bootstrap = [], deps = [], **kwargs): def ts_web_test_suite(bootstrap = [], deps = [], **kwargs):
if not bootstrap: if not bootstrap:

View File

@ -2,6 +2,7 @@
See https://www.npmjs.com/package/http-server See https://www.npmjs.com/package/http-server
""" """
load("@build_bazel_rules_nodejs//:defs.bzl", "nodejs_binary") load("@build_bazel_rules_nodejs//:defs.bzl", "nodejs_binary")
def http_server(templated_args = [], **kwargs): def http_server(templated_args = [], **kwargs):
@ -15,4 +16,5 @@ def http_server(templated_args = [], **kwargs):
node_modules = "@http-server_runtime_deps//:node_modules", node_modules = "@http-server_runtime_deps//:node_modules",
entry_point = "http-server/bin/http-server", entry_point = "http-server/bin/http-server",
templated_args = templated_args, templated_args = templated_args,
**kwargs) **kwargs
)

View File

@ -235,6 +235,7 @@ filegroup(
"node_modules/protractor/**", "node_modules/protractor/**",
"node_modules/@schematics/angular/**", "node_modules/@schematics/angular/**",
])) ]))
""") """,
)
_ng_setup_workspace() _ng_setup_workspace()

View File

@ -8,7 +8,7 @@
# This does a deep import under //internal because of not wanting the wrapper macro # This does a deep import under //internal because of not wanting the wrapper macro
# because it introduces an extra target_bin target. # because it introduces an extra target_bin target.
load("@build_bazel_rules_nodejs//internal/node:node.bzl", "nodejs_test", "nodejs_binary") load("@build_bazel_rules_nodejs//internal/node:node.bzl", "nodejs_binary", "nodejs_test")
DEFAULT_NODE_MODULES = "@angular_deps//:node_modules" DEFAULT_NODE_MODULES = "@angular_deps//:node_modules"

View File

@ -14,7 +14,8 @@
"""Runs ts_api_guardian """Runs ts_api_guardian
""" """
load("@build_bazel_rules_nodejs//internal/node:node.bzl", "nodejs_test", "nodejs_binary")
load("@build_bazel_rules_nodejs//internal/node:node.bzl", "nodejs_binary", "nodejs_test")
COMMON_MODULE_IDENTIFIERS = ["angular", "jasmine", "protractor"] COMMON_MODULE_IDENTIFIERS = ["angular", "jasmine", "protractor"]
@ -31,7 +32,8 @@ def ts_api_guardian_test(name, golden, actual, data = [], **kwargs):
# Needed so that node doesn't walk back to the source directory. # Needed so that node doesn't walk back to the source directory.
# From there, the relative imports would point to .ts files. # From there, the relative imports would point to .ts files.
"--node_options=--preserve-symlinks", "--node_options=--preserve-symlinks",
"--stripExportPattern", "^\(__\\)", "--stripExportPattern",
"^\(__\\)",
] ]
for i in COMMON_MODULE_IDENTIFIERS: for i in COMMON_MODULE_IDENTIFIERS:
args += ["--allowModuleIdentifiers", i] args += ["--allowModuleIdentifiers", i]