Skip to content

Commit 4d8de73

Browse files
committed
refactor(@angular-devkit/build-angular): exclude @angular/platform-server/init from unsafe optimizations in esbuild
While currently esbuild is not use to bundle server bundles, it will in the future. This commit adds a check for the `@angular/platform-server/init` entry-point to be excluded from advanced optimizations. (cherry picked from commit 4a38e8a)
1 parent e690b7c commit 4d8de73

File tree

2 files changed

+32
-34
lines changed

2 files changed

+32
-34
lines changed

packages/angular_devkit/build_angular/src/babel/plugins/adjust-typescript-enums_spec.ts

Lines changed: 27 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,9 @@ describe('adjust-typescript-enums Babel plugin', () => {
4343
`,
4444
expected: `
4545
var ChangeDetectionStrategy = /*#__PURE__*/ (() => {
46-
(function (ChangeDetectionStrategy) {
47-
ChangeDetectionStrategy[ChangeDetectionStrategy["OnPush"] = 0] = "OnPush";
48-
ChangeDetectionStrategy[ChangeDetectionStrategy["Default"] = 1] = "Default";
49-
})(ChangeDetectionStrategy || (ChangeDetectionStrategy = {}));
46+
ChangeDetectionStrategy = ChangeDetectionStrategy || {};
47+
ChangeDetectionStrategy[(ChangeDetectionStrategy["OnPush"] = 0)] = "OnPush";
48+
ChangeDetectionStrategy[(ChangeDetectionStrategy["Default"] = 1)] = "Default";
5049
return ChangeDetectionStrategy;
5150
})();
5251
`,
@@ -64,10 +63,9 @@ describe('adjust-typescript-enums Babel plugin', () => {
6463
`,
6564
expected: `
6665
export var ChangeDetectionStrategy = /*#__PURE__*/ (() => {
67-
(function (ChangeDetectionStrategy) {
68-
ChangeDetectionStrategy[ChangeDetectionStrategy["OnPush"] = 0] = "OnPush";
69-
ChangeDetectionStrategy[ChangeDetectionStrategy["Default"] = 1] = "Default";
70-
})(ChangeDetectionStrategy || (ChangeDetectionStrategy = {}));
66+
ChangeDetectionStrategy = ChangeDetectionStrategy || {};
67+
ChangeDetectionStrategy[(ChangeDetectionStrategy["OnPush"] = 0)] = "OnPush";
68+
ChangeDetectionStrategy[(ChangeDetectionStrategy["Default"] = 1)] = "Default";
7169
return ChangeDetectionStrategy;
7270
})();
7371
`,
@@ -85,10 +83,9 @@ describe('adjust-typescript-enums Babel plugin', () => {
8583
`,
8684
expected: `
8785
export var ChangeDetectionStrategy = /*#__PURE__*/ (() => {
88-
(function (ChangeDetectionStrategy) {
89-
ChangeDetectionStrategy[ChangeDetectionStrategy["OnPush"] = 5] = "OnPush";
90-
ChangeDetectionStrategy[ChangeDetectionStrategy["Default"] = 8] = "Default";
91-
})(ChangeDetectionStrategy || (ChangeDetectionStrategy = {}));
86+
ChangeDetectionStrategy = ChangeDetectionStrategy || {};
87+
ChangeDetectionStrategy[(ChangeDetectionStrategy["OnPush"] = 5)] = "OnPush";
88+
ChangeDetectionStrategy[(ChangeDetectionStrategy["Default"] = 8)] = "Default";
9289
return ChangeDetectionStrategy;
9390
})();
9491
`,
@@ -98,20 +95,19 @@ describe('adjust-typescript-enums Babel plugin', () => {
9895
it('wraps string-based TypeScript enums', () => {
9996
testCase({
10097
input: `
101-
var NotificationKind;
102-
(function (NotificationKind) {
103-
NotificationKind["NEXT"] = "N";
104-
NotificationKind["ERROR"] = "E";
105-
NotificationKind["COMPLETE"] = "C";
106-
})(NotificationKind || (NotificationKind = {}));
98+
var NotificationKind;
99+
(function (NotificationKind) {
100+
NotificationKind["NEXT"] = "N";
101+
NotificationKind["ERROR"] = "E";
102+
NotificationKind["COMPLETE"] = "C";
103+
})(NotificationKind || (NotificationKind = {}));
107104
`,
108105
expected: `
109106
var NotificationKind = /*#__PURE__*/ (() => {
110-
(function (NotificationKind) {
111-
NotificationKind["NEXT"] = "N";
112-
NotificationKind["ERROR"] = "E";
113-
NotificationKind["COMPLETE"] = "C";
114-
})(NotificationKind || (NotificationKind = {}));
107+
NotificationKind = NotificationKind || {};
108+
NotificationKind["NEXT"] = "N";
109+
NotificationKind["ERROR"] = "E";
110+
NotificationKind["COMPLETE"] = "C";
115111
return NotificationKind;
116112
})();
117113
`,
@@ -165,15 +161,14 @@ describe('adjust-typescript-enums Babel plugin', () => {
165161
* @deprecated use @angular/common/http instead
166162
*/
167163
var RequestMethod = /*#__PURE__*/ (() => {
168-
(function (RequestMethod) {
169-
RequestMethod[RequestMethod["Get"] = 0] = "Get";
170-
RequestMethod[RequestMethod["Post"] = 1] = "Post";
171-
RequestMethod[RequestMethod["Put"] = 2] = "Put";
172-
RequestMethod[RequestMethod["Delete"] = 3] = "Delete";
173-
RequestMethod[RequestMethod["Options"] = 4] = "Options";
174-
RequestMethod[RequestMethod["Head"] = 5] = "Head";
175-
RequestMethod[RequestMethod["Patch"] = 6] = "Patch";
176-
})(RequestMethod || (RequestMethod = {}));
164+
RequestMethod = RequestMethod || {};
165+
RequestMethod[(RequestMethod["Get"] = 0)] = "Get";
166+
RequestMethod[(RequestMethod["Post"] = 1)] = "Post";
167+
RequestMethod[(RequestMethod["Put"] = 2)] = "Put";
168+
RequestMethod[(RequestMethod["Delete"] = 3)] = "Delete";
169+
RequestMethod[(RequestMethod["Options"] = 4)] = "Options";
170+
RequestMethod[(RequestMethod["Head"] = 5)] = "Head";
171+
RequestMethod[(RequestMethod["Patch"] = 6)] = "Patch";
177172
return RequestMethod;
178173
})();
179174
`,

packages/angular_devkit/build_angular/src/builders/browser-esbuild/javascript-transformer-worker.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,10 @@ async function transformWithBabel({
5555
return useInputSourcemap ? data : data.replace(/^\/\/# sourceMappingURL=[^\r\n]*/gm, '');
5656
}
5757

58-
const angularPackage = /[\\/]node_modules[\\/]@angular[\\/]/.test(filename);
58+
// @angular/platform-server/init entry-point has side-effects.
59+
const safeAngularPackage =
60+
/[\\/]node_modules[\\/]@angular[\\/]/.test(filename) &&
61+
!/@angular[\\/]platform-server[\\/]f?esm2022[\\/]init/.test(filename);
5962

6063
// Lazy load the linker plugin only when linking is required
6164
if (shouldLink) {
@@ -86,7 +89,7 @@ async function transformWithBabel({
8689
},
8790
forceAsyncTransformation,
8891
optimize: options.advancedOptimizations && {
89-
pureTopLevel: angularPackage,
92+
pureTopLevel: safeAngularPackage,
9093
},
9194
},
9295
],

0 commit comments

Comments
 (0)