tsrx-typegen 0.0.0 → 0.1.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/README.md +120 -0
- package/package.json +23 -5
- package/src/cli.mjs +825 -0
- package/src/pack-check.mjs +594 -0
package/README.md
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
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
|
+
`--project` selects the target whose project path matches. Use `--target` to
|
|
32
|
+
select a named target directly. A target can look like this:
|
|
33
|
+
|
|
34
|
+
```json
|
|
35
|
+
{
|
|
36
|
+
"targets": {
|
|
37
|
+
"octane": {
|
|
38
|
+
"renderer": "octane",
|
|
39
|
+
"project": "tsconfig.types.json",
|
|
40
|
+
"outDir": "types/generated",
|
|
41
|
+
"entrypoints": {
|
|
42
|
+
".": {
|
|
43
|
+
"source": "src/index.ts",
|
|
44
|
+
"runtime": "./dist/index.js",
|
|
45
|
+
"types": "./types/generated/index.d.ts"
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Keep exceptional signatures in handwritten declaration sources outside the
|
|
54
|
+
generated directory, then map their generated output path explicitly:
|
|
55
|
+
|
|
56
|
+
```json
|
|
57
|
+
{
|
|
58
|
+
"overrides": {
|
|
59
|
+
"Button.d.ts": "types/overrides/Button.d.ts"
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
The override source is copied to the generated output and tracked by the
|
|
65
|
+
manifest; check mode detects edits to either the source mapping or generated
|
|
66
|
+
copy. Override declarations must use publishable module specifiers and may not
|
|
67
|
+
reference `.tsrx` files.
|
|
68
|
+
|
|
69
|
+
Relative imports between generated declarations receive runtime extensions
|
|
70
|
+
from the source map, including extensionless imports. This supports NodeNext
|
|
71
|
+
consumers as well as bundler resolution without requiring `allowArbitraryExtensions`.
|
|
72
|
+
|
|
73
|
+
Use separate target records and project configs when public signatures differ.
|
|
74
|
+
Each config must select the same source variants as its runtime build.
|
|
75
|
+
`runtime` records the published runtime path or condition map, while `types`
|
|
76
|
+
records the declaration path. The CLI does not edit `package.json`; export maps
|
|
77
|
+
remain package-owned. The default source-extension mapping is `.tsrx`, `.tsx`,
|
|
78
|
+
and `.ts` to `.js`, with `.mts` to `.mjs` and `.cts` to `.cjs`. Packages with
|
|
79
|
+
another runtime layout can override these mappings in `sourceExtensions` at
|
|
80
|
+
the target or root level.
|
|
81
|
+
|
|
82
|
+
## Publish checks
|
|
83
|
+
|
|
84
|
+
Use `--pack-check` before publishing. It checks every configured target unless
|
|
85
|
+
`--target` narrows the selection, packs a temporary tarball with lifecycle
|
|
86
|
+
scripts disabled, and verifies that package and `publishConfig` export paths
|
|
87
|
+
exist in the tarball. It also compares runtime and declaration value exports
|
|
88
|
+
and checks that relative declaration references resolve inside the package and
|
|
89
|
+
bare package imports are declared dependencies or peers. The command needs
|
|
90
|
+
`pnpm` and the system `tar` utility. It checks package structure; keep a plain
|
|
91
|
+
TypeScript consumer test for the module-resolution modes and public prop
|
|
92
|
+
contracts your package supports.
|
|
93
|
+
|
|
94
|
+
Run the same gate from `prepack` so `pnpm pack` and publication share it:
|
|
95
|
+
|
|
96
|
+
```json
|
|
97
|
+
{
|
|
98
|
+
"scripts": {
|
|
99
|
+
"build": "vite build && tsrx-typegen --target octane",
|
|
100
|
+
"prepack": "pnpm build && tsrx-typegen --pack-check"
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
When run from a package root that has `tsrx-typegen.json`, `xplat doctor`
|
|
106
|
+
delegates to `tsrx-typegen --pack-check` and returns a failing exit status if
|
|
107
|
+
that declaration gate fails.
|
|
108
|
+
|
|
109
|
+
The first supported backend is the classic `tsrx-tsc` path with TypeScript
|
|
110
|
+
5.9.x. TypeScript 7 content-mapper output needs upstream declaration naming and
|
|
111
|
+
specifier support before it can replace this backend. Generation rejects
|
|
112
|
+
compiler errors; editor-only partial transforms are not used.
|
|
113
|
+
|
|
114
|
+
This tool preserves TypeScript's declaration inference. Keep exported helpers,
|
|
115
|
+
generic signatures, overloads, and compound members explicit in source when
|
|
116
|
+
inference does not preserve the intended package contract. Always check the
|
|
117
|
+
packed package with a plain TypeScript consumer; generated declarations may
|
|
118
|
+
still express a different contract even when their paths and exports are
|
|
119
|
+
valid. Use explicit overrides for exceptional signatures and keep those
|
|
120
|
+
overrides outside the generated output directory.
|
package/package.json
CHANGED
|
@@ -1,6 +1,24 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
"name": "tsrx-typegen",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Generate consumer-ready TypeScript declarations for TSRX libraries",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/octane-xplat/octane-xplat.git",
|
|
8
|
+
"directory": "packages/tsrx-typegen"
|
|
9
|
+
},
|
|
10
|
+
"bin": {
|
|
11
|
+
"tsrx-typegen": "./src/cli.mjs"
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"src"
|
|
15
|
+
],
|
|
16
|
+
"type": "module",
|
|
17
|
+
"peerDependencies": {
|
|
18
|
+
"@tsrx/typescript-plugin": ">=0.4.11 <1",
|
|
19
|
+
"typescript": ">=5.9.3 <6"
|
|
20
|
+
},
|
|
21
|
+
"scripts": {
|
|
22
|
+
"test": "node tests/pack-check.mjs && node tests/packed-consumer.mjs"
|
|
23
|
+
}
|
|
24
|
+
}
|