@kubb/core 1.1.7 → 1.1.9

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.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { createRequire } from 'module';
2
2
  import crypto from 'node:crypto';
3
- import { promises } from 'node:fs';
3
+ import fs from 'fs-extra';
4
4
  import pathParser2 from 'node:path';
5
5
  import { camelCase, camelCaseTransformMerge } from 'change-case';
6
6
  import { rimraf } from 'rimraf';
@@ -15,13 +15,13 @@ function isPromise(result) {
15
15
  }
16
16
  async function safeWriteFileToPath(path, data) {
17
17
  const passedPath = pathParser2.dirname(pathParser2.resolve(path));
18
- await promises.mkdir(passedPath, { recursive: true });
19
- return promises.writeFile(pathParser2.resolve(path), data, { encoding: "utf-8" });
18
+ await fs.mkdir(passedPath, { recursive: true });
19
+ return fs.writeFile(pathParser2.resolve(path), data, { encoding: "utf-8" });
20
20
  }
21
21
  async function write(data, path) {
22
22
  try {
23
- await promises.stat(path);
24
- const oldContent = await promises.readFile(path, { encoding: "utf-8" });
23
+ await fs.stat(path);
24
+ const oldContent = await fs.readFile(path, { encoding: "utf-8" });
25
25
  if (oldContent?.toString() === data) {
26
26
  return;
27
27
  }
@@ -39,15 +39,17 @@ function createPluginCache(cache) {
39
39
  },
40
40
  get(id) {
41
41
  const item = cache[id];
42
- if (!item)
42
+ if (!item) {
43
43
  return null;
44
+ }
44
45
  item[0] = 0;
45
46
  return item[1];
46
47
  },
47
48
  has(id) {
48
49
  const item = cache[id];
49
- if (!item)
50
+ if (!item) {
50
51
  return false;
52
+ }
51
53
  item[0] = 0;
52
54
  return true;
53
55
  },
@@ -56,19 +58,19 @@ function createPluginCache(cache) {
56
58
  }
57
59
  };
58
60
  }
