tsrx-typegen 0.2.1 → 0.2.2
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 +66 -2
- package/package.json +1 -1
- package/src/cli.mjs +35 -10
- package/src/pack-check.mjs +1 -3
package/README.md
CHANGED
|
@@ -5,6 +5,10 @@ command uses the consuming package's TypeScript and tsrx compiler, then maps
|
|
|
5
5
|
source-extension imports in the emitted declarations to JavaScript module
|
|
6
6
|
specifiers.
|
|
7
7
|
|
|
8
|
+
```sh
|
|
9
|
+
pnpm exec tsrx-typegen --target octane
|
|
10
|
+
```
|
|
11
|
+
|
|
8
12
|
Install `tsrx-typegen` as a development tool alongside `typescript` and
|
|
9
13
|
`@tsrx/typescript-plugin`. Each target in `tsrx-typegen.json` names its
|
|
10
14
|
renderer, project config, declaration output directory, and public subpaths.
|
|
@@ -26,7 +30,13 @@ missing or stale output, unresolved `.tsrx` references, and code export paths
|
|
|
26
30
|
without declaration targets. It refuses to overwrite an unmanaged declaration
|
|
27
31
|
and removes stale files only when the manifest says it owns them. Same-name
|
|
28
32
|
sources such as `Button.ts` and `Button.tsrx` need separate target configs or an
|
|
29
|
-
explicit declaration override.
|
|
33
|
+
explicit declaration override. Case-only source renames replace the prior
|
|
34
|
+
manifest-owned declaration, including on case-insensitive filesystems; manual
|
|
35
|
+
declarations remain protected.
|
|
36
|
+
|
|
37
|
+
```sh
|
|
38
|
+
pnpm exec tsrx-typegen --target octane --check
|
|
39
|
+
```
|
|
30
40
|
|
|
31
41
|
Treat the output directory, including its ownership manifest, as generated
|
|
32
42
|
build artifacts: ignore it in Git, formatting, and linting. Keep handwritten
|
|
@@ -36,7 +46,7 @@ the tarball. Generate before local consumer typechecks, and regenerate in
|
|
|
36
46
|
`prepack` before validating the package. Workspaces that resolve generated
|
|
37
47
|
types directly also need generation during setup and refreshes during
|
|
38
48
|
development; this repository's workflow is documented in
|
|
39
|
-
[Develop against generated declarations](../../docs/toolchain-notes.md#develop-against-generated-declarations).
|
|
49
|
+
[Develop against generated declarations](../../docs/notes/toolchain-notes.md#develop-against-generated-declarations).
|
|
40
50
|
|
|
41
51
|
`--project` selects the target whose project path matches. Use `--target` to
|
|
42
52
|
select a named target directly. A target can look like this:
|
|
@@ -76,10 +86,22 @@ manifest; check mode detects edits to either the source mapping or generated
|
|
|
76
86
|
copy. Override declarations must use publishable module specifiers and may not
|
|
77
87
|
reference `.tsrx` files.
|
|
78
88
|
|
|
89
|
+
```sh
|
|
90
|
+
pnpm exec tsrx-typegen --target octane --check
|
|
91
|
+
```
|
|
92
|
+
|
|
79
93
|
Relative imports between generated declarations receive runtime extensions
|
|
80
94
|
from the source map, including extensionless imports. This supports NodeNext
|
|
81
95
|
consumers as well as bundler resolution without requiring `allowArbitraryExtensions`.
|
|
82
96
|
|
|
97
|
+
```ts
|
|
98
|
+
// Plain TypeScript consumer of the package whose exports are configured above.
|
|
99
|
+
import { Button } from 'my-component-library'
|
|
100
|
+
|
|
101
|
+
// Button is a component exported by your library's src/index.ts.
|
|
102
|
+
export { Button }
|
|
103
|
+
```
|
|
104
|
+
|
|
83
105
|
Use separate target records and project configs when public signatures differ.
|
|
84
106
|
Each config must select the same source variants as its runtime build.
|
|
85
107
|
`runtime` records the published runtime path or condition map, while `types`
|
|
@@ -89,6 +111,12 @@ and `.ts` to `.js`, with `.mts` to `.mjs` and `.cts` to `.cjs`. Packages with
|
|
|
89
111
|
another runtime layout can override these mappings in `sourceExtensions` at
|
|
90
112
|
the target or root level.
|
|
91
113
|
|
|
114
|
+
```json
|
|
115
|
+
{
|
|
116
|
+
"sourceExtensions": { ".tsrx": ".js", ".mts": ".mjs", ".cts": ".cjs" }
|
|
117
|
+
}
|
|
118
|
+
```
|
|
119
|
+
|
|
92
120
|
## Publish checks
|
|
93
121
|
|
|
94
122
|
Use `--pack-check` before publishing. It checks every configured target unless
|
|
@@ -101,6 +129,11 @@ bare package imports are declared dependencies or peers. The command needs
|
|
|
101
129
|
TypeScript consumer test for the module-resolution modes and public prop
|
|
102
130
|
contracts your package supports.
|
|
103
131
|
|
|
132
|
+
```sh
|
|
133
|
+
pnpm exec tsrx-typegen --pack-check
|
|
134
|
+
pnpm exec tsrx-typegen --pack-check --target octane
|
|
135
|
+
```
|
|
136
|
+
|
|
104
137
|
A target with `"emit": false` exists only to drive packed-package
|
|
105
138
|
verification. Packages whose declarations are handwritten or produced by
|
|
106
139
|
another tool declare one so `--pack-check` skips generation and freshness
|
|
@@ -109,6 +142,26 @@ selected for generation; a plain `--target` run against them fails. Every code
|
|
|
109
142
|
export path still needs a `types` condition — pointing at a `.d.ts` file or,
|
|
110
143
|
for source-published packages, the `.ts` source itself.
|
|
111
144
|
|
|
145
|
+
```json
|
|
146
|
+
{
|
|
147
|
+
"targets": {
|
|
148
|
+
"manual": {
|
|
149
|
+
"emit": false,
|
|
150
|
+
"renderer": "octane",
|
|
151
|
+
"project": "tsconfig.types.json",
|
|
152
|
+
"outDir": "types/generated",
|
|
153
|
+
"entrypoints": {
|
|
154
|
+
".": {
|
|
155
|
+
"source": "src/index.ts",
|
|
156
|
+
"runtime": "./dist/index.js",
|
|
157
|
+
"types": "./types/index.d.ts"
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
```
|
|
164
|
+
|
|
112
165
|
Run the same gate from `prepack` so `pnpm pack` and publication share it:
|
|
113
166
|
|
|
114
167
|
```json
|
|
@@ -125,6 +178,10 @@ When run from a package root that has `tsrx-typegen.json`, `xplat doctor`
|
|
|
125
178
|
delegates to `tsrx-typegen --pack-check` and returns a failing exit status if
|
|
126
179
|
that declaration gate fails.
|
|
127
180
|
|
|
181
|
+
```sh
|
|
182
|
+
pnpm exec xplat doctor
|
|
183
|
+
```
|
|
184
|
+
|
|
128
185
|
The first supported backend is the classic `tsrx-tsc` path with TypeScript
|
|
129
186
|
5.9.x. TypeScript 7 content-mapper output needs upstream declaration naming and
|
|
130
187
|
specifier support before it can replace this backend. Generation rejects
|
|
@@ -137,3 +194,10 @@ packed package with a plain TypeScript consumer; generated declarations may
|
|
|
137
194
|
still express a different contract even when their paths and exports are
|
|
138
195
|
valid. Use explicit overrides for exceptional signatures and keep those
|
|
139
196
|
overrides outside the generated output directory.
|
|
197
|
+
|
|
198
|
+
```ts
|
|
199
|
+
// Source of your component package; use an explicit return type for helpers.
|
|
200
|
+
export function formatCount(count: number): string {
|
|
201
|
+
return `${count} packed`
|
|
202
|
+
}
|
|
203
|
+
```
|
package/package.json
CHANGED
package/src/cli.mjs
CHANGED
|
@@ -608,19 +608,42 @@ function pathInside(root, file) {
|
|
|
608
608
|
)
|
|
609
609
|
}
|
|
610
610
|
|
|
611
|
-
function
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
continue
|
|
615
|
-
}
|
|
611
|
+
function existingOutputPath(outputDir, file) {
|
|
612
|
+
let current = outputDir
|
|
613
|
+
const actualParts = []
|
|
616
614
|
|
|
615
|
+
for (const part of normalize(file).split(sep)) {
|
|
616
|
+
let entries
|
|
617
617
|
try {
|
|
618
|
-
|
|
619
|
-
throw new Error(`refusing to overwrite unmanaged declaration: ${file}`)
|
|
618
|
+
entries = readdirSync(current)
|
|
620
619
|
} catch (error) {
|
|
621
|
-
if (error.code
|
|
622
|
-
|
|
620
|
+
if (error.code === 'ENOENT') {
|
|
621
|
+
return null
|
|
623
622
|
}
|
|
623
|
+
|
|
624
|
+
throw error
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
const actual = entries.includes(part)
|
|
628
|
+
? part
|
|
629
|
+
: entries.find((entry) => entry.toLowerCase() === part.toLowerCase())
|
|
630
|
+
|
|
631
|
+
if (!actual) {
|
|
632
|
+
return null
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
actualParts.push(actual)
|
|
636
|
+
current = join(current, actual)
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
return actualParts.join(sep)
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
function writeOutput(outputDir, generated, oldFiles, overrideFiles) {
|
|
643
|
+
for (const file of generated.keys()) {
|
|
644
|
+
const existing = existingOutputPath(outputDir, file)
|
|
645
|
+
if (existing && !oldFiles?.has(existing) && !overrideFiles.has(existing)) {
|
|
646
|
+
throw new Error(`refusing to overwrite unmanaged declaration: ${file}`)
|
|
624
647
|
}
|
|
625
648
|
}
|
|
626
649
|
|
|
@@ -743,7 +766,9 @@ function verifyPublicTypes(projectRoot, generated, outDir, target, sourceOutputs
|
|
|
743
766
|
}
|
|
744
767
|
|
|
745
768
|
const source = resolve(projectRoot, entry.source)
|
|
746
|
-
|
|
769
|
+
// TypeScript emits forward-slash paths even on Windows; resolve both
|
|
770
|
+
// sides before comparing them with the platform-native entry path.
|
|
771
|
+
if (![...sourceOutputs.values()].some((included) => resolve(included) === source)) {
|
|
747
772
|
failures.push(
|
|
748
773
|
`${subpath} source is not included by its TypeScript project: ${entry.source}`,
|
|
749
774
|
)
|
package/src/pack-check.mjs
CHANGED
|
@@ -599,8 +599,6 @@ export function checkPackedPackage(projectRoot, ts) {
|
|
|
599
599
|
mkdirSync(packOutput)
|
|
600
600
|
mkdirSync(extractedRoot)
|
|
601
601
|
try {
|
|
602
|
-
verifyPackedPackage(ts, projectRoot)
|
|
603
|
-
console.log('tsrx-typegen: workspace exports and declaration graph are valid')
|
|
604
602
|
const packed = spawnSync(
|
|
605
603
|
'pnpm',
|
|
606
604
|
['--config.ignore-scripts=true', 'pack', '--pack-destination', packOutput],
|
|
@@ -654,7 +652,7 @@ export function checkPackedPackage(projectRoot, ts) {
|
|
|
654
652
|
}
|
|
655
653
|
|
|
656
654
|
verifyPackedPackage(ts, join(extractedRoot, 'package'))
|
|
657
|
-
console.log('tsrx-typegen: packed
|
|
655
|
+
console.log('tsrx-typegen: packed exports and declaration graph are valid')
|
|
658
656
|
} finally {
|
|
659
657
|
rmSync(temporary, { recursive: true, force: true })
|
|
660
658
|
}
|