feat(builders): keep prebuilt entry points out of the TypeScript program - #133
Closed
Aukevanoost wants to merge 1 commit into
Closed
Aukevanoost wants to merge 1 commit into
Aukevanoost wants to merge 1 commit into
Conversation
A shared mapping may point at a library's build output rather than its source (`"@org/ui": ["dist/ui"]`), which is what stops ngtsc emitting deep relative imports into a mapped library and evaluating it twice. Such an entry point is already-compiled JS: esbuild loads it through the linker like any dependency, and listing it in the federation tsconfig's `files` only makes ngtsc reject it as a non-TypeScript root file. Core now marks every entry point `'source'` or `'package'`, so the decision is one it already made rather than something inferred here from a file extension. Nothing changes for existing setups: exposes and source mappings are both `'source'`, and a host whose mappings are all prebuilt still falls back to the app's own entry points to keep the program non-empty. Requires @softarc/native-federation with EntryPoint.kind.
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.
Adapter half of native-federation/native-federation-core#122 —
sharedMappingslibraries being evaluated twice at runtime (
NG0201).Why
The duplication is structural in ngtsc: metadata derived from source never carries
bestGuessOwningModule, so a synthesized reference to a path-mapped library fallsthrough to
RelativePathStrategyand emits a deep relative import, which bypasses thebundler's
externallist. The fix on the core side is to let a mapping point at alibrary's build output instead of its source:
With the library's
.d.tsoutside the app's TypeScript program,AbsoluteModuleStrategysucceeds and the import is emitted bare. Verified end-to-end: the second copy disappears
from the app bundle and the federated chunk becomes the only one.
What this changes
Such an entry point is already-compiled JS. esbuild loads it through the linker like any
dependency, but listing it in the federation tsconfig's
filesmakes ngtsc reject it:Core now marks every entry point
'source'or'package', soupdateFederationTsConfigfilters on a decision core already made rather than inferring one here from a file
extension.
Compatibility
Not a breaking change. Exposes and source mappings are both
'source', so the emittedfilesarray is identical for every setup that exists today — only the new prebuilt shapeis filtered out. A host whose mappings are all prebuilt still falls back to the app's own
entry points, so the program is never empty.
Worth noting this is the only adapter change the feature needs. The generic esbuild adapter
already resolves
.mjs/.jsentry points and never constructs a TypeScript program, so itworks with prebuilt mappings untouched — this is Angular-specific because ngtsc is.
Blocked on
@softarc/native-federationwithEntryPoint.kind. The~4.5.0pin means the core releasehas to land first; draft until then.
Testing
pnpm test201 passing (2 new), typecheck and lint clean. Also exercised against a realAngular 22 workspace with one mapping repointed at
dist.