Repository navigation
fix(schematics): require only exported devkit paths from the shipped schematics - #3793
armando-navarro wants to merge 1 commit into
Conversation
…schematics @angular-devkit/schematics 22.3 adds an exports map that allows ./tasks but not ./tasks/index.js. The shipped setup, deploy builder and v21 migration bundles required tasks/index.js, so `ng update` crashed after installing whenever it ran a 22.3 CLI, and the v21 migration never ran. The source keeps the index.js spelling, which the ESM spec run needs while the repo's devkit 21 has no exports map. An esbuild alias rewrites it in the bundles, and the build now fails when a bundle requires a package subpath that is not in exportedSubpaths, naming the importers. typescript stays external so the v21 migration uses the compiler from the user's workspace at ng update time, rather than adding about 3.5 MB to the package.
tyler-reitz
left a comment
There was a problem hiding this comment.
LGTM. Two notes, neither blocking.
Verified the fix by loading the built bundles rather than reading the diff. All six load against @angular-devkit/schematics 21.2.25 and 22.3.0-next.0; the published canary fails under 22.3.0-next.0 on setup/index.js, deploy/builder.js and update/v21/index.js with ERR_PACKAGE_PATH_NOT_EXPORTED, the three files you name. Deleting the alias and rebuilding does produce the guard error, so the new check can actually fail.
One thing to fix if you agree: the move into externalPackages drops the comment explaining why typescript is external (tools/build.ts:407-408 on main, the one about resolving it at ng-update time instead of bundling ~3.5MB). Nothing fails if someone later removes that entry, the package just gets bigger quietly, so it is worth moving the comment along with the entry.
Observation only: exportedSubpaths is never checked against a real exports map, though the comment says each entry is in one. rxjs@next (9.0.0-beta.0) has no ./operators export, so that entry is already stale for the newest rxjs. Harmless while the peer is ~7.8.0, but the build cannot notice if an entry goes bad.
Fixes #3789
The shipped schematics now require
@angular-devkit/schematics/tasks, which every devkit version accepts, instead of@angular-devkit/schematics/tasks/index.js, which theexportsmap in devkit 22.3 rejects.Changes
All in
compileSchematicsintools/build.ts.aliasrewrites@angular-devkit/schematics/tasks/index.jsto@angular-devkit/schematics/tasksin the bundles.index.jsspelling, because the ESM spec run cannot import the baretasksfolder from the repo's devkit 21, which has noexportsmap.exportedSubpaths, and names the files that import it. The list holds@angular-devkit/schematics/tasks,@schematics/angular/utilityandrxjs/operators, each of which is in its package'sexportsmap.externalPackagesconstant, which the check reads.Behavior to know
When the repo's own devkit reaches 22.3 or later, the two source imports can switch to
@angular-devkit/schematics/tasksand the alias can go.Verification
@angular-devkit/schematics21.2.25 and 22.3.0-next.0. With the current canary,setup/index.js,deploy/builder.jsandupdate/v21/index.jsfail under 22.3.0-next.0.npm run test:node: 342 specs, 0 failures.