@kubb/fabric-core 0.1.4 → 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.
- package/dist/{App-BxAl3dNP.d.ts → App-9ie0H1SF.d.ts} +12 -9
- package/dist/{App-D3DHa4Il.d.cts → App-KqAHuAyU.d.cts} +12 -9
- package/dist/index-BpPNNyhl.d.ts +18 -0
- package/dist/index-DLITiDO5.d.cts +18 -0
- package/dist/index.cjs +4 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -14
- package/dist/index.d.ts +3 -14
- package/dist/index.js +4 -3
- package/dist/index.js.map +1 -1
- package/dist/parsers/typescript.d.cts +2 -2
- package/dist/parsers/typescript.d.ts +2 -2
- package/dist/parsers.d.cts +2 -2
- package/dist/parsers.d.ts +2 -2
- package/dist/plugins.cjs +3 -1
- package/dist/plugins.cjs.map +1 -1
- package/dist/plugins.d.cts +12 -2
- package/dist/plugins.d.ts +12 -2
- package/dist/plugins.js +3 -1
- package/dist/plugins.js.map +1 -1
- package/dist/types.d.cts +2 -2
- package/dist/types.d.ts +2 -2
- package/dist/{typescriptParser-CctRhsng.d.ts → typescriptParser-Dk1rwKyJ.d.ts} +2 -2
- package/dist/{typescriptParser--N0n8KFn.d.cts → typescriptParser-Du4RIToQ.d.cts} +2 -2
- package/package.json +1 -1
- package/src/App.ts +18 -3
- package/src/defineApp.ts +9 -4
- package/src/plugins/fsPlugin.ts +20 -2
- package/src/plugins/types.ts +1 -1
- package/dist/defineApp-B9W1A5SV.d.ts +0 -9
- package/dist/defineApp-BP97CT5p.d.cts +0 -9
|
@@ -119,11 +119,11 @@ type ResolvedFile<TMeta$1 extends object = object> = File<TMeta$1> & {
|
|
|
119
119
|
type Plugin<TOptions = any[], TAppExtension$1 extends Record<string, any> = {}> = {
|
|
120
120
|
name: string;
|
|
121
121
|
type: 'plugin';
|
|
122
|
-
scope?: 'write' | 'read' | (string & {});
|
|
123
122
|
install: Install<TOptions> | Promise<Install<TOptions>>;
|
|
124
123
|
/**
|
|
125
124
|
* Runtime app overrides or extensions.
|
|
126
125
|
* Merged into the app instance after install.
|
|
126
|
+
* This cannot be async
|
|
127
127
|
*/
|
|
128
128
|
inject?: Inject<TOptions, TAppExtension$1>;
|
|
129
129
|
};
|
|
@@ -208,20 +208,21 @@ declare class FileManager {
|
|
|
208
208
|
}
|
|
209
209
|
//#endregion
|
|
210
210
|
//#region src/App.d.ts
|
|
211
|
+
declare global {
|
|
212
|
+
namespace Kubb {
|
|
213
|
+
interface App {}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
211
216
|
type Component = any;
|
|
212
217
|
type AppEvents = {
|
|
213
218
|
/**
|
|
214
219
|
* Called in the beginning of the app lifecycle.
|
|
215
220
|
*/
|
|
216
|
-
start: [
|
|
217
|
-
app: App;
|
|
218
|
-
}];
|
|
221
|
+
start: [];
|
|
219
222
|
/**
|
|
220
223
|
* Called in the end of the app lifecycle.
|
|
221
224
|
*/
|
|
222
|
-
end: [
|
|
223
|
-
app: App;
|
|
224
|
-
}];
|
|
225
|
+
end: [];
|
|
225
226
|
/**
|
|
226
227
|
* Called when being rendered
|
|
227
228
|
*/
|
|
@@ -277,13 +278,15 @@ type AppContext<TOptions = unknown> = {
|
|
|
277
278
|
};
|
|
278
279
|
type Install<TOptions = any[] | object | undefined> = TOptions extends any[] ? (app: App, ...options: TOptions) => void : TOptions extends object ? (app: App, options?: TOptions) => void : (app: App) => void;
|
|
279
280
|
type Inject<TOptions = any[] | object | undefined, TAppExtension$1 extends Record<string, any> = {}> = TOptions extends any[] ? (app: App, ...options: TOptions) => Partial<TAppExtension$1> : TOptions extends object ? (app: App, options?: TOptions) => Partial<TAppExtension$1> : (app: App) => Partial<TAppExtension$1>;
|
|
280
|
-
interface App<TOptions = unknown> {
|
|
281
|
+
interface App<TOptions = unknown> extends Kubb.App {
|
|
281
282
|
context: AppContext<TOptions>;
|
|
282
283
|
files: Array<ResolvedFile>;
|
|
283
284
|
use<TOptions extends any[] | object = any, TMeta extends object = object, TAppExtension extends Record<string, any> = {}>(pluginOrParser: Plugin<TOptions, TAppExtension> | Parser<TOptions, TMeta>, ...options: TOptions extends any[] ? NoInfer<TOptions> : [NoInfer<TOptions>]): this & TAppExtension;
|
|
284
285
|
use<TOptions extends any[] | object = any, TMeta extends object = object, TAppExtension extends Record<string, any> = {}>(pluginOrParser: Plugin<TOptions, TAppExtension> | Parser<TOptions, TMeta>): this & TAppExtension;
|
|
286
|
+
use<TOptions extends any[] | object = any, TMeta extends object = object, TAppExtension extends Record<string, any> = {}>(pluginOrParser: Plugin<TOptions, TAppExtension> | Parser<TOptions, TMeta>, ...options: TOptions extends any[] ? NoInfer<TOptions> : [NoInfer<TOptions>]): Promise<this & TAppExtension>;
|
|
287
|
+
use<TOptions extends any[] | object = any, TMeta extends object = object, TAppExtension extends Record<string, any> = {}>(pluginOrParser: Plugin<TOptions, TAppExtension> | Parser<TOptions, TMeta>): Promise<this & TAppExtension>;
|
|
285
288
|
addFile(...files: Array<File>): Promise<void>;
|
|
286
289
|
}
|
|
287
290
|
//#endregion
|
|
288
291
|
export { FileProcessor as a, Plugin as c, File as d, KubbFile_d_exports as f, FileManager as i, UserPlugin as l, AppContext as n, Parser as o, ResolvedFile as p, Component as r, UserParser as s, App as t, Extname as u };
|
|
289
|
-
//# sourceMappingURL=App-
|
|
292
|
+
//# sourceMappingURL=App-9ie0H1SF.d.ts.map
|
|
@@ -119,11 +119,11 @@ type ResolvedFile<TMeta$1 extends object = object> = File<TMeta$1> & {
|
|
|
119
119
|
type Plugin<TOptions = any[], TAppExtension$1 extends Record<string, any> = {}> = {
|
|
120
120
|
name: string;
|
|
121
121
|
type: 'plugin';
|
|
122
|
-
scope?: 'write' | 'read' | (string & {});
|
|
123
122
|
install: Install<TOptions> | Promise<Install<TOptions>>;
|
|
124
123
|
/**
|
|
125
124
|
* Runtime app overrides or extensions.
|
|
126
125
|
* Merged into the app instance after install.
|
|
126
|
+
* This cannot be async
|
|
127
127
|
*/
|
|
128
128
|
inject?: Inject<TOptions, TAppExtension$1>;
|
|
129
129
|
};
|
|
@@ -208,20 +208,21 @@ declare class FileManager {
|
|
|
208
208
|
}
|
|
209
209
|
//#endregion
|
|
210
210
|
//#region src/App.d.ts
|
|
211
|
+
declare global {
|
|
212
|
+
namespace Kubb {
|
|
213
|
+
interface App {}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
211
216
|
type Component = any;
|
|
212
217
|
type AppEvents = {
|
|
213
218
|
/**
|
|
214
219
|
* Called in the beginning of the app lifecycle.
|
|
215
220
|
*/
|
|
216
|
-
start: [
|
|
217
|
-
app: App;
|
|
218
|
-
}];
|
|
221
|
+
start: [];
|
|
219
222
|
/**
|
|
220
223
|
* Called in the end of the app lifecycle.
|
|
221
224
|
*/
|
|
222
|
-
end: [
|
|
223
|
-
app: App;
|
|
224
|
-
}];
|
|
225
|
+
end: [];
|
|
225
226
|
/**
|
|
226
227
|
* Called when being rendered
|
|
227
228
|
*/
|
|
@@ -277,13 +278,15 @@ type AppContext<TOptions = unknown> = {
|
|
|
277
278
|
};
|
|
278
279
|
type Install<TOptions = any[] | object | undefined> = TOptions extends any[] ? (app: App, ...options: TOptions) => void : TOptions extends object ? (app: App, options?: TOptions) => void : (app: App) => void;
|
|
279
280
|
type Inject<TOptions = any[] | object | undefined, TAppExtension$1 extends Record<string, any> = {}> = TOptions extends any[] ? (app: App, ...options: TOptions) => Partial<TAppExtension$1> : TOptions extends object ? (app: App, options?: TOptions) => Partial<TAppExtension$1> : (app: App) => Partial<TAppExtension$1>;
|
|
280
|
-
interface App<TOptions = unknown> {
|
|
281
|
+
interface App<TOptions = unknown> extends Kubb.App {
|
|
281
282
|
context: AppContext<TOptions>;
|
|
282
283
|
files: Array<ResolvedFile>;
|
|
283
284
|
use<TOptions extends any[] | object = any, TMeta extends object = object, TAppExtension extends Record<string, any> = {}>(pluginOrParser: Plugin<TOptions, TAppExtension> | Parser<TOptions, TMeta>, ...options: TOptions extends any[] ? NoInfer<TOptions> : [NoInfer<TOptions>]): this & TAppExtension;
|
|
284
285
|
use<TOptions extends any[] | object = any, TMeta extends object = object, TAppExtension extends Record<string, any> = {}>(pluginOrParser: Plugin<TOptions, TAppExtension> | Parser<TOptions, TMeta>): this & TAppExtension;
|
|
286
|
+
use<TOptions extends any[] | object = any, TMeta extends object = object, TAppExtension extends Record<string, any> = {}>(pluginOrParser: Plugin<TOptions, TAppExtension> | Parser<TOptions, TMeta>, ...options: TOptions extends any[] ? NoInfer<TOptions> : [NoInfer<TOptions>]): Promise<this & TAppExtension>;
|
|
287
|
+
use<TOptions extends any[] | object = any, TMeta extends object = object, TAppExtension extends Record<string, any> = {}>(pluginOrParser: Plugin<TOptions, TAppExtension> | Parser<TOptions, TMeta>): Promise<this & TAppExtension>;
|
|
285
288
|
addFile(...files: Array<File>): Promise<void>;
|
|
286
289
|
}
|
|
287
290
|
//#endregion
|
|
288
291
|
export { FileProcessor as a, Plugin as c, File as d, KubbFile_d_exports as f, FileManager as i, UserPlugin as l, AppContext as n, Parser as o, ResolvedFile as p, Component as r, UserParser as s, App as t, Extname as u };
|
|
289
|
-
//# sourceMappingURL=App-
|
|
292
|
+
//# sourceMappingURL=App-KqAHuAyU.d.cts.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { d as File, p as ResolvedFile, r as Component, t as App } from "./App-9ie0H1SF.js";
|
|
2
|
+
|
|
3
|
+
//#region src/defineApp.d.ts
|
|
4
|
+
type RootRenderFunction<TApp extends App> = (app: TApp) => void | Promise<void>;
|
|
5
|
+
type DefineApp<TOptions> = (rootComponent?: Component, options?: TOptions) => App;
|
|
6
|
+
declare function defineApp<TOptions = unknown>(instance?: RootRenderFunction<App<TOptions>>): DefineApp<TOptions>;
|
|
7
|
+
//#endregion
|
|
8
|
+
//#region src/createApp.d.ts
|
|
9
|
+
declare const createApp: DefineApp<unknown>;
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region src/createFile.d.ts
|
|
12
|
+
/**
|
|
13
|
+
* Helper to create a file with name and id set
|
|
14
|
+
*/
|
|
15
|
+
declare function createFile<TMeta extends object = object>(file: File<TMeta>): ResolvedFile<TMeta>;
|
|
16
|
+
//#endregion
|
|
17
|
+
export { defineApp as i, createApp as n, DefineApp as r, createFile as t };
|
|
18
|
+
//# sourceMappingURL=index-BpPNNyhl.d.ts.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { d as File, p as ResolvedFile, r as Component, t as App } from "./App-KqAHuAyU.cjs";
|
|
2
|
+
|
|
3
|
+
//#region src/defineApp.d.ts
|
|
4
|
+
type RootRenderFunction<TApp extends App> = (app: TApp) => void | Promise<void>;
|
|
5
|
+
type DefineApp<TOptions> = (rootComponent?: Component, options?: TOptions) => App;
|
|
6
|
+
declare function defineApp<TOptions = unknown>(instance?: RootRenderFunction<App<TOptions>>): DefineApp<TOptions>;
|
|
7
|
+
//#endregion
|
|
8
|
+
//#region src/createApp.d.ts
|
|
9
|
+
declare const createApp: DefineApp<unknown>;
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region src/createFile.d.ts
|
|
12
|
+
/**
|
|
13
|
+
* Helper to create a file with name and id set
|
|
14
|
+
*/
|
|
15
|
+
declare function createFile<TMeta extends object = object>(file: File<TMeta>): ResolvedFile<TMeta>;
|
|
16
|
+
//#endregion
|
|
17
|
+
export { defineApp as i, createApp as n, DefineApp as r, createFile as t };
|
|
18
|
+
//# sourceMappingURL=index-DLITiDO5.d.cts.map
|
package/dist/index.cjs
CHANGED
|
@@ -372,7 +372,7 @@ function defineApp(instance) {
|
|
|
372
372
|
async addFile(...newFiles) {
|
|
373
373
|
await fileManager.add(...newFiles);
|
|
374
374
|
},
|
|
375
|
-
use(pluginOrParser, ...options$1) {
|
|
375
|
+
async use(pluginOrParser, ...options$1) {
|
|
376
376
|
const args = options$1;
|
|
377
377
|
if (pluginOrParser.type === "plugin") {
|
|
378
378
|
if (installedPlugins.has(pluginOrParser)) console.warn("Plugin has already been applied to target app.");
|
|
@@ -387,13 +387,14 @@ function defineApp(instance) {
|
|
|
387
387
|
else installedParsers.add(pluginOrParser);
|
|
388
388
|
if (pluginOrParser && (0, remeda.isFunction)(pluginOrParser.install)) {
|
|
389
389
|
const installer = pluginOrParser.install;
|
|
390
|
-
installer(app, ...args);
|
|
390
|
+
await installer(app, ...args);
|
|
391
391
|
}
|
|
392
392
|
return app;
|
|
393
393
|
}
|
|
394
394
|
};
|
|
395
|
-
events.emit("start"
|
|
395
|
+
events.emit("start");
|
|
396
396
|
if (instance) instance(app);
|
|
397
|
+
events.emit("end");
|
|
397
398
|
return app;
|
|
398
399
|
}
|
|
399
400
|
return createApp$1;
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["exports","name","path","trimExtName","NodeEventEmitter","defaultParser","parser: Parser | undefined","resolvedFiles: Array<KubbFile.ResolvedFile>","path","trimExtName","createApp","options"],"sources":["../src/utils/Cache.ts","../src/createFile.ts","../src/utils/AsyncEventEmitter.ts","../src/FileProcessor.ts","../src/FileManager.ts","../src/defineApp.ts","../src/createApp.ts"],"sourcesContent":["export class Cache<T> {\n #buffer = new Map<string, T>()\n\n get(key: string): T | null {\n return this.#buffer.get(key) ?? null\n }\n\n set(key: string, value: T): void {\n this.#buffer.set(key, value)\n }\n\n delete(key: string): void {\n this.#buffer.delete(key)\n }\n\n clear(): void {\n this.#buffer.clear()\n }\n\n keys(): string[] {\n return [...this.#buffer.keys()]\n }\n\n values(): Array<T> {\n return [...this.#buffer.values()]\n }\n\n flush(): void {\n // No-op for base cache\n }\n}\n","import type * as KubbFile from './KubbFile.ts'\nimport { trimExtName } from './utils/trimExtName.ts'\nimport { createHash } from 'node:crypto'\nimport path from 'node:path'\nimport { isDeepEqual, uniqueBy } from 'remeda'\nimport { orderBy } from 'natural-orderby'\n\nfunction hashObject(obj: Record<string, unknown>): string {\n const str = JSON.stringify(obj, Object.keys(obj).sort())\n return createHash('sha256').update(str).digest('hex')\n}\n\nexport function combineSources(sources: Array<KubbFile.Source>): Array<KubbFile.Source> {\n return uniqueBy(sources, (obj) => [obj.name, obj.isExportable, obj.isTypeOnly] as const)\n}\n\nexport function combineExports(exports: Array<KubbFile.Export>): Array<KubbFile.Export> {\n return orderBy(exports, [\n (v) => !!Array.isArray(v.name),\n (v) => !v.isTypeOnly,\n (v) => v.path,\n (v) => !!v.name,\n (v) => (Array.isArray(v.name) ? orderBy(v.name) : v.name),\n ]).reduce(\n (prev, curr) => {\n const name = curr.name\n const prevByPath = prev.findLast((imp) => imp.path === curr.path)\n const prevByPathAndIsTypeOnly = prev.findLast((imp) => imp.path === curr.path && isDeepEqual(imp.name, name) && imp.isTypeOnly)\n\n if (prevByPathAndIsTypeOnly) {\n // we already have an export that has the same path but uses `isTypeOnly` (export type ...)\n return prev\n }\n\n const uniquePrev = prev.findLast(\n (imp) => imp.path === curr.path && isDeepEqual(imp.name, name) && imp.isTypeOnly === curr.isTypeOnly && imp.asAlias === curr.asAlias,\n )\n\n // we already have an item that was unique enough or name field is empty or prev asAlias is set but current has no changes\n if (uniquePrev || (Array.isArray(name) && !name.length) || (prevByPath?.asAlias && !curr.asAlias)) {\n return prev\n }\n\n if (!prevByPath) {\n return [\n ...prev,\n {\n ...curr,\n name: Array.isArray(name) ? [...new Set(name)] : name,\n },\n ]\n }\n\n // merge all names when prev and current both have the same isTypeOnly set\n if (prevByPath && Array.isArray(prevByPath.name) && Array.isArray(curr.name) && prevByPath.isTypeOnly === curr.isTypeOnly) {\n prevByPath.name = [...new Set([...prevByPath.name, ...curr.name])]\n\n return prev\n }\n\n return [...prev, curr]\n },\n [] as Array<KubbFile.Export>,\n )\n}\n\nexport function combineImports(imports: Array<KubbFile.Import>, exports: Array<KubbFile.Export>, source?: string): Array<KubbFile.Import> {\n return orderBy(imports, [\n (v) => !!Array.isArray(v.name),\n (v) => !v.isTypeOnly,\n (v) => v.path,\n (v) => !!v.name,\n (v) => (Array.isArray(v.name) ? orderBy(v.name) : v.name),\n ]).reduce(\n (prev, curr) => {\n let name = Array.isArray(curr.name) ? [...new Set(curr.name)] : curr.name\n\n const hasImportInSource = (importName: string) => {\n if (!source) {\n return true\n }\n\n const checker = (name?: string) => {\n return name && source.includes(name)\n }\n\n return checker(importName) || exports.some(({ name }) => (Array.isArray(name) ? name.some(checker) : checker(name)))\n }\n\n if (curr.path === curr.root) {\n // root and path are the same file, remove the \"./\" import\n return prev\n }\n\n // merge all names and check if the importName is being used in the generated source and if not filter those imports out\n if (Array.isArray(name)) {\n name = name.filter((item) => (typeof item === 'string' ? hasImportInSource(item) : hasImportInSource(item.propertyName)))\n }\n\n const prevByPath = prev.findLast((imp) => imp.path === curr.path && imp.isTypeOnly === curr.isTypeOnly)\n const uniquePrev = prev.findLast((imp) => imp.path === curr.path && isDeepEqual(imp.name, name) && imp.isTypeOnly === curr.isTypeOnly)\n const prevByPathNameAndIsTypeOnly = prev.findLast((imp) => imp.path === curr.path && isDeepEqual(imp.name, name) && imp.isTypeOnly)\n\n if (prevByPathNameAndIsTypeOnly) {\n // we already have an export that has the same path but uses `isTypeOnly` (import type ...)\n return prev\n }\n\n // already unique enough or name is empty\n if (uniquePrev || (Array.isArray(name) && !name.length)) {\n return prev\n }\n\n // new item, append name\n if (!prevByPath) {\n return [\n ...prev,\n {\n ...curr,\n name,\n },\n ]\n }\n\n // merge all names when prev and current both have the same isTypeOnly set\n if (prevByPath && Array.isArray(prevByPath.name) && Array.isArray(name) && prevByPath.isTypeOnly === curr.isTypeOnly) {\n prevByPath.name = [...new Set([...prevByPath.name, ...name])]\n\n return prev\n }\n\n // no import was found in the source, ignore import\n if (!Array.isArray(name) && name && !hasImportInSource(name)) {\n return prev\n }\n\n return [...prev, curr]\n },\n [] as Array<KubbFile.Import>,\n )\n}\n\n/**\n * Helper to create a file with name and id set\n */\nexport function createFile<TMeta extends object = object>(file: KubbFile.File<TMeta>): KubbFile.ResolvedFile<TMeta> {\n const extname = path.extname(file.baseName) as KubbFile.Extname\n if (!extname) {\n throw new Error(`No extname found for ${file.baseName}`)\n }\n\n const source = file.sources.map((item) => item.value).join('\\n\\n')\n const exports = file.exports?.length ? combineExports(file.exports) : []\n const imports = file.imports?.length && source ? combineImports(file.imports, exports, source) : []\n const sources = file.sources?.length ? combineSources(file.sources) : []\n\n return {\n ...file,\n id: hashObject({ path: file.path }),\n name: trimExtName(file.baseName),\n extname,\n imports: imports,\n exports: exports,\n sources: sources,\n meta: file.meta || ({} as TMeta),\n }\n}\n","import { EventEmitter as NodeEventEmitter } from 'node:events'\n\nexport class AsyncEventEmitter<TEvents extends Record<string, any>> {\n constructor(maxListener = 100) {\n this.#emitter.setMaxListeners(maxListener)\n }\n #emitter = new NodeEventEmitter()\n\n async emit<TEventName extends keyof TEvents & string>(eventName: TEventName, ...eventArgs: TEvents[TEventName]): Promise<void> {\n const listeners = this.#emitter.listeners(eventName) as Array<(...args: TEvents[TEventName]) => any>\n\n if (listeners.length === 0) {\n return undefined\n }\n\n await Promise.all(\n listeners.map(async (listener) => {\n try {\n return await listener(...eventArgs)\n } catch (err) {\n console.error(`Error in async listener for \"${eventName}\":`, err)\n }\n }),\n )\n }\n\n on<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArg: TEvents[TEventName]) => void): void {\n this.#emitter.on(eventName, handler as any)\n }\n\n off<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArg: TEvents[TEventName]) => void): void {\n this.#emitter.off(eventName, handler as any)\n }\n removeAll(): void {\n this.#emitter.removeAllListeners()\n }\n}\n","import type * as KubbFile from './KubbFile.ts'\nimport pLimit from 'p-limit'\n\nimport type { Parser } from './parsers/types.ts'\nimport { defaultParser } from './parsers/defaultParser.ts'\nimport { AsyncEventEmitter } from './utils/AsyncEventEmitter.ts'\nimport type { AppEvents } from './App.ts'\n\nexport type ProcessFilesProps = {\n parsers?: Set<Parser>\n extension?: Record<KubbFile.Extname, KubbFile.Extname | ''>\n dryRun?: boolean\n}\n\ntype GetParseOptions = {\n parsers?: Set<Parser>\n extension?: Record<KubbFile.Extname, KubbFile.Extname | ''>\n}\n\ntype Options = {\n events?: AsyncEventEmitter<AppEvents>\n}\n\nexport class FileProcessor {\n #limit = pLimit(100)\n events: AsyncEventEmitter<AppEvents>\n\n constructor({ events = new AsyncEventEmitter<AppEvents>() }: Options = {}) {\n this.events = events\n\n return this\n }\n\n async parse(file: KubbFile.ResolvedFile, { parsers = new Set(), extension }: GetParseOptions = {}): Promise<string> {\n const parseExtName = extension?.[file.extname] || undefined\n\n if (!file.extname) {\n return defaultParser.parse(file, { extname: parseExtName })\n }\n\n let parser: Parser | undefined\n for (const item of parsers) {\n if (item.extNames?.includes(file.extname)) {\n parser = item\n break\n }\n }\n\n if (!parser) {\n return defaultParser.parse(file, { extname: parseExtName })\n }\n\n return parser.parse(file, { extname: parseExtName })\n }\n\n async run(files: Array<KubbFile.ResolvedFile>, { parsers, dryRun, extension }: ProcessFilesProps = {}): Promise<KubbFile.ResolvedFile[]> {\n await this.events.emit('process:start', { files })\n\n let processed = 0\n const total = files.length\n\n const promises = files.map((resolvedFile, index) =>\n this.#limit(async () => {\n await this.events.emit('file:start', { file: resolvedFile, index, total })\n\n if (!dryRun) {\n const source = await this.parse(resolvedFile, { extension, parsers })\n const nextProcessed = processed + 1\n const percentage = (nextProcessed / total) * 100\n processed = nextProcessed\n await this.events.emit('process:progress', { file: resolvedFile, source, processed, percentage, total })\n }\n\n await this.events.emit('file:end', { file: resolvedFile, index, total })\n\n processed++\n }),\n )\n\n await Promise.all(promises)\n\n await this.events.emit('process:end', { files })\n\n return files\n }\n}\n","import type * as KubbFile from './KubbFile.ts'\nimport { Cache } from './utils/Cache.ts'\nimport { trimExtName } from './utils/trimExtName.ts'\nimport { orderBy } from 'natural-orderby'\nimport { createFile } from './createFile.ts'\nimport { FileProcessor, type ProcessFilesProps } from './FileProcessor.ts'\nimport { AsyncEventEmitter } from './utils/AsyncEventEmitter.ts'\nimport type { AppEvents } from './App.ts'\n\nfunction mergeFile<TMeta extends object = object>(a: KubbFile.File<TMeta>, b: KubbFile.File<TMeta>): KubbFile.File<TMeta> {\n return {\n ...a,\n sources: [...(a.sources || []), ...(b.sources || [])],\n imports: [...(a.imports || []), ...(b.imports || [])],\n exports: [...(a.exports || []), ...(b.exports || [])],\n }\n}\n\ntype Options = {\n events?: AsyncEventEmitter<AppEvents>\n}\n\nexport class FileManager {\n #cache = new Cache<KubbFile.ResolvedFile>()\n processor: FileProcessor\n\n constructor({ events = new AsyncEventEmitter<AppEvents>() }: Options = {}) {\n this.processor = new FileProcessor({ events })\n return this\n }\n\n async add(...files: Array<KubbFile.File>) {\n const resolvedFiles: Array<KubbFile.ResolvedFile> = []\n\n const mergedFiles = new Map<string, KubbFile.File>()\n\n files.forEach((file) => {\n const existing = mergedFiles.get(file.path)\n if (existing) {\n mergedFiles.set(file.path, mergeFile(existing, file))\n } else {\n mergedFiles.set(file.path, file)\n }\n })\n\n for (const file of mergedFiles.values()) {\n const existing = this.#cache.get(file.path)\n\n const merged = existing ? mergeFile(existing, file) : file\n const resolvedFile = createFile(merged)\n\n this.#cache.set(resolvedFile.path, resolvedFile)\n this.flush()\n\n resolvedFiles.push(resolvedFile)\n }\n\n return resolvedFiles\n }\n\n flush() {\n this.#cache.flush()\n }\n\n getByPath(path: KubbFile.Path): KubbFile.ResolvedFile | null {\n return this.#cache.get(path)\n }\n\n deleteByPath(path: KubbFile.Path): void {\n this.#cache.delete(path)\n }\n\n clear(): void {\n this.#cache.clear()\n }\n\n get files(): Array<KubbFile.ResolvedFile> {\n const cachedKeys = this.#cache.keys()\n\n // order by path length and if file is a barrel file\n const keys = orderBy(cachedKeys, [(v) => v.length, (v) => trimExtName(v).endsWith('index')])\n\n const files = keys.map((key) => this.#cache.get(key))\n\n return files.filter(Boolean)\n }\n\n async write(options: ProcessFilesProps): Promise<KubbFile.ResolvedFile[]> {\n return this.processor.run(this.files, options)\n }\n}\n","import { FileManager } from './FileManager.ts'\nimport { isFunction } from 'remeda'\nimport type { Plugin } from './plugins/types.ts'\nimport type { Parser } from './parsers/types.ts'\nimport { AsyncEventEmitter } from './utils/AsyncEventEmitter.ts'\nimport type { App, AppContext, Component, AppEvents } from './App.ts'\n\ntype RootRenderFunction<TApp extends App> = (app: TApp) => void | Promise<void>\n\nexport type DefineApp<TOptions> = (rootComponent?: Component, options?: TOptions) => App\n\nexport function defineApp<TOptions = unknown>(instance?: RootRenderFunction<App<TOptions>>): DefineApp<TOptions> {\n function createApp(options?: TOptions): App {\n const events = new AsyncEventEmitter<AppEvents>()\n const installedPlugins = new Set<Plugin>()\n const installedParsers = new Set<Parser>()\n const fileManager = new FileManager({ events })\n const context = {\n events,\n options,\n fileManager,\n installedPlugins,\n installedParsers,\n } as AppContext<TOptions>\n\n const app = {\n context,\n get files() {\n return fileManager.files\n },\n async addFile(...newFiles) {\n await fileManager.add(...newFiles)\n },\n use(pluginOrParser, ...options) {\n const args = options\n\n if (pluginOrParser.type === 'plugin') {\n if (installedPlugins.has(pluginOrParser)) {\n console.warn('Plugin has already been applied to target app.')\n } else {\n installedPlugins.add(pluginOrParser)\n }\n\n if (pluginOrParser.inject && isFunction(pluginOrParser.inject)) {\n const injecter = pluginOrParser.inject\n\n const extraApp = (injecter as any)(app, ...args)\n Object.assign(app, extraApp)\n }\n }\n if (pluginOrParser.type === 'parser') {\n if (installedParsers.has(pluginOrParser)) {\n console.warn('Parser has already been applied to target app.')\n } else {\n installedParsers.add(pluginOrParser)\n }\n }\n\n if (pluginOrParser && isFunction(pluginOrParser.install)) {\n const installer = pluginOrParser.install\n\n ;(installer as any)(app, ...args)\n }\n\n return app\n },\n } as App<TOptions>\n\n // start\n events.emit('start', { app })\n if (instance) {\n instance(app)\n }\n\n return app\n }\n\n return createApp\n}\n","import { defineApp } from './defineApp.ts'\n\nexport const createApp = defineApp()\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAa,QAAb,MAAsB;;4DACV,IAAI,K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;;;;;;AC7ElD,SAAgB,UAA8B,UAAmE;CAC/G,SAASC,YAAU,SAAyB;EAC1C,MAAM,SAAS,IAAI,mBAA8B;EACjD,MAAM,mCAAmB,IAAI,KAAa;EAC1C,MAAM,mCAAmB,IAAI,KAAa;EAC1C,MAAM,cAAc,IAAI,YAAY,EAAE,QAAQ,CAAC;EAS/C,MAAM,MAAM;GACV,SATc;IACd;IACA;IACA;IACA;IACA;IACD;GAIC,IAAI,QAAQ;AACV,WAAO,YAAY;;GAErB,MAAM,QAAQ,GAAG,UAAU;AACzB,UAAM,YAAY,IAAI,GAAG,SAAS;;GAEpC,IAAI,gBAAgB,GAAGC,WAAS;IAC9B,MAAM,OAAOA;AAEb,QAAI,eAAe,SAAS,UAAU;AACpC,SAAI,iBAAiB,IAAI,eAAe,CACtC,SAAQ,KAAK,iDAAiD;SAE9D,kBAAiB,IAAI,eAAe;AAGtC,SAAI,eAAe,iCAAqB,eAAe,OAAO,EAAE;MAC9D,MAAM,WAAW,eAAe;MAEhC,MAAM,WAAY,SAAiB,KAAK,GAAG,KAAK;AAChD,aAAO,OAAO,KAAK,SAAS;;;AAGhC,QAAI,eAAe,SAAS,SAC1B,KAAI,iBAAiB,IAAI,eAAe,CACtC,SAAQ,KAAK,iDAAiD;QAE9D,kBAAiB,IAAI,eAAe;AAIxC,QAAI,yCAA6B,eAAe,QAAQ,EAAE;KACxD,MAAM,YAAY,eAAe;AAEhC,KAAC,UAAkB,KAAK,GAAG,KAAK;;AAGnC,WAAO;;GAEV;AAGD,SAAO,KAAK,SAAS,EAAE,KAAK,CAAC;AAC7B,MAAI,SACF,UAAS,IAAI;AAGf,SAAO;;AAGT,QAAOD;;;;;AC3ET,MAAa,YAAY,WAAW"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["exports","name","path","trimExtName","NodeEventEmitter","defaultParser","parser: Parser | undefined","resolvedFiles: Array<KubbFile.ResolvedFile>","path","trimExtName","createApp","options"],"sources":["../src/utils/Cache.ts","../src/createFile.ts","../src/utils/AsyncEventEmitter.ts","../src/FileProcessor.ts","../src/FileManager.ts","../src/defineApp.ts","../src/createApp.ts"],"sourcesContent":["export class Cache<T> {\n #buffer = new Map<string, T>()\n\n get(key: string): T | null {\n return this.#buffer.get(key) ?? null\n }\n\n set(key: string, value: T): void {\n this.#buffer.set(key, value)\n }\n\n delete(key: string): void {\n this.#buffer.delete(key)\n }\n\n clear(): void {\n this.#buffer.clear()\n }\n\n keys(): string[] {\n return [...this.#buffer.keys()]\n }\n\n values(): Array<T> {\n return [...this.#buffer.values()]\n }\n\n flush(): void {\n // No-op for base cache\n }\n}\n","import type * as KubbFile from './KubbFile.ts'\nimport { trimExtName } from './utils/trimExtName.ts'\nimport { createHash } from 'node:crypto'\nimport path from 'node:path'\nimport { isDeepEqual, uniqueBy } from 'remeda'\nimport { orderBy } from 'natural-orderby'\n\nfunction hashObject(obj: Record<string, unknown>): string {\n const str = JSON.stringify(obj, Object.keys(obj).sort())\n return createHash('sha256').update(str).digest('hex')\n}\n\nexport function combineSources(sources: Array<KubbFile.Source>): Array<KubbFile.Source> {\n return uniqueBy(sources, (obj) => [obj.name, obj.isExportable, obj.isTypeOnly] as const)\n}\n\nexport function combineExports(exports: Array<KubbFile.Export>): Array<KubbFile.Export> {\n return orderBy(exports, [\n (v) => !!Array.isArray(v.name),\n (v) => !v.isTypeOnly,\n (v) => v.path,\n (v) => !!v.name,\n (v) => (Array.isArray(v.name) ? orderBy(v.name) : v.name),\n ]).reduce(\n (prev, curr) => {\n const name = curr.name\n const prevByPath = prev.findLast((imp) => imp.path === curr.path)\n const prevByPathAndIsTypeOnly = prev.findLast((imp) => imp.path === curr.path && isDeepEqual(imp.name, name) && imp.isTypeOnly)\n\n if (prevByPathAndIsTypeOnly) {\n // we already have an export that has the same path but uses `isTypeOnly` (export type ...)\n return prev\n }\n\n const uniquePrev = prev.findLast(\n (imp) => imp.path === curr.path && isDeepEqual(imp.name, name) && imp.isTypeOnly === curr.isTypeOnly && imp.asAlias === curr.asAlias,\n )\n\n // we already have an item that was unique enough or name field is empty or prev asAlias is set but current has no changes\n if (uniquePrev || (Array.isArray(name) && !name.length) || (prevByPath?.asAlias && !curr.asAlias)) {\n return prev\n }\n\n if (!prevByPath) {\n return [\n ...prev,\n {\n ...curr,\n name: Array.isArray(name) ? [...new Set(name)] : name,\n },\n ]\n }\n\n // merge all names when prev and current both have the same isTypeOnly set\n if (prevByPath && Array.isArray(prevByPath.name) && Array.isArray(curr.name) && prevByPath.isTypeOnly === curr.isTypeOnly) {\n prevByPath.name = [...new Set([...prevByPath.name, ...curr.name])]\n\n return prev\n }\n\n return [...prev, curr]\n },\n [] as Array<KubbFile.Export>,\n )\n}\n\nexport function combineImports(imports: Array<KubbFile.Import>, exports: Array<KubbFile.Export>, source?: string): Array<KubbFile.Import> {\n return orderBy(imports, [\n (v) => !!Array.isArray(v.name),\n (v) => !v.isTypeOnly,\n (v) => v.path,\n (v) => !!v.name,\n (v) => (Array.isArray(v.name) ? orderBy(v.name) : v.name),\n ]).reduce(\n (prev, curr) => {\n let name = Array.isArray(curr.name) ? [...new Set(curr.name)] : curr.name\n\n const hasImportInSource = (importName: string) => {\n if (!source) {\n return true\n }\n\n const checker = (name?: string) => {\n return name && source.includes(name)\n }\n\n return checker(importName) || exports.some(({ name }) => (Array.isArray(name) ? name.some(checker) : checker(name)))\n }\n\n if (curr.path === curr.root) {\n // root and path are the same file, remove the \"./\" import\n return prev\n }\n\n // merge all names and check if the importName is being used in the generated source and if not filter those imports out\n if (Array.isArray(name)) {\n name = name.filter((item) => (typeof item === 'string' ? hasImportInSource(item) : hasImportInSource(item.propertyName)))\n }\n\n const prevByPath = prev.findLast((imp) => imp.path === curr.path && imp.isTypeOnly === curr.isTypeOnly)\n const uniquePrev = prev.findLast((imp) => imp.path === curr.path && isDeepEqual(imp.name, name) && imp.isTypeOnly === curr.isTypeOnly)\n const prevByPathNameAndIsTypeOnly = prev.findLast((imp) => imp.path === curr.path && isDeepEqual(imp.name, name) && imp.isTypeOnly)\n\n if (prevByPathNameAndIsTypeOnly) {\n // we already have an export that has the same path but uses `isTypeOnly` (import type ...)\n return prev\n }\n\n // already unique enough or name is empty\n if (uniquePrev || (Array.isArray(name) && !name.length)) {\n return prev\n }\n\n // new item, append name\n if (!prevByPath) {\n return [\n ...prev,\n {\n ...curr,\n name,\n },\n ]\n }\n\n // merge all names when prev and current both have the same isTypeOnly set\n if (prevByPath && Array.isArray(prevByPath.name) && Array.isArray(name) && prevByPath.isTypeOnly === curr.isTypeOnly) {\n prevByPath.name = [...new Set([...prevByPath.name, ...name])]\n\n return prev\n }\n\n // no import was found in the source, ignore import\n if (!Array.isArray(name) && name && !hasImportInSource(name)) {\n return prev\n }\n\n return [...prev, curr]\n },\n [] as Array<KubbFile.Import>,\n )\n}\n\n/**\n * Helper to create a file with name and id set\n */\nexport function createFile<TMeta extends object = object>(file: KubbFile.File<TMeta>): KubbFile.ResolvedFile<TMeta> {\n const extname = path.extname(file.baseName) as KubbFile.Extname\n if (!extname) {\n throw new Error(`No extname found for ${file.baseName}`)\n }\n\n const source = file.sources.map((item) => item.value).join('\\n\\n')\n const exports = file.exports?.length ? combineExports(file.exports) : []\n const imports = file.imports?.length && source ? combineImports(file.imports, exports, source) : []\n const sources = file.sources?.length ? combineSources(file.sources) : []\n\n return {\n ...file,\n id: hashObject({ path: file.path }),\n name: trimExtName(file.baseName),\n extname,\n imports: imports,\n exports: exports,\n sources: sources,\n meta: file.meta || ({} as TMeta),\n }\n}\n","import { EventEmitter as NodeEventEmitter } from 'node:events'\n\nexport class AsyncEventEmitter<TEvents extends Record<string, any>> {\n constructor(maxListener = 100) {\n this.#emitter.setMaxListeners(maxListener)\n }\n #emitter = new NodeEventEmitter()\n\n async emit<TEventName extends keyof TEvents & string>(eventName: TEventName, ...eventArgs: TEvents[TEventName]): Promise<void> {\n const listeners = this.#emitter.listeners(eventName) as Array<(...args: TEvents[TEventName]) => any>\n\n if (listeners.length === 0) {\n return undefined\n }\n\n await Promise.all(\n listeners.map(async (listener) => {\n try {\n return await listener(...eventArgs)\n } catch (err) {\n console.error(`Error in async listener for \"${eventName}\":`, err)\n }\n }),\n )\n }\n\n on<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArg: TEvents[TEventName]) => void): void {\n this.#emitter.on(eventName, handler as any)\n }\n\n off<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArg: TEvents[TEventName]) => void): void {\n this.#emitter.off(eventName, handler as any)\n }\n removeAll(): void {\n this.#emitter.removeAllListeners()\n }\n}\n","import type * as KubbFile from './KubbFile.ts'\nimport pLimit from 'p-limit'\n\nimport type { Parser } from './parsers/types.ts'\nimport { defaultParser } from './parsers/defaultParser.ts'\nimport { AsyncEventEmitter } from './utils/AsyncEventEmitter.ts'\nimport type { AppEvents } from './App.ts'\n\nexport type ProcessFilesProps = {\n parsers?: Set<Parser>\n extension?: Record<KubbFile.Extname, KubbFile.Extname | ''>\n dryRun?: boolean\n}\n\ntype GetParseOptions = {\n parsers?: Set<Parser>\n extension?: Record<KubbFile.Extname, KubbFile.Extname | ''>\n}\n\ntype Options = {\n events?: AsyncEventEmitter<AppEvents>\n}\n\nexport class FileProcessor {\n #limit = pLimit(100)\n events: AsyncEventEmitter<AppEvents>\n\n constructor({ events = new AsyncEventEmitter<AppEvents>() }: Options = {}) {\n this.events = events\n\n return this\n }\n\n async parse(file: KubbFile.ResolvedFile, { parsers = new Set(), extension }: GetParseOptions = {}): Promise<string> {\n const parseExtName = extension?.[file.extname] || undefined\n\n if (!file.extname) {\n return defaultParser.parse(file, { extname: parseExtName })\n }\n\n let parser: Parser | undefined\n for (const item of parsers) {\n if (item.extNames?.includes(file.extname)) {\n parser = item\n break\n }\n }\n\n if (!parser) {\n return defaultParser.parse(file, { extname: parseExtName })\n }\n\n return parser.parse(file, { extname: parseExtName })\n }\n\n async run(files: Array<KubbFile.ResolvedFile>, { parsers, dryRun, extension }: ProcessFilesProps = {}): Promise<KubbFile.ResolvedFile[]> {\n await this.events.emit('process:start', { files })\n\n let processed = 0\n const total = files.length\n\n const promises = files.map((resolvedFile, index) =>\n this.#limit(async () => {\n await this.events.emit('file:start', { file: resolvedFile, index, total })\n\n if (!dryRun) {\n const source = await this.parse(resolvedFile, { extension, parsers })\n const nextProcessed = processed + 1\n const percentage = (nextProcessed / total) * 100\n processed = nextProcessed\n await this.events.emit('process:progress', { file: resolvedFile, source, processed, percentage, total })\n }\n\n await this.events.emit('file:end', { file: resolvedFile, index, total })\n\n processed++\n }),\n )\n\n await Promise.all(promises)\n\n await this.events.emit('process:end', { files })\n\n return files\n }\n}\n","import type * as KubbFile from './KubbFile.ts'\nimport { Cache } from './utils/Cache.ts'\nimport { trimExtName } from './utils/trimExtName.ts'\nimport { orderBy } from 'natural-orderby'\nimport { createFile } from './createFile.ts'\nimport { FileProcessor, type ProcessFilesProps } from './FileProcessor.ts'\nimport { AsyncEventEmitter } from './utils/AsyncEventEmitter.ts'\nimport type { AppEvents } from './App.ts'\n\nfunction mergeFile<TMeta extends object = object>(a: KubbFile.File<TMeta>, b: KubbFile.File<TMeta>): KubbFile.File<TMeta> {\n return {\n ...a,\n sources: [...(a.sources || []), ...(b.sources || [])],\n imports: [...(a.imports || []), ...(b.imports || [])],\n exports: [...(a.exports || []), ...(b.exports || [])],\n }\n}\n\ntype Options = {\n events?: AsyncEventEmitter<AppEvents>\n}\n\nexport class FileManager {\n #cache = new Cache<KubbFile.ResolvedFile>()\n processor: FileProcessor\n\n constructor({ events = new AsyncEventEmitter<AppEvents>() }: Options = {}) {\n this.processor = new FileProcessor({ events })\n return this\n }\n\n async add(...files: Array<KubbFile.File>) {\n const resolvedFiles: Array<KubbFile.ResolvedFile> = []\n\n const mergedFiles = new Map<string, KubbFile.File>()\n\n files.forEach((file) => {\n const existing = mergedFiles.get(file.path)\n if (existing) {\n mergedFiles.set(file.path, mergeFile(existing, file))\n } else {\n mergedFiles.set(file.path, file)\n }\n })\n\n for (const file of mergedFiles.values()) {\n const existing = this.#cache.get(file.path)\n\n const merged = existing ? mergeFile(existing, file) : file\n const resolvedFile = createFile(merged)\n\n this.#cache.set(resolvedFile.path, resolvedFile)\n this.flush()\n\n resolvedFiles.push(resolvedFile)\n }\n\n return resolvedFiles\n }\n\n flush() {\n this.#cache.flush()\n }\n\n getByPath(path: KubbFile.Path): KubbFile.ResolvedFile | null {\n return this.#cache.get(path)\n }\n\n deleteByPath(path: KubbFile.Path): void {\n this.#cache.delete(path)\n }\n\n clear(): void {\n this.#cache.clear()\n }\n\n get files(): Array<KubbFile.ResolvedFile> {\n const cachedKeys = this.#cache.keys()\n\n // order by path length and if file is a barrel file\n const keys = orderBy(cachedKeys, [(v) => v.length, (v) => trimExtName(v).endsWith('index')])\n\n const files = keys.map((key) => this.#cache.get(key))\n\n return files.filter(Boolean)\n }\n\n async write(options: ProcessFilesProps): Promise<KubbFile.ResolvedFile[]> {\n return this.processor.run(this.files, options)\n }\n}\n","import { FileManager } from './FileManager.ts'\nimport { isFunction } from 'remeda'\nimport type { Plugin } from './plugins/types.ts'\nimport type { Parser } from './parsers/types.ts'\nimport { AsyncEventEmitter } from './utils/AsyncEventEmitter.ts'\nimport type { AppContext, Component, AppEvents } from './App.ts'\n\nimport type { App } from './index.ts'\n\ntype RootRenderFunction<TApp extends App> = (app: TApp) => void | Promise<void>\n\nexport type DefineApp<TOptions> = (rootComponent?: Component, options?: TOptions) => App\n\nexport function defineApp<TOptions = unknown>(instance?: RootRenderFunction<App<TOptions>>): DefineApp<TOptions> {\n function createApp(options?: TOptions): App {\n const events = new AsyncEventEmitter<AppEvents>()\n const installedPlugins = new Set<Plugin>()\n const installedParsers = new Set<Parser>()\n const fileManager = new FileManager({ events })\n const context = {\n events,\n options,\n fileManager,\n installedPlugins,\n installedParsers,\n } as AppContext<TOptions>\n\n const app = {\n context,\n get files() {\n return fileManager.files\n },\n async addFile(...newFiles) {\n await fileManager.add(...newFiles)\n },\n async use(pluginOrParser, ...options) {\n const args = options\n\n if (pluginOrParser.type === 'plugin') {\n if (installedPlugins.has(pluginOrParser)) {\n console.warn('Plugin has already been applied to target app.')\n } else {\n installedPlugins.add(pluginOrParser)\n }\n\n if (pluginOrParser.inject && isFunction(pluginOrParser.inject)) {\n const injecter = pluginOrParser.inject\n\n const extraApp = (injecter as any)(app, ...args)\n Object.assign(app, extraApp)\n }\n }\n if (pluginOrParser.type === 'parser') {\n if (installedParsers.has(pluginOrParser)) {\n console.warn('Parser has already been applied to target app.')\n } else {\n installedParsers.add(pluginOrParser)\n }\n }\n\n if (pluginOrParser && isFunction(pluginOrParser.install)) {\n const installer = pluginOrParser.install\n\n await (installer as any)(app, ...args)\n }\n\n return app\n },\n } as App<TOptions>\n\n // start\n events.emit('start')\n if (instance) {\n instance(app)\n }\n\n // end\n events.emit('end')\n\n return app\n }\n\n return createApp\n}\n","import { defineApp } from './defineApp.ts'\n\nexport const createApp = defineApp()\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAa,QAAb,MAAsB;;4DACV,IAAI,KAAgB;;CAE9B,IAAI,KAAuB;;AACzB,6DAAO,KAAY,CAAC,IAAI,IAAI,+DAAI;;CAGlC,IAAI,KAAa,OAAgB;AAC/B,uCAAY,CAAC,IAAI,KAAK,MAAM;;CAG9B,OAAO,KAAmB;AACxB,uCAAY,CAAC,OAAO,IAAI;;CAG1B,QAAc;AACZ,uCAAY,CAAC,OAAO;;CAGtB,OAAiB;AACf,SAAO,CAAC,mCAAG,KAAY,CAAC,MAAM,CAAC;;CAGjC,SAAmB;AACjB,SAAO,CAAC,mCAAG,KAAY,CAAC,QAAQ,CAAC;;CAGnC,QAAc;;;;;ACpBhB,SAAS,WAAW,KAAsC;CACxD,MAAM,MAAM,KAAK,UAAU,KAAK,OAAO,KAAK,IAAI,CAAC,MAAM,CAAC;AACxD,oCAAkB,SAAS,CAAC,OAAO,IAAI,CAAC,OAAO,MAAM;;AAGvD,SAAgB,eAAe,SAAyD;AACtF,6BAAgB,UAAU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Ae,OAAO,EAAE;MAC9D,MAAM,WAAW,eAAe;MAEhC,MAAM,WAAY,SAAiB,KAAK,GAAG,KAAK;AAChD,aAAO,OAAO,KAAK,SAAS;;;AAGhC,QAAI,eAAe,SAAS,SAC1B,KAAI,iBAAiB,IAAI,eAAe,CACtC,SAAQ,KAAK,iDAAiD;QAE9D,kBAAiB,IAAI,eAAe;AAIxC,QAAI,yCAA6B,eAAe,QAAQ,EAAE;KACxD,MAAM,YAAY,eAAe;AAEjC,WAAO,UAAkB,KAAK,GAAG,KAAK;;AAGxC,WAAO;;GAEV;AAGD,SAAO,KAAK,QAAQ;AACpB,MAAI,SACF,UAAS,IAAI;AAIf,SAAO,KAAK,MAAM;AAElB,SAAO;;AAGT,QAAOD;;;;;AChFT,MAAa,YAAY,WAAW"}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,14 +1,3 @@
|
|
|
1
|
-
import { a as FileProcessor,
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
//#region src/createApp.d.ts
|
|
5
|
-
declare const createApp: DefineApp<unknown>;
|
|
6
|
-
//#endregion
|
|
7
|
-
//#region src/createFile.d.ts
|
|
8
|
-
/**
|
|
9
|
-
* Helper to create a file with name and id set
|
|
10
|
-
*/
|
|
11
|
-
declare function createFile<TMeta extends object = object>(file: File<TMeta>): ResolvedFile<TMeta>;
|
|
12
|
-
//#endregion
|
|
13
|
-
export { type App, FileManager, FileProcessor, createApp, createFile, defineApp };
|
|
14
|
-
//# sourceMappingURL=index.d.cts.map
|
|
1
|
+
import { a as FileProcessor, i as FileManager, t as App } from "./App-KqAHuAyU.cjs";
|
|
2
|
+
import { i as defineApp, n as createApp, t as createFile } from "./index-DLITiDO5.cjs";
|
|
3
|
+
export { App, FileManager, FileProcessor, createApp, createFile, defineApp };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,14 +1,3 @@
|
|
|
1
|
-
import { a as FileProcessor,
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
//#region src/createApp.d.ts
|
|
5
|
-
declare const createApp: DefineApp<unknown>;
|
|
6
|
-
//#endregion
|
|
7
|
-
//#region src/createFile.d.ts
|
|
8
|
-
/**
|
|
9
|
-
* Helper to create a file with name and id set
|
|
10
|
-
*/
|
|
11
|
-
declare function createFile<TMeta extends object = object>(file: File<TMeta>): ResolvedFile<TMeta>;
|
|
12
|
-
//#endregion
|
|
13
|
-
export { type App, FileManager, FileProcessor, createApp, createFile, defineApp };
|
|
14
|
-
//# sourceMappingURL=index.d.ts.map
|
|
1
|
+
import { a as FileProcessor, i as FileManager, t as App } from "./App-9ie0H1SF.js";
|
|
2
|
+
import { i as defineApp, n as createApp, t as createFile } from "./index-BpPNNyhl.js";
|
|
3
|
+
export { App, FileManager, FileProcessor, createApp, createFile, defineApp };
|
package/dist/index.js
CHANGED
|
@@ -365,7 +365,7 @@ function defineApp(instance) {
|
|
|
365
365
|
async addFile(...newFiles) {
|
|
366
366
|
await fileManager.add(...newFiles);
|
|
367
367
|
},
|
|
368
|
-
use(pluginOrParser, ...options$1) {
|
|
368
|
+
async use(pluginOrParser, ...options$1) {
|
|
369
369
|
const args = options$1;
|
|
370
370
|
if (pluginOrParser.type === "plugin") {
|
|
371
371
|
if (installedPlugins.has(pluginOrParser)) console.warn("Plugin has already been applied to target app.");
|
|
@@ -380,13 +380,14 @@ function defineApp(instance) {
|
|
|
380
380
|
else installedParsers.add(pluginOrParser);
|
|
381
381
|
if (pluginOrParser && isFunction(pluginOrParser.install)) {
|
|
382
382
|
const installer = pluginOrParser.install;
|
|
383
|
-
installer(app, ...args);
|
|
383
|
+
await installer(app, ...args);
|
|
384
384
|
}
|
|
385
385
|
return app;
|
|
386
386
|
}
|
|
387
387
|
};
|
|
388
|
-
events.emit("start"
|
|
388
|
+
events.emit("start");
|
|
389
389
|
if (instance) instance(app);
|
|
390
|
+
events.emit("end");
|
|
390
391
|
return app;
|
|
391
392
|
}
|
|
392
393
|
return createApp$1;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["name","NodeEventEmitter","parser: Parser | undefined","resolvedFiles: Array<KubbFile.ResolvedFile>","path","createApp","options"],"sources":["../src/utils/Cache.ts","../src/createFile.ts","../src/utils/AsyncEventEmitter.ts","../src/FileProcessor.ts","../src/FileManager.ts","../src/defineApp.ts","../src/createApp.ts"],"sourcesContent":["export class Cache<T> {\n #buffer = new Map<string, T>()\n\n get(key: string): T | null {\n return this.#buffer.get(key) ?? null\n }\n\n set(key: string, value: T): void {\n this.#buffer.set(key, value)\n }\n\n delete(key: string): void {\n this.#buffer.delete(key)\n }\n\n clear(): void {\n this.#buffer.clear()\n }\n\n keys(): string[] {\n return [...this.#buffer.keys()]\n }\n\n values(): Array<T> {\n return [...this.#buffer.values()]\n }\n\n flush(): void {\n // No-op for base cache\n }\n}\n","import type * as KubbFile from './KubbFile.ts'\nimport { trimExtName } from './utils/trimExtName.ts'\nimport { createHash } from 'node:crypto'\nimport path from 'node:path'\nimport { isDeepEqual, uniqueBy } from 'remeda'\nimport { orderBy } from 'natural-orderby'\n\nfunction hashObject(obj: Record<string, unknown>): string {\n const str = JSON.stringify(obj, Object.keys(obj).sort())\n return createHash('sha256').update(str).digest('hex')\n}\n\nexport function combineSources(sources: Array<KubbFile.Source>): Array<KubbFile.Source> {\n return uniqueBy(sources, (obj) => [obj.name, obj.isExportable, obj.isTypeOnly] as const)\n}\n\nexport function combineExports(exports: Array<KubbFile.Export>): Array<KubbFile.Export> {\n return orderBy(exports, [\n (v) => !!Array.isArray(v.name),\n (v) => !v.isTypeOnly,\n (v) => v.path,\n (v) => !!v.name,\n (v) => (Array.isArray(v.name) ? orderBy(v.name) : v.name),\n ]).reduce(\n (prev, curr) => {\n const name = curr.name\n const prevByPath = prev.findLast((imp) => imp.path === curr.path)\n const prevByPathAndIsTypeOnly = prev.findLast((imp) => imp.path === curr.path && isDeepEqual(imp.name, name) && imp.isTypeOnly)\n\n if (prevByPathAndIsTypeOnly) {\n // we already have an export that has the same path but uses `isTypeOnly` (export type ...)\n return prev\n }\n\n const uniquePrev = prev.findLast(\n (imp) => imp.path === curr.path && isDeepEqual(imp.name, name) && imp.isTypeOnly === curr.isTypeOnly && imp.asAlias === curr.asAlias,\n )\n\n // we already have an item that was unique enough or name field is empty or prev asAlias is set but current has no changes\n if (uniquePrev || (Array.isArray(name) && !name.length) || (prevByPath?.asAlias && !curr.asAlias)) {\n return prev\n }\n\n if (!prevByPath) {\n return [\n ...prev,\n {\n ...curr,\n name: Array.isArray(name) ? [...new Set(name)] : name,\n },\n ]\n }\n\n // merge all names when prev and current both have the same isTypeOnly set\n if (prevByPath && Array.isArray(prevByPath.name) && Array.isArray(curr.name) && prevByPath.isTypeOnly === curr.isTypeOnly) {\n prevByPath.name = [...new Set([...prevByPath.name, ...curr.name])]\n\n return prev\n }\n\n return [...prev, curr]\n },\n [] as Array<KubbFile.Export>,\n )\n}\n\nexport function combineImports(imports: Array<KubbFile.Import>, exports: Array<KubbFile.Export>, source?: string): Array<KubbFile.Import> {\n return orderBy(imports, [\n (v) => !!Array.isArray(v.name),\n (v) => !v.isTypeOnly,\n (v) => v.path,\n (v) => !!v.name,\n (v) => (Array.isArray(v.name) ? orderBy(v.name) : v.name),\n ]).reduce(\n (prev, curr) => {\n let name = Array.isArray(curr.name) ? [...new Set(curr.name)] : curr.name\n\n const hasImportInSource = (importName: string) => {\n if (!source) {\n return true\n }\n\n const checker = (name?: string) => {\n return name && source.includes(name)\n }\n\n return checker(importName) || exports.some(({ name }) => (Array.isArray(name) ? name.some(checker) : checker(name)))\n }\n\n if (curr.path === curr.root) {\n // root and path are the same file, remove the \"./\" import\n return prev\n }\n\n // merge all names and check if the importName is being used in the generated source and if not filter those imports out\n if (Array.isArray(name)) {\n name = name.filter((item) => (typeof item === 'string' ? hasImportInSource(item) : hasImportInSource(item.propertyName)))\n }\n\n const prevByPath = prev.findLast((imp) => imp.path === curr.path && imp.isTypeOnly === curr.isTypeOnly)\n const uniquePrev = prev.findLast((imp) => imp.path === curr.path && isDeepEqual(imp.name, name) && imp.isTypeOnly === curr.isTypeOnly)\n const prevByPathNameAndIsTypeOnly = prev.findLast((imp) => imp.path === curr.path && isDeepEqual(imp.name, name) && imp.isTypeOnly)\n\n if (prevByPathNameAndIsTypeOnly) {\n // we already have an export that has the same path but uses `isTypeOnly` (import type ...)\n return prev\n }\n\n // already unique enough or name is empty\n if (uniquePrev || (Array.isArray(name) && !name.length)) {\n return prev\n }\n\n // new item, append name\n if (!prevByPath) {\n return [\n ...prev,\n {\n ...curr,\n name,\n },\n ]\n }\n\n // merge all names when prev and current both have the same isTypeOnly set\n if (prevByPath && Array.isArray(prevByPath.name) && Array.isArray(name) && prevByPath.isTypeOnly === curr.isTypeOnly) {\n prevByPath.name = [...new Set([...prevByPath.name, ...name])]\n\n return prev\n }\n\n // no import was found in the source, ignore import\n if (!Array.isArray(name) && name && !hasImportInSource(name)) {\n return prev\n }\n\n return [...prev, curr]\n },\n [] as Array<KubbFile.Import>,\n )\n}\n\n/**\n * Helper to create a file with name and id set\n */\nexport function createFile<TMeta extends object = object>(file: KubbFile.File<TMeta>): KubbFile.ResolvedFile<TMeta> {\n const extname = path.extname(file.baseName) as KubbFile.Extname\n if (!extname) {\n throw new Error(`No extname found for ${file.baseName}`)\n }\n\n const source = file.sources.map((item) => item.value).join('\\n\\n')\n const exports = file.exports?.length ? combineExports(file.exports) : []\n const imports = file.imports?.length && source ? combineImports(file.imports, exports, source) : []\n const sources = file.sources?.length ? combineSources(file.sources) : []\n\n return {\n ...file,\n id: hashObject({ path: file.path }),\n name: trimExtName(file.baseName),\n extname,\n imports: imports,\n exports: exports,\n sources: sources,\n meta: file.meta || ({} as TMeta),\n }\n}\n","import { EventEmitter as NodeEventEmitter } from 'node:events'\n\nexport class AsyncEventEmitter<TEvents extends Record<string, any>> {\n constructor(maxListener = 100) {\n this.#emitter.setMaxListeners(maxListener)\n }\n #emitter = new NodeEventEmitter()\n\n async emit<TEventName extends keyof TEvents & string>(eventName: TEventName, ...eventArgs: TEvents[TEventName]): Promise<void> {\n const listeners = this.#emitter.listeners(eventName) as Array<(...args: TEvents[TEventName]) => any>\n\n if (listeners.length === 0) {\n return undefined\n }\n\n await Promise.all(\n listeners.map(async (listener) => {\n try {\n return await listener(...eventArgs)\n } catch (err) {\n console.error(`Error in async listener for \"${eventName}\":`, err)\n }\n }),\n )\n }\n\n on<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArg: TEvents[TEventName]) => void): void {\n this.#emitter.on(eventName, handler as any)\n }\n\n off<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArg: TEvents[TEventName]) => void): void {\n this.#emitter.off(eventName, handler as any)\n }\n removeAll(): void {\n this.#emitter.removeAllListeners()\n }\n}\n","import type * as KubbFile from './KubbFile.ts'\nimport pLimit from 'p-limit'\n\nimport type { Parser } from './parsers/types.ts'\nimport { defaultParser } from './parsers/defaultParser.ts'\nimport { AsyncEventEmitter } from './utils/AsyncEventEmitter.ts'\nimport type { AppEvents } from './App.ts'\n\nexport type ProcessFilesProps = {\n parsers?: Set<Parser>\n extension?: Record<KubbFile.Extname, KubbFile.Extname | ''>\n dryRun?: boolean\n}\n\ntype GetParseOptions = {\n parsers?: Set<Parser>\n extension?: Record<KubbFile.Extname, KubbFile.Extname | ''>\n}\n\ntype Options = {\n events?: AsyncEventEmitter<AppEvents>\n}\n\nexport class FileProcessor {\n #limit = pLimit(100)\n events: AsyncEventEmitter<AppEvents>\n\n constructor({ events = new AsyncEventEmitter<AppEvents>() }: Options = {}) {\n this.events = events\n\n return this\n }\n\n async parse(file: KubbFile.ResolvedFile, { parsers = new Set(), extension }: GetParseOptions = {}): Promise<string> {\n const parseExtName = extension?.[file.extname] || undefined\n\n if (!file.extname) {\n return defaultParser.parse(file, { extname: parseExtName })\n }\n\n let parser: Parser | undefined\n for (const item of parsers) {\n if (item.extNames?.includes(file.extname)) {\n parser = item\n break\n }\n }\n\n if (!parser) {\n return defaultParser.parse(file, { extname: parseExtName })\n }\n\n return parser.parse(file, { extname: parseExtName })\n }\n\n async run(files: Array<KubbFile.ResolvedFile>, { parsers, dryRun, extension }: ProcessFilesProps = {}): Promise<KubbFile.ResolvedFile[]> {\n await this.events.emit('process:start', { files })\n\n let processed = 0\n const total = files.length\n\n const promises = files.map((resolvedFile, index) =>\n this.#limit(async () => {\n await this.events.emit('file:start', { file: resolvedFile, index, total })\n\n if (!dryRun) {\n const source = await this.parse(resolvedFile, { extension, parsers })\n const nextProcessed = processed + 1\n const percentage = (nextProcessed / total) * 100\n processed = nextProcessed\n await this.events.emit('process:progress', { file: resolvedFile, source, processed, percentage, total })\n }\n\n await this.events.emit('file:end', { file: resolvedFile, index, total })\n\n processed++\n }),\n )\n\n await Promise.all(promises)\n\n await this.events.emit('process:end', { files })\n\n return files\n }\n}\n","import type * as KubbFile from './KubbFile.ts'\nimport { Cache } from './utils/Cache.ts'\nimport { trimExtName } from './utils/trimExtName.ts'\nimport { orderBy } from 'natural-orderby'\nimport { createFile } from './createFile.ts'\nimport { FileProcessor, type ProcessFilesProps } from './FileProcessor.ts'\nimport { AsyncEventEmitter } from './utils/AsyncEventEmitter.ts'\nimport type { AppEvents } from './App.ts'\n\nfunction mergeFile<TMeta extends object = object>(a: KubbFile.File<TMeta>, b: KubbFile.File<TMeta>): KubbFile.File<TMeta> {\n return {\n ...a,\n sources: [...(a.sources || []), ...(b.sources || [])],\n imports: [...(a.imports || []), ...(b.imports || [])],\n exports: [...(a.exports || []), ...(b.exports || [])],\n }\n}\n\ntype Options = {\n events?: AsyncEventEmitter<AppEvents>\n}\n\nexport class FileManager {\n #cache = new Cache<KubbFile.ResolvedFile>()\n processor: FileProcessor\n\n constructor({ events = new AsyncEventEmitter<AppEvents>() }: Options = {}) {\n this.processor = new FileProcessor({ events })\n return this\n }\n\n async add(...files: Array<KubbFile.File>) {\n const resolvedFiles: Array<KubbFile.ResolvedFile> = []\n\n const mergedFiles = new Map<string, KubbFile.File>()\n\n files.forEach((file) => {\n const existing = mergedFiles.get(file.path)\n if (existing) {\n mergedFiles.set(file.path, mergeFile(existing, file))\n } else {\n mergedFiles.set(file.path, file)\n }\n })\n\n for (const file of mergedFiles.values()) {\n const existing = this.#cache.get(file.path)\n\n const merged = existing ? mergeFile(existing, file) : file\n const resolvedFile = createFile(merged)\n\n this.#cache.set(resolvedFile.path, resolvedFile)\n this.flush()\n\n resolvedFiles.push(resolvedFile)\n }\n\n return resolvedFiles\n }\n\n flush() {\n this.#cache.flush()\n }\n\n getByPath(path: KubbFile.Path): KubbFile.ResolvedFile | null {\n return this.#cache.get(path)\n }\n\n deleteByPath(path: KubbFile.Path): void {\n this.#cache.delete(path)\n }\n\n clear(): void {\n this.#cache.clear()\n }\n\n get files(): Array<KubbFile.ResolvedFile> {\n const cachedKeys = this.#cache.keys()\n\n // order by path length and if file is a barrel file\n const keys = orderBy(cachedKeys, [(v) => v.length, (v) => trimExtName(v).endsWith('index')])\n\n const files = keys.map((key) => this.#cache.get(key))\n\n return files.filter(Boolean)\n }\n\n async write(options: ProcessFilesProps): Promise<KubbFile.ResolvedFile[]> {\n return this.processor.run(this.files, options)\n }\n}\n","import { FileManager } from './FileManager.ts'\nimport { isFunction } from 'remeda'\nimport type { Plugin } from './plugins/types.ts'\nimport type { Parser } from './parsers/types.ts'\nimport { AsyncEventEmitter } from './utils/AsyncEventEmitter.ts'\nimport type { App, AppContext, Component, AppEvents } from './App.ts'\n\ntype RootRenderFunction<TApp extends App> = (app: TApp) => void | Promise<void>\n\nexport type DefineApp<TOptions> = (rootComponent?: Component, options?: TOptions) => App\n\nexport function defineApp<TOptions = unknown>(instance?: RootRenderFunction<App<TOptions>>): DefineApp<TOptions> {\n function createApp(options?: TOptions): App {\n const events = new AsyncEventEmitter<AppEvents>()\n const installedPlugins = new Set<Plugin>()\n const installedParsers = new Set<Parser>()\n const fileManager = new FileManager({ events })\n const context = {\n events,\n options,\n fileManager,\n installedPlugins,\n installedParsers,\n } as AppContext<TOptions>\n\n const app = {\n context,\n get files() {\n return fileManager.files\n },\n async addFile(...newFiles) {\n await fileManager.add(...newFiles)\n },\n use(pluginOrParser, ...options) {\n const args = options\n\n if (pluginOrParser.type === 'plugin') {\n if (installedPlugins.has(pluginOrParser)) {\n console.warn('Plugin has already been applied to target app.')\n } else {\n installedPlugins.add(pluginOrParser)\n }\n\n if (pluginOrParser.inject && isFunction(pluginOrParser.inject)) {\n const injecter = pluginOrParser.inject\n\n const extraApp = (injecter as any)(app, ...args)\n Object.assign(app, extraApp)\n }\n }\n if (pluginOrParser.type === 'parser') {\n if (installedParsers.has(pluginOrParser)) {\n console.warn('Parser has already been applied to target app.')\n } else {\n installedParsers.add(pluginOrParser)\n }\n }\n\n if (pluginOrParser && isFunction(pluginOrParser.install)) {\n const installer = pluginOrParser.install\n\n ;(installer as any)(app, ...args)\n }\n\n return app\n },\n } as App<TOptions>\n\n // start\n events.emit('start', { app })\n if (instance) {\n instance(app)\n }\n\n return app\n }\n\n return createApp\n}\n","import { defineApp } from './defineApp.ts'\n\nexport const createApp = defineApp()\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAa,QAAb,MAAsB;;4DACV,IAAI,KAAgB;;CAE9B,IAAI,KAAuB;;AACzB,6DAAO,KAAY,CAAC,IAAI,IAAI,+DAAI;;CAGlC,IAAI,KAAa,OAAgB;AAC/B,uCAAY,CAAC,IAAI,KAAK,MAAM;;CAG9B,OAAO,KAAmB;AACxB,uCAAY,CAAC,OAAO,IAAI;;CAG1B,QAAc;AACZ,uCAAY,CAAC,OAAO;;CAGtB,OAAiB;AACf,SAAO,CAAC,mCAAG,KAAY,CAAC,MAAM,CAAC;;CAGjC,SAAmB;AACjB,SAAO,CAAC,mCAAG,KAAY,CAAC,QAAQ,CAAC;;CAGnC,QAAc;;;;;ACpBhB,SAAS,WAAW,KAAsC;CACxD,MAAM,MAAM,KAAK,UAAU,KAAK,OAAO,KAAK,IAAI,CAAC,MAAM,CAAC;AACxD,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eAAe,SAAS,UAAU;AACpC,SAAI,iBAAiB,IAAI,eAAe,CACtC,SAAQ,KAAK,iDAAiD;SAE9D,kBAAiB,IAAI,eAAe;AAGtC,SAAI,eAAe,UAAU,WAAW,eAAe,OAAO,EAAE;MAC9D,MAAM,WAAW,eAAe;MAEhC,MAAM,WAAY,SAAiB,KAAK,GAAG,KAAK;AAChD,aAAO,OAAO,KAAK,SAAS;;;AAGhC,QAAI,eAAe,SAAS,SAC1B,KAAI,iBAAiB,IAAI,eAAe,CACtC,SAAQ,KAAK,iDAAiD;QAE9D,kBAAiB,IAAI,eAAe;AAIxC,QAAI,kBAAkB,WAAW,eAAe,QAAQ,EAAE;KACxD,MAAM,YAAY,eAAe;AAEhC,KAAC,UAAkB,KAAK,GAAG,KAAK;;AAGnC,WAAO;;GAEV;AAGD,SAAO,KAAK,SAAS,EAAE,KAAK,CAAC;AAC7B,MAAI,SACF,UAAS,IAAI;AAGf,SAAO;;AAGT,QAAOD;;;;;AC3ET,MAAa,YAAY,WAAW"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["name","NodeEventEmitter","parser: Parser | undefined","resolvedFiles: Array<KubbFile.ResolvedFile>","path","createApp","options"],"sources":["../src/utils/Cache.ts","../src/createFile.ts","../src/utils/AsyncEventEmitter.ts","../src/FileProcessor.ts","../src/FileManager.ts","../src/defineApp.ts","../src/createApp.ts"],"sourcesContent":["export class Cache<T> {\n #buffer = new Map<string, T>()\n\n get(key: string): T | null {\n return this.#buffer.get(key) ?? null\n }\n\n set(key: string, value: T): void {\n this.#buffer.set(key, value)\n }\n\n delete(key: string): void {\n this.#buffer.delete(key)\n }\n\n clear(): void {\n this.#buffer.clear()\n }\n\n keys(): string[] {\n return [...this.#buffer.keys()]\n }\n\n values(): Array<T> {\n return [...this.#buffer.values()]\n }\n\n flush(): void {\n // No-op for base cache\n }\n}\n","import type * as KubbFile from './KubbFile.ts'\nimport { trimExtName } from './utils/trimExtName.ts'\nimport { createHash } from 'node:crypto'\nimport path from 'node:path'\nimport { isDeepEqual, uniqueBy } from 'remeda'\nimport { orderBy } from 'natural-orderby'\n\nfunction hashObject(obj: Record<string, unknown>): string {\n const str = JSON.stringify(obj, Object.keys(obj).sort())\n return createHash('sha256').update(str).digest('hex')\n}\n\nexport function combineSources(sources: Array<KubbFile.Source>): Array<KubbFile.Source> {\n return uniqueBy(sources, (obj) => [obj.name, obj.isExportable, obj.isTypeOnly] as const)\n}\n\nexport function combineExports(exports: Array<KubbFile.Export>): Array<KubbFile.Export> {\n return orderBy(exports, [\n (v) => !!Array.isArray(v.name),\n (v) => !v.isTypeOnly,\n (v) => v.path,\n (v) => !!v.name,\n (v) => (Array.isArray(v.name) ? orderBy(v.name) : v.name),\n ]).reduce(\n (prev, curr) => {\n const name = curr.name\n const prevByPath = prev.findLast((imp) => imp.path === curr.path)\n const prevByPathAndIsTypeOnly = prev.findLast((imp) => imp.path === curr.path && isDeepEqual(imp.name, name) && imp.isTypeOnly)\n\n if (prevByPathAndIsTypeOnly) {\n // we already have an export that has the same path but uses `isTypeOnly` (export type ...)\n return prev\n }\n\n const uniquePrev = prev.findLast(\n (imp) => imp.path === curr.path && isDeepEqual(imp.name, name) && imp.isTypeOnly === curr.isTypeOnly && imp.asAlias === curr.asAlias,\n )\n\n // we already have an item that was unique enough or name field is empty or prev asAlias is set but current has no changes\n if (uniquePrev || (Array.isArray(name) && !name.length) || (prevByPath?.asAlias && !curr.asAlias)) {\n return prev\n }\n\n if (!prevByPath) {\n return [\n ...prev,\n {\n ...curr,\n name: Array.isArray(name) ? [...new Set(name)] : name,\n },\n ]\n }\n\n // merge all names when prev and current both have the same isTypeOnly set\n if (prevByPath && Array.isArray(prevByPath.name) && Array.isArray(curr.name) && prevByPath.isTypeOnly === curr.isTypeOnly) {\n prevByPath.name = [...new Set([...prevByPath.name, ...curr.name])]\n\n return prev\n }\n\n return [...prev, curr]\n },\n [] as Array<KubbFile.Export>,\n )\n}\n\nexport function combineImports(imports: Array<KubbFile.Import>, exports: Array<KubbFile.Export>, source?: string): Array<KubbFile.Import> {\n return orderBy(imports, [\n (v) => !!Array.isArray(v.name),\n (v) => !v.isTypeOnly,\n (v) => v.path,\n (v) => !!v.name,\n (v) => (Array.isArray(v.name) ? orderBy(v.name) : v.name),\n ]).reduce(\n (prev, curr) => {\n let name = Array.isArray(curr.name) ? [...new Set(curr.name)] : curr.name\n\n const hasImportInSource = (importName: string) => {\n if (!source) {\n return true\n }\n\n const checker = (name?: string) => {\n return name && source.includes(name)\n }\n\n return checker(importName) || exports.some(({ name }) => (Array.isArray(name) ? name.some(checker) : checker(name)))\n }\n\n if (curr.path === curr.root) {\n // root and path are the same file, remove the \"./\" import\n return prev\n }\n\n // merge all names and check if the importName is being used in the generated source and if not filter those imports out\n if (Array.isArray(name)) {\n name = name.filter((item) => (typeof item === 'string' ? hasImportInSource(item) : hasImportInSource(item.propertyName)))\n }\n\n const prevByPath = prev.findLast((imp) => imp.path === curr.path && imp.isTypeOnly === curr.isTypeOnly)\n const uniquePrev = prev.findLast((imp) => imp.path === curr.path && isDeepEqual(imp.name, name) && imp.isTypeOnly === curr.isTypeOnly)\n const prevByPathNameAndIsTypeOnly = prev.findLast((imp) => imp.path === curr.path && isDeepEqual(imp.name, name) && imp.isTypeOnly)\n\n if (prevByPathNameAndIsTypeOnly) {\n // we already have an export that has the same path but uses `isTypeOnly` (import type ...)\n return prev\n }\n\n // already unique enough or name is empty\n if (uniquePrev || (Array.isArray(name) && !name.length)) {\n return prev\n }\n\n // new item, append name\n if (!prevByPath) {\n return [\n ...prev,\n {\n ...curr,\n name,\n },\n ]\n }\n\n // merge all names when prev and current both have the same isTypeOnly set\n if (prevByPath && Array.isArray(prevByPath.name) && Array.isArray(name) && prevByPath.isTypeOnly === curr.isTypeOnly) {\n prevByPath.name = [...new Set([...prevByPath.name, ...name])]\n\n return prev\n }\n\n // no import was found in the source, ignore import\n if (!Array.isArray(name) && name && !hasImportInSource(name)) {\n return prev\n }\n\n return [...prev, curr]\n },\n [] as Array<KubbFile.Import>,\n )\n}\n\n/**\n * Helper to create a file with name and id set\n */\nexport function createFile<TMeta extends object = object>(file: KubbFile.File<TMeta>): KubbFile.ResolvedFile<TMeta> {\n const extname = path.extname(file.baseName) as KubbFile.Extname\n if (!extname) {\n throw new Error(`No extname found for ${file.baseName}`)\n }\n\n const source = file.sources.map((item) => item.value).join('\\n\\n')\n const exports = file.exports?.length ? combineExports(file.exports) : []\n const imports = file.imports?.length && source ? combineImports(file.imports, exports, source) : []\n const sources = file.sources?.length ? combineSources(file.sources) : []\n\n return {\n ...file,\n id: hashObject({ path: file.path }),\n name: trimExtName(file.baseName),\n extname,\n imports: imports,\n exports: exports,\n sources: sources,\n meta: file.meta || ({} as TMeta),\n }\n}\n","import { EventEmitter as NodeEventEmitter } from 'node:events'\n\nexport class AsyncEventEmitter<TEvents extends Record<string, any>> {\n constructor(maxListener = 100) {\n this.#emitter.setMaxListeners(maxListener)\n }\n #emitter = new NodeEventEmitter()\n\n async emit<TEventName extends keyof TEvents & string>(eventName: TEventName, ...eventArgs: TEvents[TEventName]): Promise<void> {\n const listeners = this.#emitter.listeners(eventName) as Array<(...args: TEvents[TEventName]) => any>\n\n if (listeners.length === 0) {\n return undefined\n }\n\n await Promise.all(\n listeners.map(async (listener) => {\n try {\n return await listener(...eventArgs)\n } catch (err) {\n console.error(`Error in async listener for \"${eventName}\":`, err)\n }\n }),\n )\n }\n\n on<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArg: TEvents[TEventName]) => void): void {\n this.#emitter.on(eventName, handler as any)\n }\n\n off<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArg: TEvents[TEventName]) => void): void {\n this.#emitter.off(eventName, handler as any)\n }\n removeAll(): void {\n this.#emitter.removeAllListeners()\n }\n}\n","import type * as KubbFile from './KubbFile.ts'\nimport pLimit from 'p-limit'\n\nimport type { Parser } from './parsers/types.ts'\nimport { defaultParser } from './parsers/defaultParser.ts'\nimport { AsyncEventEmitter } from './utils/AsyncEventEmitter.ts'\nimport type { AppEvents } from './App.ts'\n\nexport type ProcessFilesProps = {\n parsers?: Set<Parser>\n extension?: Record<KubbFile.Extname, KubbFile.Extname | ''>\n dryRun?: boolean\n}\n\ntype GetParseOptions = {\n parsers?: Set<Parser>\n extension?: Record<KubbFile.Extname, KubbFile.Extname | ''>\n}\n\ntype Options = {\n events?: AsyncEventEmitter<AppEvents>\n}\n\nexport class FileProcessor {\n #limit = pLimit(100)\n events: AsyncEventEmitter<AppEvents>\n\n constructor({ events = new AsyncEventEmitter<AppEvents>() }: Options = {}) {\n this.events = events\n\n return this\n }\n\n async parse(file: KubbFile.ResolvedFile, { parsers = new Set(), extension }: GetParseOptions = {}): Promise<string> {\n const parseExtName = extension?.[file.extname] || undefined\n\n if (!file.extname) {\n return defaultParser.parse(file, { extname: parseExtName })\n }\n\n let parser: Parser | undefined\n for (const item of parsers) {\n if (item.extNames?.includes(file.extname)) {\n parser = item\n break\n }\n }\n\n if (!parser) {\n return defaultParser.parse(file, { extname: parseExtName })\n }\n\n return parser.parse(file, { extname: parseExtName })\n }\n\n async run(files: Array<KubbFile.ResolvedFile>, { parsers, dryRun, extension }: ProcessFilesProps = {}): Promise<KubbFile.ResolvedFile[]> {\n await this.events.emit('process:start', { files })\n\n let processed = 0\n const total = files.length\n\n const promises = files.map((resolvedFile, index) =>\n this.#limit(async () => {\n await this.events.emit('file:start', { file: resolvedFile, index, total })\n\n if (!dryRun) {\n const source = await this.parse(resolvedFile, { extension, parsers })\n const nextProcessed = processed + 1\n const percentage = (nextProcessed / total) * 100\n processed = nextProcessed\n await this.events.emit('process:progress', { file: resolvedFile, source, processed, percentage, total })\n }\n\n await this.events.emit('file:end', { file: resolvedFile, index, total })\n\n processed++\n }),\n )\n\n await Promise.all(promises)\n\n await this.events.emit('process:end', { files })\n\n return files\n }\n}\n","import type * as KubbFile from './KubbFile.ts'\nimport { Cache } from './utils/Cache.ts'\nimport { trimExtName } from './utils/trimExtName.ts'\nimport { orderBy } from 'natural-orderby'\nimport { createFile } from './createFile.ts'\nimport { FileProcessor, type ProcessFilesProps } from './FileProcessor.ts'\nimport { AsyncEventEmitter } from './utils/AsyncEventEmitter.ts'\nimport type { AppEvents } from './App.ts'\n\nfunction mergeFile<TMeta extends object = object>(a: KubbFile.File<TMeta>, b: KubbFile.File<TMeta>): KubbFile.File<TMeta> {\n return {\n ...a,\n sources: [...(a.sources || []), ...(b.sources || [])],\n imports: [...(a.imports || []), ...(b.imports || [])],\n exports: [...(a.exports || []), ...(b.exports || [])],\n }\n}\n\ntype Options = {\n events?: AsyncEventEmitter<AppEvents>\n}\n\nexport class FileManager {\n #cache = new Cache<KubbFile.ResolvedFile>()\n processor: FileProcessor\n\n constructor({ events = new AsyncEventEmitter<AppEvents>() }: Options = {}) {\n this.processor = new FileProcessor({ events })\n return this\n }\n\n async add(...files: Array<KubbFile.File>) {\n const resolvedFiles: Array<KubbFile.ResolvedFile> = []\n\n const mergedFiles = new Map<string, KubbFile.File>()\n\n files.forEach((file) => {\n const existing = mergedFiles.get(file.path)\n if (existing) {\n mergedFiles.set(file.path, mergeFile(existing, file))\n } else {\n mergedFiles.set(file.path, file)\n }\n })\n\n for (const file of mergedFiles.values()) {\n const existing = this.#cache.get(file.path)\n\n const merged = existing ? mergeFile(existing, file) : file\n const resolvedFile = createFile(merged)\n\n this.#cache.set(resolvedFile.path, resolvedFile)\n this.flush()\n\n resolvedFiles.push(resolvedFile)\n }\n\n return resolvedFiles\n }\n\n flush() {\n this.#cache.flush()\n }\n\n getByPath(path: KubbFile.Path): KubbFile.ResolvedFile | null {\n return this.#cache.get(path)\n }\n\n deleteByPath(path: KubbFile.Path): void {\n this.#cache.delete(path)\n }\n\n clear(): void {\n this.#cache.clear()\n }\n\n get files(): Array<KubbFile.ResolvedFile> {\n const cachedKeys = this.#cache.keys()\n\n // order by path length and if file is a barrel file\n const keys = orderBy(cachedKeys, [(v) => v.length, (v) => trimExtName(v).endsWith('index')])\n\n const files = keys.map((key) => this.#cache.get(key))\n\n return files.filter(Boolean)\n }\n\n async write(options: ProcessFilesProps): Promise<KubbFile.ResolvedFile[]> {\n return this.processor.run(this.files, options)\n }\n}\n","import { FileManager } from './FileManager.ts'\nimport { isFunction } from 'remeda'\nimport type { Plugin } from './plugins/types.ts'\nimport type { Parser } from './parsers/types.ts'\nimport { AsyncEventEmitter } from './utils/AsyncEventEmitter.ts'\nimport type { AppContext, Component, AppEvents } from './App.ts'\n\nimport type { App } from './index.ts'\n\ntype RootRenderFunction<TApp extends App> = (app: TApp) => void | Promise<void>\n\nexport type DefineApp<TOptions> = (rootComponent?: Component, options?: TOptions) => App\n\nexport function defineApp<TOptions = unknown>(instance?: RootRenderFunction<App<TOptions>>): DefineApp<TOptions> {\n function createApp(options?: TOptions): App {\n const events = new AsyncEventEmitter<AppEvents>()\n const installedPlugins = new Set<Plugin>()\n const installedParsers = new Set<Parser>()\n const fileManager = new FileManager({ events })\n const context = {\n events,\n options,\n fileManager,\n installedPlugins,\n installedParsers,\n } as AppContext<TOptions>\n\n const app = {\n context,\n get files() {\n return fileManager.files\n },\n async addFile(...newFiles) {\n await fileManager.add(...newFiles)\n },\n async use(pluginOrParser, ...options) {\n const args = options\n\n if (pluginOrParser.type === 'plugin') {\n if (installedPlugins.has(pluginOrParser)) {\n console.warn('Plugin has already been applied to target app.')\n } else {\n installedPlugins.add(pluginOrParser)\n }\n\n if (pluginOrParser.inject && isFunction(pluginOrParser.inject)) {\n const injecter = pluginOrParser.inject\n\n const extraApp = (injecter as any)(app, ...args)\n Object.assign(app, extraApp)\n }\n }\n if (pluginOrParser.type === 'parser') {\n if (installedParsers.has(pluginOrParser)) {\n console.warn('Parser has already been applied to target app.')\n } else {\n installedParsers.add(pluginOrParser)\n }\n }\n\n if (pluginOrParser && isFunction(pluginOrParser.install)) {\n const installer = pluginOrParser.install\n\n await (installer as any)(app, ...args)\n }\n\n return app\n },\n } as App<TOptions>\n\n // start\n events.emit('start')\n if (instance) {\n instance(app)\n }\n\n // end\n events.emit('end')\n\n return app\n }\n\n return createApp\n}\n","import { defineApp } from './defineApp.ts'\n\nexport const createApp = defineApp()\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAa,QAAb,MAAsB;;4DACV,IAAI,KAAgB;;CAE9B,IAAI,KAAuB;;AACzB,6DAAO,KAAY,CAAC,IAAI,IAAI,+DAAI;;CAGlC,IAAI,KAAa,OAAgB;AAC/B,uCAAY,CAAC,IAAI,KAAK,MAAM;;CAG9B,OAAO,KAAmB;AACxB,uCAAY,CAAC,OAAO,IAAI;;CAG1B,QAAc;AACZ,uCAAY,CAAC,OAAO;;CAGtB,OAAiB;AACf,SAAO,CAAC,mCAAG,KAAY,CAAC,MAAM,CAAC;;CAGjC,SAAmB;AACjB,SAAO,CAAC,mCAAG,KAAY,CAAC,QAAQ,CAAC;;CAGnC,QAAc;;;;;ACpBhB,SAAS,WAAW,KAAsC;CACxD,MAAM,MAAM,KAAK,UAAU,KAAK,OAAO,KAAK,IAAI,CAAC,MAAM,CAAC;AACxD,QAAO,WAAW,SAAS,CAAC,OAAO,IAAI,CAAC,OAAO,MAAM;;AAGvD,SAAgB,eAAe,SAAyD;AACtF,QAAO,SAAS,UAAU,QAAQ;EAAC,IAAI;EAAM,IAAI;EAAc,IAAI;EAAW,CAAU;;AAG1F,SAAgB,eAAe,SAAyD;AACtF,QAAO,QAAQ,SAAS;GACrB,MAAM,CAAC,CAAC,MAAM,QAAQ,EAAE,KAAK;GAC7B,MAAM,CAAC,EAAE;GACT,MAAM,EAAE;GACR,MAAM,CAAC,CAAC,EAAE;GACV,MAAO,MAAM,QAAQ,EAAE,KAAK,GAAG,QAAQ,EAAE,KAAK,GAAG,EAAE;EACrD,CAAC,CAAC,QACA,MAAM,SAAS;EACd,MAAM,OAAO,KAAK;EAClB,MAAM,aAAa,KAAK,UAAU,QAAQ,IAAI,SAAS,KAAK,KAAK;AAGjE,MAFgC,KAAK,UAAU,QAAQ,IAAI,SAA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,KAAK,MAAM;AAElB,SAAO;;AAGT,QAAOD;;;;;AChFT,MAAa,YAAY,WAAW"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import "../App-
|
|
2
|
-
import { i as typescriptParser, n as createImport, r as print, t as createExport } from "../typescriptParser
|
|
1
|
+
import "../App-KqAHuAyU.cjs";
|
|
2
|
+
import { i as typescriptParser, n as createImport, r as print, t as createExport } from "../typescriptParser-Du4RIToQ.cjs";
|
|
3
3
|
export { createExport, createImport, print, typescriptParser };
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import "../App-
|
|
2
|
-
import { i as typescriptParser, n as createImport, r as print, t as createExport } from "../typescriptParser-
|
|
1
|
+
import "../App-9ie0H1SF.js";
|
|
2
|
+
import { i as typescriptParser, n as createImport, r as print, t as createExport } from "../typescriptParser-Dk1rwKyJ.js";
|
|
3
3
|
export { createExport, createImport, print, typescriptParser };
|
package/dist/parsers.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { o as Parser, s as UserParser } from "./App-
|
|
2
|
-
import { i as typescriptParser } from "./typescriptParser
|
|
1
|
+
import { o as Parser, s as UserParser } from "./App-KqAHuAyU.cjs";
|
|
2
|
+
import { i as typescriptParser } from "./typescriptParser-Du4RIToQ.cjs";
|
|
3
3
|
|
|
4
4
|
//#region src/parsers/createParser.d.ts
|
|
5
5
|
declare function createParser<TOptions = any[], TMeta extends object = any>(parser: UserParser<TOptions, TMeta>): Parser<TOptions, TMeta>;
|
package/dist/parsers.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { o as Parser, s as UserParser } from "./App-
|
|
2
|
-
import { i as typescriptParser } from "./typescriptParser-
|
|
1
|
+
import { o as Parser, s as UserParser } from "./App-9ie0H1SF.js";
|
|
2
|
+
import { i as typescriptParser } from "./typescriptParser-Dk1rwKyJ.js";
|
|
3
3
|
|
|
4
4
|
//#region src/parsers/createParser.d.ts
|
|
5
5
|
declare function createParser<TOptions = any[], TMeta extends object = any>(parser: UserParser<TOptions, TMeta>): Parser<TOptions, TMeta>;
|
package/dist/plugins.cjs
CHANGED
|
@@ -49,12 +49,14 @@ async function write(path, data, options = {}) {
|
|
|
49
49
|
}
|
|
50
50
|
const fsPlugin = createPlugin({
|
|
51
51
|
name: "fs",
|
|
52
|
-
scope: "write",
|
|
53
52
|
async install(app, options) {
|
|
54
53
|
app.context.events.on("process:progress", async ({ file, source }) => {
|
|
55
54
|
if (options === null || options === void 0 ? void 0 : options.onWrite) await options.onWrite(file.path, source);
|
|
56
55
|
await write(file.path, source, { sanity: false });
|
|
57
56
|
});
|
|
57
|
+
app.context.events.on("start", async () => {
|
|
58
|
+
if (options === null || options === void 0 ? void 0 : options.clean) await fs_extra.default.remove(options.clean.path);
|
|
59
|
+
});
|
|
58
60
|
},
|
|
59
61
|
inject(app) {
|
|
60
62
|
return { async write(options = {
|
package/dist/plugins.cjs.map
CHANGED
|
@@ -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 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 '
|
|
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 clean?: {\n path: string\n }\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\n// biome-ignore lint/suspicious/noTsIgnore: production ready\n// @ts-ignore\ndeclare module '@kubb/fabric-core' {\n interface App {\n write(options?: WriteOptions): Promise<void>\n }\n}\n\ndeclare global {\n namespace Kubb {\n interface App {\n write(options?: WriteOptions): Promise<void>\n }\n }\n}\n\nexport const fsPlugin = createPlugin<Options, ExtendOptions>({\n name: 'fs',\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 app.context.events.on('start', async () => {\n if (options?.clean) {\n await fs.remove(options.clean.path)\n }\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;;;;;ACkBH,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;;AAmB/B,MAAa,WAAW,aAAqC;CAC3D,MAAM;CACN,MAAM,QAAQ,KAAK,SAAS;AAC1B,MAAI,QAAQ,OAAO,GAAG,oBAAoB,OAAO,EAAE,MAAM,aAAa;AACpE,yDAAI,QAAS,QACX,OAAM,QAAQ,QAAQ,KAAK,MAAM,OAAO;AAE1C,SAAM,MAAM,KAAK,MAAM,QAAQ,EAAE,QAAQ,OAAO,CAAC;IACjD;AAEF,MAAI,QAAQ,OAAO,GAAG,SAAS,YAAY;AACzC,yDAAI,QAAS,MACX,OAAMF,iBAAG,OAAO,QAAQ,MAAM,KAAK;IAErC;;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"}
|
package/dist/plugins.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { c as Plugin, l as UserPlugin, u as Extname } from "./App-
|
|
1
|
+
import { c as Plugin, l as UserPlugin, u as Extname } from "./App-KqAHuAyU.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>;
|
|
@@ -14,15 +14,25 @@ type Options = {
|
|
|
14
14
|
* Useful for tests to observe write operations without spying on internal functions.
|
|
15
15
|
*/
|
|
16
16
|
onWrite?: (path: string, data: string) => void | Promise<void>;
|
|
17
|
+
clean?: {
|
|
18
|
+
path: string;
|
|
19
|
+
};
|
|
17
20
|
};
|
|
18
21
|
type ExtendOptions = {
|
|
19
22
|
write(options?: WriteOptions): Promise<void>;
|
|
20
23
|
};
|
|
21
|
-
declare module '
|
|
24
|
+
declare module '@kubb/fabric-core' {
|
|
22
25
|
interface App {
|
|
23
26
|
write(options?: WriteOptions): Promise<void>;
|
|
24
27
|
}
|
|
25
28
|
}
|
|
29
|
+
declare global {
|
|
30
|
+
namespace Kubb {
|
|
31
|
+
interface App {
|
|
32
|
+
write(options?: WriteOptions): Promise<void>;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
26
36
|
declare const fsPlugin: Plugin<Options, ExtendOptions>;
|
|
27
37
|
//#endregion
|
|
28
38
|
export { createPlugin, fsPlugin };
|
package/dist/plugins.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { c as Plugin, l as UserPlugin, u as Extname } from "./App-
|
|
1
|
+
import { c as Plugin, l as UserPlugin, u as Extname } from "./App-9ie0H1SF.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>;
|
|
@@ -14,15 +14,25 @@ type Options = {
|
|
|
14
14
|
* Useful for tests to observe write operations without spying on internal functions.
|
|
15
15
|
*/
|
|
16
16
|
onWrite?: (path: string, data: string) => void | Promise<void>;
|
|
17
|
+
clean?: {
|
|
18
|
+
path: string;
|
|
19
|
+
};
|
|
17
20
|
};
|
|
18
21
|
type ExtendOptions = {
|
|
19
22
|
write(options?: WriteOptions): Promise<void>;
|
|
20
23
|
};
|
|
21
|
-
declare module '
|
|
24
|
+
declare module '@kubb/fabric-core' {
|
|
22
25
|
interface App {
|
|
23
26
|
write(options?: WriteOptions): Promise<void>;
|
|
24
27
|
}
|
|
25
28
|
}
|
|
29
|
+
declare global {
|
|
30
|
+
namespace Kubb {
|
|
31
|
+
interface App {
|
|
32
|
+
write(options?: WriteOptions): Promise<void>;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
26
36
|
declare const fsPlugin: Plugin<Options, ExtendOptions>;
|
|
27
37
|
//#endregion
|
|
28
38
|
export { createPlugin, fsPlugin };
|
package/dist/plugins.js
CHANGED
|
@@ -45,12 +45,14 @@ async function write(path$1, data, options = {}) {
|
|
|
45
45
|
}
|
|
46
46
|
const fsPlugin = createPlugin({
|
|
47
47
|
name: "fs",
|
|
48
|
-
scope: "write",
|
|
49
48
|
async install(app, options) {
|
|
50
49
|
app.context.events.on("process:progress", async ({ file, source }) => {
|
|
51
50
|
if (options === null || options === void 0 ? void 0 : options.onWrite) await options.onWrite(file.path, source);
|
|
52
51
|
await write(file.path, source, { sanity: false });
|
|
53
52
|
});
|
|
53
|
+
app.context.events.on("start", async () => {
|
|
54
|
+
if (options === null || options === void 0 ? void 0 : options.clean) await fs.remove(options.clean.path);
|
|
55
|
+
});
|
|
54
56
|
},
|
|
55
57
|
inject(app) {
|
|
56
58
|
return { async write(options = {
|
package/dist/plugins.js.map
CHANGED
|
@@ -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 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 '
|
|
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 clean?: {\n path: string\n }\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\n// biome-ignore lint/suspicious/noTsIgnore: production ready\n// @ts-ignore\ndeclare module '@kubb/fabric-core' {\n interface App {\n write(options?: WriteOptions): Promise<void>\n }\n}\n\ndeclare global {\n namespace Kubb {\n interface App {\n write(options?: WriteOptions): Promise<void>\n }\n }\n}\n\nexport const fsPlugin = createPlugin<Options, ExtendOptions>({\n name: 'fs',\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 app.context.events.on('start', async () => {\n if (options?.clean) {\n await fs.remove(options.clean.path)\n }\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;;;;;ACkBH,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,EAC5C,OAAM,IAAI,MAAM,2BAA2BD,OAAK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
|
|
|
1
|
-
import { f as KubbFile_d_exports, n as AppContext, t as App } from "./App-
|
|
2
|
-
import {
|
|
1
|
+
import { f as KubbFile_d_exports, n as AppContext, t as App } from "./App-KqAHuAyU.cjs";
|
|
2
|
+
import { r as DefineApp } from "./index-DLITiDO5.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-
|
|
2
|
-
import {
|
|
1
|
+
import { f as KubbFile_d_exports, n as AppContext, t as App } from "./App-9ie0H1SF.js";
|
|
2
|
+
import { r as DefineApp } from "./index-BpPNNyhl.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-
|
|
1
|
+
import { o as Parser } from "./App-9ie0H1SF.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-
|
|
50
|
+
//# sourceMappingURL=typescriptParser-Dk1rwKyJ.d.ts.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { o as Parser } from "./App-
|
|
1
|
+
import { o as Parser } from "./App-KqAHuAyU.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
|
|
50
|
+
//# sourceMappingURL=typescriptParser-Du4RIToQ.d.cts.map
|
package/package.json
CHANGED
package/src/App.ts
CHANGED
|
@@ -4,17 +4,23 @@ import type { Parser } from './parsers/types.ts'
|
|
|
4
4
|
import type { AsyncEventEmitter } from './utils/AsyncEventEmitter.ts'
|
|
5
5
|
import type { FileManager } from './FileManager.ts'
|
|
6
6
|
|
|
7
|
+
declare global {
|
|
8
|
+
namespace Kubb {
|
|
9
|
+
interface App {}
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
7
13
|
export type Component = any
|
|
8
14
|
|
|
9
15
|
export type AppEvents = {
|
|
10
16
|
/**
|
|
11
17
|
* Called in the beginning of the app lifecycle.
|
|
12
18
|
*/
|
|
13
|
-
start: [
|
|
19
|
+
start: []
|
|
14
20
|
/**
|
|
15
21
|
* Called in the end of the app lifecycle.
|
|
16
22
|
*/
|
|
17
|
-
end: [
|
|
23
|
+
end: []
|
|
18
24
|
/**
|
|
19
25
|
* Called when being rendered
|
|
20
26
|
*/
|
|
@@ -74,9 +80,10 @@ export type Inject<TOptions = any[] | object | undefined, TAppExtension extends
|
|
|
74
80
|
? (app: App, options?: TOptions) => Partial<TAppExtension>
|
|
75
81
|
: (app: App) => Partial<TAppExtension>
|
|
76
82
|
|
|
77
|
-
export interface App<TOptions = unknown> {
|
|
83
|
+
export interface App<TOptions = unknown> extends Kubb.App {
|
|
78
84
|
context: AppContext<TOptions>
|
|
79
85
|
files: Array<KubbFile.ResolvedFile>
|
|
86
|
+
// sync
|
|
80
87
|
use<TOptions extends any[] | object = any, TMeta extends object = object, TAppExtension extends Record<string, any> = {}>(
|
|
81
88
|
pluginOrParser: Plugin<TOptions, TAppExtension> | Parser<TOptions, TMeta>,
|
|
82
89
|
...options: TOptions extends any[] ? NoInfer<TOptions> : [NoInfer<TOptions>]
|
|
@@ -84,5 +91,13 @@ export interface App<TOptions = unknown> {
|
|
|
84
91
|
use<TOptions extends any[] | object = any, TMeta extends object = object, TAppExtension extends Record<string, any> = {}>(
|
|
85
92
|
pluginOrParser: Plugin<TOptions, TAppExtension> | Parser<TOptions, TMeta>,
|
|
86
93
|
): this & TAppExtension
|
|
94
|
+
// async
|
|
95
|
+
use<TOptions extends any[] | object = any, TMeta extends object = object, TAppExtension extends Record<string, any> = {}>(
|
|
96
|
+
pluginOrParser: Plugin<TOptions, TAppExtension> | Parser<TOptions, TMeta>,
|
|
97
|
+
...options: TOptions extends any[] ? NoInfer<TOptions> : [NoInfer<TOptions>]
|
|
98
|
+
): Promise<this & TAppExtension>
|
|
99
|
+
use<TOptions extends any[] | object = any, TMeta extends object = object, TAppExtension extends Record<string, any> = {}>(
|
|
100
|
+
pluginOrParser: Plugin<TOptions, TAppExtension> | Parser<TOptions, TMeta>,
|
|
101
|
+
): Promise<this & TAppExtension>
|
|
87
102
|
addFile(...files: Array<KubbFile.File>): Promise<void>
|
|
88
103
|
}
|
package/src/defineApp.ts
CHANGED
|
@@ -3,7 +3,9 @@ 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 {
|
|
6
|
+
import type { AppContext, Component, AppEvents } from './App.ts'
|
|
7
|
+
|
|
8
|
+
import type { App } from './index.ts'
|
|
7
9
|
|
|
8
10
|
type RootRenderFunction<TApp extends App> = (app: TApp) => void | Promise<void>
|
|
9
11
|
|
|
@@ -31,7 +33,7 @@ export function defineApp<TOptions = unknown>(instance?: RootRenderFunction<App<
|
|
|
31
33
|
async addFile(...newFiles) {
|
|
32
34
|
await fileManager.add(...newFiles)
|
|
33
35
|
},
|
|
34
|
-
use(pluginOrParser, ...options) {
|
|
36
|
+
async use(pluginOrParser, ...options) {
|
|
35
37
|
const args = options
|
|
36
38
|
|
|
37
39
|
if (pluginOrParser.type === 'plugin') {
|
|
@@ -59,7 +61,7 @@ export function defineApp<TOptions = unknown>(instance?: RootRenderFunction<App<
|
|
|
59
61
|
if (pluginOrParser && isFunction(pluginOrParser.install)) {
|
|
60
62
|
const installer = pluginOrParser.install
|
|
61
63
|
|
|
62
|
-
|
|
64
|
+
await (installer as any)(app, ...args)
|
|
63
65
|
}
|
|
64
66
|
|
|
65
67
|
return app
|
|
@@ -67,11 +69,14 @@ export function defineApp<TOptions = unknown>(instance?: RootRenderFunction<App<
|
|
|
67
69
|
} as App<TOptions>
|
|
68
70
|
|
|
69
71
|
// start
|
|
70
|
-
events.emit('start'
|
|
72
|
+
events.emit('start')
|
|
71
73
|
if (instance) {
|
|
72
74
|
instance(app)
|
|
73
75
|
}
|
|
74
76
|
|
|
77
|
+
// end
|
|
78
|
+
events.emit('end')
|
|
79
|
+
|
|
75
80
|
return app
|
|
76
81
|
}
|
|
77
82
|
|
package/src/plugins/fsPlugin.ts
CHANGED
|
@@ -15,6 +15,9 @@ type Options = {
|
|
|
15
15
|
* Useful for tests to observe write operations without spying on internal functions.
|
|
16
16
|
*/
|
|
17
17
|
onWrite?: (path: string, data: string) => void | Promise<void>
|
|
18
|
+
clean?: {
|
|
19
|
+
path: string
|
|
20
|
+
}
|
|
18
21
|
}
|
|
19
22
|
|
|
20
23
|
type ExtendOptions = {
|
|
@@ -80,15 +83,24 @@ export async function write(path: string, data: string, options: { sanity?: bool
|
|
|
80
83
|
)(path, data.trim(), options)
|
|
81
84
|
}
|
|
82
85
|
|
|
83
|
-
|
|
86
|
+
// biome-ignore lint/suspicious/noTsIgnore: production ready
|
|
87
|
+
// @ts-ignore
|
|
88
|
+
declare module '@kubb/fabric-core' {
|
|
84
89
|
interface App {
|
|
85
90
|
write(options?: WriteOptions): Promise<void>
|
|
86
91
|
}
|
|
87
92
|
}
|
|
88
93
|
|
|
94
|
+
declare global {
|
|
95
|
+
namespace Kubb {
|
|
96
|
+
interface App {
|
|
97
|
+
write(options?: WriteOptions): Promise<void>
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
89
102
|
export const fsPlugin = createPlugin<Options, ExtendOptions>({
|
|
90
103
|
name: 'fs',
|
|
91
|
-
scope: 'write',
|
|
92
104
|
async install(app, options) {
|
|
93
105
|
app.context.events.on('process:progress', async ({ file, source }) => {
|
|
94
106
|
if (options?.onWrite) {
|
|
@@ -96,6 +108,12 @@ export const fsPlugin = createPlugin<Options, ExtendOptions>({
|
|
|
96
108
|
}
|
|
97
109
|
await write(file.path, source, { sanity: false })
|
|
98
110
|
})
|
|
111
|
+
|
|
112
|
+
app.context.events.on('start', async () => {
|
|
113
|
+
if (options?.clean) {
|
|
114
|
+
await fs.remove(options.clean.path)
|
|
115
|
+
}
|
|
116
|
+
})
|
|
99
117
|
},
|
|
100
118
|
inject(app) {
|
|
101
119
|
return {
|
package/src/plugins/types.ts
CHANGED
|
@@ -3,11 +3,11 @@ import type { Install, Inject } from '../App.ts'
|
|
|
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
12
|
inject?: Inject<TOptions, TAppExtension>
|
|
13
13
|
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { r as Component, t as App } from "./App-BxAl3dNP.js";
|
|
2
|
-
|
|
3
|
-
//#region src/defineApp.d.ts
|
|
4
|
-
type RootRenderFunction<TApp extends App> = (app: TApp) => void | Promise<void>;
|
|
5
|
-
type DefineApp<TOptions> = (rootComponent?: Component, options?: TOptions) => App;
|
|
6
|
-
declare function defineApp<TOptions = unknown>(instance?: RootRenderFunction<App<TOptions>>): DefineApp<TOptions>;
|
|
7
|
-
//#endregion
|
|
8
|
-
export { defineApp as n, DefineApp as t };
|
|
9
|
-
//# sourceMappingURL=defineApp-B9W1A5SV.d.ts.map
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { r as Component, t as App } from "./App-D3DHa4Il.cjs";
|
|
2
|
-
|
|
3
|
-
//#region src/defineApp.d.ts
|
|
4
|
-
type RootRenderFunction<TApp extends App> = (app: TApp) => void | Promise<void>;
|
|
5
|
-
type DefineApp<TOptions> = (rootComponent?: Component, options?: TOptions) => App;
|
|
6
|
-
declare function defineApp<TOptions = unknown>(instance?: RootRenderFunction<App<TOptions>>): DefineApp<TOptions>;
|
|
7
|
-
//#endregion
|
|
8
|
-
export { defineApp as n, DefineApp as t };
|
|
9
|
-
//# sourceMappingURL=defineApp-BP97CT5p.d.cts.map
|