@kubb/fabric-core 0.2.14 → 0.2.15
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/README.md +5 -1
- package/dist/{Fabric-CxMkO4Rt.d.ts → Fabric-0mXLgmur.d.cts} +22 -21
- package/dist/{Fabric-BfnUdEpq.d.cts → Fabric-C-AqOkTA.d.ts} +22 -21
- package/dist/{defineFabric-CR1OjcoI.d.ts → defineFabric-D_m6CB1s.d.ts} +2 -2
- package/dist/{defineFabric-TvKfRefj.d.cts → defineFabric-Dkt2l0wC.d.cts} +2 -2
- package/dist/{defineProperty-CspRhtP3.cjs → defineProperty-B05cRoSl.cjs} +26 -26
- package/dist/{defineProperty-CspRhtP3.cjs.map → defineProperty-B05cRoSl.cjs.map} +1 -1
- package/dist/{defineProperty-BtekiGIK.js → defineProperty-BZknW4oy.js} +27 -27
- package/dist/{defineProperty-BtekiGIK.js.map → defineProperty-BZknW4oy.js.map} +1 -1
- package/dist/index.cjs +50 -39
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +50 -39
- 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.cjs.map +1 -1
- package/dist/parsers.d.cts +2 -2
- package/dist/parsers.d.ts +2 -2
- package/dist/parsers.js.map +1 -1
- package/dist/plugins.cjs +96 -96
- package/dist/plugins.cjs.map +1 -1
- package/dist/plugins.d.cts +35 -35
- package/dist/plugins.d.ts +35 -35
- package/dist/plugins.js +94 -94
- package/dist/plugins.js.map +1 -1
- package/dist/types.d.cts +2 -2
- package/dist/types.d.ts +2 -2
- package/dist/{typescriptParser-Dz9T1BQ1.d.cts → typescriptParser-B4-y6QxR.d.cts} +2 -2
- package/dist/{typescriptParser-DypTa1AN.d.ts → typescriptParser-By3ckLtc.d.ts} +2 -2
- package/dist/typescriptParser-CNHO6H2_.cjs.map +1 -1
- package/dist/typescriptParser-CWT7zCJy.js.map +1 -1
- package/package.json +1 -1
- package/src/Fabric.ts +12 -11
- package/src/FileManager.ts +4 -4
- package/src/FileProcessor.ts +3 -4
- package/src/createFile.ts +3 -3
- package/src/defineFabric.ts +16 -8
- package/src/index.ts +3 -3
- package/src/parsers/tsxParser.ts +1 -1
- package/src/parsers/types.ts +1 -1
- package/src/parsers/typescriptParser.ts +1 -1
- package/src/plugins/barrelPlugin.ts +13 -13
- package/src/plugins/fsPlugin.ts +8 -8
- package/src/plugins/graphPlugin.ts +8 -9
- package/src/plugins/index.ts +2 -3
- package/src/plugins/progressPlugin.ts +6 -6
- package/src/plugins/types.ts +1 -1
- package/src/types.ts +2 -2
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const require_trimExtName = require('./trimExtName-Bb4zGVF1.cjs');
|
|
2
|
-
const require_defineProperty = require('./defineProperty-
|
|
2
|
+
const require_defineProperty = require('./defineProperty-B05cRoSl.cjs');
|
|
3
3
|
require('./createParser-C4IkyTs5.cjs');
|
|
4
4
|
const require_defaultParser = require('./defaultParser-n9VW2iVf.cjs');
|
|
5
5
|
let natural_orderby = require("natural-orderby");
|
|
@@ -9,35 +9,6 @@ p_limit = require_trimExtName.__toESM(p_limit);
|
|
|
9
9
|
let node_events = require("node:events");
|
|
10
10
|
node_events = require_trimExtName.__toESM(node_events);
|
|
11
11
|
|
|
12
|
-
//#region src/utils/Cache.ts
|
|
13
|
-
var _buffer = /* @__PURE__ */ new WeakMap();
|
|
14
|
-
var Cache = class {
|
|
15
|
-
constructor() {
|
|
16
|
-
require_defineProperty._classPrivateFieldInitSpec(this, _buffer, /* @__PURE__ */ new Map());
|
|
17
|
-
}
|
|
18
|
-
get(key) {
|
|
19
|
-
var _this$buffer$get;
|
|
20
|
-
return (_this$buffer$get = require_defineProperty._classPrivateFieldGet2(_buffer, this).get(key)) !== null && _this$buffer$get !== void 0 ? _this$buffer$get : null;
|
|
21
|
-
}
|
|
22
|
-
set(key, value) {
|
|
23
|
-
require_defineProperty._classPrivateFieldGet2(_buffer, this).set(key, value);
|
|
24
|
-
}
|
|
25
|
-
delete(key) {
|
|
26
|
-
require_defineProperty._classPrivateFieldGet2(_buffer, this).delete(key);
|
|
27
|
-
}
|
|
28
|
-
clear() {
|
|
29
|
-
require_defineProperty._classPrivateFieldGet2(_buffer, this).clear();
|
|
30
|
-
}
|
|
31
|
-
keys() {
|
|
32
|
-
return [...require_defineProperty._classPrivateFieldGet2(_buffer, this).keys()];
|
|
33
|
-
}
|
|
34
|
-
values() {
|
|
35
|
-
return [...require_defineProperty._classPrivateFieldGet2(_buffer, this).values()];
|
|
36
|
-
}
|
|
37
|
-
flush() {}
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
//#endregion
|
|
41
12
|
//#region ../../node_modules/.pnpm/remeda@2.32.0/node_modules/remeda/dist/isFunction-BJjFuZR7.js
|
|
42
13
|
const e = (e$1) => typeof e$1 == `function`;
|
|
43
14
|
|
|
@@ -149,6 +120,35 @@ var FileProcessor = class {
|
|
|
149
120
|
}
|
|
150
121
|
};
|
|
151
122
|
|
|
123
|
+
//#endregion
|
|
124
|
+
//#region src/utils/Cache.ts
|
|
125
|
+
var _buffer = /* @__PURE__ */ new WeakMap();
|
|
126
|
+
var Cache = class {
|
|
127
|
+
constructor() {
|
|
128
|
+
require_defineProperty._classPrivateFieldInitSpec(this, _buffer, /* @__PURE__ */ new Map());
|
|
129
|
+
}
|
|
130
|
+
get(key) {
|
|
131
|
+
var _this$buffer$get;
|
|
132
|
+
return (_this$buffer$get = require_defineProperty._classPrivateFieldGet2(_buffer, this).get(key)) !== null && _this$buffer$get !== void 0 ? _this$buffer$get : null;
|
|
133
|
+
}
|
|
134
|
+
set(key, value) {
|
|
135
|
+
require_defineProperty._classPrivateFieldGet2(_buffer, this).set(key, value);
|
|
136
|
+
}
|
|
137
|
+
delete(key) {
|
|
138
|
+
require_defineProperty._classPrivateFieldGet2(_buffer, this).delete(key);
|
|
139
|
+
}
|
|
140
|
+
clear() {
|
|
141
|
+
require_defineProperty._classPrivateFieldGet2(_buffer, this).clear();
|
|
142
|
+
}
|
|
143
|
+
keys() {
|
|
144
|
+
return [...require_defineProperty._classPrivateFieldGet2(_buffer, this).keys()];
|
|
145
|
+
}
|
|
146
|
+
values() {
|
|
147
|
+
return [...require_defineProperty._classPrivateFieldGet2(_buffer, this).values()];
|
|
148
|
+
}
|
|
149
|
+
flush() {}
|
|
150
|
+
};
|
|
151
|
+
|
|
152
152
|
//#endregion
|
|
153
153
|
//#region src/FileManager.ts
|
|
154
154
|
function mergeFile(a, b) {
|
|
@@ -219,14 +219,25 @@ function defineFabric(instance) {
|
|
|
219
219
|
const installedPlugins = /* @__PURE__ */ new Set();
|
|
220
220
|
const installedParsers = /* @__PURE__ */ new Set();
|
|
221
221
|
const fileManager = new FileManager({ events });
|
|
222
|
-
const
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
installedParsers
|
|
222
|
+
const context = {
|
|
223
|
+
get files() {
|
|
224
|
+
return fileManager.files;
|
|
225
|
+
},
|
|
226
|
+
async addFile(...newFiles) {
|
|
227
|
+
await fileManager.add(...newFiles);
|
|
229
228
|
},
|
|
229
|
+
config,
|
|
230
|
+
fileManager,
|
|
231
|
+
installedPlugins,
|
|
232
|
+
installedParsers,
|
|
233
|
+
on: events.on.bind(events),
|
|
234
|
+
off: events.off.bind(events),
|
|
235
|
+
onOnce: events.onOnce.bind(events),
|
|
236
|
+
removeAll: events.removeAll.bind(events),
|
|
237
|
+
emit: events.emit.bind(events)
|
|
238
|
+
};
|
|
239
|
+
const fabric = {
|
|
240
|
+
context,
|
|
230
241
|
get files() {
|
|
231
242
|
return fileManager.files;
|
|
232
243
|
},
|
|
@@ -240,7 +251,7 @@ function defineFabric(instance) {
|
|
|
240
251
|
else installedPlugins.add(pluginOrParser);
|
|
241
252
|
if (pluginOrParser.inject && e(pluginOrParser.inject)) {
|
|
242
253
|
const injecter = pluginOrParser.inject;
|
|
243
|
-
const extraApp = injecter(
|
|
254
|
+
const extraApp = injecter(context, ...args);
|
|
244
255
|
Object.assign(fabric, extraApp);
|
|
245
256
|
}
|
|
246
257
|
}
|
|
@@ -248,7 +259,7 @@ function defineFabric(instance) {
|
|
|
248
259
|
else installedParsers.add(pluginOrParser);
|
|
249
260
|
if (pluginOrParser && e(pluginOrParser.install)) {
|
|
250
261
|
const installer = pluginOrParser.install;
|
|
251
|
-
await installer(
|
|
262
|
+
await installer(context, ...args);
|
|
252
263
|
}
|
|
253
264
|
return fabric;
|
|
254
265
|
}
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["e","NodeEventEmitter","defaultParser","parser: Parser | undefined","resolvedFiles: Array<KubbFile.ResolvedFile>","createFile","trimExtName","isFunction"],"sources":["../src/utils/Cache.ts","../../../node_modules/.pnpm/remeda@2.32.0/node_modules/remeda/dist/isFunction-BJjFuZR7.js","../src/utils/AsyncEventEmitter.ts","../src/FileProcessor.ts","../src/FileManager.ts","../src/defineFabric.ts","../src/createFabric.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","const e=e=>typeof e==`function`;export{e as isFunction};\n//# sourceMappingURL=isFunction-BJjFuZR7.js.map","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 onOnce<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArgs: TEvents[TEventName]) => void): void {\n const wrapper = (...args: TEvents[TEventName]) => {\n this.off(eventName, wrapper)\n handler(...args)\n }\n this.on(eventName, wrapper)\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 { FabricEvents, FabricMode } from './Fabric.ts'\n\nexport type ProcessFilesProps = {\n parsers?: Set<Parser>\n extension?: Record<KubbFile.Extname, KubbFile.Extname | ''>\n dryRun?: boolean\n /**\n * @default 'sequential'\n */\n mode?: FabricMode\n}\n\ntype GetParseOptions = {\n parsers?: Set<Parser>\n extension?: Record<KubbFile.Extname, KubbFile.Extname | ''>\n}\n\ntype Options = {\n events?: AsyncEventEmitter<FabricEvents>\n}\n\nexport class FileProcessor {\n #limit = pLimit(100)\n events: AsyncEventEmitter<FabricEvents>\n\n constructor({ events = new AsyncEventEmitter<FabricEvents>() }: Options = {}) {\n this.events = events\n\n return this\n }\n\n async parse(file: KubbFile.ResolvedFile, { parsers, extension }: GetParseOptions = {}): Promise<string> {\n const parseExtName = extension?.[file.extname] || undefined\n\n if (!parsers) {\n console.warn('No parsers provided, using default parser. If you want to use a specific parser, please provide it in the options.')\n\n return defaultParser.parse(file, { extname: parseExtName })\n }\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(\n files: Array<KubbFile.ResolvedFile>,\n { parsers, mode = 'sequential', dryRun, extension }: ProcessFilesProps = {},\n ): Promise<KubbFile.ResolvedFile[]> {\n await this.events.emit('process:start', { files })\n\n let processed = 0\n const total = files.length\n\n const processOne = async (resolvedFile: KubbFile.ResolvedFile, index: number) => {\n const percentage = (processed / total) * 100\n\n await this.events.emit('file:start', { file: resolvedFile, index, total })\n\n const source = dryRun ? undefined : await this.parse(resolvedFile, { extension, parsers })\n\n await this.events.emit('process:progress', {\n file: resolvedFile,\n source,\n processed,\n percentage,\n total,\n })\n\n processed++\n\n await this.events.emit('file:end', { file: resolvedFile, index, total })\n }\n\n if (mode === 'sequential') {\n async function* asyncFiles() {\n for (let index = 0; index < files.length; index++) {\n yield [files[index], index] as const\n }\n }\n\n for await (const [file, index] of asyncFiles()) {\n if (file) {\n await processOne(file, index)\n }\n }\n } else {\n const promises = files.map((resolvedFile, index) => this.#limit(() => processOne(resolvedFile, index)))\n await Promise.all(promises)\n }\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 { FabricEvents } from './Fabric.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<FabricEvents>\n}\n\nexport class FileManager {\n #cache = new Cache<KubbFile.ResolvedFile>()\n events: AsyncEventEmitter<FabricEvents>\n processor: FileProcessor\n\n constructor({ events = new AsyncEventEmitter<FabricEvents>() }: Options = {}) {\n this.processor = new FileProcessor({ events })\n\n this.events = 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 await this.events.emit('file:add', { files: resolvedFiles })\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 //TODO add test and check if write of FileManager contains the newly added file\n async write(options: ProcessFilesProps): Promise<KubbFile.ResolvedFile[]> {\n await this.events.emit('write:start', { files: this.files })\n\n const resolvedFiles = await this.processor.run(this.files, options)\n\n this.clear()\n\n await this.events.emit('write:end', { files: resolvedFiles })\n\n return resolvedFiles\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 { FabricConfig, FabricContext, FabricEvents, FabricOptions } from './Fabric.ts'\n\nimport type { Fabric } from './Fabric.ts'\n\ntype RootRenderFunction<TOptions extends FabricOptions> = (fabric: Fabric<TOptions>) => void | Promise<void>\n\nexport type DefineFabric<TOptions extends FabricOptions> = (config?: FabricConfig<TOptions>) => Fabric<TOptions>\n\nexport function defineFabric<TOptions extends FabricOptions>(instance?: RootRenderFunction<TOptions>): DefineFabric<TOptions> {\n function creator(config?: FabricConfig<TOptions>): Fabric<TOptions> {\n const events = new AsyncEventEmitter<FabricEvents>()\n const installedPlugins = new Set<Plugin<any>>()\n const installedParsers = new Set<Parser<any>>()\n const fileManager = new FileManager({ events })\n const context = {\n events,\n config,\n fileManager,\n installedPlugins,\n installedParsers,\n } as FabricContext<TOptions>\n\n const fabric = {\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 ${pluginOrParser.name} has already been applied to target fabric.`)\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)(fabric, ...args)\n Object.assign(fabric, extraApp)\n }\n }\n if (pluginOrParser.type === 'parser') {\n if (installedParsers.has(pluginOrParser)) {\n console.warn(`Parser ${pluginOrParser.name} has already been applied to target fabric.`)\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)(fabric, ...args)\n }\n\n return fabric\n },\n } as Fabric<TOptions>\n\n if (instance) {\n instance(fabric)\n }\n\n return fabric\n }\n\n return creator\n}\n","import { defineFabric } from './defineFabric.ts'\n\nexport const createFabric = defineFabric()\n"],"x_google_ignoreList":[1],"mappings":";;;;;;;;;;;;;AAAA,IAAa,QAAb,MAAsB;;mFACV,IAAI,KAAgB;;CAE9B,IAAI,KAAuB;;AACzB,oFAAO,KAAY,CAAC,IAAI,IAAI,+DAAI;;CAGlC,IAAI,KAAa,OAAgB;AAC/B,8DAAY,CAAC,IAAI,KAAK,MAAM;;CAG9B,OAAO,KAAmB;AACxB,8DAAY,CAAC,OAAO,IAAI;;CAG1B,QAAc;AACZ,8DAAY,CAAC,OAAO;;CAGtB,OAAiB;AACf,SAAO,CAAC,0DAAG,KAAY,CAAC,MAAM,CAAC;;CAGjC,SAAmB;AACjB,SAAO,CAAC,0DAAG,KAAY,CAAC,QAAQ,CAAC;;CAGnC,QAAc;;;;;AC3BhB,MAAM,KAAE,QAAG,OAAOA,OAAG;;;;;ACErB,IAAa,oBAAb,MAAoE;CAClE,YAAY,cAAc,KAAK;oEAGpB,IAAIC,0BAAkB;AAF/B,+DAAa,CAAC,gBAAgB,YAAY;;CAI5C,MAAM,KAAgD,WAAuB,GAAG,WAA+C;EAC7H,MAAM,oEAAY,KAAa,CAAC,UAAU,UAAU;AAEpD,MAAI,UAAU,WAAW,EACvB;AAGF,QAAM,QAAQ,IACZ,UAAU,IAAI,OAAO,aAAa;AAChC,OAAI;AACF,WAAO,MAAM,SAAS,GAAG,UAAU;YAC5B,KAAK;AACZ,YAAQ,MAAM,gCAAgC,UAAU,KAAK,IAAI;;IAEnE,CACH;;CAGH,GAA8C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Ae,CAAC;AAE7D,SAAO;;;;;;ACzFX,SAAgB,aAA6C,UAAiE;CAC5H,SAAS,QAAQ,QAAmD;EAClE,MAAM,SAAS,IAAI,mBAAiC;EACpD,MAAM,mCAAmB,IAAI,KAAkB;EAC/C,MAAM,mCAAmB,IAAI,KAAkB;EAC/C,MAAM,cAAc,IAAI,YAAY,EAAE,QAAQ,CAAC;EAS/C,MAAM,SAAS;GACb,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,MAAM,IAAI,gBAAgB,GAAG,SAAS;IACpC,MAAM,OAAO;AAEb,QAAI,eAAe,SAAS,UAAU;AACpC,SAAI,iBAAiB,IAAI,eAAe,CACtC,SAAQ,KAAK,UAAU,eAAe,KAAK,6CAA6C;SAExF,kBAAiB,IAAI,eAAe;AAGtC,SAAI,eAAe,UAAUC,EAAW,eAAe,OAAO,EAAE;MAC9D,MAAM,WAAW,eAAe;MAEhC,MAAM,WAAY,SAAiB,QAAQ,GAAG,KAAK;AACnD,aAAO,OAAO,QAAQ,SAAS;;;AAGnC,QAAI,eAAe,SAAS,SAC1B,KAAI,iBAAiB,IAAI,eAAe,CACtC,SAAQ,KAAK,UAAU,eAAe,KAAK,6CAA6C;QAExF,kBAAiB,IAAI,eAAe;AAIxC,QAAI,kBAAkBA,EAAW,eAAe,QAAQ,EAAE;KACxD,MAAM,YAAY,eAAe;AAEjC,WAAO,UAAkB,QAAQ,GAAG,KAAK;;AAG3C,WAAO;;GAEV;AAED,MAAI,SACF,UAAS,OAAO;AAGlB,SAAO;;AAGT,QAAO;;;;;AC3ET,MAAa,eAAe,cAAc"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["e","NodeEventEmitter","defaultParser","parser: Parser | undefined","resolvedFiles: Array<KubbFile.ResolvedFile>","createFile","trimExtName","isFunction"],"sources":["../../../node_modules/.pnpm/remeda@2.32.0/node_modules/remeda/dist/isFunction-BJjFuZR7.js","../src/utils/AsyncEventEmitter.ts","../src/FileProcessor.ts","../src/utils/Cache.ts","../src/FileManager.ts","../src/defineFabric.ts","../src/createFabric.ts"],"sourcesContent":["const e=e=>typeof e==`function`;export{e as isFunction};\n//# sourceMappingURL=isFunction-BJjFuZR7.js.map","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 onOnce<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArgs: TEvents[TEventName]) => void): void {\n const wrapper = (...args: TEvents[TEventName]) => {\n this.off(eventName, wrapper)\n handler(...args)\n }\n this.on(eventName, wrapper)\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 pLimit from 'p-limit'\nimport type { FabricEvents, FabricMode } from './Fabric.ts'\nimport type * as KubbFile from './KubbFile.ts'\nimport { defaultParser } from './parsers/defaultParser.ts'\nimport type { Parser } from './parsers/types.ts'\nimport { AsyncEventEmitter } from './utils/AsyncEventEmitter.ts'\n\nexport type ProcessFilesProps = {\n parsers?: Set<Parser>\n extension?: Record<KubbFile.Extname, KubbFile.Extname | ''>\n dryRun?: boolean\n /**\n * @default 'sequential'\n */\n mode?: FabricMode\n}\n\ntype GetParseOptions = {\n parsers?: Set<Parser>\n extension?: Record<KubbFile.Extname, KubbFile.Extname | ''>\n}\n\ntype Options = {\n events?: AsyncEventEmitter<FabricEvents>\n}\n\nexport class FileProcessor {\n #limit = pLimit(100)\n events: AsyncEventEmitter<FabricEvents>\n\n constructor({ events = new AsyncEventEmitter<FabricEvents>() }: Options = {}) {\n this.events = events\n\n return this\n }\n\n async parse(file: KubbFile.ResolvedFile, { parsers, extension }: GetParseOptions = {}): Promise<string> {\n const parseExtName = extension?.[file.extname] || undefined\n\n if (!parsers) {\n console.warn('No parsers provided, using default parser. If you want to use a specific parser, please provide it in the options.')\n\n return defaultParser.parse(file, { extname: parseExtName })\n }\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(\n files: Array<KubbFile.ResolvedFile>,\n { parsers, mode = 'sequential', dryRun, extension }: ProcessFilesProps = {},\n ): Promise<KubbFile.ResolvedFile[]> {\n await this.events.emit('process:start', { files })\n\n let processed = 0\n const total = files.length\n\n const processOne = async (resolvedFile: KubbFile.ResolvedFile, index: number) => {\n const percentage = (processed / total) * 100\n\n await this.events.emit('file:start', { file: resolvedFile, index, total })\n\n const source = dryRun ? undefined : await this.parse(resolvedFile, { extension, parsers })\n\n await this.events.emit('process:progress', {\n file: resolvedFile,\n source,\n processed,\n percentage,\n total,\n })\n\n processed++\n\n await this.events.emit('file:end', { file: resolvedFile, index, total })\n }\n\n if (mode === 'sequential') {\n async function* asyncFiles() {\n for (let index = 0; index < files.length; index++) {\n yield [files[index], index] as const\n }\n }\n\n for await (const [file, index] of asyncFiles()) {\n if (file) {\n await processOne(file, index)\n }\n }\n } else {\n const promises = files.map((resolvedFile, index) => this.#limit(() => processOne(resolvedFile, index)))\n await Promise.all(promises)\n }\n\n await this.events.emit('process:end', { files })\n\n return files\n }\n}\n","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 { orderBy } from 'natural-orderby'\nimport { createFile } from './createFile.ts'\nimport type { FabricEvents } from './Fabric.ts'\nimport { FileProcessor, type ProcessFilesProps } from './FileProcessor.ts'\nimport type * as KubbFile from './KubbFile.ts'\nimport { AsyncEventEmitter } from './utils/AsyncEventEmitter.ts'\nimport { Cache } from './utils/Cache.ts'\nimport { trimExtName } from './utils/trimExtName.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<FabricEvents>\n}\n\nexport class FileManager {\n #cache = new Cache<KubbFile.ResolvedFile>()\n events: AsyncEventEmitter<FabricEvents>\n processor: FileProcessor\n\n constructor({ events = new AsyncEventEmitter<FabricEvents>() }: Options = {}) {\n this.processor = new FileProcessor({ events })\n\n this.events = 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 await this.events.emit('file:add', { files: resolvedFiles })\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 //TODO add test and check if write of FileManager contains the newly added file\n async write(options: ProcessFilesProps): Promise<KubbFile.ResolvedFile[]> {\n await this.events.emit('write:start', { files: this.files })\n\n const resolvedFiles = await this.processor.run(this.files, options)\n\n this.clear()\n\n await this.events.emit('write:end', { files: resolvedFiles })\n\n return resolvedFiles\n }\n}\n","import { isFunction } from 'remeda'\nimport type { Fabric, FabricConfig, FabricContext, FabricEvents, FabricOptions } from './Fabric.ts'\nimport { FileManager } from './FileManager.ts'\nimport type { Parser } from './parsers/types.ts'\nimport type { Plugin } from './plugins/types.ts'\nimport { AsyncEventEmitter } from './utils/AsyncEventEmitter.ts'\n\ntype RootRenderFunction<TOptions extends FabricOptions> = (fabric: Fabric<TOptions>) => void | Promise<void>\n\nexport type DefineFabric<TOptions extends FabricOptions> = (config?: FabricConfig<TOptions>) => Fabric<TOptions>\n\nexport function defineFabric<TOptions extends FabricOptions>(instance?: RootRenderFunction<TOptions>): DefineFabric<TOptions> {\n function creator(config?: FabricConfig<TOptions>): Fabric<TOptions> {\n const events = new AsyncEventEmitter<FabricEvents>()\n const installedPlugins = new Set<Plugin<any>>()\n const installedParsers = new Set<Parser<any>>()\n const fileManager = new FileManager({ events })\n const context = {\n get files() {\n return fileManager.files\n },\n async addFile(...newFiles) {\n await fileManager.add(...newFiles)\n },\n config,\n fileManager,\n installedPlugins,\n installedParsers,\n on: events.on.bind(events),\n off: events.off.bind(events),\n onOnce: events.onOnce.bind(events),\n removeAll: events.removeAll.bind(events),\n emit: events.emit.bind(events),\n } as FabricContext<TOptions>\n\n const fabric = {\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 ${pluginOrParser.name} has already been applied to target fabric.`)\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)(context, ...args)\n Object.assign(fabric, extraApp)\n }\n }\n if (pluginOrParser.type === 'parser') {\n if (installedParsers.has(pluginOrParser)) {\n console.warn(`Parser ${pluginOrParser.name} has already been applied to target fabric.`)\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)(context, ...args)\n }\n\n return fabric\n },\n } as Fabric<TOptions>\n\n if (instance) {\n instance(fabric)\n }\n\n return fabric\n }\n\n return creator\n}\n","import { defineFabric } from './defineFabric.ts'\n\nexport const createFabric = defineFabric()\n"],"x_google_ignoreList":[0],"mappings":";;;;;;;;;;;;AAAA,MAAM,KAAE,QAAG,OAAOA,OAAG;;;;;ACErB,IAAa,oBAAb,MAAoE;CAClE,YAAY,cAAc,KAAK;oEAGpB,IAAIC,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Q,OAAO,OAAO,KAAK,OAAO;GAClC,WAAW,OAAO,UAAU,KAAK,OAAO;GACxC,MAAM,OAAO,KAAK,KAAK,OAAO;GAC/B;EAED,MAAM,SAAS;GACb;GACA,IAAI,QAAQ;AACV,WAAO,YAAY;;GAErB,MAAM,QAAQ,GAAG,UAAU;AACzB,UAAM,YAAY,IAAI,GAAG,SAAS;;GAEpC,MAAM,IAAI,gBAAgB,GAAG,SAAS;IACpC,MAAM,OAAO;AAEb,QAAI,eAAe,SAAS,UAAU;AACpC,SAAI,iBAAiB,IAAI,eAAe,CACtC,SAAQ,KAAK,UAAU,eAAe,KAAK,6CAA6C;SAExF,kBAAiB,IAAI,eAAe;AAGtC,SAAI,eAAe,UAAUC,EAAW,eAAe,OAAO,EAAE;MAC9D,MAAM,WAAW,eAAe;MAEhC,MAAM,WAAY,SAAiB,SAAS,GAAG,KAAK;AACpD,aAAO,OAAO,QAAQ,SAAS;;;AAGnC,QAAI,eAAe,SAAS,SAC1B,KAAI,iBAAiB,IAAI,eAAe,CACtC,SAAQ,KAAK,UAAU,eAAe,KAAK,6CAA6C;QAExF,kBAAiB,IAAI,eAAe;AAIxC,QAAI,kBAAkBA,EAAW,eAAe,QAAQ,EAAE;KACxD,MAAM,YAAY,eAAe;AAEjC,WAAO,UAAkB,SAAS,GAAG,KAAK;;AAG5C,WAAO;;GAEV;AAED,MAAI,SACF,UAAS,OAAO;AAGlB,SAAO;;AAGT,QAAO;;;;;ACnFT,MAAa,eAAe,cAAc"}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { a as FabricOptions,
|
|
2
|
-
import { n as defineFabric, t as DefineFabric } from "./defineFabric-
|
|
1
|
+
import { a as FabricOptions, c as FileManager, h as ResolvedFile, l as FileProcessor, p as File, t as Fabric } from "./Fabric-0mXLgmur.cjs";
|
|
2
|
+
import { n as defineFabric, t as DefineFabric } from "./defineFabric-Dkt2l0wC.cjs";
|
|
3
3
|
|
|
4
4
|
//#region src/createFabric.d.ts
|
|
5
5
|
declare const createFabric: DefineFabric<FabricOptions>;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { a as FabricOptions,
|
|
2
|
-
import { n as defineFabric, t as DefineFabric } from "./defineFabric-
|
|
1
|
+
import { a as FabricOptions, c as FileManager, h as ResolvedFile, l as FileProcessor, p as File, t as Fabric } from "./Fabric-C-AqOkTA.js";
|
|
2
|
+
import { n as defineFabric, t as DefineFabric } from "./defineFabric-D_m6CB1s.js";
|
|
3
3
|
|
|
4
4
|
//#region src/createFabric.d.ts
|
|
5
5
|
declare const createFabric: DefineFabric<FabricOptions>;
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as
|
|
1
|
+
import { a as createFile, i as _classPrivateFieldInitSpec, n as _classPrivateFieldGet2, t as _defineProperty } from "./defineProperty-BZknW4oy.js";
|
|
2
2
|
import { t as trimExtName } from "./trimExtName-CeOVQVbu.js";
|
|
3
3
|
import "./createParser-17uGjfu3.js";
|
|
4
4
|
import { t as defaultParser } from "./defaultParser--HzU9LPa.js";
|
|
@@ -6,35 +6,6 @@ import { orderBy } from "natural-orderby";
|
|
|
6
6
|
import pLimit from "p-limit";
|
|
7
7
|
import { EventEmitter } from "node:events";
|
|
8
8
|
|
|
9
|
-
//#region src/utils/Cache.ts
|
|
10
|
-
var _buffer = /* @__PURE__ */ new WeakMap();
|
|
11
|
-
var Cache = class {
|
|
12
|
-
constructor() {
|
|
13
|
-
_classPrivateFieldInitSpec(this, _buffer, /* @__PURE__ */ new Map());
|
|
14
|
-
}
|
|
15
|
-
get(key) {
|
|
16
|
-
var _this$buffer$get;
|
|
17
|
-
return (_this$buffer$get = _classPrivateFieldGet2(_buffer, this).get(key)) !== null && _this$buffer$get !== void 0 ? _this$buffer$get : null;
|
|
18
|
-
}
|
|
19
|
-
set(key, value) {
|
|
20
|
-
_classPrivateFieldGet2(_buffer, this).set(key, value);
|
|
21
|
-
}
|
|
22
|
-
delete(key) {
|
|
23
|
-
_classPrivateFieldGet2(_buffer, this).delete(key);
|
|
24
|
-
}
|
|
25
|
-
clear() {
|
|
26
|
-
_classPrivateFieldGet2(_buffer, this).clear();
|
|
27
|
-
}
|
|
28
|
-
keys() {
|
|
29
|
-
return [..._classPrivateFieldGet2(_buffer, this).keys()];
|
|
30
|
-
}
|
|
31
|
-
values() {
|
|
32
|
-
return [..._classPrivateFieldGet2(_buffer, this).values()];
|
|
33
|
-
}
|
|
34
|
-
flush() {}
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
//#endregion
|
|
38
9
|
//#region ../../node_modules/.pnpm/remeda@2.32.0/node_modules/remeda/dist/isFunction-BJjFuZR7.js
|
|
39
10
|
const e = (e$1) => typeof e$1 == `function`;
|
|
40
11
|
|
|
@@ -146,6 +117,35 @@ var FileProcessor = class {
|
|
|
146
117
|
}
|
|
147
118
|
};
|
|
148
119
|
|
|
120
|
+
//#endregion
|
|
121
|
+
//#region src/utils/Cache.ts
|
|
122
|
+
var _buffer = /* @__PURE__ */ new WeakMap();
|
|
123
|
+
var Cache = class {
|
|
124
|
+
constructor() {
|
|
125
|
+
_classPrivateFieldInitSpec(this, _buffer, /* @__PURE__ */ new Map());
|
|
126
|
+
}
|
|
127
|
+
get(key) {
|
|
128
|
+
var _this$buffer$get;
|
|
129
|
+
return (_this$buffer$get = _classPrivateFieldGet2(_buffer, this).get(key)) !== null && _this$buffer$get !== void 0 ? _this$buffer$get : null;
|
|
130
|
+
}
|
|
131
|
+
set(key, value) {
|
|
132
|
+
_classPrivateFieldGet2(_buffer, this).set(key, value);
|
|
133
|
+
}
|
|
134
|
+
delete(key) {
|
|
135
|
+
_classPrivateFieldGet2(_buffer, this).delete(key);
|
|
136
|
+
}
|
|
137
|
+
clear() {
|
|
138
|
+
_classPrivateFieldGet2(_buffer, this).clear();
|
|
139
|
+
}
|
|
140
|
+
keys() {
|
|
141
|
+
return [..._classPrivateFieldGet2(_buffer, this).keys()];
|
|
142
|
+
}
|
|
143
|
+
values() {
|
|
144
|
+
return [..._classPrivateFieldGet2(_buffer, this).values()];
|
|
145
|
+
}
|
|
146
|
+
flush() {}
|
|
147
|
+
};
|
|
148
|
+
|
|
149
149
|
//#endregion
|
|
150
150
|
//#region src/FileManager.ts
|
|
151
151
|
function mergeFile(a, b) {
|
|
@@ -216,14 +216,25 @@ function defineFabric(instance) {
|
|
|
216
216
|
const installedPlugins = /* @__PURE__ */ new Set();
|
|
217
217
|
const installedParsers = /* @__PURE__ */ new Set();
|
|
218
218
|
const fileManager = new FileManager({ events });
|
|
219
|
-
const
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
installedParsers
|
|
219
|
+
const context = {
|
|
220
|
+
get files() {
|
|
221
|
+
return fileManager.files;
|
|
222
|
+
},
|
|
223
|
+
async addFile(...newFiles) {
|
|
224
|
+
await fileManager.add(...newFiles);
|
|
226
225
|
},
|
|
226
|
+
config,
|
|
227
|
+
fileManager,
|
|
228
|
+
installedPlugins,
|
|
229
|
+
installedParsers,
|
|
230
|
+
on: events.on.bind(events),
|
|
231
|
+
off: events.off.bind(events),
|
|
232
|
+
onOnce: events.onOnce.bind(events),
|
|
233
|
+
removeAll: events.removeAll.bind(events),
|
|
234
|
+
emit: events.emit.bind(events)
|
|
235
|
+
};
|
|
236
|
+
const fabric = {
|
|
237
|
+
context,
|
|
227
238
|
get files() {
|
|
228
239
|
return fileManager.files;
|
|
229
240
|
},
|
|
@@ -237,7 +248,7 @@ function defineFabric(instance) {
|
|
|
237
248
|
else installedPlugins.add(pluginOrParser);
|
|
238
249
|
if (pluginOrParser.inject && e(pluginOrParser.inject)) {
|
|
239
250
|
const injecter = pluginOrParser.inject;
|
|
240
|
-
const extraApp = injecter(
|
|
251
|
+
const extraApp = injecter(context, ...args);
|
|
241
252
|
Object.assign(fabric, extraApp);
|
|
242
253
|
}
|
|
243
254
|
}
|
|
@@ -245,7 +256,7 @@ function defineFabric(instance) {
|
|
|
245
256
|
else installedParsers.add(pluginOrParser);
|
|
246
257
|
if (pluginOrParser && e(pluginOrParser.install)) {
|
|
247
258
|
const installer = pluginOrParser.install;
|
|
248
|
-
await installer(
|
|
259
|
+
await installer(context, ...args);
|
|
249
260
|
}
|
|
250
261
|
return fabric;
|
|
251
262
|
}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["e","NodeEventEmitter","parser: Parser | undefined","resolvedFiles: Array<KubbFile.ResolvedFile>","isFunction"],"sources":["../src/utils/Cache.ts","../../../node_modules/.pnpm/remeda@2.32.0/node_modules/remeda/dist/isFunction-BJjFuZR7.js","../src/utils/AsyncEventEmitter.ts","../src/FileProcessor.ts","../src/FileManager.ts","../src/defineFabric.ts","../src/createFabric.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","const e=e=>typeof e==`function`;export{e as isFunction};\n//# sourceMappingURL=isFunction-BJjFuZR7.js.map","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 onOnce<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArgs: TEvents[TEventName]) => void): void {\n const wrapper = (...args: TEvents[TEventName]) => {\n this.off(eventName, wrapper)\n handler(...args)\n }\n this.on(eventName, wrapper)\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 { FabricEvents, FabricMode } from './Fabric.ts'\n\nexport type ProcessFilesProps = {\n parsers?: Set<Parser>\n extension?: Record<KubbFile.Extname, KubbFile.Extname | ''>\n dryRun?: boolean\n /**\n * @default 'sequential'\n */\n mode?: FabricMode\n}\n\ntype GetParseOptions = {\n parsers?: Set<Parser>\n extension?: Record<KubbFile.Extname, KubbFile.Extname | ''>\n}\n\ntype Options = {\n events?: AsyncEventEmitter<FabricEvents>\n}\n\nexport class FileProcessor {\n #limit = pLimit(100)\n events: AsyncEventEmitter<FabricEvents>\n\n constructor({ events = new AsyncEventEmitter<FabricEvents>() }: Options = {}) {\n this.events = events\n\n return this\n }\n\n async parse(file: KubbFile.ResolvedFile, { parsers, extension }: GetParseOptions = {}): Promise<string> {\n const parseExtName = extension?.[file.extname] || undefined\n\n if (!parsers) {\n console.warn('No parsers provided, using default parser. If you want to use a specific parser, please provide it in the options.')\n\n return defaultParser.parse(file, { extname: parseExtName })\n }\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(\n files: Array<KubbFile.ResolvedFile>,\n { parsers, mode = 'sequential', dryRun, extension }: ProcessFilesProps = {},\n ): Promise<KubbFile.ResolvedFile[]> {\n await this.events.emit('process:start', { files })\n\n let processed = 0\n const total = files.length\n\n const processOne = async (resolvedFile: KubbFile.ResolvedFile, index: number) => {\n const percentage = (processed / total) * 100\n\n await this.events.emit('file:start', { file: resolvedFile, index, total })\n\n const source = dryRun ? undefined : await this.parse(resolvedFile, { extension, parsers })\n\n await this.events.emit('process:progress', {\n file: resolvedFile,\n source,\n processed,\n percentage,\n total,\n })\n\n processed++\n\n await this.events.emit('file:end', { file: resolvedFile, index, total })\n }\n\n if (mode === 'sequential') {\n async function* asyncFiles() {\n for (let index = 0; index < files.length; index++) {\n yield [files[index], index] as const\n }\n }\n\n for await (const [file, index] of asyncFiles()) {\n if (file) {\n await processOne(file, index)\n }\n }\n } else {\n const promises = files.map((resolvedFile, index) => this.#limit(() => processOne(resolvedFile, index)))\n await Promise.all(promises)\n }\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 { FabricEvents } from './Fabric.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<FabricEvents>\n}\n\nexport class FileManager {\n #cache = new Cache<KubbFile.ResolvedFile>()\n events: AsyncEventEmitter<FabricEvents>\n processor: FileProcessor\n\n constructor({ events = new AsyncEventEmitter<FabricEvents>() }: Options = {}) {\n this.processor = new FileProcessor({ events })\n\n this.events = 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 await this.events.emit('file:add', { files: resolvedFiles })\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 //TODO add test and check if write of FileManager contains the newly added file\n async write(options: ProcessFilesProps): Promise<KubbFile.ResolvedFile[]> {\n await this.events.emit('write:start', { files: this.files })\n\n const resolvedFiles = await this.processor.run(this.files, options)\n\n this.clear()\n\n await this.events.emit('write:end', { files: resolvedFiles })\n\n return resolvedFiles\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 { FabricConfig, FabricContext, FabricEvents, FabricOptions } from './Fabric.ts'\n\nimport type { Fabric } from './Fabric.ts'\n\ntype RootRenderFunction<TOptions extends FabricOptions> = (fabric: Fabric<TOptions>) => void | Promise<void>\n\nexport type DefineFabric<TOptions extends FabricOptions> = (config?: FabricConfig<TOptions>) => Fabric<TOptions>\n\nexport function defineFabric<TOptions extends FabricOptions>(instance?: RootRenderFunction<TOptions>): DefineFabric<TOptions> {\n function creator(config?: FabricConfig<TOptions>): Fabric<TOptions> {\n const events = new AsyncEventEmitter<FabricEvents>()\n const installedPlugins = new Set<Plugin<any>>()\n const installedParsers = new Set<Parser<any>>()\n const fileManager = new FileManager({ events })\n const context = {\n events,\n config,\n fileManager,\n installedPlugins,\n installedParsers,\n } as FabricContext<TOptions>\n\n const fabric = {\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 ${pluginOrParser.name} has already been applied to target fabric.`)\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)(fabric, ...args)\n Object.assign(fabric, extraApp)\n }\n }\n if (pluginOrParser.type === 'parser') {\n if (installedParsers.has(pluginOrParser)) {\n console.warn(`Parser ${pluginOrParser.name} has already been applied to target fabric.`)\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)(fabric, ...args)\n }\n\n return fabric\n },\n } as Fabric<TOptions>\n\n if (instance) {\n instance(fabric)\n }\n\n return fabric\n }\n\n return creator\n}\n","import { defineFabric } from './defineFabric.ts'\n\nexport const createFabric = defineFabric()\n"],"x_google_ignoreList":[1],"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;;;;;AC3BhB,MAAM,KAAE,QAAG,OAAOA,OAAG;;;;;ACErB,IAAa,oBAAb,MAAoE;CAClE,YAAY,cAAc,KAAK;6CAGpB,IAAIC,cAAkB;AAF/B,wCAAa,CAAC,gBAAgB,YAAY;;CAI5C,MAAM,KAAgD,WAAuB,GAAG,WAA+C;EAC7H,MAAM,6CAAY,KAAa,CAAC,UAAU,UAAU;AAEpD,MAAI,UAAU,WAAW,EACvB;AAGF,QAAM,QAAQ,IACZ,UAAU,IAAI,OAAO,aAAa;AAChC,OAAI;AACF,WAAO,MAAM,SAAS,GAAG,UAAU;YAC5B,KAAK;AACZ,YAAQ,MAAM,gCAAgC,UAAU,KAAK,IAAI;;IAEnE,CACH;;CAGH,GAA8C,WAAuB,SAA2D;AAC9H,wCAAa,CAAC,GAAG,WAAW,QAAe;;CAG7C,OAAkD,WAAuB,SAA4D;EACnI,MAAM,WAAW,GAAG,SAA8B;AAChD,QAAK,IAAI,WAAW,QAAQ;AAC5B,WAAQ,GAAG,KAAK;;AAElB,OAAK,GAAG,WAAW,QAAQ;;CAG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,YAAY,EAAE,QAAQ,CAAC;EAS/C,MAAM,SAAS;GACb,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,MAAM,IAAI,gBAAgB,GAAG,SAAS;IACpC,MAAM,OAAO;AAEb,QAAI,eAAe,SAAS,UAAU;AACpC,SAAI,iBAAiB,IAAI,eAAe,CACtC,SAAQ,KAAK,UAAU,eAAe,KAAK,6CAA6C;SAExF,kBAAiB,IAAI,eAAe;AAGtC,SAAI,eAAe,UAAUC,EAAW,eAAe,OAAO,EAAE;MAC9D,MAAM,WAAW,eAAe;MAEhC,MAAM,WAAY,SAAiB,QAAQ,GAAG,KAAK;AACnD,aAAO,OAAO,QAAQ,SAAS;;;AAGnC,QAAI,eAAe,SAAS,SAC1B,KAAI,iBAAiB,IAAI,eAAe,CACtC,SAAQ,KAAK,UAAU,eAAe,KAAK,6CAA6C;QAExF,kBAAiB,IAAI,eAAe;AAIxC,QAAI,kBAAkBA,EAAW,eAAe,QAAQ,EAAE;KACxD,MAAM,YAAY,eAAe;AAEjC,WAAO,UAAkB,QAAQ,GAAG,KAAK;;AAG3C,WAAO;;GAEV;AAED,MAAI,SACF,UAAS,OAAO;AAGlB,SAAO;;AAGT,QAAO;;;;;AC3ET,MAAa,eAAe,cAAc"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["e","NodeEventEmitter","parser: Parser | undefined","resolvedFiles: Array<KubbFile.ResolvedFile>","isFunction"],"sources":["../../../node_modules/.pnpm/remeda@2.32.0/node_modules/remeda/dist/isFunction-BJjFuZR7.js","../src/utils/AsyncEventEmitter.ts","../src/FileProcessor.ts","../src/utils/Cache.ts","../src/FileManager.ts","../src/defineFabric.ts","../src/createFabric.ts"],"sourcesContent":["const e=e=>typeof e==`function`;export{e as isFunction};\n//# sourceMappingURL=isFunction-BJjFuZR7.js.map","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 onOnce<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArgs: TEvents[TEventName]) => void): void {\n const wrapper = (...args: TEvents[TEventName]) => {\n this.off(eventName, wrapper)\n handler(...args)\n }\n this.on(eventName, wrapper)\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 pLimit from 'p-limit'\nimport type { FabricEvents, FabricMode } from './Fabric.ts'\nimport type * as KubbFile from './KubbFile.ts'\nimport { defaultParser } from './parsers/defaultParser.ts'\nimport type { Parser } from './parsers/types.ts'\nimport { AsyncEventEmitter } from './utils/AsyncEventEmitter.ts'\n\nexport type ProcessFilesProps = {\n parsers?: Set<Parser>\n extension?: Record<KubbFile.Extname, KubbFile.Extname | ''>\n dryRun?: boolean\n /**\n * @default 'sequential'\n */\n mode?: FabricMode\n}\n\ntype GetParseOptions = {\n parsers?: Set<Parser>\n extension?: Record<KubbFile.Extname, KubbFile.Extname | ''>\n}\n\ntype Options = {\n events?: AsyncEventEmitter<FabricEvents>\n}\n\nexport class FileProcessor {\n #limit = pLimit(100)\n events: AsyncEventEmitter<FabricEvents>\n\n constructor({ events = new AsyncEventEmitter<FabricEvents>() }: Options = {}) {\n this.events = events\n\n return this\n }\n\n async parse(file: KubbFile.ResolvedFile, { parsers, extension }: GetParseOptions = {}): Promise<string> {\n const parseExtName = extension?.[file.extname] || undefined\n\n if (!parsers) {\n console.warn('No parsers provided, using default parser. If you want to use a specific parser, please provide it in the options.')\n\n return defaultParser.parse(file, { extname: parseExtName })\n }\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(\n files: Array<KubbFile.ResolvedFile>,\n { parsers, mode = 'sequential', dryRun, extension }: ProcessFilesProps = {},\n ): Promise<KubbFile.ResolvedFile[]> {\n await this.events.emit('process:start', { files })\n\n let processed = 0\n const total = files.length\n\n const processOne = async (resolvedFile: KubbFile.ResolvedFile, index: number) => {\n const percentage = (processed / total) * 100\n\n await this.events.emit('file:start', { file: resolvedFile, index, total })\n\n const source = dryRun ? undefined : await this.parse(resolvedFile, { extension, parsers })\n\n await this.events.emit('process:progress', {\n file: resolvedFile,\n source,\n processed,\n percentage,\n total,\n })\n\n processed++\n\n await this.events.emit('file:end', { file: resolvedFile, index, total })\n }\n\n if (mode === 'sequential') {\n async function* asyncFiles() {\n for (let index = 0; index < files.length; index++) {\n yield [files[index], index] as const\n }\n }\n\n for await (const [file, index] of asyncFiles()) {\n if (file) {\n await processOne(file, index)\n }\n }\n } else {\n const promises = files.map((resolvedFile, index) => this.#limit(() => processOne(resolvedFile, index)))\n await Promise.all(promises)\n }\n\n await this.events.emit('process:end', { files })\n\n return files\n }\n}\n","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 { orderBy } from 'natural-orderby'\nimport { createFile } from './createFile.ts'\nimport type { FabricEvents } from './Fabric.ts'\nimport { FileProcessor, type ProcessFilesProps } from './FileProcessor.ts'\nimport type * as KubbFile from './KubbFile.ts'\nimport { AsyncEventEmitter } from './utils/AsyncEventEmitter.ts'\nimport { Cache } from './utils/Cache.ts'\nimport { trimExtName } from './utils/trimExtName.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<FabricEvents>\n}\n\nexport class FileManager {\n #cache = new Cache<KubbFile.ResolvedFile>()\n events: AsyncEventEmitter<FabricEvents>\n processor: FileProcessor\n\n constructor({ events = new AsyncEventEmitter<FabricEvents>() }: Options = {}) {\n this.processor = new FileProcessor({ events })\n\n this.events = 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 await this.events.emit('file:add', { files: resolvedFiles })\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 //TODO add test and check if write of FileManager contains the newly added file\n async write(options: ProcessFilesProps): Promise<KubbFile.ResolvedFile[]> {\n await this.events.emit('write:start', { files: this.files })\n\n const resolvedFiles = await this.processor.run(this.files, options)\n\n this.clear()\n\n await this.events.emit('write:end', { files: resolvedFiles })\n\n return resolvedFiles\n }\n}\n","import { isFunction } from 'remeda'\nimport type { Fabric, FabricConfig, FabricContext, FabricEvents, FabricOptions } from './Fabric.ts'\nimport { FileManager } from './FileManager.ts'\nimport type { Parser } from './parsers/types.ts'\nimport type { Plugin } from './plugins/types.ts'\nimport { AsyncEventEmitter } from './utils/AsyncEventEmitter.ts'\n\ntype RootRenderFunction<TOptions extends FabricOptions> = (fabric: Fabric<TOptions>) => void | Promise<void>\n\nexport type DefineFabric<TOptions extends FabricOptions> = (config?: FabricConfig<TOptions>) => Fabric<TOptions>\n\nexport function defineFabric<TOptions extends FabricOptions>(instance?: RootRenderFunction<TOptions>): DefineFabric<TOptions> {\n function creator(config?: FabricConfig<TOptions>): Fabric<TOptions> {\n const events = new AsyncEventEmitter<FabricEvents>()\n const installedPlugins = new Set<Plugin<any>>()\n const installedParsers = new Set<Parser<any>>()\n const fileManager = new FileManager({ events })\n const context = {\n get files() {\n return fileManager.files\n },\n async addFile(...newFiles) {\n await fileManager.add(...newFiles)\n },\n config,\n fileManager,\n installedPlugins,\n installedParsers,\n on: events.on.bind(events),\n off: events.off.bind(events),\n onOnce: events.onOnce.bind(events),\n removeAll: events.removeAll.bind(events),\n emit: events.emit.bind(events),\n } as FabricContext<TOptions>\n\n const fabric = {\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 ${pluginOrParser.name} has already been applied to target fabric.`)\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)(context, ...args)\n Object.assign(fabric, extraApp)\n }\n }\n if (pluginOrParser.type === 'parser') {\n if (installedParsers.has(pluginOrParser)) {\n console.warn(`Parser ${pluginOrParser.name} has already been applied to target fabric.`)\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)(context, ...args)\n }\n\n return fabric\n },\n } as Fabric<TOptions>\n\n if (instance) {\n instance(fabric)\n }\n\n return fabric\n }\n\n return creator\n}\n","import { defineFabric } from './defineFabric.ts'\n\nexport const createFabric = defineFabric()\n"],"x_google_ignoreList":[0],"mappings":";;;;;;;;;AAAA,MAAM,KAAE,QAAG,OAAOA,OAAG;;;;;ACErB,IAAa,oBAAb,MAAoE;CAClE,YAAY,cAAc,KAAK;6CAGpB,IAAIC,cAAkB;AAF/B,wCAAa,CAAC,gBAAgB,YAAY;;CAI5C,MAAM,KAAgD,WAAuB,GAAG,WAA+C;EAC7H,MAAM,6CAAY,KAAa,CAAC,UAAU,UAAU;AAEpD,MAAI,UAAU,WAAW,EACvB;AAGF,QAAM,QAAQ,IACZ,UAAU,IAAI,OAAO,aAAa;AAChC,OAAI;AACF,WAAO,MAA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pC,MAAM,IAAI,gBAAgB,GAAG,SAAS;IACpC,MAAM,OAAO;AAEb,QAAI,eAAe,SAAS,UAAU;AACpC,SAAI,iBAAiB,IAAI,eAAe,CACtC,SAAQ,KAAK,UAAU,eAAe,KAAK,6CAA6C;SAExF,kBAAiB,IAAI,eAAe;AAGtC,SAAI,eAAe,UAAUC,EAAW,eAAe,OAAO,EAAE;MAC9D,MAAM,WAAW,eAAe;MAEhC,MAAM,WAAY,SAAiB,SAAS,GAAG,KAAK;AACpD,aAAO,OAAO,QAAQ,SAAS;;;AAGnC,QAAI,eAAe,SAAS,SAC1B,KAAI,iBAAiB,IAAI,eAAe,CACtC,SAAQ,KAAK,UAAU,eAAe,KAAK,6CAA6C;QAExF,kBAAiB,IAAI,eAAe;AAIxC,QAAI,kBAAkBA,EAAW,eAAe,QAAQ,EAAE;KACxD,MAAM,YAAY,eAAe;AAEjC,WAAO,UAAkB,SAAS,GAAG,KAAK;;AAG5C,WAAO;;GAEV;AAED,MAAI,SACF,UAAS,OAAO;AAGlB,SAAO;;AAGT,QAAO;;;;;ACnFT,MAAa,eAAe,cAAc"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import "../Fabric-
|
|
2
|
-
import { i as typescriptParser, n as createImport, r as print, t as createExport } from "../typescriptParser-
|
|
1
|
+
import "../Fabric-0mXLgmur.cjs";
|
|
2
|
+
import { i as typescriptParser, n as createImport, r as print, t as createExport } from "../typescriptParser-B4-y6QxR.cjs";
|
|
3
3
|
export { createExport, createImport, print, typescriptParser };
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import "../Fabric-
|
|
2
|
-
import { i as typescriptParser, n as createImport, r as print, t as createExport } from "../typescriptParser-
|
|
1
|
+
import "../Fabric-C-AqOkTA.js";
|
|
2
|
+
import { i as typescriptParser, n as createImport, r as print, t as createExport } from "../typescriptParser-By3ckLtc.js";
|
|
3
3
|
export { createExport, createImport, print, typescriptParser };
|
package/dist/parsers.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parsers.cjs","names":["createParser","typescriptParser"],"sources":["../src/parsers/tsxParser.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"parsers.cjs","names":["createParser","typescriptParser"],"sources":["../src/parsers/tsxParser.ts"],"sourcesContent":["import { createParser } from './createParser.ts'\nimport { typescriptParser } from './typescriptParser.ts'\n\nexport const tsxParser = createParser({\n name: 'tsx',\n extNames: ['.tsx', '.jsx'],\n install() {},\n async parse(file, options = { extname: '.tsx' }) {\n return typescriptParser.parse(file, options)\n },\n})\n"],"mappings":";;;;;;;AAGA,MAAa,YAAYA,kCAAa;CACpC,MAAM;CACN,UAAU,CAAC,QAAQ,OAAO;CAC1B,UAAU;CACV,MAAM,MAAM,MAAM,UAAU,EAAE,SAAS,QAAQ,EAAE;AAC/C,SAAOC,0CAAiB,MAAM,MAAM,QAAQ;;CAE/C,CAAC"}
|
package/dist/parsers.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { i as typescriptParser } from "./typescriptParser-
|
|
1
|
+
import { d as UserParser, u as Parser } from "./Fabric-0mXLgmur.cjs";
|
|
2
|
+
import { i as typescriptParser } from "./typescriptParser-B4-y6QxR.cjs";
|
|
3
3
|
|
|
4
4
|
//#region src/parsers/createParser.d.ts
|
|
5
5
|
declare function createParser<TOptions = unknown, TMeta extends object = any>(parser: UserParser<TOptions, TMeta>): Parser<TOptions, TMeta>;
|
package/dist/parsers.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { i as typescriptParser } from "./typescriptParser-
|
|
1
|
+
import { d as UserParser, u as Parser } from "./Fabric-C-AqOkTA.js";
|
|
2
|
+
import { i as typescriptParser } from "./typescriptParser-By3ckLtc.js";
|
|
3
3
|
|
|
4
4
|
//#region src/parsers/createParser.d.ts
|
|
5
5
|
declare function createParser<TOptions = unknown, TMeta extends object = any>(parser: UserParser<TOptions, TMeta>): Parser<TOptions, TMeta>;
|
package/dist/parsers.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parsers.js","names":[],"sources":["../src/parsers/tsxParser.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"parsers.js","names":[],"sources":["../src/parsers/tsxParser.ts"],"sourcesContent":["import { createParser } from './createParser.ts'\nimport { typescriptParser } from './typescriptParser.ts'\n\nexport const tsxParser = createParser({\n name: 'tsx',\n extNames: ['.tsx', '.jsx'],\n install() {},\n async parse(file, options = { extname: '.tsx' }) {\n return typescriptParser.parse(file, options)\n },\n})\n"],"mappings":";;;;;;;AAGA,MAAa,YAAY,aAAa;CACpC,MAAM;CACN,UAAU,CAAC,QAAQ,OAAO;CAC1B,UAAU;CACV,MAAM,MAAM,MAAM,UAAU,EAAE,SAAS,QAAQ,EAAE;AAC/C,SAAO,iBAAiB,MAAM,MAAM,QAAQ;;CAE/C,CAAC"}
|