feat(package): expose subpath exports for lighter consumer imports#238
Open
tsushanth wants to merge 1 commit into
Open
feat(package): expose subpath exports for lighter consumer imports#238tsushanth wants to merge 1 commit into
tsushanth wants to merge 1 commit into
Conversation
Closes square#237. The default `import { SquareClient } from 'square'` entry transitively loads every API resource client, every Fern-generated type module, and the ~1,300 runtime serialization schemas under `serialization/types/`. On boot-sensitive workloads (serverless cold starts, autoscaling), the total dominates startup time — the reporter measured ~600 ms just from the require on an M3 MacBook Air, with `serialization/index.js` alone accounting for 12 % of the boot path. The SDK's surface is already split across small directories at the package root after `prepack` copies `dist/.` over — `./api/`, `./serialization/`, `./Client.js`, `./environments.js`, `./errors/` — but the `exports` map only published `.` and `./legacy`, so consumers who wanted to opt out couldn't reach the internal modules through a supported path. Adding subpath entries (with `types` mappings so TypeScript's nodenext / bundler resolvers find the declarations) lets them import only the slice they need: ```ts import type { Payment } from 'square/api/types/Payment'; import { PaymentsClient } from 'square/api/resources/payments'; import { Payment as PaymentSchema } from 'square/serialization/types/Payment'; import { SquareClient } from 'square/Client'; ``` The default `import { SquareClient } from 'square'` entry is unchanged and remains the recommended import for typical usage; the new entries are strictly additive. README gets a short subsection under "Usage" pointing at the new import paths and the cold-start motivation. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Closes #237.
The problem
The default
import { SquareClient } from 'square'entry transitively loads every API resource client, every Fern-generated type module, and the ~1,300 runtime serialization schemas underserialization/types/. On boot-sensitive workloads (serverless cold starts, autoscaling instances) the total dominates startup time — the issue reporter measured ~600 ms just fromrequire('square')on an M3 MacBook Air, withserialization/index.jsalone accounting for 12 % of the boot path.The SDK's surface is already split across small directories at the package root after
prepackcopiesdist/.over (./api/,./serialization/,./Client.js,./environments.js,./errors/), but theexportsmap only publishes.and./legacy, so consumers who want to opt out can't reach the internal modules through a supported path.The change
Add subpath entries — each with a
typesmapping so TypeScript'snodenext/bundlerresolvers find the declarations — that let consumers import only the slice they need:The default
import { SquareClient } from 'square'entry is unchanged and remains the recommended import for typical usage — the new entries are strictly additive, no existing call site changes shape.README gets a short
### Subpath importssubsection under## Usagepointing at the new import paths and the cold-start motivation, so the next person reading the docs after awiz/lighthouse/ cold-start profile knows the supported escape hatch.What this doesn't do
This doesn't make the default
squareentry itself faster — the eager re-exports insrc/index.tsand the Fern-generated cascade still pull in everything. That looks like a separate (and bigger) discussion about how the generator structures the umbrella module; happy to follow up there if there's appetite.