@kubb/fabric-core 0.1.2 → 0.1.4

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 (56) hide show
  1. package/dist/{App-DZuROf6f.d.ts → App-BxAl3dNP.d.ts} +16 -19
  2. package/dist/{App-zyf9KG3p.d.cts → App-D3DHa4Il.d.cts} +16 -19
  3. package/dist/createParser-B_RpW6sx.js +17 -0
  4. package/dist/createParser-B_RpW6sx.js.map +1 -0
  5. package/dist/createParser-DZB5qExa.cjs +29 -0
  6. package/dist/createParser-DZB5qExa.cjs.map +1 -0
  7. package/dist/defaultParser-Dl-OrbH1.cjs +20 -0
  8. package/dist/defaultParser-Dl-OrbH1.cjs.map +1 -0
  9. package/dist/defaultParser-vwyTb1XT.js +15 -0
  10. package/dist/defaultParser-vwyTb1XT.js.map +1 -0
  11. package/dist/defineApp-B9W1A5SV.d.ts +9 -0
  12. package/dist/defineApp-BP97CT5p.d.cts +9 -0
  13. package/dist/index.cjs +38 -74
  14. package/dist/index.cjs.map +1 -1
  15. package/dist/index.d.cts +3 -3
  16. package/dist/index.d.ts +3 -3
  17. package/dist/index.js +33 -69
  18. package/dist/index.js.map +1 -1
  19. package/dist/parsers/typescript.cjs +2 -1
  20. package/dist/parsers/typescript.d.cts +2 -2
  21. package/dist/parsers/typescript.d.ts +2 -2
  22. package/dist/parsers/typescript.js +2 -1
  23. package/dist/parsers.cjs +19 -6
  24. package/dist/parsers.cjs.map +1 -0
  25. package/dist/parsers.d.cts +2 -2
  26. package/dist/parsers.d.ts +2 -2
  27. package/dist/parsers.js +16 -3
  28. package/dist/parsers.js.map +1 -0
  29. package/dist/plugins.cjs +5 -5
  30. package/dist/plugins.cjs.map +1 -1
  31. package/dist/plugins.d.cts +8 -7
  32. package/dist/plugins.d.ts +8 -7
  33. package/dist/plugins.js +5 -5
  34. package/dist/plugins.js.map +1 -1
  35. package/dist/types.d.cts +2 -2
  36. package/dist/types.d.ts +2 -2
  37. package/dist/{typescriptParser-C-sBy1iR.d.cts → typescriptParser--N0n8KFn.d.cts} +2 -2
  38. package/dist/{typescriptParser-CtMmz0UV.d.ts → typescriptParser-CctRhsng.d.ts} +2 -2
  39. package/dist/{typescriptParser-BBGeFKlP.js → typescriptParser-CrzOv_Aw.js} +3 -17
  40. package/dist/typescriptParser-CrzOv_Aw.js.map +1 -0
  41. package/dist/{typescriptParser-BBbbmG5W.cjs → typescriptParser-JawJ8wET.cjs} +5 -31
  42. package/dist/{typescriptParser-BBGeFKlP.js.map → typescriptParser-JawJ8wET.cjs.map} +1 -1
  43. package/package.json +1 -1
  44. package/src/App.ts +9 -12
  45. package/src/FileProcessor.ts +19 -22
  46. package/src/createApp.ts +1 -13
  47. package/src/defineApp.ts +17 -32
  48. package/src/plugins/fsPlugin.ts +15 -11
  49. package/src/plugins/types.ts +2 -2
  50. package/dist/defineApp-D3B0bU-z.d.cts +0 -14
  51. package/dist/defineApp-DJVMk9lc.d.ts +0 -14
  52. package/dist/tsxParser-C741ZKCN.js +0 -26
  53. package/dist/tsxParser-C741ZKCN.js.map +0 -1
  54. package/dist/tsxParser-HDf_3TMc.cjs +0 -37
  55. package/dist/tsxParser-HDf_3TMc.cjs.map +0 -1
  56. package/dist/typescriptParser-BBbbmG5W.cjs.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"plugins.cjs","names":["fs","path","data"],"sources":["../src/plugins/createPlugin.ts","../src/plugins/fsPlugin.ts"],"sourcesContent":["import type { Plugin, UserPlugin } from './types.ts'\n\nexport function createPlugin<Options = any[], TAppExtension extends Record<string, any> = {}>(\n plugin: UserPlugin<Options, TAppExtension>,\n): Plugin<Options, TAppExtension> {\n return {\n type: 'plugin',\n ...plugin,\n }\n}\n","import { createPlugin } from './createPlugin.ts'\nimport { switcher } from 'js-runtime'\nimport fs from 'fs-extra'\nimport { resolve } from 'node:path'\nimport type * as KubbFile from '../KubbFile.ts'\n\ntype Options = {\n /**\n * Optional callback that is invoked whenever a file is written by the plugin.\n * Useful for tests to observe write operations without spying on internal functions.\n */\n onWrite?: (path: string, data: string) => void | Promise<void>\n}\n\nexport async function write(path: string, data: string, options: { sanity?: boolean } = {}): Promise<string | undefined> {\n if (data.trim() === '') {\n return undefined\n }\n return switcher(\n {\n node: async (path: string, data: string, { sanity }: { sanity?: boolean }) => {\n try {\n const oldContent = await fs.readFile(resolve(path), {\n encoding: 'utf-8',\n })\n if (oldContent?.toString() === data?.toString()) {\n return\n }\n } catch (_err) {\n /* empty */\n }\n\n await fs.outputFile(resolve(path), data, { encoding: 'utf-8' })\n\n if (sanity) {\n const savedData = await fs.readFile(resolve(path), {\n encoding: 'utf-8',\n })\n\n if (savedData?.toString() !== data?.toString()) {\n throw new Error(`Sanity check failed for ${path}\\n\\nData[${data.length}]:\\n${data}\\n\\nSaved[${savedData.length}]:\\n${savedData}\\n`)\n }\n\n return savedData\n }\n\n return data\n },\n bun: async (path: string, data: string, { sanity }: { sanity?: boolean }) => {\n try {\n await Bun.write(resolve(path), data)\n\n if (sanity) {\n const file = Bun.file(resolve(path))\n const savedData = await file.text()\n\n if (savedData?.toString() !== data?.toString()) {\n throw new Error(`Sanity check failed for ${path}\\n\\nData[${path.length}]:\\n${path}\\n\\nSaved[${savedData.length}]:\\n${savedData}\\n`)\n }\n\n return savedData\n }\n\n return data\n } catch (e) {\n console.error(e)\n }\n },\n },\n 'node',\n )(path, data.trim(), options)\n}\n\ntype WriteOptions = {\n extension?: Record<KubbFile.Extname, KubbFile.Extname | ''>\n dryRun?: boolean\n}\n\ndeclare module '../index.ts' {\n interface App {\n write(options?: WriteOptions): Promise<void>\n }\n}\n\nexport const fsPlugin = createPlugin<Options, { write(options?: WriteOptions): Promise<void> }>({\n name: 'fs',\n scope: 'write',\n async install(_app, context, options) {\n context.events.on('process:progress', async ({ file, source }) => {\n if (options?.onWrite) {\n await options.onWrite(file.path, source)\n }\n await write(file.path, source, { sanity: false })\n })\n },\n override(_app, context) {\n return {\n async write(\n options = {\n extension: { '.ts': '.ts' },\n dryRun: false,\n },\n ) {\n await context.fileManager.write({\n extension: options.extension,\n dryRun: options.dryRun,\n parsers: context.installedParsers,\n })\n },\n }\n },\n})\n"],"mappings":";;;;;;;;;AAEA,SAAgB,aACd,QACgC;AAChC,QAAO;EACL,MAAM;EACN,GAAG;EACJ;;;;;ACMH,eAAsB,MAAM,MAAc,MAAc,UAAgC,EAAE,EAA+B;AACvH,KAAI,KAAK,MAAM,KAAK,GAClB;AAEF,iCACE;EACE,MAAM,OAAO,QAAc,QAAc,EAAE,aAAmC;AAC5E,OAAI;IACF,MAAM,aAAa,MAAMA,iBAAG,gCAAiBC,OAAK,EAAE,EAClD,UAAU,SACX,CAAC;AACF,iEAAI,WAAY,UAAU,uDAAKC,OAAM,UAAU,EAC7C;YAEK,MAAM;AAIf,SAAMF,iBAAG,kCAAmBC,OAAK,EAAEC,QAAM,EAAE,UAAU,SAAS,CAAC;AAE/D,OAAI,QAAQ;IACV,MAAM,YAAY,MAAMF,iBAAG,gCAAiBC,OAAK,EAAE,EACjD,UAAU,SACX,CAAC;AAEF,+DAAI,UAAW,UAAU,uDAAKC,OAAM,UAAU,EAC5C,OAAM,IAAI,MAAM,2BAA2BD,OAAK,WAAWC,OAAK,OAAO,MAAMA,OAAK,YAAY,UAAU,OAAO,MAAM,UAAU,IAAI;AAGrI,WAAO;;AAGT,UAAOA;;EAET,KAAK,OAAO,QAAc,QAAc,EAAE,aAAmC;AAC3E,OAAI;AACF,UAAM,IAAI,6BAAcD,OAAK,EAAEC,OAAK;AAEpC,QAAI,QAAQ;KAEV,MAAM,YAAY,MADL,IAAI,4BAAaD,OAAK,CAAC,CACP,MAAM;AAEnC,gEAAI,UAAW,UAAU,uDAAKC,OAAM,UAAU,EAC5C,OAAM,IAAI,MAAM,2BAA2BD,OAAK,WAAWA,OAAK,OAAO,MAAMA,OAAK,YAAY,UAAU,OAAO,MAAM,UAAU,IAAI;AAGrI,YAAO;;AAGT,WAAOC;YACA,GAAG;AACV,YAAQ,MAAM,EAAE;;;EAGrB,EACD,OACD,CAAC,MAAM,KAAK,MAAM,EAAE,QAAQ;;AAc/B,MAAa,WAAW,aAAwE;CAC9F,MAAM;CACN,OAAO;CACP,MAAM,QAAQ,MAAM,SAAS,SAAS;AACpC,UAAQ,OAAO,GAAG,oBAAoB,OAAO,EAAE,MAAM,aAAa;AAChE,yDAAI,QAAS,QACX,OAAM,QAAQ,QAAQ,KAAK,MAAM,OAAO;AAE1C,SAAM,MAAM,KAAK,MAAM,QAAQ,EAAE,QAAQ,OAAO,CAAC;IACjD;;CAEJ,SAAS,MAAM,SAAS;AACtB,SAAO,EACL,MAAM,MACJ,UAAU;GACR,WAAW,EAAE,OAAO,OAAO;GAC3B,QAAQ;GACT,EACD;AACA,SAAM,QAAQ,YAAY,MAAM;IAC9B,WAAW,QAAQ;IACnB,QAAQ,QAAQ;IAChB,SAAS,QAAQ;IAClB,CAAC;KAEL;;CAEJ,CAAC"}
