👷 fix typecheck for unbuilt json-schema-to-typescript fork#148
Conversation
- add ambient module declaration so typecheck passes without dist - lazy-load compile fn with build-on-demand fallback
There was a problem hiding this comment.
Pull request overview
This PR addresses TypeScript resolution/runtime issues caused by using an unbuilt GitHub fork of json-schema-to-typescript (no prepare, so dist/ may be missing after install), by adding a local ambient module declaration and making the schema generation script dynamically import (and build) the fork on demand.
Changes:
- Add an ambient
declare module 'json-schema-to-typescript'to allowyarn typecheckto succeed even when the fork’sdist/isn’t present. - Update
scripts/generate-schema-types.tsto lazilyimport('json-schema-to-typescript'), auto-building the fork when the import initially fails, and caching the resolvedcompilefunction.
Reviewed changes
Copilot reviewed 1 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| scripts/lib/global.d.ts | Adds a local ambient module declaration for json-schema-to-typescript to unblock typechecking when the fork isn’t built. |
| scripts/generate-schema-types.ts | Switches to a cached dynamic import and adds a fallback build step when the module isn’t importable due to missing build output. |
cdn34dd
left a comment
There was a problem hiding this comment.
Is there any news if this will land at some point so we can get rid of the github fork ? I looked into it, and found this PR from you from 2020 (bcherny/json-schema-to-typescript#353) :D.
But if I understood the issue correctly we get the issue due to the fork not having a dist/ folder because it's not a published package, and the fix is to lazy load the module instead of statically , so if dist/ is missing we build the fork before trying it import correct ? But how did we not notice this for so long ?
No, no news.
I have stumbled upon it from time to time when starting a new worktree, I never took the time to do something about it before. |
Motivation
The
json-schema-to-typescriptdependency is a GitHub fork that addsreadonlysupport not yet in the official package. Because the fork has nopreparescript, yarn never builds itsdist/during install, causingyarn typecheckto fail withCannot find module 'json-schema-to-typescript'.This mirrors how
browser-sdkhandles the same fork.Changes
scripts/lib/global.d.ts) so TypeScript can resolve the import without a builtdist/generate-schema-types.tsto a lazy dynamic import that auto-builds the fork ifdist/is missing, with a module-level cache to avoid redundant builds across schemasTest instructions
node_modules/json-schema-to-typescript/distto simulate a fresh install stateyarn typecheck— should pass without errorsyarn json-schemas:generate— should auto-build the fork and regenerate typesChecklist