Repository navigation
fix(schematics): ship shared util chunks and load the build as CommonJS (#DS-5799) - #2262
Open
lskramarov wants to merge 2 commits into
Open
lskramarov wants to merge 2 commits into
lskramarov wants to merge 2 commits into
Conversation
…JS (#DS-5799)
Rollup put the utils shared by several entries into hashed chunks at the root of
packages/schematics/dist, which copy-meta-to-dist.js does not ship: ng-add and every
migration failed with MODULE_NOT_FOUND. Every src/utils module is now a rollup entry.
ng-packagr 21 writes "type": "module" into dist/components/package.json, so Node loaded
the CommonJS schematics as ES modules ("exports is not defined in ES module scope"). The
build now ships schematics/package.json with "type": "commonjs" and re-includes it in the
.npmignore that ng-packagr writes to drop nested manifests.
build:schematics ends with check-dist.js: every require() and import() of the shipped
files resolves, every collection factory loads, and npm pack keeps every file.
|
Visit the preview URL for this PR (updated for commit 8443fe5): https://koobiq-next--prs-2262-d8zqm75w.web.app (expires Fri, 30 Oct 2026 18:57:44 GMT) 🔥 via Firebase Hosting GitHub Action 🌎 Sign: c9e37e518febda70d0317d07e8ceb35ac43c534c |
…onsumers load them (#DS-5799) The build emits .cjs, which stays CommonJS whatever the package type, so the nested manifest and the .npmignore rule that re-included it are gone; the shipped collections point at .cjs factories. A module shared by several entries goes into utils/, which ships whole. Util entries skip .d.ts, and the build fails when shipped code imports test tooling. The copy step starts from an empty schematics directory, so a removed migration does not stay in the package. check-dist.mjs reads require() and import() from the syntax tree, resolves import() with the ESM conditions, accepts only packages that consumers have, rejects .js modules, follows the manifest fields to the collections and checks schemas and factory-less entries. The npm pack check moves to check-npm-resolution, which already packs the package and prints npm's output on failure.
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.
Summary
Both
ng add @koobiq/componentsandng updateto 21 are broken in the published 21.0.0: the schematics indist/components/schematicsfail to load, for two independent reasons.packages/schematics/dist(package-config-*.js,replacement-driver-*.js,signal-members-migration-*.js, …).copy-meta-to-dist.jscopies onlyng-add/,migrations/andutils/, song-add, two util facades and all 88 migrations require a file that is not in the package (MODULE_NOT_FOUND)."type": "module"intodist/components/package.json(packageJson.type ??= 'module'). The schematics are CommonJS.js, so Node loads them as ES modules and fails withexports is not defined in ES module scope. This error hides the first one: fixing only the module type still leavesMODULE_NOT_FOUND.List of notable changes:
rollup.config.js: the build emits.cjs, which Node loads as CommonJS whatever the package type (as@angular/coreships its schematics). Everysrc/utils/*.tsexcept specs,.d.tsandtesting.tsis an entry of its own; any other module shared by several entries goes intoutils/[name]-[hash].cjs. The build fails when shipped code imports test tooling (vitest,*/testing).copy-meta-to-dist.js: starts from an emptydist/components/schematics, copies the.cjsmodules and writescollection.json/migrations.jsonwith.cjsfactories (require.resolve()does not try.cjs; the sources stay extension-less for the specs).scripts/check-dist.mjs, run at the end ofbuild:schematics: no.jsmodule ships; everyrequire()/import()(read from the syntax tree) names a file of the package or a package consumers have — non-optional peers,tslib,@angular-devkit/schematics,@schematics/angular,@angular/compiler,typescript— and resolves,import()with the ESM conditions; the collections are found through the manifest'sschematicsandng-update.migrations, every factory loads with a plainrequire()(asExportStringRefdoes) and exports a function, every schema parses.tools/check-npm-resolution: packs with--jsonand fails when the tarball leaves out a file ofschematics/.What should reviewers focus on?
build:schematicsrelies onbuild:componentshaving run first (the copy step writes intodist/components);build-packagesalready runs them in that order..jsmodule, a package consumers lack, a missing util, a factory-less entry, a broken schema);require('…')inside strings and comments is ignored; a stale migration directory is removed by the copy step; rollup rejects a util that imports@angular-devkit/schematics/testingand ignores a.d.ts; a module shared by two migrations ships asutils/<name>-<hash>.cjs;check-npm-resolutionfails when.npmignoredrops a schematics file. A tarball fromnpm packof the fixeddist/componentsrunsng-addand all 82ng updatemigrations throughSchematicTestRunner; the published 21.0.0 fails on every one.type, and every util there has an entry), so there are no backports.