feat(react): Expose per-flag subpath exports with typed declarations#145
Open
ygor-infotera wants to merge 2 commits into
Open
feat(react): Expose per-flag subpath exports with typed declarations#145ygor-infotera wants to merge 2 commits into
ygor-infotera wants to merge 2 commits into
Conversation
Two fallouts from the typescript@^6.0.3 bump: - tsup's dts worker injects baseUrl into generated compiler options, which TS 6 rejects with TS5101 (baseUrl deprecated). Every package build failed in the DTS step. Tolerate it via ignoreDeprecations. - TS 6 enforces the inferred rootDir strictly, so the paths mapping to ../core/src fails typecheck with TS6059 in react/vue/solid. Set an explicit monorepo rootDir; with noEmit this has no output effect.
Add a ./flags/* entry to the exports map so each flag is importable as
its own module:
import { FlagBr } from '@sankyu/react-circle-flags/flags/br'
The per-flag bundles already existed in dist/flags/ but were not
reachable through the exports map. Subpath imports guarantee that only
the imported flag lands in the consumer bundle even when the bundler
cannot tree-shake the root barrel — Turbopack (Next.js 16 default)
currently bundles all ~430 flags (~400 kB minified) for a single named
import from the package root.
The postbuild step now generates a .d.ts per flag from the generated
sources (instead of deleting tsup's broken dts chunks): component flags
get a typed declaration mirroring the source signature, alias flags
re-export their target so TypeScript resolves through the sibling
declaration.
Verified: 430 declarations generated; ESM import and CJS require of
both a component flag (flags/br) and an alias flag (flags/uk) resolve
through the exports map; react test suite passes.
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
Adds a
./flags/*entry to@sankyu/react-circle-flags' exports map so each flag is importable as its own module:Why
The per-flag bundles already exist in
dist/flags/but aren't reachable through the exports map. Named imports from the package root rely on the bundler tree-shaking the barrel — and Turbopack (Next.js 16's default bundler) currently can't: a singleimport { FlagBr } from '@sankyu/react-circle-flags'bundles all ~430 flags (~400 kB minified) into the consumer's chunk. We hit this in production: the flags landed in the first load of every route of our Next.js app. Subpath imports guarantee only the imported flag ships, regardless of bundler.What changed
packages/react/package.json—"./flags/*"exports entry (types+import+require)scripts/tasks/postbuild-react.mjs— generates a.d.tsper flag from the generated sources (previously this step deleted tsup's broken per-flag dts chunks). Component flags get a declaration mirroring the source signature; alias flags (e.g.uk→gb) re-export through the sibling declaration so TypeScript resolves the chain.packages/react/README.md— documents the subpath import form and when to prefer itAlso included: TS 6 build unblock (first commit)
maincurrently fails to build/typecheck after the dependabot bump totypescript@^6.0.3(#143):baseUrl, which TS 6 rejects withTS5101TS6059(strict inferredrootDirvs the../core/srcpaths mapping)The first commit fixes both (
ignoreDeprecations: "6.0"+ explicit monoreporootDir, no emit effect undernoEmit). Happy to split it into its own PR if you prefer — the feature commit depends on it to build.Verification
pnpm build:reactpasses; 430 per-flag.d.tsgeneratedimportand CJSrequireof both a component flag (flags/br) and an alias flag (flags/uk) resolve through the exports map from a consumer projectpnpm test:reactpasses; full monorepopnpm typecheckpasses