1
+ {"version":3,"file":"plugins.cjs","names":["fs","path","data"],"sources":["../src/plugins/createPlugin.ts","../src/plugins/fsPlugin.ts"],"sourcesContent":["import type { Plugin, UserPlugin } from './types.ts'\n\nexport function createPlugin<Options = any[], TAppExtension extends Record<string, any> = {}>(\n plugin: UserPlugin<Options, TAppExtension>,\n): Plugin<Options, TAppExtension> {\n return {\n type: 'plugin',\n ...plugin,\n }\n}\n","import { createPlugin } from './createPlugin.ts'\nimport { switcher } from 'js-runtime'\nimport fs from 'fs-extra'\nimport { resolve } from 'node:path'\nimport type * as KubbFile from '../KubbFile.ts'\n\ntype WriteOptions = {\n extension?: Record<KubbFile.Extname, KubbFile.Extname | ''>\n dryRun?: boolean\n}\n\ntype Options = {\n /**\n * Optional callback that is invoked whenever a file is written by the plugin.\n * Useful for tests to observe write operations without spying on internal functions.\n */\n onWrite?: (path: string, data: string) => void | Promise<void>\n}\n\ntype ExtendOptions = {\n write(options?: WriteOptions): Promise<void>\n}\n\nexport async function write(path: string, data: string, options: { sanity?: boolean } = {}): Promise<string | undefined> {\n if (data.trim() === '') {\n return undefined\n }\n return switcher(\n {\n node: async (path: string, data: string, { sanity }: { sanity?: boolean }) => {\n try {\n const oldContent = await fs.readFile(resolve(path), {\n encoding: 'utf-8',\n })\n if (oldContent?.toString() === data?.toString()) {\n return\n }\n } catch (_err) {\n /* empty */\n }\n\n await fs.outputFile(resolve(path), data, { encoding: 'utf-8' })\n\n if (sanity) {\n const savedData = await fs.readFile(resolve(path), {\n encoding: 'utf-8',\n })\n\n if (savedData?.toString() !== data?.toString()) {\n throw new Error(`Sanity check failed for ${path}\\n\\nData[${data.length}]:\\n${data}\\n\\nSaved[${savedData.length}]:\\n${savedData}\\n`)\n }\n\n return savedData\n }\n\n return data\n },\n bun: async (path: string, data: string, { sanity }: { sanity?: boolean }) => {\n try {\n await Bun.write(resolve(path), data)\n\n if (sanity) {\n const file = Bun.file(resolve(path))\n const savedData = await file.text()\n\n if (savedData?.toString() !== data?.toString()) {\n throw new Error(`Sanity check failed for ${path}\\n\\nData[${path.length}]:\\n${path}\\n\\nSaved[${savedData.length}]:\\n${savedData}\\n`)\n }\n\n return savedData\n }\n\n return data\n } catch (e) {\n console.error(e)\n }\n },\n },\n 'node',\n )(path, data.trim(), options)\n}\n\ndeclare module '../index.ts' {\n interface App {\n write(options?: WriteOptions): Promise<void>\n }\n}\n\nexport const fsPlugin = createPlugin<Options, ExtendOptions>({\n name: 'fs',\n scope: 'write',\n async install(app, options) {\n app.context.events.on('process:progress', async ({ file, source }) => {\n if (options?.onWrite) {\n await options.onWrite(file.path, source)\n }\n await write(file.path, source, { sanity: false })\n })\n },\n inject(app) {\n return {\n async write(\n options = {\n extension: { '.ts': '.ts' },\n dryRun: false,\n },\n ) {\n await app.context.fileManager.write({\n extension: options.extension,\n dryRun: options.dryRun,\n parsers: app.context.installedParsers,\n })\n },\n }\n },\n})\n"],"mappings":";;;;;;;;;AAEA,SAAgB,aACd,QACgC;AAChC,QAAO;EACL,MAAM;EACN,GAAG;EACJ;;;;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O,EAAE,MAAM,aAAa;AACpE,yDAAI,QAAS,QACX,OAAM,QAAQ,QAAQ,KAAK,MAAM,OAAO;AAE1C,SAAM,MAAM,KAAK,MAAM,QAAQ,EAAE,QAAQ,OAAO,CAAC;IACjD;;CAEJ,OAAO,KAAK;AACV,SAAO,EACL,MAAM,MACJ,UAAU;GACR,WAAW,EAAE,OAAO,OAAO;GAC3B,QAAQ;GACT,EACD;AACA,SAAM,IAAI,QAAQ,YAAY,MAAM;IAClC,WAAW,QAAQ;IACnB,QAAQ,QAAQ;IAChB,SAAS,IAAI,QAAQ;IACtB,CAAC;KAEL;;CAEJ,CAAC"}
@@ -1,9 +1,13 @@
1
- import { c as Plugin, l as UserPlugin, u as Extname } from "./App-zyf9KG3p.cjs";
1
+ import { c as Plugin, l as UserPlugin, u as Extname } from "./App-D3DHa4Il.cjs";
2
2
 
3
3
  //#region src/plugins/createPlugin.d.ts
4
4
  declare function createPlugin<Options$1 = any[], TAppExtension extends Record<string, any> = {}>(plugin: UserPlugin<Options$1, TAppExtension>): Plugin<Options$1, TAppExtension>;
5
5
  //#endregion
6
6
  //#region src/plugins/fsPlugin.d.ts
7
+ type WriteOptions = {
8
+ extension?: Record<Extname, Extname | ''>;
9
+ dryRun?: boolean;
10
+ };
7
11
  type Options = {
8
12
  /**
9
13
  * Optional callback that is invoked whenever a file is written by the plugin.
@@ -11,18 +15,15 @@ type Options = {
11
15
  */
12
16
  onWrite?: (path: string, data: string) => void | Promise<void>;
13
17
  };
