fix: make yarn build work cleanly (node-modules linker + TypeScript)#501
Merged
Conversation
…ixes) - Switch to nodeLinker: node-modules so tsc can resolve packages properly - Force gl@9.0.0-rc.9 in resolutions to avoid gl@5.0.3 (fails to compile on GCC 13) - Enable allowDeclareFields in babel preset-typescript - Use declare modifier on context class fields (Bus, Node, connectSize) - Fix as unknown as casts in getContext.ts (TS2352) - Fix readonly index signature delete in GLViewDOM and gl-react-headless (TS2542) - Fix version string cast in GLViewDOM (TS2345) - Add globals.d.ts stubs for react-native/__DEV__/global in expo/native packages - Fix build.sh to delete .tsbuildinfo on clean so tsc always regenerates .d.ts - Extend typeRoots in gl-react tsconfig to include @types/node Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
… needs version match)
There was a problem hiding this comment.
Pull request overview
This PR restores a clean yarn build for the monorepo by switching Yarn to a node-modules linker and addressing TypeScript/Babel configuration issues that prevented tsc -b --emitDeclarationOnly from emitting .d.ts outputs.
Changes:
- Switch Yarn to
nodeLinker: node-modulesand pinglvia rootresolutionsto avoid incompatible native builds. - Make the build script reliably rebuild TS declaration output by removing stale
*.tsbuildinfo. - Fix/patch TypeScript compilation issues across packages (class
contextfields, delete on readonly rest props, WebGL context typing workarounds, minimal RN globals stubs, Babel TS preset config).
Reviewed changes
Copilot reviewed 13 out of 16 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
.yarnrc.yml |
Switches Yarn to node-modules linker to restore standard module resolution for tsc. |
package.json |
Pins gl via resolutions to avoid incompatible transitive builds on newer CI toolchains. |
yarn.lock |
Updates lockfile to reflect the linker/resolution changes (notably the gl bump and related dependency graph shifts). |
scripts/build.sh |
Cleans lib and *.tsbuildinfo per package before running Babel + tsc -b --emitDeclarationOnly. |
babel.config.js |
Enables allowDeclareFields to support TS declare class fields under Babel. |
packages/gl-react/tsconfig.json |
Expands typeRoots so @types/* (notably @types/node) are discoverable during composite builds. |
packages/gl-react/src/Node.tsx |
Uses declare context to satisfy TS class field/context typing without emitting runtime fields. |
packages/gl-react/src/connectSize.tsx |
Uses declare context for TS correctness with contextType. |
packages/gl-react/src/Bus.tsx |
Uses declare context for TS correctness with contextType. |
packages/gl-react-dom/src/GLViewDOM.tsx |
Adjusts deletion of rest props for TS and casts version for getContext call. |
packages/gl-react-dom/src/getContext.ts |
Uses unknown double-casts to coerce getContext return types under current typings. |
packages/gl-react-headless/src/index.tsx |
Uses (rest as any)[k] deletion to satisfy TS constraints on rest props. |
packages/gl-react-expo/src/GLViewNative.tsx |
Adds a JSX spread cast to any to bypass TypeScript prop typing issues for expo-gl’s GLView. |
packages/gl-react-expo/src/globals.d.ts |
Adds minimal ambient stubs for react-native, __DEV__, and global to typecheck without RN deps installed. |
packages/gl-react-native/src/globals.d.ts |
Adds minimal ambient stubs for react-native and global to typecheck without RN deps installed. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
57
to
60
| <EXGLView | ||
| {...({} as any)} | ||
| style={[ | ||
| style, |
Comment on lines
176
to
+180
| this.canvas!, | ||
| debug | ||
| ? { ...webglContextAttributes, preserveDrawingBuffer: true } | ||
| : webglContextAttributes, | ||
| version || "auto" | ||
| (version || "auto") as "webgl" | "webgl2" | "auto" |
Comment on lines
6
to
9
| let gl: WebGLRenderingContext | null = null; | ||
| if (version === "webgl2" || version === "auto") { | ||
| gl = canvas.getContext("webgl2", opts) as WebGLRenderingContext | null; | ||
| gl = canvas.getContext("webgl2", opts) as unknown as WebGLRenderingContext | null; | ||
| } |
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.
Problem
yarn buildwas silently broken:tsc -b --emitDeclarationOnlygenerated no.d.tsfilesreact,@types/node, etc.).tsbuildinfofiles made tsc think the build was up-to-date even afterrm -rf libThis also caused the CI publish workflow to fail since
gl@5.0.3(pulled in as a transitive dep) doesn't compile on GCC 13 (Ubuntu 24.04).Changes
.yarnrc.yml: switch tonodeLinker: node-modulesso tsc resolves packages via normal node_modules lookuppackage.jsonresolutions: forcegl@9.0.0-rc.9to avoidgl@5.0.3(incompatible with GCC 13)scripts/build.sh: delete*.tsbuildinfoon clean so tsc always regenerates.d.tsbabel.config.js: enableallowDeclareFieldsfor@babel/preset-typescriptgl-react,gl-react-dom,gl-react-headless,gl-react-expo:declaremodifier oncontextclass fields (TS2612)as unknown asdouble-cast forgetContext.ts(TS2352)(rest as any)[k]for readonly index signature delete (TS2542)as "webgl" | "webgl2" | "auto"cast (TS2345)packages/gl-react-expo/src/globals.d.tsandgl-react-native/src/globals.d.ts: minimal stubs forreact-native,__DEV__, andglobal(RN peer deps not installed in dev)packages/gl-react/tsconfig.json: add../../node_modules/@typestotypeRootsso@types/nodeis foundVerification
yarn build # exits 0, all 5 packages compile with Babel + 27 .d.ts files generated🤖 Generated with Claude Code