tsrx-typegen 0.1.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 +21 -0
- package/README.md +20 -1
- package/package.json +12 -1
- package/src/cli.mjs +12 -3
- package/src/pack-check.mjs +69 -5
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
CHANGED
|
@@ -28,6 +28,16 @@ and removes stale files only when the manifest says it owns them. Same-name
|
|
|
28
28
|
sources such as `Button.ts` and `Button.tsrx` need separate target configs or an
|
|
29
29
|
explicit declaration override.
|
|
30
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
|
+
|
|
31
41
|
`--project` selects the target whose project path matches. Use `--target` to
|
|
32
42
|
select a named target directly. A target can look like this:
|
|
33
43
|
|
|
@@ -91,12 +101,21 @@ bare package imports are declared dependencies or peers. The command needs
|
|
|
91
101
|
TypeScript consumer test for the module-resolution modes and public prop
|
|
92
102
|
contracts your package supports.
|
|
93
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
|
+
|
|
94
112
|
Run the same gate from `prepack` so `pnpm pack` and publication share it:
|
|
95
113
|
|
|
96
114
|
```json
|
|
97
115
|
{
|
|
98
116
|
"scripts": {
|
|
99
|
-
"
|
|
117
|
+
"typegen": "tsrx-typegen --target octane",
|
|
118
|
+
"build": "vite build && pnpm typegen",
|
|
100
119
|
"prepack": "pnpm build && tsrx-typegen --pack-check"
|
|
101
120
|
}
|
|
102
121
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tsrx-typegen",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
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",
|
|
5
16
|
"repository": {
|
|
6
17
|
"type": "git",
|
|
7
18
|
"url": "git+https://github.com/octane-xplat/octane-xplat.git",
|
package/src/cli.mjs
CHANGED
|
@@ -36,6 +36,7 @@ Options:
|
|
|
36
36
|
--target <name> Target in tsrx-typegen.json (selects its project and output)
|
|
37
37
|
--check Compare generated declarations without writing files
|
|
38
38
|
--pack-check Check declarations, pack the package, and validate the tarball
|
|
39
|
+
(targets with emit: false skip generation and only validate)
|
|
39
40
|
-h, --help Show this help`)
|
|
40
41
|
}
|
|
41
42
|
|
|
@@ -99,7 +100,7 @@ function configuredTargetNames(projectRoot, selectedTarget) {
|
|
|
99
100
|
throw new Error(`${path}: unknown target ${selectedTarget}`)
|
|
100
101
|
}
|
|
101
102
|
|
|
102
|
-
return selectedTarget ? [selectedTarget] : Object.keys(targets)
|
|
103
|
+
return { names: selectedTarget ? [selectedTarget] : Object.keys(targets), targets }
|
|
103
104
|
}
|
|
104
105
|
|
|
105
106
|
function loadProjectModule(projectRoot, specifier) {
|
|
@@ -251,6 +252,10 @@ function configOptions(projectRoot, projectArgument, targetArgument) {
|
|
|
251
252
|
}
|
|
252
253
|
|
|
253
254
|
if (selected) {
|
|
255
|
+
if (selected.emit === false) {
|
|
256
|
+
throw new Error(`${path}: target ${selectedName} has emit: false — it configures --pack-check only`)
|
|
257
|
+
}
|
|
258
|
+
|
|
254
259
|
if (typeof selected.project !== 'string' || !selected.project) {
|
|
255
260
|
throw new Error(`${path}: target ${selectedName} must name a project`)
|
|
256
261
|
}
|
|
@@ -804,8 +809,12 @@ function run() {
|
|
|
804
809
|
return
|
|
805
810
|
}
|
|
806
811
|
|
|
807
|
-
const targets = configuredTargetNames(projectRoot, args.target)
|
|
808
|
-
for (const target of
|
|
812
|
+
const { names, targets } = configuredTargetNames(projectRoot, args.target)
|
|
813
|
+
for (const target of names) {
|
|
814
|
+
if (targets[target]?.emit === false) {
|
|
815
|
+
continue
|
|
816
|
+
}
|
|
817
|
+
|
|
809
818
|
if (!runTarget(projectRoot, { ...args, target, check: true })) {
|
|
810
819
|
process.exitCode = 1
|
|
811
820
|
return
|
package/src/pack-check.mjs
CHANGED
|
@@ -190,10 +190,15 @@ function localSourceModule(file, specifier) {
|
|
|
190
190
|
const candidates = [target]
|
|
191
191
|
if (extension === '.js' || extension === '.mjs' || extension === '.cjs') {
|
|
192
192
|
const stem = target.slice(0, -extension.length)
|
|
193
|
-
candidates.push(`${stem}.ts`, `${stem}.tsx`, `${stem}.tsrx`)
|
|
193
|
+
candidates.push(`${stem}.ts`, `${stem}.tsx`, `${stem}.tsrx`, `${stem}.d.ts`)
|
|
194
194
|
} else if (!['.ts', '.tsx', '.tsrx'].includes(extension)) {
|
|
195
|
-
candidates.push(`${target}.ts`, `${target}.tsx`, `${target}.tsrx`)
|
|
196
|
-
candidates.push(
|
|
195
|
+
candidates.push(`${target}.ts`, `${target}.tsx`, `${target}.tsrx`, `${target}.d.ts`)
|
|
196
|
+
candidates.push(
|
|
197
|
+
join(target, 'index.ts'),
|
|
198
|
+
join(target, 'index.tsx'),
|
|
199
|
+
join(target, 'index.tsrx'),
|
|
200
|
+
join(target, 'index.d.ts'),
|
|
201
|
+
)
|
|
197
202
|
}
|
|
198
203
|
|
|
199
204
|
for (const candidate of candidates) {
|
|
@@ -285,7 +290,16 @@ function staticRuntimeExports(ts, file, seen = new Set()) {
|
|
|
285
290
|
return names
|
|
286
291
|
}
|
|
287
292
|
|
|
288
|
-
function compilerExports(ts, program, file) {
|
|
293
|
+
function compilerExports(ts, program, file, cache = new Map(), pending = new Set()) {
|
|
294
|
+
const absolute = resolve(file)
|
|
295
|
+
if (cache.has(absolute)) {
|
|
296
|
+
return cache.get(absolute)
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
if (pending.has(absolute)) {
|
|
300
|
+
return { all: new Set(), values: new Set() }
|
|
301
|
+
}
|
|
302
|
+
|
|
289
303
|
const source = program.getSourceFile(file)
|
|
290
304
|
if (!source) {
|
|
291
305
|
return undefined
|
|
@@ -313,7 +327,57 @@ function compilerExports(ts, program, file) {
|
|
|
313
327
|
}
|
|
314
328
|
}
|
|
315
329
|
|
|
316
|
-
|
|
330
|
+
// Type-only edges (`export type *`, `export type { X }`) re-list the
|
|
331
|
+
// target's symbols with their original flags — an ambient `declare const`
|
|
332
|
+
// still reads as a value even though no value binding crosses the edge.
|
|
333
|
+
// Subtract names whose only export edges are type-only.
|
|
334
|
+
const typeOnly = new Set()
|
|
335
|
+
for (const statement of source.statements) {
|
|
336
|
+
if (!ts.isExportDeclaration(statement) || !statement.isTypeOnly) {
|
|
337
|
+
continue
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
if (
|
|
341
|
+
!statement.exportClause &&
|
|
342
|
+
statement.moduleSpecifier &&
|
|
343
|
+
ts.isStringLiteralLike(statement.moduleSpecifier)
|
|
344
|
+
) {
|
|
345
|
+
pending.add(absolute)
|
|
346
|
+
const target = ts.resolveModuleName(
|
|
347
|
+
statement.moduleSpecifier.text,
|
|
348
|
+
file,
|
|
349
|
+
program.getCompilerOptions(),
|
|
350
|
+
ts.sys,
|
|
351
|
+
).resolvedModule?.resolvedFileName
|
|
352
|
+
|
|
353
|
+
const targetExports =
|
|
354
|
+
target && compilerExports(ts, program, target, cache, pending)
|
|
355
|
+
|
|
356
|
+
pending.delete(absolute)
|
|
357
|
+
for (const name of targetExports?.all ?? []) {
|
|
358
|
+
typeOnly.add(name)
|
|
359
|
+
}
|
|
360
|
+
} else if (statement.exportClause && ts.isNamedExports(statement.exportClause)) {
|
|
361
|
+
for (const element of statement.exportClause.elements) {
|
|
362
|
+
typeOnly.add(element.name.text)
|
|
363
|
+
}
|
|
364
|
+
} else if (statement.exportClause && ts.isNamespaceExport(statement.exportClause)) {
|
|
365
|
+
typeOnly.add(statement.exportClause.name.text)
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
if (typeOnly.size) {
|
|
370
|
+
const valueEdges = staticRuntimeExports(ts, file)
|
|
371
|
+
for (const name of values) {
|
|
372
|
+
if (typeOnly.has(name) && !valueEdges.has(name)) {
|
|
373
|
+
values.delete(name)
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
const result = { all, values }
|
|
379
|
+
cache.set(absolute, result)
|
|
380
|
+
return result
|
|
317
381
|
}
|
|
318
382
|
|
|
319
383
|
function declarationFiles(packageRoot, files) {
|