@kubb/core 5.0.0-beta.40 → 5.0.0-beta.42
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 +13 -13
- package/dist/{diagnostics-DhfW8YpT.d.ts → diagnostics-DZGgDzSv.d.ts} +183 -33
- package/dist/index.cjs +270 -34
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +16 -2
- package/dist/index.js +271 -37
- package/dist/index.js.map +1 -1
- package/dist/{memoryStorage-DTv1Kub1.js → memoryStorage-BOnaknb7.js} +170 -23
- package/dist/memoryStorage-BOnaknb7.js.map +1 -0
- package/dist/{memoryStorage-Dkxnid2K.cjs → memoryStorage-Dldu8sRT.cjs} +169 -22
- package/dist/memoryStorage-Dldu8sRT.cjs.map +1 -0
- package/dist/mocks.cjs +1 -1
- package/dist/mocks.d.ts +1 -1
- package/dist/mocks.js +1 -1
- package/package.json +4 -4
- package/src/Fingerprint.ts +98 -0
- package/src/KubbDriver.ts +102 -33
- package/src/Manifest.ts +85 -0
- package/src/Telemetry.ts +13 -1
- package/src/caches/fsCache.ts +103 -0
- package/src/createCache.ts +74 -0
- package/src/createKubb.ts +57 -4
- package/src/defineLogger.ts +10 -28
- package/src/defineParser.ts +1 -1
- package/src/index.ts +2 -0
- package/src/storages/fsStorage.ts +15 -23
- package/src/types.ts +3 -0
- package/dist/memoryStorage-DTv1Kub1.js.map +0 -1
- package/dist/memoryStorage-Dkxnid2K.cjs.map +0 -1
package/src/createKubb.ts
CHANGED
|
@@ -5,6 +5,7 @@ import type { FileNode, InputMeta, OperationNode, SchemaNode } from '@kubb/ast'
|
|
|
5
5
|
import { HOOK_LISTENERS_PER_PLUGIN } from './constants.ts'
|
|
6
6
|
import type { Adapter } from './createAdapter.ts'
|
|
7
7
|
import { type Diagnostic, Diagnostics, type ProblemDiagnostic, type UpdateDiagnostic } from './diagnostics.ts'
|
|
8
|
+
import type { Cache } from './createCache.ts'
|
|
8
9
|
import { createStorage, type Storage } from './createStorage.ts'
|
|
9
10
|
import type { GeneratorContext } from './defineGenerator.ts'
|
|
10
11
|
import type { Middleware } from './defineMiddleware.ts'
|
|
@@ -233,6 +234,26 @@ export type Config<TInput = Input> = {
|
|
|
233
234
|
* @see {@link Storage} interface for implementing custom backends.
|
|
234
235
|
*/
|
|
235
236
|
storage: Storage
|
|
237
|
+
/**
|
|
238
|
+
* Incremental build cache. Kubb fingerprints the inputs (spec content, config, plugin options,
|
|
239
|
+
* versions) and, on an unchanged "hot" run, restores the previously generated output instead of
|
|
240
|
+
* regenerating it. Same idea as Nx's computation cache.
|
|
241
|
+
*
|
|
242
|
+
* `defineConfig` enables `fsCache()` (local disk under `node_modules/.cache/kubb`) by default.
|
|
243
|
+
* Pass another backend to change where snapshots live, or `false` to turn caching off. A bare
|
|
244
|
+
* `createKubb` leaves it off unless a cache is provided.
|
|
245
|
+
*
|
|
246
|
+
* @example
|
|
247
|
+
* ```ts
|
|
248
|
+
* import { fsCache } from '@kubb/core'
|
|
249
|
+
*
|
|
250
|
+
* cache: fsCache({ dir: '.kubb-cache' })
|
|
251
|
+
* cache: false
|
|
252
|
+
* ```
|
|
253
|
+
*
|
|
254
|
+
* @see {@link Cache} interface for implementing custom backends.
|
|
255
|
+
*/
|
|
256
|
+
cache?: Cache
|
|
236
257
|
/**
|
|
237
258
|
* Plugins that run during the build to generate code and transform the AST. Each one processes
|
|
238
259
|
* the adapter's AST and can emit files for a different target (TypeScript, Zod, Faker). A plugin
|
|
@@ -336,7 +357,12 @@ export type Config<TInput = Input> = {
|
|
|
336
357
|
* })
|
|
337
358
|
* ```
|
|
338
359
|
*/
|
|
339
|
-
export type UserConfig<TInput = Input> = Omit<Config<TInput>, 'root' | 'plugins' | 'parsers' | 'adapter' | 'storage' | 'reporters'> & {
|
|
360
|
+
export type UserConfig<TInput = Input> = Omit<Config<TInput>, 'root' | 'plugins' | 'parsers' | 'adapter' | 'storage' | 'reporters' | 'cache'> & {
|
|
361
|
+
/**
|
|
362
|
+
* Incremental build cache. Defaults to `fsCache()` (local disk). Pass another {@link Cache}
|
|
363
|
+
* backend, or `false` to turn caching off.
|
|
364
|
+
*/
|
|
365
|
+
cache?: Cache | false
|
|
340
366
|
/**
|
|
341
367
|
* Project root directory, absolute or relative to the config file location.
|
|
342
368
|
* @default process.cwd()
|
|
@@ -464,6 +490,7 @@ export interface KubbHooks {
|
|
|
464
490
|
'kubb:hooks:start': []
|
|
465
491
|
'kubb:hooks:end': []
|
|
466
492
|
'kubb:hook:start': [ctx: KubbHookStartContext]
|
|
493
|
+
'kubb:hook:line': [ctx: KubbHookLineContext]
|
|
467
494
|
'kubb:hook:end': [ctx: KubbHookEndContext]
|
|
468
495
|
'kubb:info': [ctx: KubbInfoContext]
|
|
469
496
|
'kubb:error': [ctx: KubbErrorContext]
|
|
@@ -657,7 +684,7 @@ export type KubbDiagnosticContext = {
|
|
|
657
684
|
|
|
658
685
|
export type KubbFilesProcessingStartContext = {
|
|
659
686
|
/**
|
|
660
|
-
* Files about to be
|
|
687
|
+
* Files about to be serialized and written.
|
|
661
688
|
*/
|
|
662
689
|
files: Array<FileNode>
|
|
663
690
|
}
|
|
@@ -676,7 +703,7 @@ export type KubbFileProcessingUpdate = {
|
|
|
676
703
|
*/
|
|
677
704
|
percentage: number
|
|
678
705
|
/**
|
|
679
|
-
*
|
|
706
|
+
* Serialized file content, or `undefined` when the file produced no output.
|
|
680
707
|
*/
|
|
681
708
|
source?: string
|
|
682
709
|
/**
|
|
@@ -698,7 +725,7 @@ export type KubbFilesProcessingUpdateContext = {
|
|
|
698
725
|
|
|
699
726
|
export type KubbFilesProcessingEndContext = {
|
|
700
727
|
/**
|
|
701
|
-
* All files that were
|
|
728
|
+
* All files that were serialized in this batch.
|
|
702
729
|
*/
|
|
703
730
|
files: Array<FileNode>
|
|
704
731
|
}
|
|
@@ -718,6 +745,21 @@ export type KubbHookStartContext = {
|
|
|
718
745
|
args?: ReadonlyArray<string>
|
|
719
746
|
}
|
|
720
747
|
|
|
748
|
+
/**
|
|
749
|
+
* Emitted for each line streamed from a hook's stdout while it runs.
|
|
750
|
+
* A logger correlates the line to its active UI element via `id`.
|
|
751
|
+
*/
|
|
752
|
+
export type KubbHookLineContext = {
|
|
753
|
+
/**
|
|
754
|
+
* Identifier matching the corresponding `kubb:hook:start` event.
|
|
755
|
+
*/
|
|
756
|
+
id: string
|
|
757
|
+
/**
|
|
758
|
+
* A single streamed stdout line, without its trailing newline.
|
|
759
|
+
*/
|
|
760
|
+
line: string
|
|
761
|
+
}
|
|
762
|
+
|
|
721
763
|
export type KubbHookEndContext = {
|
|
722
764
|
/**
|
|
723
765
|
* Optional identifier matching the corresponding `kubb:hook:start` event.
|
|
@@ -739,6 +781,14 @@ export type KubbHookEndContext = {
|
|
|
739
781
|
* Error thrown by the command, or `null` on success.
|
|
740
782
|
*/
|
|
741
783
|
error: Error | null
|
|
784
|
+
/**
|
|
785
|
+
* Captured stdout from the process, populated when it exits non-zero.
|
|
786
|
+
*/
|
|
787
|
+
stdout?: string
|
|
788
|
+
/**
|
|
789
|
+
* Captured stderr from the process, populated when it exits non-zero.
|
|
790
|
+
*/
|
|
791
|
+
stderr?: string
|
|
742
792
|
}
|
|
743
793
|
|
|
744
794
|
/**
|
|
@@ -863,6 +913,9 @@ function resolveConfig(userConfig: UserConfig): Config {
|
|
|
863
913
|
...userConfig.output,
|
|
864
914
|
},
|
|
865
915
|
storage: userConfig.storage ?? fsStorage(),
|
|
916
|
+
// Resolve `false` to "no cache". The default `fsCache()` is applied by `defineConfig`, not here,
|
|
917
|
+
// so a raw `createKubb` stays deterministic (no surprise on-disk cache) unless a cache is passed.
|
|
918
|
+
cache: userConfig.cache === false ? undefined : userConfig.cache,
|
|
866
919
|
reporters: userConfig.reporters ?? [],
|
|
867
920
|
plugins: userConfig.plugins ?? [],
|
|
868
921
|
}
|
package/src/defineLogger.ts
CHANGED
|
@@ -34,29 +34,27 @@ export type LoggerContext = AsyncEventEmitter<KubbHooks>
|
|
|
34
34
|
/**
|
|
35
35
|
* Logger contract. A logger receives the build's event emitter and subscribes
|
|
36
36
|
* to whichever lifecycle events it wants to forward to its destination
|
|
37
|
-
* (console, file, remote
|
|
37
|
+
* (console, file, remote service).
|
|
38
38
|
*/
|
|
39
|
-
export type Logger<TOptions extends LoggerOptions = LoggerOptions
|
|
39
|
+
export type Logger<TOptions extends LoggerOptions = LoggerOptions> = {
|
|
40
40
|
/**
|
|
41
41
|
* Display name used in diagnostics.
|
|
42
42
|
*/
|
|
43
43
|
name: string
|
|
44
44
|
/**
|
|
45
|
-
* Called once per build with the shared event emitter. Subscribe to
|
|
46
|
-
*
|
|
47
|
-
* logger, which is handy for sink factories.
|
|
45
|
+
* Called once per build with the shared event emitter. Subscribe to the
|
|
46
|
+
* lifecycle events the logger wants to forward to its destination.
|
|
48
47
|
*/
|
|
49
|
-
install: (context: LoggerContext, options?: TOptions) =>
|
|
48
|
+
install: (context: LoggerContext, options?: TOptions) => void | Promise<void>
|
|
50
49
|
}
|
|
51
50
|
|
|
52
|
-
export type UserLogger<TOptions extends LoggerOptions = LoggerOptions
|
|
51
|
+
export type UserLogger<TOptions extends LoggerOptions = LoggerOptions> = Logger<TOptions>
|
|
53
52
|
|
|
54
53
|
/**
|
|
55
|
-
* Defines a typed logger.
|
|
56
|
-
*
|
|
57
|
-
* or cleanup callback to the caller.
|
|
54
|
+
* Defines a typed logger. The `install` method subscribes to lifecycle events
|
|
55
|
+
* on the shared emitter and forwards them to the logger's destination.
|
|
58
56
|
*
|
|
59
|
-
* @example
|
|
57
|
+
* @example
|
|
60
58
|
* ```ts
|
|
61
59
|
* import { defineLogger } from '@kubb/core'
|
|
62
60
|
*
|
|
@@ -68,23 +66,7 @@ export type UserLogger<TOptions extends LoggerOptions = LoggerOptions, TInstallR
|
|
|
68
66
|
* },
|
|
69
67
|
* })
|
|
70
68
|
* ```
|
|
71
|
-
*
|
|
72
|
-
* @example Logger that returns a hook sink factory
|
|
73
|
-
* ```ts
|
|
74
|
-
* import { defineLogger, type LoggerOptions } from '@kubb/core'
|
|
75
|
-
* import type { HookSinkFactory } from './sinks'
|
|
76
|
-
*
|
|
77
|
-
* export const myLogger = defineLogger<LoggerOptions, HookSinkFactory>({
|
|
78
|
-
* name: 'my-logger',
|
|
79
|
-
* install(context) {
|
|
80
|
-
* // … register event handlers …
|
|
81
|
-
* return () => ({ onStdout: console.log })
|
|
82
|
-
* },
|
|
83
|
-
* })
|
|
84
|
-
* ```
|
|
85
69
|
*/
|
|
86
|
-
export function defineLogger<Options extends LoggerOptions = LoggerOptions
|
|
87
|
-
logger: UserLogger<Options, TInstallReturn>,
|
|
88
|
-
): Logger<Options, TInstallReturn> {
|
|
70
|
+
export function defineLogger<Options extends LoggerOptions = LoggerOptions>(logger: UserLogger<Options>): Logger<Options> {
|
|
89
71
|
return logger
|
|
90
72
|
}
|
package/src/defineParser.ts
CHANGED
|
@@ -23,7 +23,7 @@ export type Parser<TMeta extends object = object, TNode = unknown> = {
|
|
|
23
23
|
*/
|
|
24
24
|
extNames: Array<FileNode['extname']> | undefined
|
|
25
25
|
/**
|
|
26
|
-
*
|
|
26
|
+
* Serialize the file's AST into source code.
|
|
27
27
|
*/
|
|
28
28
|
parse(file: FileNode<TMeta>, options?: PrintOptions): string
|
|
29
29
|
/**
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { AsyncEventEmitter, URLPath } from '@internals/utils'
|
|
2
2
|
export * as ast from '@kubb/ast'
|
|
3
3
|
export { createAdapter } from './createAdapter.ts'
|
|
4
|
+
export { createCache } from './createCache.ts'
|
|
4
5
|
export { Diagnostics } from './diagnostics.ts'
|
|
5
6
|
export { createKubb } from './createKubb.ts'
|
|
6
7
|
export { createReporter, selectReporters } from './createReporter.ts'
|
|
@@ -17,6 +18,7 @@ export { defineParser } from './defineParser.ts'
|
|
|
17
18
|
export { definePlugin } from './definePlugin.ts'
|
|
18
19
|
export { defineResolver } from './defineResolver.ts'
|
|
19
20
|
export { KubbDriver } from './KubbDriver.ts'
|
|
21
|
+
export { fsCache } from './caches/fsCache.ts'
|
|
20
22
|
export { fsStorage } from './storages/fsStorage.ts'
|
|
21
23
|
export { memoryStorage } from './storages/memoryStorage.ts'
|
|
22
24
|
export * from './types.ts'
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { clean, write } from '@internals/utils'
|
|
1
|
+
import { access, glob, readFile, rm } from 'node:fs/promises'
|
|
2
|
+
import { join, relative, resolve } from 'node:path'
|
|
3
|
+
import { clean, isBun, toPosixPath, write } from '@internals/utils'
|
|
5
4
|
import { createStorage } from '../createStorage.ts'
|
|
6
5
|
|
|
7
6
|
/**
|
|
@@ -55,29 +54,22 @@ export const fsStorage = createStorage(() => ({
|
|
|
55
54
|
async getKeys(base?: string) {
|
|
56
55
|
const resolvedBase = resolve(base ?? process.cwd())
|
|
57
56
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
entries = (await readdir(dir, {
|
|
62
|
-
withFileTypes: true,
|
|
63
|
-
})) as Array<Dirent>
|
|
64
|
-
} catch (_error) {
|
|
65
|
-
return
|
|
66
|
-
}
|
|
67
|
-
for (const entry of entries) {
|
|
68
|
-
const rel = prefix ? `${prefix}/${entry.name}` : entry.name
|
|
69
|
-
if (entry.isDirectory()) {
|
|
70
|
-
yield* walk(join(dir, entry.name), rel)
|
|
71
|
-
} else {
|
|
72
|
-
yield rel
|
|
73
|
-
}
|
|
74
|
-
}
|
|
57
|
+
if (isBun()) {
|
|
58
|
+
const bunGlob = new Bun.Glob('**/*')
|
|
59
|
+
return Array.fromAsync(bunGlob.scan({ cwd: resolvedBase, onlyFiles: true, dot: true }))
|
|
75
60
|
}
|
|
76
61
|
|
|
77
62
|
const keys: Array<string> = []
|
|
78
|
-
|
|
79
|
-
|
|
63
|
+
try {
|
|
64
|
+
for await (const entry of glob('**/*', { cwd: resolvedBase, withFileTypes: true })) {
|
|
65
|
+
if (entry.isFile()) {
|
|
66
|
+
keys.push(toPosixPath(relative(resolvedBase, join(entry.parentPath, entry.name))))
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
} catch (_error) {
|
|
70
|
+
// base directory does not exist yet
|
|
80
71
|
}
|
|
72
|
+
|
|
81
73
|
return keys
|
|
82
74
|
},
|
|
83
75
|
async clear(base?: string) {
|
package/src/types.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
export type { Adapter, AdapterFactoryOptions, AdapterSource } from './createAdapter.ts'
|
|
2
|
+
export type { Cache, CachedSnapshot } from './createCache.ts'
|
|
3
|
+
export type { FsCacheOptions } from './caches/fsCache.ts'
|
|
2
4
|
export type {
|
|
3
5
|
Diagnostic,
|
|
4
6
|
DiagnosticByCode,
|
|
@@ -31,6 +33,7 @@ export type {
|
|
|
31
33
|
KubbGenerationEndContext,
|
|
32
34
|
KubbGenerationStartContext,
|
|
33
35
|
KubbHookEndContext,
|
|
36
|
+
KubbHookLineContext,
|
|
34
37
|
KubbHookStartContext,
|
|
35
38
|
KubbHooks,
|
|
36
39
|
KubbInfoContext,
|