@kubb/parser-ts
Advanced tools
Comparing version 3.2.0 to 3.3.0
import 'typescript'; | ||
export { j as appendJSDocToNode, d as createArrayDeclaration, x as createArrayTypeNode, q as createEnumDeclaration, p as createExportDeclaration, D as createFalse, A as createIdentifier, o as createImportDeclaration, k as createIndexSignature, a as createIntersectionDeclaration, i as createJSDoc, y as createLiteralTypeNode, n as createNamespaceDeclaration, z as createNull, v as createNumericLiteral, r as createOmitDeclaration, h as createParameterSignature, g as createPropertySignature, c as createQuestionToken, w as createStringLiteral, C as createTrue, b as createTupleDeclaration, B as createTupleTypeNode, l as createTypeAliasDeclaration, t as createTypeLiteralNode, u as createTypeReferenceNode, e as createUnionDeclaration, s as keywordTypeNodes, m as modifiers } from './factory-1NIBrzkm.js'; | ||
export { j as appendJSDocToNode, d as createArrayDeclaration, A as createArrayTypeNode, t as createEnumDeclaration, r as createExportDeclaration, G as createFalse, D as createIdentifier, q as createImportDeclaration, k as createIndexSignature, n as createInterfaceDeclaration, a as createIntersectionDeclaration, i as createJSDoc, B as createLiteralTypeNode, p as createNamespaceDeclaration, C as createNull, y as createNumericLiteral, u as createOmitDeclaration, h as createParameterSignature, g as createPropertySignature, c as createQuestionToken, z as createStringLiteral, F as createTrue, b as createTupleDeclaration, E as createTupleTypeNode, l as createTypeAliasDeclaration, o as createTypeDeclaration, w as createTypeLiteralNode, x as createTypeReferenceNode, e as createUnionDeclaration, v as keywordTypeNodes, m as modifiers, s as syntaxKind } from './factory-BbbhTZjP.js'; |
@@ -1,3 +0,3 @@ | ||
export { appendJSDocToNode, createArrayDeclaration, createArrayTypeNode, createEnumDeclaration, createExportDeclaration, createFalse, createIdentifier, createImportDeclaration, createIndexSignature, createIntersectionDeclaration, createJSDoc, createLiteralTypeNode, createNamespaceDeclaration, createNull, createNumericLiteral, createOmitDeclaration, createParameterSignature, createPropertySignature, createQuestionToken, createStringLiteral, createTrue, createTupleDeclaration, createTupleTypeNode, createTypeAliasDeclaration, createTypeLiteralNode, createTypeReferenceNode, createUnionDeclaration, keywordTypeNodes, modifiers } from './chunk-RWXGFVS2.js'; | ||
export { appendJSDocToNode, createArrayDeclaration, createArrayTypeNode, createEnumDeclaration, createExportDeclaration, createFalse, createIdentifier, createImportDeclaration, createIndexSignature, createInterfaceDeclaration, createIntersectionDeclaration, createJSDoc, createLiteralTypeNode, createNamespaceDeclaration, createNull, createNumericLiteral, createOmitDeclaration, createParameterSignature, createPropertySignature, createQuestionToken, createStringLiteral, createTrue, createTupleDeclaration, createTupleTypeNode, createTypeAliasDeclaration, createTypeDeclaration, createTypeLiteralNode, createTypeReferenceNode, createUnionDeclaration, keywordTypeNodes, modifiers, syntaxKind } from './chunk-3AITTBIG.js'; | ||
//# sourceMappingURL=factory.js.map | ||
//# sourceMappingURL=factory.js.map |
import ts, { PrinterOptions } from 'typescript'; | ||
export { f as factory } from './factory-1NIBrzkm.js'; | ||
export { f as factory } from './factory-BbbhTZjP.js'; | ||
@@ -15,6 +15,6 @@ type PrintOptions = { | ||
/** | ||
* Format the generated code based on the TypeScript printer. | ||
* Format the generated code based on Prettier | ||
*/ | ||
declare function format(source: string, options?: Omit<PrintOptions, 'source'>): string; | ||
declare function format(source: string): Promise<string>; | ||
export { format, print }; |
@@ -1,3 +0,5 @@ | ||
export { factory_exports as factory } from './chunk-RWXGFVS2.js'; | ||
export { factory_exports as factory } from './chunk-3AITTBIG.js'; | ||
import ts from 'typescript'; | ||
import { format as format$1 } from 'prettier'; | ||
import pluginTypescript from 'prettier/plugins/typescript'; | ||
@@ -28,6 +30,17 @@ var { factory } = ts; | ||
} | ||
// src/format.ts | ||
function format(source, options = {}) { | ||
return print([], { source, noEmitHelpers: false, ...options }); | ||
var formatOptions = { | ||
tabWidth: 2, | ||
printWidth: 160, | ||
parser: "typescript", | ||
singleQuote: true, | ||
semi: false, | ||
bracketSameLine: false, | ||
endOfLine: "auto", | ||
plugins: [pluginTypescript] | ||
}; | ||
async function format(source) { | ||
if (!source) { | ||
return ""; | ||
} | ||
return format$1(source, formatOptions); | ||
} | ||
@@ -34,0 +47,0 @@ |
{ | ||
"name": "@kubb/parser-ts", | ||
"version": "3.2.0", | ||
"version": "3.3.0", | ||
"description": "TypeScript parser", | ||
@@ -52,2 +52,3 @@ "keywords": [ | ||
"remeda": "^2.17.4", | ||
"prettier": "^3.4.2", | ||
"typescript": "^5.7.2" | ||
@@ -57,4 +58,4 @@ }, | ||
"tsup": "^8.3.5", | ||
"@kubb/config-ts": "3.2.0", | ||
"@kubb/config-tsup": "3.2.0" | ||
"@kubb/config-ts": "3.3.0", | ||
"@kubb/config-tsup": "3.3.0" | ||
}, | ||
@@ -61,0 +62,0 @@ "engines": { |
import { isNumber } from 'remeda' | ||
import ts from 'typescript' | ||
import ts, { SyntaxKind } from 'typescript' | ||
@@ -15,2 +15,6 @@ const { factory } = ts | ||
export const syntaxKind = { | ||
union: SyntaxKind.UnionType as 192, | ||
} as const | ||
function isValidIdentifier(str: string): boolean { | ||
@@ -252,2 +256,56 @@ if (!str.length || str.trim() !== str) { | ||
export function createInterfaceDeclaration({ | ||
modifiers, | ||
name, | ||
typeParameters, | ||
members, | ||
}: { | ||
modifiers?: Array<ts.Modifier> | ||
name: string | ts.Identifier | ||
typeParameters?: Array<ts.TypeParameterDeclaration> | ||
members: Array<ts.TypeElement> | ||
}) { | ||
return factory.createInterfaceDeclaration(modifiers, name, typeParameters, undefined, members) | ||
} | ||
export function createTypeDeclaration({ | ||
syntax, | ||
isExportable, | ||
description, | ||
name, | ||
type, | ||
}: { | ||
syntax: 'type' | 'interface' | ||
description?: string | ||
isExportable?: boolean | ||
name: string | ts.Identifier | ||
type: ts.TypeNode | ||
}) { | ||
if (syntax === 'interface' && 'members' in type) { | ||
const node = createInterfaceDeclaration({ | ||
members: type.members as Array<ts.TypeElement>, | ||
modifiers: isExportable ? [modifiers.export] : [], | ||
name, | ||
typeParameters: undefined, | ||
}) | ||
return appendJSDocToNode({ | ||
node, | ||
comments: [description ? `@description ${description}` : undefined].filter(Boolean), | ||
}) | ||
} | ||
const node = createTypeAliasDeclaration({ | ||
type, | ||
modifiers: isExportable ? [modifiers.export] : [], | ||
name, | ||
typeParameters: undefined, | ||
}) | ||
return appendJSDocToNode({ | ||
node, | ||
comments: [description ? `@description ${description}` : undefined].filter(Boolean), | ||
}) | ||
} | ||
export function createNamespaceDeclaration({ | ||
@@ -254,0 +312,0 @@ statements, |
@@ -1,9 +0,27 @@ | ||
import { type PrintOptions, print } from './print.ts' | ||
import { format as prettierFormat } from 'prettier' | ||
import pluginTypescript from 'prettier/plugins/typescript' | ||
import type { Options } from 'prettier' | ||
const formatOptions: Options = { | ||
tabWidth: 2, | ||
printWidth: 160, | ||
parser: 'typescript', | ||
singleQuote: true, | ||
semi: false, | ||
bracketSameLine: false, | ||
endOfLine: 'auto', | ||
plugins: [pluginTypescript], | ||
} | ||
/** | ||
* Format the generated code based on the TypeScript printer. | ||
* Format the generated code based on Prettier | ||
*/ | ||
export function format(source: string, options: Omit<PrintOptions, 'source'> = {}) { | ||
export async function format(source: string) { | ||
// do some basic linting with the ts compiler | ||
return print([], { source, noEmitHelpers: false, ...options }) | ||
if (!source) { | ||
return '' | ||
} | ||
return prettierFormat(source, formatOptions) | ||
} |
@@ -1,2 +0,2 @@ | ||
import ts, { LanguageVariant } from 'typescript' | ||
import ts from 'typescript' | ||
@@ -3,0 +3,0 @@ import type { PrinterOptions } from 'typescript' |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
170122
2043
3
1
+ Addedprettier@^3.4.2
+ Addedprettier@3.4.2(transitive)