Skip to content

Commit

Permalink
build: remove flat module bundle workaround from view engine (#23826)
Browse files Browse the repository at this point in the history
Removes a past flat module bundle workaround that was needed when we
still shipped release packages with View Engine. The Angular compiler
picks the `index.ts` files as entry-point for the flat module bundles
(this whole flat module construct could be removed in the future anyway).

This was problematic because to avoid conflicts, the flat module out
file name was set to something unique that does not conflict with the
index file. The metadata JSON files for the `ng_module` targets (within our repo)
then did not reside next to the `index` files, but rather next to the
auto-generated flat module bundle. This broke the generation of
`defineInjectable` (which was used in VE as well) calls.

We worked around this in the past by patching the Angular compiler to
pick the public API file instead as entry-point; allowing us to let
the Angular compiler generate metadata and the bundle as `index.js` and
`index.metadata.json` (ensuring the release output worked then).

All of this is no longer needed with Ivy, so we can remove the
workaround and unblock angular/angular#43932
(which fails due to us patching some files in the compiler-cli package)

(cherry picked from commit 0fd321f)
  • Loading branch information
devversion authored and wagnermaciel committed Oct 24, 2021
1 parent f802cda commit 1fd4be5
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 31 deletions.
21 changes: 0 additions & 21 deletions tools/defaults.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -108,34 +108,14 @@ def ng_module(
deps = [],
srcs = [],
tsconfig = None,
flat_module_out_file = None,
testonly = False,
**kwargs):
if not tsconfig:
tsconfig = _getDefaultTsConfig(testonly)

# We only generate a flat module if there is a "public-api.ts" file that
# will be picked up by NGC or ngtsc.
needs_flat_module = "public-api.ts" in srcs

# Compute an AMD module name for the target.
module_name = _compute_module_name(testonly)

# Targets which have a module name and are not used for tests, should
# have a default flat module out file named "index". This is necessary
# as imports to that target should go through the flat module bundle.
if needs_flat_module and module_name and not flat_module_out_file and not testonly:
flat_module_out_file = "index"

# Workaround to avoid a lot of changes to the Bazel build rules. Since
# for most targets the flat module out file is "index.js", we cannot
# include "index.ts" (if present) as source-file. This would resolve
# in a conflict in the metadata bundler. Once we switch to Ivy and
# no longer need metadata bundles, we can remove this logic.
if flat_module_out_file == "index":
if "index.ts" in srcs:
srcs.remove("index.ts")

local_deps = [
# Add tslib because we use import helpers for all public packages.
"@npm//tslib",
Expand All @@ -155,7 +135,6 @@ def ng_module(
# NodeJS executions, by activating the Bazel NodeJS linker.
# See: https://github.com/bazelbuild/rules_nodejs/pull/2799.
package_name = module_name,
flat_module_out_file = flat_module_out_file,
strict_templates = True,
deps = local_deps,
tsconfig = tsconfig,
Expand Down
11 changes: 1 addition & 10 deletions tools/postinstall/apply-patches.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const chalk = require('chalk');
* Version of the post install patch. Needs to be incremented when
* existing patches or edits have been modified.
*/
const PATCH_VERSION = 13;
const PATCH_VERSION = 14;

/** Path to the project directory. */
const projectDir = path.join(__dirname, '../..');
Expand Down Expand Up @@ -52,15 +52,6 @@ async function main() {
}

function applyPatches() {
// Workaround for: https://github.com/angular/angular/pull/32650
searchAndReplace(
'let resolvedEntryPoint = null;',
`
let resolvedEntryPoint = tsFiles.find(f => f.endsWith('/public-api.ts')) || null;
`,
'node_modules/@angular/compiler-cli/bundles/index.js',
);

// Switches the devmode output for Angular Bazel to ES2020 target and module.
applyPatch(path.join(__dirname, './devmode-es2020-bazel.patch'));

Expand Down

0 comments on commit 1fd4be5

Please sign in to comment.