@kubb/fabric-core 0.1.3 → 0.1.5

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-DUFbq4lD.d.ts → App-9ie0H1SF.d.ts} +24 -24
  2. package/dist/{App-DoQNlnGL.d.cts → App-KqAHuAyU.d.cts} +24 -24
  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/index-BpPNNyhl.d.ts +18 -0
  12. package/dist/index-DLITiDO5.d.cts +18 -0
  13. package/dist/index.cjs +39 -68
  14. package/dist/index.cjs.map +1 -1
  15. package/dist/index.d.cts +3 -14
  16. package/dist/index.d.ts +3 -14
  17. package/dist/index.js +33 -62
  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 +8 -6
  30. package/dist/plugins.cjs.map +1 -1
  31. package/dist/plugins.d.cts +19 -8
  32. package/dist/plugins.d.ts +19 -8
  33. package/dist/plugins.js +8 -6
  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-BBGeFKlP.js → typescriptParser-CrzOv_Aw.js} +3 -17
  38. package/dist/typescriptParser-CrzOv_Aw.js.map +1 -0
  39. package/dist/{typescriptParser-C9WJrwRd.d.ts → typescriptParser-Dk1rwKyJ.d.ts} +2 -2
  40. package/dist/{typescriptParser-DOD1_QTe.d.cts → typescriptParser-Du4RIToQ.d.cts} +2 -2
  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 +26 -14
  45. package/src/FileProcessor.ts +13 -12
  46. package/src/createApp.ts +1 -13
  47. package/src/defineApp.ts +24 -34
  48. package/src/plugins/fsPlugin.ts +35 -13
  49. package/src/plugins/types.ts +3 -3
  50. package/dist/defineApp-C6WnoREI.d.ts +0 -14
  51. package/dist/defineApp-D1-njmtr.d.cts +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
package/src/defineApp.ts CHANGED
@@ -1,22 +1,18 @@
1
1
  import { FileManager } from './FileManager.ts'
2
- import { isFunction, isPromise } from 'remeda'
2
+ import { isFunction } from 'remeda'
3
3
  import type { Plugin } from './plugins/types.ts'
4
4
  import type { Parser } from './parsers/types.ts'
5
5
  import { AsyncEventEmitter } from './utils/AsyncEventEmitter.ts'
6
- import type { App, AppContext, Component, AppEvents } from './App.ts'
6
+ import type { AppContext, Component, AppEvents } from './App.ts'
7
7
 
8
- type AppRenderer = {
9
- render(): Promise<void> | void
10
- renderToString(): Promise<string> | string
11
- waitUntilExit(): Promise<void>
12
- }
8
+ import type { App } from './index.ts'
13
9
 
14
- type RootRenderFunction<THostElement, TContext extends AppContext> = (this: TContext, container: THostElement, context: TContext) => AppRenderer
10
+ type RootRenderFunction<TApp extends App> = (app: TApp) => void | Promise<void>
15
11
 
16
- export type DefineApp<TContext extends AppContext> = (rootComponent?: Component, options?: TContext['options']) => App
12
+ export type DefineApp<TOptions> = (rootComponent?: Component, options?: TOptions) => App
17
13
 