14
- type WriteOptions = {
15
- extension?: Record<Extname, Extname | ''>;
16
- dryRun?: boolean;
18
+ type ExtendOptions = {
19
+ write(options?: WriteOptions): Promise<void>;
17
20
  };
18
21
  declare module '../index.ts' {
19
22
  interface App {
20
23
  write(options?: WriteOptions): Promise<void>;
21
24
  }
22
25
  }
23
- declare const fsPlugin: Plugin<Options, {
24
- write(options?: WriteOptions): Promise<void>;
25
- }>;
26
+ declare const fsPlugin: Plugin<Options, ExtendOptions>;
26
27
  //#endregion
27
28
  export { createPlugin, fsPlugin };
28
29
  //# sourceMappingURL=plugins.d.cts.map
package/dist/plugins.d.ts CHANGED
@@ -1,9 +1,13 @@
1
- import { c as Plugin, l as UserPlugin, u as Extname } from "./App-DZuROf6f.js";
1
+ import { c as Plugin, l as UserPlugin, u as Extname } from "./App-BxAl3dNP.js";
2
2
 
3
3
  //#region src/plugins/createPlugin.d.ts
4
4
  declare function createPlugin<Options$1 = any[], TAppExtension extends Record<string, any> = {}>(plugin: UserPlugin<Options$1, TAppExtension>): Plugin<Options$1, TAppExtension>;
5
5
  //#endregion
6
6
  //#region src/plugins/fsPlugin.d.ts
7
+ type WriteOptions = {
8
+ extension?: Record<Extname, Extname | ''>;
9
+ dryRun?: boolean;
10
+ };
7
11
  type Options = {
8
12
  /**
9
13
  * Optional callback that is invoked whenever a file is written by the plugin.
@@ -11,18 +15,15 @@ type Options = {
11
15
  */
12
16
  onWrite?: (path: string, data: string) => void | Promise<void>;
13
17
  };
14
- type WriteOptions = {
15
- extension?: Record<Extname, Extname | ''>;
16
- dryRun?: boolean;
18
+ type ExtendOptions = {
19
+ write(options?: WriteOptions): Promise<void>;
17
20
  };
18
21
  declare module '../index.ts' {
19
22
  interface App {
20
23
  write(options?: WriteOptions): Promise<void>;
21
24
  }
22
25
  }
23
- declare const fsPlugin: Plugin<Options, {
24
- write(options?: WriteOptions): Promise<void>;
25
- }>;
26
+ declare const fsPlugin: Plugin<Options, ExtendOptions>;
26
27
  //#endregion
27
28
  export { createPlugin, fsPlugin };
28
29
  //# sourceMappingURL=plugins.d.ts.map
package/dist/plugins.js CHANGED
@@ -46,21 +46,21 @@ async function write(path$1, data, options = {}) {
46
46
  const fsPlugin = createPlugin({
47
47
  name: "fs",
48
48
  scope: "write",
49
- async install(_app, context, options) {
50
- context.events.on("process:progress", async ({ file, source }) => {
49
+ async install(app, options) {
50
+ app.context.events.on("process:progress", async ({ file, source }) => {
51
51
  if (options === null || options === void 0 ? void 0 : options.onWrite) await options.onWrite(file.path, source);
52
52
  await write(file.path, source, { sanity: false });
53
53
  });
54
54
  },
55
- override(_app, context) {
55
+ inject(app) {
56
56
  return { async write(options = {
57
57
  extension: { ".ts": ".ts" },
58
58
  dryRun: false
59
59
  }) {
60
- await context.fileManager.write({
60
+ await app.context.fileManager.write({
61
61
  extension: options.extension,
62
62
  dryRun: options.dryRun,
63
- parsers: context.installedParsers
63
+ parsers: app.context.installedParsers
64
64
  });
65
65
  } };
66
66
  }
@@ -1 +1 @@
1
- {"version":3,"file":"plugins.js","names":["path","data"],"sources":["../src/plugins/createPlugin.ts","../src/plugins/fsPlugin.ts"],"sourcesContent":["import type { Plugin, UserPlugin } from './types.ts'\n\nexport function createPlugin<Options = any[], TAppExtension extends Record<string, any> = {}>(\n plugin: UserPlugin<Options, TAppExtension>,\n): Plugin<Options, TAppExtension> {\n return {\n type: 'plugin',\n ...plugin,\n }\n}\n","import { createPlugin } from './createPlugin.ts'\nimport { switcher } from 'js-runtime'\nimport fs from 'fs-extra'\nimport { resolve } from 'node:path'\nimport type * as KubbFile from '../KubbFile.ts'\n\ntype Options = {\n /**\n * Optional callback that is invoked whenever a file is written by the plugin.\n * Useful for tests to observe write operations without spying on internal functions.\n */\n onWrite?: (path: string, data: string) => void | Promise<void>\n}\n\nexport async function write(path: string, data: string, options: { sanity?: boolean } = {}): Promise<string | undefined> {\n if (data.trim() === '') {\n return undefined\n }\n return switcher(\n {\n node: async (path: string, data: string, { sanity }: { sanity?: boolean }) => {\n try {\n const oldContent = await fs.readFile(resolve(path), {\n encoding: 'utf-8',\n })\n if (oldContent?.toString() === data?.toString()) {\n return\n }\n } catch (_err) {\n /* empty */\n }\n\n await fs.outputFile(resolve(path), data, { encoding: 'utf-8' })\n\n if (sanity) {\n const savedData = await fs.readFile(resolve(path), {\n encoding: 'utf-8',\n })\n\n if (savedData?.toString() !== data?.toString()) {\n throw new Error(`Sanity check failed for ${path}\\n\\nData[${data.length}]:\\n${data}\\n\\nSaved[${savedData.length}]:\\n${savedData}\\n`)\n }\n\n return savedData\n }\n\n return data\n },\n bun: async (path: string, data: string, { sanity }: { sanity?: boolean }) => {\n try {\n await Bun.write(resolve(path), data)\n\n if (sanity) {\n const file = Bun.file(resolve(path))\n const savedData = await file.text()\n\n if (savedData?.toString() !== data?.toString()) {\n throw new Error(`Sanity check failed for ${path}\\n\\nData[${path.length}]:\\n${path}\\n\\nSaved[${savedData.length}]:\\n${savedData}\\n`)\n }\n\n return savedData\n }\n\n return data\n } catch (e) {\n console.error(e)\n }\n },\n },\n 'node',\n )(path, data.trim(), options)\n}\n\ntype WriteOptions = {\n extension?: Record<KubbFile.Extname, KubbFile.Extname | ''>\n dryRun?: boolean\n}\n\ndeclare module '../index.ts' {\n interface App {\n write(options?: WriteOptions): Promise<void>\n }\n}\n\nexport const fsPlugin = createPlugin<Options, { write(options?: WriteOptions): Promise<void> }>({\n name: 'fs',\n scope: 'write',\n async install(_app, context, options) {\n context.events.on('process:progress', async ({ file, source }) => {\n if (options?.onWrite) {\n await options.onWrite(file.path, source)\n }\n await write(file.path, source, { sanity: false })\n })\n },\n override(_app, context) {\n return {\n async write(\n options = {\n extension: { '.ts': '.ts' },\n dryRun: false,\n },\n ) {\n await context.fileManager.write({\n extension: options.extension,\n dryRun: options.dryRun,\n parsers: context.installedParsers,\n })\n },\n }\n },\n})\n"],"mappings":";;;;;AAEA,SAAgB,aACd,QACgC;AAChC,QAAO;EACL,MAAM;EACN,GAAG;EACJ;;;;;ACMH,eAAsB,MAAM,QAAc,MAAc,UAAgC,EAAE,EAA+B;AACvH,KAAI,KAAK,MAAM,KAAK,GAClB;AAEF,QAAO,SACL;EACE,MAAM,OAAO,QAAc,QAAc,EAAE,aAAmC;AAC5E,OAAI;IACF,MAAM,aAAa,MAAM,GAAG,SAAS,QAAQA,OAAK,EAAE,EAClD,UAAU,SACX,CAAC;AACF,iEAAI,WAAY,UAAU,uDAAKC,OAAM,UAAU,EAC7C;YAEK,MAAM;AAIf,SAAM,GAAG,WAAW,QAAQ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Q;IACnB,QAAQ,QAAQ;IAChB,SAAS,QAAQ;IAClB,CAAC;KAEL;;CAEJ,CAAC"}
1
+ {"version":3,"file":"plugins.js","names":["path","data"],"sources":["../src/plugins/createPlugin.ts","../src/plugins/fsPlugin.ts"],"sourcesContent":["import type { Plugin, UserPlugin } from './types.ts'\n\nexport function createPlugin<Options = any[], TAppExtension extends Record<string, any> = {}>(\n plugin: UserPlugin<Options, TAppExtension>,\n): Plugin<Options, TAppExtension> {\n return {\n type: 'plugin',\n ...plugin,\n }\n}\n","import { createPlugin } from './createPlugin.ts'\nimport { switcher } from 'js-runtime'\nimport fs from 'fs-extra'\nimport { resolve } from 'node:path'\nimport type * as KubbFile from '../KubbFile.ts'\n\ntype WriteOptions = {\n extension?: Record<KubbFile.Extname, KubbFile.Extname | ''>\n dryRun?: boolean\n}\n\ntype Options = {\n /**\n * Optional callback that is invoked whenever a file is written by the plugin.\n * Useful for tests to observe write operations without spying on internal functions.\n */\n onWrite?: (path: string, data: string) => void | Promise<void>\n}\n\ntype ExtendOptions = {\n write(options?: WriteOptions): Promise<void>\n}\n\nexport async function write(path: string, data: string, options: { sanity?: boolean } = {}): Promise<string | undefined> {\n if (data.trim() === '') {\n return undefined\n }\n return switcher(\n {\n node: async (path: string, data: string, { sanity }: { sanity?: boolean }) => {\n try {\n const oldContent = await fs.readFile(resolve(path), {\n encoding: 'utf-8',\n })\n if (oldContent?.toString() === data?.toString()) {\n return\n }\n } catch (_err) {\n /* empty */\n }\n\n await fs.outputFile(resolve(path), data, { encoding: 'utf-8' })\n\n if (sanity) {\n const savedData = await fs.readFile(resolve(path), {\n encoding: 'utf-8',\n })\n\n if (savedData?.toString() !== data?.toString()) {\n throw new Error(`Sanity check failed for ${path}\\n\\nData[${data.length}]:\\n${data}\\n\\nSaved[${savedData.length}]:\\n${savedData}\\n`)\n }\n\n return savedData\n }\n\n return data\n },\n bun: async (path: string, data: string, { sanity }: { sanity?: boolean }) => {\n try {\n await Bun.write(resolve(path), data)\n\n if (sanity) {\n const file = Bun.file(resolve(path))\n const savedData = await file.text()\n\n if (savedData?.toString() !== data?.toString()) {\n throw new Error(`Sanity check failed for ${path}\\n\\nData[${path.length}]:\\n${path}\\n\\nSaved[${savedData.length}]:\\n${savedData}\\n`)\n }\n\n return savedData\n }\n\n return data\n } catch (e) {\n console.error(e)\n }\n },\n },\n 'node',\n )(path, data.trim(), options)\n}\n\ndeclare module '../index.ts' {\n interface App {\n write(options?: WriteOptions): Promise<void>\n }\n}\n\nexport const fsPlugin = createPlugin<Options, ExtendOptions>({\n name: 'fs',\n scope: 'write',\n async install(app, options) {\n app.context.events.on('process:progress', async ({ file, source }) => {\n if (options?.onWrite) {\n await options.onWrite(file.path, source)\n }\n await write(file.path, source, { sanity: false })\n })\n },\n inject(app) {\n return {\n async write(\n options = {\n extension: { '.ts': '.ts' },\n dryRun: false,\n },\n ) {\n await app.context.fileManager.write({\n extension: options.extension,\n dryRun: options.dryRun,\n parsers: app.context.installedParsers,\n })\n },\n }\n },\n})\n"],"mappings":";;;;;AAEA,SAAgB,aACd,QACgC;AAChC,QAAO;EACL,MAAM;EACN,GAAG;EACJ;;;;;ACeH,eAAsB,MAAM,QAAc,MAAc,UAAgC,EAAE,EAA+B;AACvH,KAAI,KAAK,MAAM,KAAK,GAClB;AAEF,QAAO,SACL;EACE,MAAM,OAAO,QAAc,QAAc,EAAE,aAAmC;AAC5E,OAAI;IACF,MAAM,aAAa,MAAM,GAAG,SAAS,QAAQA,OAAK,EAAE,EAClD,UAAU,SACX,CAAC;AACF,iEAAI,WAAY,UAAU,uDAAKC,OAAM,UAAU,EAC7C;YAEK,MAAM;AAIf,SAAM,GAAG,WAAW,QAAQD,OAAK,EAAEC,QAAM,EAAE,UAAU,SAAS,CAAC;AAE/D,OAAI,QAAQ;IACV,MAAM,YAAY,MAAM,GAAG,SAAS,QAAQD,OAAK,EAAE,EACjD,UAAU,SACX,CAAC;AAEF,+DAAI,UAAW,UAAU,uDAAKC,OAAM,UAAU,E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efineApp } from "./defineApp-D3B0bU-z.cjs";
1
+ import { f as KubbFile_d_exports, n as AppContext, t as App } from "./App-D3DHa4Il.cjs";
2
+ import { t as DefineApp } from "./defineApp-BP97CT5p.cjs";
3
3
  export { type App, type AppContext, type DefineApp, KubbFile_d_exports as KubbFile };
package/dist/types.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import { f as KubbFile_d_exports, n as AppContext, t as App } from "./App-DZuROf6f.js";
2
- import { t as DefineApp } from "./defineApp-DJVMk9lc.js";
1
+ import { f as KubbFile_d_exports, n as AppContext, t as App } from "./App-BxAl3dNP.js";
2
+ import { t as DefineApp } from "./defineApp-B9W1A5SV.js";
3
3
  export { type App, type AppContext, type DefineApp, KubbFile_d_exports as KubbFile };
@@ -1,4 +1,4 @@
1
- import { o as Parser } from "./App-zyf9KG3p.cjs";
1
+ import { o as Parser } from "./App-D3DHa4Il.cjs";
2
2
  import ts from "typescript";
3
3
 
4
4
  //#region src/parsers/typescriptParser.d.ts
@@ -47,4 +47,4 @@ declare function createExport({
47
47
  declare const typescriptParser: Parser<[], any>;
48
48
  //#endregion
49
49
  export { typescriptParser as i, createImport as n, print as r, createExport as t };
50
- //# sourceMappingURL=typescriptParser-C-sBy1iR.d.cts.map
50
+ //# sourceMappingURL=typescriptParser--N0n8KFn.d.cts.map
@@ -1,4 +1,4 @@
1
- import { o as Parser } from "./App-DZuROf6f.js";
1
+ import { o as Parser } from "./App-BxAl3dNP.js";
2
2
  import ts from "typescript";
3
3
 
4
4
  //#region src/parsers/typescriptParser.d.ts
@@ -47,4 +47,4 @@ declare function createExport({
47
47
  declare const typescriptParser: Parser<[], any>;
48
48
  //#endregion
49
49
  export { typescriptParser as i, createImport as n, print as r, createExport as t };
50
- //# sourceMappingURL=typescriptParser-CtMmz0UV.d.ts.map
50
+ //# sourceMappingURL=typescriptParser-CctRhsng.d.ts.map
@@ -1,21 +1,7 @@
1
+ import { n as trimExtName, t as createParser } from "./createParser-B_RpW6sx.js";
1
2
  import path, { normalize, relative } from "node:path";
2
3
  import ts from "typescript";
3
4
 
4
- //#region src/utils/trimExtName.ts
5
- function trimExtName(text) {
6
- return text.replace(/\.[^/.]+$/, "");
7
- }
8
-
9
- //#endregion
10
- //#region src/parsers/createParser.ts
11
- function createParser(parser) {
12
- return {
13
- type: "parser",
14
- ...parser
15
- };
16
- }
17
-
18
- //#endregion
19
5
  //#region src/utils/getRelativePath.ts
20
6
  function slash(path$1, platform = "linux") {
21
7
  const isWindowsPath = /^\\\\\?\\/.test(path$1);
@@ -129,5 +115,5 @@ const typescriptParser = createParser({
129
115
  });
130
116
 
131
117
  //#endregion
132
- export { createParser as a, typescriptParser as i, createImport as n, trimExtName as o, print as r, createExport as t };
133
- //# sourceMappingURL=typescriptParser-BBGeFKlP.js.map
118
+ export { typescriptParser as i, createImport as n, print as r, createExport as t };
119
+ //# sourceMappingURL=typescriptParser-CrzOv_Aw.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typescriptParser-CrzOv_Aw.js","names":["path","output: string","path","importPropertyName: ts.Identifier | undefined","importName: ts.NamedImportBindings | undefined"],"sources":["../src/utils/getRelativePath.ts","../src/parsers/typescriptParser.ts"],"sourcesContent":["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","import ts from 'typescript'\nimport { getRelativePath } from '../utils/getRelativePath.ts'\nimport { trimExtName } from '../utils/trimExtName.ts'\nimport path from 'node:path'\nimport { createParser } from './createParser.ts'\n\nconst { factory } = ts\n\ntype PrintOptions = {\n source?: string\n baseName?: string\n scriptKind?: ts.ScriptKind\n}\n\n/**\n * Escaped new lines in code with block comments so they can be restored by {@link restoreNewLines}\n */\nconst escapeNewLines = (code: string) => code.replace(/\\n\\n/g, '\\n/* :newline: */')\n\n/**\n * Reverses {@link escapeNewLines} and restores new lines\n */\nconst restoreNewLines = (code: string) => code.replace(/\\/\\* :newline: \\*\\//g, '\\n')\n\n/**\n * Convert AST TypeScript/TSX nodes to a string based on the TypeScript printer.\n * Ensures consistent output across environments.\n * Also works as a formatter when `source` is provided without `elements`.\n */\nexport function print(elements: Array<ts.Node> = [], { source = '', baseName = 'print.tsx', scriptKind = ts.ScriptKind.TSX }: PrintOptions = {}): string {\n const sourceFile = ts.createSourceFile(baseName, escapeNewLines(source), ts.ScriptTarget.ES2022, true, scriptKind)\n\n const printer = ts.createPrinter({\n omitTrailingSemicolon: true,\n newLine: ts.NewLineKind.LineFeed,\n removeComments: false,\n noEmitHelpers: true,\n })\n\n let output: string\n\n if (elements.length > 0) {\n // Print only provided nodes\n const nodes = elements.filter(Boolean).sort((a, b) => (a.pos ?? 0) - (b.pos ?? 0))\n output = printer.printList(ts.ListFormat.MultiLine, factory.createNodeArray(nodes), sourceFile)\n } else {\n // Format the whole file\n output = printer.printFile(sourceFile)\n }\n\n return restoreNewLines(output).replace(/\\r\\n/g, '\\n')\n}\n\nexport function createImport({\n name,\n path,\n root,\n isTypeOnly = false,\n isNameSpace = false,\n}: {\n name: string | Array<string | { propertyName: string; name?: string }>\n path: string\n root?: string\n isTypeOnly?: boolean\n isNameSpace?: boolean\n}) {\n const resolvePath = root ? getRelativePath(root, path) : path\n\n if (!Array.isArray(name)) {\n let importPropertyName: ts.Identifier | undefined = factory.createIdentifier(name)\n let importName: ts.NamedImportBindings | undefined\n\n if (isNameSpace) {\n importPropertyName = undefined\n importName = factory.createNamespaceImport(factory.createIdentifier(name))\n }\n\n return factory.createImportDeclaration(\n undefined,\n factory.createImportClause(isTypeOnly, importPropertyName, importName),\n factory.createStringLiteral(resolvePath),\n undefined,\n )\n }\n\n return factory.createImportDeclaration(\n undefined,\n factory.createImportClause(\n isTypeOnly,\n undefined,\n factory.createNamedImports(\n name.map((item) => {\n if (typeof item === 'object') {\n const obj = item as { propertyName: string; name?: string }\n if (obj.name) {\n return factory.createImportSpecifier(false, factory.createIdentifier(obj.propertyName), factory.createIdentifier(obj.name))\n }\n\n return factory.createImportSpecifier(false, undefined, factory.createIdentifier(obj.propertyName))\n }\n\n return factory.createImportSpecifier(false, undefined, factory.createIdentifier(item))\n }),\n ),\n ),\n factory.createStringLiteral(resolvePath),\n undefined,\n )\n}\n\nexport function createExport({\n path,\n asAlias,\n isTypeOnly = false,\n name,\n}: {\n path: string\n asAlias?: boolean\n isTypeOnly?: boolean\n name?: string | Array<ts.Identifier | string>\n}) {\n if (name && !Array.isArray(name) && !asAlias) {\n console.warn(`When using name as string, asAlias should be true ${name}`)\n }\n\n if (!Array.isArray(name)) {\n const parsedName = name?.match(/^\\d/) ? `_${name?.slice(1)}` : name\n\n return factory.createExportDeclaration(\n undefined,\n isTypeOnly,\n asAlias && parsedName ? factory.createNamespaceExport(factory.createIdentifier(parsedName)) : undefined,\n factory.createStringLiteral(path),\n undefined,\n )\n }\n\n return factory.createExportDeclaration(\n undefined,\n isTypeOnly,\n factory.createNamedExports(\n name.map((propertyName) => {\n return factory.createExportSpecifier(false, undefined, typeof propertyName === 'string' ? factory.createIdentifier(propertyName) : propertyName)\n }),\n ),\n factory.createStringLiteral(path),\n undefined,\n )\n}\n\nexport const typescriptParser = createParser({\n name: 'typescript',\n extNames: ['.ts', '.js'],\n install() {},\n async parse(file, options = { extname: '.ts' }) {\n const source = file.sources.map((item) => item.value).join('\\n\\n')\n\n const importNodes = file.imports\n .map((item) => {\n const importPath = item.root ? getRelativePath(item.root, item.path) : item.path\n const hasExtname = !!path.extname(importPath)\n\n return createImport({\n name: item.name,\n path: options.extname && hasExtname ? `${trimExtName(importPath)}${options.extname}` : item.root ? trimExtName(importPath) : importPath,\n isTypeOnly: item.isTypeOnly,\n })\n })\n .filter(Boolean)\n\n const exportNodes = file.exports\n .map((item) => {\n const exportPath = item.path\n\n const hasExtname = !!path.extname(exportPath)\n\n return createExport({\n name: item.name,\n path: options.extname && hasExtname ? `${trimExtName(item.path)}${options.extname}` : trimExtName(item.path),\n isTypeOnly: item.isTypeOnly,\n asAlias: item.asAlias,\n })\n })\n .filter(Boolean)\n\n return [file.banner, print([...importNodes, ...exportNodes]), source, file.footer].join('\\n')\n },\n})\n"],"mappings":";;;;;AAEA,SAAS,MAAM,QAAc,WAAwC,SAAS;CAC5E,MAAM,gBAAgB,YAAY,KAAKA,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;;;;;ACxBd,MAAM,EAAE,YAAY;;;;AAWpB,MAAM,kBAAkB,SAAiB,KAAK,QAAQ,SAAS,oB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KAAK,MAAM,KAAK,KAAK,GAAG,KAAK;GAC5E,MAAM,aAAa,CAAC,CAAC,KAAK,QAAQ,WAAW;AAE7C,UAAO,aAAa;IAClB,MAAM,KAAK;IACX,MAAM,QAAQ,WAAW,aAAa,GAAG,YAAY,WAAW,GAAG,QAAQ,YAAY,KAAK,OAAO,YAAY,WAAW,GAAG;IAC7H,YAAY,KAAK;IAClB,CAAC;IACF,CACD,OAAO,QAAQ;EAElB,MAAM,cAAc,KAAK,QACtB,KAAK,SAAS;GACb,MAAM,aAAa,KAAK;GAExB,MAAM,aAAa,CAAC,CAAC,KAAK,QAAQ,WAAW;AAE7C,UAAO,aAAa;IAClB,MAAM,KAAK;IACX,MAAM,QAAQ,WAAW,aAAa,GAAG,YAAY,KAAK,KAAK,GAAG,QAAQ,YAAY,YAAY,KAAK,KAAK;IAC5G,YAAY,KAAK;IACjB,SAAS,KAAK;IACf,CAAC;IACF,CACD,OAAO,QAAQ;AAElB,SAAO;GAAC,KAAK;GAAQ,MAAM,CAAC,GAAG,aAAa,GAAG,YAAY,CAAC;GAAE;GAAQ,KAAK;GAAO,CAAC,KAAK,KAAK;;CAEhG,CAAC"}
@@ -1,24 +1,10 @@
1
1
  const require_chunk = require('./chunk-CUT6urMc.cjs');
2
+ const require_createParser = require('./createParser-DZB5qExa.cjs');
2
3
  let node_path = require("node:path");
3
4
  node_path = require_chunk.__toESM(node_path);
4
5
  let typescript = require("typescript");
5
6
  typescript = require_chunk.__toESM(typescript);
6
7
 
7
- //#region src/utils/trimExtName.ts
8
- function trimExtName(text) {
9
- return text.replace(/\.[^/.]+$/, "");
10
- }
11
-
12
- //#endregion
13
- //#region src/parsers/createParser.ts
14
- function createParser(parser) {
15
- return {
16
- type: "parser",
17
- ...parser
18
- };
19
- }
20
-
21
- //#endregion
22
8
  //#region src/utils/getRelativePath.ts
23
9
  function slash(path$1, platform = "linux") {
24
10
  const isWindowsPath = /^\\\\\?\\/.test(path$1);
@@ -97,7 +83,7 @@ function createExport({ path: path$1, asAlias, isTypeOnly = false, name }) {
97
83
  return factory.createExportSpecifier(false, void 0, typeof propertyName === "string" ? factory.createIdentifier(propertyName) : propertyName);
98
84
  })), factory.createStringLiteral(path$1), void 0);
99
85
  }
100
- const typescriptParser = createParser({
86
+ const typescriptParser = require_createParser.createParser({
101
87
  name: "typescript",
102
88
  extNames: [".ts", ".js"],
103
89
  install() {},
@@ -108,7 +94,7 @@ const typescriptParser = createParser({
108
94
  const hasExtname = !!node_path.default.extname(importPath);
109
95
  return createImport({
110
96
  name: item.name,
111
- path: options.extname && hasExtname ? `${trimExtName(importPath)}${options.extname}` : item.root ? trimExtName(importPath) : importPath,
97
+ path: options.extname && hasExtname ? `${require_createParser.trimExtName(importPath)}${options.extname}` : item.root ? require_createParser.trimExtName(importPath) : importPath,
112
98
  isTypeOnly: item.isTypeOnly
113
99
  });
114
100
  }).filter(Boolean);
@@ -117,7 +103,7 @@ const typescriptParser = createParser({
117
103
  const hasExtname = !!node_path.default.extname(exportPath);
118
104
  return createExport({
119
105
  name: item.name,
120
- path: options.extname && hasExtname ? `${trimExtName(item.path)}${options.extname}` : trimExtName(item.path),
106
+ path: options.extname && hasExtname ? `${require_createParser.trimExtName(item.path)}${options.extname}` : require_createParser.trimExtName(item.path),
121
107
  isTypeOnly: item.isTypeOnly,
122
108
  asAlias: item.asAlias
123
109
  });
@@ -144,28 +130,16 @@ Object.defineProperty(exports, 'createImport', {
144
130
  return createImport;
145
131
  }
146
132
  });
147
- Object.defineProperty(exports, 'createParser', {
148
- enumerable: true,
149
- get: function () {
150
- return createParser;
151
- }
152
- });
153
133
  Object.defineProperty(exports, 'print', {
154
134
  enumerable: true,
155
135
  get: function () {
156
136
  return print;
157
137
  }
158
138
  });
159
- Object.defineProperty(exports, 'trimExtName', {
160
- enumerable: true,
161
- get: function () {
162
- return trimExtName;
163
- }
164
- });
165
139
  Object.defineProperty(exports, 'typescriptParser', {
166
140
  enumerable: true,
167
141
  get: function () {
168
142
  return typescriptParser;
169
143
  }
170
144
  });
171
- //# sourceMappingURL=typescriptParser-BBbbmG5W.cjs.map
145
+ //# sourceMappingURL=typescriptParser-JawJ8wET.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"typescriptParser-BBGeFKlP.js","names":["path","output: string","path","importPropertyName: ts.Identifier | undefined","importName: ts.NamedImportBindings | undefined"],"sources":["../src/utils/trimExtName.ts","../src/parsers/createParser.ts","../src/utils/getRelativePath.ts","../src/parsers/typescriptParser.ts"],"sourcesContent":["export function trimExtName(text: string): string {\n return text.replace(/\\.[^/.]+$/, '')\n}\n","import type { Parser, UserParser } from './types.ts'\n\nexport function createParser<TOptions = any[], TMeta extends object = any>(parser: UserParser<TOptions, TMeta>): Parser<TOptions, TMeta> {\n return {\n type: 'parser',\n ...parser,\n }\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","import ts from 'typescript'\nimport { getRelativePath } from '../utils/getRelativePath.ts'\nimport { trimExtName } from '../utils/trimExtName.ts'\nimport path from 'node:path'\nimport { createParser } from './createParser.ts'\n\nconst { factory } = ts\n\ntype PrintOptions = {\n source?: string\n baseName?: string\n scriptKind?: ts.ScriptKind\n}\n\n/**\n * Escaped new lines in code with block comments so they can be restored by {@link restoreNewLines}\n */\nconst escapeNewLines = (code: string) => code.replace(/\\n\\n/g, '\\n/* :newline: */')\n\n/**\n * Reverses {@link escapeNewLines} and restores new lines\n */\nconst restoreNewLines = (code: string) => code.replace(/\\/\\* :newline: \\*\\//g, '\\n')\n\n/**\n * Convert AST TypeScript/TSX nodes to a string based on the TypeScript printer.\n * Ensures consistent output across environments.\n * Also works as a formatter when `source` is provided without `elements`.\n */\nexport function print(elements: Array<ts.Node> = [], { source = '', baseName = 'print.tsx', scriptKind = ts.ScriptKind.TSX }: PrintOptions = {}): string {\n const sourceFile = ts.createSourceFile(baseName, escapeNewLines(source), ts.ScriptTarget.ES2022, true, scriptKind)\n\n const printer = ts.createPrinter({\n omitTrailingSemicolon: true,\n newLine: ts.NewLineKind.LineFeed,\n removeComments: false,\n noEmitHelpers: true,\n })\n\n let output: string\n\n if (elements.length > 0) {\n // Print only provided nodes\n const nodes = elements.filter(Boolean).sort((a, b) => (a.pos ?? 0) - (b.pos ?? 0))\n output = printer.printList(ts.ListFormat.MultiLine, factory.createNodeArray(nodes), sourceFile)\n } else {\n // Format the whole file\n output = printer.printFile(sourceFile)\n }\n\n return restoreNewLines(output).replace(/\\r\\n/g, '\\n')\n}\n\nexport function createImport({\n name,\n path,\n root,\n isTypeOnly = false,\n isNameSpace = false,\n}: {\n name: string | Array<string | { propertyName: string; name?: string }>\n path: string\n root?: string\n isTypeOnly?: boolean\n isNameSpace?: boolean\n}) {\n const resolvePath = root ? getRelativePath(root, path) : path\n\n if (!Array.isArray(name)) {\n let importPropertyName: ts.Identifier | undefined = factory.createIdentifier(name)\n let importName: ts.NamedImportBindings | undefined\n\n if (isNameSpace) {\n importPropertyName = undefined\n importName = factory.createNamespaceImport(factory.createIdentifier(name))\n }\n\n return factory.createImportDeclaration(\n undefined,\n factory.createImportClause(isTypeOnly, importPropertyName, importName),\n factory.createStringLiteral(resolvePath),\n undefined,\n )\n }\n\n return factory.createImportDeclaration(\n undefined,\n factory.createImportClause(\n isTypeOnly,\n undefined,\n factory.createNamedImports(\n name.map((item) => {\n if (typeof item === 'object') {\n const obj = item as { propertyName: string; name?: string }\n if (obj.name) {\n return factory.createImportSpecifier(false, factory.createIdentifier(obj.propertyName), factory.createIdentifier(obj.name))\n }\n\n return factory.createImportSpecifier(false, undefined, factory.createIdentifier(obj.propertyName))\n }\n\n return factory.createImportSpecifier(false, undefined, factory.createIdentifier(item))\n }),\n ),\n ),\n factory.createStringLiteral(resolvePath),\n undefined,\n )\n}\n\nexport function createExport({\n path,\n asAlias,\n isTypeOnly = false,\n name,\n}: {\n path: string\n asAlias?: boolean\n isTypeOnly?: boolean\n name?: string | Array<ts.Identifier | string>\n}) {\n if (name && !Array.isArray(name) && !asAlias) {\n console.warn(`When using name as string, asAlias should be true ${name}`)\n }\n\n if (!Array.isArray(name)) {\n const parsedName = name?.match(/^\\d/) ? `_${name?.slice(1)}` : name\n\n return factory.createExportDeclaration(\n undefined,\n isTypeOnly,\n asAlias && parsedName ? factory.createNamespaceExport(factory.createIdentifier(parsedName)) : undefined,\n factory.createStringLiteral(path),\n undefined,\n )\n }\n\n return factory.createExportDeclaration(\n undefined,\n isTypeOnly,\n factory.createNamedExports(\n name.map((propertyName) => {\n return factory.createExportSpecifier(false, undefined, typeof propertyName === 'string' ? factory.createIdentifier(propertyName) : propertyName)\n }),\n ),\n factory.createStringLiteral(path),\n undefined,\n )\n}\n\nexport const typescriptParser = createParser({\n name: 'typescript',\n extNames: ['.ts', '.js'],\n install() {},\n async parse(file, options = { extname: '.ts' }) {\n const source = file.sources.map((item) => item.value).join('\\n\\n')\n\n const importNodes = file.imports\n .map((item) => {\n const importPath = item.root ? getRelativePath(item.root, item.path) : item.path\n const hasExtname = !!path.extname(importPath)\n\n return createImport({\n name: item.name,\n path: options.extname && hasExtname ? `${trimExtName(importPath)}${options.extname}` : item.root ? trimExtName(importPath) : importPath,\n isTypeOnly: item.isTypeOnly,\n })\n })\n .filter(Boolean)\n\n const exportNodes = file.exports\n .map((item) => {\n const exportPath = item.path\n\n const hasExtname = !!path.extname(exportPath)\n\n return createExport({\n name: item.name,\n path: options.extname && hasExtname ? `${trimExtName(item.path)}${options.extname}` : trimExtName(item.path),\n isTypeOnly: item.isTypeOnly,\n asAlias: item.asAlias,\n })\n })\n .filter(Boolean)\n\n return [file.banner, print([...importNodes, ...exportNodes]), source, file.footer].join('\\n')\n },\n})\n"],"mappings":";;;;AAAA,SAAgB,YAAY,MAAsB;AAChD,QAAO,KAAK,QAAQ,aAAa,GAAG;;;;;ACCtC,SAAgB,aAA2D,QAA8D;AACvI,QAAO;EACL,MAAM;EACN,GAAG;EACJ;;;;;ACJH,SAAS,MAAM,QAAc,WAAwC,SAAS;CAC5E,MAAM,gBAAgB,YAAY,KAAKA,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;;;;;ACxBd,MAAM,EAAE,YAAY;;;;AAWpB,MAAM,kBAAkB,SAAiB,KAAK,QAAQ,SAAS,oBAAoB;;;;AAKnF,MAAM,mBAAmB,SAAiB,KAAK,QAAQ,wBAAwB,KAAK;;;;;;AAOpF,SAAgB,MAAM,WAA2B,EAA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a;IAClB,MAAM,KAAK;IACX,MAAM,QAAQ,WAAW,aAAa,GAAG,YAAY,WAAW,GAAG,QAAQ,YAAY,KAAK,OAAO,YAAY,WAAW,GAAG;IAC7H,YAAY,KAAK;IAClB,CAAC;IACF,CACD,OAAO,QAAQ;EAElB,MAAM,cAAc,KAAK,QACtB,KAAK,SAAS;GACb,MAAM,aAAa,KAAK;GAExB,MAAM,aAAa,CAAC,CAAC,KAAK,QAAQ,WAAW;AAE7C,UAAO,aAAa;IAClB,MAAM,KAAK;IACX,MAAM,QAAQ,WAAW,aAAa,GAAG,YAAY,KAAK,KAAK,GAAG,QAAQ,YAAY,YAAY,KAAK,KAAK;IAC5G,YAAY,KAAK;IACjB,SAAS,KAAK;IACf,CAAC;IACF,CACD,OAAO,QAAQ;AAElB,SAAO;GAAC,KAAK;GAAQ,MAAM,CAAC,GAAG,aAAa,GAAG,YAAY,CAAC;GAAE;GAAQ,KAAK;GAAO,CAAC,KAAK,KAAK;;CAEhG,CAAC"}
1
+ {"version":3,"file":"typescriptParser-JawJ8wET.cjs","names":["path","ts","output: string","path","importPropertyName: ts.Identifier | undefined","importName: ts.NamedImportBindings | undefined","createParser","trimExtName"],"sources":["../src/utils/getRelativePath.ts","../src/parsers/typescriptParser.ts"],"sourcesContent":["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","import ts from 'typescript'\nimport { getRelativePath } from '../utils/getRelativePath.ts'\nimport { trimExtName } from '../utils/trimExtName.ts'\nimport path from 'node:path'\nimport { createParser } from './createParser.ts'\n\nconst { factory } = ts\n\ntype PrintOptions = {\n source?: string\n baseName?: string\n scriptKind?: ts.ScriptKind\n}\n\n/**\n * Escaped new lines in code with block comments so they can be restored by {@link restoreNewLines}\n */\nconst escapeNewLines = (code: string) => code.replace(/\\n\\n/g, '\\n/* :newline: */')\n\n/**\n * Reverses {@link escapeNewLines} and restores new lines\n */\nconst restoreNewLines = (code: string) => code.replace(/\\/\\* :newline: \\*\\//g, '\\n')\n\n/**\n * Convert AST TypeScript/TSX nodes to a string based on the TypeScript printer.\n * Ensures consistent output across environments.\n * Also works as a formatter when `source` is provided without `elements`.\n */\nexport function print(elements: Array<ts.Node> = [], { source = '', baseName = 'print.tsx', scriptKind = ts.ScriptKind.TSX }: PrintOptions = {}): string {\n const sourceFile = ts.createSourceFile(baseName, escapeNewLines(source), ts.ScriptTarget.ES2022, true, scriptKind)\n\n const printer = ts.createPrinter({\n omitTrailingSemicolon: true,\n newLine: ts.NewLineKind.LineFeed,\n removeComments: false,\n noEmitHelpers: true,\n })\n\n let output: string\n\n if (elements.length > 0) {\n // Print only provided nodes\n const nodes = elements.filter(Boolean).sort((a, b) => (a.pos ?? 0) - (b.pos ?? 0))\n output = printer.printList(ts.ListFormat.MultiLine, factory.createNodeArray(nodes), sourceFile)\n } else {\n // Format the whole file\n output = printer.printFile(sourceFile)\n }\n\n return restoreNewLines(output).replace(/\\r\\n/g, '\\n')\n}\n\nexport function createImport({\n name,\n path,\n root,\n isTypeOnly = false,\n isNameSpace = false,\n}: {\n name: string | Array<string | { propertyName: string; name?: string }>\n path: string\n root?: string\n isTypeOnly?: boolean\n isNameSpace?: boolean\n}) {\n const resolvePath = root ? getRelativePath(root, path) : path\n\n if (!Array.isArray(name)) {\n let importPropertyName: ts.Identifier | undefined = factory.createIdentifier(name)\n let importName: ts.NamedImportBindings | undefined\n\n if (isNameSpace) {\n importPropertyName = undefined\n importName = factory.createNamespaceImport(factory.createIdentifier(name))\n }\n\n return factory.createImportDeclaration(\n undefined,\n factory.createImportClause(isTypeOnly, importPropertyName, importName),\n factory.createStringLiteral(resolvePath),\n undefined,\n )\n }\n\n return factory.createImportDeclaration(\n undefined,\n factory.createImportClause(\n isTypeOnly,\n undefined,\n factory.createNamedImports(\n name.map((item) => {\n if (typeof item === 'object') {\n const obj = item as { propertyName: string; name?: string }\n if (obj.name) {\n return factory.createImportSpecifier(false, factory.createIdentifier(obj.propertyName), factory.createIdentifier(obj.name))\n }\n\n return factory.createImportSpecifier(false, undefined, factory.createIdentifier(obj.propertyName))\n }\n\n return factory.createImportSpecifier(false, undefined, factory.createIdentifier(item))\n }),\n ),\n ),\n factory.createStringLiteral(resolvePath),\n undefined,\n )\n}\n\nexport function createExport({\n path,\n asAlias,\n isTypeOnly = false,\n name,\n}: {\n path: string\n asAlias?: boolean\n isTypeOnly?: boolean\n name?: string | Array<ts.Identifier | string>\n}) {\n if (name && !Array.isArray(name) && !asAlias) {\n console.warn(`When using name as string, asAlias should be true ${name}`)\n }\n\n if (!Array.isArray(name)) {\n const parsedName = name?.match(/^\\d/) ? `_${name?.slice(1)}` : name\n\n return factory.createExportDeclaration(\n undefined,\n isTypeOnly,\n asAlias && parsedName ? factory.createNamespaceExport(factory.createIdentifier(parsedName)) : undefined,\n factory.createStringLiteral(path),\n undefined,\n )\n }\n\n return factory.createExportDeclaration(\n undefined,\n isTypeOnly,\n factory.createNamedExports(\n name.map((propertyName) => {\n return factory.createExportSpecifier(false, undefined, typeof propertyName === 'string' ? factory.createIdentifier(propertyName) : propertyName)\n }),\n ),\n factory.createStringLiteral(path),\n undefined,\n )\n}\n\nexport const typescriptParser = createParser({\n name: 'typescript',\n extNames: ['.ts', '.js'],\n install() {},\n async parse(file, options = { extname: '.ts' }) {\n const source = file.sources.map((item) => item.value).join('\\n\\n')\n\n const importNodes = file.imports\n .map((item) => {\n const importPath = item.root ? getRelativePath(item.root, item.path) : item.path\n const hasExtname = !!path.extname(importPath)\n\n return createImport({\n name: item.name,\n path: options.extname && hasExtname ? `${trimExtName(importPath)}${options.extname}` : item.root ? trimExtName(importPath) : importPath,\n isTypeOnly: item.isTypeOnly,\n })\n })\n .filter(Boolean)\n\n const exportNodes = file.exports\n .map((item) => {\n const exportPath = item.path\n\n const hasExtname = !!path.extname(exportPath)\n\n return createExport({\n name: item.name,\n path: options.extname && hasExtname ? `${trimExtName(item.path)}${options.extname}` : trimExtName(item.path),\n isTypeOnly: item.isTypeOnly,\n asAlias: item.asAlias,\n })\n })\n .filter(Boolean)\n\n return [file.banner, print([...importNodes, ...exportNodes]), source, file.footer].join('\\n')\n },\n})\n"],"mappings":";;;;;;;;AAEA,SAAS,MAAM,QAAc,WAAwC,SAAS;CAC5E,MAAM,gBAAgB,YAAY,KAAKA,OAAK;CAC5C,MAAM,0CAA2BA,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,8BAJU,SAAS,SAAS,EAIR,SAAS;AAEjD,KAAI,YAAY,WAAW,MAAM,CAC/B,QAAO;AAGT,QAAO,KAAK;;;;;ACxBd,MAAM,EAAE,YAAYC;;;;AA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,KAAK,QACtB,KAAK,SAAS;GACb,MAAM,aAAa,KAAK,OAAO,gBAAgB,KAAK,MAAM,KAAK,KAAK,GAAG,KAAK;GAC5E,MAAM,aAAa,CAAC,CAACH,kBAAK,QAAQ,WAAW;AAE7C,UAAO,aAAa;IAClB,MAAM,KAAK;IACX,MAAM,QAAQ,WAAW,aAAa,GAAGI,iCAAY,WAAW,GAAG,QAAQ,YAAY,KAAK,OAAOA,iCAAY,WAAW,GAAG;IAC7H,YAAY,KAAK;IAClB,CAAC;IACF,CACD,OAAO,QAAQ;EAElB,MAAM,cAAc,KAAK,QACtB,KAAK,SAAS;GACb,MAAM,aAAa,KAAK;GAExB,MAAM,aAAa,CAAC,CAACJ,kBAAK,QAAQ,WAAW;AAE7C,UAAO,aAAa;IAClB,MAAM,KAAK;IACX,MAAM,QAAQ,WAAW,aAAa,GAAGI,iCAAY,KAAK,KAAK,GAAG,QAAQ,YAAYA,iCAAY,KAAK,KAAK;IAC5G,YAAY,KAAK;IACjB,SAAS,KAAK;IACf,CAAC;IACF,CACD,OAAO,QAAQ;AAElB,SAAO;GAAC,KAAK;GAAQ,MAAM,CAAC,GAAG,aAAa,GAAG,YAAY,CAAC;GAAE;GAAQ,KAAK;GAAO,CAAC,KAAK,KAAK;;CAEhG,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/fabric-core",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "Core functionality for Kubb's plugin-based code generation system, providing the foundation for transforming OpenAPI specifications.",
5
5
  "keywords": [
6
6
  "typescript",
package/src/App.ts CHANGED
@@ -63,21 +63,19 @@ export type AppContext<TOptions = unknown> = {
63
63
  }
64
64
 
65
65
  export type Install<TOptions = any[] | object | undefined> = TOptions extends any[]
66
- ? (app: App, context: AppContext, ...options: TOptions) => void
66
+ ? (app: App, ...options: TOptions) => void
67
67
  : TOptions extends object
68
- ? (app: App, context: AppContext, options?: TOptions) => void
69
- : (app: App, context: AppContext) => void
68
+ ? (app: App, options?: TOptions) => void
69
+ : (app: App) => void
70
70
 
71
- export type Override<TOptions = any[] | object | undefined, TAppExtension extends Record<string, any> = {}> = TOptions extends any[]
72
- ? (app: App, context: AppContext, ...options: TOptions) => Partial<TAppExtension>
71
+ export type Inject<TOptions = any[] | object | undefined, TAppExtension extends Record<string, any> = {}> = TOptions extends any[]
72
+ ? (app: App, ...options: TOptions) => Partial<TAppExtension>
73
73
  : TOptions extends object
74
- ? (app: App, context: AppContext, options?: TOptions) => Partial<TAppExtension>
75
- : (app: App, context: AppContext) => Partial<TAppExtension>
74
+ ? (app: App, options?: TOptions) => Partial<TAppExtension>
75
+ : (app: App) => Partial<TAppExtension>
76
76
 
77
- export interface App {
78
- _component: Component
79
- render(): Promise<void>
80
- renderToString(): Promise<string>
77
+ export interface App<TOptions = unknown> {
78
+ context: AppContext<TOptions>
81
79
  files: Array<KubbFile.ResolvedFile>
82
80
  use<TOptions extends any[] | object = any, TMeta extends object = object, TAppExtension extends Record<string, any> = {}>(
83
81
  pluginOrParser: Plugin<TOptions, TAppExtension> | Parser<TOptions, TMeta>,
@@ -87,5 +85,4 @@ export interface App {
87
85
  pluginOrParser: Plugin<TOptions, TAppExtension> | Parser<TOptions, TMeta>,
88
86
  ): this & TAppExtension
89
87
  addFile(...files: Array<KubbFile.File>): Promise<void>
90
- waitUntilExit(): Promise<void>
91
88
  }
@@ -1,13 +1,10 @@
1
1
  import type * as KubbFile from './KubbFile.ts'
2
2
  import pLimit from 'p-limit'
3
- import path from 'node:path'
4
3
 
5
4
  import type { Parser } from './parsers/types.ts'
6
5
  import { defaultParser } from './parsers/defaultParser.ts'
7
6
  import { AsyncEventEmitter } from './utils/AsyncEventEmitter.ts'
8
7
  import type { AppEvents } from './App.ts'
9
- import { typescriptParser } from './parsers/typescriptParser.ts'
10
- import { tsxParser } from './parsers/tsxParser.ts'
11
8
 
12
9
  export type ProcessFilesProps = {
13
10
  parsers?: Set<Parser>
@@ -17,7 +14,7 @@ export type ProcessFilesProps = {
17
14
 
18
15
  type GetParseOptions = {
19
16
  parsers?: Set<Parser>
20
- extname?: KubbFile.Extname
17
+ extension?: Record<KubbFile.Extname, KubbFile.Extname | ''>
21
18
  }
22
19
 
23
20
  type Options = {
@@ -34,27 +31,26 @@ export class FileProcessor {
34
31
  return this
35
32
  }
36
33
 
37
- get #defaultParser(): Set<Parser> {
38
- console.warn(`[parser] using default parsers, please consider using the "use" method to add custom parsers.`)
39
-
40
- return new Set<Parser>([typescriptParser, tsxParser, defaultParser])
41
- }
34
+ async parse(file: KubbFile.ResolvedFile, { parsers = new Set(), extension }: GetParseOptions = {}): Promise<string> {
35
+ const parseExtName = extension?.[file.extname] || undefined
42
36
 
43
- async parse(file: KubbFile.ResolvedFile, { parsers = this.#defaultParser, extname }: GetParseOptions = {}): Promise<string> {
44
- if (!extname) {
45
- console.warn('[parser] No extname found, default parser will be used')
46
- return defaultParser.parse(file, { extname })
37
+ if (!file.extname) {
38
+ return defaultParser.parse(file, { extname: parseExtName })
47
39
  }
48
40
 
49
- const parser = [...parsers].find((item) => item.extNames?.includes(extname))
41
+ let parser: Parser | undefined
42
+ for (const item of parsers) {
43
+ if (item.extNames?.includes(file.extname)) {
44
+ parser = item
45
+ break
46
+ }
47
+ }
50
48
 
51
49
  if (!parser) {
52
- console.warn(`[parser] No parser found for ${extname}, default parser will be used`)
53
-
54
- return defaultParser.parse(file, { extname })
50
+ return defaultParser.parse(file, { extname: parseExtName })
55
51
  }
56
52
 
57
- return parser.parse(file, { extname })
53
+ return parser.parse(file, { extname: parseExtName })
58
54
  }
59
55
 
60
56
  async run(files: Array<KubbFile.ResolvedFile>, { parsers, dryRun, extension }: ProcessFilesProps = {}): Promise<KubbFile.ResolvedFile[]> {
@@ -65,13 +61,14 @@ export class FileProcessor {
65
61
 
66
62
  const promises = files.map((resolvedFile, index) =>
67
63
  this.#limit(async () => {
68
- const extname = extension?.[resolvedFile.extname] || (path.extname(resolvedFile.path) as KubbFile.Extname)
69
-
70
64
  await this.events.emit('file:start', { file: resolvedFile, index, total })
71
65
 
72
66
  if (!dryRun) {
73
- const source = await this.parse(resolvedFile, { extname, parsers })
74
- await this.events.emit('process:progress', { file: resolvedFile, source, processed, percentage: (processed / total) * 100, total })
67
+ const source = await this.parse(resolvedFile, { extension, parsers })
68
+ const nextProcessed = processed + 1
69
+ const percentage = (nextProcessed / total) * 100
70
+ processed = nextProcessed
71
+ await this.events.emit('process:progress', { file: resolvedFile, source, processed, percentage, total })
75
72
  }
76
73
 
77
74
  await this.events.emit('file:end', { file: resolvedFile, index, total })
package/src/createApp.ts CHANGED
@@ -1,15 +1,3 @@
1
1
  import { defineApp } from './defineApp.ts'
2
2
 
3
- export const createApp = defineApp(() => {
4
- return {
5
- async render() {
6
- throw new Error('Method not implemented')
7
- },
8
- async renderToString() {
9
- throw new Error('Method not implemented')
10
- },
11
- async waitUntilExit() {
12
- throw new Error('Method not implemented')
13
- },
14
- }
15
- })
3
+ export const createApp = defineApp()