@kubb/parser-ts 5.0.0-beta.5 → 5.0.0-beta.50

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/extension.yaml CHANGED
@@ -2,7 +2,7 @@ $schema: https://kubb.dev/schemas/extension.json
2
2
  kind: parser
3
3
  id: parser-ts
4
4
  name: TypeScript
5
- description: TypeScript and TSX file parser for Kubb. Converts the universal AST to `.ts`/`.tsx` source code using the official TypeScript compiler.
5
+ description: Default file parser for Kubb. Converts the universal AST to `.ts`/`.tsx` source using the official TypeScript compiler.
6
6
  category: typescript
7
7
  type: official
8
8
  npmPackage: '@kubb/parser-ts'
@@ -29,23 +29,21 @@ featured: true
29
29
  icon:
30
30
  light: https://kubb.dev/feature/typescript.svg
31
31
  intro: |-
32
- The TypeScript parser is the default file parser used by Kubb when no `parsers` option is set in `defineConfig`. It converts Kubb's universal AST into `.ts` and `.tsx` source code using the official [TypeScript compiler](https://www.typescriptlang.org/).
32
+ `@kubb/parser-ts` takes the `FileNode` staged by your plugins and prints it as TypeScript source using the official [TypeScript compiler](https://www.typescriptlang.org/). It resolves import paths, deduplicates declarations, prints JSDoc, and rewrites extensions based on `output.extension`.
33
33
 
34
- Two parser instances are exported:
34
+ Two parsers are exported:
35
35
 
36
- - `parserTs` — handles `.ts` and `.js` files
37
- - `parserTsx` — handles `.tsx` and `.jsx` files
38
-
39
- Both are configured globally in `defineConfig` and apply to every file produced by every plugin.
36
+ - `parserTs` — handles `.ts` and `.js` files.
37
+ - `parserTsx` — handles `.tsx` and `.jsx` files. Use this for React projects so JSX in generated components is preserved.
40
38
  options:
41
39
  - name: extname
42
40
  type: "'.ts' | '.js' | '.tsx' | '.jsx' | string"
43
41
  required: false
44
42
  default: "'.ts'"
45
43
  description: |-
46
- File extension used when rewriting relative import paths. Set to `.js` for ESM-friendly emit, `.tsx` for React projects, or leave unset to keep TypeScript's default behaviour.
44
+ Controls which extension is written into the generated import specifiers. Set `.js` for ESM-compatible output, `.tsx` for React projects. Leave unset for the TypeScript default.
47
45
 
48
- Extension rewriting is configured via `output.extension` in `defineConfig`, not as a parser argument.
46
+ To rewrite extensions in the generated source (e.g. `./foo` → `./foo.js`), use `output.extension` in `defineConfig`, not this option.
49
47
  codeBlock:
50
48
  lang: typescript
51
49
  title: kubb.config.ts
@@ -56,10 +54,11 @@ options:
56
54
  import { parserTs } from '@kubb/parser-ts'
57
55
 
58
56
  export default defineConfig({
59
- input: { path: './petstore.yaml' },
57
+ input: { path: './petStore.yaml' },
60
58
  output: { path: './src/gen', extension: { '.ts': '.js' } },
61
59
  adapter: adapterOas(),
62
60
  parsers: [parserTs],
61
+ plugins: [],
63
62
  })
64
63
  examples:
65
64
  - name: TypeScript (default)
@@ -73,10 +72,11 @@ examples:
73
72
  import { parserTs } from '@kubb/parser-ts'
74
73
 
75
74
  export default defineConfig({
76
- input: { path: './petstore.yaml' },
75
+ input: { path: './petStore.yaml' },
77
76
  output: { path: './src/gen' },
78
77
  adapter: adapterOas(),
79
78
  parsers: [parserTs],
79
+ plugins: [],
80
80
  })
81
81
  - name: TSX (React)
82
82
  files:
@@ -89,12 +89,13 @@ examples:
89
89
  import { parserTsx } from '@kubb/parser-ts'
90
90
 
91
91
  export default defineConfig({
92
- input: { path: './petstore.yaml' },
92
+ input: { path: './petStore.yaml' },
93
93
  output: { path: './src/gen' },
94
94
  adapter: adapterOas(),
95
95
  parsers: [parserTsx],
96
+ plugins: [],
96
97
  })
97
98
  notes:
98
99
  - type: tip
99
100
  body: |-
100
- `parser-ts` is bundled with Kubb and used automatically when no `parsers` option is provided. You only need to install it explicitly when combining it with other parsers or providing a fully custom parsers list.
101
+ `@kubb/parser-ts` is bundled with Kubb and used automatically when no `parsers` option is set. Install it explicitly only when combining it with other parsers or providing a fully custom parser list.
package/package.json CHANGED
@@ -1,9 +1,8 @@
1
1
  {
2
2
  "name": "@kubb/parser-ts",
3
- "version": "5.0.0-beta.5",
4
- "description": "TypeScript and TSX file parser for Kubb, converting generated files to strings using the TypeScript compiler.",
3
+ "version": "5.0.0-beta.50",
4
+ "description": "TypeScript and TSX source file parser for Kubb. Converts AST nodes and raw TypeScript code into formatted source strings using the TypeScript compiler API.",
5
5
  "keywords": [
6
- "code-generator",
7
6
  "codegen",
8
7
  "kubb",
9
8
  "parser",
@@ -43,22 +42,23 @@
43
42
  },
44
43
  "dependencies": {
45
44
  "typescript": "^6.0.3",
46
- "@kubb/core": "5.0.0-beta.5"
45
+ "@kubb/core": "5.0.0-beta.50"
47
46
  },
48
47
  "devDependencies": {
49
48
  "@internals/utils": "0.0.0",
50
- "@kubb/ast": "5.0.0-beta.5"
49
+ "@kubb/ast": "5.0.0-beta.50"
51
50
  },
52
51
  "engines": {
53
52
  "node": ">=22"
54
53
  },
55
54
  "scripts": {
56
55
  "build": "tsdown",
57
- "clean": "npx rimraf ./dist",
56
+ "clean": "node -e \"require('node:fs').rmSync('./dist', {recursive:true,force:true})\"",
58
57
  "lint": "oxlint .",
59
58
  "lint:fix": "oxlint --fix .",
60
59
  "release": "pnpm publish --no-git-check",
61
60
  "release:canary": "bash ../../.github/canary.sh && node ../../scripts/build.js canary && pnpm publish --no-git-check",
61
+ "release:stage": "pnpm stage publish --no-git-check",
62
62
  "start": "tsdown --watch",
63
63
  "test": "vitest --passWithNoTests",
64
64
  "typecheck": "tsc -p ./tsconfig.json --noEmit --emitDeclarationOnly false"
package/src/constants.ts CHANGED
@@ -1,8 +1,18 @@
1
1
  /**
2
- * Number of spaces used to indent a nested block when pretty-printing.
2
+ * Character used for a single indent step. Set to `'\t'` to emit tab-indented output.
3
+ */
4
+ export const INDENT_CHAR = ' '
5
+
6
+ /**
7
+ * Number of {@link INDENT_CHAR} repeats that make up one nesting level.
3
8
  */
4
9
  export const INDENT_SIZE = 2 as const
5
10
 
11
+ /**
12
+ * Indentation unit prepended once per nesting level when pretty-printing.
13
+ */
14
+ export const INDENT = INDENT_CHAR.repeat(INDENT_SIZE)
15
+
6
16
  /**
7
17
  * Matches the trailing `.<ext>` segment of a path (keeps segments like `foo.bar.ts`
8
18
  * intact by only trimming the last run of non-`/`/`.` characters).
@@ -15,23 +25,23 @@ export const FILE_EXTENSION_PATTERN = /\.[^/.]+$/
15
25
  export const WINDOWS_PATH_SEPARATOR = /\\/g
16
26
 
17
27
  /**
18
- * Matches `*\/` in free-form text so JSDoc bodies can neutralise premature
28
+ * Matches `*\/` in free-form text so JSDoc bodies can neutralize premature
19
29
  * comment terminators (`*\/` → `* /`).
20
30
  */
21
31
  export const JSDOC_TERMINATOR_PATTERN = /\*\//g
22
32
 
23
33
  /**
24
- * Matches carriage returns for normalising CRLF/CR line endings to LF.
34
+ * Matches carriage returns for normalizing CRLF/CR line endings to LF.
25
35
  */
26
36
  export const CARRIAGE_RETURN_PATTERN = /\r/g
27
37
 
28
38
  /**
29
- * Matches CRLF sequences used when normalising TypeScript printer output.
39
+ * Matches CRLF sequences used when normalizing TypeScript printer output.
30
40
  */
31
41
  export const CRLF_PATTERN = /\r\n/g
32
42
 
33
43
  /**
34
- * Matches an identifier that starts with a digit JavaScript disallows this
44
+ * Matches an identifier that starts with a digit. JavaScript disallows this,
35
45
  * so the printer prefixes such names with `_`.
36
46
  */
37
47
  export const LEADING_DIGIT_PATTERN = /^\d/
package/src/index.ts CHANGED
@@ -1,2 +1,2 @@
1
- export { createExport, createImport, parserTs, print, safePrint, validateNodes } from './parserTs.ts'
1
+ export { parserTs } from './parserTs.ts'
2
2
  export { parserTsx } from './parserTsx.ts'