@kubb/fabric-core 0.2.16 → 0.2.18
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/{Fabric-CBrTERuf.d.cts → Fabric-BezqNTQ9.d.cts} +12 -7
- package/dist/{Fabric-AmREkq58.d.ts → Fabric-CVe8cc8b.d.ts} +12 -7
- package/dist/{defineProperty-Dlhh3lSJ.cjs → defineProperty-DZi5DvrW.cjs} +13 -1
- package/dist/{defineProperty-Dlhh3lSJ.cjs.map → defineProperty-DZi5DvrW.cjs.map} +1 -1
- package/dist/{defineProperty-_FBdEen_.js → defineProperty-DcP1vZ2K.js} +2 -2
- package/dist/{defineProperty-_FBdEen_.js.map → defineProperty-DcP1vZ2K.js.map} +1 -1
- package/dist/index.cjs +28 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +28 -5
- 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 -5
- package/dist/plugins.cjs.map +1 -1
- package/dist/plugins.d.cts +7 -1
- package/dist/plugins.d.ts +7 -1
- package/dist/plugins.js +3 -5
- package/dist/plugins.js.map +1 -1
- package/dist/types.d.cts +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/{typescriptParser-DaOfAlmM.d.ts → typescriptParser-B5SxjtvV.d.ts} +2 -2
- package/dist/{typescriptParser-C3B3dzh_.d.cts → typescriptParser-PfAO0SSm.d.cts} +2 -2
- package/package.json +1 -1
- package/src/Fabric.ts +7 -8
- package/src/FileManager.ts +16 -1
- package/src/defineFabric.ts +1 -1
- package/src/plugins/barrelPlugin.ts +7 -1
- package/src/plugins/fsPlugin.ts +1 -1
- package/src/utils/AsyncEventEmitter.ts +14 -2
package/src/FileManager.ts
CHANGED
|
@@ -33,6 +33,18 @@ export class FileManager {
|
|
|
33
33
|
return this
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
+
async #resolvePath(file: KubbFile.File): Promise<KubbFile.File> {
|
|
37
|
+
await this.events.emit('file:resolve:path', { file })
|
|
38
|
+
|
|
39
|
+
return file
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
async #resolveName(file: KubbFile.File): Promise<KubbFile.File> {
|
|
43
|
+
await this.events.emit('file:resolve:name', { file })
|
|
44
|
+
|
|
45
|
+
return file
|
|
46
|
+
}
|
|
47
|
+
|
|
36
48
|
async add(...files: Array<KubbFile.File>) {
|
|
37
49
|
const resolvedFiles: Array<KubbFile.ResolvedFile> = []
|
|
38
50
|
|
|
@@ -47,9 +59,12 @@ export class FileManager {
|
|
|
47
59
|
}
|
|
48
60
|
})
|
|
49
61
|
|
|
50
|
-
for (
|
|
62
|
+
for (let file of mergedFiles.values()) {
|
|
51
63
|
const existing = this.#cache.get(file.path)
|
|
52
64
|
|
|
65
|
+
file = await this.#resolveName(file)
|
|
66
|
+
file = await this.#resolvePath(file)
|
|
67
|
+
|
|
53
68
|
const merged = existing ? mergeFile(existing, file) : file
|
|
54
69
|
const resolvedFile = createFile(merged)
|
|
55
70
|
|
package/src/defineFabric.ts
CHANGED
|
@@ -27,7 +27,7 @@ export type CreateFabric<T extends FabricOptions> = (config?: FabricConfig<T>) =
|
|
|
27
27
|
* })
|
|
28
28
|
*/
|
|
29
29
|
export function defineFabric<T extends FabricOptions>(init?: FabricInitializer<T>): CreateFabric<T> {
|
|
30
|
-
function create(config
|
|
30
|
+
function create(config: FabricConfig<T> = { mode: 'sequential' } as FabricConfig<T>): Fabric<T> {
|
|
31
31
|
const events = new AsyncEventEmitter<FabricEvents>()
|
|
32
32
|
const installedPlugins = new Set<Plugin<any>>()
|
|
33
33
|
const installedParsers = new Set<Parser<any>>()
|
|
@@ -21,12 +21,18 @@ type WriteEntryOptions = {
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
type ExtendOptions = {
|
|
24
|
+
/**
|
|
25
|
+
* `fabric.writeEntry` should be called before `fabric.write`
|
|
26
|
+
*/
|
|
24
27
|
writeEntry(options: WriteEntryOptions): Promise<void>
|
|
25
28
|
}
|
|
26
29
|
|
|
27
30
|
declare global {
|
|
28
31
|
namespace Kubb {
|
|
29
32
|
interface Fabric {
|
|
33
|
+
/**
|
|
34
|
+
* `fabric.writeEntry` should be called before `fabric.write`
|
|
35
|
+
*/
|
|
30
36
|
writeEntry(options: WriteEntryOptions): Promise<void>
|
|
31
37
|
}
|
|
32
38
|
}
|
|
@@ -188,7 +194,7 @@ export const barrelPlugin = createPlugin<Options, ExtendOptions>({
|
|
|
188
194
|
await ctx.addFile(entryFile)
|
|
189
195
|
|
|
190
196
|
await ctx.fileManager.write({
|
|
191
|
-
mode: ctx.config
|
|
197
|
+
mode: ctx.config.mode,
|
|
192
198
|
dryRun: options.dryRun,
|
|
193
199
|
parsers: ctx.installedParsers,
|
|
194
200
|
})
|
package/src/plugins/fsPlugin.ts
CHANGED
|
@@ -107,7 +107,7 @@ export const fsPlugin = createPlugin<Options, ExtendOptions>({
|
|
|
107
107
|
},
|
|
108
108
|
) {
|
|
109
109
|
await ctx.fileManager.write({
|
|
110
|
-
mode: ctx.config
|
|
110
|
+
mode: ctx.config.mode,
|
|
111
111
|
extension: options.extension,
|
|
112
112
|
dryRun,
|
|
113
113
|
parsers: ctx.installedParsers,
|
|
@@ -22,13 +22,16 @@ export class AsyncEventEmitter<TEvents extends Record<string, any>> {
|
|
|
22
22
|
return
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
+
const errors: Error[] = []
|
|
26
|
+
|
|
25
27
|
if (this.#mode === 'sequential') {
|
|
26
28
|
// Run listeners one by one, in order
|
|
27
29
|
for (const listener of listeners) {
|
|
28
30
|
try {
|
|
29
31
|
await listener(...eventArgs)
|
|
30
32
|
} catch (err) {
|
|
31
|
-
|
|
33
|
+
const error = err instanceof Error ? err : new Error(String(err))
|
|
34
|
+
errors.push(error)
|
|
32
35
|
}
|
|
33
36
|
}
|
|
34
37
|
} else {
|
|
@@ -37,11 +40,20 @@ export class AsyncEventEmitter<TEvents extends Record<string, any>> {
|
|
|
37
40
|
try {
|
|
38
41
|
await listener(...eventArgs)
|
|
39
42
|
} catch (err) {
|
|
40
|
-
|
|
43
|
+
const error = err instanceof Error ? err : new Error(String(err))
|
|
44
|
+
errors.push(error)
|
|
41
45
|
}
|
|
42
46
|
})
|
|
43
47
|
await Promise.all(promises)
|
|
44
48
|
}
|
|
49
|
+
|
|
50
|
+
if (errors.length === 1) {
|
|
51
|
+
throw errors[0]
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (errors.length > 1) {
|
|
55
|
+
throw new AggregateError(errors, `Errors in async listeners for "${eventName}"`)
|
|
56
|
+
}
|
|
45
57
|
}
|
|
46
58
|
|
|
47
59
|
on<TEventName extends keyof TEvents & string>(eventName: TEventName, handler: (...eventArg: TEvents[TEventName]) => void): void {
|