Skip to content

Commit 966d25b

Browse files
clydindgp1130
authored andcommittedMar 23, 2022
fix(@angular-devkit/build-angular): remove unneeded JIT reflect metadata polyfill
Since Angular 8, the CLI has transformed decorator metadata to a form that can be used by the Angular dependency injector without the TDZ limitations of Typescript's decorator metadata emit feature. As a result, a JIT application compiled with the CLI no longer requires the reflect metadata polyfill that was provided by `core-js`. This polyfill was also the last remaining usage of the `core-js` package within `@angular-devkit/build-angular` which allows the `core-js` package to also be removed. Refs: #14473 & angular/angular#37382 BREAKING CHANGE: Reflect metadata polyfill is no longer automatically provided in JIT mode Reflect metadata support is not required by Angular in JIT applications compiled by the CLI. Applications built in AOT mode did not and will continue to not provide the polyfill. For the majority of applications, the reflect metadata polyfill removal should have no effect. However, if an application uses JIT mode and also uses the previously polyfilled reflect metadata JavaScript APIs, the polyfill will need to be manually added to the application after updating. To replicate the previous behavior, the `core-js` package should be manually installed and the `import 'core-js/proposals/reflect-metadata';` statement should be added to the application's `polyfills.ts` file.
1 parent e4f7b5e commit 966d25b

File tree

9 files changed

+29
-64
lines changed

9 files changed

+29
-64
lines changed
 

‎package.json

-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@
130130
"cacache": "16.0.2",
131131
"chokidar": "^3.5.2",
132132
"copy-webpack-plugin": "10.2.4",
133-
"core-js": "3.21.1",
134133
"critters": "0.0.16",
135134
"css-loader": "6.7.1",
136135
"debug": "^4.1.1",

‎packages/angular_devkit/build_angular/BUILD.bazel

-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ ts_library(
131131
"@npm//browserslist",
132132
"@npm//cacache",
133133
"@npm//copy-webpack-plugin",
134-
"@npm//core-js",
135134
"@npm//critters",
136135
"@npm//css-loader",
137136
"@npm//esbuild",

‎packages/angular_devkit/build_angular/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
"browserslist": "^4.9.1",
2828
"cacache": "16.0.2",
2929
"copy-webpack-plugin": "10.2.4",
30-
"core-js": "3.21.1",
3130
"critters": "0.0.16",
3231
"css-loader": "6.7.1",
3332
"esbuild-wasm": "0.14.27",

‎packages/angular_devkit/build_angular/src/webpack/configs/common.ts

-9
Original file line numberDiff line numberDiff line change
@@ -123,15 +123,6 @@ export async function getCommonConfig(wco: WebpackConfigOptions): Promise<Config
123123
entryPoints['polyfills'] = [projectPolyfills];
124124
}
125125
}
126-
127-
if (!buildOptions.aot) {
128-
const jitPolyfills = require.resolve('core-js/proposals/reflect-metadata');
129-
if (entryPoints['polyfills']) {
130-
entryPoints['polyfills'].push(jitPolyfills);
131-
} else {
132-
entryPoints['polyfills'] = [jitPolyfills];
133-
}
134-
}
135126
}
136127

