@kubb/parser-ts 3.14.0 → 3.14.1
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 +3 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +3 -12
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
- package/src/print.ts +8 -17
package/dist/index.cjs
CHANGED
|
@@ -21,18 +21,9 @@ function print(elements, { source = "", baseName = "print.ts", removeComments, n
|
|
|
21
21
|
removeComments,
|
|
22
22
|
noEmitHelpers
|
|
23
23
|
});
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
if (Array.isArray(elements)) {
|
|
29
|
-
nodes = elements.filter(Boolean);
|
|
30
|
-
} else {
|
|
31
|
-
nodes = [elements].filter(Boolean);
|
|
32
|
-
}
|
|
33
|
-
const outputFile = printer.printList(ts__default.default.ListFormat.MultiLine, factory.createNodeArray(nodes), sourceFile);
|
|
34
|
-
const outputSource = printer.printFile(sourceFile);
|
|
35
|
-
return [outputFile, restoreNewLines(outputSource)].filter(Boolean).join("\n");
|
|
24
|
+
const nodes = (Array.isArray(elements) ? elements : [elements]).filter(Boolean).sort((a, b) => (a.pos ?? 0) - (b.pos ?? 0));
|
|
25
|
+
const output = printer.printList(ts__default.default.ListFormat.MultiLine, factory.createNodeArray(nodes), sourceFile);
|
|
26
|
+
return restoreNewLines(output).replace(/\r\n/g, "\n");
|
|
36
27
|
}
|
|
37
28
|
var formatOptions = {
|
|
38
29
|
tabWidth: 2,
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/print.ts","../src/format.ts"],"names":["ts","pluginTypescript","prettierFormat"],"mappings":";;;;;;;;;;;;AAIA,IAAM,EAAE,SAAY,GAAAA,mBAAA;AAapB,IAAM,iBAAiB,CAAC,IAAA,KAAiB,I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,OAAQ,CAAA,SAAA,CAAUA,mBAAG,CAAA,UAAA,CAAW,WAAW,OAAQ,CAAA,eAAA,CAAgB,KAAK,CAAA,EAAG,UAAU,CAAA;AAEpG,EAAA,OAAO,eAAgB,CAAA,MAAM,CAAE,CAAA,OAAA,CAAQ,SAAS,IAAI,CAAA;AACtD;AC3CA,IAAM,aAAyB,GAAA;AAAA,EAC7B,QAAU,EAAA,CAAA;AAAA,EACV,UAAY,EAAA,GAAA;AAAA,EACZ,MAAQ,EAAA,YAAA;AAAA,EACR,WAAa,EAAA,IAAA;AAAA,EACb,IAAM,EAAA,KAAA;AAAA,EACN,eAAiB,EAAA,KAAA;AAAA,EACjB,SAAW,EAAA,MAAA;AAAA,EACX,OAAA,EAAS,CAACC,iCAAgB;AAC5B,CAAA;AAKA,eAAsB,OAAO,MAAgB,EAAA;AAE3C,EAAA,IAAI,CAAC,MAAQ,EAAA;AACX,IAAO,OAAA,EAAA;AAAA;AAGT,EAAO,OAAAC,eAAA,CAAe,QAAQ,aAAa,CAAA;AAC7C","file":"index.cjs","sourcesContent":["import ts from 'typescript'\n\nimport type { PrinterOptions } from 'typescript'\n\nconst { factory } = ts\n\nexport type PrintOptions = {\n source?: string\n baseName?: string\n scriptKind?: ts.ScriptKind\n} & PrinterOptions\n\n/**\n * Escaped new lines in code with block comments so they can be restored by {@link restoreNewLines}\n * @param code The code to escape new lines in\n * @returns The same code but with new lines escaped using block comments\n */\nconst escapeNewLines = (code: string) => code.replace(/\\n\\n/g, '\\n/* :newline: */')\n\n/**\n * Reverses {@link escapeNewLines} and restores new lines\n * @param code The code with escaped new lines\n * @returns The same code with new lines restored\n */\nconst restoreNewLines = (code: string) => code.replace(/\\/\\* :newline: \\*\\//g, '\\n')\n\n/**\n * Convert AST TypeScript nodes to a string based on the TypeScript printer.\n * Ensures consistent output across environments.\n */\nexport function print(\n elements: Array<ts.Node>,\n { source = '', baseName = 'print.ts', removeComments, noEmitHelpers, newLine = ts.NewLineKind.LineFeed, scriptKind = ts.ScriptKind.TS }: PrintOptions = {},\n): string {\n const sourceFile = ts.createSourceFile(baseName, escapeNewLines(source), ts.ScriptTarget.ES2022, false, scriptKind)\n\n const printer = ts.createPrinter({\n omitTrailingSemicolon: true,\n newLine,\n removeComments,\n noEmitHelpers,\n })\n // make sure that the nodes have the same order on every machine\n const nodes = (Array.isArray(elements) ? elements : [elements]).filter(Boolean).sort((a, b) => (a.pos ?? 0) - (b.pos ?? 0))\n\n const output = printer.printList(ts.ListFormat.MultiLine, factory.createNodeArray(nodes), sourceFile)\n\n return restoreNewLines(output).replace(/\\r\\n/g, '\\n')\n}\n","import { format as prettierFormat } from 'prettier'\nimport pluginTypescript from 'prettier/plugins/typescript'\n\nimport type { Options } from 'prettier'\n\nconst formatOptions: Options = {\n tabWidth: 2,\n printWidth: 160,\n parser: 'typescript',\n singleQuote: true,\n semi: false,\n bracketSameLine: false,\n endOfLine: 'auto',\n plugins: [pluginTypescript],\n}\n\n/**\n * Format the generated code based on Prettier\n */\nexport async function format(source: string) {\n // do some basic linting with the ts compiler\n if (!source) {\n return ''\n }\n\n return prettierFormat(source, formatOptions)\n}\n"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -8,6 +8,7 @@ type PrintOptions = {
|
|
|
8
8
|
} & PrinterOptions;
|
|
9
9
|
/**
|
|
10
10
|
* Convert AST TypeScript nodes to a string based on the TypeScript printer.
|
|
11
|
+
* Ensures consistent output across environments.
|
|
11
12
|
*/
|
|
12
13
|
declare function print(elements: Array<ts.Node>, { source, baseName, removeComments, noEmitHelpers, newLine, scriptKind }?: PrintOptions): string;
|
|
13
14
|
|
package/dist/index.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ type PrintOptions = {
|
|
|
8
8
|
} & PrinterOptions;
|
|
9
9
|
/**
|
|
10
10
|
* Convert AST TypeScript nodes to a string based on the TypeScript printer.
|
|
11
|
+
* Ensures consistent output across environments.
|
|
11
12
|
*/
|
|
12
13
|
declare function print(elements: Array<ts.Node>, { source, baseName, removeComments, noEmitHelpers, newLine, scriptKind }?: PrintOptions): string;
|
|
13
14
|
|
package/dist/index.js
CHANGED
|
@@ -14,18 +14,9 @@ function print(elements, { source = "", baseName = "print.ts", removeComments, n
|
|
|
14
14
|
removeComments,
|
|
15
15
|
noEmitHelpers
|
|
16
16
|
});
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
if (Array.isArray(elements)) {
|
|
22
|
-
nodes = elements.filter(Boolean);
|
|
23
|
-
} else {
|
|
24
|
-
nodes = [elements].filter(Boolean);
|
|
25
|
-
}
|
|
26
|
-
const outputFile = printer.printList(ts.ListFormat.MultiLine, factory.createNodeArray(nodes), sourceFile);
|
|
27
|
-
const outputSource = printer.printFile(sourceFile);
|
|
28
|
-
return [outputFile, restoreNewLines(outputSource)].filter(Boolean).join("\n");
|
|
17
|
+
const nodes = (Array.isArray(elements) ? elements : [elements]).filter(Boolean).sort((a, b) => (a.pos ?? 0) - (b.pos ?? 0));
|
|
18
|
+
const output = printer.printList(ts.ListFormat.MultiLine, factory.createNodeArray(nodes), sourceFile);
|
|
19
|
+
return restoreNewLines(output).replace(/\r\n/g, "\n");
|
|
29
20
|
}
|
|
30
21
|
var formatOptions = {
|
|
31
22
|
tabWidth: 2,
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/print.ts","../src/format.ts"],"names":["prettierFormat"],"mappings":";;;;;AAIA,IAAM,EAAE,SAAY,GAAA,EAAA;AAapB,IAAM,iBAAiB,CAAC,IAAA,KAAiB,IAAK,CAAA,OAAA,CAAQ,SAAS,mBAAmB,CAAA;AAOlF,IAAM,kBAAkB,CAAC,IAAA,KAAiB,IAAK,CAAA,OAAA,CAAQ,wBAAwB,IAAI,CAAA;
|
|
1
|
+
{"version":3,"sources":["../src/print.ts","../src/format.ts"],"names":["prettierFormat"],"mappings":";;;;;AAIA,IAAM,EAAE,SAAY,GAAA,EAAA;AAapB,IAA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;AAAA,EACZ,MAAQ,EAAA,YAAA;AAAA,EACR,WAAa,EAAA,IAAA;AAAA,EACb,IAAM,EAAA,KAAA;AAAA,EACN,eAAiB,EAAA,KAAA;AAAA,EACjB,SAAW,EAAA,MAAA;AAAA,EACX,OAAA,EAAS,CAAC,gBAAgB;AAC5B,CAAA;AAKA,eAAsB,OAAO,MAAgB,EAAA;AAE3C,EAAA,IAAI,CAAC,MAAQ,EAAA;AACX,IAAO,OAAA,EAAA;AAAA;AAGT,EAAO,OAAAA,QAAA,CAAe,QAAQ,aAAa,CAAA;AAC7C","file":"index.js","sourcesContent":["import ts from 'typescript'\n\nimport type { PrinterOptions } from 'typescript'\n\nconst { factory } = ts\n\nexport type PrintOptions = {\n source?: string\n baseName?: string\n scriptKind?: ts.ScriptKind\n} & PrinterOptions\n\n/**\n * Escaped new lines in code with block comments so they can be restored by {@link restoreNewLines}\n * @param code The code to escape new lines in\n * @returns The same code but with new lines escaped using block comments\n */\nconst escapeNewLines = (code: string) => code.replace(/\\n\\n/g, '\\n/* :newline: */')\n\n/**\n * Reverses {@link escapeNewLines} and restores new lines\n * @param code The code with escaped new lines\n * @returns The same code with new lines restored\n */\nconst restoreNewLines = (code: string) => code.replace(/\\/\\* :newline: \\*\\//g, '\\n')\n\n/**\n * Convert AST TypeScript nodes to a string based on the TypeScript printer.\n * Ensures consistent output across environments.\n */\nexport function print(\n elements: Array<ts.Node>,\n { source = '', baseName = 'print.ts', removeComments, noEmitHelpers, newLine = ts.NewLineKind.LineFeed, scriptKind = ts.ScriptKind.TS }: PrintOptions = {},\n): string {\n const sourceFile = ts.createSourceFile(baseName, escapeNewLines(source), ts.ScriptTarget.ES2022, false, scriptKind)\n\n const printer = ts.createPrinter({\n omitTrailingSemicolon: true,\n newLine,\n removeComments,\n noEmitHelpers,\n })\n // make sure that the nodes have the same order on every machine\n const nodes = (Array.isArray(elements) ? elements : [elements]).filter(Boolean).sort((a, b) => (a.pos ?? 0) - (b.pos ?? 0))\n\n const output = printer.printList(ts.ListFormat.MultiLine, factory.createNodeArray(nodes), sourceFile)\n\n return restoreNewLines(output).replace(/\\r\\n/g, '\\n')\n}\n","import { format as prettierFormat } from 'prettier'\nimport pluginTypescript from 'prettier/plugins/typescript'\n\nimport type { Options } from 'prettier'\n\nconst formatOptions: Options = {\n tabWidth: 2,\n printWidth: 160,\n parser: 'typescript',\n singleQuote: true,\n semi: false,\n bracketSameLine: false,\n endOfLine: 'auto',\n plugins: [pluginTypescript],\n}\n\n/**\n * Format the generated code based on Prettier\n */\nexport async function format(source: string) {\n // do some basic linting with the ts compiler\n if (!source) {\n return ''\n }\n\n return prettierFormat(source, formatOptions)\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/parser-ts",
|
|
3
|
-
"version": "3.14.
|
|
3
|
+
"version": "3.14.1",
|
|
4
4
|
"description": "TypeScript parsing and manipulation utilities for Kubb, enabling code generation with proper TypeScript syntax and formatting.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -53,13 +53,13 @@
|
|
|
53
53
|
],
|
|
54
54
|
"dependencies": {
|
|
55
55
|
"prettier": "^3.6.2",
|
|
56
|
-
"remeda": "^2.
|
|
57
|
-
"typescript": "
|
|
56
|
+
"remeda": "^2.25.0",
|
|
57
|
+
"typescript": "5.8.3"
|
|
58
58
|
},
|
|
59
59
|
"devDependencies": {
|
|
60
60
|
"tsup": "^8.5.0",
|
|
61
|
-
"@kubb/config-ts": "3.14.
|
|
62
|
-
"@kubb/config-tsup": "3.14.
|
|
61
|
+
"@kubb/config-ts": "3.14.1",
|
|
62
|
+
"@kubb/config-tsup": "3.14.1"
|
|
63
63
|
},
|
|
64
64
|
"engines": {
|
|
65
65
|
"node": ">=20"
|
package/src/print.ts
CHANGED
|
@@ -12,47 +12,38 @@ export type PrintOptions = {
|
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* Escaped new lines in code with block comments so they can be restored by {@link restoreNewLines}
|
|
15
|
-
* @param
|
|
15
|
+
* @param code The code to escape new lines in
|
|
16
16
|
* @returns The same code but with new lines escaped using block comments
|
|
17
17
|
*/
|
|
18
18
|
const escapeNewLines = (code: string) => code.replace(/\n\n/g, '\n/* :newline: */')
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
21
|
* Reverses {@link escapeNewLines} and restores new lines
|
|
22
|
-
* @param
|
|
22
|
+
* @param code The code with escaped new lines
|
|
23
23
|
* @returns The same code with new lines restored
|
|
24
24
|
*/
|
|
25
25
|
const restoreNewLines = (code: string) => code.replace(/\/\* :newline: \*\//g, '\n')
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
28
|
* Convert AST TypeScript nodes to a string based on the TypeScript printer.
|
|
29
|
+
* Ensures consistent output across environments.
|
|
29
30
|
*/
|
|
30
31
|
export function print(
|
|
31
32
|
elements: Array<ts.Node>,
|
|
32
33
|
{ source = '', baseName = 'print.ts', removeComments, noEmitHelpers, newLine = ts.NewLineKind.LineFeed, scriptKind = ts.ScriptKind.TS }: PrintOptions = {},
|
|
33
34
|
): string {
|
|
34
35
|
const sourceFile = ts.createSourceFile(baseName, escapeNewLines(source), ts.ScriptTarget.ES2022, false, scriptKind)
|
|
36
|
+
|
|
35
37
|
const printer = ts.createPrinter({
|
|
36
38
|
omitTrailingSemicolon: true,
|
|
37
39
|
newLine,
|
|
38
40
|
removeComments,
|
|
39
41
|
noEmitHelpers,
|
|
40
42
|
})
|
|
43
|
+
// make sure that the nodes have the same order on every machine
|
|
44
|
+
const nodes = (Array.isArray(elements) ? elements : [elements]).filter(Boolean).sort((a, b) => (a.pos ?? 0) - (b.pos ?? 0))
|
|
41
45
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
if (!elements) {
|
|
45
|
-
return ''
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
if (Array.isArray(elements)) {
|
|
49
|
-
nodes = elements.filter(Boolean)
|
|
50
|
-
} else {
|
|
51
|
-
nodes = [elements].filter(Boolean)
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const outputFile = printer.printList(ts.ListFormat.MultiLine, factory.createNodeArray(nodes), sourceFile)
|
|
55
|
-
const outputSource = printer.printFile(sourceFile)
|
|
46
|
+
const output = printer.printList(ts.ListFormat.MultiLine, factory.createNodeArray(nodes), sourceFile)
|
|
56
47
|
|
|
57
|
-
return
|
|
48
|
+
return restoreNewLines(output).replace(/\r\n/g, '\n')
|
|
58
49
|
}
|