Skip to content

Commit

Permalink
fix: esm5_sources rule (wip not yet working)
Browse files Browse the repository at this point in the history
  • Loading branch information
gregmagolan committed Oct 22, 2019
1 parent f6c1ff1 commit 341ebc4
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 4 deletions.
26 changes: 24 additions & 2 deletions packages/bazel/src/esm5.bzl
Expand Up @@ -12,7 +12,7 @@ However we need to publish this flavor on NPM, so it's necessary to be able
to produce it.
"""

load(":external.bzl", "DEFAULT_NG_COMPILER")
load(":external.bzl", "DEFAULT_NG_COMPILER", "JSEcmaScriptModuleInfo")

# The provider downstream rules use to access the outputs
ESM5Info = provider(
Expand Down Expand Up @@ -214,10 +214,32 @@ def flatten_esm5(ctx):
rerooted_file = ctx.actions.declare_file("/".join([esm5_root_dir(ctx), path]))
result.append(rerooted_file)

# print("copy", f.short_path, "to", rerooted_file.short_path)
ctx.actions.expand_template(
output = rerooted_file,
template = f,
substitutions = {},
)
return depset(result)

def _esm5_sources(ctx):
sources = flatten_esm5(ctx)

return [
DefaultInfo(
files = sources,
runfiles = ctx.runfiles(transitive_files = sources),
),
JSEcmaScriptModuleInfo(
direct_sources = depset(),
sources = sources,
)
]

esm5_sources = rule(
implementation = _esm5_sources,
attrs = {
"deps": attr.label_list(
aspects = [esm5_outputs_aspect],
),
},
)
2 changes: 2 additions & 0 deletions packages/bazel/src/external.bzl
Expand Up @@ -20,6 +20,7 @@ load(
load(
"@build_bazel_rules_nodejs//:providers.bzl",
_NpmPackageInfo = "NpmPackageInfo",
_JSEcmaScriptModuleInfo = "JSEcmaScriptModuleInfo",
_js_ecma_script_module_info = "js_ecma_script_module_info",
_js_named_module_info = "js_named_module_info",
_node_modules_aspect = "node_modules_aspect",
Expand All @@ -40,5 +41,6 @@ DEFAULT_NG_COMPILER = "@npm//@angular/bazel/bin:ngc-wrapped"
DEFAULT_NG_XI18N = "@npm//@angular/bazel/bin:xi18n"
FLAT_DTS_FILE_SUFFIX = ".bundle.d.ts"
TsConfigInfo = _TsConfigInfo
JSEcmaScriptModuleInfo = _JSEcmaScriptModuleInfo
js_ecma_script_module_info = _js_ecma_script_module_info
js_named_module_info = _js_named_module_info
19 changes: 19 additions & 0 deletions packages/bazel/src/ng_package/esm5.bzl
@@ -0,0 +1,19 @@
# Copyright 2017 The Bazel Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Example of a rule that requires ES6 inputs.
"""

load("@build_bazel_rules_nodejs//:providers.bzl", "JSEcmaScriptModuleInfo")

12 changes: 10 additions & 2 deletions tools/defaults.bzl
Expand Up @@ -5,6 +5,7 @@ load("@npm_bazel_jasmine//:index.bzl", _jasmine_node_test = "jasmine_node_test")
load("@npm_bazel_karma//:index.bzl", _karma_web_test = "karma_web_test", _karma_web_test_suite = "karma_web_test_suite", _ts_web_test = "ts_web_test", _ts_web_test_suite = "ts_web_test_suite")
load("@npm_bazel_typescript//:index.bzl", _ts_library = "ts_library")
load("//packages/bazel:index.bzl", _ng_module = "ng_module", _ng_package = "ng_package")
load("//packages/bazel/src:esm5.bzl", "esm5_sources")
load("@npm_bazel_rollup//:index.bzl", _rollup_bundle = "rollup_bundle")
load("@npm_bazel_terser//:index.bzl", "terser_minified")
load("@npm//@babel/cli:index.bzl", "babel")
Expand Down Expand Up @@ -305,7 +306,7 @@ def jasmine_node_test(deps = [], **kwargs):
**kwargs
)

def ng_rollup_bundle(name, deps = [], **kwargs):
def ng_rollup_bundle(name, entry_point, deps = [], **kwargs):
"""Rollup with Build Optimizer
This provides a variant of the [legacy rollup_bundle] rule that works better for Angular apps.
Expand Down Expand Up @@ -335,10 +336,17 @@ def ng_rollup_bundle(name, deps = [], **kwargs):
"@npm//tslib",
"@npm//reflect-metadata",
]
esm5_sources(
name = "esm5_sources",
deps = deps,
)
entry_point_label = entry_point
esm5_entry_point = Label("@%s//%s:%s" % (entry_point_label.workspace_name, entry_point_label.package, "esm5_sources.esm5/" + entry_point_label.name))
_rollup_bundle(
name = name + ".es2015",
config_file = "//tools:ng_rollup_bundle.config.js",
deps = deps,
entry_point = esm5_entry_point,
deps = ":esm5_sources",
**kwargs
)
terser_minified(name = name + ".min.es2015", src = name + ".es2015", sourcemap = False)
Expand Down

0 comments on commit 341ebc4

Please sign in to comment.