fix(schematics): drop the @schematics/angular runtime import - #123
Merged
Conversation
add-dependencies.ts imported '@schematics/angular/utility/dependencies' at runtime, but the package was only a devDependency. npm's flat node_modules made it resolve by accident; under pnpm's isolated layout `ng g @angular-architects/native-federation:init` failed with "Cannot find package '@schematics/angular'". Only addPackageJsonDependency and NodeDependencyType were used, so replace them with a local helper following the readJson/overwrite pattern already used in update-package-json.ts, and remove the dependency instead of promoting it to a runtime one.
getFederationArg's default branch (--type=remote) returned
`{ '<project>': './remoteEntry.json' }`, so a generated remote passed a
map pointing at its own remoteEntry. Return an empty arg instead.
Also reformats the file to prettier's double-quote/trailing-comma style.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
ng g @angular-architects/native-federation:initfails on pnpm:add-dependencies.tsimported@schematics/angular/utility/dependenciesat runtime, but the package was only listed indevDependencies, so it never shipped in the publishedpackage.json. npm's flatnode_modulesmakes it resolve by accident (@angular/clihoists it to the top); pnpm's isolated layout does not — the package's ownnode_modulesonly contains its declared deps, and it isn't in the virtual store's hoist dir either.Reproduces on a stock
ng newapp with pnpm as package manager. Affects every pnpm user runninginit.Fix
Only
addPackageJsonDependencyand theNodeDependencyTypeenum were used, so rather than promoting@schematics/angularto a runtime dependency, they're replaced with a local helper following thereadJson→ mutate →overwritepattern already used inupdate-package-json.tsandwire-serve-ssr-script.ts. The dependency is removed entirely — it was the only import site in the repo.Semantics are unchanged (
overwritestill means "replace if present"). One behavioural difference:addPackageJsonDependencyusedJSONFile, which edits surgically and preserves the user's formatting, whereas this rewrites the file with 2-space indent. That's already what the two steps above do in the same schematic run, so nothing is lost in practice.Also included
4fd8430—getFederationArg's--type=remotebranch emitted{ '<project>': './remoteEntry.json' }, so a generated remote passed a map pointing at its own remoteEntry. Now emitsinitFederation()with no argument. The file is also reformatted to prettier's double-quote/trailing-comma style.Verification
pnpm typecheckpnpm lintpnpm buildpnpm knippnpm testgrep -r @schematics/angular dist/Note
21.x.xcarries the identical bug ("@schematics/angular": "^21.2.0"indevDependencies, same single import site) — not ported here.