@kubb/core 1.1.8 → 1.1.10

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.cjs CHANGED
@@ -2,9 +2,8 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var module$1 = require('module');
6
5
  var crypto = require('crypto');
7
- var fs = require('fs');
6
+ var fs = require('fs-extra');
8
7
  var pathParser2 = require('path');
9
8
  var changeCase = require('change-case');
10
9
  var rimraf = require('rimraf');
@@ -14,10 +13,11 @@ var tsCodegen = require('@kubb/ts-codegen');
14
13
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
15
14
 
16
15
  var crypto__default = /*#__PURE__*/_interopDefault(crypto);
16
+ var fs__default = /*#__PURE__*/_interopDefault(fs);
17
17
  var pathParser2__default = /*#__PURE__*/_interopDefault(pathParser2);
18
18
  var dirTree__default = /*#__PURE__*/_interopDefault(dirTree);
19
19
 
20
- module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (document.currentScript && document.currentScript.src || new URL('out.js', document.baseURI).href)));
20
+ // src/managers/fileManager/FileManager.ts
21
21
 
22
22
  // src/utils/isPromise.ts
23
23
  function isPromise(result) {
@@ -25,13 +25,13 @@ function isPromise(result) {
25
25
  }
26
26
  async function safeWriteFileToPath(path, data) {
27
27
  const passedPath = pathParser2__default.default.dirname(pathParser2__default.default.resolve(path));
28
- await fs.promises.mkdir(passedPath, { recursive: true });
29
- return fs.promises.writeFile(pathParser2__default.default.resolve(path), data, { encoding: "utf-8" });
28
+ await fs__default.default.mkdir(passedPath, { recursive: true });
29
+ return fs__default.default.writeFile(pathParser2__default.default.resolve(path), data, { encoding: "utf-8" });
30
30
  }
31
31
  async function write(data, path) {
32
32
  try {
33
- await fs.promises.stat(path);
34
- const oldContent = await fs.promises.readFile(path, { encoding: "utf-8" });
33
+ await fs__default.default.stat(path);
34
+ const oldContent = await fs__default.default.readFile(path, { encoding: "utf-8" });
35
35
  if (oldContent?.toString() === data) {
36
36
  return;
37
37
  }
@@ -49,15 +49,17 @@ function createPluginCache(cache) {
49
49
  },
50
50
  get(id) {
51
51
  const item = cache[id];
52
- if (!item)
52
+ if (!item) {
53
53
  return null;
54
+ }
54
55
  item[0] = 0;
55
56
  return item[1];
56
57
  },
57
58
  has(id) {
58
59
  const item = cache[id];
59
- if (!item)
60
+ if (!item) {
60
61
  return false;
62
+ }
61
63
  item[0] = 0;
62
64
  return true;
63
65
  },
@@ -67,15 +69,15 @@ function createPluginCache(cache) {
67
69
  };
68
70
  }
69
71
  function slash(path, platform = "linux") {
70
- const isExtendedLengthPath = /^\\\\\?\\/.test(path);
71
- if (isExtendedLengthPath || platform === "linux" || platform === "mac") {
72
- return path.replace("../", "").trimEnd();
72
+ const isWindowsPath = /^\\\\\?\\/.test(path);
73
+ if (["linux", "mac"].includes(platform) && !isWindowsPath) {
74
+ return path.replaceAll(/\\/g, "/").replace("../", "").trimEnd();
73
75
  }
74
- return path.replace(/\\/g, "/").replace("../", "").trimEnd();
76
+ return path.replaceAll(/\\/g, "/").replace("../", "").trimEnd();
75
77
  }
76
78
  function getRelativePath(rootDir, filePath, platform = "linux") {
77
79
  if (!rootDir || !filePath) {
78
- throw new Error(`Root and file should be filled in when retrieving the relativePath, ${rootDir} ${filePath}`);
80
+ throw new Error(`Root and file should be filled in when retrieving the relativePath, ${rootDir || ""} ${filePath || ""}`);
79
81
  }
80
82
  const relativePath = pathParser2__default.default.relative(rootDir, filePath);
81
83
  const path = slash(relativePath, platform);
@@ -91,7 +93,7 @@ function getPathMode(path) {
91
93
  return pathParser2__default.default.extname(path) ? "file" : "directory";
92
94
  }
93
95
  async function read(path) {
94
- return fs.promises.readFile(path, { encoding: "utf8" });
96
+ return fs__default.default.readFile(path, { encoding: "utf8" });
95
97
  }
96
98
 
97
99
  // src/utils/isURL.ts
@@ -179,9 +181,10 @@ var Queue = class {
179
181
  this.work();
180
182
  });
181
183
  }
182
- async work() {
183
- if (this.workerCount >= this.maxParallel)
184
+ work() {
185
+ if (this.workerCount >= this.maxParallel) {
184
186
  return;
187
+ }
185
188
  this.workerCount++;
186
189
  let entry;
187
190
  while (entry = this.queue.shift()) {
@@ -651,10 +654,12 @@ var definePlugin = createPlugin((options) => {
651
654
  async addFile(...files) {
652
655
  const trace = getStackTrace();
653
656
  const plugins = options.config.plugins?.filter((plugin) => trace[1].getFileName()?.includes(plugin.name)).sort((a, b) => {
654
- if (a.name.length < b.name.length)
657
+ if (a.name.length < b.name.length) {
655
658
  return 1;
656
- if (a.name.length > b.name.length)
659
+ }
660
+ if (a.name.length > b.name.length) {
657
661
  return -1;
662
+ }
658
663
  return 0;
659
664
  });
660
665
  const pluginName = plugins?.[0].name;
@@ -826,8 +831,9 @@ var PluginManager = class {
826
831
  }) {
827
832
  let promise = Promise.resolve(null);
828
833
  for (const plugin of this.getSortedPlugins(hookName)) {
829
- if (skipped && skipped.has(plugin))
834
+ if (skipped && skipped.has(plugin)) {
830
835
  continue;
836
+ }
831
837
  promise = promise.then(async (parseResult) => {
832
838
  if (parseResult?.result != null) {
833
839
  return parseResult;
@@ -857,8 +863,9 @@ var PluginManager = class {
857
863
  }) {
858
864
  let parseResult = null;
859
865
  for (const plugin of this.getSortedPlugins(hookName)) {
860
- if (skipped && skipped.has(plugin))
866
+ if (skipped && skipped.has(plugin)) {
861
867
  continue;
868
+ }
862
869
  parseResult = {
863
870
  result: this.executeSync({
864
871
  strategy: "hookFirst",
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
  },
@@ -57,15 +59,15 @@ function createPluginCache(cache) {
57
59
  };
58
60
  }
59
61
  function slash(path, platform = "linux") {
60
- const isExtendedLengthPath = /^\\\\\?\\/.test(path);
61
- if (isExtendedLengthPath || platform === "linux" || platform === "mac") {
62
- return path.replace("../", "").trimEnd();
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, "/").replace("../", "").trimEnd();
66
+ return path.replaceAll(/\\/g, "/").replace("../", "").trimEnd();
65
67
  }
66
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
73
  const path = slash(relativePath, platform);
@@ -81,7 +83,7 @@ function getPathMode(path) {
81
83
  return pathParser2.extname(path) ? "file" : "directory";
82
84
  }
83
85
  async function read(path) {
84
- return promises.readFile(path, { encoding: "utf8" });
86
+ return fs.readFile(path, { encoding: "utf8" });
85
87
  }
86
88
 
87
89
  // src/utils/isURL.ts
@@ -169,9 +171,10 @@ var Queue = class {
169
171
  this.work();
170
172
  });
171
173
  }
172
- async work() {
173
- if (this.workerCount >= this.maxParallel)
174
+ work() {
175
+ if (this.workerCount >= this.maxParallel) {
174
176
  return;
177
+ }
175
178
  this.workerCount++;
176
179
  let entry;
177
180
  while (entry = this.queue.shift()) {
@@ -641,10 +644,12 @@ var definePlugin = createPlugin((options) => {
641
644
  async addFile(...files) {
642
645
  const trace = getStackTrace();
643
646
  const plugins = options.config.plugins?.filter((plugin) => trace[1].getFileName()?.includes(plugin.name)).sort((a, b) => {
644
- if (a.name.length < b.name.length)
647
+ if (a.name.length < b.name.length) {
645
648
  return 1;
646
- if (a.name.length > b.name.length)
649
+ }
650
+ if (a.name.length > b.name.length) {
647
651
  return -1;
652
+ }
648
653
  return 0;
649
654
  });
650
655
  const pluginName = plugins?.[0].name;
@@ -816,8 +821,9 @@ var PluginManager = class {
816
821
  }) {
817
822
  let promise = Promise.resolve(null);
818
823
  for (const plugin of this.getSortedPlugins(hookName)) {
819
- if (skipped && skipped.has(plugin))
824
+ if (skipped && skipped.has(plugin)) {
820
825
  continue;
826
+ }
821
827
  promise = promise.then(async (parseResult) => {
822
828
  if (parseResult?.result != null) {
823
829
  return parseResult;
@@ -847,8 +853,9 @@ var PluginManager = class {
847
853
  }) {
848
854
  let parseResult = null;
849
855
  for (const plugin of this.getSortedPlugins(hookName)) {
850
- if (skipped && skipped.has(plugin))
856
+ if (skipped && skipped.has(plugin)) {
851
857
  continue;
858
+ }
852
859
  parseResult = {
853
860
  result: this.executeSync({
854
861
  strategy: "hookFirst",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/core",
3
- "version": "1.1.8",
3
+ "version": "1.1.10",
4
4
  "description": "Generator core",
5
5
  "keywords": [
6
6
  "typescript",
@@ -42,17 +42,20 @@
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.8"
48
+ "@kubb/ts-codegen": "1.1.10"
47
49
  },
48
50
  "devDependencies": {
51
+ "@types/fs-extra": "^11.0.1",
49
52
  "eslint": "^8.42.0",
50
53
  "ora": "^6.3.1",
51
54
  "tsup": "^6.7.0",
52
55
  "typescript": "^5.1.3",
53
- "@kubb/eslint-config": "0.1.0",
54
- "@kubb/tsup-config": "0.1.0",
55
- "@kubb/typescript-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"
56
59
  },
57
60
  "packageManager": "pnpm@8.3.0",
58
61
  "engines": {
@@ -66,8 +69,8 @@
66
69
  "scripts": {
67
70
  "build": "tsup",
68
71
  "clean": "rimraf ./dist",
69
- "lint": "eslint \"**/*.{ts,tsx}\"",
70
- "lint-fix": "eslint \"**/*.{ts,tsx}\" --quiet --fix",
72
+ "lint": "ESLINT_USE_FLAT_CONFIG=true eslint \"**/*.{ts,tsx}\"",
73
+ "lint-fix": "bun run lint --quiet --fix",
71
74
  "release": "pnpm publish --no-git-check",
72
75
  "start": "tsup --watch",
73
76
  "test": "vitest --passWithNoTests",
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
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'
@@ -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
@@ -1,6 +1,3 @@
1
- /* eslint-disable no-param-reassign */
2
- /* eslint-disable consistent-return */
3
-
4
1
  export interface Cache<T extends object = object> {
5
2
  delete(id: keyof T): boolean
6
3
  get(id: keyof T): T[keyof T] | null
@@ -15,13 +12,17 @@ export function createPluginCache<T extends Record<string, [number, unknown]>>(c
15
12
  },
16
13
  get(id) {
17
14
  const item = cache[id]
18
- if (!item) return null
15
+ if (!item) {
16
+ return null
17
+ }
19
18
  item[0] = 0
20
19
  return item[1] as T[keyof T]
21
20
  },
22
21
  has(id) {
23
22
  const item = cache[id]
24
- if (!item) return false
23
+ if (!item) {
24
+ return false
25
+ }
25
26
  item[0] = 0
26
27
  return true
27
28
  },
@@ -1,4 +1,5 @@
1
- // eslint-disable-next-line @typescript-eslint/ban-types, no-undef
1
+ /* eslint-disable @typescript-eslint/no-unsafe-member-access */
2
+ // eslint-disable-next-line @typescript-eslint/ban-types
2
3
  export function getStackTrace(belowFn?: Function): NodeJS.CallSite[] {
3
4
  const oldLimit = Error.stackTraceLimit
4
5
  Error.stackTraceLimit = Infinity
@@ -15,5 +16,5 @@ export function getStackTrace(belowFn?: Function): NodeJS.CallSite[] {
15
16
  Error.prepareStackTrace = v8Handler
16
17
  Error.stackTraceLimit = oldLimit
17
18
 
18
- return v8StackTrace
19
+ return v8StackTrace as NodeJS.CallSite[]
19
20
  }
@@ -1,4 +1,3 @@
1
- /* eslint-disable no-param-reassign */
2
1
  export function getUniqueName(originalName: string, data: Record<string, number>) {
3
2
  let used = data[originalName] || 0
4
3
  if (used) {
package/src/utils/read.ts CHANGED
@@ -1,21 +1,21 @@
1
- import { promises as fs } from 'node:fs'
2
1
  import pathParser from 'node:path'
2
+ import fs from 'fs-extra'
3
3
 
4
4
  function slash(path: string, platform: 'windows' | 'mac' | 'linux' = 'linux') {
5
- const isExtendedLengthPath = /^\\\\\?\\/.test(path)
5
+ const isWindowsPath = /^\\\\\?\\/.test(path)
6
6
 
7
- if (isExtendedLengthPath || platform === 'linux' || platform === 'mac') {
7
+ if (['linux', 'mac'].includes(platform) && !isWindowsPath) {
8
8
  // linux and mac
9
- return path.replace('../', '').trimEnd()
9
+ return path.replaceAll(/\\/g, '/').replace('../', '').trimEnd()
10
10
  }
11
11
 
12
12
  // windows
13
- return path.replace(/\\/g, '/').replace('../', '').trimEnd()
13
+ return path.replaceAll(/\\/g, '/').replace('../', '').trimEnd()
14
14
  }
15
15
 
16
16
  export function getRelativePath(rootDir?: string | null, filePath?: string | null, platform: 'windows' | 'mac' | 'linux' = 'linux') {
17
17
  if (!rootDir || !filePath) {
18
- throw new Error(`Root and file should be filled in when retrieving the relativePath, ${rootDir} ${filePath}`)
18
+ throw new Error(`Root and file should be filled in when retrieving the relativePath, ${rootDir || ''} ${filePath || ''}`)
19
19
  }
20
20
 
21
21
  const relativePath = pathParser.relative(rootDir, filePath)
@@ -1,5 +1,4 @@
1
- /* eslint-disable consistent-return */
2
- import { promises as fs } from 'node:fs'
1
+ import fs from 'fs-extra'
3
2
  import pathParser from 'node:path'
4
3
 
5
4
  async function safeWriteFileToPath(path: string, data: string) {