@kubb/core 4.4.0 → 4.5.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 (74) hide show
  1. package/dist/{URLPath-Bpc_OJmh.js → URLPath-DbWtfVa1.js} +2 -2
  2. package/dist/{URLPath-Bpc_OJmh.js.map → URLPath-DbWtfVa1.js.map} +1 -1
  3. package/dist/{URLPath-Bu6Wkco7.cjs → URLPath-Dir2mxRT.cjs} +2 -2
  4. package/dist/{URLPath-Bu6Wkco7.cjs.map → URLPath-Dir2mxRT.cjs.map} +1 -1
  5. package/dist/hooks.cjs.map +1 -1
  6. package/dist/hooks.d.cts +5 -5
  7. package/dist/hooks.d.ts +5 -5
  8. package/dist/hooks.js.map +1 -1
  9. package/dist/index.cjs +87 -14
  10. package/dist/index.cjs.map +1 -1
  11. package/dist/index.d.cts +8 -8
  12. package/dist/index.d.ts +8 -8
  13. package/dist/index.js +79 -8
  14. package/dist/index.js.map +1 -1
  15. package/dist/{logger-C7JFdYpj.cjs → logger-BIzTtBYJ.cjs} +47 -4
  16. package/dist/logger-BIzTtBYJ.cjs.map +1 -0
  17. package/dist/{logger-DpoDtxfo.d.cts → logger-BjfDkvkn.d.cts} +1 -1
  18. package/dist/{logger-D_jvWsUF.d.ts → logger-BwhJWK-H.d.ts} +1 -1
  19. package/dist/{logger-khF_Lft4.js → logger-Bxe022ug.js} +39 -4
  20. package/dist/logger-Bxe022ug.js.map +1 -0
  21. package/dist/logger.cjs +1 -2
  22. package/dist/logger.d.cts +1 -1
  23. package/dist/logger.d.ts +1 -1
  24. package/dist/logger.js +1 -2
  25. package/dist/{prompt-CgJLZzbf.cjs → prompt-D5DZPtWc.cjs} +1 -1
  26. package/dist/{prompt-CgJLZzbf.cjs.map → prompt-D5DZPtWc.cjs.map} +1 -1
  27. package/dist/{prompt-CIpZjUDy.js → prompt-xM0onfy8.js} +1 -1
  28. package/dist/{prompt-CIpZjUDy.js.map → prompt-xM0onfy8.js.map} +1 -1
  29. package/dist/{transformers-BN5jfIAt.js → transformers-CeNW0G32.js} +1 -1
  30. package/dist/{transformers-BN5jfIAt.js.map → transformers-CeNW0G32.js.map} +1 -1
  31. package/dist/{transformers-BpnIvSiH.cjs → transformers-DWLXDYKb.cjs} +1 -1
  32. package/dist/{transformers-BpnIvSiH.cjs.map → transformers-DWLXDYKb.cjs.map} +1 -1
  33. package/dist/transformers.cjs +1 -1
  34. package/dist/transformers.js +1 -1
  35. package/dist/{types-CCUiy4jG.d.ts → types-CVONMhN_.d.cts} +14 -14
  36. package/dist/{types-EV6-sImo.d.cts → types-CyDeSlGF.d.ts} +14 -14
  37. package/dist/{types-ClXc6HFo.d.ts → types-DCR_QgGt.d.ts} +1 -1
  38. package/dist/{types-C3ea5qNG.d.cts → types-DueAg3XP.d.cts} +1 -1
  39. package/dist/utils.cjs +24 -2
  40. package/dist/utils.cjs.map +1 -1
  41. package/dist/utils.d.cts +9 -2
  42. package/dist/utils.d.ts +9 -2
  43. package/dist/utils.js +22 -5
  44. package/dist/utils.js.map +1 -1
  45. package/package.json +13 -11
  46. package/src/BarrelManager.ts +1 -1
  47. package/src/FileManager.ts +5 -2
  48. package/src/PluginManager.ts +1 -1
  49. package/src/build.ts +2 -1
  50. package/src/config.ts +1 -1
  51. package/src/fs/index.ts +0 -7
  52. package/src/hooks/useMode.ts +1 -1
  53. package/src/types.ts +1 -1
  54. package/src/utils/TreeNode.ts +1 -1
  55. package/src/utils/index.ts +1 -0
  56. package/src/utils/resolveModuleSource.ts +15 -0
  57. package/dist/fs-BIPMUfpW.js +0 -90
  58. package/dist/fs-BIPMUfpW.js.map +0 -1
  59. package/dist/fs-CM7ohZSu.cjs +0 -141
  60. package/dist/fs-CM7ohZSu.cjs.map +0 -1
  61. package/dist/fs.cjs +0 -17
  62. package/dist/fs.d.cts +0 -2
  63. package/dist/fs.d.ts +0 -2
  64. package/dist/fs.js +0 -4
  65. package/dist/index-BmQIxvw0.d.cts +0 -144
  66. package/dist/index-DdO15F70.d.ts +0 -144
  67. package/dist/logger-C7JFdYpj.cjs.map +0 -1
  68. package/dist/logger-khF_Lft4.js.map +0 -1
  69. package/dist/write-BsFt8M9e.cjs +0 -49
  70. package/dist/write-BsFt8M9e.cjs.map +0 -1
  71. package/dist/write-CxO1CDML.js +0 -40
  72. package/dist/write-CxO1CDML.js.map +0 -1
  73. package/src/fs/types.ts +0 -132
  74. package/src/fs/unlink.ts +0 -5
@@ -1,7 +1,6 @@
1
1
  import { extname, join } from 'node:path'
2
+ import type { KubbFile } from '@kubb/fabric-core/types'
2
3
  import { BarrelManager } from './BarrelManager.ts'
3
- import type { KubbFile } from './fs/index.ts'
4
- import { trimExtName } from './fs/index.ts'
5
4
  import type { Logger } from './logger.ts'
