@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/core",
3
- "version": "1.0.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
- "lodash.uniq": "^4.5.0",
47
- "rimraf": "^3.0.2",
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": "^12.17.0 || ^14.13 || >=16.0.0"
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 pathParser from 'path'
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 { isURL } from './utils/isURL'
5
- import { PluginManager } from './managers/pluginManager'
6
- import { clean, read } from './utils'
7
- import { getFileSource } from './managers/fileManager'
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?: 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 buildImplementation(options: BuildOptions): Promise<BuildOutput> {
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 pluginManager = new PluginManager(config, { logger, task: queueTask as QueueTask })
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.ts
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
  */
@@ -1,4 +1,4 @@
1
- import { Generator } from './Generator'
1
+ import { Generator } from './Generator.ts'
2
2
  /**
3
3
  * Abstract class that contains the building blocks for plugins to create their own SchemaGenerator
4
4
  */
@@ -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 { CorePluginOptions, createPlugin, name } from './plugin'
7
- export * from './utils'
8
- export * from './types'
9
- export * from './managers'
10
- export * from './generators'
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 { v4 as uuidv4 } from 'uuid'
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: uuidv4(), file, status: 'new' as Status }
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'
@@ -28,6 +28,9 @@ export type File = {
28
28
  * @default `false`
29
29
  */
30
30
  override?: boolean
31
+ meta?: {
32
+ pluginName?: string
33
+ }
31
34
  }
32
35
 
33
36
  export type UUID = string
@@ -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) ? uniq(curr.name) : 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 = uniq([...exists.name, ...curr.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) ? uniq(curr.name) : 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 = uniq([...exists.name, ...curr.name])
143
+ exists.name = [...new Set([...exists.name, ...curr.name])]
146
144
  }
147
145
  }
148
146
  })
@@ -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
+ }