tsrx-typegen 0.0.0 → 0.2.0

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,139 @@
1
+ # tsrx-typegen
2
+
3
+ Generate declaration files for packages that export `.tsrx` modules. The
4
+ command uses the consuming package's TypeScript and tsrx compiler, then maps
5
+ source-extension imports in the emitted declarations to JavaScript module
6
+ specifiers.
7
+
8
+ Install `tsrx-typegen` as a development tool alongside `typescript` and
9
+ `@tsrx/typescript-plugin`. Each target in `tsrx-typegen.json` names its
10
+ renderer, project config, declaration output directory, and public subpaths.
11
+ The project config selects source variants and enables `declaration`,
12
+ `emitDeclarationOnly`, and `noEmit: false`. The target's `renderer` is checked
13
+ against `compilerOptions.jsxImportSource` when TypeScript sets it; the project
14
+ config continues to select the actual tsrx compiler and platform.
15
+
16
+ ```sh
17
+ pnpm exec tsrx-typegen --target octane
18
+ pnpm exec tsrx-typegen --project tsconfig.types.json --check
19
+ pnpm exec tsrx-typegen --pack-check
20
+ ```
21
+
22
+ Generation writes only TypeScript declaration files under the config's `outDir` and records
23
+ which files it owns in `.tsrx-typegen-manifest.json`. Check mode emits to a
24
+ temporary directory and compares the result with those owned files. It reports
25
+ missing or stale output, unresolved `.tsrx` references, and code export paths
26
+ without declaration targets. It refuses to overwrite an unmanaged declaration
27
+ and removes stale files only when the manifest says it owns them. Same-name
28
+ sources such as `Button.ts` and `Button.tsrx` need separate target configs or an
29
+ explicit declaration override.
30
+
31
+ Treat the output directory, including its ownership manifest, as generated
32
+ build artifacts: ignore it in Git, formatting, and linting. Keep handwritten
33
+ declarations and override sources outside that directory. Include the output
34
+ directory in the package's `files` list so ignored declarations still ship in
35
+ the tarball. Generate before local consumer typechecks, and regenerate in
36
+ `prepack` before validating the package. Workspaces that resolve generated
37
+ types directly also need generation during setup and refreshes during
38
+ development; this repository's workflow is documented in
39
+ [Develop against generated declarations](../../docs/toolchain-notes.md#develop-against-generated-declarations).
40
+
41
+ `--project` selects the target whose project path matches. Use `--target` to
42
+ select a named target directly. A target can look like this:
43
+
44
+ ```json
45
+ {
46
+ "targets": {
47
+ "octane": {
48
+ "renderer": "octane",
49
+ "project": "tsconfig.types.json",
50
+ "outDir": "types/generated",
51
+ "entrypoints": {
52
+ ".": {
53
+ "source": "src/index.ts",
54
+ "runtime": "./dist/index.js",
55
+ "types": "./types/generated/index.d.ts"
56
+ }
57
+ }
58
+ }
59
+ }
60
+ }
61
+ ```
62
+
63
+ Keep exceptional signatures in handwritten declaration sources outside the
64
+ generated directory, then map their generated output path explicitly:
65
+
66
+ ```json
67
+ {
68
+ "overrides": {
69
+ "Button.d.ts": "types/overrides/Button.d.ts"
70
+ }
71
+ }
72
+ ```
73
+
74
+ The override source is copied to the generated output and tracked by the
75
+ manifest; check mode detects edits to either the source mapping or generated
76
+ copy. Override declarations must use publishable module specifiers and may not
77
+ reference `.tsrx` files.
78
+
79
+ Relative imports between generated declarations receive runtime extensions
80
+ from the source map, including extensionless imports. This supports NodeNext
81
+ consumers as well as bundler resolution without requiring `allowArbitraryExtensions`.
82
+
83
+ Use separate target records and project configs when public signatures differ.
84
+ Each config must select the same source variants as its runtime build.
85
+ `runtime` records the published runtime path or condition map, while `types`
86
+ records the declaration path. The CLI does not edit `package.json`; export maps
87
+ remain package-owned. The default source-extension mapping is `.tsrx`, `.tsx`,
88
+ and `.ts` to `.js`, with `.mts` to `.mjs` and `.cts` to `.cjs`. Packages with
89
+ another runtime layout can override these mappings in `sourceExtensions` at
90
+ the target or root level.
91
+
92
+ ## Publish checks
93
+
94
+ Use `--pack-check` before publishing. It checks every configured target unless
95
+ `--target` narrows the selection, packs a temporary tarball with lifecycle
96
+ scripts disabled, and verifies that package and `publishConfig` export paths
97
+ exist in the tarball. It also compares runtime and declaration value exports
98
+ and checks that relative declaration references resolve inside the package and
99
+ bare package imports are declared dependencies or peers. The command needs
100
+ `pnpm` and the system `tar` utility. It checks package structure; keep a plain
101
+ TypeScript consumer test for the module-resolution modes and public prop
102
+ contracts your package supports.
103
+
104
+ A target with `"emit": false` exists only to drive packed-package
105
+ verification. Packages whose declarations are handwritten or produced by
106
+ another tool declare one so `--pack-check` skips generation and freshness
107
+ checks for it and only validates the packed package. Such targets cannot be
108
+ selected for generation; a plain `--target` run against them fails. Every code
109
+ export path still needs a `types` condition — pointing at a `.d.ts` file or,
110
+ for source-published packages, the `.ts` source itself.
111
+
112
+ Run the same gate from `prepack` so `pnpm pack` and publication share it:
113
+
114
+ ```json
115
+ {
116
+ "scripts": {
117
+ "typegen": "tsrx-typegen --target octane",
118
+ "build": "vite build && pnpm typegen",
119
+ "prepack": "pnpm build && tsrx-typegen --pack-check"
120
+ }
121
+ }
122
+ ```
123
+
124
+ When run from a package root that has `tsrx-typegen.json`, `xplat doctor`
125
+ delegates to `tsrx-typegen --pack-check` and returns a failing exit status if
126
+ that declaration gate fails.
127
+
128
+ The first supported backend is the classic `tsrx-tsc` path with TypeScript
129
+ 5.9.x. TypeScript 7 content-mapper output needs upstream declaration naming and
130
+ specifier support before it can replace this backend. Generation rejects
131
+ compiler errors; editor-only partial transforms are not used.
132
+
133
+ This tool preserves TypeScript's declaration inference. Keep exported helpers,
134
+ generic signatures, overloads, and compound members explicit in source when
135
+ inference does not preserve the intended package contract. Always check the
136
+ packed package with a plain TypeScript consumer; generated declarations may
137
+ still express a different contract even when their paths and exports are
138
+ valid. Use explicit overrides for exceptional signatures and keep those
139
+ overrides outside the generated output directory.
package/package.json CHANGED
@@ -1,6 +1,35 @@
1
1
  {
2
- "name": "tsrx-typegen",
3
- "version": "0.0.0",
4
- "description": "Stub reserving the name; real releases publish from CI via trusted publishing.",
5
- "publishConfig": {"access": "public"}
6
- }
2
+ "name": "tsrx-typegen",
3
+ "version": "0.2.0",
4
+ "description": "Generate consumer-ready TypeScript declarations for TSRX libraries",
5
+ "keywords": [
6
+ "tsrx",
7
+ "typegen",
8
+ "typescript",
9
+ "declarations",
10
+ "dts",
11
+ "codegen",
12
+ "build-tool"
13
+ ],
14
+ "license": "MIT",
15
+ "homepage": "https://github.com/octane-xplat/octane-xplat/tree/main/packages/tsrx-typegen",
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/octane-xplat/octane-xplat.git",
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
+ }