From 2e270bb96a162af797bfc80f06cff3dd1c523877 Mon Sep 17 00:00:00 2001 From: Alex Eagle Date: Thu, 12 Apr 2018 17:43:27 -0700 Subject: [PATCH] build: include tslib in umd bundles (#23354) Fixes #22971 PR Close #23354 --- packages/bazel/src/ng_package/ng_package.bzl | 11 ++++++++--- packages/bazel/test/ng_package/core_package.spec.ts | 6 ++++-- tools/defaults.bzl | 5 +---- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/packages/bazel/src/ng_package/ng_package.bzl b/packages/bazel/src/ng_package/ng_package.bzl index 68e5218456..93ed711413 100644 --- a/packages/bazel/src/ng_package/ng_package.bzl +++ b/packages/bazel/src/ng_package/ng_package.bzl @@ -76,7 +76,7 @@ WELL_KNOWN_GLOBALS = { p: _global_name(p) for p in [ "rxjs/operators", ]} -def _rollup(ctx, rollup_config, entry_point, inputs, js_output, format = "es", package_name = ""): +def _rollup(ctx, rollup_config, entry_point, inputs, js_output, format = "es", package_name = "", include_tslib = False): map_output = ctx.actions.declare_file(js_output.basename + ".map", sibling = js_output) args = ctx.actions.args() @@ -96,7 +96,10 @@ def _rollup(ctx, rollup_config, entry_point, inputs, js_output, format = "es", p globals = dict(WELL_KNOWN_GLOBALS, **ctx.attr.globals) args.add("--external") - args.add(globals.keys(), join_with=",") + external = globals.keys() + if not include_tslib: + external.append("tslib") + args.add(external, join_with=",") args.add("--globals") args.add(["%s:%s" % g for g in globals.items()], join_with=",") @@ -220,7 +223,9 @@ def _ng_package_impl(ctx): fesm2015.append(_rollup(ctx, config, es2015_entry_point, esm_2015_files, fesm2015_output)) fesm5.append(_rollup(ctx, config, es5_entry_point, esm5_sources, fesm5_output)) - bundles.append(_rollup(ctx, config, es5_entry_point, esm5_sources, umd_output, format = "umd", package_name = package_name)) + bundles.append( + _rollup(ctx, config, es5_entry_point, esm5_sources, 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)) diff --git a/packages/bazel/test/ng_package/core_package.spec.ts b/packages/bazel/test/ng_package/core_package.spec.ts index b41dcd45f9..5950889318 100644 --- a/packages/bazel/test/ng_package/core_package.spec.ts +++ b/packages/bazel/test/ng_package/core_package.spec.ts @@ -178,8 +178,10 @@ describe('@angular/core ng_package', () => { .toMatch(/@license Angular v\d+\.\d+\.\d+(?!-PLACEHOLDER)/); }); - it('should have tslib helpers', - () => { expect(shx.cat('bundles/core.umd.js')).not.toContain('undefined.__extends'); }); + it('should have tslib helpers', () => { + expect(shx.cat('bundles/core.umd.js')).toContain('function __extends'); + expect(shx.cat('bundles/core.umd.js')).not.toContain('undefined.__extends'); + }); it('should have an AMD name', () => { expect(shx.cat('bundles/core.umd.js')).toContain('define(\'@angular/core\''); }); it('should define ng global symbols', diff --git a/tools/defaults.bzl b/tools/defaults.bzl index 0a5ad0026a..20bfb625c2 100644 --- a/tools/defaults.bzl +++ b/tools/defaults.bzl @@ -48,7 +48,7 @@ def ng_module(name, tsconfig = None, entry_point = None, **kwargs): entry_point = "public_api.ts" _ng_module(name = name, flat_module_out_file = name, tsconfig = tsconfig, entry_point = entry_point, **kwargs) -def ng_package(name, readme_md = None, license_banner = None, globals = {}, **kwargs): +def ng_package(name, readme_md = None, license_banner = None, **kwargs): if not readme_md: readme_md = "//packages:README.md" if not license_banner: @@ -58,9 +58,6 @@ def ng_package(name, readme_md = None, license_banner = None, globals = {}, **kw name = name, readme_md = readme_md, license_banner = license_banner, - globals = dict(globals, **{ - "tslib": "tslib" - }), replacements = PKG_GROUP_REPLACEMENTS, **kwargs)