@kubb/core
Advanced tools
Comparing version 1.1.5 to 1.1.6
@@ -127,3 +127,3 @@ import { Ora } from 'ora'; | ||
queue: Queue; | ||
task: QueueTask<unknown>; | ||
task?: QueueTask<unknown>; | ||
}); | ||
@@ -133,2 +133,3 @@ private getCache; | ||
get files(): File[]; | ||
get cachedFiles(): CacheStore[]; | ||
add(file: File): Promise<File>; | ||
@@ -215,2 +216,6 @@ addOrAppend(file: File): Promise<File>; | ||
}): SafeParseResult<H>; | ||
/** | ||
* | ||
* Parallel, runs all plugins | ||
*/ | ||
hookParallel<H extends PluginLifecycleHooks, TOuput = void>({ hookName, parameters, }: { | ||
@@ -220,2 +225,6 @@ hookName: H; | ||
}): Promise<Awaited<TOuput>[]>; | ||
/** | ||
* | ||
* Chains, reduces returned value, handling the reduced value as the first hook argument | ||
*/ | ||
hookReduceArg0<H extends PluginLifecycleHooks>({ hookName, parameters, reduce, }: { | ||
@@ -226,2 +235,5 @@ hookName: H; | ||
}): Promise<Argument0<H>>; | ||
/** | ||
* Chains plugins | ||
*/ | ||
hookSeq<H extends PluginLifecycleHooks>({ hookName, parameters }: { | ||
@@ -232,3 +244,3 @@ hookName: H; | ||
private getSortedPlugins; | ||
private getPlugin; | ||
getPlugin(hookName: keyof PluginLifecycle, pluginName: string): KubbPlugin; | ||
private addExecuter; | ||
@@ -235,0 +247,0 @@ /** |
@@ -516,2 +516,9 @@ import { createRequire } from 'module'; | ||
} | ||
get cachedFiles() { | ||
const files = []; | ||
this.cache.forEach((item) => { | ||
files.push(item); | ||
}); | ||
return files; | ||
} | ||
async add(file) { | ||
@@ -685,5 +692,5 @@ const cacheItem = { id: crypto.randomUUID(), file, status: "new" }; | ||
continue; | ||
promise = promise.then(async (result) => { | ||
if (result != null) { | ||
return result; | ||
promise = promise.then(async (parseResult) => { | ||
if (parseResult?.result != null) { | ||
return parseResult; | ||
} | ||
@@ -713,7 +720,7 @@ const value = await this.execute({ | ||
}) { | ||
let result = null; | ||
let parseResult = null; | ||
for (const plugin of this.getSortedPlugins(hookName)) { | ||
if (skipped && skipped.has(plugin)) | ||
continue; | ||
result = { | ||
parseResult = { | ||
result: this.executeSync({ | ||
@@ -724,11 +731,15 @@ strategy: "hookFirst", | ||
plugin | ||
}) | ||
}), | ||
plugin | ||
}; | ||
if (result != null) { | ||
if (parseResult?.result != null) { | ||
break; | ||
} | ||
} | ||
return result; | ||
return parseResult; | ||
} | ||
// parallel | ||
/** | ||
* | ||
* Parallel, runs all plugins | ||
*/ | ||
async hookParallel({ | ||
@@ -740,16 +751,5 @@ hookName, | ||
for (const plugin of this.getSortedPlugins(hookName)) { | ||
if (plugin[hookName]?.sequential) { | ||
await Promise.all(parallelPromises); | ||
parallelPromises.length = 0; | ||
await this.execute({ | ||
strategy: "hookParallel", | ||
hookName, | ||
parameters, | ||
plugin | ||
}); | ||
} else { | ||
const promise = this.execute({ strategy: "hookParallel", hookName, parameters, plugin }); | ||
if (promise) { | ||
parallelPromises.push(promise); | ||
} | ||
const promise = this.execute({ strategy: "hookParallel", hookName, parameters, plugin }); | ||
if (promise) { | ||
parallelPromises.push(promise); | ||
} | ||
@@ -764,3 +764,6 @@ } | ||
} | ||
// chains, reduces returned value, handling the reduced value as the first hook argument | ||
/** | ||
* | ||
* Chains, reduces returned value, handling the reduced value as the first hook argument | ||
*/ | ||
hookReduceArg0({ | ||
@@ -774,7 +777,7 @@ hookName, | ||
for (const plugin of this.getSortedPlugins(hookName)) { | ||
promise = promise.then((argument02) => { | ||
promise = promise.then((arg0) => { | ||
const value = this.execute({ | ||
strategy: "hookReduceArg0", | ||
hookName, | ||
parameters: [argument02, ...rest], | ||
parameters: [arg0, ...rest], | ||
plugin | ||
@@ -787,3 +790,5 @@ }); | ||
} | ||
// chains | ||
/** | ||
* Chains plugins | ||
*/ | ||
hookSeq({ hookName, parameters }) { | ||
@@ -1068,5 +1073,2 @@ let promise = Promise.resolve(); | ||
async function transformReducer(_previousCode, result, _plugin) { | ||
if (result === null) { | ||
return null; | ||
} | ||
return result; | ||
@@ -1073,0 +1075,0 @@ } |
{ | ||
"name": "@kubb/core", | ||
"version": "1.1.5", | ||
"version": "1.1.6", | ||
"description": "Generator core", | ||
@@ -46,3 +46,3 @@ "repository": { | ||
"rimraf": "^5.0.1", | ||
"@kubb/ts-codegen": "1.1.5" | ||
"@kubb/ts-codegen": "1.1.6" | ||
}, | ||
@@ -59,3 +59,3 @@ "devDependencies": { | ||
"engines": { | ||
"node": ">=16", | ||
"node": ">=18", | ||
"pnpm": ">=8" | ||
@@ -62,0 +62,0 @@ }, |
@@ -28,5 +28,2 @@ /* eslint-disable no-async-promise-executor */ | ||
): Promise<string | null> { | ||
if (result === null) { | ||
return null | ||
} | ||
return result | ||
@@ -33,0 +30,0 @@ } |
@@ -15,3 +15,3 @@ import crypto from 'node:crypto' | ||
constructor(options?: { queue: Queue; task: QueueTask<unknown> }) { | ||
constructor(options?: { queue: Queue; task?: QueueTask<unknown> }) { | ||
if (options) { | ||
@@ -47,2 +47,11 @@ this.task = options.task | ||
get cachedFiles() { | ||
const files: CacheStore[] = [] | ||
this.cache.forEach((item) => { | ||
files.push(item) | ||
}) | ||
return files | ||
} | ||
async add(file: File) { | ||
@@ -49,0 +58,0 @@ const cacheItem = { id: crypto.randomUUID(), file, status: 'new' as Status } |
@@ -168,5 +168,5 @@ /* eslint-disable @typescript-eslint/ban-types */ | ||
if (skipped && skipped.has(plugin)) continue | ||
promise = promise.then(async (result) => { | ||
if (result != null) { | ||
return result | ||
promise = promise.then(async (parseResult) => { | ||
if (parseResult?.result != null) { | ||
return parseResult | ||
} | ||
@@ -183,3 +183,3 @@ const value = await this.execute<H>({ | ||
result: value, | ||
} as typeof result) | ||
} as typeof parseResult) | ||
}) | ||
@@ -204,3 +204,3 @@ } | ||
}): SafeParseResult<H> { | ||
let result: SafeParseResult<H> = null as unknown as SafeParseResult<H> | ||
let parseResult: SafeParseResult<H> = null as unknown as SafeParseResult<H> | ||
@@ -210,3 +210,3 @@ for (const plugin of this.getSortedPlugins(hookName)) { | ||
result = { | ||
parseResult = { | ||
result: this.executeSync<H>({ | ||
@@ -218,12 +218,16 @@ strategy: 'hookFirst', | ||
}), | ||
plugin, | ||
} as SafeParseResult<H> | ||
if (result != null) { | ||
if (parseResult?.result != null) { | ||
break | ||
} | ||
} | ||
return result as SafeParseResult<H> | ||
return parseResult as SafeParseResult<H> | ||
} | ||
// parallel | ||
/** | ||
* | ||
* Parallel, runs all plugins | ||
*/ | ||
async hookParallel<H extends PluginLifecycleHooks, TOuput = void>({ | ||
@@ -239,17 +243,17 @@ hookName, | ||
for (const plugin of this.getSortedPlugins(hookName)) { | ||
if ((plugin[hookName] as { sequential?: boolean })?.sequential) { | ||
await Promise.all(parallelPromises) | ||
parallelPromises.length = 0 | ||
await this.execute({ | ||
strategy: 'hookParallel', | ||
hookName, | ||
parameters, | ||
plugin, | ||
}) | ||
} else { | ||
const promise: Promise<TOuput> | null = this.execute({ strategy: 'hookParallel', hookName, parameters, plugin }) | ||
// TODO implement sequential with `buildStart` as an object({ sequential: boolean; handler: PluginContext["buildStart"] }) | ||
// if ((plugin[hookName] as { sequential?: boolean })?.sequential) { | ||
// await Promise.all(parallelPromises) | ||
// parallelPromises.length = 0 | ||
// await this.execute({ | ||
// strategy: 'hookParallel', | ||
// hookName, | ||
// parameters, | ||
// plugin, | ||
// }) | ||
// } | ||
const promise: Promise<TOuput> | null = this.execute({ strategy: 'hookParallel', hookName, parameters, plugin }) | ||
if (promise) { | ||
parallelPromises.push(promise) | ||
} | ||
if (promise) { | ||
parallelPromises.push(promise) | ||
} | ||
@@ -267,3 +271,6 @@ } | ||
// chains, reduces returned value, handling the reduced value as the first hook argument | ||
/** | ||
* | ||
* Chains, reduces returned value, handling the reduced value as the first hook argument | ||
*/ | ||
hookReduceArg0<H extends PluginLifecycleHooks>({ | ||
@@ -283,7 +290,7 @@ hookName, | ||
promise = promise | ||
.then((argument0) => { | ||
.then((arg0) => { | ||
const value = this.execute({ | ||
strategy: 'hookReduceArg0', | ||
hookName, | ||
parameters: [argument0, ...rest] as Parameters<PluginLifecycle[H]>, | ||
parameters: [arg0, ...rest] as Parameters<PluginLifecycle[H]>, | ||
plugin, | ||
@@ -298,4 +305,5 @@ }) | ||
// chains | ||
/** | ||
* Chains plugins | ||
*/ | ||
hookSeq<H extends PluginLifecycleHooks>({ hookName, parameters }: { hookName: H; parameters?: Parameters<PluginLifecycle[H]> }) { | ||
@@ -322,3 +330,3 @@ let promise: Promise<void | null> = Promise.resolve() | ||
private getPlugin(hookName: keyof PluginLifecycle, pluginName: string): KubbPlugin { | ||
public getPlugin(hookName: keyof PluginLifecycle, pluginName: string): KubbPlugin { | ||
const plugins = [...this.plugins] | ||
@@ -325,0 +333,0 @@ |
Sorry, the diff of this file is not supported yet
137299
4532
+ Added@kubb/ts-codegen@1.1.6(transitive)
- Removed@kubb/ts-codegen@1.1.5(transitive)
Updated@kubb/ts-codegen@1.1.6