137128
if (allowedCommonJsDependencies) {

‎packages/angular_devkit/build_webpack/test/angular-app/src/polyfills.ts

-22
Original file line numberDiff line numberDiff line change
@@ -26,28 +26,6 @@
2626
* BROWSER POLYFILLS
2727
*/
2828

29-
/** IE9, IE10 and IE11 requires all of the following polyfills. **/
30-
// import 'core-js/es6/symbol';
31-
// import 'core-js/es6/object';
32-
// import 'core-js/es6/function';
33-
// import 'core-js/es6/parse-int';
34-
// import 'core-js/es6/parse-float';
35-
// import 'core-js/es6/number';
36-
// import 'core-js/es6/math';
37-
// import 'core-js/es6/string';
38-
// import 'core-js/es6/date';
39-
// import 'core-js/es6/array';
40-
// import 'core-js/es6/regexp';
41-
// import 'core-js/es6/map';
42-
// import 'core-js/es6/weak-map';
43-
// import 'core-js/es6/set';
44-
45-
/** IE10 and IE11 requires the following for NgClass support on SVG elements */
46-
// import 'classlist.js'; // Run `npm install --save classlist.js`.
47-
48-
/** IE10 and IE11 requires the following for the Reflect API. */
49-
// import 'core-js/es6/reflect';
50-
5129
/**
5230
* Required to support Web Animations `@angular/platform-browser/animations`.
5331
* Needed for: All but Chrome, Firefox and Opera. http://caniuse.com/#feat=web-animation

‎tests/legacy-cli/e2e/assets/webpack/test-app/app/main.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import 'core-js/proposals/reflect-metadata';
21
import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
32
import {AppModule} from './app.module';
43

‎tests/legacy-cli/e2e/assets/webpack/test-app/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
"@angular/platform-server": "^13.1.0-next",
1212
"@angular/router": "^13.1.0-next",
1313
"@ngtools/webpack": "0.0.0",
14-
"core-js": "^3.10.0",
1514
"rxjs": "^6.6.7",
1615
"zone.js": "^0.11.4"
1716
},

‎tests/legacy-cli/e2e/tests/build/polyfills.ts

-6
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,16 @@ export default async function () {
1111
await ng('build', '--aot=false', '--configuration=development');
1212

1313
// files were created successfully
14-
await expectFileToMatch('dist/test-project/polyfills.js', 'core-js/proposals/reflect-metadata');
1514
await expectFileToMatch('dist/test-project/polyfills.js', 'zone.js');
1615
await expectFileToMatch(
1716
'dist/test-project/index.html',
1817
'<script src="polyfills.js" type="module">',
1918
);
20-
const jitPolyfillSize = await getFileSize('dist/test-project/polyfills.js');
2119

2220
await ng('build', '--aot=true', '--configuration=development');
2321

2422
// files were created successfully
2523
await expectFileToExist('dist/test-project/polyfills.js');
26-
await expectFileSizeToBeUnder('dist/test-project/polyfills.js', jitPolyfillSize);
27-
await expectToFail(() =>
28-
expectFileToMatch('dist/test-project/polyfills.js', 'core-js/proposals/reflect-metadata'),
29-
);
3024
await expectFileToMatch('dist/test-project/polyfills.js', 'zone.js');
3125
await expectFileToMatch(
3226
'dist/test-project/index.html',
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,33 @@
11
import { writeFile, writeMultipleFiles } from '../../utils/fs';
22
import { ng } from '../../utils/process';
33

4-
54
export default function () {
65
// TODO(architect): Figure out what a minimal config is for architect apps.
76
return;
87

98
return Promise.resolve()
10-
.then(() => writeFile('angular.json', JSON.stringify({
11-
apps: [{
12-
root: 'src',
13-
main: 'main.ts',
14-
scripts: [
15-
'../node_modules/core-js/client/shim.min.js',
16-
'../node_modules/zone.js/dist/zone.js'
17-
]
18-
}],
19-
e2e: { protractor: { config: './protractor.conf.js' } }
20-
})))
9+
.then(() =>
10+
writeFile(
11+
'angular.json',
12+
JSON.stringify({
13+
apps: [
14+
{
15+
root: 'src',
16+
main: 'main.ts',
17+
scripts: ['../node_modules/zone.js/dist/zone.js'],
18+
},
19+
],
20+
e2e: { protractor: { config: './protractor.conf.js' } },
21+
}),
22+
),
23+
)
2124
.then(() => ng('e2e', 'test-project-e2e'))
22-
.then(() => writeMultipleFiles({
23-
'./src/script.js': `
25+
.then(() =>
26+
writeMultipleFiles({
27+
'./src/script.js': `
2428
document.querySelector('app-root').innerHTML = '<h1>app works!</h1>';
2529
`,
26-
'./e2e/app.e2e-spec.ts': `
30+
'./e2e/app.e2e-spec.ts': `
2731
import { browser, element, by } from 'protractor';
2832
2933
describe('minimal project App', function() {
@@ -35,13 +39,16 @@ export default function () {
3539
});
3640
});
3741
`,
38-
'angular.json': JSON.stringify({
39-
apps: [{
40-
root: 'src',
41-
scripts: ['./script.js']
42-
}],
43-
e2e: { protractor: { config: './protractor.conf.js' } }
42+
'angular.json': JSON.stringify({
43+
apps: [
44+
{
45+
root: 'src',
46+
scripts: ['./script.js'],
47+
},
48+
],
49+
e2e: { protractor: { config: './protractor.conf.js' } },
50+
}),
4451
}),
45-
}))
52+
)
4653
.then(() => ng('e2e', 'test-project-e2e'));
4754
}

0 commit comments

Comments
 (0)
Please sign in to comment.