@kubb/core 2.11.1 → 2.12.0

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 (92) hide show
  1. package/dist/{chunk-4GE2JRAA.cjs → chunk-33S7A7ZE.cjs} +28 -5
  2. package/dist/chunk-33S7A7ZE.cjs.map +1 -0
  3. package/dist/{chunk-CH2676BL.js → chunk-4BZD7YTT.js} +2 -2
  4. package/dist/{chunk-G7EQ47A4.js → chunk-ALE7CO7I.js} +26 -3
  5. package/dist/chunk-ALE7CO7I.js.map +1 -0
  6. package/dist/{chunk-WAIHMG76.cjs → chunk-F4TSJHGA.cjs} +3 -3
  7. package/dist/chunk-FOWWV3PP.js +41 -0
  8. package/dist/chunk-FOWWV3PP.js.map +1 -0
  9. package/dist/{chunk-XZZ2F3LK.cjs → chunk-IBUMXAET.cjs} +3 -3
  10. package/dist/{chunk-WXV3UNEP.js → chunk-IP732R22.js} +1 -29
  11. package/dist/chunk-IP732R22.js.map +1 -0
  12. package/dist/chunk-KPXUT3DG.cjs +143 -0
  13. package/dist/chunk-KPXUT3DG.cjs.map +1 -0
  14. package/dist/{chunk-UYADU5OY.js → chunk-L2OHRGUS.js} +7 -3
  15. package/dist/chunk-L2OHRGUS.js.map +1 -0
  16. package/dist/{chunk-JDIEEDDB.cjs → chunk-OMX2RMAX.cjs} +3 -3
  17. package/dist/{chunk-TJHTFTXA.cjs → chunk-OVLOS3IJ.cjs} +267 -347
  18. package/dist/chunk-OVLOS3IJ.cjs.map +1 -0
  19. package/dist/{chunk-KOQSM5X7.cjs → chunk-VHRZO2NC.cjs} +20 -20
  20. package/dist/chunk-VHRZO2NC.cjs.map +1 -0
  21. package/dist/chunk-YYCT7ZB7.cjs +94 -0
  22. package/dist/chunk-YYCT7ZB7.cjs.map +1 -0
  23. package/dist/{chunk-H7U5WQ3I.js → chunk-Z5N655B7.js} +20 -20
  24. package/dist/chunk-Z5N655B7.js.map +1 -0
  25. package/dist/{chunk-DOELQNBO.cjs → chunk-ZS3YTJ2L.cjs} +3 -133
  26. package/dist/chunk-ZS3YTJ2L.cjs.map +1 -0
  27. package/dist/fs.cjs +5 -4
  28. package/dist/fs.cjs.map +1 -1
  29. package/dist/fs.js +3 -3
  30. package/dist/index.cjs +2672 -83
  31. package/dist/index.cjs.map +1 -1
  32. package/dist/index.d.cts +6 -1
  33. package/dist/index.d.ts +6 -1
  34. package/dist/index.js +1981 -52
  35. package/dist/index.js.map +1 -1
  36. package/dist/logger.cjs +4 -3
  37. package/dist/logger.js +2 -2
  38. package/dist/mocks.cjs +6 -10
  39. package/dist/mocks.cjs.map +1 -1
  40. package/dist/mocks.js +1 -6
  41. package/dist/mocks.js.map +1 -1
  42. package/dist/transformers.cjs +34 -21
  43. package/dist/transformers.cjs.map +1 -1
  44. package/dist/transformers.d.cts +4 -2
  45. package/dist/transformers.d.ts +4 -2
  46. package/dist/transformers.js +24 -11
  47. package/dist/transformers.js.map +1 -1
  48. package/dist/utils.cjs +28 -26
  49. package/dist/utils.cjs.map +1 -1
  50. package/dist/utils.js +29 -27
  51. package/dist/utils.js.map +1 -1
  52. package/package.json +4 -3
  53. package/src/BarrelManager.ts +33 -31
  54. package/src/FileManager.ts +176 -137
  55. package/src/PackageManager.ts +4 -4
  56. package/src/PluginManager.ts +62 -52
  57. package/src/build.ts +28 -9
  58. package/src/config.ts +3 -3
  59. package/src/fs/write.ts +6 -2
  60. package/src/index.ts +1 -1
  61. package/src/transformers/casing.ts +11 -5
  62. package/src/transformers/escape.ts +2 -4
  63. package/src/transformers/index.ts +3 -2
  64. package/src/transformers/stringify.ts +19 -3
  65. package/src/transformers/toNumber.ts +1 -1
  66. package/src/transformers/toRegExp.ts +1 -5
  67. package/src/types.ts +67 -71
  68. package/src/utils/FunctionParams.ts +24 -23
  69. package/src/utils/TreeNode.ts +15 -4
  70. package/src/utils/URLPath.ts +2 -6
  71. package/src/utils/executeStrategies.ts +7 -7
  72. package/src/utils/index.ts +5 -1
  73. package/dist/chunk-4GE2JRAA.cjs.map +0 -1
  74. package/dist/chunk-B7DTFNR4.js +0 -30
  75. package/dist/chunk-B7DTFNR4.js.map +0 -1
  76. package/dist/chunk-DOELQNBO.cjs.map +0 -1
  77. package/dist/chunk-G7EQ47A4.js.map +0 -1
  78. package/dist/chunk-H7U5WQ3I.js.map +0 -1
  79. package/dist/chunk-KOQSM5X7.cjs.map +0 -1
  80. package/dist/chunk-TJHTFTXA.cjs.map +0 -1
  81. package/dist/chunk-UIWHEBZA.cjs +0 -2549
  82. package/dist/chunk-UIWHEBZA.cjs.map +0 -1
  83. package/dist/chunk-UUBXTHJG.cjs +0 -30
  84. package/dist/chunk-UUBXTHJG.cjs.map +0 -1
  85. package/dist/chunk-UYADU5OY.js.map +0 -1
  86. package/dist/chunk-WXV3UNEP.js.map +0 -1
  87. package/dist/chunk-ZNYG4U5D.js +0 -1888
  88. package/dist/chunk-ZNYG4U5D.js.map +0 -1
  89. /package/dist/{chunk-CH2676BL.js.map → chunk-4BZD7YTT.js.map} +0 -0
  90. /package/dist/{chunk-WAIHMG76.cjs.map → chunk-F4TSJHGA.cjs.map} +0 -0
  91. /package/dist/{chunk-XZZ2F3LK.cjs.map → chunk-IBUMXAET.cjs.map} +0 -0
  92. /package/dist/{chunk-JDIEEDDB.cjs.map → chunk-OMX2RMAX.cjs.map} +0 -0
