@kubb/core 2.18.4 → 2.18.5

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 (69) hide show
  1. package/dist/chunk-7TB4GNKF.cjs +1268 -0
  2. package/dist/chunk-7TB4GNKF.cjs.map +1 -0
  3. package/dist/{chunk-TIYJPVUG.js → chunk-7UMWFPXG.js} +1 -9
  4. package/dist/chunk-7UMWFPXG.js.map +1 -0
  5. package/dist/{chunk-GRBLCGB5.cjs → chunk-BE4KSMB4.cjs} +5 -5
  6. package/dist/chunk-EPAC7V2R.js +597 -0
  7. package/dist/chunk-EPAC7V2R.js.map +1 -0
  8. package/dist/{chunk-YTLMG2AN.cjs → chunk-FWUA552W.cjs} +29 -29
  9. package/dist/{chunk-NP7GXHZS.cjs → chunk-JI763CHT.cjs} +18 -18
  10. package/dist/{chunk-GG3XRJX3.cjs → chunk-M6VNU2SJ.cjs} +12 -20
  11. package/dist/chunk-M6VNU2SJ.cjs.map +1 -0
  12. package/dist/{chunk-XUCU53HT.cjs → chunk-TCFN5BZ6.cjs} +3 -11
  13. package/dist/chunk-TCFN5BZ6.cjs.map +1 -0
  14. package/dist/index.cjs +1297 -10
  15. package/dist/index.cjs.map +1 -1
  16. package/dist/index.d.cts +26 -148
  17. package/dist/index.d.ts +26 -148
  18. package/dist/index.js +991 -22
  19. package/dist/index.js.map +1 -1
  20. package/dist/logger.cjs +3 -4
  21. package/dist/logger.js +1 -2
  22. package/dist/mocks.cjs +15 -14
  23. package/dist/mocks.cjs.map +1 -1
  24. package/dist/mocks.d.cts +4 -2
  25. package/dist/mocks.d.ts +4 -2
  26. package/dist/mocks.js +7 -6
  27. package/dist/mocks.js.map +1 -1
  28. package/dist/transformers.cjs +4 -4
  29. package/dist/utils.cjs +4 -4
  30. package/package.json +8 -18
  31. package/src/BarrelManager.ts +1 -1
  32. package/src/FileManager.ts +36 -167
  33. package/src/PackageManager.ts +1 -1
  34. package/src/PluginManager.ts +5 -5
  35. package/src/build.ts +6 -8
  36. package/src/index.ts +2 -3
  37. package/src/logger.ts +0 -7
  38. package/src/types.ts +3 -2
  39. package/src/utils/TreeNode.ts +1 -1
  40. package/dist/chunk-2F7E62RD.js +0 -85
  41. package/dist/chunk-2F7E62RD.js.map +0 -1
  42. package/dist/chunk-6NMPKKGV.js +0 -1597
  43. package/dist/chunk-6NMPKKGV.js.map +0 -1
  44. package/dist/chunk-7PBKI3OR.cjs +0 -2584
  45. package/dist/chunk-7PBKI3OR.cjs.map +0 -1
  46. package/dist/chunk-AQJCCWPW.cjs +0 -75
  47. package/dist/chunk-AQJCCWPW.cjs.map +0 -1
  48. package/dist/chunk-GG3XRJX3.cjs.map +0 -1
  49. package/dist/chunk-MDO6MCFJ.js +0 -65
  50. package/dist/chunk-MDO6MCFJ.js.map +0 -1
  51. package/dist/chunk-TIYJPVUG.js.map +0 -1
  52. package/dist/chunk-X5IJHUXJ.cjs +0 -2332
  53. package/dist/chunk-X5IJHUXJ.cjs.map +0 -1
  54. package/dist/chunk-XUCU53HT.cjs.map +0 -1
  55. package/dist/fs.cjs +0 -23
  56. package/dist/fs.cjs.map +0 -1
  57. package/dist/fs.d.cts +0 -5
  58. package/dist/fs.d.ts +0 -5
  59. package/dist/fs.js +0 -18
  60. package/dist/fs.js.map +0 -1
  61. package/dist/write-CN8f7bYv.d.cts +0 -10
  62. package/dist/write-CN8f7bYv.d.ts +0 -10
  63. package/src/fs/clean.ts +0 -5
  64. package/src/fs/index.ts +0 -3
  65. package/src/fs/read.ts +0 -68
  66. package/src/fs/write.ts +0 -83
  67. /package/dist/{chunk-GRBLCGB5.cjs.map → chunk-BE4KSMB4.cjs.map} +0 -0
  68. /package/dist/{chunk-YTLMG2AN.cjs.map → chunk-FWUA552W.cjs.map} +0 -0
  69. /package/dist/{chunk-NP7GXHZS.cjs.map → chunk-JI763CHT.cjs.map} +0 -0
