@kubb/core 3.0.0-alpha.0 → 3.0.0-alpha.2
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/FileManager-BW--rO8q.d.ts +437 -0
- package/dist/FileManager-Bw-FNS3q.d.cts +437 -0
- package/dist/{chunk-XRC6KXC3.cjs → chunk-67C6RBGQ.cjs} +5 -5
- package/dist/{chunk-XRC6KXC3.cjs.map → chunk-67C6RBGQ.cjs.map} +1 -1
- package/dist/{chunk-Y3LLJA4H.cjs → chunk-ADC5UNZ5.cjs} +145 -145
- package/dist/{chunk-Y3LLJA4H.cjs.map → chunk-ADC5UNZ5.cjs.map} +1 -1
- package/dist/{chunk-XRUOSVKX.cjs → chunk-LM2YQC3T.cjs} +12 -12
- package/dist/{chunk-XRUOSVKX.cjs.map → chunk-LM2YQC3T.cjs.map} +1 -1
- package/dist/{chunk-DKW7IBJV.cjs → chunk-PZT4CTBV.cjs} +18 -18
- package/dist/{chunk-DKW7IBJV.cjs.map → chunk-PZT4CTBV.cjs.map} +1 -1
- package/dist/{chunk-LKXUCYWU.cjs → chunk-XCPFG6DO.cjs} +3 -3
- package/dist/chunk-XCPFG6DO.cjs.map +1 -0
- package/dist/{chunk-OPOT6TCT.cjs → chunk-YTSNYMHW.cjs} +28 -28
- package/dist/{chunk-OPOT6TCT.cjs.map → chunk-YTSNYMHW.cjs.map} +1 -1
- package/dist/index.cjs +152 -196
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +10 -465
- package/dist/index.d.ts +10 -465
- package/dist/index.js +11 -55
- package/dist/index.js.map +1 -1
- package/dist/logger.cjs +3 -3
- package/dist/mocks.cjs +8 -8
- package/dist/mocks.d.cts +1 -1
- package/dist/mocks.d.ts +1 -1
- package/dist/transformers.cjs +4 -4
- package/dist/utils.cjs +4 -4
- package/package.json +9 -12
- package/src/PluginManager.ts +10 -19
- package/src/build.ts +3 -52
- package/src/index.ts +0 -3
- package/src/plugin.ts +1 -1
- package/src/types.ts +12 -37
- package/dist/chunk-LKXUCYWU.cjs.map +0 -1
- package/globals.d.ts +0 -49
- package/src/kubb.ts +0 -11
package/dist/index.d.ts
CHANGED
|
@@ -1,467 +1,15 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
1
|
+
import { P as PluginContext, F as FileManager, a as PluginManager, U as UserConfig, C as Config, I as InputPath, b as PluginFactoryOptions, c as UserPluginWithLifeCycle } from './FileManager-BW--rO8q.js';
|
|
2
|
+
export { d as FileMetaBase, G as GetPluginFactoryOptions, e as InputData, h as Plugin, m as PluginCache, f as PluginKey, j as PluginLifecycle, k as PluginLifecycleHooks, l as PluginParameter, i as PluginWithLifeCycle, n as ResolveNameParams, R as ResolvePathParams, g as UserPlugin } from './FileManager-BW--rO8q.js';
|
|
3
|
+
import { L as Logger } from './logger-DChjnJMn.js';
|
|
4
|
+
import { PossiblePromise } from '@kubb/types';
|
|
5
|
+
import 'p-queue';
|
|
6
|
+
import '@kubb/fs';
|
|
7
|
+
import '@kubb/fs/types';
|
|
8
|
+
import '@kubb/fs/src/types.ts';
|
|
9
|
+
import 'directory-tree';
|
|
8
10
|
import 'consola';
|
|
9
11
|
import 'ora';
|
|
10
12
|
|
|
11
|
-
type BarrelManagerOptions = {
|
|
12
|
-
treeNode?: DirectoryTreeOptions;
|
|
13
|
-
isTypeOnly?: boolean;
|
|
14
|
-
/**
|
|
15
|
-
* Add .ts or .js
|
|
16
|
-
*/
|
|
17
|
-
extName?: KubbFile.Extname;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
type RequiredPluginLifecycle = Required<PluginLifecycle>;
|
|
21
|
-
/**
|
|
22
|
-
* Get the type of the first argument in a function.
|
|
23
|
-
* @example Arg0<(a: string, b: number) => void> -> string
|
|
24
|
-
*/
|
|
25
|
-
type Argument0<H extends keyof PluginLifecycle> = Parameters<RequiredPluginLifecycle[H]>[0];
|
|
26
|
-
type Strategy$1 = 'hookFirst' | 'hookForPlugin' | 'hookParallel' | 'hookReduceArg0' | 'hookSeq';
|
|
27
|
-
type Executer<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
|
|
28
|
-
strategy: Strategy$1;
|
|
29
|
-
hookName: H;
|
|
30
|
-
plugin: Plugin;
|
|
31
|
-
parameters?: unknown[] | undefined;
|
|
32
|
-
output?: unknown;
|
|
33
|
-
};
|
|
34
|
-
type ParseResult<H extends PluginLifecycleHooks> = RequiredPluginLifecycle[H];
|
|
35
|
-
type SafeParseResult<H extends PluginLifecycleHooks, Result = ReturnType<ParseResult<H>>> = {
|
|
36
|
-
result: Result;
|
|
37
|
-
plugin: Plugin;
|
|
38
|
-
};
|
|
39
|
-
type Options$2 = {
|
|
40
|
-
logger: Logger;
|
|
41
|
-
/**
|
|
42
|
-
* Task for the FileManager
|
|
43
|
-
*/
|
|
44
|
-
task: (file: ResolvedFile) => Promise<ResolvedFile>;
|
|
45
|
-
};
|
|
46
|
-
type Events = {
|
|
47
|
-
execute: [executer: Executer];
|
|
48
|
-
executed: [executer: Executer];
|
|
49
|
-
error: [error: Error];
|
|
50
|
-
};
|
|
51
|
-
type GetFileProps<TOptions = object> = {
|
|
52
|
-
name: string;
|
|
53
|
-
mode?: KubbFile.Mode;
|
|
54
|
-
extName: KubbFile.Extname;
|
|
55
|
-
pluginKey: Plugin['key'];
|
|
56
|
-
options?: TOptions;
|
|
57
|
-
};
|
|
58
|
-
declare class PluginManager {
|
|
59
|
-
#private;
|
|
60
|
-
readonly plugins: PluginWithLifeCycle[];
|
|
61
|
-
readonly fileManager: FileManager;
|
|
62
|
-
readonly events: EventEmitter<Events>;
|
|
63
|
-
readonly config: Config;
|
|
64
|
-
readonly executed: Array<Executer>;
|
|
65
|
-
readonly logger: Logger;
|
|
66
|
-
readonly queue: PQueue;
|
|
67
|
-
constructor(config: Config, options: Options$2);
|
|
68
|
-
getFile<TOptions = object>({ name, mode, extName, pluginKey, options }: GetFileProps<TOptions>): KubbFile.File<{
|
|
69
|
-
pluginKey: Plugin['key'];
|
|
70
|
-
}>;
|
|
71
|
-
resolvePath: <TOptions = object>(params: ResolvePathParams<TOptions>) => KubbFile.OptionalPath;
|
|
72
|
-
resolveName: (params: ResolveNameParams) => string;
|
|
73
|
-
/**
|
|
74
|
-
* Instead of calling `pluginManager.events.on` you can use `pluginManager.on`. This one also has better types.
|
|
75
|
-
*/
|
|
76
|
-
on<TEventName extends keyof Events & string>(eventName: TEventName, handler: (...eventArg: Events[TEventName]) => void): void;
|
|
77
|
-
/**
|
|
78
|
-
* Run a specific hookName for plugin x.
|
|
79
|
-
*/
|
|
80
|
-
hookForPlugin<H extends PluginLifecycleHooks>({ pluginKey, hookName, parameters, }: {
|
|
81
|
-
pluginKey: Plugin['key'];
|
|
82
|
-
hookName: H;
|
|
83
|
-
parameters: PluginParameter<H>;
|
|
84
|
-
}): Promise<Array<ReturnType<ParseResult<H>> | null>> | null;
|
|
85
|
-
/**
|
|
86
|
-
* Run a specific hookName for plugin x.
|
|
87
|
-
*/
|
|
88
|
-
hookForPluginSync<H extends PluginLifecycleHooks>({ pluginKey, hookName, parameters, }: {
|
|
89
|
-
pluginKey: Plugin['key'];
|
|
90
|
-
hookName: H;
|
|
91
|
-
parameters: PluginParameter<H>;
|
|
92
|
-
}): Array<ReturnType<ParseResult<H>>> | null;
|
|
93
|
-
/**
|
|
94
|
-
* First non-null result stops and will return it's value.
|
|
95
|
-
*/
|
|
96
|
-
hookFirst<H extends PluginLifecycleHooks>({ hookName, parameters, skipped, }: {
|
|
97
|
-
hookName: H;
|
|
98
|
-
parameters: PluginParameter<H>;
|
|
99
|
-
skipped?: ReadonlySet<Plugin> | null;
|
|
100
|
-
}): Promise<SafeParseResult<H>>;
|
|
101
|
-
/**
|
|
102
|
-
* First non-null result stops and will return it's value.
|
|
103
|
-
*/
|
|
104
|
-
hookFirstSync<H extends PluginLifecycleHooks>({ hookName, parameters, skipped, }: {
|
|
105
|
-
hookName: H;
|
|
106
|
-
parameters: PluginParameter<H>;
|
|
107
|
-
skipped?: ReadonlySet<Plugin> | null;
|
|
108
|
-
}): SafeParseResult<H>;
|
|
109
|
-
/**
|
|
110
|
-
* Run all plugins in parallel(order will be based on `this.plugin` and if `pre` or `post` is set).
|
|
111
|
-
*/
|
|
112
|
-
hookParallel<H extends PluginLifecycleHooks, TOuput = void>({ hookName, parameters, }: {
|
|
113
|
-
hookName: H;
|
|
114
|
-
parameters?: Parameters<RequiredPluginLifecycle[H]> | undefined;
|
|
115
|
-
}): Promise<Awaited<TOuput>[]>;
|
|
116
|
-
/**
|
|
117
|
-
* Chain all plugins, `reduce` can be passed through to handle every returned value. The return value of the first plugin will be used as the first parameter for the plugin after that.
|
|
118
|
-
*/
|
|
119
|
-
hookReduceArg0<H extends PluginLifecycleHooks>({ hookName, parameters, reduce, }: {
|
|
120
|
-
hookName: H;
|
|
121
|
-
parameters: PluginParameter<H>;
|
|
122
|
-
reduce: (reduction: Argument0<H>, result: ReturnType<ParseResult<H>>, plugin: Plugin) => PossiblePromise<Argument0<H> | null>;
|
|
123
|
-
}): Promise<Argument0<H>>;
|
|
124
|
-
/**
|
|
125
|
-
* Chains plugins
|
|
126
|
-
*/
|
|
127
|
-
hookSeq<H extends PluginLifecycleHooks>({ hookName, parameters }: {
|
|
128
|
-
hookName: H;
|
|
129
|
-
parameters?: PluginParameter<H>;
|
|
130
|
-
}): Promise<void>;
|
|
131
|
-
getPluginsByKey(hookName: keyof PluginLifecycle, pluginKey: Plugin['key']): Plugin[];
|
|
132
|
-
static getDependedPlugins<T1 extends PluginFactoryOptions, T2 extends PluginFactoryOptions = never, T3 extends PluginFactoryOptions = never, TOutput = T3 extends never ? (T2 extends never ? [T1: Plugin<T1>] : [T1: Plugin<T1>, T2: Plugin<T2>]) : [T1: Plugin<T1>, T2: Plugin<T2>, T3: Plugin<T3>]>(plugins: Array<Plugin>, dependedPluginNames: string | string[]): TOutput;
|
|
133
|
-
static get hooks(): readonly ["buildStart", "resolvePath", "resolveName", "load", "transform", "writeFile", "buildEnd"];
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
type Plugins = _Register;
|
|
137
|
-
type OptionsPlugins = {
|
|
138
|
-
[K in keyof Plugins]: Plugins[K]['options'];
|
|
139
|
-
};
|
|
140
|
-
type PluginUnion = TupleToUnion<ObjValueTuple<OptionsPlugins>>;
|
|
141
|
-
|
|
142
|
-
interface Cache<TStore extends object = object> {
|
|
143
|
-
delete(id: keyof TStore): boolean;
|
|
144
|
-
get(id: keyof TStore): TStore[keyof TStore] | null;
|
|
145
|
-
has(id: keyof TStore): boolean;
|
|
146
|
-
set(id: keyof TStore, value: unknown): void;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
* Config used in `kubb.config.js`
|
|
151
|
-
*
|
|
152
|
-
* @example import { defineConfig } from '@kubb/core'
|
|
153
|
-
* export default defineConfig({
|
|
154
|
-
* ...
|
|
155
|
-
* })
|
|
156
|
-
*/
|
|
157
|
-
type UserConfig = Omit<Config, 'root' | 'plugins'> & {
|
|
158
|
-
/**
|
|
159
|
-
* Project root directory. Can be an absolute path, or a path relative from
|
|
160
|
-
* the location of the config file itself.
|
|
161
|
-
* @default process.cwd()
|
|
162
|
-
*/
|
|
163
|
-
root?: string;
|
|
164
|
-
/**
|
|
165
|
-
* Plugin type can be KubbJSONPlugin or Plugin
|
|
166
|
-
* Example: ['@kubb/plugin-oas', { output: false }]
|
|
167
|
-
* Or: pluginOas({ output: false })
|
|
168
|
-
*/
|
|
169
|
-
plugins?: Array<Omit<UnknownUserPlugin, 'api'> | UnionPlugins | [name: string, options: object]>;
|
|
170
|
-
};
|
|
171
|
-
type InputPath = {
|
|
172
|
-
/**
|
|
173
|
-
* Path to be used as the input. This can be an absolute path or a path relative to the `root`.
|
|
174
|
-
*/
|
|
175
|
-
path: string;
|
|
176
|
-
};
|
|
177
|
-
type InputData = {
|
|
178
|
-
/**
|
|
179
|
-
* `string` or `object` containing the data.
|
|
180
|
-
*/
|
|
181
|
-
data: string | unknown;
|
|
182
|
-
};
|
|
183
|
-
type Input = InputPath | InputData;
|
|
184
|
-
/**
|
|
185
|
-
* @private
|
|
186
|
-
*/
|
|
187
|
-
type Config<TInput = Input> = {
|
|
188
|
-
/**
|
|
189
|
-
* Optional config name to show in CLI output
|
|
190
|
-
*/
|
|
191
|
-
name?: string;
|
|
192
|
-
/**
|
|
193
|
-
* Project root directory. Can be an absolute path, or a path relative from
|
|
194
|
-
* the location of the config file itself.
|
|
195
|
-
* @default process.cwd()
|
|
196
|
-
*/
|
|
197
|
-
root: string;
|
|
198
|
-
input: TInput;
|
|
199
|
-
output: {
|
|
200
|
-
/**
|
|
201
|
-
* Path to be used to export all generated files.
|
|
202
|
-
* This can be an absolute path, or a path relative based of the defined `root` option.
|
|
203
|
-
*/
|
|
204
|
-
path: string;
|
|
205
|
-
/**
|
|
206
|
-
* Clean output directory before each build.
|
|
207
|
-
*/
|
|
208
|
-
clean?: boolean;
|
|
209
|
-
/**
|
|
210
|
-
* Write files to the fileSystem
|
|
211
|
-
* This is being used for the playground.
|
|
212
|
-
* @default true
|
|
213
|
-
*/
|
|
214
|
-
write?: boolean;
|
|
215
|
-
};
|
|
216
|
-
/**
|
|
217
|
-
* Array of Kubb plugins to use.
|
|
218
|
-
* The plugin/package can forsee some options that you need to pass through.
|
|
219
|
-
* Sometimes a plugin is depended on another plugin, if that's the case you will get an error back from the plugin you installed.
|
|
220
|
-
*/
|
|
221
|
-
plugins?: Array<Plugin>;
|
|
222
|
-
/**
|
|
223
|
-
* Hooks that will be called when a specific action is triggered in Kubb.
|
|
224
|
-
*/
|
|
225
|
-
hooks?: {
|
|
226
|
-
/**
|
|
227
|
-
* Hook that will be triggered at the end of all executions.
|
|
228
|
-
* Useful for running Prettier or ESLint to format/lint your code.
|
|
229
|
-
*/
|
|
230
|
-
done?: string | Array<string>;
|
|
231
|
-
};
|
|
232
|
-
};
|
|
233
|
-
type UnionPlugins = PluginUnion;
|
|
234
|
-
type ObjectPlugin = keyof OptionsPlugins;
|
|
235
|
-
type PluginFactoryOptions<
|
|
236
|
-
/**
|
|
237
|
-
* Name to be used for the plugin, this will also be used for they key.
|
|
238
|
-
*/
|
|
239
|
-
TName extends string = string,
|
|
240
|
-
/**
|
|
241
|
-
* Options of the plugin.
|
|
242
|
-
*/
|
|
243
|
-
TOptions extends object = object,
|
|
244
|
-
/**
|
|
245
|
-
* Options of the plugin that can be used later on, see `options` inside your plugin config.
|
|
246
|
-
*/
|
|
247
|
-
TResolvedOptions extends object = TOptions,
|
|
248
|
-
/**
|
|
249
|
-
* API that you want to expose to other plugins.
|
|
250
|
-
*/
|
|
251
|
-
TAPI = any,
|
|
252
|
-
/**
|
|
253
|
-
* When calling `resolvePath` you can specify better types.
|
|
254
|
-
*/
|
|
255
|
-
TResolvePathOptions extends object = object> = {
|
|
256
|
-
name: TName;
|
|
257
|
-
/**
|
|
258
|
-
* Same behaviour like what has been done with `QueryKey` in `@tanstack/react-query`
|
|
259
|
-
*/
|
|
260
|
-
key: PluginKey<TName | string>;
|
|
261
|
-
options: TOptions;
|
|
262
|
-
resolvedOptions: TResolvedOptions;
|
|
263
|
-
api: TAPI;
|
|
264
|
-
resolvePathOptions: TResolvePathOptions;
|
|
265
|
-
};
|
|
266
|
-
type PluginKey<TName> = [name: TName, identifier?: string | number];
|
|
267
|
-
type GetPluginFactoryOptions<TPlugin extends UserPlugin> = TPlugin extends UserPlugin<infer X> ? X : never;
|
|
268
|
-
type UserPlugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
269
|
-
/**
|
|
270
|
-
* Unique name used for the plugin
|
|
271
|
-
* The name of the plugin follows the format scope:foo-bar or foo-bar, adding scope: can avoid naming conflicts with other plugins.
|
|
272
|
-
* @example @kubb/typescript
|
|
273
|
-
*/
|
|
274
|
-
name: TOptions['name'];
|
|
275
|
-
/**
|
|
276
|
-
* Options set for a specific plugin(see kubb.config.js), passthrough of options.
|
|
277
|
-
*/
|
|
278
|
-
options: TOptions['resolvedOptions'];
|
|
279
|
-
/**
|
|
280
|
-
* Specifies the preceding plugins for the current plugin. You can pass an array of preceding plugin names, and the current plugin will be executed after these plugins.
|
|
281
|
-
* Can be used to validate depended plugins.
|
|
282
|
-
*/
|
|
283
|
-
pre?: Array<string>;
|
|
284
|
-
/**
|
|
285
|
-
* Specifies the succeeding plugins for the current plugin. You can pass an array of succeeding plugin names, and the current plugin will be executed before these plugins.
|
|
286
|
-
*/
|
|
287
|
-
post?: Array<string>;
|
|
288
|
-
} & (TOptions['api'] extends never ? {
|
|
289
|
-
api?: never;
|
|
290
|
-
} : {
|
|
291
|
-
api: (this: TOptions['name'] extends 'core' ? null : Omit<PluginContext<TOptions>, 'addFile'>) => TOptions['api'];
|
|
292
|
-
});
|
|
293
|
-
type UserPluginWithLifeCycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = UserPlugin<TOptions> & PluginLifecycle<TOptions>;
|
|
294
|
-
type UnknownUserPlugin = UserPlugin<PluginFactoryOptions<any, any, any, any, any>>;
|
|
295
|
-
type Plugin<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
296
|
-
/**
|
|
297
|
-
* Unique name used for the plugin
|
|
298
|
-
* @example @kubb/typescript
|
|
299
|
-
*/
|
|
300
|
-
name: TOptions['name'];
|
|
301
|
-
/**
|
|
302
|
-
* Internal key used when a developer uses more than one of the same plugin
|
|
303
|
-
* @private
|
|
304
|
-
*/
|
|
305
|
-
key: TOptions['key'];
|
|
306
|
-
/**
|
|
307
|
-
* Specifies the preceding plugins for the current plugin. You can pass an array of preceding plugin names, and the current plugin will be executed after these plugins.
|
|
308
|
-
* Can be used to validate depended plugins.
|
|
309
|
-
*/
|
|
310
|
-
pre?: Array<string>;
|
|
311
|
-
/**
|
|
312
|
-
* Specifies the succeeding plugins for the current plugin. You can pass an array of succeeding plugin names, and the current plugin will be executed before these plugins.
|
|
313
|
-
*/
|
|
314
|
-
post?: Array<string>;
|
|
315
|
-
/**
|
|
316
|
-
* Options set for a specific plugin(see kubb.config.js), passthrough of options.
|
|
317
|
-
*/
|
|
318
|
-
options: TOptions['resolvedOptions'];
|
|
319
|
-
} & (TOptions['api'] extends never ? {
|
|
320
|
-
api?: never;
|
|
321
|
-
} : {
|
|
322
|
-
api: TOptions['api'];
|
|
323
|
-
});
|
|
324
|
-
type PluginWithLifeCycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = Plugin<TOptions> & PluginLifecycle<TOptions>;
|
|
325
|
-
type PluginLifecycle<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
326
|
-
/**
|
|
327
|
-
* Start of the lifecycle of a plugin.
|
|
328
|
-
* @type hookParallel
|
|
329
|
-
*/
|
|
330
|
-
buildStart?: (this: PluginContext<TOptions>, Config: Config) => PossiblePromise<void>;
|
|
331
|
-
/**
|
|
332
|
-
* Resolve to a Path based on a baseName(example: `./Pet.ts`) and directory(example: `./models`).
|
|
333
|
-
* Options can als be included.
|
|
334
|
-
* @type hookFirst
|
|
335
|
-
* @example ('./Pet.ts', './src/gen/') => '/src/gen/Pet.ts'
|
|
336
|
-
*/
|
|
337
|
-
resolvePath?: (this: PluginContext<TOptions>, baseName: string, mode?: KubbFile.Mode, options?: TOptions['resolvePathOptions']) => KubbFile.OptionalPath;
|
|
338
|
-
/**
|
|
339
|
-
* Resolve to a name based on a string.
|
|
340
|
-
* Useful when converting to PascalCase or camelCase.
|
|
341
|
-
* @type hookFirst
|
|
342
|
-
* @example ('pet') => 'Pet'
|
|
343
|
-
*/
|
|
344
|
-
resolveName?: (this: PluginContext<TOptions>, name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
|
|
345
|
-
/**
|
|
346
|
-
* Makes it possible to run async logic to override the path defined previously by `resolvePath`.
|
|
347
|
-
* @type hookFirst
|
|
348
|
-
*/
|
|
349
|
-
load?: (this: Omit<PluginContext<TOptions>, 'addFile'>, path: KubbFile.Path) => PossiblePromise<TransformResult | null>;
|
|
350
|
-
/**
|
|
351
|
-
* Transform the source-code.
|
|
352
|
-
* @type hookReduceArg0
|
|
353
|
-
*/
|
|
354
|
-
transform?: (this: Omit<PluginContext<TOptions>, 'addFile'>, source: string, path: KubbFile.Path) => PossiblePromise<TransformResult>;
|
|
355
|
-
/**
|
|
356
|
-
* Write the result to the file-system based on the id(defined by `resolvePath` or changed by `load`).
|
|
357
|
-
* @type hookParallel
|
|
358
|
-
*/
|
|
359
|
-
writeFile?: (this: Omit<PluginContext<TOptions>, 'addFile'>, path: KubbFile.Path, source: string | undefined) => PossiblePromise<string | void>;
|
|
360
|
-
/**
|
|
361
|
-
* End of the plugin lifecycle.
|
|
362
|
-
* @type hookParallel
|
|
363
|
-
*/
|
|
364
|
-
buildEnd?: (this: PluginContext<TOptions>) => PossiblePromise<void>;
|
|
365
|
-
};
|
|
366
|
-
type PluginLifecycleHooks = keyof PluginLifecycle;
|
|
367
|
-
type PluginParameter<H extends PluginLifecycleHooks> = Parameters<Required<PluginLifecycle>[H]>;
|
|
368
|
-
type PluginCache = Record<string, [number, unknown]>;
|
|
369
|
-
type ResolvePathParams<TOptions = object> = {
|
|
370
|
-
pluginKey?: Plugin['key'];
|
|
371
|
-
baseName: string;
|
|
372
|
-
mode?: KubbFile.Mode;
|
|
373
|
-
/**
|
|
374
|
-
* Options to be passed to 'resolvePath' 3th parameter
|
|
375
|
-
*/
|
|
376
|
-
options?: TOptions;
|
|
377
|
-
};
|
|
378
|
-
type ResolveNameParams = {
|
|
379
|
-
name: string;
|
|
380
|
-
pluginKey?: Plugin['key'];
|
|
381
|
-
/**
|
|
382
|
-
* `file` will be used to customize the name of the created file(use of camelCase)
|
|
383
|
-
* `function` can be used used to customize the exported functions(use of camelCase)
|
|
384
|
-
* `type` is a special type for TypeScript(use of PascalCase)
|
|
385
|
-
*/
|
|
386
|
-
type?: 'file' | 'function' | 'type';
|
|
387
|
-
};
|
|
388
|
-
type PluginContext<TOptions extends PluginFactoryOptions = PluginFactoryOptions> = {
|
|
389
|
-
config: Config;
|
|
390
|
-
cache: Cache<PluginCache>;
|
|
391
|
-
fileManager: FileManager;
|
|
392
|
-
pluginManager: PluginManager;
|
|
393
|
-
addFile: (...file: Array<KubbFile.File>) => Promise<Array<KubbFile.File>>;
|
|
394
|
-
resolvePath: (params: ResolvePathParams<TOptions['resolvePathOptions']>) => KubbFile.OptionalPath;
|
|
395
|
-
resolveName: (params: ResolveNameParams) => string;
|
|
396
|
-
logger: Logger;
|
|
397
|
-
/**
|
|
398
|
-
* All plugins
|
|
399
|
-
*/
|
|
400
|
-
plugins: Plugin[];
|
|
401
|
-
/**
|
|
402
|
-
* Current plugin
|
|
403
|
-
*/
|
|
404
|
-
plugin: Plugin<TOptions>;
|
|
405
|
-
};
|
|
406
|
-
type TransformResult = string | null;
|
|
407
|
-
|
|
408
|
-
type ResolvedFile<TMeta extends FileMetaBase = FileMetaBase, TBaseName extends BaseName = BaseName> = File<TMeta, TBaseName> & {
|
|
409
|
-
/**
|
|
410
|
-
* @default crypto.randomUUID()
|
|
411
|
-
*/
|
|
412
|
-
id: UUID;
|
|
413
|
-
/**
|
|
414
|
-
* Contains the first part of the baseName, generated based on baseName
|
|
415
|
-
* @link https://nodejs.org/api/path.html#pathformatpathobject
|
|
416
|
-
*/
|
|
417
|
-
name: string;
|
|
418
|
-
};
|
|
419
|
-
type FileMetaBase = {
|
|
420
|
-
pluginKey?: Plugin['key'];
|
|
421
|
-
};
|
|
422
|
-
type FileWithMeta<TMeta extends FileMetaBase = FileMetaBase> = KubbFile.File<TMeta>;
|
|
423
|
-
type AddResult<T extends Array<FileWithMeta>> = Promise<Awaited<GreaterThan<T['length'], 1> extends true ? Promise<ResolvedFile[]> : Promise<ResolvedFile>>>;
|
|
424
|
-
type AddIndexesProps = {
|
|
425
|
-
/**
|
|
426
|
-
* Root based on root and output.path specified in the config
|
|
427
|
-
*/
|
|
428
|
-
root: string;
|
|
429
|
-
/**
|
|
430
|
-
* Output for plugin
|
|
431
|
-
*/
|
|
432
|
-
output: {
|
|
433
|
-
path: string;
|
|
434
|
-
exportAs?: string;
|
|
435
|
-
extName?: KubbFile.Extname;
|
|
436
|
-
exportType?: 'barrel' | 'barrelNamed' | false;
|
|
437
|
-
};
|
|
438
|
-
logger: Logger;
|
|
439
|
-
options?: BarrelManagerOptions;
|
|
440
|
-
meta?: FileWithMeta['meta'];
|
|
441
|
-
};
|
|
442
|
-
type Options$1 = {
|
|
443
|
-
queue?: PQueue;
|
|
444
|
-
task?: (file: ResolvedFile) => Promise<ResolvedFile>;
|
|
445
|
-
};
|
|
446
|
-
declare class FileManager {
|
|
447
|
-
#private;
|
|
448
|
-
constructor({ task, queue }?: Options$1);
|
|
449
|
-
get files(): Array<FileWithMeta>;
|
|
450
|
-
get isExecuting(): boolean;
|
|
451
|
-
add<T extends Array<FileWithMeta> = Array<FileWithMeta>>(...files: T): AddResult<T>;
|
|
452
|
-
addIndexes({ root, output, meta, logger, options }: AddIndexesProps): Promise<void>;
|
|
453
|
-
getCacheByUUID(UUID: KubbFile.UUID): FileWithMeta | undefined;
|
|
454
|
-
get(path: KubbFile.Path): Array<FileWithMeta> | undefined;
|
|
455
|
-
remove(path: KubbFile.Path): void;
|
|
456
|
-
write(...params: Parameters<typeof write>): Promise<string | undefined>;
|
|
457
|
-
read(...params: Parameters<typeof read>): Promise<string>;
|
|
458
|
-
static getSource<TMeta extends FileMetaBase = FileMetaBase>(file: FileWithMeta<TMeta>): Promise<string>;
|
|
459
|
-
static combineFiles<TMeta extends FileMetaBase = FileMetaBase>(files: Array<FileWithMeta<TMeta> | null>): Array<FileWithMeta<TMeta>>;
|
|
460
|
-
static getMode(path: string | undefined | null): KubbFile.Mode;
|
|
461
|
-
static get extensions(): Array<KubbFile.Extname>;
|
|
462
|
-
static isJavascript(baseName: string): boolean;
|
|
463
|
-
}
|
|
464
|
-
|
|
465
13
|
type BuildOptions = {
|
|
466
14
|
config: PluginContext['config'];
|
|
467
15
|
/**
|
|
@@ -582,7 +130,4 @@ declare class PromiseManager<TState = any> {
|
|
|
582
130
|
run<TInput extends Array<PromiseFunc<TValue, null>>, TValue, TStrategy extends Strategy, TOutput = StrategySwitch<TStrategy, TInput, TValue>>(strategy: TStrategy, promises: TInput): TOutput;
|
|
583
131
|
}
|
|
584
132
|
|
|
585
|
-
|
|
586
|
-
}
|
|
587
|
-
|
|
588
|
-
export { type Config, FileManager, type FileMetaBase, Generator, type GetPluginFactoryOptions, type InputData, type InputPath, type ObjectPlugin, PackageManager, type Plugin, type PluginCache, type PluginContext, type PluginFactoryOptions, type PluginKey, type PluginLifecycle, type PluginLifecycleHooks, PluginManager, type PluginParameter, type PluginWithLifeCycle, PromiseManager, type ResolveNameParams, type ResolvePathParams, type TransformResult, type UnionPlugins, type UserConfig, type UserPlugin, type UserPluginWithLifeCycle, Warning, type _Register, build, createPlugin, build as default, defineConfig, isInputPath, safeBuild };
|
|
133
|
+
export { Config, FileManager, Generator, InputPath, PackageManager, PluginContext, PluginFactoryOptions, PluginManager, PromiseManager, UserConfig, UserPluginWithLifeCycle, Warning, build, createPlugin, build as default, defineConfig, isInputPath, safeBuild };
|
package/dist/index.js
CHANGED
|
@@ -146,7 +146,7 @@ var pluginCore = createPlugin((options) => {
|
|
|
146
146
|
name: "core",
|
|
147
147
|
options,
|
|
148
148
|
key: ["core"],
|
|
149
|
-
|
|
149
|
+
context() {
|
|
150
150
|
return {
|
|
151
151
|
get config() {
|
|
152
152
|
return options.config;
|
|
@@ -261,9 +261,9 @@ Falling back on the first item.
|
|
|
261
261
|
resolveName: this.resolveName.bind(this),
|
|
262
262
|
getPlugins: __privateMethod(this, _PluginManager_instances, getSortedPlugins_fn).bind(this)
|
|
263
263
|
});
|
|
264
|
-
__privateSet(this, _core, __privateMethod(this, _PluginManager_instances, parse_fn).call(this, core, this, core.
|
|
264
|
+
__privateSet(this, _core, __privateMethod(this, _PluginManager_instances, parse_fn).call(this, core, this, core.context.call(null)));
|
|
265
265
|
this.plugins = [__privateGet(this, _core), ...plugins].map((plugin) => {
|
|
266
|
-
return __privateMethod(this, _PluginManager_instances, parse_fn).call(this, plugin, this, __privateGet(this, _core).
|
|
266
|
+
return __privateMethod(this, _PluginManager_instances, parse_fn).call(this, plugin, this, __privateGet(this, _core).context);
|
|
267
267
|
});
|
|
268
268
|
return this;
|
|
269
269
|
}
|
|
@@ -427,7 +427,7 @@ Falling back on the first item.
|
|
|
427
427
|
plugin
|
|
428
428
|
});
|
|
429
429
|
return value;
|
|
430
|
-
}).then((result) => reduce.call(__privateGet(this, _core).
|
|
430
|
+
}).then((result) => reduce.call(__privateGet(this, _core).context, argument0, result, plugin));
|
|
431
431
|
}
|
|
432
432
|
return promise;
|
|
433
433
|
}
|
|
@@ -484,7 +484,7 @@ Falling back on the first item.
|
|
|
484
484
|
});
|
|
485
485
|
}
|
|
486
486
|
static get hooks() {
|
|
487
|
-
return ["buildStart", "resolvePath", "resolveName", "
|
|
487
|
+
return ["buildStart", "resolvePath", "resolveName", "buildEnd"];
|
|
488
488
|
}
|
|
489
489
|
};
|
|
490
490
|
_core = new WeakMap();
|
|
@@ -547,7 +547,7 @@ execute_fn = function({
|
|
|
547
547
|
this.events.emit("execute", { strategy, hookName, parameters, plugin });
|
|
548
548
|
const task = Promise.resolve().then(() => {
|
|
549
549
|
if (typeof hook === "function") {
|
|
550
|
-
const possiblePromiseResult = hook.apply({ ...__privateGet(this, _core).
|
|
550
|
+
const possiblePromiseResult = hook.apply({ ...__privateGet(this, _core).context, plugin }, parameters);
|
|
551
551
|
if (isPromise(possiblePromiseResult)) {
|
|
552
552
|
return Promise.resolve(possiblePromiseResult);
|
|
553
553
|
}
|
|
@@ -591,7 +591,7 @@ executeSync_fn = function({
|
|
|
591
591
|
this.events.emit("execute", { strategy, hookName, parameters, plugin });
|
|
592
592
|
try {
|
|
593
593
|
if (typeof hook === "function") {
|
|
594
|
-
const fn = hook.apply({ ...__privateGet(this, _core).
|
|
594
|
+
const fn = hook.apply({ ...__privateGet(this, _core).context, plugin }, parameters);
|
|
595
595
|
output = fn;
|
|
596
596
|
return fn;
|
|
597
597
|
}
|
|
@@ -618,17 +618,11 @@ parse_fn = function(plugin, pluginManager, context) {
|
|
|
618
618
|
const usedPluginNames = __privateGet(pluginManager, _usedPluginNames);
|
|
619
619
|
setUniqueName(plugin.name, usedPluginNames);
|
|
620
620
|
const key = [plugin.name, usedPluginNames[plugin.name]].filter(Boolean);
|
|
621
|
-
if (
|
|
622
|
-
plugin.transform = function transform(_path, code) {
|
|
623
|
-
return code;
|
|
624
|
-
};
|
|
625
|
-
}
|
|
626
|
-
if (plugin.api && typeof plugin.api === "function") {
|
|
627
|
-
const api = plugin.api.call(context);
|
|
621
|
+
if (plugin.context && typeof plugin.context === "function") {
|
|
628
622
|
return {
|
|
629
623
|
...plugin,
|
|
630
624
|
key,
|
|
631
|
-
|
|
625
|
+
context: plugin.context.call(context)
|
|
632
626
|
};
|
|
633
627
|
}
|
|
634
628
|
return {
|
|
@@ -646,9 +640,6 @@ function isInputPath(result) {
|
|
|
646
640
|
}
|
|
647
641
|
|
|
648
642
|
// src/build.ts
|
|
649
|
-
async function transformReducer(_previousCode, result, _plugin) {
|
|
650
|
-
return result;
|
|
651
|
-
}
|
|
652
643
|
async function setup(options) {
|
|
653
644
|
const { config, logger = createLogger({ logLevel: LogLevel.silent }) } = options;
|
|
654
645
|
let count = 0;
|
|
@@ -671,35 +662,10 @@ async function setup(options) {
|
|
|
671
662
|
}
|
|
672
663
|
const task = async (file) => {
|
|
673
664
|
const { path: path2 } = file;
|
|
674
|
-
|
|
675
|
-
const { result: loadedResult } = await pluginManager.hookFirst({
|
|
676
|
-
hookName: "load",
|
|
677
|
-
parameters: [path2]
|
|
678
|
-
});
|
|
679
|
-
if (loadedResult && isPromise(loadedResult)) {
|
|
680
|
-
source = await loadedResult;
|
|
681
|
-
}
|
|
682
|
-
if (loadedResult && !isPromise(loadedResult)) {
|
|
683
|
-
source = loadedResult;
|
|
684
|
-
}
|
|
665
|
+
const source = await FileManager.getSource(file);
|
|
685
666
|
if (source) {
|
|
686
|
-
source = await pluginManager.hookReduceArg0({
|
|
687
|
-
hookName: "transform",
|
|
688
|
-
parameters: [path2, source],
|
|
689
|
-
reduce: transformReducer
|
|
690
|
-
});
|
|
691
667
|
if (config.output.write || config.output.write === void 0) {
|
|
692
|
-
|
|
693
|
-
await pluginManager.hookForPlugin({
|
|
694
|
-
pluginKey: file.meta?.pluginKey,
|
|
695
|
-
hookName: "writeFile",
|
|
696
|
-
parameters: [path2, source]
|
|
697
|
-
});
|
|
698
|
-
}
|
|
699
|
-
await pluginManager.hookFirst({
|
|
700
|
-
hookName: "writeFile",
|
|
701
|
-
parameters: [path2, source]
|
|
702
|
-
});
|
|
668
|
+
await pluginManager.fileManager.write(path2, source, { sanity: false });
|
|
703
669
|
}
|
|
704
670
|
}
|
|
705
671
|
return {
|
|
@@ -708,16 +674,6 @@ async function setup(options) {
|
|
|
708
674
|
};
|
|
709
675
|
};
|
|
710
676
|
const pluginManager = new PluginManager(config, { logger, task });
|
|
711
|
-
pluginManager.on("execute", (executer) => {
|
|
712
|
-
const { hookName, parameters, plugin } = executer;
|
|
713
|
-
if (hookName === "writeFile") {
|
|
714
|
-
const [code] = parameters;
|
|
715
|
-
logger.emit("debug", [`PluginKey ${p.dim(JSON.stringify(plugin.key))}
|
|
716
|
-
with source
|
|
717
|
-
|
|
718
|
-
${code}`]);
|
|
719
|
-
}
|
|
720
|
-
});
|
|
721
677
|
pluginManager.queue.on("add", () => {
|
|
722
678
|
if (logger.logLevel !== LogLevel.info) {
|
|
723
679
|
return;
|