@kubb/parser-ts 5.8.2 → 5.8.3
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 +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/docs/options.md +30 -0
- package/{OVERVIEW.md → docs/overview.md} +11 -6
- package/kubb-extension.json +2 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
[![Node][node-src]][node-href]
|
|
11
11
|
|
|
12
12
|
<h4>
|
|
13
|
-
<a href="https://kubb.dev" target="_blank">Documentation</a>
|
|
13
|
+
<a href="https://kubb.dev/extensions/kubb-labs/parser-ts" target="_blank">Documentation</a>
|
|
14
14
|
<span> · </span>
|
|
15
15
|
<a href="https://github.com/kubb-labs/kubb/issues/" target="_blank">Report Bug</a>
|
|
16
16
|
<span> · </span>
|
package/dist/index.cjs
CHANGED
package/dist/index.js
CHANGED
package/docs/options.md
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# Options
|
|
2
|
+
|
|
3
|
+
`parserTs` and `parserTsx` accept the same single option, `extension`, which rewrites the import and export extensions the TypeScript parser emits.
|
|
4
|
+
|
|
5
|
+
## Options overview
|
|
6
|
+
|
|
7
|
+
| Option | Purpose | Default |
|
|
8
|
+
| ------------------------- | --------------------------------------------------------------- | --------------- |
|
|
9
|
+
| [`extension`](#extension) | Rewrite the extensions emitted in `import`/`export` statements. | `{ '.ts': '' }` |
|
|
10
|
+
|
|
11
|
+
## Option details
|
|
12
|
+
|
|
13
|
+
### extension
|
|
14
|
+
|
|
15
|
+
Rewrites the extensions emitted in `import`/`export` statements. Keys are the source extension, values the output, and `''` drops it. Only the module-specifier string changes, never the on-disk filename.
|
|
16
|
+
|
|
17
|
+
Use it to emit `.js` imports from `.ts` sources for an ESM dual package, or to keep the source extension for Node16/NodeNext resolution.
|
|
18
|
+
|
|
19
|
+
The same mapping applies to runtime templates a plugin copies into the output, such as the `.kubb/` runtime files of `@kubb/plugin-fetch`. Their top-level `import` and `export … from` statements become import and export nodes, so the whole output follows one convention.
|
|
20
|
+
|
|
21
|
+
| | |
|
|
22
|
+
| -------- | ------------------------ |
|
|
23
|
+
| Type | `Record<string, string>` |
|
|
24
|
+
| Required | `false` |
|
|
25
|
+
| Default | `{ '.ts': '' }` |
|
|
26
|
+
|
|
27
|
+
```typescript
|
|
28
|
+
parserTs({ extension: { '.ts': '.js' } }) // import './api.js' instead of './api'
|
|
29
|
+
parserTs({ extension: { '.ts': '.ts' } }) // import './api.ts' instead of './api'
|
|
30
|
+
```
|
|
@@ -8,19 +8,24 @@ The package also exports `parserTsx`, which handles `.tsx` and `.jsx` files with
|
|
|
8
8
|
|
|
9
9
|
Set `defineConfig.parsers` only to change an option. A custom `parsers` array replaces the default set, so list every parser your plugins need. Files no parser claims are written as their source text.
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
## Options
|
|
12
|
+
|
|
13
|
+
`extension` rewrites the extension of relative imports and exports. Keys are the source extension and values the output, and `''` drops it. By default `.ts` imports have no extension. Use `{ '.ts': '.js' }` for ESM packages, or `{ '.ts': '.ts' }` for Node.js `NodeNext` resolution. Package imports stay unchanged. See [Options](https://kubb.dev/extensions/kubb-labs/parser-ts/options) for its type and default.
|
|
14
|
+
|
|
15
|
+
## Example
|
|
16
|
+
|
|
17
|
+
Override import extensions while keeping every default parser registered.
|
|
18
|
+
|
|
19
|
+
```typescript [kubb.config.ts]
|
|
12
20
|
import { defineConfig } from 'kubb/config'
|
|
13
21
|
import { parserTs, parserTsx } from '@kubb/parser-ts'
|
|
14
22
|
import { parserMd } from '@kubb/parser-md'
|
|
23
|
+
import { pluginTs } from '@kubb/plugin-ts'
|
|
15
24
|
|
|
16
25
|
export default defineConfig({
|
|
17
26
|
input: './petStore.yaml',
|
|
18
27
|
output: { path: './src/gen' },
|
|
19
28
|
parsers: [parserTs({ extension: { '.ts': '.js' } }), parserTsx(), parserMd()],
|
|
20
|
-
plugins: [],
|
|
29
|
+
plugins: [pluginTs()],
|
|
21
30
|
})
|
|
22
31
|
```
|
|
23
|
-
|
|
24
|
-
## Options
|
|
25
|
-
|
|
26
|
-
`extension` rewrites the extension of relative imports and exports. Keys are the source extension and values the output, and `''` drops it. By default `.ts` imports have no extension. Use `{ '.ts': '.js' }` for ESM packages, or `{ '.ts': '.ts' }` for Node.js `NodeNext` resolution. Package imports stay unchanged.
|
package/kubb-extension.json
CHANGED
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
"light": "https://kubb.dev/feature/typescript.svg"
|
|
11
11
|
},
|
|
12
12
|
"tags": ["typescript", "tsx", "parser", "printer", "ast"],
|
|
13
|
-
"docs": "https://kubb.dev/
|
|
13
|
+
"docs": "https://kubb.dev/extensions/kubb-labs/parser-ts",
|
|
14
|
+
"maintainers": [{ "name": "Stijn Van Hulle", "github": "stijnvanhulle" }],
|
|
14
15
|
"compatibility": {
|
|
15
16
|
"kubb": ">=5.8.0",
|
|
16
17
|
"node": ">=22"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/parser-ts",
|
|
3
|
-
"version": "5.8.
|
|
3
|
+
"version": "5.8.3",
|
|
4
4
|
"description": "TypeScript and TSX source file parser for Kubb. Converts AST nodes into formatted source strings using the TypeScript compiler API.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"codegen",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"tsx",
|
|
11
11
|
"typescript"
|
|
12
12
|
],
|
|
13
|
-
"homepage": "https://kubb.dev/
|
|
13
|
+
"homepage": "https://kubb.dev/extensions/kubb-labs/parser-ts",
|
|
14
14
|
"license": "MIT",
|
|
15
15
|
"author": "stijnvanhulle",
|
|
16
16
|
"repository": {
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"files": [
|
|
36
36
|
"dist",
|
|
37
37
|
"kubb-extension.json",
|
|
38
|
-
"
|
|
38
|
+
"docs",
|
|
39
39
|
"!/**/**.test.**",
|
|
40
40
|
"!/**/__tests__/**",
|
|
41
41
|
"!/**/__snapshots__/**"
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
"registry": "https://registry.npmjs.org/"
|
|
60
60
|
},
|
|
61
61
|
"dependencies": {
|
|
62
|
-
"@kubb/kit": "5.8.
|
|
62
|
+
"@kubb/kit": "5.8.3",
|
|
63
63
|
"typescript": "^6.0.3"
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|