# dedupe

Shared-first-party dedupe: an additive post-emit pass that lifts first-party modules inlined into multiple per-entry bundles into shared `_shared/<srcPath>/index.<fmt>.js` chunks and rewrites each consuming entry to import them. Runs over the already-bundled [`esm`](https://www.hyperfrontend.dev/docs/libraries/builder/models/#api-BuildConfig-prop-esm)/[`cjs`](https://www.hyperfrontend.dev/docs/libraries/builder/models/#api-BuildConfig-prop-cjs) outputs only, leaving per-entry isolated bundling intact.

`hoistSharedFirstParty(...)` is the entry point. It only hoists copies that [`planHoists`](https://www.hyperfrontend.dev/docs/libraries/builder/bundle/dedupe/#api-planHoists) proves safe — structurally identical, references resolvable, and initialization cycle-free — so the worst case is output identical to the input.

The pass is built from composable stages, each exported for direct use: module attribution ([`attribute`](https://www.hyperfrontend.dev/docs/libraries/builder/bundle/dedupe/#api-attribute), [`indexOwners`](https://www.hyperfrontend.dev/docs/libraries/builder/bundle/dedupe/#api-indexOwners), [`parseEntry`](https://www.hyperfrontend.dev/docs/libraries/builder/bundle/dedupe/#api-parseEntry)), source reachability ([`collectReachableSources`](https://www.hyperfrontend.dev/docs/libraries/builder/bundle/dedupe/#api-collectReachableSources)), chunk planning and extraction ([`planHoists`](https://www.hyperfrontend.dev/docs/libraries/builder/bundle/dedupe/#api-planHoists), [`renderChunk`](https://www.hyperfrontend.dev/docs/libraries/builder/bundle/dedupe/#api-renderChunk), [`resolveModuleRefs`](https://www.hyperfrontend.dev/docs/libraries/builder/bundle/dedupe/#api-resolveModuleRefs)), and entry rewriting ([`rewriteEntry`](https://www.hyperfrontend.dev/docs/libraries/builder/bundle/dedupe/#api-rewriteEntry)).

Ownership is bounded to modules reachable from the entry points' sources, so a spec-only fixture can never own a name, and reference classification is scope-aware ([`collectFreeRefs`](https://github.com/AndrewRedican/hyperfrontend/tree/main/libs/builder/src/bundle/dedupe)), so a parameter that shadows an owned name never becomes an import edge.

---

Canonical page: https://www.hyperfrontend.dev/docs/libraries/builder/bundle/dedupe/
This file: https://www.hyperfrontend.dev/docs/libraries/builder/bundle/dedupe.md
Documentation index: https://www.hyperfrontend.dev/llms.txt
