@kubb/parser-ts 5.20.1 → 5.20.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/dist/index.cjs CHANGED
@@ -11,7 +11,7 @@ var compatibility = {
11
11
  "node": ">=22.22"
12
12
  };
13
13
  // package.json
14
- var version = "5.20.1";
14
+ var version = "5.20.3";
15
15
  // src/inline.ts
16
16
  const keyStarts = /* @__PURE__ */ new Set([
17
17
  yuku_parser.TokenKind.LeftBrace,
package/dist/index.js CHANGED
@@ -10,7 +10,7 @@ var compatibility = {
10
10
  "node": ">=22.22"
11
11
  };
12
12
  // package.json
13
- var version = "5.20.1";
13
+ var version = "5.20.3";
14
14
  // src/inline.ts
15
15
  const keyStarts = /* @__PURE__ */ new Set([
16
16
  TokenKind.LeftBrace,
package/docs/options.md CHANGED
@@ -1,22 +1,18 @@
1
1
  # Options
2
2
 
3
- `parserTs` and `parserTsx` accept the same single option, `extension`, which rewrites the import and export extensions the TypeScript parser emits.
3
+ `parserTs()` and `parserTsx()` take one option, `extension`, which sets the extension on the relative imports and exports they write.
4
4
 
5
5
  ## Options overview
6
6
 
7
7
  | Option | Purpose | Default |
8
8
  | ------------------------- | --------------------------------------------------------------- | --------------- |
9
- | [`extension`](#extension) | Rewrite the extensions emitted in `import`/`export` statements. | `{ '.ts': '' }` |
9
+ | [`extension`](#extension) | Extension written on relative `import` and `export` specifiers. | `{ '.ts': '' }` |
10
10
 
11
11
  ## Option details
12
12
 
13
13
  ### extension
14
14
 
15
- Rewrites the extensions emitted in relative `import`/`export` statements. Each key is the extension of a generated file, and its value is the extension written on the relative specifiers in that file. `''` drops it, and so does a generated file whose extension has no key. Package specifiers and the on-disk filenames never change.
16
-
17
- Use `{ '.ts': '.js' }` to emit `.js` specifiers for ESM output compiled to JavaScript. Use `{ '.ts': '.ts' }` to keep `.ts` specifiers when you run the `.ts` files directly in Node.js or compile them with `rewriteRelativeImportExtensions`.
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 are rewritten the same way, so the whole output follows one convention.
15
+ Maps the extension of a generated file to the extension its relative specifiers get. `''` drops the extension. Package specifiers and the file names on disk never change.
20
16
 
21
17
  | | |
22
18
  | -------- | ------------------------ |
@@ -24,7 +20,15 @@ The same mapping applies to runtime templates a plugin copies into the output, s
24
20
  | Required | `false` |
25
21
  | Default | `{ '.ts': '' }` |
26
22
 
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
- ```
23
+ | Value | Writes | Use it when |
24
+ | ------------------------- | ------------------- | --------------------------------------------------------------------------------------------- |
25
+ | `{ '.ts': '' }` (default) | `import './api'` | A bundler or `moduleResolution: 'bundler'` resolves the files. |
26
+ | `{ '.ts': '.js' }` | `import './api.js'` | You compile the output to ESM JavaScript. |
27
+ | `{ '.ts': '.ts' }` | `import './api.ts'` | Node.js runs the `.ts` files directly, or you compile with `rewriteRelativeImportExtensions`. |
28
+
29
+ The same map applies to the runtime templates a plugin copies into the output, such as the `.kubb/` files of `@kubb/plugin-fetch`.
30
+
31
+ > [!NOTE]
32
+ > `parserTsx` reads only its own map. Set the `.tsx` key on it, such as `parserTsx({ extension: { '.tsx': '.js' } })`.
33
+
34
+ A file whose extension has no key also loses its extension. A relative specifier without an extension stays unchanged.
package/docs/overview.md CHANGED
@@ -1,24 +1,30 @@
1
1
  # TypeScript
2
2
 
3
- The TypeScript parser writes `.ts` and `.js` files. It turns each file's AST into source text with imports, exports, declarations, and JSDoc, and resolves relative import paths.
3
+ The TypeScript parser prints the `.ts` and `.js` files that plugins generate, with imports, exports, declarations, and JSDoc.
4
4
 
5
- The package also exports `parserTsx`, which writes `.tsx` and `.jsx` files with the same options.
5
+ - It rewrites relative import paths.
6
+ - The package also exports `parserTsx` for `.tsx` and `.jsx` files, with the same options.
6
7
 
7
8
  ## Setup
8
9
 
9
- Kubb registers `parserTs`, `parserTsx`, and `parserMd` by default, in `defineConfig` and in the bundler integrations, so no setup is needed. Set `parsers` in `defineConfig` only to change an option or add a parser. A custom `parsers` array replaces the default set, so list every parser your plugins need. Files that no parser claims are written as their source text only, without imports, exports, banner, or footer.
10
+ No setup is needed. `defineConfig` and the bundler integrations register `parserTs()`, `parserTsx()`, and `parserMd()` by default. Set `parsers` only to change an option or to add a parser.
10
11
 
11
- ## Options worth knowing
12
+ > [!WARNING]
13
+ > A custom `parsers` array replaces the default set, so list every parser your plugins need. A file that no parser claims is written as its source text only, without imports, exports, banner, or footer.
12
14
 
13
- - `extension` rewrites the extension of relative imports and exports. Each key is a generated file's extension, and each value is the extension its relative imports and exports get. `''` drops it. By default, imports in `.ts` files have no extension. Use `{ '.ts': '.js' }` for ESM packages. Use `{ '.ts': '.ts' }` when Node.js runs the `.ts` files directly, or when you compile with `rewriteRelativeImportExtensions`. Package imports stay unchanged.
15
+ ## Options worth knowing
14
16
 
15
- `parserTsx` reads its own `extension` map, so set the `.tsx` key on it as well.
17
+ | Option | Default | What it does |
18
+ | -------------------------------------------------------------------------------- | --------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------- |
19
+ | [`extension`](https://kubb.dev/extensions/kubb-labs/parser-ts/options#extension) | `{ '.ts': '' }` | Sets the extension that relative imports and exports get. Use `{ '.ts': '.js' }` for ESM output and `{ '.ts': '.ts' }` to run `.ts` files directly in Node.js. |
16
20
 
17
- See [Options](https://kubb.dev/extensions/kubb-labs/parser-ts/options) for its type and default.
21
+ `parserTsx` reads its own `extension` map, so set the `.tsx` key on it too.
18
22
 
19
23
  ## Example
20
24
 
21
- The config below adds `.js` to relative imports in `.ts` and `.tsx` files and keeps every default parser registered.
25
+ This config adds `.js` to relative imports in `.ts` and `.tsx` files and keeps every default parser.
26
+
27
+ ::code-group
22
28
 
23
29
  ```typescript [kubb.config.ts]
24
30
  import { defineConfig } from 'kubb/config'
@@ -34,8 +40,17 @@ export default defineConfig({
34
40
  parserTsx({ extension: { '.tsx': '.js' } }),
35
41
  parserMd(),
36
42
  ],
37
- plugins: [
38
- pluginTs(),
39
- ],
43
+ plugins: [pluginTs()],
40
44
  })
41
45
  ```
46
+
47
+ ```typescript [src/gen/types/Pet.ts]
48
+ import type { Category } from './Category.js'
49
+
50
+ export type Pet = {
51
+ category?: Category
52
+ name: string
53
+ }
54
+ ```
55
+
56
+ ::
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/parser-ts",
3
- "version": "5.20.1",
3
+ "version": "5.20.3",
4
4
  "description": "TypeScript and TSX parser for Kubb. Prints AST nodes as TypeScript and TSX source, with imports, exports and JSDoc.",
5
5
  "keywords": [
6
6
  "codegen",
@@ -64,8 +64,8 @@
64
64
  "registry": "https://registry.npmjs.org/"
65
65
  },
66
66
  "dependencies": {
67
- "@kubb/ast": "^5.20.1",
68
- "@kubb/core": "^5.20.1",
67
+ "@kubb/ast": "^5.20.3",
68
+ "@kubb/core": "^5.20.3",
69
69
  "yuku-parser": "^0.19.0"
70
70
  },
71
71
  "devDependencies": {