@kubb/core 5.0.0-alpha.4 → 5.0.0-alpha.41
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/PluginDriver-BQwm8hDd.cjs +1729 -0
- package/dist/PluginDriver-BQwm8hDd.cjs.map +1 -0
- package/dist/PluginDriver-CgXFtmNP.js +1617 -0
- package/dist/PluginDriver-CgXFtmNP.js.map +1 -0
- package/dist/index.cjs +915 -1901
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +268 -264
- package/dist/index.js +894 -1863
- package/dist/index.js.map +1 -1
- package/dist/mocks.cjs +164 -0
- package/dist/mocks.cjs.map +1 -0
- package/dist/mocks.d.ts +74 -0
- package/dist/mocks.js +159 -0
- package/dist/mocks.js.map +1 -0
- package/dist/types-C6NCtNqM.d.ts +2151 -0
- package/package.json +11 -14
- package/src/FileManager.ts +131 -0
- package/src/FileProcessor.ts +84 -0
- package/src/Kubb.ts +174 -85
- package/src/PluginDriver.ts +941 -0
- package/src/constants.ts +33 -43
- package/src/createAdapter.ts +25 -0
- package/src/createKubb.ts +605 -0
- package/src/createPlugin.ts +31 -0
- package/src/createRenderer.ts +57 -0
- package/src/createStorage.ts +58 -0
- package/src/defineGenerator.ts +88 -100
- package/src/defineLogger.ts +13 -3
- package/src/defineParser.ts +45 -0
- package/src/definePlugin.ts +90 -7
- package/src/defineResolver.ts +453 -0
- package/src/devtools.ts +14 -14
- package/src/index.ts +12 -17
- package/src/mocks.ts +234 -0
- package/src/renderNode.ts +35 -0
- package/src/storages/fsStorage.ts +29 -9
- package/src/storages/memoryStorage.ts +2 -2
- package/src/types.ts +821 -152
- package/src/utils/TreeNode.ts +47 -9
- package/src/utils/diagnostics.ts +4 -1
- package/src/utils/executeStrategies.ts +16 -13
- package/src/utils/getBarrelFiles.ts +88 -15
- package/src/utils/isInputPath.ts +10 -0
- package/src/utils/packageJSON.ts +75 -0
- package/dist/chunk-ByKO4r7w.cjs +0 -38
- package/dist/hooks.cjs +0 -50
- package/dist/hooks.cjs.map +0 -1
- package/dist/hooks.d.ts +0 -49
- package/dist/hooks.js +0 -46
- package/dist/hooks.js.map +0 -1
- package/dist/types-Bbh1o0yW.d.ts +0 -1057
- package/src/BarrelManager.ts +0 -74
- package/src/PackageManager.ts +0 -180
- package/src/PluginManager.ts +0 -668
- package/src/PromiseManager.ts +0 -40
- package/src/build.ts +0 -420
- package/src/config.ts +0 -56
- package/src/defineAdapter.ts +0 -22
- package/src/defineStorage.ts +0 -56
- package/src/errors.ts +0 -1
- package/src/hooks/index.ts +0 -8
- package/src/hooks/useKubb.ts +0 -22
- package/src/hooks/useMode.ts +0 -11
- package/src/hooks/usePlugin.ts +0 -11
- package/src/hooks/usePluginManager.ts +0 -11
- package/src/utils/FunctionParams.ts +0 -155
- package/src/utils/formatters.ts +0 -56
- package/src/utils/getConfigs.ts +0 -30
- package/src/utils/getPlugins.ts +0 -23
- package/src/utils/linters.ts +0 -25
- package/src/utils/resolveOptions.ts +0 -93
package/src/utils/TreeNode.ts
CHANGED
|
@@ -1,17 +1,26 @@
|
|
|
1
1
|
import path from 'node:path'
|
|
2
|
-
import type {
|
|
3
|
-
import {
|
|
2
|
+
import type { FileNode } from '@kubb/ast'
|
|
3
|
+
import { PluginDriver } from '../PluginDriver.ts'
|
|
4
4
|
|
|
5
5
|
type BarrelData = {
|
|
6
|
-
file?:
|
|
6
|
+
file?: FileNode
|
|
7
7
|
/**
|
|
8
8
|
* @deprecated use file instead
|
|
9
9
|
*/
|
|
10
|
-
type:
|
|
10
|
+
type: 'single' | 'split'
|
|
11
11
|
path: string
|
|
12
12
|
name: string
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
+
/**
|
|
16
|
+
* Tree structure used to build per-directory barrel (`index.ts`) files from a
|
|
17
|
+
* flat list of generated {@link FileNode} entries.
|
|
18
|
+
*
|
|
19
|
+
* Each node represents either a directory or a file within the output tree.
|
|
20
|
+
* Use {@link TreeNode.build} to construct a root node from a file list, then
|
|
21
|
+
* traverse with {@link TreeNode.forEach}, {@link TreeNode.leaves}, or the
|
|
22
|
+
* `*Deep` helpers.
|
|
23
|
+
*/
|
|
15
24
|
export class TreeNode {
|
|
16
25
|
data: BarrelData
|
|
17
26
|
parent?: TreeNode
|
|
@@ -32,6 +41,9 @@ export class TreeNode {
|
|
|
32
41
|
return child
|
|
33
42
|
}
|
|
34
43
|
|
|
44
|
+
/**
|
|
45
|
+
* Returns the root ancestor of this node, walking up via `parent` links.
|
|
46
|
+
*/
|
|
35
47
|
get root(): TreeNode {
|
|
36
48
|
if (!this.parent) {
|
|
37
49
|
return this
|
|
@@ -39,6 +51,11 @@ export class TreeNode {
|
|
|
39
51
|
return this.parent.root
|
|
40
52
|
}
|
|
41
53
|
|
|
54
|
+
/**
|
|
55
|
+
* Returns all leaf descendants (nodes with no children) of this node.
|
|
56
|
+
*
|
|
57
|
+
* Results are cached after the first traversal.
|
|
58
|
+
*/
|
|
42
59
|
get leaves(): Array<TreeNode> {
|
|
43
60
|
if (!this.children || this.children.length === 0) {
|
|
44
61
|
// this is a leaf
|
|
@@ -59,6 +76,9 @@ export class TreeNode {
|
|
|
59
76
|
return leaves
|
|
60
77
|
}
|
|
61
78
|
|
|
79
|
+
/**
|
|
80
|
+
* Visits this node and every descendant in depth-first order.
|
|
81
|
+
*/
|
|
62
82
|
forEach(callback: (treeNode: TreeNode) => void): this {
|
|
63
83
|
if (typeof callback !== 'function') {
|
|
64
84
|
throw new TypeError('forEach() callback must be a function')
|
|
@@ -73,6 +93,9 @@ export class TreeNode {
|
|
|
73
93
|
return this
|
|
74
94
|
}
|
|
75
95
|
|
|
96
|
+
/**
|
|
97
|
+
* Finds the first leaf that satisfies `predicate`, or `undefined` when none match.
|
|
98
|
+
*/
|
|
76
99
|
findDeep(predicate?: (value: TreeNode, index: number, obj: TreeNode[]) => boolean): TreeNode | undefined {
|
|
77
100
|
if (typeof predicate !== 'function') {
|
|
78
101
|
throw new TypeError('find() predicate must be a function')
|
|
@@ -81,6 +104,9 @@ export class TreeNode {
|
|
|
81
104
|
return this.leaves.find(predicate)
|
|
82
105
|
}
|
|
83
106
|
|
|
107
|
+
/**
|
|
108
|
+
* Calls `callback` for every leaf of this node.
|
|
109
|
+
*/
|
|
84
110
|
forEachDeep(callback: (treeNode: TreeNode) => void): void {
|
|
85
111
|
if (typeof callback !== 'function') {
|
|
86
112
|
throw new TypeError('forEach() callback must be a function')
|
|
@@ -89,6 +115,9 @@ export class TreeNode {
|
|
|
89
115
|
this.leaves.forEach(callback)
|
|
90
116
|
}
|
|
91
117
|
|
|
118
|
+
/**
|
|
119
|
+
* Returns all leaves that satisfy `callback`.
|
|
120
|
+
*/
|
|
92
121
|
filterDeep(callback: (treeNode: TreeNode) => boolean): Array<TreeNode> {
|
|
93
122
|
if (typeof callback !== 'function') {
|
|
94
123
|
throw new TypeError('filter() callback must be a function')
|
|
@@ -97,6 +126,9 @@ export class TreeNode {
|
|
|
97
126
|
return this.leaves.filter(callback)
|
|
98
127
|
}
|
|
99
128
|
|
|
129
|
+
/**
|
|
130
|
+
* Maps every leaf through `callback` and returns the resulting array.
|
|
131
|
+
*/
|
|
100
132
|
mapDeep<T>(callback: (treeNode: TreeNode) => T): Array<T> {
|
|
101
133
|
if (typeof callback !== 'function') {
|
|
102
134
|
throw new TypeError('map() callback must be a function')
|
|
@@ -105,7 +137,13 @@ export class TreeNode {
|
|
|
105
137
|
return this.leaves.map(callback)
|
|
106
138
|
}
|
|
107
139
|
|
|
108
|
-
|
|
140
|
+
/**
|
|
141
|
+
* Builds a {@link TreeNode} tree from a flat list of files.
|
|
142
|
+
*
|
|
143
|
+
* - Filters to files under `root` (when provided) and skips `.json` files.
|
|
144
|
+
* - Returns `null` when no files match.
|
|
145
|
+
*/
|
|
146
|
+
public static build(files: FileNode[], root?: string): TreeNode | null {
|
|
109
147
|
try {
|
|
110
148
|
const filteredTree = buildDirectoryTree(files, root)
|
|
111
149
|
|
|
@@ -117,7 +155,7 @@ export class TreeNode {
|
|
|
117
155
|
name: filteredTree.name,
|
|
118
156
|
path: filteredTree.path,
|
|
119
157
|
file: filteredTree.file,
|
|
120
|
-
type: getMode(filteredTree.path),
|
|
158
|
+
type: PluginDriver.getMode(filteredTree.path),
|
|
121
159
|
})
|
|
122
160
|
|
|
123
161
|
const recurse = (node: typeof treeNode, item: DirectoryTree) => {
|
|
@@ -125,7 +163,7 @@ export class TreeNode {
|
|
|
125
163
|
name: item.name,
|
|
126
164
|
path: item.path,
|
|
127
165
|
file: item.file,
|
|
128
|
-
type: getMode(item.path),
|
|
166
|
+
type: PluginDriver.getMode(item.path),
|
|
129
167
|
})
|
|
130
168
|
|
|
131
169
|
if (item.children?.length) {
|
|
@@ -149,13 +187,13 @@ export class TreeNode {
|
|
|
149
187
|
type DirectoryTree = {
|
|
150
188
|
name: string
|
|
151
189
|
path: string
|
|
152
|
-
file?:
|
|
190
|
+
file?: FileNode
|
|
153
191
|
children: Array<DirectoryTree>
|
|
154
192
|
}
|
|
155
193
|
|
|
156
194
|
const normalizePath = (p: string): string => p.replaceAll('\\', '/')
|
|
157
195
|
|
|
158
|
-
function buildDirectoryTree(files: Array<
|
|
196
|
+
function buildDirectoryTree(files: Array<FileNode>, rootFolder = ''): DirectoryTree | null {
|
|
159
197
|
const normalizedRootFolder = normalizePath(rootFolder)
|
|
160
198
|
const rootPrefix = normalizedRootFolder.endsWith('/') ? normalizedRootFolder : `${normalizedRootFolder}/`
|
|
161
199
|
|
package/src/utils/diagnostics.ts
CHANGED
|
@@ -2,7 +2,10 @@ import { version as nodeVersion } from 'node:process'
|
|
|
2
2
|
import { version as KubbVersion } from '../../package.json'
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* Returns a snapshot of the current runtime environment.
|
|
6
|
+
*
|
|
7
|
+
* Useful for attaching context to debug logs and error reports so that
|
|
8
|
+
* issues can be reproduced without manual information gathering.
|
|
6
9
|
*/
|
|
7
10
|
export function getDiagnosticInfo() {
|
|
8
11
|
return {
|
|
@@ -7,7 +7,12 @@ type ValueOfPromiseFuncArray<TInput extends Array<unknown>> = TInput extends Arr
|
|
|
7
7
|
type SeqOutput<TInput extends Array<PromiseFunc<TValue, null>>, TValue> = Promise<Array<Awaited<ValueOfPromiseFuncArray<TInput>>>>
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
|
-
*
|
|
10
|
+
* Runs promise functions in sequence, threading each result into the next call.
|
|
11
|
+
*
|
|
12
|
+
* - Each function receives the accumulated state from the previous call.
|
|
13
|
+
* - Skips functions that return a falsy value (acts as a no-op for that step).
|
|
14
|
+
* - Returns an array of all individual results.
|
|
15
|
+
* @deprecated
|
|
11
16
|
*/
|
|
12
17
|
export function hookSeq<TInput extends Array<PromiseFunc<TValue, null>>, TValue, TOutput = SeqOutput<TInput, TValue>>(promises: TInput): TOutput {
|
|
13
18
|
return promises.filter(Boolean).reduce(
|
|
@@ -33,7 +38,11 @@ export function hookSeq<TInput extends Array<PromiseFunc<TValue, null>>, TValue,
|
|
|
33
38
|
type HookFirstOutput<TInput extends Array<PromiseFunc<TValue, null>>, TValue = unknown> = ValueOfPromiseFuncArray<TInput>
|
|
34
39
|
|
|
35
40
|
/**
|
|
36
|
-
*
|
|
41
|
+
* Runs promise functions in sequence and returns the first non-null result.
|
|
42
|
+
*
|
|
43
|
+
* - Stops as soon as `nullCheck` passes for a result (default: `!== null`).
|
|
44
|
+
* - Subsequent functions are skipped once a match is found.
|
|
45
|
+
* @deprecated
|
|
37
46
|
*/
|
|
38
47
|
export function hookFirst<TInput extends Array<PromiseFunc<TValue, null>>, TValue = unknown, TOutput = HookFirstOutput<TInput, TValue>>(
|
|
39
48
|
promises: TInput,
|
|
@@ -57,7 +66,11 @@ export function hookFirst<TInput extends Array<PromiseFunc<TValue, null>>, TValu
|
|
|
57
66
|
type HookParallelOutput<TInput extends Array<PromiseFunc<TValue, null>>, TValue> = Promise<PromiseSettledResult<Awaited<ValueOfPromiseFuncArray<TInput>>>[]>
|
|
58
67
|
|
|
59
68
|
/**
|
|
60
|
-
* Runs
|
|
69
|
+
* Runs promise functions concurrently and returns all settled results.
|
|
70
|
+
*
|
|
71
|
+
* - Limits simultaneous executions to `concurrency` (default: unlimited).
|
|
72
|
+
* - Uses `Promise.allSettled` so individual failures do not cancel other tasks.
|
|
73
|
+
* @deprecated
|
|
61
74
|
*/
|
|
62
75
|
export function hookParallel<TInput extends Array<PromiseFunc<TValue, null>>, TValue = unknown, TOutput = HookParallelOutput<TInput, TValue>>(
|
|
63
76
|
promises: TInput,
|
|
@@ -69,13 +82,3 @@ export function hookParallel<TInput extends Array<PromiseFunc<TValue, null>>, TV
|
|
|
69
82
|
|
|
70
83
|
return Promise.allSettled(tasks) as TOutput
|
|
71
84
|
}
|
|
72
|
-
|
|
73
|
-
export type Strategy = 'seq' | 'first' | 'parallel'
|
|
74
|
-
|
|
75
|
-
export type StrategySwitch<TStrategy extends Strategy, TInput extends Array<PromiseFunc<TValue, null>>, TValue> = TStrategy extends 'first'
|
|
76
|
-
? HookFirstOutput<TInput, TValue>
|
|
77
|
-
: TStrategy extends 'seq'
|
|
78
|
-
? SeqOutput<TInput, TValue>
|
|
79
|
-
: TStrategy extends 'parallel'
|
|
80
|
-
? HookParallelOutput<TInput, TValue>
|
|
81
|
-
: never
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
/** biome-ignore-all lint/suspicious/useIterableCallbackReturn: not needed */
|
|
1
2
|
import { join } from 'node:path'
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
3
|
+
import { getRelativePath } from '@internals/utils'
|
|
4
|
+
import type { FileNode } from '@kubb/ast'
|
|
5
|
+
import { createExport, createFile, createSource } from '@kubb/ast'
|
|
4
6
|
import type { BarrelType } from '../types.ts'
|
|
7
|
+
import { TreeNode } from './TreeNode.ts'
|
|
5
8
|
|
|
6
9
|
export type FileMetaBase = {
|
|
7
10
|
pluginName?: string
|
|
@@ -10,11 +13,11 @@ export type FileMetaBase = {
|
|
|
10
13
|
type AddIndexesProps = {
|
|
11
14
|
type: BarrelType | false | undefined
|
|
12
15
|
/**
|
|
13
|
-
*
|
|
16
|
+
* Absolute output root derived from config `root` and `output.path`.
|
|
14
17
|
*/
|
|
15
18
|
root: string
|
|
16
19
|
/**
|
|
17
|
-
* Output for plugin
|
|
20
|
+
* Output settings for the plugin.
|
|
18
21
|
*/
|
|
19
22
|
output: {
|
|
20
23
|
path: string
|
|
@@ -27,6 +30,74 @@ type AddIndexesProps = {
|
|
|
27
30
|
meta?: FileMetaBase
|
|
28
31
|
}
|
|
29
32
|
|
|
33
|
+
function getBarrelFilesByRoot(root: string | undefined, files: Array<FileNode>): Array<FileNode> {
|
|
34
|
+
const cachedFiles = new Map<string, FileNode>()
|
|
35
|
+
|
|
36
|
+
TreeNode.build(files, root)?.forEach((treeNode) => {
|
|
37
|
+
if (!treeNode?.children || !treeNode.parent?.data.path) {
|
|
38
|
+
return
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const barrelFilePath = join(treeNode.parent?.data.path, 'index.ts')
|
|
42
|
+
const barrelFile = createFile({
|
|
43
|
+
path: barrelFilePath,
|
|
44
|
+
baseName: 'index.ts',
|
|
45
|
+
exports: [],
|
|
46
|
+
imports: [],
|
|
47
|
+
sources: [],
|
|
48
|
+
})
|
|
49
|
+
const previousBarrelFile = cachedFiles.get(barrelFile.path)
|
|
50
|
+
const leaves = treeNode.leaves
|
|
51
|
+
|
|
52
|
+
leaves.forEach((item) => {
|
|
53
|
+
if (!item.data.name) {
|
|
54
|
+
return
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const sources = item.data.file?.sources || []
|
|
58
|
+
|
|
59
|
+
sources.forEach((source) => {
|
|
60
|
+
if (!item.data.file?.path || !source.isIndexable || !source.name) {
|
|
61
|
+
return
|
|
62
|
+
}
|
|
63
|
+
const alreadyContainInPreviousBarrelFile = previousBarrelFile?.sources.some(
|
|
64
|
+
(item) => item.name === source.name && item.isTypeOnly === source.isTypeOnly,
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
if (alreadyContainInPreviousBarrelFile) {
|
|
68
|
+
return
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
barrelFile.exports.push(
|
|
72
|
+
createExport({
|
|
73
|
+
name: [source.name],
|
|
74
|
+
path: getRelativePath(treeNode.parent?.data.path, item.data.path),
|
|
75
|
+
isTypeOnly: source.isTypeOnly,
|
|
76
|
+
}),
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
barrelFile.sources.push(
|
|
80
|
+
createSource({
|
|
81
|
+
name: source.name,
|
|
82
|
+
isTypeOnly: source.isTypeOnly,
|
|
83
|
+
isExportable: false,
|
|
84
|
+
isIndexable: false,
|
|
85
|
+
}),
|
|
86
|
+
)
|
|
87
|
+
})
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
if (previousBarrelFile) {
|
|
91
|
+
previousBarrelFile.sources.push(...barrelFile.sources)
|
|
92
|
+
previousBarrelFile.exports.push(...barrelFile.exports)
|
|
93
|
+
} else {
|
|
94
|
+
cachedFiles.set(barrelFile.path, barrelFile)
|
|
95
|
+
}
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
return [...cachedFiles.values()]
|
|
99
|
+
}
|
|
100
|
+
|
|
30
101
|
function trimExtName(text: string): string {
|
|
31
102
|
const dotIndex = text.lastIndexOf('.')
|
|
32
103
|
// Only strip when the dot is found and no path separator follows it
|
|
@@ -37,36 +108,38 @@ function trimExtName(text: string): string {
|
|
|
37
108
|
return text
|
|
38
109
|
}
|
|
39
110
|
|
|
40
|
-
|
|
111
|
+
/**
|
|
112
|
+
* Generates `index.ts` barrel files for all directories under `root/output.path`.
|
|
113
|
+
*
|
|
114
|
+
* - Returns an empty array when `type` is falsy or `'propagate'`.
|
|
115
|
+
* - Skips generation when the output path itself ends with `index` (already a barrel).
|
|
116
|
+
* - When `type` is `'all'`, strips named exports so every re-export becomes a wildcard (`export * from`).
|
|
117
|
+
* - Attaches `meta` to each barrel file for downstream plugin identification.
|
|
118
|
+
*/
|
|
119
|
+
export async function getBarrelFiles(files: Array<FileNode>, { type, meta = {}, root, output }: AddIndexesProps): Promise<Array<FileNode>> {
|
|
41
120
|
if (!type || type === 'propagate') {
|
|
42
121
|
return []
|
|
43
122
|
}
|
|
44
123
|
|
|
45
|
-
const barrelManager = new BarrelManager()
|
|
46
|
-
|
|
47
124
|
const pathToBuildFrom = join(root, output.path)
|
|
48
125
|
|
|
49
126
|
if (trimExtName(pathToBuildFrom).endsWith('index')) {
|
|
50
127
|
return []
|
|
51
128
|
}
|
|
52
129
|
|
|
53
|
-
const barrelFiles =
|
|
54
|
-
files,
|
|
55
|
-
root: pathToBuildFrom,
|
|
56
|
-
meta,
|
|
57
|
-
})
|
|
130
|
+
const barrelFiles = getBarrelFilesByRoot(pathToBuildFrom, files)
|
|
58
131
|
|
|
59
132
|
if (type === 'all') {
|
|
60
133
|
return barrelFiles.map((file) => {
|
|
61
134
|
return {
|
|
62
135
|
...file,
|
|
63
|
-
exports: file.exports
|
|
136
|
+
exports: file.exports.map((exportItem) => {
|
|
64
137
|
return {
|
|
65
138
|
...exportItem,
|
|
66
139
|
name: undefined,
|
|
67
140
|
}
|
|
68
141
|
}),
|
|
69
|
-
}
|
|
142
|
+
} as FileNode
|
|
70
143
|
})
|
|
71
144
|
}
|
|
72
145
|
|
|
@@ -74,6 +147,6 @@ export async function getBarrelFiles(files: Array<KubbFile.ResolvedFile>, { type
|
|
|
74
147
|
return {
|
|
75
148
|
...indexFile,
|
|
76
149
|
meta,
|
|
77
|
-
}
|
|
150
|
+
} as FileNode
|
|
78
151
|
})
|
|
79
152
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Config, InputPath, UserConfig } from '../types'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Type guard to check if a given config has an `input.path`.
|
|
5
|
+
*/
|
|
6
|
+
export function isInputPath(config: UserConfig | undefined): config is UserConfig<InputPath>
|
|
7
|
+
export function isInputPath(config: Config | undefined): config is Config<InputPath>
|
|
8
|
+
export function isInputPath(config: Config | UserConfig | undefined): config is Config<InputPath> | UserConfig<InputPath> {
|
|
9
|
+
return typeof config?.input === 'object' && config.input !== null && 'path' in config.input
|
|
10
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { findPackageJSON, readSync } from '@internals/utils'
|
|
2
|
+
import { coerce, satisfies } from 'semver'
|
|
3
|
+
|
|
4
|
+
type PackageJSON = {
|
|
5
|
+
dependencies?: Record<string, string>
|
|
6
|
+
devDependencies?: Record<string, string>
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
type DependencyName = string
|
|
10
|
+
type DependencyVersion = string
|
|
11
|
+
|
|
12
|
+
function getPackageJSONSync(cwd?: string): PackageJSON | null {
|
|
13
|
+
const pkgPath = findPackageJSON(cwd)
|
|
14
|
+
if (!pkgPath) {
|
|
15
|
+
return null
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return JSON.parse(readSync(pkgPath)) as PackageJSON
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function match(packageJSON: PackageJSON, dependency: DependencyName | RegExp): string | null {
|
|
22
|
+
const dependencies = {
|
|
23
|
+
...(packageJSON.dependencies || {}),
|
|
24
|
+
...(packageJSON.devDependencies || {}),
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (typeof dependency === 'string' && dependencies[dependency]) {
|
|
28
|
+
return dependencies[dependency]
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const matched = Object.keys(dependencies).find((dep) => dep.match(dependency))
|
|
32
|
+
|
|
33
|
+
return matched ? (dependencies[matched] ?? null) : null
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function getVersionSync(dependency: DependencyName | RegExp, cwd?: string): DependencyVersion | null {
|
|
37
|
+
const packageJSON = getPackageJSONSync(cwd)
|
|
38
|
+
|
|
39
|
+
return packageJSON ? match(packageJSON, dependency) : null
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Returns `true` when the nearest `package.json` declares a dependency that
|
|
44
|
+
* satisfies the given semver range.
|
|
45
|
+
*
|
|
46
|
+
* - Searches both `dependencies` and `devDependencies`.
|
|
47
|
+
* - Accepts a string package name or a `RegExp` to match scoped/pattern packages.
|
|
48
|
+
* - Uses `semver.satisfies` for range comparison; returns `false` when the
|
|
49
|
+
* version string cannot be coerced into a valid semver.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```ts
|
|
53
|
+
* satisfiesDependency('react', '>=18') // true when react@18.x is installed
|
|
54
|
+
* satisfiesDependency(/^@tanstack\//, '>=5') // true when any @tanstack/* >=5 is found
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
export function satisfiesDependency(dependency: DependencyName | RegExp, version: DependencyVersion, cwd?: string): boolean {
|
|
58
|
+
const packageVersion = getVersionSync(dependency, cwd)
|
|
59
|
+
|
|
60
|
+
if (!packageVersion) {
|
|
61
|
+
return false
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (packageVersion === version) {
|
|
65
|
+
return true
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const semVer = coerce(packageVersion)
|
|
69
|
+
|
|
70
|
+
if (!semVer) {
|
|
71
|
+
return false
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return satisfies(semVer, version)
|
|
75
|
+
}
|
package/dist/chunk-ByKO4r7w.cjs
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
//#region \0rolldown/runtime.js
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __name = (target, value) => __defProp(target, "name", {
|
|
5
|
-
value,
|
|
6
|
-
configurable: true
|
|
7
|
-
});
|
|
8
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
9
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
10
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
11
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
14
|
-
key = keys[i];
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
16
|
-
get: ((k) => from[k]).bind(null, key),
|
|
17
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
return to;
|
|
21
|
-
};
|
|
22
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
23
|
-
value: mod,
|
|
24
|
-
enumerable: true
|
|
25
|
-
}) : target, mod));
|
|
26
|
-
//#endregion
|
|
27
|
-
Object.defineProperty(exports, "__name", {
|
|
28
|
-
enumerable: true,
|
|
29
|
-
get: function() {
|
|
30
|
-
return __name;
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
Object.defineProperty(exports, "__toESM", {
|
|
34
|
-
enumerable: true,
|
|
35
|
-
get: function() {
|
|
36
|
-
return __toESM;
|
|
37
|
-
}
|
|
38
|
-
});
|
package/dist/hooks.cjs
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
require("./chunk-ByKO4r7w.cjs");
|
|
3
|
-
let _kubb_react_fabric = require("@kubb/react-fabric");
|
|
4
|
-
//#region src/hooks/useKubb.ts
|
|
5
|
-
function useKubb() {
|
|
6
|
-
const { meta } = (0, _kubb_react_fabric.useApp)();
|
|
7
|
-
return {
|
|
8
|
-
plugin: meta.plugin,
|
|
9
|
-
mode: meta.mode,
|
|
10
|
-
config: meta.pluginManager.config,
|
|
11
|
-
getPluginByName: meta.pluginManager.getPluginByName.bind(meta.pluginManager),
|
|
12
|
-
getFile: meta.pluginManager.getFile.bind(meta.pluginManager),
|
|
13
|
-
resolveName: meta.pluginManager.resolveName.bind(meta.pluginManager),
|
|
14
|
-
resolvePath: meta.pluginManager.resolvePath.bind(meta.pluginManager)
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
//#endregion
|
|
18
|
-
//#region src/hooks/useMode.ts
|
|
19
|
-
/**
|
|
20
|
-
* @deprecated use `useKubb` instead
|
|
21
|
-
*/
|
|
22
|
-
function useMode() {
|
|
23
|
-
const { meta } = (0, _kubb_react_fabric.useApp)();
|
|
24
|
-
return meta.mode;
|
|
25
|
-
}
|
|
26
|
-
//#endregion
|
|
27
|
-
//#region src/hooks/usePlugin.ts
|
|
28
|
-
/**
|
|
29
|
-
* @deprecated use useApp instead
|
|
30
|
-
*/
|
|
31
|
-
function usePlugin() {
|
|
32
|
-
const { meta } = (0, _kubb_react_fabric.useApp)();
|
|
33
|
-
return meta.plugin;
|
|
34
|
-
}
|
|
35
|
-
//#endregion
|
|
36
|
-
//#region src/hooks/usePluginManager.ts
|
|
37
|
-
/**
|
|
38
|
-
* @deprecated use `useKubb` instead
|
|
39
|
-
*/
|
|
40
|
-
function usePluginManager() {
|
|
41
|
-
const { meta } = (0, _kubb_react_fabric.useApp)();
|
|
42
|
-
return meta.pluginManager;
|
|
43
|
-
}
|
|
44
|
-
//#endregion
|
|
45
|
-
exports.useKubb = useKubb;
|
|
46
|
-
exports.useMode = useMode;
|
|
47
|
-
exports.usePlugin = usePlugin;
|
|
48
|
-
exports.usePluginManager = usePluginManager;
|
|
49
|
-
|
|
50
|
-
//# sourceMappingURL=hooks.cjs.map
|
package/dist/hooks.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.cjs","names":[],"sources":["../src/hooks/useKubb.ts","../src/hooks/useMode.ts","../src/hooks/usePlugin.ts","../src/hooks/usePluginManager.ts"],"sourcesContent":["import type { KubbFile } from '@kubb/fabric-core/types'\nimport { useApp as useAppBase } from '@kubb/react-fabric'\nimport type { PluginManager } from '../PluginManager.ts'\nimport type { Plugin, PluginFactoryOptions } from '../types.ts'\n\nexport function useKubb<TOptions extends PluginFactoryOptions = PluginFactoryOptions>() {\n const { meta } = useAppBase<{\n plugin: Plugin<TOptions>\n mode: KubbFile.Mode\n pluginManager: PluginManager\n }>()\n\n return {\n plugin: meta.plugin as Plugin<TOptions>,\n mode: meta.mode,\n config: meta.pluginManager.config,\n getPluginByName: meta.pluginManager.getPluginByName.bind(meta.pluginManager),\n getFile: meta.pluginManager.getFile.bind(meta.pluginManager),\n resolveName: meta.pluginManager.resolveName.bind(meta.pluginManager),\n resolvePath: meta.pluginManager.resolvePath.bind(meta.pluginManager),\n }\n}\n","import type { KubbFile } from '@kubb/fabric-core/types'\nimport { useApp } from '@kubb/react-fabric'\n\n/**\n * @deprecated use `useKubb` instead\n */\nexport function useMode(): KubbFile.Mode {\n const { meta } = useApp<{ mode: KubbFile.Mode }>()\n\n return meta.mode\n}\n","import { useApp } from '@kubb/react-fabric'\nimport type { Plugin, PluginFactoryOptions } from '../types.ts'\n\n/**\n * @deprecated use useApp instead\n */\nexport function usePlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions>(): Plugin<TOptions> {\n const { meta } = useApp<{ plugin: Plugin<TOptions> }>()\n\n return meta.plugin\n}\n","import { useApp } from '@kubb/react-fabric'\nimport type { PluginManager } from '../PluginManager.ts'\n\n/**\n * @deprecated use `useKubb` instead\n */\nexport function usePluginManager(): PluginManager {\n const { meta } = useApp<{ pluginManager: PluginManager }>()\n\n return meta.pluginManager\n}\n"],"mappings":";;;;AAKA,SAAgB,UAAwE;CACtF,MAAM,EAAE,UAAA,GAAA,mBAAA,SAIJ;AAEJ,QAAO;EACL,QAAQ,KAAK;EACb,MAAM,KAAK;EACX,QAAQ,KAAK,cAAc;EAC3B,iBAAiB,KAAK,cAAc,gBAAgB,KAAK,KAAK,cAAc;EAC5E,SAAS,KAAK,cAAc,QAAQ,KAAK,KAAK,cAAc;EAC5D,aAAa,KAAK,cAAc,YAAY,KAAK,KAAK,cAAc;EACpE,aAAa,KAAK,cAAc,YAAY,KAAK,KAAK,cAAc;EACrE;;;;;;;ACdH,SAAgB,UAAyB;CACvC,MAAM,EAAE,UAAA,GAAA,mBAAA,SAA0C;AAElD,QAAO,KAAK;;;;;;;ACHd,SAAgB,YAA4F;CAC1G,MAAM,EAAE,UAAA,GAAA,mBAAA,SAA+C;AAEvD,QAAO,KAAK;;;;;;;ACHd,SAAgB,mBAAkC;CAChD,MAAM,EAAE,UAAA,GAAA,mBAAA,SAAmD;AAE3D,QAAO,KAAK"}
|
package/dist/hooks.d.ts
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { t as __name } from "./chunk--u3MIqq1.js";
|
|
2
|
-
import { I as PluginManager, T as ResolvePathParams, _ as PluginFactoryOptions, a as Config, h as Plugin, w as ResolveNameParams } from "./types-Bbh1o0yW.js";
|
|
3
|
-
import { KubbFile } from "@kubb/fabric-core/types";
|
|
4
|
-
|
|
5
|
-
//#region src/hooks/useKubb.d.ts
|
|
6
|
-
declare function useKubb<TOptions extends PluginFactoryOptions = PluginFactoryOptions>(): {
|
|
7
|
-
plugin: Plugin<TOptions>;
|
|
8
|
-
mode: KubbFile.Mode;
|
|
9
|
-
config: Config;
|
|
10
|
-
getPluginByName: (pluginName: string) => Plugin | undefined;
|
|
11
|
-
getFile: <TOptions_1 = object>({
|
|
12
|
-
name,
|
|
13
|
-
mode,
|
|
14
|
-
extname,
|
|
15
|
-
pluginName,
|
|
16
|
-
options
|
|
17
|
-
}: {
|
|
18
|
-
name: string;
|
|
19
|
-
mode?: KubbFile.Mode;
|
|
20
|
-
extname: KubbFile.Extname;
|
|
21
|
-
pluginName: string;
|
|
22
|
-
options?: TOptions_1 | undefined;
|
|
23
|
-
}) => KubbFile.File<{
|
|
24
|
-
pluginName: string;
|
|
25
|
-
}>;
|
|
26
|
-
resolveName: (params: ResolveNameParams) => string;
|
|
27
|
-
resolvePath: <TOptions_1 = object>(params: ResolvePathParams<TOptions_1>) => KubbFile.Path;
|
|
28
|
-
};
|
|
29
|
-
//#endregion
|
|
30
|
-
//#region src/hooks/useMode.d.ts
|
|
31
|
-
/**
|
|
32
|
-
* @deprecated use `useKubb` instead
|
|
33
|
-
*/
|
|
34
|
-
declare function useMode(): KubbFile.Mode;
|
|
35
|
-
//#endregion
|
|
36
|
-
//#region src/hooks/usePlugin.d.ts
|
|
37
|
-
/**
|
|
38
|
-
* @deprecated use useApp instead
|
|
39
|
-
*/
|
|
40
|
-
declare function usePlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions>(): Plugin<TOptions>;
|
|
41
|
-
//#endregion
|
|
42
|
-
//#region src/hooks/usePluginManager.d.ts
|
|
43
|
-
/**
|
|
44
|
-
* @deprecated use `useKubb` instead
|
|
45
|
-
*/
|
|
46
|
-
declare function usePluginManager(): PluginManager;
|
|
47
|
-
//#endregion
|
|
48
|
-
export { useKubb, useMode, usePlugin, usePluginManager };
|
|
49
|
-
//# sourceMappingURL=hooks.d.ts.map
|
package/dist/hooks.js
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import "./chunk--u3MIqq1.js";
|
|
2
|
-
import { useApp } from "@kubb/react-fabric";
|
|
3
|
-
//#region src/hooks/useKubb.ts
|
|
4
|
-
function useKubb() {
|
|
5
|
-
const { meta } = useApp();
|
|
6
|
-
return {
|
|
7
|
-
plugin: meta.plugin,
|
|
8
|
-
mode: meta.mode,
|
|
9
|
-
config: meta.pluginManager.config,
|
|
10
|
-
getPluginByName: meta.pluginManager.getPluginByName.bind(meta.pluginManager),
|
|
11
|
-
getFile: meta.pluginManager.getFile.bind(meta.pluginManager),
|
|
12
|
-
resolveName: meta.pluginManager.resolveName.bind(meta.pluginManager),
|
|
13
|
-
resolvePath: meta.pluginManager.resolvePath.bind(meta.pluginManager)
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
//#endregion
|
|
17
|
-
//#region src/hooks/useMode.ts
|
|
18
|
-
/**
|
|
19
|
-
* @deprecated use `useKubb` instead
|
|
20
|
-
*/
|
|
21
|
-
function useMode() {
|
|
22
|
-
const { meta } = useApp();
|
|
23
|
-
return meta.mode;
|
|
24
|
-
}
|
|
25
|
-
//#endregion
|
|
26
|
-
//#region src/hooks/usePlugin.ts
|
|
27
|
-
/**
|
|
28
|
-
* @deprecated use useApp instead
|
|
29
|
-
*/
|
|
30
|
-
function usePlugin() {
|
|
31
|
-
const { meta } = useApp();
|
|
32
|
-
return meta.plugin;
|
|
33
|
-
}
|
|
34
|
-
//#endregion
|
|
35
|
-
//#region src/hooks/usePluginManager.ts
|
|
36
|
-
/**
|
|
37
|
-
* @deprecated use `useKubb` instead
|
|
38
|
-
*/
|
|
39
|
-
function usePluginManager() {
|
|
40
|
-
const { meta } = useApp();
|
|
41
|
-
return meta.pluginManager;
|
|
42
|
-
}
|
|
43
|
-
//#endregion
|
|
44
|
-
export { useKubb, useMode, usePlugin, usePluginManager };
|
|
45
|
-
|
|
46
|
-
//# sourceMappingURL=hooks.js.map
|
package/dist/hooks.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.js","names":["useAppBase"],"sources":["../src/hooks/useKubb.ts","../src/hooks/useMode.ts","../src/hooks/usePlugin.ts","../src/hooks/usePluginManager.ts"],"sourcesContent":["import type { KubbFile } from '@kubb/fabric-core/types'\nimport { useApp as useAppBase } from '@kubb/react-fabric'\nimport type { PluginManager } from '../PluginManager.ts'\nimport type { Plugin, PluginFactoryOptions } from '../types.ts'\n\nexport function useKubb<TOptions extends PluginFactoryOptions = PluginFactoryOptions>() {\n const { meta } = useAppBase<{\n plugin: Plugin<TOptions>\n mode: KubbFile.Mode\n pluginManager: PluginManager\n }>()\n\n return {\n plugin: meta.plugin as Plugin<TOptions>,\n mode: meta.mode,\n config: meta.pluginManager.config,\n getPluginByName: meta.pluginManager.getPluginByName.bind(meta.pluginManager),\n getFile: meta.pluginManager.getFile.bind(meta.pluginManager),\n resolveName: meta.pluginManager.resolveName.bind(meta.pluginManager),\n resolvePath: meta.pluginManager.resolvePath.bind(meta.pluginManager),\n }\n}\n","import type { KubbFile } from '@kubb/fabric-core/types'\nimport { useApp } from '@kubb/react-fabric'\n\n/**\n * @deprecated use `useKubb` instead\n */\nexport function useMode(): KubbFile.Mode {\n const { meta } = useApp<{ mode: KubbFile.Mode }>()\n\n return meta.mode\n}\n","import { useApp } from '@kubb/react-fabric'\nimport type { Plugin, PluginFactoryOptions } from '../types.ts'\n\n/**\n * @deprecated use useApp instead\n */\nexport function usePlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions>(): Plugin<TOptions> {\n const { meta } = useApp<{ plugin: Plugin<TOptions> }>()\n\n return meta.plugin\n}\n","import { useApp } from '@kubb/react-fabric'\nimport type { PluginManager } from '../PluginManager.ts'\n\n/**\n * @deprecated use `useKubb` instead\n */\nexport function usePluginManager(): PluginManager {\n const { meta } = useApp<{ pluginManager: PluginManager }>()\n\n return meta.pluginManager\n}\n"],"mappings":";;;AAKA,SAAgB,UAAwE;CACtF,MAAM,EAAE,SAASA,QAIb;AAEJ,QAAO;EACL,QAAQ,KAAK;EACb,MAAM,KAAK;EACX,QAAQ,KAAK,cAAc;EAC3B,iBAAiB,KAAK,cAAc,gBAAgB,KAAK,KAAK,cAAc;EAC5E,SAAS,KAAK,cAAc,QAAQ,KAAK,KAAK,cAAc;EAC5D,aAAa,KAAK,cAAc,YAAY,KAAK,KAAK,cAAc;EACpE,aAAa,KAAK,cAAc,YAAY,KAAK,KAAK,cAAc;EACrE;;;;;;;ACdH,SAAgB,UAAyB;CACvC,MAAM,EAAE,SAAS,QAAiC;AAElD,QAAO,KAAK;;;;;;;ACHd,SAAgB,YAA4F;CAC1G,MAAM,EAAE,SAAS,QAAsC;AAEvD,QAAO,KAAK;;;;;;;ACHd,SAAgB,mBAAkC;CAChD,MAAM,EAAE,SAAS,QAA0C;AAE3D,QAAO,KAAK"}
|