build: fix ng_package & ng_rollup_bundle windows issues (#33607)

Fixes ng_package and ng_rollup_bundle rollup issue on Windows where .js file was resolved by bazel resolved instead of .mjs file as there is no sandbox.

Fixes https://github.com/angular/angular/issues/32603 by passing globals and external through templated rollup config as Windows CLI argument limit can be easily exceeded. Also fixes this for ng_rollup_bundle.

PR Close #33607
This commit is contained in:
Greg Magolan
2019-11-05 16:56:25 -08:00
committed by atscott
parent 1c22e464b2
commit cf598f71fd
4 changed files with 44 additions and 25 deletions

View File

@ -255,6 +255,12 @@ def _write_rollup_config(ctx, root_dir, build_optimizer, filename = "_%s.rollup.
(dep.label, k, mappings[k], v)), "deps")
mappings[k] = v
globals = {}
external = []
if ctx.attr.globals:
globals = ctx.attr.globals.items()
external = ctx.attr.globals.keys()
ctx.actions.expand_template(
output = config,
template = ctx.file._rollup_config_tmpl,
@ -266,6 +272,8 @@ def _write_rollup_config(ctx, root_dir, build_optimizer, filename = "_%s.rollup.
"TMPL_root_dir": root_dir,
"TMPL_stamp_data": "\"%s\"" % ctx.version_file.path if ctx.version_file else "undefined",
"TMPL_workspace_name": ctx.workspace_name,
"TMPL_external": ", ".join(["'%s'" % e for e in external]),
"TMPL_globals": ", ".join(["'%s': '%s'" % g for g in globals]),
},
)
@ -295,12 +303,6 @@ def _run_rollup(ctx, entry_point_path, sources, config):
args.add("--preserveSymlinks")
if ctx.attr.globals:
args.add("--external")
args.add_joined(ctx.attr.globals.keys(), join_with = ",")
args.add("--globals")
args.add_joined(["%s:%s" % g for g in ctx.attr.globals.items()], join_with = ",")
direct_inputs = [config]
# Also include files from npm fine grained deps as inputs.

View File

@ -117,6 +117,13 @@ function resolveBazel(
}
if (resolved) {
if (path.extname(resolved) == '.js') {
// check for .mjs file and prioritize that
const resolved_mjs = resolved.substr(0, resolved.length - 3) + '.mjs';
if (fileExists(resolved_mjs)) {
resolved = resolved_mjs;
}
}
log_verbose(`resolved to ${resolved}`);
} else {
log_verbose(`allowing rollup to resolve '${importee}' with node module resolution`);
@ -174,8 +181,10 @@ if (bannerFile) {
const config = {
plugins,
external: [TMPL_external],
output: {
banner,
globals: {TMPL_globals},
banner,
}
};