18
- export function defineApp<THostElement, TContext extends AppContext>(instance: RootRenderFunction<THostElement, TContext>): DefineApp<TContext> {
19
- function createApp(rootComponent: Component, options?: TContext['options']): App {
14
+ export function defineApp<TOptions = unknown>(instance?: RootRenderFunction<App<TOptions>>): DefineApp<TOptions> {
15
+ function createApp(options?: TOptions): App {
20
16
  const events = new AsyncEventEmitter<AppEvents>()
21
17
  const installedPlugins = new Set<Plugin>()
22
18
  const installedParsers = new Set<Parser>()
@@ -27,31 +23,18 @@ export function defineApp<THostElement, TContext extends AppContext>(instance: R
27
23
  fileManager,
28
24
  installedPlugins,
29
25
  installedParsers,
30
- } as TContext
31
-
32
- const { render, renderToString, waitUntilExit } = instance.call(context, rootComponent, context)
26
+ } as AppContext<TOptions>
33
27
 
34
28
  const app = {
35
- _component: rootComponent,
36
- async render() {
37
- if (isPromise(render)) {
38
- await render()
39
- } else {
40
- render()
41
- }
42
- },
43
- async renderToString() {
44
- return renderToString()
45
- },
29
+ context,
46
30
  get files() {
47
31
  return fileManager.files
48
32
  },
49
- waitUntilExit,
50
33
  async addFile(...newFiles) {
51
34
  await fileManager.add(...newFiles)
52
35
  },
53
- use(pluginOrParser, ...options) {
54
- const args = Array.isArray(options) ? options : [options[0]]
36
+ async use(pluginOrParser, ...options) {
37
+ const args = options
55
38
 
56
39
  if (pluginOrParser.type === 'plugin') {
57
40
  if (installedPlugins.has(pluginOrParser)) {
@@ -60,10 +43,10 @@ export function defineApp<THostElement, TContext extends AppContext>(instance: R
60
43
  installedPlugins.add(pluginOrParser)
61
44
  }
62
45
 
63
- if (pluginOrParser.override && isFunction(pluginOrParser.override)) {
64
- const overrider = pluginOrParser.override
46
+ if (pluginOrParser.inject && isFunction(pluginOrParser.inject)) {
47
+ const injecter = pluginOrParser.inject
65
48
 
66
- const extraApp = (overrider as any)(app, context, ...args)
49
+ const extraApp = (injecter as any)(app, ...args)
67
50
  Object.assign(app, extraApp)
68
51
  }
69
52
  }
@@ -78,14 +61,21 @@ export function defineApp<THostElement, TContext extends AppContext>(instance: R
78
61
  if (pluginOrParser && isFunction(pluginOrParser.install)) {
79
62
  const installer = pluginOrParser.install
80
63
 
81
- ;(installer as any)(app, context, ...args)
64
+ await (installer as any)(app, ...args)
82
65
  }
83
66
 
84
67
  return app
85
68
  },
86
- } as App
69
+ } as App<TOptions>
70
+
71
+ // start
72
+ events.emit('start')
73
+ if (instance) {
74
+ instance(app)
75
+ }
87
76
 
88
- events.emit('start', { app })
77
+ // end
78
+ events.emit('end')
89
79
 
90
80
  return app
91
81
  }
@@ -4,12 +4,24 @@ import fs from 'fs-extra'
4
4
  import { resolve } from 'node:path'
5
5
  import type * as KubbFile from '../KubbFile.ts'
6
6
 
7
+ type WriteOptions = {
8
+ extension?: Record<KubbFile.Extname, KubbFile.Extname | ''>
9
+ dryRun?: boolean
10
+ }
11
+
7
12
  type Options = {
8
13
  /**
9
14
  * Optional callback that is invoked whenever a file is written by the plugin.
10
15
  * Useful for tests to observe write operations without spying on internal functions.
11
16
  */
12
17
  onWrite?: (path: string, data: string) => void | Promise<void>
18
+ clean?: {
19
+ path: string
20
+ }
21
+ }
22
+
23
+ type ExtendOptions = {
24
+ write(options?: WriteOptions): Promise<void>
13
25
  }
14
26
 
15
27
  export async function write(path: string, data: string, options: { sanity?: boolean } = {}): Promise<string | undefined> {
@@ -71,29 +83,39 @@ export async function write(path: string, data: string, options: { sanity?: bool
71
83
  )(path, data.trim(), options)
72
84
  }
73
85
 
74
- type WriteOptions = {
75
- extension?: Record<KubbFile.Extname, KubbFile.Extname | ''>
76
- dryRun?: boolean
77
- }
78
-
79
- declare module '../index.ts' {
86
+ // biome-ignore lint/suspicious/noTsIgnore: production ready
87
+ // @ts-ignore
88
+ declare module '@kubb/fabric-core' {
80
89
  interface App {
81
90
  write(options?: WriteOptions): Promise<void>
82
91
  }
83
92
  }
84
93
 
85
- export const fsPlugin = createPlugin<Options, { write(options?: WriteOptions): Promise<void> }>({
94
+ declare global {
95
+ namespace Kubb {
96
+ interface App {
97
+ write(options?: WriteOptions): Promise<void>
98
+ }
99
+ }
100
+ }
101
+
102
+ export const fsPlugin = createPlugin<Options, ExtendOptions>({
86
103
  name: 'fs',
87
- scope: 'write',
88
- async install(_app, context, options) {
89
- context.events.on('process:progress', async ({ file, source }) => {
104
+ async install(app, options) {
105
+ app.context.events.on('process:progress', async ({ file, source }) => {
90
106
  if (options?.onWrite) {
91
107
  await options.onWrite(file.path, source)
92
108
  }
93
109
  await write(file.path, source, { sanity: false })
94
110
  })
111
+
112
+ app.context.events.on('start', async () => {
113
+ if (options?.clean) {
114
+ await fs.remove(options.clean.path)
115
+ }
116
+ })
95
117
  },
96
- override(_app, context) {
118
+ inject(app) {
97
119
  return {
98
120
  async write(
99
121
  options = {
@@ -101,10 +123,10 @@ export const fsPlugin = createPlugin<Options, { write(options?: WriteOptions): P
101
123
  dryRun: false,
102
124
  },
103
125
  ) {
104
- await context.fileManager.write({
126
+ await app.context.fileManager.write({
105
127
  extension: options.extension,
106
128
  dryRun: options.dryRun,
107
- parsers: context.installedParsers,
129
+ parsers: app.context.installedParsers,
108
130
  })
109
131
  },
110
132
  }
@@ -1,15 +1,15 @@
1
- import type { Install, Override } from '../App.ts'
1
+ import type { Install, Inject } from '../App.ts'
2
2
 
3
3
  export type Plugin<TOptions = any[], TAppExtension extends Record<string, any> = {}> = {
4
4
  name: string
5
5
  type: 'plugin'
6
- scope?: 'write' | 'read' | (string & {})
7
6
  install: Install<TOptions> | Promise<Install<TOptions>>
8
7
  /**
9
8
  * Runtime app overrides or extensions.
10
9
  * Merged into the app instance after install.
10
+ * This cannot be async
11
11
  */
12
- override?: Override<TOptions, TAppExtension>
12
+ inject?: Inject<TOptions, TAppExtension>
13
13
  }
14
14
 
15
15
  export type UserPlugin<TOptions = any[], TAppExtension extends Record<string, any> = {}> = Omit<Plugin<TOptions, TAppExtension>, 'type'>
@@ -1,14 +0,0 @@
1
- import { n as AppContext, r as Component, t as App } from "./App-DUFbq4lD.js";
2
-
3
- //#region src/defineApp.d.ts
4
- type AppRenderer = {
5
- render(): Promise<void> | void;
6
- renderToString(): Promise<string> | string;
7
- waitUntilExit(): Promise<void>;
8
- };
9
- type RootRenderFunction<THostElement, TContext extends AppContext> = (this: TContext, container: THostElement, context: TContext) => AppRenderer;
10
- type DefineApp<TContext extends AppContext> = (rootComponent?: Component, options?: TContext['options']) => App;
11
- declare function defineApp<THostElement, TContext extends AppContext>(instance: RootRenderFunction<THostElement, TContext>): DefineApp<TContext>;
12
- //#endregion
13
- export { defineApp as n, DefineApp as t };
14
- //# sourceMappingURL=defineApp-C6WnoREI.d.ts.map
@@ -1,14 +0,0 @@
1
- import { n as AppContext, r as Component, t as App } from "./App-DoQNlnGL.cjs";
2
-
3
- //#region src/defineApp.d.ts
4
- type AppRenderer = {
5
- render(): Promise<void> | void;
6
- renderToString(): Promise<string> | string;
7
- waitUntilExit(): Promise<void>;
8
- };
9
- type RootRenderFunction<THostElement, TContext extends AppContext> = (this: TContext, container: THostElement, context: TContext) => AppRenderer;
10
- type DefineApp<TContext extends AppContext> = (rootComponent?: Component, options?: TContext['options']) => App;
11
- declare function defineApp<THostElement, TContext extends AppContext>(instance: RootRenderFunction<THostElement, TContext>): DefineApp<TContext>;
12
- //#endregion
13
- export { defineApp as n, DefineApp as t };
14
- //# sourceMappingURL=defineApp-D1-njmtr.d.cts.map
@@ -1,26 +0,0 @@
1
- import { a as createParser, i as typescriptParser } from "./typescriptParser-BBGeFKlP.js";
2
-
3
- //#region src/parsers/defaultParser.ts
4
- const defaultParser = createParser({
5
- name: "default",
6
- extNames: [".json"],
7
- install() {},
8
- async parse(file) {
9
- return file.sources.map((item) => item.value).join("\n\n");
10
- }
11
- });
12
-
13
- //#endregion
14
- //#region src/parsers/tsxParser.ts
15
- const tsxParser = createParser({
16
- name: "tsx",
17
- extNames: [".tsx", ".jsx"],
18
- install() {},
19
- async parse(file, options = { extname: ".tsx" }) {
20
- return typescriptParser.parse(file, options);
21
- }
22
- });
23
-
24
- //#endregion
25
- export { defaultParser as n, tsxParser as t };
26
- //# sourceMappingURL=tsxParser-C741ZKCN.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tsxParser-C741ZKCN.js","names":[],"sources":["../src/parsers/defaultParser.ts","../src/parsers/tsxParser.ts"],"sourcesContent":["import { createParser } from './createParser.ts'\n\nexport const defaultParser = createParser({\n name: 'default',\n extNames: ['.json'],\n install() {},\n async parse(file) {\n return file.sources.map((item) => item.value).join('\\n\\n')\n },\n})\n","import { typescriptParser } from './typescriptParser.ts'\nimport { createParser } from './createParser.ts'\n\nexport const tsxParser = createParser({\n name: 'tsx',\n extNames: ['.tsx', '.jsx'],\n install() {},\n async parse(file, options = { extname: '.tsx' }) {\n return typescriptParser.parse(file, options)\n },\n})\n"],"mappings":";;;AAEA,MAAa,gBAAgB,aAAa;CACxC,MAAM;CACN,UAAU,CAAC,QAAQ;CACnB,UAAU;CACV,MAAM,MAAM,MAAM;AAChB,SAAO,KAAK,QAAQ,KAAK,SAAS,KAAK,MAAM,CAAC,KAAK,OAAO;;CAE7D,CAAC;;;;ACNF,MAAa,YAAY,aAAa;CACpC,MAAM;CACN,UAAU,CAAC,QAAQ,OAAO;CAC1B,UAAU;CACV,MAAM,MAAM,MAAM,UAAU,EAAE,SAAS,QAAQ,EAAE;AAC/C,SAAO,iBAAiB,MAAM,MAAM,QAAQ;;CAE/C,CAAC"}
@@ -1,37 +0,0 @@
1
- const require_typescriptParser = require('./typescriptParser-BBbbmG5W.cjs');
2
-
3
- //#region src/parsers/defaultParser.ts
4
- const defaultParser = require_typescriptParser.createParser({
5
- name: "default",
6
- extNames: [".json"],
7
- install() {},
8
- async parse(file) {
9
- return file.sources.map((item) => item.value).join("\n\n");
10
- }
11
- });
12
-
13
- //#endregion
14
- //#region src/parsers/tsxParser.ts
15
- const tsxParser = require_typescriptParser.createParser({
16
- name: "tsx",
17
- extNames: [".tsx", ".jsx"],
18
- install() {},
19
- async parse(file, options = { extname: ".tsx" }) {
20
- return require_typescriptParser.typescriptParser.parse(file, options);
21
- }
22
- });
23
-
24
- //#endregion
25
- Object.defineProperty(exports, 'defaultParser', {
26
- enumerable: true,
27
- get: function () {
28
- return defaultParser;
29
- }
30
- });
31
- Object.defineProperty(exports, 'tsxParser', {
32
- enumerable: true,
33
- get: function () {
34
- return tsxParser;
35
- }
36
- });
37
- //# sourceMappingURL=tsxParser-HDf_3TMc.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tsxParser-HDf_3TMc.cjs","names":["createParser","createParser","typescriptParser"],"sources":["../src/parsers/defaultParser.ts","../src/parsers/tsxParser.ts"],"sourcesContent":["import { createParser } from './createParser.ts'\n\nexport const defaultParser = createParser({\n name: 'default',\n extNames: ['.json'],\n install() {},\n async parse(file) {\n return file.sources.map((item) => item.value).join('\\n\\n')\n },\n})\n","import { typescriptParser } from './typescriptParser.ts'\nimport { createParser } from './createParser.ts'\n\nexport const tsxParser = createParser({\n name: 'tsx',\n extNames: ['.tsx', '.jsx'],\n install() {},\n async parse(file, options = { extname: '.tsx' }) {\n return typescriptParser.parse(file, options)\n },\n})\n"],"mappings":";;;AAEA,MAAa,gBAAgBA,sCAAa;CACxC,MAAM;CACN,UAAU,CAAC,QAAQ;CACnB,UAAU;CACV,MAAM,MAAM,MAAM;AAChB,SAAO,KAAK,QAAQ,KAAK,SAAS,KAAK,MAAM,CAAC,KAAK,OAAO;;CAE7D,CAAC;;;;ACNF,MAAa,YAAYC,sCAAa;CACpC,MAAM;CACN,UAAU,CAAC,QAAQ,OAAO;CAC1B,UAAU;CACV,MAAM,MAAM,MAAM,UAAU,EAAE,SAAS,QAAQ,EAAE;AAC/C,SAAOC,0CAAiB,MAAM,MAAM,QAAQ;;CAE/C,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"typescriptParser-BBbbmG5W.cjs","names":["path","ts","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,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;;;;AAWpB,MAAM,kBAAkB,SAAiB,KAAK,QAAQ,SAAS,oBAAoB;;;;AAKnF,MAAM,mBAAmB,SAAiB,KAAK,QAAQ,wBAAwB,KAAK;;;;;;AAOpF,SAAgB,MAAM,WAA2B,EAAE,EAAE,EAAE,SAAS,IAAI,WAAW,aAAa,aAAaA,mBAAG,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