From 293f3b07493de5ac1abbdc5696d6965635b6c3a1 Mon Sep 17 00:00:00 2001 From: Charles Lyding <19598772+clydin@users.noreply.github.com> Date: Mon, 11 Sep 2023 11:18:26 -0400 Subject: [PATCH] refactor(@angular-devkit/build-angular): update babel package usage and types based on current versions Newer versions of the babel packages allow for removing some types packages as well as some helper packages. The `@babel/template` package export used within the CLI is accessible from the `@babel/core` package which allows removal of `@babel/template` as a direct dependency. Also, the `@babel/plugin-proposal-async-generator-functions` package has been transitioned to `@babel/plugin-transform-async-generator-functions` due to async generators being merged into the ECMAScript standard. Minor code cleanup based on the type cleanup was also performed in the build optimizer babel passes. --- package.json | 4 +-- .../angular_devkit/build_angular/BUILD.bazel | 4 +-- .../angular_devkit/build_angular/package.json | 3 +- .../build_angular/src/babel-bazel.d.ts | 6 ---- .../plugins/adjust-static-class-members.ts | 7 ++-- .../babel/plugins/adjust-typescript-enums.ts | 2 +- .../src/tools/babel/presets/application.ts | 2 +- .../build_angular/src/typings.d.ts | 2 +- .../build_angular/src/utils/process-bundle.ts | 2 +- yarn.lock | 36 +++++++++++-------- 10 files changed, 32 insertions(+), 36 deletions(-) diff --git a/package.json b/package.json index c8edc3c44ba9..0b1c2b3960da 100644 --- a/package.json +++ b/package.json @@ -80,12 +80,11 @@ "@babel/generator": "7.22.15", "@babel/helper-annotate-as-pure": "7.22.5", "@babel/helper-split-export-declaration": "7.22.6", - "@babel/plugin-proposal-async-generator-functions": "7.20.7", + "@babel/plugin-transform-async-generator-functions": "7.22.5", "@babel/plugin-transform-async-to-generator": "7.22.5", "@babel/plugin-transform-runtime": "7.22.15", "@babel/preset-env": "7.22.15", "@babel/runtime": "7.22.15", - "@babel/template": "7.22.15", "@bazel/bazelisk": "1.18.0", "@bazel/buildifier": "6.3.3", "@bazel/concatjs": "5.8.1", @@ -95,7 +94,6 @@ "@rollup/plugin-commonjs": "^25.0.0", "@rollup/plugin-node-resolve": "^13.0.5", "@types/babel__core": "7.20.1", - "@types/babel__template": "7.4.1", "@types/browser-sync": "^2.27.0", "@types/browserslist": "^4.15.0", "@types/express": "^4.16.0", diff --git a/packages/angular_devkit/build_angular/BUILD.bazel b/packages/angular_devkit/build_angular/BUILD.bazel index 3d69c0c3961c..8d1f1147d466 100644 --- a/packages/angular_devkit/build_angular/BUILD.bazel +++ b/packages/angular_devkit/build_angular/BUILD.bazel @@ -137,15 +137,13 @@ ts_library( "@npm//@babel/generator", "@npm//@babel/helper-annotate-as-pure", "@npm//@babel/helper-split-export-declaration", - "@npm//@babel/plugin-proposal-async-generator-functions", + "@npm//@babel/plugin-transform-async-generator-functions", "@npm//@babel/plugin-transform-async-to-generator", "@npm//@babel/plugin-transform-runtime", "@npm//@babel/preset-env", "@npm//@babel/runtime", - "@npm//@babel/template", "@npm//@discoveryjs/json-ext", "@npm//@types/babel__core", - "@npm//@types/babel__template", "@npm//@types/browser-sync", "@npm//@types/browserslist", "@npm//@types/inquirer", diff --git a/packages/angular_devkit/build_angular/package.json b/packages/angular_devkit/build_angular/package.json index 840faf63728d..b1086a9cb2ef 100644 --- a/packages/angular_devkit/build_angular/package.json +++ b/packages/angular_devkit/build_angular/package.json @@ -14,12 +14,11 @@ "@babel/generator": "7.22.15", "@babel/helper-annotate-as-pure": "7.22.5", "@babel/helper-split-export-declaration": "7.22.6", - "@babel/plugin-proposal-async-generator-functions": "7.20.7", + "@babel/plugin-transform-async-generator-functions": "7.22.5", "@babel/plugin-transform-async-to-generator": "7.22.5", "@babel/plugin-transform-runtime": "7.22.15", "@babel/preset-env": "7.22.15", "@babel/runtime": "7.22.15", - "@babel/template": "7.22.15", "@discoveryjs/json-ext": "0.5.7", "@ngtools/webpack": "0.0.0-PLACEHOLDER", "@vitejs/plugin-basic-ssl": "1.0.1", diff --git a/packages/angular_devkit/build_angular/src/babel-bazel.d.ts b/packages/angular_devkit/build_angular/src/babel-bazel.d.ts index f52defff2b1e..e6504d1651d8 100644 --- a/packages/angular_devkit/build_angular/src/babel-bazel.d.ts +++ b/packages/angular_devkit/build_angular/src/babel-bazel.d.ts @@ -15,9 +15,3 @@ declare module '@babel/core' { declare module '@babel/generator' { export { default } from '@types/babel__generator'; } -declare module '@babel/traverse' { - export { default } from '@types/babel__traverse'; -} -declare module '@babel/template' { - export { default } from '@types/babel__template'; -} diff --git a/packages/angular_devkit/build_angular/src/tools/babel/plugins/adjust-static-class-members.ts b/packages/angular_devkit/build_angular/src/tools/babel/plugins/adjust-static-class-members.ts index dcc5dae54a3a..226c135fd5bd 100644 --- a/packages/angular_devkit/build_angular/src/tools/babel/plugins/adjust-static-class-members.ts +++ b/packages/angular_devkit/build_angular/src/tools/babel/plugins/adjust-static-class-members.ts @@ -105,7 +105,7 @@ function analyzeClassSiblings( const wrapStatementPaths: NodePath[] = []; let hasPotentialSideEffects = false; for (let i = 1; ; ++i) { - const nextStatement = origin.getSibling(+origin.key + i); + const nextStatement = origin.getSibling(+(origin.key ?? 0) + i); if (!nextStatement.isExpressionStatement()) { break; } @@ -213,7 +213,7 @@ export default function (): PluginObj { // to a subsequent statement to prevent a JavaScript syntax error. ExportDefaultDeclaration(path: NodePath, state: PluginPass) { const declaration = path.get('declaration'); - if (!declaration.isClassDeclaration()) { + if (!declaration.isClassDeclaration() || !declaration.node.id) { return; } @@ -232,7 +232,8 @@ export default function (): PluginObj { const { node: classNode, parentPath } = path; const { wrapDecorators } = state.opts as { wrapDecorators: boolean }; - if (visitedClasses.has(classNode)) { + // Skip if already visited or has no name + if (visitedClasses.has(classNode) || !classNode.id) { return; } diff --git a/packages/angular_devkit/build_angular/src/tools/babel/plugins/adjust-typescript-enums.ts b/packages/angular_devkit/build_angular/src/tools/babel/plugins/adjust-typescript-enums.ts index 0554e738fa46..93495b7b0c22 100644 --- a/packages/angular_devkit/build_angular/src/tools/babel/plugins/adjust-typescript-enums.ts +++ b/packages/angular_devkit/build_angular/src/tools/babel/plugins/adjust-typescript-enums.ts @@ -46,7 +46,7 @@ export default function (): PluginObj { const hasExport = parentPath.isExportNamedDeclaration() || parentPath.isExportDefaultDeclaration(); const origin = hasExport ? parentPath : path; - const nextStatement = origin.getSibling(+origin.key + 1); + const nextStatement = origin.getSibling(+(origin.key ?? 0) + 1); if (!nextStatement.isExpressionStatement()) { return; } diff --git a/packages/angular_devkit/build_angular/src/tools/babel/presets/application.ts b/packages/angular_devkit/build_angular/src/tools/babel/presets/application.ts index 830e6cdcd9c1..e67f6a183b83 100644 --- a/packages/angular_devkit/build_angular/src/tools/babel/presets/application.ts +++ b/packages/angular_devkit/build_angular/src/tools/babel/presets/application.ts @@ -242,7 +242,7 @@ export default function (api: unknown, options: ApplicationPresetOptions) { // Always transform async/await to support Zone.js plugins.push( require('@babel/plugin-transform-async-to-generator').default, - require('@babel/plugin-proposal-async-generator-functions').default, + require('@babel/plugin-transform-async-generator-functions').default, ); needRuntimeTransform = true; } diff --git a/packages/angular_devkit/build_angular/src/typings.d.ts b/packages/angular_devkit/build_angular/src/typings.d.ts index 2468d5b261ba..a4845f8c9d15 100644 --- a/packages/angular_devkit/build_angular/src/typings.d.ts +++ b/packages/angular_devkit/build_angular/src/typings.d.ts @@ -14,7 +14,7 @@ declare module '@babel/helper-annotate-as-pure' { declare module '@babel/helper-split-export-declaration' { export default function splitExportDeclaration( - exportDeclaration: import('@babel/traverse').NodePath< + exportDeclaration: import('@babel/core').NodePath< import('@babel/types').ExportDefaultDeclaration >, ): void; diff --git a/packages/angular_devkit/build_angular/src/utils/process-bundle.ts b/packages/angular_devkit/build_angular/src/utils/process-bundle.ts index e492e04e1bbd..96b26bda3507 100644 --- a/packages/angular_devkit/build_angular/src/utils/process-bundle.ts +++ b/packages/angular_devkit/build_angular/src/utils/process-bundle.ts @@ -11,12 +11,12 @@ import { NodePath, ParseResult, parseSync, + template as templateBuilder, transformAsync, transformFromAstSync, traverse, types, } from '@babel/core'; -import templateBuilder from '@babel/template'; import * as fs from 'fs/promises'; import * as path from 'path'; import { workerData } from 'worker_threads'; diff --git a/yarn.lock b/yarn.lock index bf6356f82936..13ecc51304ad 100644 --- a/yarn.lock +++ b/yarn.lock @@ -122,8 +122,7 @@ tslib "^2.3.0" "@angular/bazel@https://github.com/angular/bazel-builds.git#209efddd1c2cac304183971c2259e70a4a7b5f7b": - version "17.0.0-next.3+sha-05762b9" - uid "209efddd1c2cac304183971c2259e70a4a7b5f7b" + version "17.0.0-next.3" resolved "https://github.com/angular/bazel-builds.git#209efddd1c2cac304183971c2259e70a4a7b5f7b" dependencies: "@microsoft/api-extractor" "^7.24.2" @@ -140,7 +139,6 @@ "@angular/build-tooling@https://github.com/angular/dev-infra-private-build-tooling-builds.git#a870de5389e6533dd007b46512942249e7c82e95": version "0.0.0-c95355fd247d8003f18dcd2f1a410b906566cab6" - uid a870de5389e6533dd007b46512942249e7c82e95 resolved "https://github.com/angular/dev-infra-private-build-tooling-builds.git#a870de5389e6533dd007b46512942249e7c82e95" dependencies: "@angular-devkit/build-angular" "16.2.0-rc.1" @@ -301,7 +299,6 @@ "@angular/ng-dev@https://github.com/angular/dev-infra-private-ng-dev-builds.git#3e0d49e91578f0aa9ff6972ef7979df18c126c68": version "0.0.0-c95355fd247d8003f18dcd2f1a410b906566cab6" - uid "3e0d49e91578f0aa9ff6972ef7979df18c126c68" resolved "https://github.com/angular/dev-infra-private-ng-dev-builds.git#3e0d49e91578f0aa9ff6972ef7979df18c126c68" dependencies: "@yarnpkg/lockfile" "^1.1.0" @@ -820,6 +817,16 @@ dependencies: "@babel/helper-plugin-utils" "^7.22.5" +"@babel/plugin-transform-async-generator-functions@7.22.5": + version "7.22.5" + resolved "https://registry.yarnpkg.com/@babel/plugin-transform-async-generator-functions/-/plugin-transform-async-generator-functions-7.22.5.tgz#7336356d23380eda9a56314974f053a020dab0c3" + integrity sha512-gGOEvFzm3fWoyD5uZq7vVTD57pPJ3PczPUD/xCFGjzBpUosnklmXyKnGQbbbGs1NPNPskFex0j93yKbHt0cHyg== + dependencies: + "@babel/helper-environment-visitor" "^7.22.5" + "@babel/helper-plugin-utils" "^7.22.5" + "@babel/helper-remap-async-to-generator" "^7.22.5" + "@babel/plugin-syntax-async-generators" "^7.8.4" + "@babel/plugin-transform-async-generator-functions@^7.22.15", "@babel/plugin-transform-async-generator-functions@^7.22.7": version "7.22.15" resolved "https://registry.yarnpkg.com/@babel/plugin-transform-async-generator-functions/-/plugin-transform-async-generator-functions-7.22.15.tgz#3b153af4a6b779f340d5b80d3f634f55820aefa3" @@ -1436,15 +1443,6 @@ dependencies: regenerator-runtime "^0.13.11" -"@babel/template@7.22.15", "@babel/template@^7.22.15", "@babel/template@^7.22.5": - version "7.22.15" - resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.22.15.tgz#09576efc3830f0430f4548ef971dde1350ef2f38" - integrity sha512-QPErUVm4uyJa60rkI73qneDacvdvzxshT3kksGqlGWYdOTIUOwJ7RDUL8sGqslY1uXWSL6xMFKEXDS3ox2uF0w== - dependencies: - "@babel/code-frame" "^7.22.13" - "@babel/parser" "^7.22.15" - "@babel/types" "^7.22.15" - "@babel/template@7.22.5": version "7.22.5" resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.22.5.tgz#0c8c4d944509875849bd0344ff0050756eefc6ec" @@ -1454,6 +1452,15 @@ "@babel/parser" "^7.22.5" "@babel/types" "^7.22.5" +"@babel/template@^7.22.15", "@babel/template@^7.22.5": + version "7.22.15" + resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.22.15.tgz#09576efc3830f0430f4548ef971dde1350ef2f38" + integrity sha512-QPErUVm4uyJa60rkI73qneDacvdvzxshT3kksGqlGWYdOTIUOwJ7RDUL8sGqslY1uXWSL6xMFKEXDS3ox2uF0w== + dependencies: + "@babel/code-frame" "^7.22.13" + "@babel/parser" "^7.22.15" + "@babel/types" "^7.22.15" + "@babel/traverse@^7.22.15", "@babel/traverse@^7.22.17", "@babel/traverse@^7.22.5", "@babel/traverse@^7.22.8": version "7.22.17" resolved "https://registry.yarnpkg.com/@babel/traverse/-/traverse-7.22.17.tgz#b23c203ab3707e3be816043081b4a994fcacec44" @@ -3301,7 +3308,7 @@ dependencies: "@babel/types" "^7.0.0" -"@types/babel__template@*", "@types/babel__template@7.4.1": +"@types/babel__template@*": version "7.4.1" resolved "https://registry.yarnpkg.com/@types/babel__template/-/babel__template-7.4.1.tgz#3d1a48fd9d6c0edfd56f2ff578daed48f36c8969" integrity sha512-azBFKemX6kMg5Io+/rdGT0dkGreboUVR0Cdm3fz9QJWpaQGJRQXl7C+6hOTCZcMll7KFyEQpgbYI2lHdsS4U7g== @@ -11079,7 +11086,6 @@ sass@1.66.1, sass@^1.55.0: "sauce-connect-proxy@https://saucelabs.com/downloads/sc-4.9.1-linux.tar.gz": version "0.0.0" - uid "9310bc860f7870a1f872b11c4dc6073a1ad34e5e" resolved "https://saucelabs.com/downloads/sc-4.9.1-linux.tar.gz#9310bc860f7870a1f872b11c4dc6073a1ad34e5e" saucelabs@^1.5.0: