@kubb/core 2.0.0-beta.12 → 2.0.0-beta.14

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.
Files changed (73) hide show
  1. package/dist/chunk-35FDNG5F.cjs +71 -0
  2. package/dist/chunk-35FDNG5F.cjs.map +1 -0
  3. package/dist/chunk-7CNPSL5M.js +85 -0
  4. package/dist/chunk-7CNPSL5M.js.map +1 -0
  5. package/dist/chunk-DKYWBKNH.js +18 -0
  6. package/dist/chunk-DKYWBKNH.js.map +1 -0
  7. package/dist/chunk-EZSRGYAY.js +128 -0
  8. package/dist/chunk-EZSRGYAY.js.map +1 -0
  9. package/dist/chunk-GBX7KRCX.cjs +162 -0
  10. package/dist/chunk-GBX7KRCX.cjs.map +1 -0
  11. package/dist/chunk-ICRPOCV4.cjs +2290 -0
  12. package/dist/chunk-ICRPOCV4.cjs.map +1 -0
  13. package/dist/chunk-LAS7UYTK.cjs +129 -0
  14. package/dist/chunk-LAS7UYTK.cjs.map +1 -0
  15. package/dist/chunk-LJHT3DNH.js +67 -0
  16. package/dist/chunk-LJHT3DNH.js.map +1 -0
  17. package/dist/chunk-MM42A6GN.cjs +91 -0
  18. package/dist/chunk-MM42A6GN.cjs.map +1 -0
  19. package/dist/chunk-SRGTC4FJ.js +129 -0
  20. package/dist/chunk-SRGTC4FJ.js.map +1 -0
  21. package/dist/chunk-ST7GHHSU.cjs +104 -0
  22. package/dist/chunk-ST7GHHSU.cjs.map +1 -0
  23. package/dist/chunk-U4C2WTCI.cjs +131 -0
  24. package/dist/chunk-U4C2WTCI.cjs.map +1 -0
  25. package/dist/chunk-UIQUKFF4.js +155 -0
  26. package/dist/chunk-UIQUKFF4.js.map +1 -0
  27. package/dist/chunk-WTSDXEWD.js +71 -0
  28. package/dist/chunk-WTSDXEWD.js.map +1 -0
  29. package/dist/fs.cjs +20 -2372
  30. package/dist/fs.cjs.map +1 -1
  31. package/dist/fs.d.cts +1 -1
  32. package/dist/fs.d.ts +1 -1
  33. package/dist/fs.js +4 -2373
  34. package/dist/fs.js.map +1 -1
  35. package/dist/index.cjs +930 -3261
  36. package/dist/index.cjs.map +1 -1
  37. package/dist/index.d.cts +17 -15
  38. package/dist/index.d.ts +17 -15
  39. package/dist/index.js +208 -3490
  40. package/dist/index.js.map +1 -1
  41. package/dist/logger.cjs +19 -141
  42. package/dist/logger.cjs.map +1 -1
  43. package/dist/logger.d.cts +1 -0
  44. package/dist/logger.d.ts +1 -0
  45. package/dist/logger.js +3 -135
  46. package/dist/logger.js.map +1 -1
  47. package/dist/transformers.cjs +40 -208
  48. package/dist/transformers.cjs.map +1 -1
  49. package/dist/transformers.js +15 -201
  50. package/dist/transformers.js.map +1 -1
  51. package/dist/utils.cjs +22 -524
  52. package/dist/utils.cjs.map +1 -1
  53. package/dist/utils.d.cts +0 -1
  54. package/dist/utils.d.ts +0 -1
  55. package/dist/utils.js +11 -517
  56. package/dist/utils.js.map +1 -1
  57. package/dist/{write-46ytbnu9.d.cts → write-A6VgHkYA.d.cts} +4 -1
  58. package/dist/{write-46ytbnu9.d.ts → write-A6VgHkYA.d.ts} +4 -1
  59. package/package.json +9 -8
  60. package/src/BarrelManager.ts +3 -3
  61. package/src/FileManager.ts +66 -62
  62. package/src/PluginManager.ts +11 -18
  63. package/src/build.ts +57 -32
  64. package/src/fs/clean.ts +2 -2
  65. package/src/fs/read.ts +1 -0
  66. package/src/fs/write.ts +40 -24
  67. package/src/logger.ts +10 -0
  68. package/src/utils/FunctionParams.ts +2 -2
  69. package/src/utils/URLPath.ts +5 -5
  70. package/src/utils/index.ts +0 -2
  71. package/dist/Queue-2-6pMcCx.d.cts +0 -32
  72. package/dist/Queue-2-6pMcCx.d.ts +0 -32
  73. package/src/utils/Queue.ts +0 -110
package/src/fs/write.ts CHANGED
@@ -1,20 +1,14 @@
1
- import { dirname, resolve } from 'node:path'
1
+ import { resolve } from 'node:path'
2
2
 
3
3
  import fs from 'fs-extra'
4
4
  import { switcher } from 'js-runtime'
5
5
 
6
- async function saveCreateDirectory(path: string): Promise<void> {
7
- // resolve the full path and get just the directory, ignoring the file and extension
8
- const passedPath = dirname(resolve(path))
9
- // make the directory, recursively. Theoretically, if every directory in the path exists, this won't do anything.
10
- await fs.mkdir(passedPath, { recursive: true })
11
- }
6
+ type Options = { sanity?: boolean }
12
7
 
13
8
  const writer = switcher(
14
9
  {
15
- node: async (path: string, data: string) => {
10
+ node: async (path: string, data: string, { sanity }: Options) => {
16
11
  try {
17
- await fs.stat(resolve(path))
18
12
  const oldContent = await fs.readFile(resolve(path), { encoding: 'utf-8' })
19
13
  if (oldContent?.toString() === data?.toString()) {
20
14
  return
@@ -23,30 +17,36 @@ const writer = switcher(
23
17
  /* empty */
24
18
  }
25
19
 
26
- await saveCreateDirectory(path)
27
- await fs.writeFile(resolve(path), data, { encoding: 'utf-8' })
20
+ await fs.outputFile(resolve(path), data, { encoding: 'utf-8' })
21
+
22
+ if (sanity) {
23
+ const savedData = await fs.readFile(resolve(path), { encoding: 'utf-8' })
28
24
 
29
- const savedData = await fs.readFile(resolve(path), { encoding: 'utf-8' })
25
+ if (savedData?.toString() !== data?.toString()) {
26
+ throw new Error(`Sanity check failed for ${path}\n\nData[${data.length}]:\n${data}\n\nSaved[${savedData.length}]:\n${savedData}\n`)
27
+ }
30
28
 
31
- if (savedData?.toString() !== data?.toString()) {
32
- throw new Error(`Sanity check failed for ${path}\n\nData[${data.length}]:\n${data}\n\nSaved[${savedData.length}]:\n${savedData}\n`)
29
+ return savedData
33
30
  }
34
31
 
35
- return savedData
32
+ return data
36
33
  },
37
- bun: async (path: string, data: string) => {
34
+ bun: async (path: string, data: string, { sanity }: Options) => {
38
35
  try {
39
- await saveCreateDirectory(path)
40
36
  await Bun.write(resolve(path), data)
41
37
 
42
- const file = Bun.file(resolve(path))
43
- const savedData = await file.text()
38
+ if (sanity) {
39
+ const file = Bun.file(resolve(path))
40
+ const savedData = await file.text()
44
41
 
45
- if (savedData?.toString() !== data?.toString()) {
46
- throw new Error(`Sanity check failed for ${path}\n\nData[${data.length}]:\n${data}\n\nSaved[${savedData.length}]:\n${savedData}\n`)
42
+ if (savedData?.toString() !== data?.toString()) {
43
+ throw new Error(`Sanity check failed for ${path}\n\nData[${data.length}]:\n${data}\n\nSaved[${savedData.length}]:\n${savedData}\n`)
44
+ }
45
+
46
+ return savedData
47
47
  }
48
48
 
49
- return savedData
49
+ return data
50
50
  } catch (e) {
51
51
  console.log(e, resolve(path))
52
52
  }
@@ -55,9 +55,25 @@ const writer = switcher(
55
55
  'node',
56
56
  )
57
57
 
58
- export async function write(data: string, path: string): Promise<string | undefined> {
58
+ export async function write(data: string, path: string, options: Options = {}): Promise<string | undefined> {
59
59
  if (data.trim() === '') {
60
60
  return undefined
61
61
  }
62
- return writer(path, data.trim())
62
+ return writer(path, data.trim(), options)
63
+ }
64
+
65
+ export async function writeLog(data: string): Promise<string | undefined> {
66
+ if (data.trim() === '') {
67
+ return undefined
68
+ }
69
+ const path = resolve(process.cwd(), 'kubb-log.log')
70
+ let previousLogs = ''
71
+
72
+ try {
73
+ previousLogs = await fs.readFile(resolve(path), { encoding: 'utf-8' })
74
+ } catch (_err) {
75
+ /* empty */
76
+ }
77
+
78
+ return writer(path, [previousLogs, data.trim()].filter(Boolean).join('\n\n\n'), { sanity: false })
63
79
  }
package/src/logger.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  import seedrandom from 'seedrandom'
2
2
  import c, { createColors } from 'tinyrainbow'
3
3
 
4
+ import { writeLog } from './fs/write.ts'
5
+
4
6
  import type { Ora } from 'ora'
5
7
  import type { Formatter } from 'tinyrainbow'
6
8
 
@@ -22,6 +24,7 @@ export type Logger = {
22
24
  error: (message: string | null) => void
23
25
  info: (message: string | null) => void
24
26
  warn: (message: string | null) => void
27
+ debug: (message: string | null) => Promise<void>
25
28
  spinner?: Ora
26
29
  logs: string[]
27
30
  }
@@ -61,6 +64,12 @@ export function createLogger({ logLevel, name, spinner }: Props): Logger {
61
64
  }
62
65
  }
63
66
 
67
+ const debug: Logger['debug'] = async (message) => {
68
+ if (message) {
69
+ await writeLog(message)
70
+ }
71
+ }
72
+
64
73
  const logger: Logger = {
65
74
  name,
66
75
  logLevel,
@@ -68,6 +77,7 @@ export function createLogger({ logLevel, name, spinner }: Props): Logger {
68
77
  error,
69
78
  warn,
70
79
  info,
80
+ debug,
71
81
  spinner,
72
82
  logs,
73
83
  }
@@ -1,6 +1,6 @@
1
1
  import { orderBy } from 'natural-orderby'
2
2
 
3
- import transformers from '../transformers/index.ts'
3
+ import { camelCase } from '../transformers/casing.ts'
4
4
 
5
5
  type FunctionParamsASTWithoutType = {
6
6
  name?: string
@@ -67,7 +67,7 @@ export class FunctionParams {
67
67
  return acc
68
68
  }
69
69
  // TODO check whey we still need the camelcase here
70
- const parameterName = name.startsWith('{') ? name : transformers.camelCase(name)
70
+ const parameterName = name.startsWith('{') ? name : camelCase(name)
71
71
 
72
72
  if (type) {
73
73
  if (required) {
@@ -1,4 +1,4 @@
1
- import transformers from '../transformers/index.ts'
1
+ import { camelCase } from '../transformers/casing.ts'
2
2
 
3
3
  export type URLObject = {
4
4
  url: string
@@ -90,8 +90,8 @@ export class URLPath {
90
90
  if (found) {
91
91
  newPath = found.reduce((prev, curr) => {
92
92
  const pathParam = replacer
93
- ? replacer(transformers.camelCase(curr))
94
- : transformers.camelCase(curr)
93
+ ? replacer(camelCase(curr))
94
+ : camelCase(curr)
95
95
  const replacement = `\${${pathParam}}`
96
96
 
97
97
  return prev.replace(curr, replacement)
@@ -114,8 +114,8 @@ export class URLPath {
114
114
  item = item.replaceAll('{', '').replaceAll('}', '')
115
115
 
116
116
  const pathParam = replacer
117
- ? replacer(transformers.camelCase(item))
118
- : transformers.camelCase(item)
117
+ ? replacer(camelCase(item))
118
+ : camelCase(item)
119
119
 
120
120
  params[pathParam] = pathParam
121
121
  }, this.path)
@@ -1,8 +1,6 @@
1
1
  export type { FunctionParamsAST } from './FunctionParams.ts'
2
2
  export { FunctionParams } from './FunctionParams.ts'
3
3
  export { isPromise, isPromiseFulfilledResult, isPromiseRejectedResult } from './promise.ts'
4
- export type { QueueJob } from './Queue.ts'
5
- export { Queue } from './Queue.ts'
6
4
  export { renderTemplate } from './renderTemplate.ts'
7
5
  export { timeout } from './timeout.ts'
8
6
  export { getUniqueName, setUniqueName } from './uniqueName.ts'
@@ -1,32 +0,0 @@
1
- declare class EventEmitter<TEvents extends Record<string, any>> {
2
- #private;
3
- constructor();
4
- emit<TEventName extends keyof TEvents & string>(eventName: TEventName, ...eventArg: TEvents[TEventName]): void;
5
- on<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArg: TEvents[TEventName]) => void): void;
6
- off<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArg: TEvents[TEventName]) => void): void;
7
- removeAll(): void;
8
- }
9
-
10
- type QueueJob<T = unknown> = {
11
- (...args: unknown[]): Promise<T | void>;
12
- };
13
- type RunOptions = {
14
- controller?: AbortController;
15
- name?: string;
16
- description?: string;
17
- };
18
- type Events = {
19
- jobDone: [result: unknown];
20
- jobFailed: [error: Error];
21
- };
22
- declare class Queue {
23
- #private;
24
- readonly eventEmitter: EventEmitter<Events>;
25
- constructor(maxParallel: number, debug?: boolean);
26
- run<T>(job: QueueJob<T>, options?: RunOptions): Promise<T>;
27
- runSync<T>(job: QueueJob<T>, options?: RunOptions): void;
28
- get hasJobs(): boolean;
29
- get count(): number;
30
- }
31
-
32
- export { EventEmitter as E, Queue as Q, type QueueJob as a };
@@ -1,32 +0,0 @@
1
- declare class EventEmitter<TEvents extends Record<string, any>> {
2
- #private;
3
- constructor();
4
- emit<TEventName extends keyof TEvents & string>(eventName: TEventName, ...eventArg: TEvents[TEventName]): void;
5
- on<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArg: TEvents[TEventName]) => void): void;
6
- off<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArg: TEvents[TEventName]) => void): void;
7
- removeAll(): void;
8
- }
9
-
10
- type QueueJob<T = unknown> = {
11
- (...args: unknown[]): Promise<T | void>;
12
- };
13
- type RunOptions = {
14
- controller?: AbortController;
15
- name?: string;
16
- description?: string;
17
- };
18
- type Events = {
19
- jobDone: [result: unknown];
20
- jobFailed: [error: Error];
21
- };
22
- declare class Queue {
23
- #private;
24
- readonly eventEmitter: EventEmitter<Events>;
25
- constructor(maxParallel: number, debug?: boolean);
26
- run<T>(job: QueueJob<T>, options?: RunOptions): Promise<T>;
27
- runSync<T>(job: QueueJob<T>, options?: RunOptions): void;
28
- get hasJobs(): boolean;
29
- get count(): number;
30
- }
31
-
32
- export { EventEmitter as E, Queue as Q, type QueueJob as a };
@@ -1,110 +0,0 @@
1
- import crypto from 'node:crypto'
2
- import { performance } from 'node:perf_hooks'
3
-
4
- import { EventEmitter } from './EventEmitter.ts'
5
-
6
- export type QueueJob<T = unknown> = {
7
- (...args: unknown[]): Promise<T | void>
8
- }
9
-
10
- type RunOptions = {
11
- controller?: AbortController
12
- name?: string
13
- description?: string
14
- }
15
-
16
- type QueueItem = {
17
- reject: <T>(reason?: T) => void
18
- resolve: <T>(value: T | PromiseLike<T>) => void
19
- job: QueueJob<unknown>
20
- } & Required<RunOptions>
21
-
22
- type Events = {
23
- jobDone: [result: unknown]
24
- jobFailed: [error: Error]
25
- }
26
-
27
- export class Queue {
28
- #queue: QueueItem[] = []
29
- readonly eventEmitter: EventEmitter<Events> = new EventEmitter()
30
-
31
- #workerCount = 0
32
-
33
- #maxParallel: number
34
- #debug = false
35
-
36
- constructor(maxParallel: number, debug = false) {
37
- this.#maxParallel = maxParallel
38
- this.#debug = debug
39
- }
40
-
41
- run<T>(job: QueueJob<T>, options: RunOptions = { controller: new AbortController(), name: crypto.randomUUID(), description: '' }): Promise<T> {
42
- return new Promise<T>((resolve, reject) => {
43
- const item = { reject, resolve, job, name: options.name, description: options.description || options.name } as QueueItem
44
-
45
- options.controller?.signal.addEventListener('abort', () => {
46
- this.#queue = this.#queue.filter((queueItem) => queueItem.name === item.name)
47
-
48
- reject('Aborted')
49
- })
50
-
51
- this.#queue.push(item)
52
- this.#work()
53
- })
54
- }
55
-
56
- runSync<T>(job: QueueJob<T>, options: RunOptions = { controller: new AbortController(), name: crypto.randomUUID(), description: '' }): void {
57
- new Promise<T>((resolve, reject) => {
58
- const item = { reject, resolve, job, name: options.name, description: options.description || options.name } as QueueItem
59
-
60
- options.controller?.signal.addEventListener('abort', () => {
61
- this.#queue = this.#queue.filter((queueItem) => queueItem.name === item.name)
62
- })
63
-
64
- this.#queue.push(item)
65
- this.#work()
66
- })
67
- }
68
-
69
- get hasJobs(): boolean {
70
- return this.#workerCount > 0 || this.#queue.length > 0
71
- }
72
-
73
- get count(): number {
74
- return this.#workerCount
75
- }
76
-
77
- #work(): void {
78
- if (this.#workerCount >= this.#maxParallel) {
79
- return
80
- }
81
-
82
- this.#workerCount++
83
-
84
- let entry: QueueItem | undefined
85
- while ((entry = this.#queue.shift())) {
86
- const { reject, resolve, job, name, description } = entry
87
-
88
- if (this.#debug) {
89
- performance.mark(name + '_start')
90
- }
91
-
92
- job()
93
- .then((result) => {
94
- this.eventEmitter.emit('jobDone', result)
95
-
96
- resolve(result)
97
-
98
- if (this.#debug) {
99
- performance.mark(name + '_stop')
100
- performance.measure(description, name + '_start', name + '_stop')
101
- }
102
- })
103
- .catch((err) => {
104
- this.eventEmitter.emit('jobFailed', err as Error)
105
- reject(err)
106
- })
107
- }
108
- this.#workerCount--
109
- }
110
- }