Skip to content

Commit

Permalink
refactor(@angular-devkit/build-angular): exclude `@angular/platform-s…
Browse files Browse the repository at this point in the history
…erver/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)
  • Loading branch information
alan-agius4 committed Apr 27, 2023
1 parent e690b7c commit 4d8de73
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,9 @@ describe('adjust-typescript-enums Babel plugin', () => {
`,
expected: `
var ChangeDetectionStrategy = /*#__PURE__*/ (() => {
(function (ChangeDetectionStrategy) {
ChangeDetectionStrategy[ChangeDetectionStrategy["OnPush"] = 0] = "OnPush";
ChangeDetectionStrategy[ChangeDetectionStrategy["Default"] = 1] = "Default";
})(ChangeDetectionStrategy || (ChangeDetectionStrategy = {}));
ChangeDetectionStrategy = ChangeDetectionStrategy || {};
ChangeDetectionStrategy[(ChangeDetectionStrategy["OnPush"] = 0)] = "OnPush";
ChangeDetectionStrategy[(ChangeDetectionStrategy["Default"] = 1)] = "Default";
return ChangeDetectionStrategy;
})();
`,
Expand All @@ -64,10 +63,9 @@ describe('adjust-typescript-enums Babel plugin', () => {
`,
expected: `
export var ChangeDetectionStrategy = /*#__PURE__*/ (() => {
(function (ChangeDetectionStrategy) {
ChangeDetectionStrategy[ChangeDetectionStrategy["OnPush"] = 0] = "OnPush";
ChangeDetectionStrategy[ChangeDetectionStrategy["Default"] = 1] = "Default";
})(ChangeDetectionStrategy || (ChangeDetectionStrategy = {}));
ChangeDetectionStrategy = ChangeDetectionStrategy || {};
ChangeDetectionStrategy[(ChangeDetectionStrategy["OnPush"] = 0)] = "OnPush";
ChangeDetectionStrategy[(ChangeDetectionStrategy["Default"] = 1)] = "Default";
return ChangeDetectionStrategy;
})();
`,
Expand All @@ -85,10 +83,9 @@ describe('adjust-typescript-enums Babel plugin', () => {
`,
expected: `
export var ChangeDetectionStrategy = /*#__PURE__*/ (() => {
(function (ChangeDetectionStrategy) {
ChangeDetectionStrategy[ChangeDetectionStrategy["OnPush"] = 5] = "OnPush";
ChangeDetectionStrategy[ChangeDetectionStrategy["Default"] = 8] = "Default";
})(ChangeDetectionStrategy || (ChangeDetectionStrategy = {}));
ChangeDetectionStrategy = ChangeDetectionStrategy || {};
ChangeDetectionStrategy[(ChangeDetectionStrategy["OnPush"] = 5)] = "OnPush";
ChangeDetectionStrategy[(ChangeDetectionStrategy["Default"] = 8)] = "Default";
return ChangeDetectionStrategy;
})();
`,
Expand All @@ -98,20 +95,19 @@ describe('adjust-typescript-enums Babel plugin', () => {
it('wraps string-based TypeScript enums', () => {
testCase({
input: `
var NotificationKind;
(function (NotificationKind) {
NotificationKind["NEXT"] = "N";
NotificationKind["ERROR"] = "E";
NotificationKind["COMPLETE"] = "C";
})(NotificationKind || (NotificationKind = {}));
var NotificationKind;
(function (NotificationKind) {
NotificationKind["NEXT"] = "N";
NotificationKind["ERROR"] = "E";
NotificationKind["COMPLETE"] = "C";
})(NotificationKind || (NotificationKind = {}));
`,
expected: `
var NotificationKind = /*#__PURE__*/ (() => {
(function (NotificationKind) {
NotificationKind["NEXT"] = "N";
NotificationKind["ERROR"] = "E";
NotificationKind["COMPLETE"] = "C";
})(NotificationKind || (NotificationKind = {}));
NotificationKind = NotificationKind || {};
NotificationKind["NEXT"] = "N";
NotificationKind["ERROR"] = "E";
NotificationKind["COMPLETE"] = "C";
return NotificationKind;
})();
`,
Expand Down Expand Up @@ -165,15 +161,14 @@ describe('adjust-typescript-enums Babel plugin', () => {
* @deprecated use @angular/common/http instead
*/
var RequestMethod = /*#__PURE__*/ (() => {
(function (RequestMethod) {
RequestMethod[RequestMethod["Get"] = 0] = "Get";
RequestMethod[RequestMethod["Post"] = 1] = "Post";
RequestMethod[RequestMethod["Put"] = 2] = "Put";
RequestMethod[RequestMethod["Delete"] = 3] = "Delete";
RequestMethod[RequestMethod["Options"] = 4] = "Options";
RequestMethod[RequestMethod["Head"] = 5] = "Head";
RequestMethod[RequestMethod["Patch"] = 6] = "Patch";
})(RequestMethod || (RequestMethod = {}));
RequestMethod = RequestMethod || {};
RequestMethod[(RequestMethod["Get"] = 0)] = "Get";
RequestMethod[(RequestMethod["Post"] = 1)] = "Post";
RequestMethod[(RequestMethod["Put"] = 2)] = "Put";
RequestMethod[(RequestMethod["Delete"] = 3)] = "Delete";
RequestMethod[(RequestMethod["Options"] = 4)] = "Options";
RequestMethod[(RequestMethod["Head"] = 5)] = "Head";
RequestMethod[(RequestMethod["Patch"] = 6)] = "Patch";
return RequestMethod;
})();
`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ async function transformWithBabel({
return useInputSourcemap ? data : data.replace(/^\/\/# sourceMappingURL=[^\r\n]*/gm, '');
}

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

// Lazy load the linker plugin only when linking is required
if (shouldLink) {
Expand Down Expand Up @@ -86,7 +89,7 @@ async function transformWithBabel({
},
forceAsyncTransformation,
optimize: options.advancedOptimizations && {
pureTopLevel: angularPackage,
pureTopLevel: safeAngularPackage,
},
},
],
Expand Down

0 comments on commit 4d8de73

Please sign in to comment.