fix: ship with zero runtime dependencies, and check it - #10
Merged
Merged
Conversation
Bundlephobia reported "1 dependency" for 0.0.2, beside a README that says none. The dependency was tslib, and the built code never imported it: the published FESM imports exactly one module, @angular/core, which is a peer. It got there because ng-packagr injects tslib into the built package.json unconditionally whenever a library does not declare it — there is no option to turn that off, so removing it from the source package.json is not enough. - Remove the declaration from the library's package.json. - Set importHelpers: false in the library tsconfig, so any helper TypeScript ever needs is inlined rather than imported from tslib. Output is unchanged today (8.6 KB, byte-identical size) because an ES2022 target needs none. - strip-tslib.mjs removes the entry ng-packagr writes, as part of build:lib, so `npm run release` publishes the corrected file. - verify-deps.mjs fails if package.json declares any dependency, or if the built code imports any module that is not a declared peer. The second check is what makes stripping safe: a build that genuinely needed tslib would fail CI rather than break a consumer. - CI runs it on every pull request. Confirmed the check catches the bug before trusting it: against the 0.0.2 build it fails with "package.json declares dependencies: tslib"; after the fix it passes. 185 tests pass, and verify:compat installs the tarball and builds a real app cleanly on Angular 17 and 22.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This branch was successfully deployed
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.
Bundlephobia reported "1 dependency" for 0.0.2, beside a README that says none. The dependency was tslib, and the built code never imported it: the published FESM imports exactly one module, @angular/core, which is a peer.
It got there because ng-packagr injects tslib into the built package.json unconditionally whenever a library does not declare it — there is no option to turn that off, so removing it from the source package.json is not enough.
npm run releasepublishes the corrected file.Confirmed the check catches the bug before trusting it: against the 0.0.2 build it fails with "package.json declares dependencies: tslib"; after the fix it passes. 185 tests pass, and verify:compat installs the tarball and builds a real app cleanly on Angular 17 and 22.
What does this change?
How to see it
Checks
npm testpassesnpm run formatrun on the files I touchednpm run verify:compat, if I changed anything public (builds a real app on Angular 17–22)