@kubb/core 5.0.0-alpha.6 → 5.0.0-alpha.60

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 (72) hide show
  1. package/README.md +3 -2
  2. package/dist/PluginDriver-Bc0HQM8V.js +948 -0
  3. package/dist/PluginDriver-Bc0HQM8V.js.map +1 -0
  4. package/dist/PluginDriver-Dyl2fwfQ.cjs +1039 -0
  5. package/dist/PluginDriver-Dyl2fwfQ.cjs.map +1 -0
  6. package/dist/index.cjs +691 -1798
  7. package/dist/index.cjs.map +1 -1
  8. package/dist/index.d.ts +279 -265
  9. package/dist/index.js +678 -1765
  10. package/dist/index.js.map +1 -1
  11. package/dist/mocks.cjs +138 -0
  12. package/dist/mocks.cjs.map +1 -0
  13. package/dist/mocks.d.ts +74 -0
  14. package/dist/mocks.js +133 -0
  15. package/dist/mocks.js.map +1 -0
  16. package/dist/types-i0b4_23K.d.ts +1903 -0
  17. package/package.json +51 -57
  18. package/src/FileManager.ts +110 -0
  19. package/src/FileProcessor.ts +86 -0
  20. package/src/Kubb.ts +205 -130
  21. package/src/PluginDriver.ts +424 -0
  22. package/src/constants.ts +20 -47
  23. package/src/createAdapter.ts +25 -0
  24. package/src/createKubb.ts +527 -0
  25. package/src/createRenderer.ts +57 -0
  26. package/src/createStorage.ts +58 -0
  27. package/src/defineGenerator.ts +88 -100
  28. package/src/defineLogger.ts +13 -3
  29. package/src/defineMiddleware.ts +59 -0
  30. package/src/defineParser.ts +45 -0
  31. package/src/definePlugin.ts +78 -7
  32. package/src/defineResolver.ts +521 -0
  33. package/src/devtools.ts +14 -14
  34. package/src/index.ts +13 -17
  35. package/src/mocks.ts +171 -0
  36. package/src/renderNode.ts +35 -0
  37. package/src/storages/fsStorage.ts +40 -11
  38. package/src/storages/memoryStorage.ts +4 -3
  39. package/src/types.ts +738 -218
  40. package/src/utils/diagnostics.ts +4 -1
  41. package/src/utils/isInputPath.ts +10 -0
  42. package/src/utils/packageJSON.ts +99 -0
  43. package/dist/PluginManager-vZodFEMe.d.ts +0 -1056
  44. package/dist/chunk-ByKO4r7w.cjs +0 -38
  45. package/dist/hooks.cjs +0 -60
  46. package/dist/hooks.cjs.map +0 -1
  47. package/dist/hooks.d.ts +0 -64
  48. package/dist/hooks.js +0 -56
  49. package/dist/hooks.js.map +0 -1
  50. package/src/BarrelManager.ts +0 -74
  51. package/src/PackageManager.ts +0 -180
  52. package/src/PluginManager.ts +0 -667
  53. package/src/PromiseManager.ts +0 -40
  54. package/src/build.ts +0 -419
  55. package/src/config.ts +0 -56
  56. package/src/defineAdapter.ts +0 -22
  57. package/src/defineStorage.ts +0 -56
  58. package/src/errors.ts +0 -1
  59. package/src/hooks/index.ts +0 -4
  60. package/src/hooks/useKubb.ts +0 -55
  61. package/src/hooks/useMode.ts +0 -11
  62. package/src/hooks/usePlugin.ts +0 -11
  63. package/src/hooks/usePluginManager.ts +0 -11
  64. package/src/utils/FunctionParams.ts +0 -155
  65. package/src/utils/TreeNode.ts +0 -215
  66. package/src/utils/executeStrategies.ts +0 -81
  67. package/src/utils/formatters.ts +0 -56
  68. package/src/utils/getBarrelFiles.ts +0 -79
  69. package/src/utils/getConfigs.ts +0 -30
  70. package/src/utils/getPlugins.ts +0 -23
  71. package/src/utils/linters.ts +0 -25
  72. package/src/utils/resolveOptions.ts +0 -93
