tsrx-typegen 0.0.0-nightly.g2e22171

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2026 Alec Larson
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,220 @@
1
+ # tsrx-typegen
2
+
3
+ Generate `.d.ts` declaration files for packages that export `.tsrx` modules.
4
+ Use it when publishing an Octane/tsrx component package: it runs the consuming
5
+ package's own TypeScript and tsrx compiler, then rewrites source-extension
6
+ imports in the emitted declarations to JavaScript module specifiers.
7
+
8
+ Install `tsrx-typegen` as a development tool alongside `typescript` and
9
+ `@tsrx/typescript-plugin`, then run it against a named target:
10
+
11
+ ```sh
12
+ pnpm exec tsrx-typegen --target octane # generate declarations
13
+ pnpm exec tsrx-typegen --target octane --check # verify output is fresh
14
+ pnpm exec tsrx-typegen --pack-check # validate the packed tarball
15
+ ```
16
+
17
+ Each target in `tsrx-typegen.json` names its renderer, project config,
18
+ declaration output directory, and public subpaths:
19
+
20
+ ```json
21
+ {
22
+ "targets": {
23
+ "octane": {
24
+ "renderer": "octane",
25
+ "project": "tsconfig.types.json",
26
+ "outDir": "types/generated",
27
+ "entrypoints": {
28
+ ".": {
29
+ "source": "src/index.ts",
30
+ "runtime": "./src/index.ts",
31
+ "types": "./types/generated/index.d.ts"
32
+ }
33
+ }
34
+ }
35
+ }
36
+ }
37
+ ```
38
+
39
+ The project config selects source variants and enables `declaration`,
40
+ `emitDeclarationOnly`, and `noEmit: false`. The target's `renderer` is checked
41
+ against `compilerOptions.jsxImportSource` when TypeScript sets it; the project
42
+ config continues to select the actual tsrx compiler and platform. `--project`
43
+ selects the target whose project path matches; `--target` selects a named
44
+ target directly.
45
+
46
+ ## What generation writes and checks
47
+
48
+ Generation writes only TypeScript declaration files under the config's
49
+ `outDir` and records which files it owns in `.tsrx-typegen-manifest.json`.
50
+ Declaration inputs included by the project under `rootDir` are copied beside
51
+ emitted declarations, with the same import rewriting and freshness checks.
52
+ Check mode emits to a temporary directory and compares the result with those
53
+ owned files. It reports missing or stale output, unresolved `.tsrx`
54
+ references, and code export paths without declaration targets. It refuses to
55
+ overwrite an unmanaged declaration and removes stale files only when the
56
+ manifest says it owns them. Same-name sources such as `Button.ts` and
57
+ `Button.tsrx` need separate target configs or an explicit declaration
58
+ override. Case-only source renames replace the prior manifest-owned
59
+ declaration, including on case-insensitive filesystems; manual declarations
60
+ remain protected.
61
+
62
+ Treat the output directory, including its ownership manifest, as generated
63
+ build artifacts: ignore it in Git, formatting, and linting. Keep handwritten
64
+ declarations and override sources outside that directory. Include the output
65
+ directory in the package's `files` list so ignored declarations still ship in
66
+ the tarball. Generate before local consumer typechecks, and regenerate in
67
+ `prepack` before validating the package. Workspaces that resolve generated
68
+ types directly also need generation during setup and refreshes during
69
+ development; this repository's workflow is documented in
70
+ [Develop against generated declarations](../../.agents/docs/notes/toolchain-notes.md#develop-against-generated-declarations).
71
+
72
+ ## Overrides and import rewriting
73
+
74
+ Keep exceptional signatures in handwritten declaration sources outside the
75
+ generated directory, then map their generated output path explicitly:
76
+
77
+ ```json
78
+ {
79
+ "overrides": {
80
+ "Button.d.ts": "types/overrides/Button.d.ts"
81
+ }
82
+ }
83
+ ```
84
+
85
+ The override source is copied to the generated output and tracked by the
86
+ manifest; check mode detects edits to either the source mapping or generated
87
+ copy. Override declarations must use publishable module specifiers and may not
88
+ reference `.tsrx` files.
89
+
90
+ Relative imports between generated declarations receive runtime extensions
91
+ from the source map, including extensionless imports. This supports NodeNext
92
+ consumers as well as bundler resolution without requiring
93
+ `allowArbitraryExtensions`. A plain TypeScript consumer then imports the
94
+ package normally:
95
+
96
+ ```ts
97
+ import { Button } from 'my-component-library'
98
+ ```
99
+
100
+ The `.js` specifiers inside declarations resolve to sibling `.d.ts` files
101
+ through TypeScript's extension substitution. They do not require a JavaScript
102
+ package build. Keep runtime exports pointed at authored source and type exports
103
+ pointed at declarations:
104
+
105
+ ```json
106
+ {
107
+ "exports": {
108
+ ".": {
109
+ "types": "./types/generated/index.d.ts",
110
+ "default": "./src/index.ts"
111
+ },
112
+ "./*": {
113
+ "types": "./types/generated/*.d.ts",
114
+ "default": "./src/*"
115
+ }
116
+ },
117
+ "files": ["src", "types"]
118
+ }
119
+ ```
120
+
121
+ Keep wildcard runtime targets extensionless so the app bundler can select
122
+ `.web.ts`, `.ios.ts`, or `.web.tsrx` siblings. The declaration wildcard uses
123
+ the same module stem, and the pack check verifies each source variant has its
124
+ matching declaration.
125
+
126
+ Use separate target records and project configs when public signatures differ.
127
+ Each config must select the source variants exposed by its runtime exports.
128
+ `runtime` records the published runtime path or condition map, while `types`
129
+ records the declaration path. The CLI does not edit `package.json`; export
130
+ maps remain package-owned. The default source-extension mapping is `.tsrx`,
131
+ `.tsx`, and `.ts` to `.js`, with `.mts` to `.mjs` and `.cts` to `.cjs`.
132
+ Packages with another runtime layout can override these mappings in
133
+ `sourceExtensions` at the target or root level:
134
+
135
+ ```json
136
+ {
137
+ "sourceExtensions": { ".tsrx": ".js", ".mts": ".mjs", ".cts": ".cjs" }
138
+ }
139
+ ```
140
+
141
+ ## Publish checks
142
+
143
+ Use `--pack-check` before publishing. It checks every configured target unless
144
+ `--target` narrows the selection, packs a temporary tarball with lifecycle
145
+ scripts disabled, and verifies that package and `publishConfig` export paths
146
+ exist in the tarball. It also compares runtime and declaration value exports
147
+ and checks that relative declaration references resolve to declarations inside
148
+ the package and bare package imports are declared dependencies or peers. The command needs
149
+ `pnpm` and the system `tar` utility. It checks package structure; keep a plain
150
+ TypeScript consumer test for the module-resolution modes and public prop
151
+ contracts your package supports.
152
+
153
+ A target with `"emit": false` exists only to drive packed-package
154
+ verification. Packages whose declarations are handwritten or produced by
155
+ another tool declare one so `--pack-check` skips generation and freshness
156
+ checks for it and only validates the packed package. Such targets cannot be
157
+ selected for generation; a plain `--target` run against them fails. Every code
158
+ export path still needs a `types` condition — pointing at a `.d.ts` file or,
159
+ for source-published packages, the `.ts` source itself.
160
+
161
+ ```json
162
+ {
163
+ "targets": {
164
+ "manual": {
165
+ "emit": false,
166
+ "renderer": "octane",
167
+ "project": "tsconfig.types.json",
168
+ "outDir": "types/generated",
169
+ "entrypoints": {
170
+ ".": {
171
+ "source": "src/index.ts",
172
+ "runtime": "./src/index.ts",
173
+ "types": "./types/index.d.ts"
174
+ }
175
+ }
176
+ }
177
+ }
178
+ }
179
+ ```
180
+
181
+ Run the same gate from `prepack` so `pnpm pack` and publication share it:
182
+
183
+ ```json
184
+ {
185
+ "scripts": {
186
+ "typegen": "tsrx-typegen --target octane",
187
+ "prepack": "pnpm typegen && tsrx-typegen --pack-check"
188
+ }
189
+ }
190
+ ```
191
+
192
+ When run from a package root that has `tsrx-typegen.json`, `xplat doctor`
193
+ delegates to `tsrx-typegen --pack-check` and returns a failing exit status if
194
+ that declaration gate fails.
195
+
196
+ ```sh
197
+ pnpm exec xplat doctor
198
+ ```
199
+
200
+ ## Backend and inference
201
+
202
+ The first supported backend is the classic `tsrx-tsc` path with TypeScript
203
+ 5.9.x. TypeScript 7 content-mapper output needs upstream declaration naming
204
+ and specifier support before it can replace this backend. Generation rejects
205
+ compiler errors; editor-only partial transforms are not used.
206
+
207
+ This tool preserves TypeScript's declaration inference. Keep exported helpers,
208
+ generic signatures, overloads, and compound members explicit in source when
209
+ inference does not preserve the intended package contract. Always check the
210
+ packed package with a plain TypeScript consumer; generated declarations may
211
+ still express a different contract even when their paths and exports are
212
+ valid. Use explicit overrides for exceptional signatures and keep those
213
+ overrides outside the generated output directory.
214
+
215
+ ```ts
216
+ // Source of your component package; use an explicit return type for helpers.
217
+ export function formatCount(count: number): string {
218
+ return `${count} packed`
219
+ }
220
+ ```
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "tsrx-typegen",
3
+ "version": "0.0.0-nightly.g2e22171",
4
+ "description": "Generate consumer-ready TypeScript declarations for TSRX libraries",
5
+ "keywords": [
6
+ "build-tool",
7
+ "codegen",
8
+ "declarations",
9
+ "dts",
10
+ "tsrx",
11
+ "typegen",
12
+ "typescript"
13
+ ],
14
+ "homepage": "https://github.com/octane-xplat/octane-xplat/tree/main/packages/tsrx-typegen",
15
+ "license": "MIT",
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "https://github.com/octane-xplat/octane-xplat",
19
+ "directory": "packages/tsrx-typegen"
20
+ },
21
+ "bin": {
22
+ "tsrx-typegen": "./src/cli.mjs"
23
+ },
24
+ "files": [
25
+ "src"
26
+ ],
27
+ "type": "module",
28
+ "peerDependencies": {
29
+ "@tsrx/typescript-plugin": ">=0.4.11 <1",
30
+ "typescript": ">=5.9.3 <6"
31
+ },
32
+ "scripts": {
33
+ "test": "node tests/pack-check.mjs && node tests/packed-consumer.mjs"
34
+ }
35
+ }