@@ -9,11 +9,11 @@ import isEqual from 'lodash.isequal'
9
9
  import { orderBy } from 'natural-orderby'
10
10
  import PQueue from 'p-queue'
11
11
 
12
+ import { BarrelManager } from './BarrelManager.ts'
12
13
  import { getRelativePath, read } from './fs/read.ts'
13
14
  import { write } from './fs/write.ts'
14
15
  import { searchAndReplace } from './transformers/searchAndReplace.ts'
15
16
  import { trimExtName } from './transformers/trim.ts'
16
- import { BarrelManager } from './BarrelManager.ts'
17
17
 
18
18
  import type { GreaterThan } from '@kubb/types'
19
19
  import type { BarrelManagerOptions } from './BarrelManager.ts'
@@ -31,11 +31,12 @@ export namespace KubbFile {
31
31
  name:
32
32
  | string
33
33
  | Array<
34
- string | {
35
- propertyName: string
36
- name?: string
37
- }
38
- >
34
+ | string
35
+ | {
36
+ propertyName: string
37
+ name?: string
38
+ }
39
+ >
39
40
  /**
40
41
  * Path for the import
41
42
  * @xample '@kubb/core'
@@ -48,6 +49,7 @@ export namespace KubbFile {
48
49
  /**
49
50
  * Add `* as` prefix to the import, this will result in: `import * as path from './path'`.
50
51
  */
52
+
51
53
  isNameSpace?: boolean
52
54
  /**
53
55
  * When root is set it will get the path with relative getRelativePath(root, path).
@@ -109,10 +111,7 @@ export namespace KubbFile {
109
111
  pluginKey?: Plugin['key']
110
112
  }
111
113
 
112
- export type File<
113
- TMeta extends FileMetaBase = FileMetaBase,
114
- TBaseName extends BaseName = BaseName,
115
- > = {
114
+ export type File<TMeta extends FileMetaBase = FileMetaBase, TBaseName extends BaseName = BaseName> = {
116
115
  /**
117
116
  * Unique identifier to reuse later
118
117
  * @default crypto.randomUUID()
@@ -141,6 +140,11 @@ export namespace KubbFile {
141
140
  * Use extra meta, this is getting used to generate the barrel/index files.
142
141
  */
143
142
  meta?: TMeta
143
+ /**
144
+ * Override if a file can be exported by the BarrelManager
145
+ * @default true
146
+ */
147
+ exportable?: boolean
144
148
  /**
145
149
  * This will override `process.env[key]` inside the `source`, see `getFileSource`.
146
150
  */
@@ -151,10 +155,7 @@ export namespace KubbFile {
151
155
  language?: string
152
156
  }
153
157
 
154
- export type ResolvedFile<
155
- TMeta extends FileMetaBase = FileMetaBase,
156
- TBaseName extends BaseName = BaseName,
157
- > = KubbFile.File<TMeta, TBaseName> & {
158
+ export type ResolvedFile<TMeta extends FileMetaBase = FileMetaBase, TBaseName extends BaseName = BaseName> = KubbFile.File<TMeta, TBaseName> & {
158
159
  /**
159
160
  * @default crypto.randomUUID()
160
161
  */
@@ -224,9 +225,7 @@ export class FileManager {
224
225
  return this.#queue.size !== 0 && this.#queue.pending !== 0
225
226
  }
226
227
 
227
- async add<T extends Array<KubbFile.File> = Array<KubbFile.File>>(
228
- ...files: T
229
- ): AddResult<T> {
228
+ async add<T extends Array<KubbFile.File> = Array<KubbFile.File>>(...files: T): AddResult<T> {
230
229
  const promises = combineFiles(files).map((file) => {
231
230
  if (file.override) {
232
231
  return this.#add(file)
@@ -246,7 +245,25 @@ export class FileManager {
246
245
 
247
246
  async #add(file: KubbFile.File): Promise<KubbFile.ResolvedFile> {
248
247
  const controller = new AbortController()
249
- const resolvedFile: KubbFile.ResolvedFile = { id: crypto.randomUUID(), name: trimExtName(file.baseName), ...file }
248
+ const resolvedFile: KubbFile.ResolvedFile = {
249
+ id: crypto.randomUUID(),
250
+ name: trimExtName(file.baseName),
251
+ ...file,
252
+ }
253
+
254
+ if (resolvedFile.exports?.length) {
255
+ const folder = resolvedFile.path.replace(resolvedFile.baseName, '')
256
+
257
+ resolvedFile.exports = resolvedFile.exports.filter((exportItem) => {
258
+ const exportedFile = this.files.find((file) => file.path.includes(resolve(folder, exportItem.path)))
259
+
260
+ if (exportedFile) {
261
+ return exportedFile.exportable
262
+ }
263
+
264
+ return true
265
+ })
266
+ }
250
267
 
251
268
  this.#cache.set(resolvedFile.path, [{ cancel: () => controller.abort(), ...resolvedFile }])
252
269
 
@@ -286,7 +303,10 @@ export class FileManager {
286
303
  const pathToBuildFrom = resolve(root, output.path)
287
304
  const exportPath = output.path.startsWith('./') ? trimExtName(output.path) : `./${trimExtName(output.path)}`
288
305
  const mode = FileManager.getMode(output.path)
289
- const barrelManager = new BarrelManager({ extName: output.extName, ...options })
306
+ const barrelManager = new BarrelManager({
307
+ extName: output.extName,
308
+ ...options,
309
+ })
290
310
  let files = barrelManager.getIndexes(pathToBuildFrom)
291
311
 
292
312
  if (!files) {
@@ -294,7 +314,7 @@ export class FileManager {
294
314
  }
295
315
 
296
316
  if (exportType === 'barrelNamed') {
297
- files = files.map(file => {
317
+ files = files.map((file) => {
298
318
  if (file.exports) {
299
319
  return {
300
320
  ...file,
@@ -322,16 +342,17 @@ export class FileManager {
322
342
  exports: [
323
343
  output.exportAs
324
344
  ? {
325
- name: output.exportAs,
326
- asAlias: true,
327
- path: rootPath,
328
- isTypeOnly: options.isTypeOnly,
329
- }
345
+ name: output.exportAs,
346
+ asAlias: true,
347
+ path: rootPath,
348
+ isTypeOnly: options.isTypeOnly,
349
+ }
330
350
  : {
331
- path: rootPath,
332
- isTypeOnly: options.isTypeOnly,
333
- },
351
+ path: rootPath,
352
+ isTypeOnly: options.isTypeOnly,
353
+ },
334
354
  ],
355
+ exportable: true,
335
356
  }
336
357
 
337
358
  if (exportType === 'barrelNamed' && !output.exportAs && rootFile.exports?.[0]) {
@@ -399,39 +420,40 @@ export class FileManager {
399
420
  }
400
421
  }
401
422
 
402
- function combineFiles<TMeta extends KubbFile.FileMetaBase = KubbFile.FileMetaBase>(
403
- files: Array<KubbFile.File<TMeta> | null>,
404
- ): Array<KubbFile.File<TMeta>> {
405
- return files.filter(Boolean).reduce((acc, file: KubbFile.File<TMeta>) => {
406
- const prevIndex = acc.findIndex((item) => item.path === file.path)
423
+ function combineFiles<TMeta extends KubbFile.FileMetaBase = KubbFile.FileMetaBase>(files: Array<KubbFile.File<TMeta> | null>): Array<KubbFile.File<TMeta>> {
424
+ return files.filter(Boolean).reduce(
425
+ (acc, file: KubbFile.File<TMeta>) => {
426
+ const prevIndex = acc.findIndex((item) => item.path === file.path)
407
427
 
408
- if (prevIndex === -1) {
409
- return [...acc, file]
410
- }
428
+ if (prevIndex === -1) {
429
+ return [...acc, file]
430
+ }
411
431
 
412
- const prev = acc[prevIndex]
432
+ const prev = acc[prevIndex]
413
433
 
414
- if (prev && file.override) {
415
- acc[prevIndex] = {
416
- imports: [],
417
- exports: [],
418
- ...file,
434
+ if (prev && file.override) {
435
+ acc[prevIndex] = {
436
+ imports: [],
437
+ exports: [],
438
+ ...file,
439
+ }
440
+ return acc
419
441
  }
420
- return acc
421
- }
422
442
 
423
- if (prev) {
424
- acc[prevIndex] = {
425
- ...file,
426
- source: prev.source && file.source ? `${prev.source}\n${file.source}` : '',
427
- imports: [...(prev.imports || []), ...(file.imports || [])],
428
- exports: [...(prev.exports || []), ...(file.exports || [])],
429
- env: { ...(prev.env || {}), ...(file.env || {}) },
443
+ if (prev) {
444
+ acc[prevIndex] = {
445
+ ...file,
446
+ source: prev.source && file.source ? `${prev.source}\n${file.source}` : '',
447
+ imports: [...(prev.imports || []), ...(file.imports || [])],
448
+ exports: [...(prev.exports || []), ...(file.exports || [])],
449
+ env: { ...(prev.env || {}), ...(file.env || {}) },
450
+ }
430
451
  }
431
- }
432
452
 
433
- return acc
434
- }, [] as Array<KubbFile.File<TMeta>>)
453
+ return acc
454
+ },
455
+ [] as Array<KubbFile.File<TMeta>>,
456
+ )
435
457
  }
436
458
 
437
459
  export function getSource<TMeta extends KubbFile.FileMetaBase = KubbFile.FileMetaBase>(file: KubbFile.File<TMeta>): string {
@@ -445,24 +467,26 @@ export function getSource<TMeta extends KubbFile.FileMetaBase = KubbFile.FileMet
445
467
  // imports should be defined and source should contain code or we have imports without them being used
446
468
  const imports = file.imports && file.source ? combineImports(file.imports, exports, file.source) : []
447
469
 
448
- const importNodes = imports.filter(item => {
449
- // isImportNotNeeded
450
- // trim extName
451
- return item.path !== trimExtName(file.path)
452
- }).map((item) => {
453
- return factory.createImportDeclaration({
454
- name: item.name,
455
- path: item.root ? getRelativePath(item.root, item.path) : item.path,
456
- isTypeOnly: item.isTypeOnly,
470
+ const importNodes = imports
471
+ .filter((item) => {
472
+ // isImportNotNeeded
473
+ // trim extName
474
+ return item.path !== trimExtName(file.path)
475
+ })
476
+ .map((item) => {
477
+ return factory.createImportDeclaration({
478
+ name: item.name,
479
+ path: item.root ? getRelativePath(item.root, item.path) : item.path,
480
+ isTypeOnly: item.isTypeOnly,
481
+ })
457
482
  })
458
- })
459
483
  const exportNodes = exports.map((item) =>
460
484
  factory.createExportDeclaration({
461
485
  name: item.name,
462
486
  path: item.path,
463
487
  isTypeOnly: item.isTypeOnly,
464
488
  asAlias: item.asAlias,
465
- })
489
+ }),
466
490
  )
467
491
 
468
492
  const source = [print([...importNodes, ...exportNodes]), getEnvSource(file.source, file.env)].join('\n')
@@ -472,98 +496,104 @@ export function getSource<TMeta extends KubbFile.FileMetaBase = KubbFile.FileMet
472
496
  }
473
497
 
474
498
  export function combineExports(exports: Array<KubbFile.Export>): Array<KubbFile.Export> {
475
- const combinedExports = orderBy(exports, [(v) => !v.isTypeOnly], ['asc']).reduce((prev, curr) => {
476
- const name = curr.name
477
- const prevByPath = prev.findLast((imp) => imp.path === curr.path)
478
- const prevByPathAndIsTypeOnly = prev.findLast((imp) => imp.path === curr.path && isEqual(imp.name, name) && imp.isTypeOnly)
479
-
480
- if (prevByPathAndIsTypeOnly) {
481
- // we already have an export that has the same path but uses `isTypeOnly` (export type ...)
482
- return prev
483
- }
499
+ const combinedExports = orderBy(exports, [(v) => !v.isTypeOnly], ['asc']).reduce(
500
+ (prev, curr) => {
501
+ const name = curr.name
502
+ const prevByPath = prev.findLast((imp) => imp.path === curr.path)
503
+ const prevByPathAndIsTypeOnly = prev.findLast((imp) => imp.path === curr.path && isEqual(imp.name, name) && imp.isTypeOnly)
504
+
505
+ if (prevByPathAndIsTypeOnly) {
506
+ // we already have an export that has the same path but uses `isTypeOnly` (export type ...)
507
+ return prev
508
+ }
484
509
 
485
- const uniquePrev = prev.findLast(
486
- (imp) => imp.path === curr.path && isEqual(imp.name, name) && imp.isTypeOnly === curr.isTypeOnly && imp.asAlias === curr.asAlias,
487
- )
510
+ const uniquePrev = prev.findLast(
511
+ (imp) => imp.path === curr.path && isEqual(imp.name, name) && imp.isTypeOnly === curr.isTypeOnly && imp.asAlias === curr.asAlias,
512
+ )
488
513
 
489
- if (uniquePrev || (Array.isArray(name) && !name.length) || (prevByPath?.asAlias && !curr.asAlias)) {
490
- return prev
491
- }
514
+ if (uniquePrev || (Array.isArray(name) && !name.length) || (prevByPath?.asAlias && !curr.asAlias)) {
515
+ return prev
516
+ }
492
517
 
493
- if (!prevByPath) {
494
- return [
495
- ...prev,
496
- {
497
- ...curr,
498
- name: Array.isArray(name) ? [...new Set(name)] : name,
499
- },
500
- ]
501
- }
518
+ if (!prevByPath) {
519
+ return [
520
+ ...prev,
521
+ {
522
+ ...curr,
523
+ name: Array.isArray(name) ? [...new Set(name)] : name,
524
+ },
525
+ ]
526
+ }
502
527
 
503
- if (prevByPath && Array.isArray(prevByPath.name) && Array.isArray(curr.name) && prevByPath.isTypeOnly === curr.isTypeOnly) {
504
- prevByPath.name = [...new Set([...prevByPath.name, ...curr.name])]
528
+ if (prevByPath && Array.isArray(prevByPath.name) && Array.isArray(curr.name) && prevByPath.isTypeOnly === curr.isTypeOnly) {
529
+ prevByPath.name = [...new Set([...prevByPath.name, ...curr.name])]
505
530
 
506
- return prev
507
- }
531
+ return prev
532
+ }
508
533
 
509
- return [...prev, curr]
510
- }, [] as Array<KubbFile.Export>)
534
+ return [...prev, curr]
535
+ },
536
+ [] as Array<KubbFile.Export>,
537
+ )
511
538
 
512
539
  return orderBy(combinedExports, [(v) => !v.isTypeOnly, (v) => v.asAlias], ['desc', 'desc'])
513
540
  }
514
541
 
515
542
  export function combineImports(imports: Array<KubbFile.Import>, exports: Array<KubbFile.Export>, source?: string): Array<KubbFile.Import> {
516
- const combinedImports = orderBy(imports, [(v) => !v.isTypeOnly], ['asc']).reduce((prev, curr) => {
517
- let name = Array.isArray(curr.name) ? [...new Set(curr.name)] : curr.name
543
+ const combinedImports = orderBy(imports, [(v) => !v.isTypeOnly], ['asc']).reduce(
544
+ (prev, curr) => {
545
+ let name = Array.isArray(curr.name) ? [...new Set(curr.name)] : curr.name
518
546
 
519
- const hasImportInSource = (importName: string) => {
520
- if (!source) {
521
- return true
522
- }
547
+ const hasImportInSource = (importName: string) => {
548
+ if (!source) {
549
+ return true
550
+ }
523
551
 
524
- const checker = (name?: string) => name && !!source.includes(name)
525
- return checker(importName) || exports.some(({ name }) => (Array.isArray(name) ? name.some(checker) : checker(name)))
526
- }
552
+ const checker = (name?: string) => name && !!source.includes(name)
553
+ return checker(importName) || exports.some(({ name }) => (Array.isArray(name) ? name.some(checker) : checker(name)))
554
+ }
527
555
 
528
- if (Array.isArray(name)) {
529
- name = name.filter((item) => typeof item === 'string' ? hasImportInSource(item) : hasImportInSource(item.propertyName))
530
- }
556
+ if (Array.isArray(name)) {
557
+ name = name.filter((item) => (typeof item === 'string' ? hasImportInSource(item) : hasImportInSource(item.propertyName)))
558
+ }
531
559
 
532
- const prevByPath = prev.findLast((imp) => imp.path === curr.path && imp.isTypeOnly === curr.isTypeOnly)
533
- const uniquePrev = prev.findLast((imp) => imp.path === curr.path && isEqual(imp.name, name) && imp.isTypeOnly === curr.isTypeOnly)
534
- const prevByPathNameAndIsTypeOnly = prev.findLast((imp) => imp.path === curr.path && isEqual(imp.name, name) && imp.isTypeOnly)
560
+ const prevByPath = prev.findLast((imp) => imp.path === curr.path && imp.isTypeOnly === curr.isTypeOnly)
561
+ const uniquePrev = prev.findLast((imp) => imp.path === curr.path && isEqual(imp.name, name) && imp.isTypeOnly === curr.isTypeOnly)
562
+ const prevByPathNameAndIsTypeOnly = prev.findLast((imp) => imp.path === curr.path && isEqual(imp.name, name) && imp.isTypeOnly)
535
563
 
536
- if (prevByPathNameAndIsTypeOnly) {
537
- // we already have an export that has the same path but uses `isTypeOnly` (import type ...)
538
- return prev
539
- }
564
+ if (prevByPathNameAndIsTypeOnly) {
565
+ // we already have an export that has the same path but uses `isTypeOnly` (import type ...)
566
+ return prev
567
+ }
540
568
 
541
- if (uniquePrev || (Array.isArray(name) && !name.length)) {
542
- return prev
543
- }
569
+ if (uniquePrev || (Array.isArray(name) && !name.length)) {
570
+ return prev
571
+ }
544
572
 
545
- if (!prevByPath) {
546
- return [
547
- ...prev,
548
- {
549
- ...curr,
550
- name,
551
- },
552
- ]
553
- }
573
+ if (!prevByPath) {
574
+ return [
575
+ ...prev,
576
+ {
577
+ ...curr,
578
+ name,
579
+ },
580
+ ]
581
+ }
554
582
 
555
- if (prevByPath && Array.isArray(prevByPath.name) && Array.isArray(name) && prevByPath.isTypeOnly === curr.isTypeOnly) {
556
- prevByPath.name = [...new Set([...prevByPath.name, ...name])]
583
+ if (prevByPath && Array.isArray(prevByPath.name) && Array.isArray(name) && prevByPath.isTypeOnly === curr.isTypeOnly) {
584
+ prevByPath.name = [...new Set([...prevByPath.name, ...name])]
557
585
 
558
- return prev
559
- }
586
+ return prev
587
+ }
560
588
 
561
- if (!Array.isArray(name) && name && !hasImportInSource(name)) {
562
- return prev
563
- }
589
+ if (!Array.isArray(name) && name && !hasImportInSource(name)) {
590
+ return prev
591
+ }
564
592
 
565
- return [...prev, curr]
566
- }, [] as Array<KubbFile.Import>)
593
+ return [...prev, curr]
594
+ },
595
+ [] as Array<KubbFile.Import>,
596
+ )
567
597
 
568
598
  return orderBy(combinedImports, [(v) => !v.isTypeOnly], ['desc'])
569
599
  }
@@ -588,9 +618,18 @@ function getEnvSource(source: string, env: NodeJS.ProcessEnv | undefined): strin
588
618
  }
589
619
 
590
620
  if (typeof replaceBy === 'string') {
591
- prev = searchAndReplace({ text: prev.replaceAll(`process.env.${key}`, replaceBy), replaceBy, prefix: 'process.env', key })
621
+ prev = searchAndReplace({
622
+ text: prev.replaceAll(`process.env.${key}`, replaceBy),
623
+ replaceBy,
624
+ prefix: 'process.env',
625
+ key,
626
+ })
592
627
  // removes `declare const ...`
593
- prev = searchAndReplace({ text: prev.replaceAll(new RegExp(`(declare const).*\n`, 'ig'), ''), replaceBy, key })
628
+ prev = searchAndReplace({
629
+ text: prev.replaceAll(/(declare const).*\n/gi, ''),
630
+ replaceBy,
631
+ key,
632
+ })
594
633
  }
595
634
 
596
635
  return prev
@@ -60,7 +60,7 @@ export class PackageManager {
60
60
  try {
61
61
  let location = this.getLocation(path)
62
62
 
63
- if (os.platform() == 'win32') {
63
+ if (os.platform() === 'win32') {
64
64
  location = pathToFileURL(location).href
65
65
  }
66
66
 
@@ -107,15 +107,15 @@ export class PackageManager {
107
107
 
108
108
  #match(packageJSON: PackageJSON, dependency: DependencyName | RegExp): string | undefined {
109
109
  const dependencies = {
110
- ...packageJSON['dependencies'] || {},
111
- ...packageJSON['devDependencies'] || {},
110
+ ...(packageJSON['dependencies'] || {}),
111
+ ...(packageJSON['devDependencies'] || {}),
112
112
  }
113
113
 
114
114
  if (typeof dependency === 'string' && dependencies[dependency]) {
115
115
  return dependencies[dependency]
116
116
  }
117
117
 
118
- const matchedDependency = Object.keys(dependencies).find(dep => dep.match(dependency))
118
+ const matchedDependency = Object.keys(dependencies).find((dep) => dep.match(dependency))
119
119
 
120
120
  return matchedDependency ? dependencies[matchedDependency] : undefined
121
121
  }
@@ -102,8 +102,13 @@ export class PluginManager {
102
102
  this.config = config
103
103
  this.logger = options.logger
104
104
  this.queue = new PQueue({ concurrency: 1 })
105
- this.fileManager = new FileManager({ task: options.task, queue: this.queue })
106
- this.#promiseManager = new PromiseManager({ nullCheck: (state: SafeParseResult<'resolveName'> | null) => !!state?.result })
105
+ this.fileManager = new FileManager({
106
+ task: options.task,
107
+ queue: this.queue,
108
+ })
109
+ this.#promiseManager = new PromiseManager({
110
+ nullCheck: (state: SafeParseResult<'resolveName'> | null) => !!state?.result,
111
+ })
107
112
 
108
113
  const plugins = config.plugins || []
109
114
 
@@ -162,9 +167,9 @@ export class PluginManager {
162
167
 
163
168
  if (paths && paths?.length > 1 && this.logger.logLevel === LogLevel.debug) {
164
169
  this.logger.emit('debug', [
165
- `Cannot return a path where the 'pluginKey' ${params.pluginKey ? JSON.stringify(params.pluginKey) : '"'} is not unique enough\n\nPaths: ${
166
- JSON.stringify(paths, undefined, 2)
167
- }\n\nFalling back on the first item.\n`,
170
+ `Cannot return a path where the 'pluginKey' ${
171
+ params.pluginKey ? JSON.stringify(params.pluginKey) : '"'
172
+ } is not unique enough\n\nPaths: ${JSON.stringify(paths, undefined, 2)}\n\nFalling back on the first item.\n`,
168
173
  ])
169
174
  }
170
175
 
@@ -185,9 +190,9 @@ export class PluginManager {
185
190
 
186
191
  if (names && names?.length > 1 && this.logger.logLevel === LogLevel.debug) {
187
192
  this.logger.emit('debug', [
188
- `Cannot return a name where the 'pluginKey' ${params.pluginKey ? JSON.stringify(params.pluginKey) : '"'} is not unique enough\n\nNames: ${
189
- JSON.stringify(names, undefined, 2)
190
- }\n\nFalling back on the first item.\n`,
193
+ `Cannot return a name where the 'pluginKey' ${
194
+ params.pluginKey ? JSON.stringify(params.pluginKey) : '"'
195
+ } is not unique enough\n\nNames: ${JSON.stringify(names, undefined, 2)}\n\nFalling back on the first item.\n`,
191
196
  ])
192
197
  }
193
198
 
@@ -275,25 +280,25 @@ export class PluginManager {
275
280
  parameters: PluginParameter<H>
276
281
  skipped?: ReadonlySet<Plugin> | null
277
282
  }): Promise<SafeParseResult<H>> {
278
- const promises = this.#getSortedPlugins().filter(plugin => {
279
- return skipped ? skipped.has(plugin) : true
280
- }).map((plugin) => {
281
- return async () => {
282
- const value = await this.#execute<H>({
283
- strategy: 'hookFirst',
284
- hookName,
285
- parameters,
286
- plugin,
287
- })
283
+ const promises = this.#getSortedPlugins()
284
+ .filter((plugin) => {
285
+ return skipped ? skipped.has(plugin) : true
286
+ })
287
+ .map((plugin) => {
288
+ return async () => {
289
+ const value = await this.#execute<H>({
290
+ strategy: 'hookFirst',
291
+ hookName,
292
+ parameters,
293
+ plugin,
294
+ })
288
295
 
289
- return Promise.resolve(
290
- {
296
+ return Promise.resolve({
291
297
  plugin,
292
298
  result: value,
293
- } as SafeParseResult<H>,
294
- )
295
- }
296
- })
299
+ } as SafeParseResult<H>)
300
+ }
301
+ })
297
302
 
298
303
  return this.#promiseManager.run('first', promises)
299
304
  }
@@ -313,7 +318,7 @@ export class PluginManager {
313
318
  let parseResult: SafeParseResult<H> = null as unknown as SafeParseResult<H>
314
319
 
315
320
  for (const plugin of this.#getSortedPlugins()) {
316
- if (skipped && skipped.has(plugin)) {
321
+ if (skipped?.has(plugin)) {
317
322
  continue
318
323
  }
319
324
 
@@ -345,19 +350,24 @@ export class PluginManager {
345
350
  parameters?: Parameters<RequiredPluginLifecycle[H]> | undefined
346
351
  }): Promise<Awaited<TOuput>[]> {
347
352
  const promises = this.#getSortedPlugins().map((plugin) => {
348
- return () => this.#execute({ strategy: 'hookParallel', hookName, parameters, plugin }) as Promise<TOuput>
353
+ return () =>
354
+ this.#execute({
355
+ strategy: 'hookParallel',
356
+ hookName,
357
+ parameters,
358
+ plugin,
359
+ }) as Promise<TOuput>
349
360
  })
350
361
 
351
362
  const results = await this.#promiseManager.run('parallel', promises)
352
363
 
353
- results
354
- .forEach((result, index) => {
355
- if (isPromiseRejectedResult<Error>(result)) {
356
- const plugin = this.#getSortedPlugins()[index]
364
+ results.forEach((result, index) => {
365
+ if (isPromiseRejectedResult<Error>(result)) {
366
+ const plugin = this.#getSortedPlugins()[index]
357
367
 
358
- this.#catcher<H>(result.reason, plugin, hookName)
359
- }
360
- })
368
+ this.#catcher<H>(result.reason, plugin, hookName)
369
+ }
370
+ })
361
371
 
362
372
  return results.filter((result) => result.status === 'fulfilled').map((result) => (result as PromiseFulfilledResult<Awaited<TOuput>>).value)
363
373
  }
@@ -426,25 +436,27 @@ export class PluginManager {
426
436
  }
427
437
  // TODO add test case for sorting with pre/post
428
438
 
429
- return plugins.map(plugin => {
430
- if (plugin.pre) {
431
- const isValid = plugin.pre.every(pluginName => plugins.find(pluginToFind => pluginToFind.name === pluginName))
439
+ return plugins
440
+ .map((plugin) => {
441
+ if (plugin.pre) {
442
+ const isValid = plugin.pre.every((pluginName) => plugins.find((pluginToFind) => pluginToFind.name === pluginName))
432
443
 
433
- if (!isValid) {
434
- throw new ValidationPluginError(`This plugin has a pre set that is not valid(${JSON.stringify(plugin.pre, undefined, 2)})`)
444
+ if (!isValid) {
445
+ throw new ValidationPluginError(`This plugin has a pre set that is not valid(${JSON.stringify(plugin.pre, undefined, 2)})`)
446
+ }
435
447
  }
436
- }
437
448
 
438
- return plugin
439
- }).sort((a, b) => {
440
- if (b.pre?.includes(a.name)) {
441
- return 1
442
- }
443
- if (b.post?.includes(a.name)) {
444
- return -1
445
- }
446
- return 0
447
- })
449
+ return plugin
450
+ })
451
+ .sort((a, b) => {
452
+ if (b.pre?.includes(a.name)) {
453
+ return 1
454
+ }
455
+ if (b.post?.includes(a.name)) {
456
+ return -1
457
+ }
458
+ return 0
459
+ })
448
460
  }
449
461
 
450
462
  getPluginsByKey(hookName: keyof PluginLifecycle, pluginKey: Plugin['key']): Plugin[] {
@@ -652,9 +664,7 @@ export class PluginManager {
652
664
  T1 extends PluginFactoryOptions,
653
665
  T2 extends PluginFactoryOptions = never,
654
666
  T3 extends PluginFactoryOptions = never,
655
- TOutput = T3 extends never ? T2 extends never ? [T1: Plugin<T1>]
656
- : [T1: Plugin<T1>, T2: Plugin<T2>]
657
- : [T1: Plugin<T1>, T2: Plugin<T2>, T3: Plugin<T3>],
667
+ TOutput = T3 extends never ? (T2 extends never ? [T1: Plugin<T1>] : [T1: Plugin<T1>, T2: Plugin<T2>]) : [T1: Plugin<T1>, T2: Plugin<T2>, T3: Plugin<T3>],
658
668
  >(plugins: Array<Plugin>, dependedPluginNames: string | string[]): TOutput {
659
669
  let pluginNames: string[] = []
660
670
  if (typeof dependedPluginNames === 'string') {