@@ -1,38 +0,0 @@
1
- //#region \0rolldown/runtime.js
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __name = (target, value) => __defProp(target, "name", {
5
- value,
6
- configurable: true
7
- });
8
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
9
- var __getOwnPropNames = Object.getOwnPropertyNames;
10
- var __getProtoOf = Object.getPrototypeOf;
11
- var __hasOwnProp = Object.prototype.hasOwnProperty;
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
14
- key = keys[i];
15
- if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
16
- get: ((k) => from[k]).bind(null, key),
17
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
18
- });
19
- }
20
- return to;
21
- };
22
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
23
- value: mod,
24
- enumerable: true
25
- }) : target, mod));
26
- //#endregion
27
- Object.defineProperty(exports, "__name", {
28
- enumerable: true,
29
- get: function() {
30
- return __name;
31
- }
32
- });
33
- Object.defineProperty(exports, "__toESM", {
34
- enumerable: true,
35
- get: function() {
36
- return __toESM;
37
- }
38
- });
package/dist/hooks.cjs DELETED
@@ -1,60 +0,0 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- require("./chunk-ByKO4r7w.cjs");
3
- let _kubb_react_fabric = require("@kubb/react-fabric");
4
- //#region src/hooks/useKubb.ts
5
- function useKubb() {
6
- const { meta } = (0, _kubb_react_fabric.useFabric)();
7
- const defaultPluginName = meta.plugin.name;
8
- return {
9
- plugin: meta.plugin,
10
- mode: meta.mode,
11
- config: meta.pluginManager.config,
12
- getPluginByName: (pluginName = defaultPluginName) => meta.pluginManager.getPluginByName.call(meta.pluginManager, pluginName),
13
- getFile: ({ pluginName = defaultPluginName, ...rest }) => meta.pluginManager.getFile.call(meta.pluginManager, {
14
- pluginName,
15
- ...rest
16
- }),
17
- resolveName: ({ pluginName = defaultPluginName, ...rest }) => meta.pluginManager.resolveName.call(meta.pluginManager, {
18
- pluginName,
19
- ...rest
20
- }),
21
- resolvePath: ({ pluginName = defaultPluginName, ...rest }) => meta.pluginManager.resolvePath.call(meta.pluginManager, {
22
- pluginName,
23
- ...rest
24
- })
25
- };
26
- }
27
- //#endregion
28
- //#region src/hooks/useMode.ts
29
- /**
30
- * @deprecated use `useKubb` instead
31
- */
32
- function useMode() {
33
- const { meta } = (0, _kubb_react_fabric.useFabric)();
34
- return meta.mode;
35
- }
36
- //#endregion
37
- //#region src/hooks/usePlugin.ts
38
- /**
39
- * @deprecated use useKubb instead
40
- */
41
- function usePlugin() {
42
- const { meta } = (0, _kubb_react_fabric.useFabric)();
43
- return meta.plugin;
44
- }
45
- //#endregion
46
- //#region src/hooks/usePluginManager.ts
47
- /**
48
- * @deprecated use `useKubb` instead
49
- */
50
- function usePluginManager() {
51
- const { meta } = (0, _kubb_react_fabric.useFabric)();
52
- return meta.pluginManager;
53
- }
54
- //#endregion
55
- exports.useKubb = useKubb;
56
- exports.useMode = useMode;
57
- exports.usePlugin = usePlugin;
58
- exports.usePluginManager = usePluginManager;
59
-
60
- //# sourceMappingURL=hooks.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"hooks.cjs","names":[],"sources":["../src/hooks/useKubb.ts","../src/hooks/useMode.ts","../src/hooks/usePlugin.ts","../src/hooks/usePluginManager.ts"],"sourcesContent":["import type { KubbFile } from '@kubb/fabric-core/types'\nimport { useFabric } from '@kubb/react-fabric'\nimport type { GetFileOptions, PluginManager } from '../PluginManager.ts'\nimport type { Config, Plugin, PluginFactoryOptions, ResolveNameParams, ResolvePathParams } from '../types.ts'\n\ntype ResolvePathOptions = {\n pluginName?: string\n group?: {\n tag?: string\n path?: string\n }\n type?: ResolveNameParams['type']\n}\n\ntype UseKubbReturn<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {\n plugin: Plugin<TOptions>\n mode: KubbFile.Mode\n config: Config\n /**\n * Returns the plugin whose `name` matches `pluginName`, defaulting to the current plugin.\n */\n getPluginByName: (pluginName?: string) => Plugin | undefined\n /**\n * Resolves a file reference, defaulting `pluginName` to the current plugin.\n */\n getFile: (params: Omit<GetFileOptions<ResolvePathOptions>, 'pluginName'> & { pluginName?: string }) => KubbFile.File<{ pluginName: string }>\n /**\n * Resolves a name, defaulting `pluginName` to the current plugin.\n */\n resolveName: (params: Omit<ResolveNameParams, 'pluginName'> & { pluginName?: string }) => string\n /**\n * Resolves a path, defaulting `pluginName` to the current plugin.\n */\n resolvePath: <TPathOptions = object>(params: Omit<ResolvePathParams<TPathOptions>, 'pluginName'> & { pluginName?: string }) => KubbFile.Path\n}\n\nexport function useKubb<TOptions extends PluginFactoryOptions = PluginFactoryOptions>(): UseKubbReturn<TOptions> {\n const { meta } = useFabric<{\n plugin: Plugin<TOptions>\n mode: KubbFile.Mode\n pluginManager: PluginManager\n }>()\n\n const defaultPluginName = meta.plugin.name\n\n return {\n plugin: meta.plugin as Plugin<TOptions>,\n mode: meta.mode,\n config: meta.pluginManager.config,\n getPluginByName: (pluginName = defaultPluginName) => meta.pluginManager.getPluginByName.call(meta.pluginManager, pluginName),\n getFile: ({ pluginName = defaultPluginName, ...rest }) => meta.pluginManager.getFile.call(meta.pluginManager, { pluginName, ...rest }),\n resolveName: ({ pluginName = defaultPluginName, ...rest }) => meta.pluginManager.resolveName.call(meta.pluginManager, { pluginName, ...rest }),\n resolvePath: ({ pluginName = defaultPluginName, ...rest }) => meta.pluginManager.resolvePath.call(meta.pluginManager, { pluginName, ...rest }),\n }\n}\n","import type { KubbFile } from '@kubb/fabric-core/types'\nimport { useFabric } from '@kubb/react-fabric'\n\n/**\n * @deprecated use `useKubb` instead\n */\nexport function useMode(): KubbFile.Mode {\n const { meta } = useFabric<{ mode: KubbFile.Mode }>()\n\n return meta.mode\n}\n","import { useFabric } from '@kubb/react-fabric'\nimport type { Plugin, PluginFactoryOptions } from '../types.ts'\n\n/**\n * @deprecated use useKubb instead\n */\nexport function usePlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions>(): Plugin<TOptions> {\n const { meta } = useFabric<{ plugin: Plugin<TOptions> }>()\n\n return meta.plugin\n}\n","import { useFabric } from '@kubb/react-fabric'\nimport type { PluginManager } from '../PluginManager.ts'\n\n/**\n * @deprecated use `useKubb` instead\n */\nexport function usePluginManager(): PluginManager {\n const { meta } = useFabric<{ pluginManager: PluginManager }>()\n\n return meta.pluginManager\n}\n"],"mappings":";;;;AAoCA,SAAgB,UAAiG;CAC/G,MAAM,EAAE,UAAA,GAAA,mBAAA,YAIJ;CAEJ,MAAM,oBAAoB,KAAK,OAAO;AAEtC,QAAO;EACL,QAAQ,KAAK;EACb,MAAM,KAAK;EACX,QAAQ,KAAK,cAAc;EAC3B,kBAAkB,aAAa,sBAAsB,KAAK,cAAc,gBAAgB,KAAK,KAAK,eAAe,WAAW;EAC5H,UAAU,EAAE,aAAa,mBAAmB,GAAG,WAAW,KAAK,cAAc,QAAQ,KAAK,KAAK,eAAe;GAAE;GAAY,GAAG;GAAM,CAAC;EACtI,cAAc,EAAE,aAAa,mBAAmB,GAAG,WAAW,KAAK,cAAc,YAAY,KAAK,KAAK,eAAe;GAAE;GAAY,GAAG;GAAM,CAAC;EAC9I,cAAc,EAAE,aAAa,mBAAmB,GAAG,WAAW,KAAK,cAAc,YAAY,KAAK,KAAK,eAAe;GAAE;GAAY,GAAG;GAAM,CAAC;EAC/I;;;;;;;AC/CH,SAAgB,UAAyB;CACvC,MAAM,EAAE,UAAA,GAAA,mBAAA,YAA6C;AAErD,QAAO,KAAK;;;;;;;ACHd,SAAgB,YAA4F;CAC1G,MAAM,EAAE,UAAA,GAAA,mBAAA,YAAkD;AAE1D,QAAO,KAAK;;;;;;;ACHd,SAAgB,mBAAkC;CAChD,MAAM,EAAE,UAAA,GAAA,mBAAA,YAAsD;AAE9D,QAAO,KAAK"}
package/dist/hooks.d.ts DELETED
@@ -1,64 +0,0 @@
1
- import { t as __name } from "./chunk--u3MIqq1.js";
2
- import { D as ResolveNameParams, O as ResolvePathParams, b as PluginFactoryOptions, c as Config, n as PluginManager, t as GetFileOptions, v as Plugin } from "./PluginManager-vZodFEMe.js";
3
- import { KubbFile } from "@kubb/fabric-core/types";
4
-
5
- //#region src/hooks/useKubb.d.ts
6
- type ResolvePathOptions = {
7
- pluginName?: string;
8
- group?: {
9
- tag?: string;
10
- path?: string;
11
- };
12
- type?: ResolveNameParams['type'];
13
- };
14
- type UseKubbReturn<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
15
- plugin: Plugin<TOptions>;
16
- mode: KubbFile.Mode;
17
- config: Config;
18
- /**
19
- * Returns the plugin whose `name` matches `pluginName`, defaulting to the current plugin.
20
- */
21
- getPluginByName: (pluginName?: string) => Plugin | undefined;
22
- /**
23
- * Resolves a file reference, defaulting `pluginName` to the current plugin.
24
- */
25
- getFile: (params: Omit<GetFileOptions<ResolvePathOptions>, 'pluginName'> & {
26
- pluginName?: string;
27
- }) => KubbFile.File<{
28
- pluginName: string;
29
- }>;
30
- /**
31
- * Resolves a name, defaulting `pluginName` to the current plugin.
32
- */
33
- resolveName: (params: Omit<ResolveNameParams, 'pluginName'> & {
34
- pluginName?: string;
35
- }) => string;
36
- /**
37
- * Resolves a path, defaulting `pluginName` to the current plugin.
38
- */
39
- resolvePath: <TPathOptions = object>(params: Omit<ResolvePathParams<TPathOptions>, 'pluginName'> & {
40
- pluginName?: string;
41
- }) => KubbFile.Path;
42
- };
43
- declare function useKubb<TOptions extends PluginFactoryOptions = PluginFactoryOptions>(): UseKubbReturn<TOptions>;
44
- //#endregion
45
- //#region src/hooks/useMode.d.ts
46
- /**
47
- * @deprecated use `useKubb` instead
48
- */
49
- declare function useMode(): KubbFile.Mode;
50
- //#endregion
51
- //#region src/hooks/usePlugin.d.ts
52
- /**
53
- * @deprecated use useKubb instead
54
- */
55
- declare function usePlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions>(): Plugin<TOptions>;
56
- //#endregion
57
- //#region src/hooks/usePluginManager.d.ts
58
- /**
59
- * @deprecated use `useKubb` instead
60
- */
61
- declare function usePluginManager(): PluginManager;
62
- //#endregion
63
- export { useKubb, useMode, usePlugin, usePluginManager };
64
- //# sourceMappingURL=hooks.d.ts.map
package/dist/hooks.js DELETED
@@ -1,56 +0,0 @@
1
- import "./chunk--u3MIqq1.js";
2
- import { useFabric } from "@kubb/react-fabric";
3
- //#region src/hooks/useKubb.ts
4
- function useKubb() {
5
- const { meta } = useFabric();
6
- const defaultPluginName = meta.plugin.name;
7
- return {
8
- plugin: meta.plugin,
9
- mode: meta.mode,
10
- config: meta.pluginManager.config,
11
- getPluginByName: (pluginName = defaultPluginName) => meta.pluginManager.getPluginByName.call(meta.pluginManager, pluginName),
12
- getFile: ({ pluginName = defaultPluginName, ...rest }) => meta.pluginManager.getFile.call(meta.pluginManager, {
13
- pluginName,
14
- ...rest
15
- }),
16
- resolveName: ({ pluginName = defaultPluginName, ...rest }) => meta.pluginManager.resolveName.call(meta.pluginManager, {
17
- pluginName,
18
- ...rest
19
- }),
20
- resolvePath: ({ pluginName = defaultPluginName, ...rest }) => meta.pluginManager.resolvePath.call(meta.pluginManager, {
21
- pluginName,
22
- ...rest
23
- })
24
- };
25
- }
26
- //#endregion
27
- //#region src/hooks/useMode.ts
28
- /**
29
- * @deprecated use `useKubb` instead
30
- */
31
- function useMode() {
32
- const { meta } = useFabric();
33
- return meta.mode;
34
- }
35
- //#endregion
36
- //#region src/hooks/usePlugin.ts
37
- /**
38
- * @deprecated use useKubb instead
39
- */
40
- function usePlugin() {
41
- const { meta } = useFabric();
42
- return meta.plugin;
43
- }
44
- //#endregion
45
- //#region src/hooks/usePluginManager.ts
46
- /**
47
- * @deprecated use `useKubb` instead
48
- */
49
- function usePluginManager() {
50
- const { meta } = useFabric();
51
- return meta.pluginManager;
52
- }
53
- //#endregion
54
- export { useKubb, useMode, usePlugin, usePluginManager };
55
-
56
- //# sourceMappingURL=hooks.js.map
package/dist/hooks.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"hooks.js","names":[],"sources":["../src/hooks/useKubb.ts","../src/hooks/useMode.ts","../src/hooks/usePlugin.ts","../src/hooks/usePluginManager.ts"],"sourcesContent":["import type { KubbFile } from '@kubb/fabric-core/types'\nimport { useFabric } from '@kubb/react-fabric'\nimport type { GetFileOptions, PluginManager } from '../PluginManager.ts'\nimport type { Config, Plugin, PluginFactoryOptions, ResolveNameParams, ResolvePathParams } from '../types.ts'\n\ntype ResolvePathOptions = {\n pluginName?: string\n group?: {\n tag?: string\n path?: string\n }\n type?: ResolveNameParams['type']\n}\n\ntype UseKubbReturn<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {\n plugin: Plugin<TOptions>\n mode: KubbFile.Mode\n config: Config\n /**\n * Returns the plugin whose `name` matches `pluginName`, defaulting to the current plugin.\n */\n getPluginByName: (pluginName?: string) => Plugin | undefined\n /**\n * Resolves a file reference, defaulting `pluginName` to the current plugin.\n */\n getFile: (params: Omit<GetFileOptions<ResolvePathOptions>, 'pluginName'> & { pluginName?: string }) => KubbFile.File<{ pluginName: string }>\n /**\n * Resolves a name, defaulting `pluginName` to the current plugin.\n */\n resolveName: (params: Omit<ResolveNameParams, 'pluginName'> & { pluginName?: string }) => string\n /**\n * Resolves a path, defaulting `pluginName` to the current plugin.\n */\n resolvePath: <TPathOptions = object>(params: Omit<ResolvePathParams<TPathOptions>, 'pluginName'> & { pluginName?: string }) => KubbFile.Path\n}\n\nexport function useKubb<TOptions extends PluginFactoryOptions = PluginFactoryOptions>(): UseKubbReturn<TOptions> {\n const { meta } = useFabric<{\n plugin: Plugin<TOptions>\n mode: KubbFile.Mode\n pluginManager: PluginManager\n }>()\n\n const defaultPluginName = meta.plugin.name\n\n return {\n plugin: meta.plugin as Plugin<TOptions>,\n mode: meta.mode,\n config: meta.pluginManager.config,\n getPluginByName: (pluginName = defaultPluginName) => meta.pluginManager.getPluginByName.call(meta.pluginManager, pluginName),\n getFile: ({ pluginName = defaultPluginName, ...rest }) => meta.pluginManager.getFile.call(meta.pluginManager, { pluginName, ...rest }),\n resolveName: ({ pluginName = defaultPluginName, ...rest }) => meta.pluginManager.resolveName.call(meta.pluginManager, { pluginName, ...rest }),\n resolvePath: ({ pluginName = defaultPluginName, ...rest }) => meta.pluginManager.resolvePath.call(meta.pluginManager, { pluginName, ...rest }),\n }\n}\n","import type { KubbFile } from '@kubb/fabric-core/types'\nimport { useFabric } from '@kubb/react-fabric'\n\n/**\n * @deprecated use `useKubb` instead\n */\nexport function useMode(): KubbFile.Mode {\n const { meta } = useFabric<{ mode: KubbFile.Mode }>()\n\n return meta.mode\n}\n","import { useFabric } from '@kubb/react-fabric'\nimport type { Plugin, PluginFactoryOptions } from '../types.ts'\n\n/**\n * @deprecated use useKubb instead\n */\nexport function usePlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions>(): Plugin<TOptions> {\n const { meta } = useFabric<{ plugin: Plugin<TOptions> }>()\n\n return meta.plugin\n}\n","import { useFabric } from '@kubb/react-fabric'\nimport type { PluginManager } from '../PluginManager.ts'\n\n/**\n * @deprecated use `useKubb` instead\n */\nexport function usePluginManager(): PluginManager {\n const { meta } = useFabric<{ pluginManager: PluginManager }>()\n\n return meta.pluginManager\n}\n"],"mappings":";;;AAoCA,SAAgB,UAAiG;CAC/G,MAAM,EAAE,SAAS,WAIb;CAEJ,MAAM,oBAAoB,KAAK,OAAO;AAEtC,QAAO;EACL,QAAQ,KAAK;EACb,MAAM,KAAK;EACX,QAAQ,KAAK,cAAc;EAC3B,kBAAkB,aAAa,sBAAsB,KAAK,cAAc,gBAAgB,KAAK,KAAK,eAAe,WAAW;EAC5H,UAAU,EAAE,aAAa,mBAAmB,GAAG,WAAW,KAAK,cAAc,QAAQ,KAAK,KAAK,eAAe;GAAE;GAAY,GAAG;GAAM,CAAC;EACtI,cAAc,EAAE,aAAa,mBAAmB,GAAG,WAAW,KAAK,cAAc,YAAY,KAAK,KAAK,eAAe;GAAE;GAAY,GAAG;GAAM,CAAC;EAC9I,cAAc,EAAE,aAAa,mBAAmB,GAAG,WAAW,KAAK,cAAc,YAAY,KAAK,KAAK,eAAe;GAAE;GAAY,GAAG;GAAM,CAAC;EAC/I;;;;;;;AC/CH,SAAgB,UAAyB;CACvC,MAAM,EAAE,SAAS,WAAoC;AAErD,QAAO,KAAK;;;;;;;ACHd,SAAgB,YAA4F;CAC1G,MAAM,EAAE,SAAS,WAAyC;AAE1D,QAAO,KAAK;;;;;;;ACHd,SAAgB,mBAAkC;CAChD,MAAM,EAAE,SAAS,WAA6C;AAE9D,QAAO,KAAK"}
@@ -1,74 +0,0 @@
1
- /** biome-ignore-all lint/suspicious/useIterableCallbackReturn: not needed */
2
- import { join } from 'node:path'
3
- import { getRelativePath } from '@internals/utils'
4
- import type { KubbFile } from '@kubb/fabric-core/types'
5
-
6
- import type { FileMetaBase } from './utils/getBarrelFiles.ts'
7
- import { TreeNode } from './utils/TreeNode.ts'
8
-
9
- export class BarrelManager {
10
- getFiles({ files: generatedFiles, root }: { files: KubbFile.File[]; root?: string; meta?: FileMetaBase | undefined }): Array<KubbFile.File> {
11
- const cachedFiles = new Map<KubbFile.Path, KubbFile.File>()
12
-
13
- TreeNode.build(generatedFiles, root)?.forEach((treeNode) => {
14
- if (!treeNode || !treeNode.children || !treeNode.parent?.data.path) {
15
- return
16
- }
17
-
18
- const barrelFile: KubbFile.File = {
19
- path: join(treeNode.parent?.data.path, 'index.ts') as KubbFile.Path,
20
- baseName: 'index.ts',
21
- exports: [],
22
- imports: [],
23
- sources: [],
24
- }
25
- const previousBarrelFile = cachedFiles.get(barrelFile.path)
26
- const leaves = treeNode.leaves
27
-
28
- leaves.forEach((item) => {
29
- if (!item.data.name) {
30
- return
31
- }
32
-
33
- const sources = item.data.file?.sources || []
34
-
35
- sources.forEach((source) => {
36
- if (!item.data.file?.path || !source.isIndexable || !source.name) {
37
- return
38
- }
39
- const alreadyContainInPreviousBarrelFile = previousBarrelFile?.sources.some(
40
- (item) => item.name === source.name && item.isTypeOnly === source.isTypeOnly,
41
- )
42
-
43
- if (alreadyContainInPreviousBarrelFile) {
44
- return
45
- }
46
-
47
- barrelFile.exports!.push({
48
- name: [source.name],
49
- path: getRelativePath(treeNode.parent?.data.path, item.data.path),
50
- isTypeOnly: source.isTypeOnly,
51
- })
52
-
53
- barrelFile.sources.push({
54
- name: source.name,
55
- isTypeOnly: source.isTypeOnly,
56
- //TODO use parser to generate import
57
- value: '',
58
- isExportable: false,
59
- isIndexable: false,
60
- })
61
- })
62
- })
63
-
64
- if (previousBarrelFile) {
65
- previousBarrelFile.sources.push(...barrelFile.sources)
66
- previousBarrelFile.exports?.push(...(barrelFile.exports || []))
67
- } else {
68
- cachedFiles.set(barrelFile.path, barrelFile)
69
- }
70
- })
71
-
72
- return [...cachedFiles.values()]
73
- }
74
- }
@@ -1,180 +0,0 @@
1
- import mod from 'node:module'
2
- import os from 'node:os'
3
- import { pathToFileURL } from 'node:url'
4
- import { read, readSync } from '@internals/utils'
5
- import * as pkg from 'empathic/package'
6
- import { coerce, satisfies } from 'semver'
7
- import { PATH_SEPARATORS } from './constants.ts'
8
-
9
- type PackageJSON = {
10
- dependencies?: Record<string, string>
11
- devDependencies?: Record<string, string>
12
- }
13
-
14
- type DependencyName = string
15
-
16
- type DependencyVersion = string
17
-
18
- export class PackageManager {
19
- static #cache: Record<DependencyName, DependencyVersion> = {}
20
-
21
- #cwd?: string
22
-
23
- constructor(workspace?: string) {
24
- if (workspace) {
25
- this.#cwd = workspace
26
- }
27
- }
28
-
29
- set workspace(workspace: string) {
30
- this.#cwd = workspace
31
- }
32
-
33
- get workspace(): string | undefined {
34
- return this.#cwd
35
- }
36
-
37
- normalizeDirectory(directory: string): string {
38
- const lastChar = directory[directory.length - 1]
39
- if (lastChar && !(PATH_SEPARATORS as readonly string[]).includes(lastChar)) {
40
- return `${directory}/`
41
- }
42
-
43
- return directory
44
- }
45
-
46
- getLocation(path: string): string {
47
- let location = path
48
-
49
- if (this.#cwd) {
50
- const require = mod.createRequire(this.normalizeDirectory(this.#cwd))
51
- location = require.resolve(path)
52
- }
53
-
54
- return location
55
- }
56
-
57
- async import(path: string): Promise<unknown> {
58
- let location = this.getLocation(path)
59
-
60
- if (os.platform() === 'win32') {
61
- location = pathToFileURL(location).href
62
- }
63
-
64
- const module = await import(location)
65
-
66
- return module?.default ?? module
67
- }
68
-
69
- async getPackageJSON(): Promise<PackageJSON | undefined> {
70
- const pkgPath = pkg.up({
71
- cwd: this.#cwd,
72
- })
73
- if (!pkgPath) {
74
- return undefined
75
- }
76
-
77
- const json = await read(pkgPath)
78
-
79
- return JSON.parse(json) as PackageJSON
80
- }
81
-
82
- getPackageJSONSync(): PackageJSON | undefined {
83
- const pkgPath = pkg.up({
84
- cwd: this.#cwd,
85
- })
86
- if (!pkgPath) {
87
- return undefined
88
- }
89
-
90
- const json = readSync(pkgPath)
91
-
92
- return JSON.parse(json) as PackageJSON
93
- }
94
-
95
- static setVersion(dependency: DependencyName, version: DependencyVersion): void {
96
- PackageManager.#cache[dependency] = version
97
- }
98
-
99
- #match(packageJSON: PackageJSON, dependency: DependencyName | RegExp): string | undefined {
100
- const dependencies = {
101
- ...(packageJSON.dependencies || {}),
102
- ...(packageJSON.devDependencies || {}),
103
- }
104
-
105
- if (typeof dependency === 'string' && dependencies[dependency]) {
106
- return dependencies[dependency]
107
- }
108
-
109
- const matchedDependency = Object.keys(dependencies).find((dep) => dep.match(dependency))
110
-
111
- return matchedDependency ? dependencies[matchedDependency] : undefined
112
- }
113
-
114
- async getVersion(dependency: DependencyName | RegExp): Promise<DependencyVersion | undefined> {
115
- if (typeof dependency === 'string' && PackageManager.#cache[dependency]) {
116
- return PackageManager.#cache[dependency]
117
- }
118
-
119
- const packageJSON = await this.getPackageJSON()
120
-
121
- if (!packageJSON) {
122
- return undefined
123
- }
124
-
125
- return this.#match(packageJSON, dependency)
126
- }
127
-
128
- getVersionSync(dependency: DependencyName | RegExp): DependencyVersion | undefined {
129
- if (typeof dependency === 'string' && PackageManager.#cache[dependency]) {
130
- return PackageManager.#cache[dependency]
131
- }
132
-
133
- const packageJSON = this.getPackageJSONSync()
134
-
135
- if (!packageJSON) {
136
- return undefined
137
- }
138
-
139
- return this.#match(packageJSON, dependency)
140
- }
141
-
142
- async isValid(dependency: DependencyName | RegExp, version: DependencyVersion): Promise<boolean> {
143
- const packageVersion = await this.getVersion(dependency)
144
-
145
- if (!packageVersion) {
146
- return false
147
- }
148
-
149
- if (packageVersion === version) {
150
- return true
151
- }
152
-
153
- const semVer = coerce(packageVersion)
154
-
155
- if (!semVer) {
156
- return false
157
- }
158
-
159
- return satisfies(semVer, version)
160
- }
161
- isValidSync(dependency: DependencyName | RegExp, version: DependencyVersion): boolean {
162
- const packageVersion = this.getVersionSync(dependency)
163
-
164
- if (!packageVersion) {
165
- return false
166
- }
167
-
168
- if (packageVersion === version) {
169
- return true
170
- }
171
-
172
- const semVer = coerce(packageVersion)
173
-
174
- if (!semVer) {
175
- return false
176
- }
177
-
178
- return satisfies(semVer, version)
179
- }
180
- }