6
5
  import type { BarrelType, Plugin } from './types.ts'
7
6
 
@@ -37,6 +36,10 @@ export function getMode(path: string | undefined | null): KubbFile.Mode {
37
36
  return extname(path) ? 'single' : 'split'
38
37
  }
39
38
 
39
+ function trimExtName(text: string): string {
40
+ return text.replace(/\.[^/.]+$/, '')
41
+ }
42
+
40
43
  export async function getBarrelFiles(
41
44
  files: Array<KubbFile.ResolvedFile>,
42
45
  { type, meta = {}, root, output, logger }: AddIndexesProps,
@@ -1,6 +1,6 @@
1
+ import type { KubbFile } from '@kubb/fabric-core/types'
1
2
  import type { Fabric } from '@kubb/react-fabric'
2
3
  import { ValidationPluginError } from './errors.ts'
3
- import type { KubbFile } from './fs/index.ts'
4
4
  import type { Logger } from './logger.ts'
5
5
  import { isPromiseRejectedResult, PromiseManager } from './PromiseManager.ts'
6
6
  import type { PluginCore } from './plugin.ts'
package/src/build.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { join, relative, resolve } from 'node:path'
2
+ import type { KubbFile } from '@kubb/fabric-core/types'
2
3
  import type { Fabric } from '@kubb/react-fabric'
3
4
  import { createFabric } from '@kubb/react-fabric'
4
5
  import { typescriptParser } from '@kubb/react-fabric/parsers'
@@ -6,7 +7,7 @@ import { fsPlugin } from '@kubb/react-fabric/plugins'
6
7
  import pc from 'picocolors'
7
8
  import { isDeepEqual } from 'remeda'
8
9
  import { isInputPath } from './config.ts'
9
- import { clean, exists, getRelativePath, type KubbFile, write } from './fs/index.ts'
10
+ import { clean, exists, getRelativePath, write } from './fs/index.ts'
10
11
  import type { Logger } from './logger.ts'
11
12
  import { createLogger } from './logger.ts'
12
13
  import { PluginManager } from './PluginManager.ts'
package/src/config.ts CHANGED
@@ -1,5 +1,5 @@
1
- import type { PossiblePromise } from './utils/types.ts'
2
1
  import type { InputPath, UserConfig } from './types.ts'
2
+ import type { PossiblePromise } from './utils/types.ts'
3
3
 
4
4
  type Args = {
5
5
  /**
package/src/fs/index.ts CHANGED
@@ -1,12 +1,5 @@
1
1
  export { clean } from './clean.ts'
2
2
  export { exists } from './exists.ts'
3
3
  export { read, readSync } from './read.ts'
4
- export { unlink } from './unlink.ts'
5
4
  export { getRelativePath } from './utils.ts'
6
5
  export { write } from './write.ts'
7
-
8
- export function trimExtName(text: string): string {
9
- return text.replace(/\.[^/.]+$/, '')
10
- }
11
-
12
- export * as KubbFile from './types.ts'
@@ -1,5 +1,5 @@
1
+ import type { KubbFile } from '@kubb/fabric-core/types'
1
2
  import { useApp } from '@kubb/react-fabric'
2
- import type { KubbFile } from '../fs/index.ts'
3
3
 
4
4
  export function useMode(): KubbFile.Mode {
5
5
  const { meta } = useApp<{ mode: KubbFile.Mode }>()
package/src/types.ts CHANGED
@@ -1,5 +1,5 @@
1
+ import type { KubbFile } from '@kubb/fabric-core/types'
1
2
  import type { Fabric, FileManager } from '@kubb/react-fabric'
2
- import type { KubbFile } from './fs/index.ts'
3
3
  import type { Logger } from './logger.ts'
4
4
  import type { PluginManager } from './PluginManager.ts'
5
5
  import type { PossiblePromise } from './utils/types.ts'
@@ -1,5 +1,5 @@
1
+ import type { KubbFile } from '@kubb/fabric-core/types'
1
2
  import { getMode } from '../FileManager.ts'
2
- import type { KubbFile } from '../fs/index.ts'
3
3
 
4
4
  type BarrelData = {
5
5
  file?: KubbFile.File
@@ -7,6 +7,7 @@ export {
7
7
  isPromiseRejectedResult,
8
8
  } from './promise.ts'
9
9
  export { renderTemplate } from './renderTemplate.ts'
10
+ export { resolveModuleSource } from './resolveModuleSource.ts'
10
11
  export { timeout } from './timeout.ts'
11
12
  export type { URLObject } from './URLPath.ts'
12
13
  export { URLPath } from './URLPath.ts'
@@ -0,0 +1,15 @@
1
+ import { readFileSync } from 'node:fs'
2
+ import path from 'node:path'
3
+ import { fileURLToPath } from 'node:url'
4
+ import createJiti from 'jiti'
5
+
6
+ export function resolveModuleSource(pkgName: string) {
7
+ const parentURL = import.meta.url
8
+ const jiti = createJiti(parentURL)
9
+
10
+ const resolved = jiti.esmResolve(pkgName, parentURL)
11
+ const filePath = resolved.startsWith('file:') ? fileURLToPath(resolved) : resolved
12
+ const source = readFileSync(filePath, { encoding: 'utf-8' })
13
+ const ext = path.extname(filePath)
14
+ return { path: filePath, source, ext } as const
15
+ }
@@ -1,90 +0,0 @@
1
- import { normalize, relative } from "node:path";
2
- import fs from "fs-extra";
3
- import { switcher } from "js-runtime";
4
-
5
- //#region src/fs/clean.ts
6
- async function clean(path$1) {
7
- return fs.remove(path$1);
8
- }
9
-
10
- //#endregion
11
- //#region src/fs/exists.ts
12
- const reader$1 = switcher({
13
- node: async (path$1) => {
14
- return fs.pathExists(path$1);
15
- },
16
- bun: async (path$1) => {
17
- return Bun.file(path$1).exists();
18
- }
19
- }, "node");
20
- const syncReader$1 = switcher({
21
- node: (path$1) => {
22
- return fs.pathExistsSync(path$1);
23
- },
24
- bun: () => {
25
- throw new Error("Bun cannot read sync");
26
- }
27
- }, "node");
28
- async function exists(path$1) {
29
- return reader$1(path$1);
30
- }
31
-
32
- //#endregion
33
- //#region src/fs/read.ts
34
- const reader = switcher({
35
- node: async (path$1) => {
36
- return fs.readFile(path$1, { encoding: "utf8" });
37
- },
38
- bun: async (path$1) => {
39
- return Bun.file(path$1).text();
40
- }
41
- }, "node");
42
- const syncReader = switcher({
43
- node: (path$1) => {
44
- return fs.readFileSync(path$1, { encoding: "utf8" });
45
- },
46
- bun: () => {
47
- throw new Error("Bun cannot read sync");
48
- }
49
- }, "node");
50
- async function read(path$1) {
51
- return reader(path$1);
52
- }
53
- function readSync(path$1) {
54
- return syncReader(path$1);
55
- }
56
-
57
- //#endregion
58
- //#region src/fs/unlink.ts
59
- async function unlink(path$1) {
60
- return fs.unlink(path$1);
61
- }
62
-
63
- //#endregion
64
- //#region src/fs/utils.ts
65
- function slash(path$1, platform = "linux") {
66
- const isWindowsPath = /^\\\\\?\\/.test(path$1);
67
- const normalizedPath = normalize(path$1);
68
- if (["linux", "mac"].includes(platform) && !isWindowsPath) return normalizedPath.replaceAll(/\\/g, "/").replace("../", "");
69
- return normalizedPath.replaceAll(/\\/g, "/").replace("../", "");
70
- }
71
- function getRelativePath(rootDir, filePath, platform = "linux") {
72
- if (!rootDir || !filePath) throw new Error(`Root and file should be filled in when retrieving the relativePath, ${rootDir || ""} ${filePath || ""}`);
73
- const slashedPath = slash(relative(rootDir, filePath), platform);
74
- if (slashedPath.startsWith("../")) return slashedPath;
75
- return `./${slashedPath}`;
76
- }
77
-
78
- //#endregion
79
- //#region src/fs/types.ts
80
- var types_exports = {};
81
-
82
- //#endregion
83
- //#region src/fs/index.ts
84
- function trimExtName(text) {
85
- return text.replace(/\.[^/.]+$/, "");
86
- }
87
-
88
- //#endregion
89
- export { read as a, clean as c, unlink as i, types_exports as n, readSync as o, getRelativePath as r, exists as s, trimExtName as t };
90
- //# sourceMappingURL=fs-BIPMUfpW.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"fs-BIPMUfpW.js","names":["path","reader","path","syncReader","path","path","path"],"sources":["../src/fs/clean.ts","../src/fs/exists.ts","../src/fs/read.ts","../src/fs/unlink.ts","../src/fs/utils.ts","../src/fs/types.ts","../src/fs/index.ts"],"sourcesContent":["import fs from 'fs-extra'\n\nexport async function clean(path: string): Promise<void> {\n return fs.remove(path)\n}\n","import fs from 'fs-extra'\nimport { switcher } from 'js-runtime'\n\nconst reader = switcher(\n {\n node: async (path: string) => {\n return fs.pathExists(path)\n },\n bun: async (path: string) => {\n const file = Bun.file(path)\n\n return file.exists()\n },\n },\n 'node',\n)\n\nconst syncReader = switcher(\n {\n node: (path: string) => {\n return fs.pathExistsSync(path)\n },\n bun: () => {\n throw new Error('Bun cannot read sync')\n },\n },\n 'node',\n)\n\nexport async function exists(path: string): Promise<boolean> {\n return reader(path)\n}\n\nexport function existsSync(path: string): boolean {\n return syncReader(path)\n}\n","import fs from 'fs-extra'\nimport { switcher } from 'js-runtime'\n\nconst reader = switcher(\n {\n node: async (path: string) => {\n return fs.readFile(path, { encoding: 'utf8' })\n },\n bun: async (path: string) => {\n const file = Bun.file(path)\n\n return file.text()\n },\n },\n 'node',\n)\n\nconst syncReader = switcher(\n {\n node: (path: string) => {\n return fs.readFileSync(path, { encoding: 'utf8' })\n },\n bun: () => {\n throw new Error('Bun cannot read sync')\n },\n },\n 'node',\n)\n\nexport async function read(path: string): Promise<string> {\n return reader(path)\n}\n\nexport function readSync(path: string): string {\n return syncReader(path)\n}\n","import fs from 'fs-extra'\n\nexport async function unlink(path: string): Promise<void> {\n return fs.unlink(path)\n}\n","import { normalize, relative } from 'node:path'\n\nfunction slash(path: string, platform: 'windows' | 'mac' | 'linux' = 'linux') {\n const isWindowsPath = /^\\\\\\\\\\?\\\\/.test(path)\n const normalizedPath = normalize(path)\n\n if (['linux', 'mac'].includes(platform) && !isWindowsPath) {\n // linux and mac\n return normalizedPath.replaceAll(/\\\\/g, '/').replace('../', '')\n }\n\n // windows\n return normalizedPath.replaceAll(/\\\\/g, '/').replace('../', '')\n}\n\nexport function getRelativePath(rootDir?: string | null, filePath?: string | null, platform: 'windows' | 'mac' | 'linux' = 'linux'): string {\n if (!rootDir || !filePath) {\n throw new Error(`Root and file should be filled in when retrieving the relativePath, ${rootDir || ''} ${filePath || ''}`)\n }\n\n const relativePath = relative(rootDir, filePath)\n\n // On Windows, paths are separated with a \"\\\"\n // However, web browsers use \"/\" no matter the platform\n const slashedPath = slash(relativePath, platform)\n\n if (slashedPath.startsWith('../')) {\n return slashedPath\n }\n\n return `./${slashedPath}`\n}\n","type BasePath<T extends string = string> = `${T}/`\n\nexport type Import = {\n /**\n * Import name to be used\n * @example [\"useState\"]\n * @example \"React\"\n */\n name:\n | string\n | Array<\n | string\n | {\n propertyName: string\n name?: string\n }\n >\n /**\n * Path for the import\n * @example '@kubb/core'\n */\n path: string\n /**\n * Add `type` prefix to the import, this will result in: `import type { Type } from './path'`.\n */\n isTypeOnly?: boolean\n\n isNameSpace?: boolean\n /**\n * When root is set it will get the path with relative getRelativePath(root, path).\n */\n root?: string\n}\n\nexport type Source = {\n name?: string\n value?: string\n isTypeOnly?: boolean\n /**\n * Has const or type 'export'\n * @default false\n */\n isExportable?: boolean\n /**\n * When set, barrel generation will add this\n * @default false\n */\n isIndexable?: boolean\n}\n\nexport type Export = {\n /**\n * Export name to be used.\n * @example [\"useState\"]\n * @example \"React\"\n */\n name?: string | Array<string>\n /**\n * Path for the import.\n * @example '@kubb/core'\n */\n path: string\n /**\n * Add `type` prefix to the export, this will result in: `export type { Type } from './path'`.\n */\n isTypeOnly?: boolean\n /**\n * Make it possible to override the name, this will result in: `export * as aliasName from './path'`.\n */\n asAlias?: boolean\n}\n\nexport type Extname = '.ts' | '.js' | '.tsx' | '.json' | `.${string}`\n\nexport type Mode = 'single' | 'split'\n\n/**\n * Name to be used to dynamicly create the baseName(based on input.path)\n * Based on UNIX basename\n * @link https://nodejs.org/api/path.html#pathbasenamepath-suffix\n */\nexport type BaseName = `${string}.${string}`\n\n/**\n * Path will be full qualified path to a specified file\n */\nexport type Path = string\n\nexport type AdvancedPath<T extends BaseName = BaseName> = `${BasePath}${T}`\n\nexport type OptionalPath = Path | undefined | null\n\nexport type File<TMeta extends object = object> = {\n /**\n * Name to be used to create the path\n * Based on UNIX basename, `${name}.extname`\n * @link https://nodejs.org/api/path.html#pathbasenamepath-suffix\n */\n baseName: BaseName\n /**\n * Path will be full qualified path to a specified file\n */\n path: AdvancedPath<BaseName> | Path\n sources: Array<Source>\n imports?: Array<Import>\n exports?: Array<Export>\n /**\n * Use extra meta, this is getting used to generate the barrel/index files.\n */\n meta?: TMeta\n banner?: string\n footer?: string\n}\n\nexport type ResolvedImport = Import\n\nexport type ResolvedExport = Export\n\nexport type ResolvedFile<TMeta extends object = object> = File<TMeta> & {\n /**\n * @default object-hash\n */\n id: string\n /**\n * Contains the first part of the baseName, generated based on baseName\n * @link https://nodejs.org/api/path.html#pathformatpathobject\n */\n name: string\n extname: Extname\n imports: Array<ResolvedImport>\n exports: Array<ResolvedExport>\n}\n","export { clean } from './clean.ts'\nexport { exists } from './exists.ts'\nexport { read, readSync } from './read.ts'\nexport { unlink } from './unlink.ts'\nexport { getRelativePath } from './utils.ts'\nexport { write } from './write.ts'\n\nexport function trimExtName(text: string): string {\n return text.replace(/\\.[^/.]+$/, '')\n}\n\nexport * as KubbFile from './types.ts'\n"],"mappings":";;;;;AAEA,eAAsB,MAAM,QAA6B;AACvD,QAAO,GAAG,OAAOA,OAAK;;;;;ACAxB,MAAMC,WAAS,SACb;CACE,MAAM,OAAO,WAAiB;AAC5B,SAAO,GAAG,WAAWC,OAAK;;CAE5B,KAAK,OAAO,WAAiB;AAG3B,SAFa,IAAI,KAAKA,OAAK,CAEf,QAAQ;;CAEvB,EACD,OACD;AAED,MAAMC,eAAa,SACjB;CACE,OAAO,WAAiB;AACtB,SAAO,GAAG,eAAeD,OAAK;;CAEhC,WAAW;AACT,QAAM,IAAI,MAAM,uBAAuB;;CAE1C,EACD,OACD;AAED,eAAsB,OAAO,QAAgC;AAC3D,QAAOD,SAAOC,OAAK;;;;;AC3BrB,MAAM,SAAS,SACb;CACE,MAAM,OAAO,WAAiB;AAC5B,SAAO,GAAG,SAASE,QAAM,EAAE,UAAU,QAAQ,CAAC;;CAEhD,KAAK,OAAO,WAAiB;AAG3B,SAFa,IAAI,KAAKA,OAAK,CAEf,MAAM;;CAErB,EACD,OACD;AAED,MAAM,aAAa,SACjB;CACE,OAAO,WAAiB;AACtB,SAAO,GAAG,aAAaA,QAAM,EAAE,UAAU,QAAQ,CAAC;;CAEpD,WAAW;AACT,QAAM,IAAI,MAAM,uBAAuB;;CAE1C,EACD,OACD;AAED,eAAsB,KAAK,QAA+B;AACxD,QAAO,OAAOA,OAAK;;AAGrB,SAAgB,SAAS,QAAsB;AAC7C,QAAO,WAAWA,OAAK;;;;;AChCzB,eAAsB,OAAO,QAA6B;AACxD,QAAO,GAAG,OAAOC,OAAK;;;;;ACDxB,SAAS,MAAM,QAAc,WAAwC,SAAS;CAC5E,MAAM,gBAAgB,YAAY,KAAKC,OAAK;CAC5C,MAAM,iBAAiB,UAAUA,OAAK;AAEtC,KAAI,CAAC,SAAS,MAAM,CAAC,SAAS,SAAS,IAAI,CAAC,cAE1C,QAAO,eAAe,WAAW,OAAO,IAAI,CAAC,QAAQ,OAAO,GAAG;AAIjE,QAAO,eAAe,WAAW,OAAO,IAAI,CAAC,QAAQ,OAAO,GAAG;;AAGjE,SAAgB,gBAAgB,SAAyB,UAA0B,WAAwC,SAAiB;AAC1I,KAAI,CAAC,WAAW,CAAC,SACf,OAAM,IAAI,MAAM,uEAAuE,WAAW,GAAG,GAAG,YAAY,KAAK;CAO3H,MAAM,cAAc,MAJC,SAAS,SAAS,SAAS,EAIR,SAAS;AAEjD,KAAI,YAAY,WAAW,MAAM,CAC/B,QAAO;AAGT,QAAO,KAAK;;;;;;;;;AEvBd,SAAgB,YAAY,MAAsB;AAChD,QAAO,KAAK,QAAQ,aAAa,GAAG"}
@@ -1,141 +0,0 @@
1
- const require_chunk = require('./chunk-CUT6urMc.cjs');
2
- let node_path = require("node:path");
3
- node_path = require_chunk.__toESM(node_path);
4
- let fs_extra = require("fs-extra");
5
- fs_extra = require_chunk.__toESM(fs_extra);
6
- let js_runtime = require("js-runtime");
7
- js_runtime = require_chunk.__toESM(js_runtime);
8
-
9
- //#region src/fs/clean.ts
10
- async function clean(path) {
11
- return fs_extra.default.remove(path);
12
- }
13
-
14
- //#endregion
15
- //#region src/fs/exists.ts
16
- const reader$1 = (0, js_runtime.switcher)({
17
- node: async (path) => {
18
- return fs_extra.default.pathExists(path);
19
- },
20
- bun: async (path) => {
21
- return Bun.file(path).exists();
22
- }
23
- }, "node");
24
- const syncReader$1 = (0, js_runtime.switcher)({
25
- node: (path) => {
26
- return fs_extra.default.pathExistsSync(path);
27
- },
28
- bun: () => {
29
- throw new Error("Bun cannot read sync");
30
- }
31
- }, "node");
32
- async function exists(path) {
33
- return reader$1(path);
34
- }
35
-
36
- //#endregion
37
- //#region src/fs/read.ts
38
- const reader = (0, js_runtime.switcher)({
39
- node: async (path) => {
40
- return fs_extra.default.readFile(path, { encoding: "utf8" });
41
- },
42
- bun: async (path) => {
43
- return Bun.file(path).text();
44
- }
45
- }, "node");
46
- const syncReader = (0, js_runtime.switcher)({
47
- node: (path) => {
48
- return fs_extra.default.readFileSync(path, { encoding: "utf8" });
49
- },
50
- bun: () => {
51
- throw new Error("Bun cannot read sync");
52
- }
53
- }, "node");
54
- async function read(path) {
55
- return reader(path);
56
- }
57
- function readSync(path) {
58
- return syncReader(path);
59
- }
60
-
61
- //#endregion
62
- //#region src/fs/unlink.ts
63
- async function unlink(path) {
64
- return fs_extra.default.unlink(path);
65
- }
66
-
67
- //#endregion
68
- //#region src/fs/utils.ts
69
- function slash(path, platform = "linux") {
70
- const isWindowsPath = /^\\\\\?\\/.test(path);
71
- const normalizedPath = (0, node_path.normalize)(path);
72
- if (["linux", "mac"].includes(platform) && !isWindowsPath) return normalizedPath.replaceAll(/\\/g, "/").replace("../", "");
73
- return normalizedPath.replaceAll(/\\/g, "/").replace("../", "");
74
- }
75
- function getRelativePath(rootDir, filePath, platform = "linux") {
76
- if (!rootDir || !filePath) throw new Error(`Root and file should be filled in when retrieving the relativePath, ${rootDir || ""} ${filePath || ""}`);
77
- const slashedPath = slash((0, node_path.relative)(rootDir, filePath), platform);
78
- if (slashedPath.startsWith("../")) return slashedPath;
79
- return `./${slashedPath}`;
80
- }
81
-
82
- //#endregion
83
- //#region src/fs/types.ts
84
- var types_exports = {};
85
-
86
- //#endregion
87
- //#region src/fs/index.ts
88
- function trimExtName(text) {
89
- return text.replace(/\.[^/.]+$/, "");
90
- }
91
-
92
- //#endregion
93
- Object.defineProperty(exports, 'clean', {
94
- enumerable: true,
95
- get: function () {
96
- return clean;
97
- }
98
- });
99
- Object.defineProperty(exports, 'exists', {
100
- enumerable: true,
101
- get: function () {
102
- return exists;
103
- }
104
- });
105
- Object.defineProperty(exports, 'getRelativePath', {
106
- enumerable: true,
107
- get: function () {
108
- return getRelativePath;
109
- }
110
- });
111
- Object.defineProperty(exports, 'read', {
112
- enumerable: true,
113
- get: function () {
114
- return read;
115
- }
116
- });
117
- Object.defineProperty(exports, 'readSync', {
118
- enumerable: true,
119
- get: function () {
120
- return readSync;
121
- }
122
- });
123
- Object.defineProperty(exports, 'trimExtName', {
124
- enumerable: true,
125
- get: function () {
126
- return trimExtName;
127
- }
128
- });
129
- Object.defineProperty(exports, 'types_exports', {
130
- enumerable: true,
131
- get: function () {
132
- return types_exports;
133
- }
134
- });
135
- Object.defineProperty(exports, 'unlink', {
136
- enumerable: true,
137
- get: function () {
138
- return unlink;
139
- }
140
- });
141
- //# sourceMappingURL=fs-CM7ohZSu.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"fs-CM7ohZSu.cjs","names":["fs","reader","fs","syncReader","fs","fs"],"sources":["../src/fs/clean.ts","../src/fs/exists.ts","../src/fs/read.ts","../src/fs/unlink.ts","../src/fs/utils.ts","../src/fs/types.ts","../src/fs/index.ts"],"sourcesContent":["import fs from 'fs-extra'\n\nexport async function clean(path: string): Promise<void> {\n return fs.remove(path)\n}\n","import fs from 'fs-extra'\nimport { switcher } from 'js-runtime'\n\nconst reader = switcher(\n {\n node: async (path: string) => {\n return fs.pathExists(path)\n },\n bun: async (path: string) => {\n const file = Bun.file(path)\n\n return file.exists()\n },\n },\n 'node',\n)\n\nconst syncReader = switcher(\n {\n node: (path: string) => {\n return fs.pathExistsSync(path)\n },\n bun: () => {\n throw new Error('Bun cannot read sync')\n },\n },\n 'node',\n)\n\nexport async function exists(path: string): Promise<boolean> {\n return reader(path)\n}\n\nexport function existsSync(path: string): boolean {\n return syncReader(path)\n}\n","import fs from 'fs-extra'\nimport { switcher } from 'js-runtime'\n\nconst reader = switcher(\n {\n node: async (path: string) => {\n return fs.readFile(path, { encoding: 'utf8' })\n },\n bun: async (path: string) => {\n const file = Bun.file(path)\n\n return file.text()\n },\n },\n 'node',\n)\n\nconst syncReader = switcher(\n {\n node: (path: string) => {\n return fs.readFileSync(path, { encoding: 'utf8' })\n },\n bun: () => {\n throw new Error('Bun cannot read sync')\n },\n },\n 'node',\n)\n\nexport async function read(path: string): Promise<string> {\n return reader(path)\n}\n\nexport function readSync(path: string): string {\n return syncReader(path)\n}\n","import fs from 'fs-extra'\n\nexport async function unlink(path: string): Promise<void> {\n return fs.unlink(path)\n}\n","import { normalize, relative } from 'node:path'\n\nfunction slash(path: string, platform: 'windows' | 'mac' | 'linux' = 'linux') {\n const isWindowsPath = /^\\\\\\\\\\?\\\\/.test(path)\n const normalizedPath = normalize(path)\n\n if (['linux', 'mac'].includes(platform) && !isWindowsPath) {\n // linux and mac\n return normalizedPath.replaceAll(/\\\\/g, '/').replace('../', '')\n }\n\n // windows\n return normalizedPath.replaceAll(/\\\\/g, '/').replace('../', '')\n}\n\nexport function getRelativePath(rootDir?: string | null, filePath?: string | null, platform: 'windows' | 'mac' | 'linux' = 'linux'): string {\n if (!rootDir || !filePath) {\n throw new Error(`Root and file should be filled in when retrieving the relativePath, ${rootDir || ''} ${filePath || ''}`)\n }\n\n const relativePath = relative(rootDir, filePath)\n\n // On Windows, paths are separated with a \"\\\"\n // However, web browsers use \"/\" no matter the platform\n const slashedPath = slash(relativePath, platform)\n\n if (slashedPath.startsWith('../')) {\n return slashedPath\n }\n\n return `./${slashedPath}`\n}\n","type BasePath<T extends string = string> = `${T}/`\n\nexport type Import = {\n /**\n * Import name to be used\n * @example [\"useState\"]\n * @example \"React\"\n */\n name:\n | string\n | Array<\n | string\n | {\n propertyName: string\n name?: string\n }\n >\n /**\n * Path for the import\n * @example '@kubb/core'\n */\n path: string\n /**\n * Add `type` prefix to the import, this will result in: `import type { Type } from './path'`.\n */\n isTypeOnly?: boolean\n\n isNameSpace?: boolean\n /**\n * When root is set it will get the path with relative getRelativePath(root, path).\n */\n root?: string\n}\n\nexport type Source = {\n name?: string\n value?: string\n isTypeOnly?: boolean\n /**\n * Has const or type 'export'\n * @default false\n */\n isExportable?: boolean\n /**\n * When set, barrel generation will add this\n * @default false\n */\n isIndexable?: boolean\n}\n\nexport type Export = {\n /**\n * Export name to be used.\n * @example [\"useState\"]\n * @example \"React\"\n */\n name?: string | Array<string>\n /**\n * Path for the import.\n * @example '@kubb/core'\n */\n path: string\n /**\n * Add `type` prefix to the export, this will result in: `export type { Type } from './path'`.\n */\n isTypeOnly?: boolean\n /**\n * Make it possible to override the name, this will result in: `export * as aliasName from './path'`.\n */\n asAlias?: boolean\n}\n\nexport type Extname = '.ts' | '.js' | '.tsx' | '.json' | `.${string}`\n\nexport type Mode = 'single' | 'split'\n\n/**\n * Name to be used to dynamicly create the baseName(based on input.path)\n * Based on UNIX basename\n * @link https://nodejs.org/api/path.html#pathbasenamepath-suffix\n */\nexport type BaseName = `${string}.${string}`\n\n/**\n * Path will be full qualified path to a specified file\n */\nexport type Path = string\n\nexport type AdvancedPath<T extends BaseName = BaseName> = `${BasePath}${T}`\n\nexport type OptionalPath = Path | undefined | null\n\nexport type File<TMeta extends object = object> = {\n /**\n * Name to be used to create the path\n * Based on UNIX basename, `${name}.extname`\n * @link https://nodejs.org/api/path.html#pathbasenamepath-suffix\n */\n baseName: BaseName\n /**\n * Path will be full qualified path to a specified file\n */\n path: AdvancedPath<BaseName> | Path\n sources: Array<Source>\n imports?: Array<Import>\n exports?: Array<Export>\n /**\n * Use extra meta, this is getting used to generate the barrel/index files.\n */\n meta?: TMeta\n banner?: string\n footer?: string\n}\n\nexport type ResolvedImport = Import\n\nexport type ResolvedExport = Export\n\nexport type ResolvedFile<TMeta extends object = object> = File<TMeta> & {\n /**\n * @default object-hash\n */\n id: string\n /**\n * Contains the first part of the baseName, generated based on baseName\n * @link https://nodejs.org/api/path.html#pathformatpathobject\n */\n name: string\n extname: Extname\n imports: Array<ResolvedImport>\n exports: Array<ResolvedExport>\n}\n","export { clean } from './clean.ts'\nexport { exists } from './exists.ts'\nexport { read, readSync } from './read.ts'\nexport { unlink } from './unlink.ts'\nexport { getRelativePath } from './utils.ts'\nexport { write } from './write.ts'\n\nexport function trimExtName(text: string): string {\n return text.replace(/\\.[^/.]+$/, '')\n}\n\nexport * as KubbFile from './types.ts'\n"],"mappings":";;;;;;;;;AAEA,eAAsB,MAAM,MAA6B;AACvD,QAAOA,iBAAG,OAAO,KAAK;;;;;ACAxB,MAAMC,oCACJ;CACE,MAAM,OAAO,SAAiB;AAC5B,SAAOC,iBAAG,WAAW,KAAK;;CAE5B,KAAK,OAAO,SAAiB;AAG3B,SAFa,IAAI,KAAK,KAAK,CAEf,QAAQ;;CAEvB,EACD,OACD;AAED,MAAMC,wCACJ;CACE,OAAO,SAAiB;AACtB,SAAOD,iBAAG,eAAe,KAAK;;CAEhC,WAAW;AACT,QAAM,IAAI,MAAM,uBAAuB;;CAE1C,EACD,OACD;AAED,eAAsB,OAAO,MAAgC;AAC3D,QAAOD,SAAO,KAAK;;;;;AC3BrB,MAAM,kCACJ;CACE,MAAM,OAAO,SAAiB;AAC5B,SAAOG,iBAAG,SAAS,MAAM,EAAE,UAAU,QAAQ,CAAC;;CAEhD,KAAK,OAAO,SAAiB;AAG3B,SAFa,IAAI,KAAK,KAAK,CAEf,MAAM;;CAErB,EACD,OACD;AAED,MAAM,sCACJ;CACE,OAAO,SAAiB;AACtB,SAAOA,iBAAG,aAAa,MAAM,EAAE,UAAU,QAAQ,CAAC;;CAEpD,WAAW;AACT,QAAM,IAAI,MAAM,uBAAuB;;CAE1C,EACD,OACD;AAED,eAAsB,KAAK,MAA+B;AACxD,QAAO,OAAO,KAAK;;AAGrB,SAAgB,SAAS,MAAsB;AAC7C,QAAO,WAAW,KAAK;;;;;AChCzB,eAAsB,OAAO,MAA6B;AACxD,QAAOC,iBAAG,OAAO,KAAK;;;;;ACDxB,SAAS,MAAM,MAAc,WAAwC,SAAS;CAC5E,MAAM,gBAAgB,YAAY,KAAK,KAAK;CAC5C,MAAM,0CAA2B,KAAK;AAEtC,KAAI,CAAC,SAAS,MAAM,CAAC,SAAS,SAAS,IAAI,CAAC,cAE1C,QAAO,eAAe,WAAW,OAAO,IAAI,CAAC,QAAQ,OAAO,GAAG;AAIjE,QAAO,eAAe,WAAW,OAAO,IAAI,CAAC,QAAQ,OAAO,GAAG;;AAGjE,SAAgB,gBAAgB,SAAyB,UAA0B,WAAwC,SAAiB;AAC1I,KAAI,CAAC,WAAW,CAAC,SACf,OAAM,IAAI,MAAM,uEAAuE,WAAW,GAAG,GAAG,YAAY,KAAK;CAO3H,MAAM,cAAc,8BAJU,SAAS,SAAS,EAIR,SAAS;AAEjD,KAAI,YAAY,WAAW,MAAM,CAC/B,QAAO;AAGT,QAAO,KAAK;;;;;;;;;AEvBd,SAAgB,YAAY,MAAsB;AAChD,QAAO,KAAK,QAAQ,aAAa,GAAG"}
package/dist/fs.cjs DELETED
@@ -1,17 +0,0 @@
1
- const require_fs = require('./fs-CM7ohZSu.cjs');
2
- const require_write = require('./write-BsFt8M9e.cjs');
3
-
4
- Object.defineProperty(exports, 'KubbFile', {
5
- enumerable: true,
6
- get: function () {
7
- return require_fs.types_exports;
8
- }
9
- });
10
- exports.clean = require_fs.clean;
11
- exports.exists = require_fs.exists;
12
- exports.getRelativePath = require_fs.getRelativePath;
13
- exports.read = require_fs.read;
14
- exports.readSync = require_fs.readSync;
15
- exports.trimExtName = require_fs.trimExtName;
16
- exports.unlink = require_fs.unlink;
17
- exports.write = require_write.write;
package/dist/fs.d.cts DELETED
@@ -1,2 +0,0 @@
1
- import { c as types_d_exports, d as unlink, f as read, h as clean, l as write, m as exists, p as readSync, t as trimExtName, u as getRelativePath } from "./index-BmQIxvw0.cjs";
2
- export { types_d_exports as KubbFile, clean, exists, getRelativePath, read, readSync, trimExtName, unlink, write };
package/dist/fs.d.ts DELETED
@@ -1,2 +0,0 @@
1
- import { c as types_d_exports, d as unlink, f as read, h as clean, l as write, m as exists, p as readSync, t as trimExtName, u as getRelativePath } from "./index-DdO15F70.js";
2
- export { types_d_exports as KubbFile, clean, exists, getRelativePath, read, readSync, trimExtName, unlink, write };
package/dist/fs.js DELETED
@@ -1,4 +0,0 @@
1
- import { a as read, c as clean, i as unlink, n as types_exports, o as readSync, r as getRelativePath, s as exists, t as trimExtName } from "./fs-BIPMUfpW.js";
2
- import { t as write } from "./write-CxO1CDML.js";
3
-
4
- export { types_exports as KubbFile, clean, exists, getRelativePath, read, readSync, trimExtName, unlink, write };
@@ -1,144 +0,0 @@
1
- //#endregion
2
- //#region src/fs/clean.d.ts
3
- declare function clean(path: string): Promise<void>;
4
- //#endregion
5
- //#region src/fs/exists.d.ts
6
- declare function exists(path: string): Promise<boolean>;
7
- //#endregion
8
- //#region src/fs/read.d.ts
9
- declare function read(path: string): Promise<string>;
10
- declare function readSync(path: string): string;
11
- //#endregion
12
- //#region src/fs/unlink.d.ts
13
- declare function unlink(path: string): Promise<void>;
14
- //#endregion
15
- //#region src/fs/utils.d.ts
16
- declare function getRelativePath(rootDir?: string | null, filePath?: string | null, platform?: 'windows' | 'mac' | 'linux'): string;
17
- //#endregion
18
- //#region src/fs/write.d.ts
19
- type Options = {
20
- sanity?: boolean;
21
- };
22
- declare function write(path: string, data: string, options?: Options): Promise<string | undefined>;
23
- declare namespace types_d_exports {
24
- export { AdvancedPath, BaseName, Export, Extname, File, Import, Mode, OptionalPath, Path, ResolvedExport, ResolvedFile, ResolvedImport, Source };
25
- }
26
- type BasePath<T extends string = string> = `${T}/`;
27
- type Import = {
28
- /**
29
- * Import name to be used
30
- * @example ["useState"]
31
- * @example "React"
32
- */
33
- name: string | Array<string | {
34
- propertyName: string;
35
- name?: string;
36
- }>;
37
- /**
38
- * Path for the import
39
- * @example '@kubb/core'
40
- */
41
- path: string;
42
- /**
43
- * Add `type` prefix to the import, this will result in: `import type { Type } from './path'`.
44
- */
45
- isTypeOnly?: boolean;
46
- isNameSpace?: boolean;
47
- /**
48
- * When root is set it will get the path with relative getRelativePath(root, path).
49
- */
50
- root?: string;
51
- };
52
- type Source = {
53
- name?: string;
54
- value?: string;
55
- isTypeOnly?: boolean;
56
- /**
57
- * Has const or type 'export'
58
- * @default false
59
- */
60
- isExportable?: boolean;
61
- /**
62
- * When set, barrel generation will add this
63
- * @default false
64
- */
65
- isIndexable?: boolean;
66
- };
67
- type Export = {
68
- /**
69
- * Export name to be used.
70
- * @example ["useState"]
71
- * @example "React"
72
- */
73
- name?: string | Array<string>;
74
- /**
75
- * Path for the import.
76
- * @example '@kubb/core'
77
- */
78
- path: string;
79
- /**
80
- * Add `type` prefix to the export, this will result in: `export type { Type } from './path'`.
81
- */
82
- isTypeOnly?: boolean;
83
- /**
84
- * Make it possible to override the name, this will result in: `export * as aliasName from './path'`.
85
- */
86
- asAlias?: boolean;
87
- };
88
- type Extname = '.ts' | '.js' | '.tsx' | '.json' | `.${string}`;
89
- type Mode = 'single' | 'split';
90
- /**
91
- * Name to be used to dynamicly create the baseName(based on input.path)
92
- * Based on UNIX basename
93
- * @link https://nodejs.org/api/path.html#pathbasenamepath-suffix
94
- */
95
- type BaseName = `${string}.${string}`;
96
- /**
97
- * Path will be full qualified path to a specified file
98
- */
99
- type Path = string;
100
- type AdvancedPath<T extends BaseName = BaseName> = `${BasePath}${T}`;
101
- type OptionalPath = Path | undefined | null;
102
- type File<TMeta extends object = object> = {
103
- /**
104
- * Name to be used to create the path
105
- * Based on UNIX basename, `${name}.extname`
106
- * @link https://nodejs.org/api/path.html#pathbasenamepath-suffix
107
- */
108
- baseName: BaseName;
109
- /**
110
- * Path will be full qualified path to a specified file
111
- */
112
- path: AdvancedPath<BaseName> | Path;
113
- sources: Array<Source>;
114
- imports?: Array<Import>;
115
- exports?: Array<Export>;
116
- /**
117
- * Use extra meta, this is getting used to generate the barrel/index files.
118
- */
119
- meta?: TMeta;
120
- banner?: string;
121
- footer?: string;
122
- };
123
- type ResolvedImport = Import;
124
- type ResolvedExport = Export;
125
- type ResolvedFile<TMeta extends object = object> = File<TMeta> & {
126
- /**
127
- * @default object-hash
128
- */
129
- id: string;
130
- /**
131
- * Contains the first part of the baseName, generated based on baseName
132
- * @link https://nodejs.org/api/path.html#pathformatpathobject
133
- */
134
- name: string;
135
- extname: Extname;
136
- imports: Array<ResolvedImport>;
137
- exports: Array<ResolvedExport>;
138
- };
139
- //#endregion
140
- //#region src/fs/index.d.ts
141
- declare function trimExtName(text: string): string;
142
- //#endregion
143
- export { Mode as a, types_d_exports as c, unlink as d, read as f, clean as h, File as i, write as l, exists as m, BaseName as n, OptionalPath as o, readSync as p, Extname as r, ResolvedFile as s, trimExtName as t, getRelativePath as u };
144
- //# sourceMappingURL=index-BmQIxvw0.d.cts.map