@@ -5,12 +5,14 @@ import { orderBy } from 'natural-orderby'
5
5
  import PQueue from 'p-queue'
6
6
  import { isDeepEqual } from 'remeda'
7
7
 
8
+ import { getRelativePath, read, write } from '@kubb/fs'
8
9
  import { BarrelManager } from './BarrelManager.ts'
9
- import { getRelativePath, read } from './fs/read.ts'
10
- import { write } from './fs/write.ts'
11
10
  import { searchAndReplace } from './transformers/searchAndReplace.ts'
12
11
  import { trimExtName } from './transformers/trim.ts'
13
12
 
13
+ import type * as KubbFile from '@kubb/fs/types'
14
+
15
+ import type { BaseName, File, UUID } from '@kubb/fs/src/types.ts'
14
16
  import type { GreaterThan } from '@kubb/types'
15
17
  import type { BarrelManagerOptions } from './BarrelManager.ts'
16
18
  import type { Logger } from './logger.ts'
@@ -18,163 +20,30 @@ import transformers from './transformers/index.ts'
18
20
  import type { Plugin } from './types.ts'
19
21
  import { getParser } from './utils'
20
22
 
21
- type BasePath<T extends string = string> = `${T}/`
22
-
23
- export namespace KubbFile {
24
- export type Import = {
25
- /**
26
- * Import name to be used
27
- * @example ["useState"]
28
- * @example "React"
29
- */
30
- name:
31
- | string
32
- | Array<
33
- | string
34
- | {
35
- propertyName: string
36
- name?: string
37
- }
38
- >
39
- /**
40
- * Path for the import
41
- * @xample '@kubb/core'
42
- */
43
- path: string
44
- /**
45
- * Add `type` prefix to the import, this will result in: `import type { Type } from './path'`.
46
- */
47
- isTypeOnly?: boolean
48
- /**
49
- * Add `* as` prefix to the import, this will result in: `import * as path from './path'`.
50
- */
51
-
52
- isNameSpace?: boolean
53
- /**
54
- * When root is set it will get the path with relative getRelativePath(root, path).
55
- */
56
- root?: string
57
- }
58
-
59
- export type Export = {
60
- /**
61
- * Export name to be used.
62
- * @example ["useState"]
63
- * @example "React"
64
- */
65
- name?: string | Array<string>
66
- /**
67
- * Path for the import.
68
- * @xample '@kubb/core'
69
- */
70
- path: string
71
- /**
72
- * Add `type` prefix to the export, this will result in: `export type { Type } from './path'`.
73
- */
74
- isTypeOnly?: boolean
75
- /**
76
- * Make it possible to override the name, this will result in: `export * as aliasName from './path'`.
77
- */
78
- asAlias?: boolean
79
- }
80
-
81
- export declare const dataTagSymbol: unique symbol
82
- export type DataTag<Type, Value> = Type & {
83
- [dataTagSymbol]: Value
84
- }
85
-
86
- export type UUID = string
87
- export type Source = string
88
-
89
- export type Extname = '.ts' | '.js' | '.tsx' | '.json' | `.${string}`
90
-
91
- export type Mode = 'single' | 'split'
92
-
23
+ export type ResolvedFile<TMeta extends FileMetaBase = FileMetaBase, TBaseName extends BaseName = BaseName> = File<TMeta, TBaseName> & {
93
24
  /**
94
- * Name to be used to dynamicly create the baseName(based on input.path)
95
- * Based on UNIX basename
96
- * @link https://nodejs.org/api/path.html#pathbasenamepath-suffix
25
+ * @default crypto.randomUUID()
97
26
  */
98
- export type BaseName = `${string}${Extname}`
99
-
27
+ id: UUID
100
28
  /**
101
- * Path will be full qualified path to a specified file
29
+ * Contains the first part of the baseName, generated based on baseName
30
+ * @link https://nodejs.org/api/path.html#pathformatpathobject
102
31
  */
103
- export type Path = string
104
32
 
105
- export type AdvancedPath<T extends BaseName = BaseName> = `${BasePath}${T}`
106
-
107
- export type OptionalPath = Path | undefined | null
108
-
109
- export type FileMetaBase = {
110
- pluginKey?: Plugin['key']
111
- }
112
-
113
- export type File<TMeta extends FileMetaBase = FileMetaBase, TBaseName extends BaseName = BaseName> = {
114
- /**
115
- * Unique identifier to reuse later
116
- * @default crypto.randomUUID()
117
- */
118
- id?: string
119
- /**
120
- * Name to be used to create the path
121
- * Based on UNIX basename, `${name}.extName`
122
- * @link https://nodejs.org/api/path.html#pathbasenamepath-suffix
123
- */
124
- baseName: TBaseName
125
- /**
126
- * Path will be full qualified path to a specified file
127
- */
128
- path: AdvancedPath<TBaseName> | Path
129
- source: Source
130
- imports?: Import[]
131
- exports?: Export[]
132
- /**
133
- * This will call fileManager.add instead of fileManager.addOrAppend, adding the source when the files already exists
134
- * This will also ignore the combinefiles utils
135
- * @default `false`
136
- */
137
- override?: boolean
138
- /**
139
- * Use extra meta, this is getting used to generate the barrel/index files.
140
- */
141
- meta?: TMeta
142
- /**
143
- * Override if a file can be exported by the BarrelManager
144
- * @default true
145
- */
146
- exportable?: boolean
147
- /**
148
- * This will override `process.env[key]` inside the `source`, see `getFileSource`.
149
- */
150
- env?: NodeJS.ProcessEnv
151
- /**
152
- * The name of the language being used. This can be TypeScript, JavaScript and still have another ext.
153
- */
154
- language?: string
155
- }
33
+ name: string
34
+ }
156
35
 
157
- export type ResolvedFile<TMeta extends FileMetaBase = FileMetaBase, TBaseName extends BaseName = BaseName> = KubbFile.File<TMeta, TBaseName> & {
158
- /**
159
- * @default crypto.randomUUID()
160
- */
161
- id: UUID
162
- /**
163
- * Contains the first part of the baseName, generated based on baseName
164
- * @link https://nodejs.org/api/path.html#pathformatpathobject
165
- */
166
-
167
- name: string
168
- }
36
+ export type FileMetaBase = {
37
+ pluginKey?: Plugin['key']
169
38
  }
170
39
 
171
- type CacheItem = KubbFile.ResolvedFile & {
40
+ type FileWithMeta<TMeta extends FileMetaBase = FileMetaBase> = KubbFile.File<TMeta>
41
+
42
+ type CacheItem = ResolvedFile & {
172
43
  cancel?: () => void
173
44
  }
174
45
 
175
- type AddResult<T extends Array<KubbFile.File>> = Promise<
176
- Awaited<GreaterThan<T['length'], 1> extends true ? Promise<KubbFile.ResolvedFile[]> : Promise<KubbFile.ResolvedFile>>
177
- >
46
+ type AddResult<T extends Array<FileWithMeta>> = Promise<Awaited<GreaterThan<T['length'], 1> extends true ? Promise<ResolvedFile[]> : Promise<ResolvedFile>>>
178
47
 
179
48
  type AddIndexesProps = {
180
49
  /**
@@ -192,12 +61,12 @@ type AddIndexesProps = {
192
61
  }
193
62
  logger: Logger
194
63
  options?: BarrelManagerOptions
195
- meta?: KubbFile.File['meta']
64
+ meta?: FileWithMeta['meta']
196
65
  }
197
66
 
198
67
  type Options = {
199
68
  queue?: PQueue
200
- task?: (file: KubbFile.ResolvedFile) => Promise<KubbFile.ResolvedFile>
69
+ task?: (file: ResolvedFile) => Promise<ResolvedFile>
201
70
  }
202
71
 
203
72
  export class FileManager {
@@ -213,8 +82,8 @@ export class FileManager {
213
82
  return this
214
83
  }
215
84
 
216
- get files(): Array<KubbFile.File> {
217
- const files: Array<KubbFile.File> = []
85
+ get files(): Array<FileWithMeta> {
86
+ const files: Array<FileWithMeta> = []
218
87
  this.#cache.forEach((item) => {
219
88
  files.push(...item.flat(1))
220
89
  })
@@ -225,7 +94,7 @@ export class FileManager {
225
94
  return this.#queue.size !== 0 && this.#queue.pending !== 0
226
95
  }
227
96
 
228
- async add<T extends Array<KubbFile.File> = Array<KubbFile.File>>(...files: T): AddResult<T> {
97
+ async add<T extends Array<FileWithMeta> = Array<FileWithMeta>>(...files: T): AddResult<T> {
229
98
  const promises = combineFiles(files).map((file) => {
230
99
  if (file.override) {
231
100
  return this.#add(file)
@@ -243,9 +112,9 @@ export class FileManager {
243
112
  return resolvedFiles[0] as unknown as AddResult<T>
244
113
  }
245
114
 
246
- async #add(file: KubbFile.File): Promise<KubbFile.ResolvedFile> {
115
+ async #add(file: FileWithMeta): Promise<ResolvedFile> {
247
116
  const controller = new AbortController()
248
- const resolvedFile: KubbFile.ResolvedFile = {
117
+ const resolvedFile: ResolvedFile = {
249
118
  id: crypto.randomUUID(),
250
119
  name: trimExtName(file.baseName),
251
120
  ...file,
@@ -272,10 +141,10 @@ export class FileManager {
272
141
  return this.#task?.(resolvedFile)
273
142
  },
274
143
  { signal: controller.signal },
275
- ) as Promise<KubbFile.ResolvedFile>
144
+ ) as Promise<ResolvedFile>
276
145
  }
277
146
 
278
- async #addOrAppend(file: KubbFile.File): Promise<KubbFile.ResolvedFile> {
147
+ async #addOrAppend(file: FileWithMeta): Promise<ResolvedFile> {
279
148
  const previousCaches = this.#cache.get(file.path)
280
149
  const previousCache = previousCaches ? previousCaches.at(previousCaches.length - 1) : undefined
281
150
 
@@ -341,7 +210,7 @@ export class FileManager {
341
210
  )
342
211
 
343
212
  const rootPath = mode === 'split' ? `${exportPath}/index${output.extName || ''}` : `${exportPath}${output.extName || ''}`
344
- const rootFile: KubbFile.File = {
213
+ const rootFile: FileWithMeta = {
345
214
  path: resolve(root, 'index.ts'),
346
215
  baseName: 'index.ts',
347
216
  source: '',
@@ -371,8 +240,8 @@ export class FileManager {
371
240
  })
372
241
  }
373
242
 
374
- getCacheByUUID(UUID: KubbFile.UUID): KubbFile.File | undefined {
375
- let cache: KubbFile.File | undefined
243
+ getCacheByUUID(UUID: KubbFile.UUID): FileWithMeta | undefined {
244
+ let cache: FileWithMeta | undefined
376
245
 
377
246
  this.#cache.forEach((files) => {
378
247
  cache = files.find((item) => item.id === UUID)
@@ -380,7 +249,7 @@ export class FileManager {
380
249
  return cache
381
250
  }
382
251
 
383
- get(path: KubbFile.Path): Array<KubbFile.File> | undefined {
252
+ get(path: KubbFile.Path): Array<FileWithMeta> | undefined {
384
253
  return this.#cache.get(path)
385
254
  }
386
255
 
@@ -403,11 +272,11 @@ export class FileManager {
403
272
 
404
273
  // statics
405
274
 
406
- static async getSource<TMeta extends KubbFile.FileMetaBase = KubbFile.FileMetaBase>(file: KubbFile.File<TMeta>): Promise<string> {
275
+ static async getSource<TMeta extends FileMetaBase = FileMetaBase>(file: FileWithMeta<TMeta>): Promise<string> {
407
276
  return getSource<TMeta>(file)
408
277
  }
409
278
 
410
- static combineFiles<TMeta extends KubbFile.FileMetaBase = KubbFile.FileMetaBase>(files: Array<KubbFile.File<TMeta> | null>): Array<KubbFile.File<TMeta>> {
279
+ static combineFiles<TMeta extends FileMetaBase = FileMetaBase>(files: Array<FileWithMeta<TMeta> | null>): Array<FileWithMeta<TMeta>> {
411
280
  return combineFiles<TMeta>(files)
412
281
  }
413
282
  static getMode(path: string | undefined | null): KubbFile.Mode {
@@ -426,9 +295,9 @@ export class FileManager {
426
295
  }
427
296
  }
428
297
 
429
- function combineFiles<TMeta extends KubbFile.FileMetaBase = KubbFile.FileMetaBase>(files: Array<KubbFile.File<TMeta> | null>): Array<KubbFile.File<TMeta>> {
298
+ function combineFiles<TMeta extends FileMetaBase = FileMetaBase>(files: Array<FileWithMeta<TMeta> | null>): Array<FileWithMeta<TMeta>> {
430
299
  return files.filter(Boolean).reduce(
431
- (acc, file: KubbFile.File<TMeta>) => {
300
+ (acc, file: FileWithMeta<TMeta>) => {
432
301
  const prevIndex = acc.findIndex((item) => item.path === file.path)
433
302
 
434
303
  if (prevIndex === -1) {
@@ -458,11 +327,11 @@ function combineFiles<TMeta extends KubbFile.FileMetaBase = KubbFile.FileMetaBas
458
327
 
459
328
  return acc
460
329
  },
461
- [] as Array<KubbFile.File<TMeta>>,
330
+ [] as Array<FileWithMeta<TMeta>>,
462
331
  )
463
332
  }
464
333
 
465
- export async function getSource<TMeta extends KubbFile.FileMetaBase = KubbFile.FileMetaBase>(file: KubbFile.File<TMeta>): Promise<string> {
334
+ export async function getSource<TMeta extends FileMetaBase = FileMetaBase>(file: FileWithMeta<TMeta>): Promise<string> {
466
335
  // only use .js, .ts or .tsx files for ESM imports
467
336
 
468
337
  if (file.language ? !['typescript', 'javascript'].includes(file.language) : !FileManager.isJavascript(file.baseName)) {
@@ -5,7 +5,7 @@ import { pathToFileURL } from 'node:url'
5
5
  import { findUp, findUpSync } from 'find-up'
6
6
  import { coerce, satisfies } from 'semver'
7
7
 
8
- import { read, readSync } from './fs/read'
8
+ import { read, readSync } from '@kubb/fs'
9
9
 
10
10
  type PackageJSON = {
11
11
  dependencies?: Record<string, string>
@@ -1,18 +1,18 @@
1
1
  import PQueue from 'p-queue'
2
2
 
3
- import { FileManager } from './FileManager.ts'
3
+ import { readSync } from '@kubb/fs'
4
+ import { FileManager, type ResolvedFile } from './FileManager.ts'
4
5
  import { isPromise, isPromiseRejectedResult } from './PromiseManager.ts'
5
6
  import { PromiseManager } from './PromiseManager.ts'
6
7
  import { ValidationPluginError } from './errors.ts'
7
- import { readSync } from './fs/read.ts'
8
8
  import { LogLevel } from './logger.ts'
9
9
  import { pluginCore } from './plugin.ts'
10
10
  import { transformReservedWord } from './transformers/transformReservedWord.ts'
11
11
  import { EventEmitter } from './utils/EventEmitter.ts'
12
12
  import { setUniqueName } from './utils/uniqueName.ts'
13
13
 
14
+ import type * as KubbFile from '@kubb/fs/types'
14
15
  import type { PossiblePromise } from '@kubb/types'
15
- import type { KubbFile } from './FileManager.ts'
16
16
  import type { Logger } from './logger.ts'
17
17
  import type { PluginCore } from './plugin.ts'
18
18
  import type {
@@ -63,7 +63,7 @@ type Options = {
63
63
  /**
64
64
  * Task for the FileManager
65
65
  */
66
- task: (file: KubbFile.ResolvedFile) => Promise<KubbFile.ResolvedFile>
66
+ task: (file: ResolvedFile) => Promise<ResolvedFile>
67
67
  }
68
68
 
69
69
  type Events = {
@@ -634,7 +634,7 @@ export class PluginManager {
634
634
 
635
635
  // default transform
636
636
  if (!plugin.transform) {
637
- plugin.transform = function transform(code) {
637
+ plugin.transform = function transform(_path, code) {
638
638
  return code
639
639
  }
640
640
  }
package/src/build.ts CHANGED
@@ -1,15 +1,13 @@
1
1
  import c from 'tinyrainbow'
2
2
 
3
- import { FileManager } from './FileManager.ts'
3
+ import { clean, read } from '@kubb/fs'
4
+ import { FileManager, type ResolvedFile } from './FileManager.ts'
4
5
  import { PluginManager } from './PluginManager.ts'
5
6
  import { isPromise } from './PromiseManager.ts'
6
7
  import { isInputPath } from './config.ts'
7
- import { clean } from './fs/clean.ts'
8
- import { read } from './fs/read.ts'
9
8
  import { LogLevel, createLogger, randomCliColour } from './logger.ts'
10
9
  import { URLPath } from './utils/URLPath.ts'
11
10
 
12
- import type { KubbFile } from './FileManager.ts'
13
11
  import type { Logger } from './logger.ts'
14
12
  import type { Plugin, PluginContext, PluginParameter, TransformResult } from './types.ts'
15
13
 
@@ -62,7 +60,7 @@ async function setup(options: BuildOptions): Promise<PluginManager> {
62
60
  await clean(config.output.path)
63
61
  }
64
62
 
65
- const task = async (file: KubbFile.ResolvedFile): Promise<KubbFile.ResolvedFile> => {
63
+ const task = async (file: ResolvedFile): Promise<ResolvedFile> => {
66
64
  const { path } = file
67
65
 
68
66
  let source: string | null = await FileManager.getSource(file)
@@ -81,7 +79,7 @@ async function setup(options: BuildOptions): Promise<PluginManager> {
81
79
  if (source) {
82
80
  source = await pluginManager.hookReduceArg0({
83
81
  hookName: 'transform',
84
- parameters: [source, path],
82
+ parameters: [path, source],
85
83
  reduce: transformReducer,
86
84
  })
87
85
 
@@ -91,13 +89,13 @@ async function setup(options: BuildOptions): Promise<PluginManager> {
91
89
  await pluginManager.hookForPlugin({
92
90
  pluginKey: file.meta?.pluginKey,
93
91
  hookName: 'writeFile',
94
- parameters: [source, path],
92
+ parameters: [path, source],
95
93
  })
96
94
  }
97
95
 
98
96
  await pluginManager.hookFirst({
99
97
  hookName: 'writeFile',
100
- parameters: [source, path],
98
+ parameters: [path, source],
101
99
  })
102
100
  }
103
101
  }
package/src/index.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  export { build, build as default, safeBuild } from './build.ts'
2
2
  export { defineConfig, isInputPath } from './config.ts'
3
3
  export { Warning } from './errors.ts'
4
- export { FileManager, KubbFile } from './FileManager.ts'
4
+ export { FileManager } from './FileManager.ts'
5
+ export type { FileMetaBase } from './FileManager.ts'
5
6
  export { Generator } from './Generator.ts'
6
7
  export { PackageManager } from './PackageManager.ts'
7
8
  export { createPlugin } from './plugin.ts'
@@ -11,5 +12,3 @@ export type * from './types.ts'
11
12
 
12
13
  // biome-ignore lint/suspicious/noEmptyInterface: <explanation>
13
14
  export interface _Register {}
14
-
15
- export * as Kubb from './kubb.ts'
package/src/logger.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  import seedrandom from 'seedrandom'
2
2
  import c, { createColors } from 'tinyrainbow'
3
3
 
4
- import { writeLog } from './fs/write.ts'
5
4
  import { EventEmitter } from './utils/EventEmitter.ts'
6
5
 
7
6
  import type { ConsolaInstance } from 'consola'
@@ -78,12 +77,6 @@ export function createLogger({ logLevel, name, spinner, consola }: Props): Logge
78
77
  throw error
79
78
  })
80
79
 
81
- events.on('debug', async (messages) => {
82
- if (logLevel === LogLevel.debug) {
83
- await writeLog(messages.join('\n'))
84
- }
85
- })
86
-
87
80
  const logger: Logger = {
88
81
  name,
89
82
  logLevel,
package/src/types.ts CHANGED
@@ -1,5 +1,6 @@
1
+ import type * as KubbFile from '@kubb/fs/types'
1
2
  import type { PossiblePromise } from '@kubb/types'
2
- import type { FileManager, KubbFile } from './FileManager.ts'
3
+ import type { FileManager } from './FileManager.ts'
3
4
  import type { PluginManager } from './PluginManager.ts'
4
5
  import type { OptionsPlugins, PluginUnion } from './kubb.ts'
5
6
  import type { Logger } from './logger.ts'
@@ -242,7 +243,7 @@ export type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactor
242
243
  * Write the result to the file-system based on the id(defined by `resolvePath` or changed by `load`).
243
244
  * @type hookParallel
244
245
  */
245
- writeFile?: (this: Omit<PluginContext<TOptions>, 'addFile'>, source: string | undefined, path: KubbFile.Path) => PossiblePromise<string | void>
246
+ writeFile?: (this: Omit<PluginContext<TOptions>, 'addFile'>, path: KubbFile.Path, source: string | undefined) => PossiblePromise<string | void>
246
247
  /**
247
248
  * End of the plugin lifecycle.
248
249
  * @type hookParallel
@@ -2,8 +2,8 @@ import dirTree from 'directory-tree'
2
2
 
3
3
  import { FileManager } from '../FileManager.ts'
4
4
 
5
+ import type * as KubbFile from '@kubb/fs/types'
5
6
  import type { DirectoryTree, DirectoryTreeOptions } from 'directory-tree'
6
- import type { KubbFile } from '../FileManager.ts'
7
7
 
8
8
  export type TreeNodeOptions = DirectoryTreeOptions
9
9
 
@@ -1,85 +0,0 @@
1
- // src/fs/write.ts
2
- import { resolve } from "path";
3
- import fs from "fs-extra";
4
- import { switcher } from "js-runtime";
5
- var writer = switcher(
6
- {
7
- node: async (path, data, { sanity }) => {
8
- try {
9
- const oldContent = await fs.readFile(resolve(path), {
10
- encoding: "utf-8"
11
- });
12
- if (oldContent?.toString() === data?.toString()) {
13
- return;
14
- }
15
- } catch (_err) {
16
- }
17
- await fs.outputFile(resolve(path), data, { encoding: "utf-8" });
18
- if (sanity) {
19
- const savedData = await fs.readFile(resolve(path), {
20
- encoding: "utf-8"
21
- });
22
- if (savedData?.toString() !== data?.toString()) {
23
- throw new Error(`Sanity check failed for ${path}
24
-
25
- Data[${data.length}]:
26
- ${data}
27
-
28
- Saved[${savedData.length}]:
29
- ${savedData}
30
- `);
31
- }
32
- return savedData;
33
- }
34
- return data;
35
- },
36
- bun: async (path, data, { sanity }) => {
37
- try {
38
- await Bun.write(resolve(path), data);
39
- if (sanity) {
40
- const file = Bun.file(resolve(path));
41
- const savedData = await file.text();
42
- if (savedData?.toString() !== data?.toString()) {
43
- throw new Error(`Sanity check failed for ${path}
44
-
45
- Data[${data.length}]:
46
- ${data}
47
-
48
- Saved[${savedData.length}]:
49
- ${savedData}
50
- `);
51
- }
52
- return savedData;
53
- }
54
- return data;
55
- } catch (e) {
56
- console.log(e, resolve(path));
57
- }
58
- }
59
- },
60
- "node"
61
- );
62
- async function write(data, path, options = {}) {
63
- if (data.trim() === "") {
64
- return void 0;
65
- }
66
- return writer(path, data.trim(), options);
67
- }
68
- async function writeLog(data) {
69
- if (data.trim() === "") {
70
- return void 0;
71
- }
72
- const path = resolve(process.cwd(), "kubb-log.log");
73
- let previousLogs = "";
74
- try {
75
- previousLogs = await fs.readFile(resolve(path), { encoding: "utf-8" });
76
- } catch (_err) {
77
- }
78
- return writer(path, [previousLogs, data.trim()].filter(Boolean).join("\n\n\n"), { sanity: false });
79
- }
80
-
81
- export {
82
- write,
83
- writeLog
84
- };
85
- //# sourceMappingURL=chunk-2F7E62RD.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/fs/write.ts"],"sourcesContent":["import { resolve } from 'node:path'\n\nimport fs from 'fs-extra'\nimport { switcher } from 'js-runtime'\n\ntype Options = { sanity?: boolean }\n\nconst writer = switcher(\n {\n node: async (path: string, data: string, { sanity }: Options) => {\n try {\n const oldContent = await fs.readFile(resolve(path), {\n encoding: 'utf-8',\n })\n if (oldContent?.toString() === data?.toString()) {\n return\n }\n } catch (_err) {\n /* empty */\n }\n\n await fs.outputFile(resolve(path), data, { encoding: 'utf-8' })\n\n if (sanity) {\n const savedData = await fs.readFile(resolve(path), {\n encoding: 'utf-8',\n })\n\n if (savedData?.toString() !== data?.toString()) {\n throw new Error(`Sanity check failed for ${path}\\n\\nData[${data.length}]:\\n${data}\\n\\nSaved[${savedData.length}]:\\n${savedData}\\n`)\n }\n\n return savedData\n }\n\n return data\n },\n bun: async (path: string, data: string, { sanity }: Options) => {\n try {\n await Bun.write(resolve(path), data)\n\n if (sanity) {\n const file = Bun.file(resolve(path))\n const savedData = await file.text()\n\n if (savedData?.toString() !== data?.toString()) {\n throw new Error(`Sanity check failed for ${path}\\n\\nData[${data.length}]:\\n${data}\\n\\nSaved[${savedData.length}]:\\n${savedData}\\n`)\n }\n\n return savedData\n }\n\n return data\n } catch (e) {\n console.log(e, resolve(path))\n }\n },\n },\n 'node',\n)\n\nexport async function write(data: string, path: string, options: Options = {}): Promise<string | undefined> {\n if (data.trim() === '') {\n return undefined\n }\n return writer(path, data.trim(), options)\n}\n\nexport async function writeLog(data: string): Promise<string | undefined> {\n if (data.trim() === '') {\n return undefined\n }\n const path = resolve(process.cwd(), 'kubb-log.log')\n let previousLogs = ''\n\n try {\n previousLogs = await fs.readFile(resolve(path), { encoding: 'utf-8' })\n } catch (_err) {\n /* empty */\n }\n\n return writer(path, [previousLogs, data.trim()].filter(Boolean).join('\\n\\n\\n'), { sanity: false })\n}\n"],"mappings":";AAAA,SAAS,eAAe;AAExB,OAAO,QAAQ;AACf,SAAS,gBAAgB;AAIzB,IAAM,SAAS;AAAA,EACb;AAAA,IACE,MAAM,OAAO,MAAc,MAAc,EAAE,OAAO,MAAe;AAC/D,UAAI;AACF,cAAM,aAAa,MAAM,GAAG,SAAS,QAAQ,IAAI,GAAG;AAAA,UAClD,UAAU;AAAA,QACZ,CAAC;AACD,YAAI,YAAY,SAAS,MAAM,MAAM,SAAS,GAAG;AAC/C;AAAA,QACF;AAAA,MACF,SAAS,MAAM;AAAA,MAEf;AAEA,YAAM,GAAG,WAAW,QAAQ,IAAI,GAAG,MAAM,EAAE,UAAU,QAAQ,CAAC;AAE9D,UAAI,QAAQ;AACV,cAAM,YAAY,MAAM,GAAG,SAAS,QAAQ,IAAI,GAAG;AAAA,UACjD,UAAU;AAAA,QACZ,CAAC;AAED,YAAI,WAAW,SAAS,MAAM,MAAM,SAAS,GAAG;AAC9C,gBAAM,IAAI,MAAM,2BAA2B,IAAI;AAAA;AAAA,OAAY,KAAK,MAAM;AAAA,EAAO,IAAI;AAAA;AAAA,QAAa,UAAU,MAAM;AAAA,EAAO,SAAS;AAAA,CAAI;AAAA,QACpI;AAEA,eAAO;AAAA,MACT;AAEA,aAAO;AAAA,IACT;AAAA,IACA,KAAK,OAAO,MAAc,MAAc,EAAE,OAAO,MAAe;AAC9D,UAAI;AACF,cAAM,IAAI,MAAM,QAAQ,IAAI,GAAG,IAAI;AAEnC,YAAI,QAAQ;AACV,gBAAM,OAAO,IAAI,KAAK,QAAQ,IAAI,CAAC;AACnC,gBAAM,YAAY,MAAM,KAAK,KAAK;AAElC,cAAI,WAAW,SAAS,MAAM,MAAM,SAAS,GAAG;AAC9C,kBAAM,IAAI,MAAM,2BAA2B,IAAI;AAAA;AAAA,OAAY,KAAK,MAAM;AAAA,EAAO,IAAI;AAAA;AAAA,QAAa,UAAU,MAAM;AAAA,EAAO,SAAS;AAAA,CAAI;AAAA,UACpI;AAEA,iBAAO;AAAA,QACT;AAEA,eAAO;AAAA,MACT,SAAS,GAAG;AACV,gBAAQ,IAAI,GAAG,QAAQ,IAAI,CAAC;AAAA,MAC9B;AAAA,IACF;AAAA,EACF;AAAA,EACA;AACF;AAEA,eAAsB,MAAM,MAAc,MAAc,UAAmB,CAAC,GAAgC;AAC1G,MAAI,KAAK,KAAK,MAAM,IAAI;AACtB,WAAO;AAAA,EACT;AACA,SAAO,OAAO,MAAM,KAAK,KAAK,GAAG,OAAO;AAC1C;AAEA,eAAsB,SAAS,MAA2C;AACxE,MAAI,KAAK,KAAK,MAAM,IAAI;AACtB,WAAO;AAAA,EACT;AACA,QAAM,OAAO,QAAQ,QAAQ,IAAI,GAAG,cAAc;AAClD,MAAI,eAAe;AAEnB,MAAI;AACF,mBAAe,MAAM,GAAG,SAAS,QAAQ,IAAI,GAAG,EAAE,UAAU,QAAQ,CAAC;AAAA,EACvE,SAAS,MAAM;AAAA,EAEf;AAEA,SAAO,OAAO,MAAM,CAAC,cAAc,KAAK,KAAK,CAAC,EAAE,OAAO,OAAO,EAAE,KAAK,QAAQ,GAAG,EAAE,QAAQ,MAAM,CAAC;AACnG;","names":[]}