59
- function slash(path) {
60
- const isExtendedLengthPath = /^\\\\\?\\/.test(path);
61
- if (isExtendedLengthPath) {
62
- return path;
61
+ function slash(path, platform = "linux") {
62
+ const isWindowsPath = /^\\\\\?\\/.test(path);
63
+ if (["linux", "mac"].includes(platform) && !isWindowsPath) {
64
+ return path.replaceAll(/\\/g, "/").replace("../", "").trimEnd();
63
65
  }
64
- return path.replace(/\\/g, "/");
66
+ return path.replaceAll(/\\/g, "/").replace("../", "").trimEnd();
65
67
  }
66
- function getRelativePath(rootDir, filePath) {
68
+ function getRelativePath(rootDir, filePath, platform = "linux") {
67
69
  if (!rootDir || !filePath) {
68
- throw new Error(`Root and file should be filled in when retrieving the relativePath, ${rootDir} ${filePath}`);
70
+ throw new Error(`Root and file should be filled in when retrieving the relativePath, ${rootDir || ""} ${filePath || ""}`);
69
71
  }
70
72
  const relativePath = pathParser2.relative(rootDir, filePath);
71
- const path = slash(relativePath).replace("../", "").trimEnd();
73
+ const path = slash(relativePath, platform);
72
74
  if (path.startsWith("../")) {
73
75
  return path.replace(pathParser2.basename(path), pathParser2.basename(path, pathParser2.extname(filePath)));
74
76
  }
@@ -81,12 +83,7 @@ function getPathMode(path) {
81
83
  return pathParser2.extname(path) ? "file" : "directory";
82
84
  }
83
85
  async function read(path) {
84
- try {
85
- return promises.readFile(path, { encoding: "utf8" });
86
- } catch (err) {
87
- console.error(err);
88
- throw err;
89
- }
86
+ return fs.readFile(path, { encoding: "utf8" });
90
87
  }
91
88
 
92
89
  // src/utils/isURL.ts
@@ -174,9 +171,10 @@ var Queue = class {
174
171
  this.work();
175
172
  });
176
173
  }
177
- async work() {
178
- if (this.workerCount >= this.maxParallel)
174
+ work() {
175
+ if (this.workerCount >= this.maxParallel) {
179
176
  return;
177
+ }
180
178
  this.workerCount++;
181
179
  let entry;
182
180
  while (entry = this.queue.shift()) {
@@ -223,10 +221,13 @@ var TreeNode = class {
223
221
  return child;
224
222
  }
225
223
  find(data) {
224
+ if (!data) {
225
+ return null;
226
+ }
226
227
  if (data === this.data) {
227
228
  return this;
228
229
  }
229
- if (this.children) {
230
+ if (this.children?.length) {
230
231
  for (let i = 0, { length } = this.children, target = null; i < length; i++) {
231
232
  target = this.children[i].find(data);
232
233
  if (target) {
@@ -236,23 +237,23 @@ var TreeNode = class {
236
237
  }
237
238
  return null;
238
239
  }
239
- leaves() {
240
+ get leaves() {
240
241
  if (!this.children || this.children.length === 0) {
241
242
  return [this];
242
243
  }
243
244
  const leaves = [];
244
245
  if (this.children) {
245
246
  for (let i = 0, { length } = this.children; i < length; i++) {
246
- leaves.push.apply(leaves, this.children[i].leaves());
247
+ leaves.push.apply(leaves, this.children[i].leaves);
247
248
  }
248
249
  }
249
250
  return leaves;
250
251
  }
251
- root() {
252
+ get root() {
252
253
  if (!this.parent) {
253
254
  return this;
254
255
  }
255
- return this.parent.root();
256
+ return this.parent.root;
256
257
  }
257
258
  forEach(callback) {
258
259
  if (typeof callback !== "function") {
@@ -267,21 +268,26 @@ var TreeNode = class {
267
268
  return this;
268
269
  }
269
270
  static build(path, options = {}) {
270
- const filteredTree = dirTree(path, { extensions: options?.extensions, exclude: options.exclude });
271
- if (!filteredTree) {
272
- return null;
273
- }
274
- const treeNode = new TreeNode({ name: filteredTree.name, path: filteredTree.path, type: filteredTree.type });
275
- const recurse = (node, item) => {
276
- const subNode = node.addChild({ name: item.name, path: item.path, type: item.type });
277
- if (item.children?.length) {
278
- item.children?.forEach((child) => {
279
- recurse(subNode, child);
280
- });
271
+ try {
272
+ const exclude = Array.isArray(options.exclude) ? options.exclude : [options.exclude].filter(Boolean);
273
+ const filteredTree = dirTree(path, { extensions: options.extensions, exclude: [/node_modules/, ...exclude] });
274
+ if (!filteredTree) {
275
+ return null;
281
276
  }
282
- };
283
- filteredTree.children?.forEach((child) => recurse(treeNode, child));
284
- return treeNode;
277
+ const treeNode = new TreeNode({ name: filteredTree.name, path: filteredTree.path, type: filteredTree.type || getPathMode(filteredTree.path) });
278
+ const recurse = (node, item) => {
279
+ const subNode = node.addChild({ name: item.name, path: item.path, type: item.type || getPathMode(item.path) });
280
+ if (item.children?.length) {
281
+ item.children?.forEach((child) => {
282
+ recurse(subNode, child);
283
+ });
284
+ }
285
+ };
286
+ filteredTree.children?.forEach((child) => recurse(treeNode, child));
287
+ return treeNode;
288
+ } catch (e) {
289
+ throw new Error("Something went wrong with creating index files with the TreehNode class", { cause: e });
290
+ }
285
291
  }
286
292
  };
287
293
 
@@ -394,6 +400,9 @@ function getStackTrace(belowFn) {
394
400
  return v8StackTrace;
395
401
  }
396
402
 
403
+ // src/utils/uniqueId.ts
404
+ var uniqueId = ((counter) => (str = "") => `${str}${++counter}`)(0);
405
+
397
406
  // src/managers/fileManager/FileManager.ts
398
407
  var FileManager = class {
399
408
  cache = /* @__PURE__ */ new Map();
@@ -486,18 +495,18 @@ ${file.source}`,
486
495
  return read(...params);
487
496
  }
488
497
  };
489
- function writeIndexes(root, options) {
498
+ function writeIndexes(root, options = {}) {
490
499
  const tree = TreeNode.build(root, { extensions: /\.ts/, ...options });
491
500
  if (!tree) {
492
- return void 0;
501
+ return null;
493
502
  }
494
- const fileReducer = (files2, item) => {
495
- if (!item.children) {
503
+ const fileReducer = (files2, currentTree) => {
504
+ if (!currentTree.children) {
496
505
  return [];
497
506
  }
498
- if (item.children?.length > 1) {
499
- const path = pathParser2.resolve(item.data.path, "index.ts");
500
- const exports = item.children.map((file) => {
507
+ if (currentTree.children?.length > 1) {
508
+ const path = pathParser2.resolve(currentTree.data.path, "index.ts");
509
+ const exports = currentTree.children.map((file) => {
501
510
  if (!file) {
502
511
  return void 0;
503
512
  }
@@ -514,8 +523,8 @@ function writeIndexes(root, options) {
514
523
  exports
515
524
  });
516
525
  } else {
517
- item.children?.forEach((child) => {
518
- const path = pathParser2.resolve(item.data.path, "index.ts");
526
+ currentTree.children?.forEach((child) => {
527
+ const path = pathParser2.resolve(currentTree.data.path, "index.ts");
519
528
  const importPath = child.data.type === "directory" ? `./${child.data.name}` : `./${child.data.name.replace(/\.[^.]*$/, "")}`;
520
529
  files2.push({
521
530
  path,
@@ -525,7 +534,7 @@ function writeIndexes(root, options) {
525
534
  });
526
535
  });
527
536
  }
528
- item.children.forEach((childItem) => {
537
+ currentTree.children.forEach((childItem) => {
529
538
  fileReducer(files2, childItem);
530
539
  });
531
540
  return files2;
@@ -535,9 +544,6 @@ function writeIndexes(root, options) {
535
544
  }
536
545
  function combineFiles(files) {
537
546
  return files.filter(Boolean).reduce((acc, curr) => {
538
- if (!curr) {
539
- return acc;
540
- }
541
547
  const prevIndex = acc.findIndex((item) => item.path === curr.path);
542
548
  if (prevIndex !== -1) {
543
549
  const prev = acc[prevIndex];
@@ -562,19 +568,19 @@ function getFileSource(file) {
562
568
  const imports = [];
563
569
  const exports = [];
564
570
  file.imports?.forEach((curr) => {
565
- const exists = imports.find((imp) => imp.path === curr.path);
566
- if (!exists) {
571
+ const existingImport = imports.find((imp) => imp.path === curr.path);
572
+ if (!existingImport) {
567
573
  imports.push({
568
574
  ...curr,
569
575
  name: Array.isArray(curr.name) ? [...new Set(curr.name)] : curr.name
570
576
  });
571
577
  }
572
- if (exists && !Array.isArray(exists.name) && exists.name !== curr.name) {
578
+ if (existingImport && !Array.isArray(existingImport.name) && existingImport.name !== curr.name) {
573
579
  imports.push(curr);
574
580
  }
575
- if (exists && Array.isArray(exists.name)) {
581
+ if (existingImport && Array.isArray(existingImport.name)) {
576
582
  if (Array.isArray(curr.name)) {
577
- exists.name = [.../* @__PURE__ */ new Set([...exists.name, ...curr.name])];
583
+ existingImport.name = [.../* @__PURE__ */ new Set([...existingImport.name, ...curr.name])];
578
584
  }
579
585
  }
580
586
  });
@@ -600,7 +606,7 @@ function getFileSource(file) {
600
606
  }, []);
601
607
  const importSource = print(importNodes);
602
608
  const exportNodes = exports.reduce((prev, curr) => {
603
- return [...prev, createExportDeclaration({ name: curr.name, path: curr.path, asAlias: curr.asAlias })];
609
+ return [...prev, createExportDeclaration({ name: curr.name, path: curr.path, isTypeOnly: curr.isTypeOnly, asAlias: curr.asAlias })];
604
610
  }, []);
605
611
  const exportSource = print(exportNodes);
606
612
  if (importSource) {
@@ -638,10 +644,12 @@ var definePlugin = createPlugin((options) => {
638
644
  async addFile(...files) {
639
645
  const trace = getStackTrace();
640
646
  const plugins = options.config.plugins?.filter((plugin) => trace[1].getFileName()?.includes(plugin.name)).sort((a, b) => {
641
- if (a.name.length < b.name.length)
647
+ if (a.name.length < b.name.length) {
642
648
  return 1;
643
- if (a.name.length > b.name.length)
649
+ }
650
+ if (a.name.length > b.name.length) {
644
651
  return -1;
652
+ }
645
653
  return 0;
646
654
  });
647
655
  const pluginName = plugins?.[0].name;
@@ -813,8 +821,9 @@ var PluginManager = class {
813
821
  }) {
814
822
  let promise = Promise.resolve(null);
815
823
  for (const plugin of this.getSortedPlugins(hookName)) {
816
- if (skipped && skipped.has(plugin))
824
+ if (skipped && skipped.has(plugin)) {
817
825
  continue;
826
+ }
818
827
  promise = promise.then(async (parseResult) => {
819
828
  if (parseResult?.result != null) {
820
829
  return parseResult;
@@ -844,8 +853,9 @@ var PluginManager = class {
844
853
  }) {
845
854
  let parseResult = null;
846
855
  for (const plugin of this.getSortedPlugins(hookName)) {
847
- if (skipped && skipped.has(plugin))
856
+ if (skipped && skipped.has(plugin)) {
848
857
  continue;
858
+ }
849
859
  parseResult = {
850
860
  result: this.executeSync({
851
861
  strategy: "hookFirst",
@@ -1071,7 +1081,7 @@ async function build(options) {
1071
1081
  await read(config.input.path);
1072
1082
  }
1073
1083
  } catch (e) {
1074
- throw new Error("Cannot read file defined in `input.path` or set with --input in the CLI of your Kubb config", { cause: e });
1084
+ throw new Error("Cannot read file/URL defined in `input.path` or set with --input in the CLI of your Kubb config", { cause: e });
1075
1085
  }
1076
1086
  if (config.output.clean) {
1077
1087
  await clean(config.output.path);
@@ -1154,4 +1164,4 @@ var SchemaGenerator = class extends Generator {
1154
1164
  // src/index.ts
1155
1165
  var src_default = build;
1156
1166
 
1157
- export { FileManager, Generator, ParallelPluginError, PluginError, PluginManager, Queue, SchemaGenerator, TreeNode, ValidationPluginError, build, clean, combineFiles, createJSDocBlockText, createPlugin, createPluginCache, src_default as default, defineConfig, getEncodedText, getFileSource, getPathMode, getRelativePath, getStackTrace, getUniqueName, hooks, isPromise, isURL, name, nameSorter, objectToParameters, read, renderTemplate, timeout, transformReservedWord, validatePlugins, write, writeIndexes };
1167
+ export { FileManager, Generator, ParallelPluginError, PluginError, PluginManager, Queue, SchemaGenerator, TreeNode, ValidationPluginError, build, clean, combineFiles, createJSDocBlockText, createPlugin, createPluginCache, src_default as default, defineConfig, getEncodedText, getFileSource, getPathMode, getRelativePath, getStackTrace, getUniqueName, hooks, isPromise, isURL, name, nameSorter, objectToParameters, read, renderTemplate, timeout, transformReservedWord, uniqueId, validatePlugins, write, writeIndexes };
package/package.json CHANGED
@@ -1,7 +1,13 @@
1
1
  {
2
2
  "name": "@kubb/core",
3
- "version": "1.1.7",
3
+ "version": "1.1.9",
4
4
  "description": "Generator core",
5
+ "keywords": [
6
+ "typescript",
7
+ "plugins",
8
+ "kubb",
9
+ "codegen"
10
+ ],
5
11
  "repository": {
6
12
  "type": "git",
7
13
  "url": "git://github.com/kubb-project/kubb.git",
@@ -9,17 +15,8 @@
9
15
  },
10
16
  "license": "MIT",
11
17
  "author": "Stijn Van Hulle <stijn@stijnvanhulle.be",
12
- "keywords": [
13
- "typescript",
14
- "plugins",
15
- "kubb",
16
- "codegen"
17
- ],
18
18
  "sideEffects": false,
19
19
  "type": "module",
20
- "main": "dist/index.js",
21
- "module": "dist/index.js",
22
- "types": "./dist/index.d.ts",
23
20
  "exports": {
24
21
  ".": {
25
22
  "types": "./dist/index.d.ts",
@@ -29,6 +26,9 @@
29
26
  },
30
27
  "./package.json": "./package.json"
31
28
  },
29
+ "main": "dist/index.js",
30
+ "module": "dist/index.js",
31
+ "types": "./dist/index.d.ts",
32
32
  "typesVersions": {
33
33
  "*": {}
34
34
  },
@@ -42,33 +42,39 @@
42
42
  "dependencies": {
43
43
  "change-case": "^4.1.2",
44
44
  "directory-tree": "^3.5.1",
45
+ "graceful-fs": "^4.2.11",
46
+ "fs-extra": "^11.1.1",
45
47
  "rimraf": "^5.0.1",
46
- "@kubb/ts-codegen": "1.1.7"
48
+ "@kubb/ts-codegen": "1.1.9"
47
49
  },
48
50
  "devDependencies": {
51
+ "@types/fs-extra": "^11.0.1",
49
52
  "eslint": "^8.42.0",
50
- "tsup": "^6.7.0",
51
53
  "ora": "^6.3.1",
54
+ "tsup": "^6.7.0",
52
55
  "typescript": "^5.1.3",
53
- "@kubb/tsup-config": "0.1.0",
54
- "@kubb/eslint-config": "0.1.0"
56
+ "@kubb/eslint-config": "1.1.8",
57
+ "@kubb/ts-config": "0.1.0",
58
+ "@kubb/tsup-config": "1.1.8"
59
+ },
60
+ "packageManager": "pnpm@8.3.0",
61
+ "engines": {
62
+ "node": ">=18",
63
+ "pnpm": ">=8.3.0"
55
64
  },
56
65
  "publishConfig": {
57
66
  "access": "public",
58
67
  "registry": "https://registry.npmjs.org/"
59
68
  },
60
- "engines": {
61
- "node": ">=18",
62
- "pnpm": ">=8"
63
- },
64
69
  "scripts": {
65
70
  "build": "tsup",
66
- "start": "tsup --watch",
67
- "release": "pnpm publish --no-git-check",
68
- "lint": "eslint \"**/*.{ts,tsx}\"",
71
+ "clean": "rimraf ./dist",
72
+ "lint": "ESLINT_USE_FLAT_CONFIG=true eslint \"**/*.{ts,tsx}\"",
69
73
  "lint-fix": "eslint \"**/*.{ts,tsx}\" --quiet --fix",
74
+ "release": "pnpm publish --no-git-check",
75
+ "start": "tsup --watch",
70
76
  "test": "vitest --passWithNoTests",
71
- "upgrade": "pnpm update",
72
- "typecheck": "tsc -p ./tsconfig.json --noEmit --emitDeclarationOnly false"
77
+ "typecheck": "tsc -p ./tsconfig.json --noEmit --emitDeclarationOnly false",
78
+ "upgrade": "pnpm update"
73
79
  }
74
80
  }
package/src/build.ts CHANGED
@@ -1,4 +1,3 @@
1
- /* eslint-disable no-async-promise-executor */
2
1
  import { getFileSource } from './managers/fileManager/index.ts'
3
2
  import { PluginManager } from './managers/pluginManager/index.ts'
4
3
  import { clean, isURL, read } from './utils/index.ts'
@@ -23,6 +22,7 @@ async function transformReducer(
23
22
  this: PluginContext,
24
23
  _previousCode: string,
25
24
  result: TransformResult | Promise<TransformResult>,
25
+
26
26
  _plugin: KubbPlugin
27
27
  ): Promise<string | null> {
28
28
  return result
@@ -36,7 +36,7 @@ export async function build(options: BuildOptions): Promise<BuildOutput> {
36
36
  await read(config.input.path)
37
37
  }
38
38
  } catch (e: any) {
39
- throw new Error('Cannot read file defined in `input.path` or set with --input in the CLI of your Kubb config', { cause: e })
39
+ throw new Error('Cannot read file/URL defined in `input.path` or set with --input in the CLI of your Kubb config', { cause: e })
40
40
  }
41
41
 
42
42
  if (config.output.clean) {
package/src/index.ts CHANGED
@@ -1,4 +1,3 @@
1
- /* eslint-disable @typescript-eslint/no-empty-interface */
2
1
  import { build } from './build.ts'
3
2
 
4
3
  export * from './config.ts'
@@ -9,21 +9,23 @@ import type { Path } from '../../types.ts'
9
9
  import type { PathMode, TreeNodeOptions } from '../../utils/index.ts'
10
10
  import type { File } from './types.ts'
11
11
 
12
- export function writeIndexes(root: string, options: TreeNodeOptions) {
13
- const tree = TreeNode.build<{ type: PathMode; path: Path; name: string }>(root, { extensions: /\.ts/, ...options })
12
+ type TreeNodeData = { type: PathMode; path: Path; name: string }
13
+
14
+ export function writeIndexes(root: string, options: TreeNodeOptions = {}): File[] | null {
15
+ const tree = TreeNode.build<TreeNodeData>(root, { extensions: /\.ts/, ...options })
14
16
 
15
17
  if (!tree) {
16
- return undefined
18
+ return null
17
19
  }
18
20
 
19
- const fileReducer = (files: File[], item: typeof tree) => {
20
- if (!item.children) {
21
+ const fileReducer = (files: File[], currentTree: typeof tree) => {
22
+ if (!currentTree.children) {
21
23
  return []
22
24
  }
23
25
 
24
- if (item.children?.length > 1) {
25
- const path = pathParser.resolve(item.data.path, 'index.ts')
26
- const exports = item.children
26
+ if (currentTree.children?.length > 1) {
27
+ const path = pathParser.resolve(currentTree.data.path, 'index.ts')
28
+ const exports = currentTree.children
27
29
  .map((file) => {
28
30
  if (!file) {
29
31
  return undefined
@@ -47,8 +49,8 @@ export function writeIndexes(root: string, options: TreeNodeOptions) {
47
49
  exports,
48
50
  })
49
51
  } else {
50
- item.children?.forEach((child) => {
51
- const path = pathParser.resolve(item.data.path, 'index.ts')
52
+ currentTree.children?.forEach((child) => {
53
+ const path = pathParser.resolve(currentTree.data.path, 'index.ts')
52
54
  const importPath = child.data.type === 'directory' ? `./${child.data.name}` : `./${child.data.name.replace(/\.[^.]*$/, '')}`
53
55
 
54
56
  files.push({
@@ -60,7 +62,7 @@ export function writeIndexes(root: string, options: TreeNodeOptions) {
60
62
  })
61
63
  }
62
64
 
63
- item.children.forEach((childItem) => {
65
+ currentTree.children.forEach((childItem) => {
64
66
  fileReducer(files, childItem)
65
67
  })
66
68
 
@@ -72,11 +74,8 @@ export function writeIndexes(root: string, options: TreeNodeOptions) {
72
74
  return files
73
75
  }
74
76
 
75
- export function combineFiles(files: Array<File | null>) {
76
- return files.filter(Boolean).reduce((acc, curr: File | null) => {
77
- if (!curr) {
78
- return acc
79
- }
77
+ export function combineFiles(files: Array<File | null>): File[] {
78
+ return (files.filter(Boolean) as File[]).reduce((acc, curr: File) => {
80
79
  const prevIndex = acc.findIndex((item) => item.path === curr.path)
81
80
 
82
81
  if (prevIndex !== -1) {
@@ -95,7 +94,7 @@ export function combineFiles(files: Array<File | null>) {
95
94
  }, [] as File[])
96
95
  }
97
96
 
98
- export function getFileSource(file: File) {
97
+ export function getFileSource(file: File): string {
99
98
  let { source } = file
100
99
 
101
100
  // TODO make generic check
@@ -106,21 +105,22 @@ export function getFileSource(file: File) {
106
105
  const exports: File['exports'] = []
107
106
 
108
107
  file.imports?.forEach((curr) => {
109
- const exists = imports.find((imp) => imp.path === curr.path)
110
- if (!exists) {
108
+ const existingImport = imports.find((imp) => imp.path === curr.path)
109
+
110
+ if (!existingImport) {
111
111
  imports.push({
112
112
  ...curr,
113
113
  name: Array.isArray(curr.name) ? [...new Set(curr.name)] : curr.name,
114
114
  })
115
115
  }
116
116
 
117
- if (exists && !Array.isArray(exists.name) && exists.name !== curr.name) {
117
+ if (existingImport && !Array.isArray(existingImport.name) && existingImport.name !== curr.name) {
118
118
  imports.push(curr)
119
119
  }
120
120
 
121
- if (exists && Array.isArray(exists.name)) {
121
+ if (existingImport && Array.isArray(existingImport.name)) {
122
122
  if (Array.isArray(curr.name)) {
123
- exists.name = [...new Set([...exists.name, ...curr.name])]
123
+ existingImport.name = [...new Set([...existingImport.name, ...curr.name])]
124
124
  }
125
125
  }
126
126
  })
@@ -151,7 +151,7 @@ export function getFileSource(file: File) {
151
151
  const importSource = print(importNodes)
152
152
 
153
153
  const exportNodes = exports.reduce((prev, curr) => {
154
- return [...prev, createExportDeclaration({ name: curr.name, path: curr.path, asAlias: curr.asAlias })]
154
+ return [...prev, createExportDeclaration({ name: curr.name, path: curr.path, isTypeOnly: curr.isTypeOnly, asAlias: curr.asAlias })]
155
155
  }, [] as ts.ExportDeclaration[])
156
156
  const exportSource = print(exportNodes)
157
157
 
@@ -1,6 +1,4 @@
1
1
  /* eslint-disable @typescript-eslint/ban-types */
2
- /* eslint-disable no-await-in-loop */
3
- /* eslint-disable no-restricted-syntax */
4
2
 
5
3
  import { definePlugin } from '../../plugin.ts'
6
4
  import { isPromise } from '../../utils/isPromise.ts'
@@ -160,10 +158,12 @@ export class PluginManager {
160
158
  parameters: Parameters<PluginLifecycle[H]>
161
159
  skipped?: ReadonlySet<KubbPlugin> | null
162
160
  }): Promise<SafeParseResult<H>> {
163
- let promise: Promise<SafeParseResult<H>> = Promise.resolve(null as any)
161
+ let promise: Promise<SafeParseResult<H>> = Promise.resolve(null as unknown as SafeParseResult<H>)
164
162
 
165
163
  for (const plugin of this.getSortedPlugins(hookName)) {
166
- if (skipped && skipped.has(plugin)) continue
164
+ if (skipped && skipped.has(plugin)) {
165
+ continue
166
+ }
167
167
  promise = promise.then(async (parseResult) => {
168
168
  if (parseResult?.result != null) {
169
169
  return parseResult
@@ -201,7 +201,9 @@ export class PluginManager {
201
201
  let parseResult: SafeParseResult<H> = null as unknown as SafeParseResult<H>
202
202
 
203
203
  for (const plugin of this.getSortedPlugins(hookName)) {
204
- if (skipped && skipped.has(plugin)) continue
204
+ if (skipped && skipped.has(plugin)) {
205
+ continue
206
+ }
205
207
 
206
208
  parseResult = {
207
209
  result: this.executeSync<H>({
@@ -371,10 +373,10 @@ export class PluginManager {
371
373
  }
372
374
 
373
375
  if (typeof hook === 'function') {
374
- const hookResult = (hook as Function).apply(this.core.api, parameters)
376
+ const hookResult = (hook as Function).apply(this.core.api, parameters) as TResult
375
377
 
376
378
  if (isPromise(hookResult)) {
377
- return Promise.resolve(hookResult).then((result) => {
379
+ return Promise.resolve(hookResult).then((result: TResult) => {
378
380
  this.addExecuter({
379
381
  strategy,
380
382
  hookName,
@@ -433,9 +435,8 @@ export class PluginManager {
433
435
  plugin,
434
436
  }
435
437
 
436
- // eslint-disable-next-line @typescript-eslint/ban-types
437
438
  if (typeof hook === 'function') {
438
- const fn = (hook as Function).apply(this.core.api, parameters)
439
+ const fn = (hook as Function).apply(this.core.api, parameters) as ReturnType<ParseResult<H>>
439
440
 
440
441
  this.addExecuter({
441
442
  strategy,
package/src/plugin.ts CHANGED
@@ -56,8 +56,12 @@ export const definePlugin = createPlugin<CorePluginOptions>((options) => {
56
56
  const plugins = options.config.plugins
57
57
  ?.filter((plugin) => trace[1].getFileName()?.includes(plugin.name))
58
58
  .sort((a, b) => {
59
- if (a.name.length < b.name.length) return 1
60
- if (a.name.length > b.name.length) return -1
59
+ if (a.name.length < b.name.length) {
60
+ return 1
61
+ }
62
+ if (a.name.length > b.name.length) {
63
+ return -1
64
+ }
61
65
  return 0
62
66
  })
63
67
  const pluginName = plugins?.[0].name
@@ -1,5 +1,3 @@
1
- /* eslint-disable no-cond-assign */
2
-
3
1
  export type QueueTask<T = unknown> = {
4
2
  (...args: unknown[]): Promise<T>
5
3
  }
@@ -29,8 +27,10 @@ export class Queue {
29
27
  })
30
28
  }
31
29
 
32
- private async work(): Promise<void> {
33
- if (this.workerCount >= this.maxParallel) return
30
+ private work(): void {
31
+ if (this.workerCount >= this.maxParallel) {
32
+ return
33
+ }
34
34
  this.workerCount++
35
35
 
36
36
  let entry: QueueItem | undefined