@kubb/core 1.0.0 → 1.0.2
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 +300 -205
- package/dist/index.d.ts +292 -247
- package/dist/index.js +300 -207
- package/package.json +7 -10
- package/src/build.ts +32 -44
- package/src/config.ts +2 -2
- package/src/generators/SchemaGenerator.ts +1 -1
- package/src/generators/index.ts +2 -2
- package/src/index.ts +9 -8
- package/src/managers/fileManager/FileManager.ts +5 -5
- package/src/managers/fileManager/index.ts +3 -3
- package/src/managers/fileManager/types.ts +3 -0
- package/src/managers/fileManager/utils.ts +9 -11
- package/src/managers/index.ts +2 -2
- package/src/managers/pluginManager/ParallelPluginError.ts +15 -0
- package/src/managers/pluginManager/PluginError.ts +11 -0
- package/src/managers/pluginManager/PluginManager.ts +129 -64
- package/src/managers/pluginManager/index.ts +5 -3
- package/src/managers/pluginManager/types.ts +10 -1
- package/src/managers/pluginManager/validate.ts +1 -1
- package/src/plugin.ts +34 -5
- package/src/types.ts +31 -4
- package/src/utils/clean.ts +2 -10
- package/src/utils/getStackTrace.ts +19 -0
- package/src/utils/index.ts +17 -16
- package/src/utils/isPromise.ts +1 -1
- package/src/utils/read.ts +2 -2
- package/src/utils/transformReservedWord.ts +2 -2
- package/src/utils/write.ts +2 -2
- package/dist/index.cjs.map +0 -1
- package/dist/index.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/core",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Generator core",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -40,18 +40,14 @@
|
|
|
40
40
|
"!/**/__tests__/**"
|
|
41
41
|
],
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@kubb/ts-codegen": "1.0.0",
|
|
44
43
|
"change-case": "^4.1.2",
|
|
45
44
|
"directory-tree": "^3.5.1",
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"uuid": "^9.0.0"
|
|
45
|
+
"rimraf": "^5.0.1",
|
|
46
|
+
"@kubb/ts-codegen": "1.0.2"
|
|
49
47
|
},
|
|
50
48
|
"devDependencies": {
|
|
51
|
-
"@types/lodash.uniq": "^4.5.7",
|
|
52
|
-
"@types/rimraf": "^3.0.2",
|
|
53
|
-
"@types/uuid": "^9.0.1",
|
|
54
49
|
"tsup": "^6.7.0",
|
|
50
|
+
"ora": "^6.3.1",
|
|
55
51
|
"typescript": "^5.1.3"
|
|
56
52
|
},
|
|
57
53
|
"publishConfig": {
|
|
@@ -59,7 +55,8 @@
|
|
|
59
55
|
"registry": "https://registry.npmjs.org/"
|
|
60
56
|
},
|
|
61
57
|
"engines": {
|
|
62
|
-
"node": "
|
|
58
|
+
"node": ">=16",
|
|
59
|
+
"pnpm": ">=8"
|
|
63
60
|
},
|
|
64
61
|
"scripts": {
|
|
65
62
|
"build": "tsup",
|
|
@@ -70,6 +67,6 @@
|
|
|
70
67
|
"test": "vitest --passWithNoTests",
|
|
71
68
|
"upgrade": "ncu -u",
|
|
72
69
|
"upgrade:local": "ncu --interactive --doctor",
|
|
73
|
-
"typecheck": "tsc -p ./tsconfig.json --noEmit"
|
|
70
|
+
"typecheck": "tsc -p ./tsconfig.json --noEmit --emitDeclarationOnly false"
|
|
74
71
|
}
|
|
75
72
|
}
|
package/src/build.ts
CHANGED
|
@@ -1,33 +1,17 @@
|
|
|
1
1
|
/* eslint-disable no-async-promise-executor */
|
|
2
|
-
import
|
|
2
|
+
import { PluginManager } from './managers/pluginManager/index.ts'
|
|
3
|
+
import { clean, isURL, read } from './utils/index.ts'
|
|
4
|
+
import { getFileSource } from './managers/fileManager/index.ts'
|
|
3
5
|
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
import type { FileManager, File } from './managers/fileManager'
|
|
10
|
-
import type { QueueTask } from './utils'
|
|
11
|
-
import type { PluginContext, TransformResult, LogLevel, KubbPlugin } from './types'
|
|
12
|
-
|
|
13
|
-
type BuildOutput = {
|
|
14
|
-
files: FileManager['files']
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
// Same type as ora
|
|
18
|
-
type Spinner = {
|
|
19
|
-
start: (text?: string) => Spinner
|
|
20
|
-
succeed: (text: string) => Spinner
|
|
21
|
-
fail: (text?: string) => Spinner
|
|
22
|
-
stopAndPersist: (options: { text: string }) => Spinner
|
|
23
|
-
render: () => Spinner
|
|
24
|
-
text: string
|
|
25
|
-
info: (text: string) => Spinner
|
|
26
|
-
}
|
|
6
|
+
import type { OnExecute } from './managers/pluginManager/index.ts'
|
|
7
|
+
import type { File } from './managers/fileManager/index.ts'
|
|
8
|
+
import type { QueueTask } from './utils/index.ts'
|
|
9
|
+
import type { PluginContext, TransformResult, LogLevel, KubbPlugin, BuildOutput } from './types.ts'
|
|
10
|
+
import type { Ora } from 'ora'
|
|
27
11
|
|
|
28
12
|
export type Logger = {
|
|
29
13
|
log: (message: string, logLevel: LogLevel) => void
|
|
30
|
-
spinner?:
|
|
14
|
+
spinner?: Ora
|
|
31
15
|
}
|
|
32
16
|
type BuildOptions = {
|
|
33
17
|
config: PluginContext['config']
|
|
@@ -46,9 +30,17 @@ async function transformReducer(
|
|
|
46
30
|
return result
|
|
47
31
|
}
|
|
48
32
|
|
|
49
|
-
async function
|
|
33
|
+
export async function build(options: BuildOptions): Promise<BuildOutput> {
|
|
50
34
|
const { config, logger } = options
|
|
51
35
|
|
|
36
|
+
try {
|
|
37
|
+
if (!isURL(config.input.path)) {
|
|
38
|
+
await read(config.input.path)
|
|
39
|
+
}
|
|
40
|
+
} catch (e: any) {
|
|
41
|
+
throw new Error('Cannot read file defined in `input.path` or set with --input in the CLI of your Kubb config', { cause: e })
|
|
42
|
+
}
|
|
43
|
+
|
|
52
44
|
if (config.output.clean) {
|
|
53
45
|
await clean(config.output.path)
|
|
54
46
|
}
|
|
@@ -82,7 +74,19 @@ async function buildImplementation(options: BuildOptions): Promise<BuildOutput>
|
|
|
82
74
|
}
|
|
83
75
|
}
|
|
84
76
|
|
|
85
|
-
const
|
|
77
|
+
const onExecute: OnExecute = (executer) => {
|
|
78
|
+
if (!executer) {
|
|
79
|
+
return
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const { strategy, hookName, plugin } = executer
|
|
83
|
+
|
|
84
|
+
if (config.logLevel === 'info' && logger?.spinner) {
|
|
85
|
+
logger.spinner.text = `[${strategy}] ${hookName}: Excecuting task for plugin ${plugin.name} \n`
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const pluginManager = new PluginManager(config, { task: queueTask as QueueTask, onExecute })
|
|
86
90
|
const { plugins, fileManager } = pluginManager
|
|
87
91
|
|
|
88
92
|
await pluginManager.hookParallel<'validate', true>({
|
|
@@ -97,21 +101,5 @@ async function buildImplementation(options: BuildOptions): Promise<BuildOutput>
|
|
|
97
101
|
|
|
98
102
|
await pluginManager.hookParallel({ hookName: 'buildEnd' })
|
|
99
103
|
|
|
100
|
-
return { files: fileManager.files.map((file) => ({ ...file, source: getFileSource(file) })) }
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
export type KubbBuild = (options: BuildOptions) => Promise<BuildOutput>
|
|
104
|
-
|
|
105
|
-
export function build(options: BuildOptions): Promise<BuildOutput> {
|
|
106
|
-
return new Promise(async (resolve, reject) => {
|
|
107
|
-
try {
|
|
108
|
-
const output = await buildImplementation(options)
|
|
109
|
-
|
|
110
|
-
setTimeout(() => {
|
|
111
|
-
resolve(output)
|
|
112
|
-
}, 500)
|
|
113
|
-
} catch (e) {
|
|
114
|
-
reject(e)
|
|
115
|
-
}
|
|
116
|
-
})
|
|
104
|
+
return { files: fileManager.files.map((file) => ({ ...file, source: getFileSource(file) })), pluginManager }
|
|
117
105
|
}
|
package/src/config.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { MaybePromise, KubbUserConfig, CLIOptions } from './types'
|
|
1
|
+
import type { MaybePromise, KubbUserConfig, CLIOptions } from './types.ts'
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* Type helper to make it easier to use kubb.config.
|
|
4
|
+
* Type helper to make it easier to use kubb.config.js
|
|
5
5
|
* accepts a direct {@link KubbConfig} object, or a function that returns it.
|
|
6
6
|
* The function receives a {@link ConfigEnv} object that exposes two properties:
|
|
7
7
|
*/
|
package/src/generators/index.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './SchemaGenerator'
|
|
2
|
-
export * from './Generator'
|
|
1
|
+
export * from './SchemaGenerator.ts'
|
|
2
|
+
export * from './Generator.ts'
|
package/src/index.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-empty-interface */
|
|
2
|
-
import { build } from './build'
|
|
2
|
+
import { build } from './build.ts'
|
|
3
3
|
|
|
4
|
-
export * from './config'
|
|
5
|
-
export * from './build'
|
|
6
|
-
export
|
|
7
|
-
export
|
|
8
|
-
|
|
9
|
-
export * from './
|
|
10
|
-
export * from './
|
|
4
|
+
export * from './config.ts'
|
|
5
|
+
export * from './build.ts'
|
|
6
|
+
export * from './types.ts'
|
|
7
|
+
export { CorePluginOptions, createPlugin, name } from './plugin.ts'
|
|
8
|
+
|
|
9
|
+
export * from './utils/index.ts'
|
|
10
|
+
export * from './managers/index.ts'
|
|
11
|
+
export * from './generators/index.ts'
|
|
11
12
|
|
|
12
13
|
export default build
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import
|
|
1
|
+
import crypto from 'node:crypto'
|
|
2
2
|
|
|
3
|
-
import { write, read } from '../../utils'
|
|
3
|
+
import { write, read } from '../../utils/index.ts'
|
|
4
4
|
|
|
5
|
-
import type { QueueTask, Queue } from '../../utils'
|
|
6
|
-
import type { CacheStore, UUID, Status, File } from './types'
|
|
5
|
+
import type { QueueTask, Queue } from '../../utils/index.ts'
|
|
6
|
+
import type { CacheStore, UUID, Status, File } from './types.ts'
|
|
7
7
|
|
|
8
8
|
export class FileManager {
|
|
9
9
|
private cache: Map<CacheStore['id'], CacheStore> = new Map()
|
|
@@ -44,7 +44,7 @@ export class FileManager {
|
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
async add(file: File) {
|
|
47
|
-
const cacheItem = { id:
|
|
47
|
+
const cacheItem = { id: crypto.randomUUID(), file, status: 'new' as Status }
|
|
48
48
|
|
|
49
49
|
this.cache.set(cacheItem.id, cacheItem)
|
|
50
50
|
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from './FileManager'
|
|
2
|
-
export * from './types'
|
|
3
|
-
export * from './utils'
|
|
1
|
+
export * from './FileManager.ts'
|
|
2
|
+
export * from './types.ts'
|
|
3
|
+
export * from './utils.ts'
|
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
import pathParser from 'path'
|
|
2
|
-
|
|
3
|
-
import uniq from 'lodash.uniq'
|
|
1
|
+
import pathParser from 'node:path'
|
|
4
2
|
|
|
5
3
|
import { createImportDeclaration, createExportDeclaration, print } from '@kubb/ts-codegen'
|
|
6
4
|
|
|
7
|
-
import { TreeNode } from '../../utils'
|
|
5
|
+
import { TreeNode } from '../../utils/index.ts'
|
|
8
6
|
|
|
9
|
-
import type { PathMode, TreeNodeOptions } from '../../utils'
|
|
10
|
-
import type { Path } from '../../types'
|
|
7
|
+
import type { PathMode, TreeNodeOptions } from '../../utils/index.ts'
|
|
8
|
+
import type { Path } from '../../types.ts'
|
|
11
9
|
import type ts from 'typescript'
|
|
12
|
-
import type { File } from './types'
|
|
10
|
+
import type { File } from './types.ts'
|
|
13
11
|
|
|
14
12
|
export function writeIndexes(root: string, options: TreeNodeOptions) {
|
|
15
13
|
const tree = TreeNode.build<{ type: PathMode; path: Path; name: string }>(root, { extensions: /\.ts/, ...options })
|
|
@@ -112,7 +110,7 @@ export function getFileSource(file: File) {
|
|
|
112
110
|
if (!exists) {
|
|
113
111
|
imports.push({
|
|
114
112
|
...curr,
|
|
115
|
-
name: Array.isArray(curr.name) ?
|
|
113
|
+
name: Array.isArray(curr.name) ? [...new Set(curr.name)] : curr.name,
|
|
116
114
|
})
|
|
117
115
|
}
|
|
118
116
|
|
|
@@ -122,7 +120,7 @@ export function getFileSource(file: File) {
|
|
|
122
120
|
|
|
123
121
|
if (exists && Array.isArray(exists.name)) {
|
|
124
122
|
if (Array.isArray(curr.name)) {
|
|
125
|
-
exists.name =
|
|
123
|
+
exists.name = [...new Set([...exists.name, ...curr.name])]
|
|
126
124
|
}
|
|
127
125
|
}
|
|
128
126
|
})
|
|
@@ -132,7 +130,7 @@ export function getFileSource(file: File) {
|
|
|
132
130
|
if (!exists) {
|
|
133
131
|
exports.push({
|
|
134
132
|
...curr,
|
|
135
|
-
name: Array.isArray(curr.name) ?
|
|
133
|
+
name: Array.isArray(curr.name) ? [...new Set(curr.name)] : curr.name,
|
|
136
134
|
})
|
|
137
135
|
}
|
|
138
136
|
|
|
@@ -142,7 +140,7 @@ export function getFileSource(file: File) {
|
|
|
142
140
|
|
|
143
141
|
if (exists && Array.isArray(exists.name)) {
|
|
144
142
|
if (Array.isArray(curr.name)) {
|
|
145
|
-
exists.name =
|
|
143
|
+
exists.name = [...new Set([...exists.name, ...curr.name])]
|
|
146
144
|
}
|
|
147
145
|
}
|
|
148
146
|
})
|
package/src/managers/index.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './fileManager'
|
|
2
|
-
export * from './pluginManager'
|
|
1
|
+
export * from './fileManager/index.ts'
|
|
2
|
+
export * from './pluginManager/index.ts'
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { PluginError } from './PluginError.ts'
|
|
2
|
+
import type { PluginManager } from './PluginManager'
|
|
3
|
+
|
|
4
|
+
export class ParallelPluginError extends Error {
|
|
5
|
+
public errors: PluginError[]
|
|
6
|
+
|
|
7
|
+
public pluginManager: PluginManager
|
|
8
|
+
|
|
9
|
+
constructor(message: string, options: { cause?: Error; errors: PluginError[]; pluginManager: PluginManager }) {
|
|
10
|
+
super(message, { cause: options.cause })
|
|
11
|
+
|
|
12
|
+
this.errors = options.errors
|
|
13
|
+
this.pluginManager = options.pluginManager
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { PluginManager } from './PluginManager'
|
|
2
|
+
|
|
3
|
+
export class PluginError extends Error {
|
|
4
|
+
public pluginManager: PluginManager
|
|
5
|
+
|
|
6
|
+
constructor(message: string, options: { cause?: Error; pluginManager: PluginManager }) {
|
|
7
|
+
super(message, { cause: options.cause })
|
|
8
|
+
|
|
9
|
+
this.pluginManager = options.pluginManager
|
|
10
|
+
}
|
|
11
|
+
}
|