Repository navigation
build(schematics): keep only architect declared, bundle jsonc-parser - #3808
Conversation
The published manifest declared five build-time packages that only the schematics and the ng deploy builder use. The Angular CLI runs schematics installed under node_modules/@angular/ through its own loader, which supplies @angular-devkit/* and @schematics/* from the CLI's copy, so declaring @angular-devkit/schematics, @angular-devkit/core and @schematics/angular never changed which copy ran. They leave the manifest, and jsonc-parser, the one package the schematics had to resolve on their own, is bundled. @angular-devkit/architect stays: the architect host loads the deploy builder with a plain require, outside that loader. The deploy bundles stop importing the schematic packages (the .firebaserc helper moves out of utils.ts, SchematicsException becomes Error), and the build now fails if a deploy bundle requires a package the manifest does not declare. On a build of this commit, ng add and the deploy builder load under Yarn Plug'n'Play and pnpm hoist=false, and the full ng add command works through a registry on npm. The same change built before angular#3803 merged ran the wider set of yarn and pnpm layouts and the ng update migration. A production install of a CLI app lists 112 packages instead of 136. Fixes angular#3694 Refs angular#3746
# Conflicts: # src/ng-package.json
tyler-reitz
left a comment
There was a problem hiding this comment.
One follow-up: the body says the upgrade-guide note lands with docs/version-22-upgrade.md from #3805, but #3805 merged without it. Nothing documents yet that on pnpm with hoist=false, a locally installed schematics command needs @angular-devkit/schematics, @angular-devkit/core and @schematics/angular declared at the workspace root. Worth adding to that guide in a follow-up.
|
I added the missing upgrade-guide note to this PR (78a08eb). It's a new "Fewer build-time packages" section at the end of |
Checklist
peerDependenciesordevDependencies#3694 (required)docs/version-22-upgrade.md.yarn install,yarn testrun successfully?: yes, with npm (npm ci,npm run build,npm run build:jasmine && npm run test:node)Description
Fixes #3694.
The published manifest declared five build-time packages that only the schematics and the
ng deploybuilder use:@angular-devkit/architect,@angular-devkit/core,@angular-devkit/schematics,@schematics/angularandjsonc-parser. After this change it declares one.What changes
@angular-devkit/schematics,@angular-devkit/coreand@schematics/angularleavedependencies.jsonc-parseris bundled into the schematics (an esbuild alias to its ESM entry, since its UMDmaincannot be bundled). Of the five, it was the one the schematics had to resolve on their own.@angular-devkit/architectstays declared.builder.tsimported a.firebaserchelper fromutils.ts, whose module-level imports esbuild kept, andactions.tsthrewSchematicsExceptionwhereErrorprints the same message.Why the three can leave and
architectcannotnode_modules/@angular/, this one included, through its own module loader (schematic-engine-host.js).@angular-devkit/*and@schematics/*from the CLI's own copy and falls back to its copy of@angular-devkit/core.@angular/cdk,@angular/material,@angular/ssrand@angular/localizeship the same way.require, outside that loader, so the builder must find@angular-devkit/architecton its own.What was measured
On fresh Angular 22 apps:
ng addand the deploy builder under Yarn Plug'n'Play and under pnpm 9 withhoist=false, and the fullng add @angular/firecommand through a local registry on npm 11.ng addand the deploy builder on yarn 1, yarn 4 (both linkers), pnpm 9 in five layouts and pnpm 10, and theng updatemigration on npm 11 and Yarn Plug'n'Play.npm ci --omit=dev, thennpm ls --omit=dev), and@schematics/angularwith itsoxc-parserdependency leaves it.Compatibility
Not a breaking change.
schematicscommand) have no module loader of their own and resolve these packages from the workspace. Nx's Angular template declares the three at the workspace root, andnx g @angular/fire:ng-addandnx run <project>:deployreach the same points as under the CLI on pnpm's default layout.hoist=false, a locally installedschematicscommand needs the workspace root to declare@angular-devkit/schematics,@angular-devkit/coreand@schematics/angular.Relation to #3746
node_modules/.pnpm/node_modules.architectfor the builder.Refs #3746