ReviewOS

also looking at this

stacks/dtsx

feat(stx): generate component declarations

#3105
Merged chris wants to merge codex/stx-component-declarations into main
19 files +894 -37

Review threads live on the whole diff, not on one commit, so none are shown here - a thread's line means something in the branch's final form, and painting it into an intermediate step would put it on code it is not about.

README.mdmodified+27-2
Changes to README.md
@@ -52,7 +52,7 @@ import { generate, processSource } from '@stacksjs/dtsx'
5252const options: DtsGenerationOptions = {
5353 cwd: './', // default: process.cwd()
5454 root: './src', // default: './src'
55 entrypoints: ['**/*.ts'], // default: ['**/*.ts']
55 entrypoints: ['**/*.{ts,tsx,mts,cts,vue,stx}'], // default
5656 outdir: './dist', // default: './dist'
5757 clean: true, // default: false
5858 verbose: true, // default: false
@@ -80,6 +80,31 @@ console.log(dtsContent)
8080// export declare function greet(name: string): string;
8181```
8282
83### STX Components
84
85`.stx` files are declaration entrypoints alongside TypeScript and Vue files.
86dtsx reads Vue-style `<script server|client>` blocks and Blade-style `@ts`
87blocks, then emits an `@stacksjs/stx` `DefineComponent` declaration. Props are
88derived from typed macros, runtime prop schemas, explicit `props as Props`
89assertions, and legacy `$props.name` access:
90
91```stx
92<script server lang="ts">
93interface CardProps {
94 title: string
95 count?: number
96}
97
98const props = withDefaults(defineProps<CardProps>(), { count: 0 })
99</script>
100
101<article>{{ props.title }}</article>
102```
103
104This emits `Card.d.ts` with `{ title: string; count?: number }` as its `$props`
105contract. The same transform feeds the semantic inference path and the
106annotation-first `isolatedDeclarations` path.
107
83108Library usage can also be configured using a `dts.config.ts` _(or `dts.config.js`)_ file, automatically loaded when running `./dtsx` _(or `bunx dtsx`)_ and when calling `generate()` unless custom options are provided.
84109
85110```ts
@@ -185,7 +210,7 @@ cat src/utils.ts | dtsx stdin > dist/utils.d.ts
185210
186211- `--cwd <path>`: Set the current working directory _(default: current directory)_
187212- `--root <path>`: Specify the root directory of the project _(default: './src')_
188- `--entrypoints <files>`: Define entry point files _(comma-separated, default: '**/*.ts')_
213- `--entrypoints <files>`: Define entry point files _(comma-separated, default: `**/*.{ts,tsx,mts,cts,vue,stx}`)_
189214- `--outdir <path>`: Set the output directory for generated .d.ts files _(default: './dist')_
190215- `--keep-comments`: Keep comments in generated .d.ts files _(default: true)_
191216- `--clean`: Clean output directory before generation _(default: false)_
docs/usage.mdmodified+2-2
Changes to docs/usage.md
@@ -25,7 +25,7 @@ import { generate } from '@stacksjs/dtsx'
2525const config: DtsGenerationConfig = {
2626 cwd: './', // default: process.cwd()
2727 root: './src', // default: './src'
28 entrypoints: ['**/*.ts'], // default: ['**/*.ts']
28 entrypoints: ['**/*.{ts,tsx,mts,cts,vue,stx}'], // default
2929 outdir: './dist', // default: './dist'
3030 keepComments: true, // default: true
3131 clean: true, // default: true
@@ -134,7 +134,7 @@ dtsx generate --output-structure flat
134134|--------|------|---------|-------------|
135135| `--cwd <path>` | `string` | current directory | Set the current working directory |
136136| `--root <path>` | `string` | `'./src'` | Specify the root directory of the project |
137| `--entrypoints <files>` | `string` | `'**/*.ts'` | Define entry point files (comma-separated) |
137| `--entrypoints <files>` | `string` | `'**/*.{ts,tsx,mts,cts,vue,stx}'` | Define entry point files (comma-separated) |
138138| `--outdir <path>` | `string` | `'./dist'` | Set the output directory for generated .d.ts files |
139139| `--keep-comments [value]` | `boolean` | `true` | Keep comments in generated .d.ts files |
140140| `--clean` | `boolean` | `true` | Clean output directory before generation |
packages/dtsx/README.mdmodified+9-2
Changes to packages/dtsx/README.md
@@ -64,7 +64,7 @@ import { generate } from '@stacksjs/dtsx'
6464const options: DtsGenerationOptions = {
6565 cwd: './', // default: process.cwd()
6666 root: './src', // default: './src'
67 entrypoints: ['**/*.ts'], // default: ['**/*.ts']
67 entrypoints: ['**/*.{ts,tsx,mts,cts,vue,stx}'], // default
6868 outdir: './dist', // default: './dist'
6969 clean: true, // default: false
7070 verbose: true, // default: false
@@ -74,6 +74,13 @@ const options: DtsGenerationOptions = {
7474await generate(options)
7575```
7676
77### STX Components
78
79`.stx` entrypoints support Vue-style script blocks, Blade-style `@ts` blocks,
80typed and runtime `defineProps`, `props as Props`, and legacy `$props.name`
81contracts. dtsx emits the default component as
82`DefineComponent<Props>` from `@stacksjs/stx` in semantic and isolated modes.
83
7784### Configuration File
7885
7986Library usage can also be configured using a `dts.config.ts` _(or `dts.config.js`)_ file which is automatically loaded when running the `./dtsx` _(or `bunx dtsx`)_ command. It is also loaded when the `generate` function is called, unless custom options are provided.
@@ -269,7 +276,7 @@ echo "export function foo(): string { return 'bar' }" | dtsx stdin
269276#### Generate Options
270277
271278- `--root <path>`: Specify the root directory of the project _(default: './src')_
272- `--entrypoints <files>`: Define entry point files _(comma-separated, default: '**/*.ts')_
279- `--entrypoints <files>`: Define entry point files _(comma-separated, default: `**/*.{ts,tsx,mts,cts,vue,stx}`)_
273280- `--outdir <path>`: Set the output directory for generated .d.ts files _(default: './dist')_
274281- `--keep-comments`: Keep comments in generated .d.ts files _(default: true)_
275282- `--clean`: Clean output directory before generation _(default: false)_