Skip to content

Commit 01e7ff6

Browse files
alxhubmhevery
authored andcommitted
test(ivy): todo app only includes reflect-metadata in JIT mode (angular#24677)
Previously the todo app imported reflect-metadata, since it is a dependency of JIT and the todo app tests run in both JIT and AOT modes. However, the code doesn't get tree-shaken away in AOT mode. This change adds a target //packages/core/test/bundling/util:reflect_metadata which, depending on whether the compile flag is in JIT or AOT mode, either includes reflect-metadata or is a no-op. Not including reflect-metadata gets the compressed todo bundle down to 12.5 kB. PR Close angular#24677
1 parent 34c4283 commit 01e7ff6

File tree

7 files changed

+61
-1
lines changed

7 files changed

+61
-1
lines changed

packages/core/test/bundling/todo/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ ng_module(
1414
deps = [
1515
"//packages/common",
1616
"//packages/core",
17+
"//packages/core/test/bundling/util:reflect_metadata",
1718
],
1819
)
1920

@@ -31,6 +32,7 @@ ng_rollup_bundle(
3132
":todo",
3233
"//packages/common",
3334
"//packages/core",
35+
"//packages/core/test/bundling/util:reflect_metadata",
3436
],
3537
)
3638

packages/core/test/bundling/todo/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import 'reflect-metadata';
9+
import '@angular/core/test/bundling/util/src/reflect_metadata';
1010

1111
import {CommonModule, NgForOf, NgIf} from '@angular/common';
1212
import {Component, Injectable, IterableDiffers, NgModule, defineInjector, ɵNgOnChangesFeature as NgOnChangesFeature, ɵdefineDirective as defineDirective, ɵdirectiveInject as directiveInject, ɵinjectTemplateRef as injectTemplateRef, ɵinjectViewContainerRef as injectViewContainerRef, ɵrenderComponent as renderComponent} from '@angular/core';
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package(default_visibility = ["//visibility:public"])
2+
3+
load("//tools:defaults.bzl", "ts_library")
4+
5+
# Either loads reflect-metadata or is a no-op, depending on whether compilation is in JIT mode.
6+
ts_library(
7+
name = "reflect_metadata",
8+
srcs = [
9+
"src/reflect_metadata_jit.ts",
10+
"src/reflect_metadata_legacy.ts",
11+
"src/reflect_metadata_local.ts",
12+
":metadata_switch",
13+
],
14+
module_name = "@angular/core/test/bundling/util/src/reflect_metadata",
15+
)
16+
17+
# See packages/core/BUILD.bazel.
18+
genrule(
19+
name = "metadata_switch",
20+
outs = ["src/reflect_metadata.ts"],
21+
cmd = "echo import \"'./reflect_metadata_$(compile)';\" > $@",
22+
)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* @license
3+
* Copyright Google Inc. All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
import './reflect_metadata_legacy';
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* @license
3+
* Copyright Google Inc. All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
import 'reflect-metadata';
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* @license
3+
* Copyright Google Inc. All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
export const UNUSED = true;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* @license
3+
* Copyright Google Inc. All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
export const UNUSED = true;

0 commit comments

Comments
 (0)