Repository navigation
Split node/browser builds with conditional exports - #100
Merged
Merged
Conversation
Runtime `is_node()` branching is replaced by a build-time `#platform` alias, resolved by `tsconfig.node.json` / `tsconfig.browser.json` to `src/platform/node` or `src/platform/browser`. The same source now produces two runtime trees (`lib/node`, `lib/browser`) sharing one set of declarations, wired through `exports` conditions plus explicit `tgrid/node` and `tgrid/browser` subpaths. - browser bundle imports only `tstl`; no `ws`, `http`, `fs`, `child_process` or `worker_threads` references remain - node platform imports its modules statically; `import2` dependency and `NodeModule` / `WebSocketPolyfill` indirections are removed - `IWorkerChannel` abstracts the worker-to-parent channel so `WorkerServer` no longer branches on `self.document` - browser tests compile through `test/browser/tsconfig.json`; `test_worker_compiler` runs a node-platform bundle instead of the browser one Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AQaTBspPxvUiYtTCbC8Tcg
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AQaTBspPxvUiYtTCbC8Tcg
- `react-native` export condition maps to the browser tree instead of falling through to the node default - `sideEffects: false` for bundler tree-shaking - `src/typings`: rename `Object` type parameters to `Wrapper` and mark the intentional `Function` / wrapper-object usages with scoped eslint-disable comments; `npx eslint src` is now clean. No type semantics changed. - version 1.3.0 (new subpaths and exports shape) Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AQaTBspPxvUiYtTCbC8Tcg
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
WebSocketServer,WorkerConnector,SharedWorkerServeretc. behave differently in NodeJS and browsers, but that difference lived only at runtime (is_node()branches,import2()tricks,NodeModulesingletons). The package shipped a singlelib/tree, so every bundler sawws,http,worker_threads,child_processreferences even when targeting the browser, and every Node consumer carried the browser polyfill paths.Solution
The platform is now decided at build time, not runtime.
Shared classes import a single alias,
#platform, whichtsconfig.node.jsonandtsconfig.browser.jsonresolve to different directories viapaths(rewritten in the emit by the already-usedts-patch+typescript-transform-paths). One source, one set of.d.ts, two runtime trees.Verification
lib/browser/index.mjsimports onlytstl; nows/http/fs/child_process/worker_threadsanywhere inlib/browser/**lib/node/index.mjsstatically importswsand node builtinsnpm pack+ consumer project:require("tgrid")→lib/node,node --conditions=browserand--conditions=react-native→lib/browser, same for ESM and the./node/./browsersubpathsmoduleResolutionnode,node16, andbundlerWebSocketServerin browser,SharedWorkerServerin node)npm run test:node(17 tests) andnpm run test:browser(puppeteer, 3 pages) passwebsitetypedoc: 0 errors (19 pre-existing doc-link warnings, unchanged)npx eslint src: cleanOther changes
import2dependency removed;NodeModule.ts,WebSocketPolyfill.tsdeletedNodeWorkerCompiler,FileSystem,Process*/Thread*moved tosrc/platform/node/, simplified from async factories to plain classes / functionsIWorkerChannelinterface abstracts the worker-to-parent channel, soWorkerServerno longer checksself.documentitselftest/browser/tsconfig.jsoncompiles browser-side test scripts with the browser platform intobin/browser/;devscript watches both projects withtsc --buildtest_worker_compilerpreviously ran the browser bundle inside a Node child process (which only worked thanks to runtime detection); it now uses a separate node-platform bundle (bundle/worker-server.node.js)src/typings:Objecttype parameters renamed toWrapper; intentionalFunction/Boolean/Number/Stringusages get scopedeslint-disablecomments. No type semantics changed.exportsshape🤖 Generated with Claude Code
https://claude.ai/code/session_01AQaTBspPxvUiYtTCbC8Tcg