@kubb/core 0.30.0 → 0.31.0

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/index.d.ts CHANGED
@@ -1,23 +1,6 @@
1
1
  import EventEmitter from 'events';
2
2
  import { DirectoryTreeOptions } from 'directory-tree';
3
3
 
4
- declare class TreeNode<T = unknown> {
5
- data: T;
6
- parent?: TreeNode<T>;
7
- children: Array<TreeNode<T>>;
8
- constructor(data: T, parent?: TreeNode<T>);
9
- addChild(data: T): any;
10
- find(data: T): any;
11
- leaves(): this[];
12
- root(): any;
13
- forEach(callback: (treeNode: TreeNode<T>) => void): this;
14
- static generate(path: string, options?: DirectoryTreeOptions): TreeNode<{
15
- name: string;
16
- path: string;
17
- type: "file" | "directory";
18
- }>;
19
- }
20
-
21
4
  /**
22
5
  * @deprecated Use userFile instead
23
6
  */
@@ -85,7 +68,23 @@ declare class FileManager {
85
68
  setStatus(id: UUID, status: Status): void;
86
69
  get(id: UUID): File | undefined;
87
70
  remove(id: UUID): void;
88
- static writeIndexes(root: string, output: string, options: Parameters<typeof TreeNode.generate>[1]): Promise<void>[];
71
+ }
72
+
73
+ declare class TreeNode<T = unknown> {
74
+ data: T;
75
+ parent?: TreeNode<T>;
76
+ children: Array<TreeNode<T>>;
77
+ constructor(data: T, parent?: TreeNode<T>);
78
+ addChild(data: T): any;
79
+ find(data: T): any;
80
+ leaves(): this[];
81
+ root(): any;
82
+ forEach(callback: (treeNode: TreeNode<T>) => void): this;
83
+ static generate(path: string, options?: DirectoryTreeOptions): TreeNode<{
84
+ name: string;
85
+ path: string;
86
+ type: "file" | "directory";
87
+ }>;
89
88
  }
90
89
 
91
90
  interface Cache<TCache = any> {
package/dist/index.js CHANGED
@@ -82,6 +82,61 @@ var getPathMode = (path) => {
82
82
  return pathParser.extname(path) ? "file" : "directory";
83
83
  };
84
84
 
85
+ // src/plugin.ts
86
+ function createPlugin(factory) {
87
+ return (options) => {
88
+ const plugin = factory(options);
89
+ if (Array.isArray(plugin)) {
90
+ throw new Error("Not implemented");
91
+ }
92
+ if (!plugin.transform) {
93
+ plugin.transform = function transform(code) {
94
+ return code;
95
+ };
96
+ }
97
+ return plugin;
98
+ };
99
+ }
100
+ var name = "core";
101
+ var isEmittedFile = (result) => {
102
+ return !!result.id;
103
+ };
104
+ var definePlugin = createPlugin((options) => {
105
+ const { fileManager, resolveId, load } = options;
106
+ const api = {
107
+ get config() {
108
+ return options.config;
109
+ },
110
+ fileManager,
111
+ async addFile(file, options2) {
112
+ if (isEmittedFile(file)) {
113
+ const resolvedId = await resolveId({ fileName: file.id, directory: file.importer, options: file.options });
114
+ const path = resolvedId || file.importer || file.id;
115
+ return fileManager.add({
116
+ path,
117
+ fileName: file.name || file.id,
118
+ source: file.source || ""
119
+ });
120
+ }
121
+ if (options2?.root) ;
122
+ return fileManager.addOrAppend(file);
123
+ },
124
+ resolveId,
125
+ load,
126
+ cache: createPluginCache(/* @__PURE__ */ Object.create(null))
127
+ };
128
+ return {
129
+ name,
130
+ api,
131
+ resolveId(fileName, directory) {
132
+ if (!directory) {
133
+ return null;
134
+ }
135
+ return pathParser.resolve(directory, fileName);
136
+ }
137
+ };
138
+ });
139
+
85
140
  // src/managers/fileManager/events.ts
86
141
  var keys = {
87
142
  getFileKey: () => `file`,
@@ -129,82 +184,6 @@ var getFileManagerEvents = (emitter) => {
129
184
  }
130
185
  };
131
186
  };
132
- var TreeNode = class {
133
- data;
134
- parent;
135
- children;
136
- constructor(data, parent) {
137
- this.data = data;
138
- this.parent = parent;
139
- return this;
140
- }
141
- addChild(data) {
142
- const child = new TreeNode(data, this);
143
- if (!this.children) {
144
- this.children = [];
145
- }
146
- this.children.push(child);
147
- return child;
148
- }
149
- find(data) {
150
- if (data === this.data) {
151
- return this;
152
- }
153
- if (this.children) {
154
- for (let i = 0, { length } = this.children, target = null; i < length; i++) {
155
- target = this.children[i].find(data);
156
- if (target) {
157
- return target;
158
- }
159
- }
160
- }
161
- return null;
162
- }
163
- leaves() {
164
- if (!this.children || this.children.length === 0) {
165
- return [this];
166
- }
167
- const leaves = [];
168
- if (this.children) {
169
- for (let i = 0, { length } = this.children; i < length; i++) {
170
- leaves.push.apply(leaves, this.children[i].leaves());
171
- }
172
- }
173
- return leaves;
174
- }
175
- root() {
176
- if (!this.parent) {
177
- return this;
178
- }
179
- return this.parent.root();
180
- }
181
- forEach(callback) {
182
- if (typeof callback !== "function") {
183
- throw new TypeError("forEach() callback must be a function");
184
- }
185
- callback(this);
186
- if (this.children) {
187
- for (let i = 0, { length } = this.children; i < length; i++) {
188
- this.children[i].forEach(callback);
189
- }
190
- }
191
- return this;
192
- }
193
- static generate(path, options = {}) {
194
- const filteredTree = dirTree(path, { extensions: options?.extensions, exclude: options.exclude });
195
- const treeNode = new TreeNode({ name: filteredTree.name, path: filteredTree.path, type: filteredTree.type });
196
- const recurse = (node, item) => {
197
- const subNode = node.addChild({ name: item.name, path: item.path, type: item.type });
198
- if (item.children?.length) {
199
- item.children?.forEach((child) => {
200
- recurse(subNode, child);
201
- });
202
- }
203
- };
204
- filteredTree.children?.forEach((child) => recurse(treeNode, child));
205
- return treeNode;
206
- }
207
- };
208
187
 
209
188
  // src/managers/fileManager/FileManager.ts
210
189
  var FileManager = class {
@@ -291,109 +270,83 @@ ${file.source}`
291
270
  this.setStatus(id, "removed");
292
271
  this.events.emitRemove(id, cacheItem.file);
293
272
  }
294
- static writeIndexes(root, output, options) {
295
- const tree = TreeNode.generate(output, { extensions: /\.ts/, ...options });
296
- const fileReducer = (files2, item) => {
297
- if (!item.children) {
298
- return [];
273
+ };
274
+ var TreeNode = class {
275
+ data;
276
+ parent;
277
+ children;
278
+ constructor(data, parent) {
279
+ this.data = data;
280
+ this.parent = parent;
281
+ return this;
282
+ }
283
+ addChild(data) {
284
+ const child = new TreeNode(data, this);
285
+ if (!this.children) {
286
+ this.children = [];
287
+ }
288
+ this.children.push(child);
289
+ return child;
290
+ }
291
+ find(data) {
292
+ if (data === this.data) {
293
+ return this;
294
+ }
295
+ if (this.children) {
296
+ for (let i = 0, { length } = this.children, target = null; i < length; i++) {
297
+ target = this.children[i].find(data);
298
+ if (target) {
299
+ return target;
300
+ }
299
301
  }
300
- if (item.children?.length > 1) {
301
- const path = pathParser.resolve(root, item.data.path, "index.ts");
302
- const source = item.children.reduce((source2, file) => {
303
- if (!file) {
304
- return source2;
305
- }
306
- const importPath = file.data.type === "directory" ? `./${file.data.name}` : `./${file.data.name.replace(/\.[^.]*$/, "")}`;
307
- if (importPath.includes("index") && path.includes("index")) {
308
- return source2;
309
- }
310
- return `${source2}export * from "${importPath}";
311
- `;
312
- }, "");
313
- files2.push({
314
- path,
315
- fileName: "index.ts",
316
- source
317
- });
318
- } else {
319
- item.children?.forEach((child) => {
320
- const path = pathParser.resolve(root, item.data.path, "index.ts");
321
- const importPath = child.data.type === "directory" ? `./${child.data.name}` : `./${child.data.name.replace(/\.[^.]*$/, "")}`;
322
- files2.push({
323
- path,
324
- fileName: "index.ts",
325
- source: `export * from "${importPath}";
326
- `
327
- });
328
- });
302
+ }
303
+ return null;
304
+ }
305
+ leaves() {
306
+ if (!this.children || this.children.length === 0) {
307
+ return [this];
308
+ }
309
+ const leaves = [];
310
+ if (this.children) {
311
+ for (let i = 0, { length } = this.children; i < length; i++) {
312
+ leaves.push.apply(leaves, this.children[i].leaves());
329
313
  }
330
- item.children.forEach((childItem) => {
331
- fileReducer(files2, childItem);
332
- });
333
- return files2;
334
- };
335
- const files = fileReducer([], tree);
336
- return files.map((file) => write(file.source, file.path));
314
+ }
315
+ return leaves;
337
316
  }
338
- };
339
-
340
- // src/plugin.ts
341
- function createPlugin(factory) {
342
- return (options) => {
343
- const plugin = factory(options);
344
- if (Array.isArray(plugin)) {
345
- throw new Error("Not implemented");
317
+ root() {
318
+ if (!this.parent) {
319
+ return this;
346
320
  }
347
- if (!plugin.transform) {
348
- plugin.transform = function transform(code) {
349
- return code;
350
- };
321
+ return this.parent.root();
322
+ }
323
+ forEach(callback) {
324
+ if (typeof callback !== "function") {
325
+ throw new TypeError("forEach() callback must be a function");
351
326
  }
352
- return plugin;
353
- };
354
- }
355
- var name = "core";
356
- var isEmittedFile = (result) => {
357
- return !!result.id;
358
- };
359
- var definePlugin = createPlugin((options) => {
360
- const { fileManager, resolveId, load } = options;
361
- const api = {
362
- get config() {
363
- return options.config;
364
- },
365
- fileManager,
366
- async addFile(file, options2) {
367
- if (isEmittedFile(file)) {
368
- const resolvedId = await resolveId({ fileName: file.id, directory: file.importer, options: file.options });
369
- const path = resolvedId || file.importer || file.id;
370
- return fileManager.add({
371
- path,
372
- fileName: file.name || file.id,
373
- source: file.source || ""
374
- });
375
- }
376
- if (options2?.root) ;
377
- return fileManager.addOrAppend(file);
378
- },
379
- resolveId,
380
- load,
381
- cache: createPluginCache(/* @__PURE__ */ Object.create(null))
382
- };
383
- return {
384
- name,
385
- api,
386
- async buildEnd() {
387
- await FileManager.writeIndexes(this.config.root, this.config.output.path, { exclude: [/schemas/, /json/] });
388
- },
389
- resolveId(fileName, directory) {
390
- if (!directory) {
391
- return null;
327
+ callback(this);
328
+ if (this.children) {
329
+ for (let i = 0, { length } = this.children; i < length; i++) {
330
+ this.children[i].forEach(callback);
392
331
  }
393
- return pathParser.resolve(directory, fileName);
394
332
  }
395
- };
396
- });
333
+ return this;
334
+ }
335
+ static generate(path, options = {}) {
336
+ const filteredTree = dirTree(path, { extensions: options?.extensions, exclude: options.exclude });
337
+ const treeNode = new TreeNode({ name: filteredTree.name, path: filteredTree.path, type: filteredTree.type });
338
+ const recurse = (node, item) => {
339
+ const subNode = node.addChild({ name: item.name, path: item.path, type: item.type });
340
+ if (item.children?.length) {
341
+ item.children?.forEach((child) => {
342
+ recurse(subNode, child);
343
+ });
344
+ }
345
+ };
346
+ filteredTree.children?.forEach((child) => recurse(treeNode, child));
347
+ return treeNode;
348
+ }
349
+ };
397
350
 
398
351
  // src/managers/pluginManager/PluginManager.ts
399
352
  var hookNames = {
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/build.ts","../src/plugin.ts","../src/utils/isPromise.ts","../src/utils/write.ts","../src/utils/format.ts","../src/utils/cache.ts","../src/utils/read.ts","../src/managers/fileManager/FileManager.ts","../src/managers/fileManager/events.ts","../src/managers/fileManager/TreeNode.ts","../src/managers/pluginManager/PluginManager.ts","../src/config.ts","../src/index.ts"],"names":["fse","pathParser","file","files","source","options","argument0"],"mappings":";AAAA,OAAOA,UAAS;;;ACAhB,OAAOC,iBAAgB;;;ACEhB,IAAM,YAAY,CAAI,WAAkD;AAC7E,SAAO,OAAQ,QAAgB,SAAS;AAC1C;;;ACHA,OAAO,SAAS;;;ACDhB,SAAS,UAAU,sBAAsB;AAIzC,IAAM,gBAAyB;AAAA,EAC7B,UAAU;AAAA,EACV,YAAY;AAAA,EACZ,QAAQ;AAAA,EACR,aAAa;AAAA,EACb,MAAM;AAAA,EACN,iBAAiB;AAAA,EACjB,WAAW;AACb;AACO,IAAM,SAAS,CAAC,SAAiB;AACtC,SAAO,eAAe,MAAM,aAAa;AAC3C;;;ADNO,IAAM,QAAQ,OAAO,MAAc,MAAc,UAAwB,EAAE,QAAQ,MAAM,MAAM;AACpG,QAAM,gBAAgB,QAAQ,SAAS,OAAO,IAAI,IAAI;AAEtD,MAAI;AACF,UAAM,IAAI,KAAK,IAAI;AACnB,UAAM,aAAa,MAAM,IAAI,SAAS,MAAM,EAAE,UAAU,QAAQ,CAAC;AACjE,QAAI,YAAY,SAAS,MAAM,eAAe;AAC5C;AAAA,IACF;AAAA,EACF,SAAS,MAAP;AACA,WAAO,IAAI,WAAW,MAAM,aAAa;AAAA,EAC3C;AAEA,SAAO,IAAI,WAAW,MAAM,aAAa;AAC3C;;;AEbO,SAAS,kBAAkB,OAAmB;AACnD,SAAO;AAAA,IACL,OAAO,IAAY;AACjB,aAAO,OAAO,MAAM;AAAA,IACtB;AAAA,IACA,IAAI,IAAY;AACd,YAAM,OAAO,MAAM;AACnB,UAAI,CAAC;A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AQ,CAAC,SAAS,WAAW;AACtC,QAAI;AACF,0BAAoB,SAAS,OAAO;AAAA,IACtC,SAAS,GAAP;AACA,aAAO,CAAC;AAAA,IACV;AAAA,EACF,CAAC;AACH;;;AWxFO,IAAM,eAAe,CAC1B,YAMG;;;ACLL,IAAO,cAAQ","sourcesContent":["import fse from 'fs-extra'\n\nimport { PluginManager } from './managers/pluginManager'\n\nimport type { PluginContext, TransformResult, ValidationResult, LogLevel, KubbPlugin } from './types'\n\ntype BuildOutput = void\n\n// Same type as ora\ntype Spinner = {\n start: (text?: string) => Spinner\n succeed: (text: string) => Spinner\n fail: (text?: string) => Spinner\n stopAndPersist: (options: { text: string }) => Spinner\n render: () => Spinner\n text: string\n info: (text: string) => Spinner\n}\n\nexport type Logger = {\n log: (message: string, logLevel: LogLevel) => void\n spinner?: Spinner\n}\ntype BuildOptions = {\n config: PluginContext['config']\n mode: 'development' | 'production'\n logger?: Logger\n}\n\nasync function transformReducer(this: PluginContext, _previousCode: string, result: TransformResult, _plugin: KubbPlugin) {\n if (result === null) {\n return null\n }\n return result\n}\n\nasync function buildImplementation(options: BuildOptions, done: (output: BuildOutput) => void) {\n const { config, logger } = options\n\n if (config.output.clean) {\n await fse.remove(config.output.path)\n }\n\n const pluginManager = new PluginManager(config, { logger })\n const { plugins, fileManager } = pluginManager\n\n const validations = await pluginManager.hookParallel<'validate', ValidationResult>('validate', [plugins])\n const validationsWithMessage = validations.filter(Boolean)\n\n if (validationsWithMessage.some((validation) => typeof validation !== 'boolean')) {\n validationsWithMessage.forEach((validation) => {\n if (validation && typeof validation !== 'boolean' && validation?.message) {\n logger?.log(validation.message, 'warn')\n }\n })\n\n return\n }\n\n fileManager.events.onSuccess(async () => {\n await pluginManager.hookParallel('buildEnd')\n setTimeout(() => {\n done()\n }, 1000)\n })\n\n fileManager.events.onAdd(async (id, file) => {\n const { path } = file\n let { source: code } = file\n\n const loadedResult = await pluginManager.hookFirst('load', [path])\n if (loadedResult) {\n code = loadedResult\n }\n\n if (code) {\n const transformedCode = await pluginManager.hookReduceArg0('transform', [code, path], transformReducer)\n\n await pluginManager.hookParallel('writeFile', [transformedCode, path])\n fileManager.setStatus(id, 'success')\n fileManager.remove(id)\n }\n })\n\n await pluginManager.hookParallel('buildStart', [config])\n}\n\nexport function build(options: BuildOptions): Promise<BuildOutput> {\n return new Promise((resolve, reject) => {\n try {\n buildImplementation(options, resolve)\n } catch (e) {\n reject(e)\n }\n })\n}\n","import pathParser from 'path'\n\nimport { createPluginCache } from './utils'\nimport { FileManager } from './managers/fileManager'\n\nimport type { EmittedFile, File } from './managers/fileManager'\nimport type { PluginContext, KubbPlugin, PluginFactoryOptions } from './types'\n\ntype KubbPluginFactory<T extends PluginFactoryOptions = PluginFactoryOptions> = (\n options: T['options']\n) => T['nested'] extends true ? Array<KubbPlugin<T>> : KubbPlugin<T>\n\nexport function createPlugin<T extends PluginFactoryOptions = PluginFactoryOptions>(factory: KubbPluginFactory<T>) {\n return (options: T['options']) => {\n const plugin = factory(options)\n if (Array.isArray(plugin)) {\n throw new Error('Not implemented')\n }\n\n // default transform\n if (!plugin.transform) {\n plugin.transform = function transform(code) {\n return code\n }\n }\n\n return plugin\n }\n}\n\ntype Options = {\n config: PluginContext['config']\n fileManager: FileManager\n resolveId: PluginContext['resolveId']\n load: PluginContext['load']\n}\n\n// not publicly exported\nexport type CorePluginOptions = PluginFactoryOptions<Options, false, PluginContext>\n\nexport const name = 'core' as const\n\nconst isEmittedFile = (result: EmittedFile | File): result is EmittedFile => {\n return !!(result as any).id\n}\n\nexport const definePlugin = createPlugin<CorePluginOptions>((options) => {\n const { fileManager, resolveId, load } = options\n const indexFiles: File[] = []\n\n const api: PluginContext = {\n get config() {\n return options.config\n },\n fileManager,\n async addFile(file, options) {\n if (isEmittedFile(file)) {\n const resolvedId = await resolveId({ fileName: file.id, directory: file.importer, options: file.options })\n const path = resolvedId || file.importer || file.id\n\n return fileManager.add({\n path,\n fileName: file.name || file.id,\n source: file.source || '',\n })\n }\n\n if (options?.root) {\n indexFiles.push(file)\n }\n\n return fileManager.addOrAppend(file)\n },\n resolveId,\n load,\n cache: createPluginCache(Object.create(null)),\n }\n\n return {\n name,\n api,\n async buildEnd() {\n await FileManager.writeIndexes(this.config.root, this.config.output.path, { exclude: [/schemas/, /json/] })\n },\n resolveId(fileName, directory) {\n if (!directory) {\n return null\n }\n return pathParser.resolve(directory, fileName)\n },\n }\n})\n","import type { MaybePromise } from '../types'\n\nexport const isPromise = <T>(result: MaybePromise<T>): result is Promise<T> => {\n return typeof (result as any)?.then === 'function'\n}\n","/* eslint-disable consistent-return */\nimport fse from 'fs-extra'\n\nimport { format } from './format'\n\ntype WriteOptions = {\n format: boolean\n}\n\nexport const write = async (data: string, path: string, options: WriteOptions = { format: false }) => {\n const formattedData = options.format ? format(data) : data\n\n try {\n await fse.stat(path)\n const oldContent = await fse.readFile(path, { encoding: 'utf-8' })\n if (oldContent?.toString() === formattedData) {\n return\n }\n } catch (_err) {\n return fse.outputFile(path, formattedData)\n }\n\n return fse.outputFile(path, formattedData)\n}\n","import { format as prettierFormat } from 'prettier'\n\nimport type { Options } from 'prettier'\n\nconst formatOptions: Options = {\n tabWidth: 2,\n printWidth: 160,\n parser: 'typescript',\n singleQuote: true,\n semi: false,\n bracketSameLine: false,\n endOfLine: 'auto',\n}\nexport const format = (text: string) => {\n return prettierFormat(text, formatOptions)\n}\n","/* eslint-disable no-param-reassign */\n/* eslint-disable consistent-return */\n\nexport interface Cache<TCache = any> {\n delete(id: string): boolean\n get<T = TCache>(id: string): T\n has(id: string): boolean\n set<T = TCache>(id: string, value: T): void\n}\n\nexport function createPluginCache(cache: any): Cache {\n return {\n delete(id: string) {\n return delete cache[id]\n },\n get(id: string) {\n const item = cache[id]\n if (!item) return\n item[0] = 0\n return item[1]\n },\n has(id: string) {\n const item = cache[id]\n if (!item) return false\n item[0] = 0\n return true\n },\n set(id: string, value: any) {\n cache[id] = [0, value]\n },\n }\n}\n","import pathParser from 'path'\n\n// TODO check for a better way or resolving the relative path\nexport const getRelativePath = (root?: string | null, file?: string | null) => {\n if (!root || !file) {\n throw new Error('Root and file should be filled in when retrieving the relativePath')\n }\n const newPath = pathParser.relative(root, file).replace('../', '').replace('.ts', '').trimEnd()\n\n return `./${newPath}`\n}\n\nexport const getPathMode = (path: string | undefined | null) => {\n if (!path) {\n return undefined\n }\n return pathParser.extname(path) ? 'file' : 'directory'\n}\n","import EventEmitter from 'events'\nimport { randomUUID } from 'crypto'\nimport pathParser from 'path'\n\nimport { getFileManagerEvents } from './events'\nimport { TreeNode } from './TreeNode'\n\nimport { write } from '../../utils/write'\n\nimport type { CacheStore, UUID, Status, File } from './types'\n\nexport class FileManager {\n private cache: Map<CacheStore['id'], CacheStore> = new Map()\n\n emitter = new EventEmitter()\n\n events = getFileManagerEvents(this.emitter)\n\n constructor() {\n this.events.onStatusChange(() => {\n if (this.getCountByStatus('removed') === this.cache.size) {\n // all files are been resolved and written to the file system\n this.events.emitSuccess()\n }\n })\n }\n\n private getCache(id: UUID) {\n return this.cache.get(id)\n }\n\n private getCacheByPath(path: string | undefined): CacheStore | undefined {\n let cache\n\n this.cache.forEach((item) => {\n if (item.file.path === path) {\n cache = item\n }\n })\n return cache as CacheStore\n }\n\n private getCountByStatus(status: Status) {\n let count = 0\n\n this.cache.forEach((item) => {\n if (item.status === status) {\n count++\n }\n })\n return count\n }\n\n get files() {\n const files: File[] = []\n this.cache.forEach((item) => {\n files.push(item.file)\n })\n\n return files\n }\n\n add(file: File) {\n const cacheItem = { id: randomUUID(), file, status: 'new' as Status }\n\n this.cache.set(cacheItem.id, cacheItem)\n this.events.emitFile(cacheItem.id, file)\n\n return new Promise<File>((resolve) => {\n const unsubscribe = this.events.onRemove(cacheItem.id, (file) => {\n resolve(file)\n unsubscribe()\n })\n })\n }\n\n addOrAppend(file: File) {\n const previousCache = this.getCacheByPath(file.path)\n\n if (previousCache) {\n this.remove(previousCache.id)\n return this.add({\n ...file,\n source: `${previousCache.file.source}\\n${file.source}`,\n })\n }\n return this.add(file)\n }\n\n setStatus(id: UUID, status: Status) {\n const cacheItem = this.getCache(id)\n if (!cacheItem) {\n return\n }\n\n cacheItem.status = status\n this.cache.set(id, cacheItem)\n this.events.emitStatusChange(cacheItem.file)\n this.events.emitStatusChangeById(id, status)\n }\n\n get(id: UUID) {\n const cacheItem = this.getCache(id)\n return cacheItem?.file\n }\n\n remove(id: UUID) {\n const cacheItem = this.getCache(id)\n if (!cacheItem) {\n return\n }\n\n this.setStatus(id, 'removed')\n this.events.emitRemove(id, cacheItem.file)\n }\n\n public static writeIndexes(root: string, output: string, options: Parameters<typeof TreeNode.generate>[1]) {\n const tree = TreeNode.generate(output, { extensions: /\\.ts/, ...options })\n\n const fileReducer = (files: File[], item: typeof tree) => {\n if (!item.children) {\n return []\n }\n\n if (item.children?.length > 1) {\n const path = pathParser.resolve(root, item.data.path, 'index.ts')\n const source = item.children.reduce((source, file) => {\n if (!file) {\n return source\n }\n\n const importPath: string = file.data.type === 'directory' ? `./${file.data.name}` : `./${file.data.name.replace(/\\.[^.]*$/, '')}`\n\n // TODO weird hacky fix\n if (importPath.includes('index') && path.includes('index')) {\n return source\n }\n\n return `${source}export * from \"${importPath}\";\\n`\n }, '')\n\n files.push({\n path,\n fileName: 'index.ts',\n source,\n })\n } else {\n item.children?.forEach((child) => {\n const path = pathParser.resolve(root, item.data.path, 'index.ts')\n const importPath = child.data.type === 'directory' ? `./${child.data.name}` : `./${child.data.name.replace(/\\.[^.]*$/, '')}`\n\n files.push({\n path,\n fileName: 'index.ts',\n source: `export * from \"${importPath}\";\\n`,\n })\n })\n }\n\n item.children.forEach((childItem) => {\n fileReducer(files, childItem)\n })\n\n return files\n }\n\n const files = fileReducer([], tree)\n\n return files.map((file) => write(file.source, file.path))\n }\n}\n","import type EventEmitter from 'events'\nimport type { File, Status, UUID } from './types'\n\nconst keys = {\n getFileKey: () => `file`,\n getStatusChangeKey: () => `status-change`,\n getStatusChangeByIdKey: (id: string) => `${id}-status-change`,\n getSuccessKey: () => `success`,\n getRemoveKey: (id: string) => `${id}remove`,\n} as const\n\ntype VoidFunction = () => void\n\nexport const getFileManagerEvents = (emitter: EventEmitter) => {\n return {\n /**\n * Emiter\n */\n emitFile: (id: UUID, file: File): void => {\n emitter.emit(keys.getFileKey(), id, file)\n },\n emitStatusChange: (file: File): void => {\n emitter.emit(keys.getStatusChangeKey(), file)\n },\n emitStatusChangeById: (id: UUID, status: Status): void => {\n emitter.emit(keys.getStatusChangeByIdKey(id), status)\n },\n emitSuccess: (): void => {\n emitter.emit(keys.getSuccessKey())\n },\n emitRemove: (id: UUID, file: File): void => {\n emitter.emit(keys.getRemoveKey(id), file)\n },\n /**\n * Listeners\n */\n\n onAdd: (callback: (id: UUID, file: File) => void): VoidFunction => {\n emitter.on(keys.getFileKey(), callback)\n return () => emitter.removeListener(keys.getFileKey(), callback)\n },\n onStatusChange: (callback: (file: File) => void): VoidFunction => {\n emitter.on(keys.getStatusChangeKey(), callback)\n return () => emitter.removeListener(keys.getStatusChangeKey(), callback)\n },\n onStatusChangeById: (id: UUID, callback: (status: Status) => void): VoidFunction => {\n emitter.on(keys.getStatusChangeByIdKey(id), callback)\n return () => emitter.removeListener(keys.getStatusChangeByIdKey(id), callback)\n },\n onSuccess: (callback: () => void): VoidFunction => {\n emitter.on(keys.getSuccessKey(), callback)\n return () => emitter.removeListener(keys.getSuccessKey(), callback)\n },\n onRemove: (id: UUID, callback: (file: File) => void): VoidFunction => {\n emitter.on(keys.getRemoveKey(id), callback)\n return () => emitter.removeListener(keys.getRemoveKey(id), callback)\n },\n }\n}\n","import dirTree from 'directory-tree'\n\nimport type { DirectoryTree, DirectoryTreeOptions } from 'directory-tree'\n\nexport class TreeNode<T = unknown> {\n public data: T\n\n public parent?: TreeNode<T>\n\n public children: Array<TreeNode<T>>\n\n constructor(data: T, parent?: TreeNode<T>) {\n this.data = data\n this.parent = parent\n return this\n }\n\n addChild(data: T) {\n const child = new TreeNode(data, this)\n if (!this.children) {\n this.children = []\n }\n this.children.push(child)\n return child\n }\n\n find(data: T) {\n if (data === this.data) {\n return this\n }\n\n if (this.children) {\n for (let i = 0, { length } = this.children, target: any = null; i < length; i++) {\n target = this.children[i].find(data)\n if (target) {\n return target\n }\n }\n }\n\n return null\n }\n\n leaves() {\n if (!this.children || this.children.length === 0) {\n // this is a leaf\n return [this]\n }\n\n // if not a leaf, return all children's leaves recursively\n const leaves = []\n if (this.children) {\n for (let i = 0, { length } = this.children; i < length; i++) {\n // eslint-disable-next-line prefer-spread\n leaves.push.apply(leaves, this.children[i].leaves())\n }\n }\n return leaves\n }\n\n root() {\n if (!this.parent) {\n return this\n }\n return this.parent.root()\n }\n\n forEach(callback: (treeNode: TreeNode<T>) => void) {\n if (typeof callback !== 'function') {\n throw new TypeError('forEach() callback must be a function')\n }\n\n // run this node through function\n callback(this)\n\n // do the same for all children\n if (this.children) {\n for (let i = 0, { length } = this.children; i < length; i++) {\n this.children[i].forEach(callback)\n }\n }\n\n return this\n }\n\n public static generate(path: string, options: DirectoryTreeOptions = {}) {\n const filteredTree = dirTree(path, { extensions: options?.extensions, exclude: options.exclude })\n const treeNode = new TreeNode({ name: filteredTree.name, path: filteredTree.path, type: filteredTree.type })\n\n const recurse = (node: typeof treeNode, item: DirectoryTree) => {\n const subNode = node.addChild({ name: item.name, path: item.path, type: item.type })\n\n if (item.children?.length) {\n item.children?.forEach((child) => {\n recurse(subNode, child)\n })\n }\n }\n\n filteredTree.children?.forEach((child) => recurse(treeNode, child))\n\n return treeNode\n }\n}\n","/* eslint-disable no-await-in-loop */\n/* eslint-disable no-restricted-syntax */\n\nimport { definePlugin } from '../../plugin'\nimport { FileManager } from '../fileManager'\n\nimport type { Argument0, Strategy } from './types'\nimport type { KubbConfig, KubbPlugin, PluginLifecycleHooks, PluginLifecycle, MaybePromise, ResolveIdParams } from '../../types'\nimport type { Logger } from '../../build'\nimport type { CorePluginOptions } from '../../plugin'\n\n// inspired by: https://github.com/rollup/rollup/blob/master/src/utils/PluginDriver.ts#\n\n// This will make sure no input hook is omitted\nconst hookNames: {\n [P in PluginLifecycleHooks]: 1\n} = {\n validate: 1,\n buildStart: 1,\n resolveId: 1,\n load: 1,\n transform: 1,\n writeFile: 1,\n buildEnd: 1,\n}\nexport const hooks = Object.keys(hookNames) as [PluginLifecycleHooks]\n\nexport class PluginManager {\n public plugins: KubbPlugin[]\n\n public readonly fileManager: FileManager\n\n private readonly logger?: Logger\n\n private readonly config: KubbConfig\n\n public readonly core: KubbPlugin<CorePluginOptions>\n\n constructor(config: KubbConfig, options: { logger?: Logger }) {\n this.logger = options.logger\n this.config = config\n\n this.fileManager = new FileManager()\n this.core = definePlugin({\n config,\n fileManager: this.fileManager,\n load: this.load,\n resolveId: this.resolveId,\n }) as KubbPlugin<CorePluginOptions> & {\n api: CorePluginOptions['api']\n }\n this.plugins = [this.core, ...(config.plugins || [])]\n }\n\n resolveId = (params: ResolveIdParams) => {\n if (params.pluginName) {\n return this.hookForPlugin(params.pluginName, 'resolveId', [params.fileName, params.directory, params.options])\n }\n return this.hookFirst('resolveId', [params.fileName, params.directory, params.options])\n }\n\n load = async (id: string) => {\n return this.hookFirst('load', [id])\n }\n\n // run only hook for a specific plugin name\n hookForPlugin<H extends PluginLifecycleHooks>(\n pluginName: string,\n hookName: H,\n parameters: Parameters<PluginLifecycle[H]>,\n skipped?: ReadonlySet<KubbPlugin> | null\n ): Promise<ReturnType<PluginLifecycle[H]> | null> {\n let promise: Promise<ReturnType<PluginLifecycle[H]> | null> = Promise.resolve(null)\n for (const plugin of this.getSortedPlugins(hookName, pluginName)) {\n if (skipped && skipped.has(plugin)) continue\n promise = promise.then((result) => {\n if (result != null) return result\n return this.run('hookFirst', hookName, parameters, plugin) as any\n })\n }\n return promise\n }\n\n // chains, first non-null result stops and returns\n hookFirst<H extends PluginLifecycleHooks>(\n hookName: H,\n parameters: Parameters<PluginLifecycle[H]>,\n skipped?: ReadonlySet<KubbPlugin> | null\n ): Promise<ReturnType<PluginLifecycle[H]> | null> {\n let promise: Promise<ReturnType<PluginLifecycle[H]> | null> = Promise.resolve(null)\n for (const plugin of this.getSortedPlugins(hookName)) {\n if (skipped && skipped.has(plugin)) continue\n promise = promise.then((result) => {\n if (result != null) return result\n return this.run('hookFirst', hookName, parameters, plugin) as any\n })\n }\n return promise\n }\n\n // parallel\n async hookParallel<H extends PluginLifecycleHooks, TOuput = void>(hookName: H, parameters?: Parameters<PluginLifecycle[H]> | undefined) {\n const parallelPromises: Promise<TOuput>[] = []\n\n for (const plugin of this.getSortedPlugins(hookName)) {\n if ((plugin[hookName] as { sequential?: boolean })?.sequential) {\n await Promise.all(parallelPromises)\n parallelPromises.length = 0\n await this.run('hookParallel', hookName, parameters, plugin)\n } else {\n const promise: Promise<TOuput> = this.run('hookParallel', hookName, parameters, plugin)\n\n parallelPromises.push(promise)\n }\n }\n return Promise.all(parallelPromises)\n }\n\n // chains, reduces returned value, handling the reduced value as the first hook argument\n hookReduceArg0<H extends PluginLifecycleHooks>(\n hookName: H,\n [argument0, ...rest]: Parameters<PluginLifecycle[H]>,\n reduce: (reduction: Argument0<H>, result: ReturnType<PluginLifecycle[H]>, plugin: KubbPlugin) => MaybePromise<Argument0<H> | null>\n ): Promise<Argument0<H>> {\n let promise = Promise.resolve(argument0)\n for (const plugin of this.getSortedPlugins(hookName)) {\n promise = promise.then((argument0) =>\n this.run('hookReduceArg0', hookName, [argument0, ...rest] as Parameters<PluginLifecycle[H]>, plugin).then((result) =>\n reduce.call(this.core.api, argument0, result, plugin)\n )\n )\n }\n return promise\n }\n\n // chains\n\n hookSeq<H extends PluginLifecycleHooks>(hookName: H, parameters?: Parameters<PluginLifecycle[H]>) {\n let promise: Promise<void> = Promise.resolve()\n for (const plugin of this.getSortedPlugins(hookName)) {\n promise = promise.then(() => this.run('hookSeq', hookName, parameters, plugin))\n }\n return promise.then(noReturn)\n }\n\n private getSortedPlugins(hookName: keyof PluginLifecycle, pluginName?: string): KubbPlugin[] {\n const plugins = [...this.plugins]\n\n if (pluginName) {\n const pluginsByPluginName = plugins.filter((item) => item.name === pluginName && item[hookName])\n if (pluginsByPluginName.length === 0) {\n // fallback on the core plugin when there is no match\n if (this.config.logLevel === 'warn' && this.logger?.spinner) {\n this.logger.spinner.info(`Plugin hook with ${hookName} not found for plugin ${pluginName}`)\n }\n return [this.core]\n }\n return pluginsByPluginName\n }\n\n return plugins\n }\n\n /**\n * Run an async plugin hook and return the result.\n * @param hookName Name of the plugin hook. Must be either in `PluginHooks` or `OutputPluginValueHooks`.\n * @param args Arguments passed to the plugin hook.\n * @param plugin The actual pluginObject to run.\n */\n // Implementation signature\n private run<H extends PluginLifecycleHooks, TResult = void>(\n strategy: Strategy,\n hookName: H,\n parameters: unknown[] | undefined,\n plugin: KubbPlugin\n ): Promise<TResult> {\n const hook = plugin[hookName]!\n\n return Promise.resolve()\n .then(() => {\n if (typeof hook !== 'function') {\n return hook\n }\n\n if (this.config.logLevel === 'info' && this.logger?.spinner) {\n this.logger.spinner.text = `[${strategy}] ${hookName}: Excecuting task for plugin ${plugin.name} \\n`\n }\n\n const hookResult = (hook as any).apply(this.core.api, parameters)\n\n if (!hookResult?.then) {\n // short circuit for non-thenables and non-Promises\n if (this.config.logLevel === 'info' && this.logger?.spinner) {\n this.logger.spinner.succeed(`[${strategy}] ${hookName}: Excecuting task for plugin ${plugin.name} \\n`)\n }\n return hookResult\n }\n\n return Promise.resolve(hookResult).then((result) => {\n // action was fulfilled\n if (this.config.logLevel === 'info' && this.logger?.spinner) {\n this.logger.spinner.succeed(`[${strategy}] ${hookName}: Excecuting task for plugin ${plugin.name} \\n`)\n }\n return result\n })\n })\n .catch((e: Error) => this.catcher<H>(e, plugin, hookName))\n }\n\n /**\n * Run a sync plugin hook and return the result.\n * @param hookName Name of the plugin hook. Must be in `PluginHooks`.\n * @param args Arguments passed to the plugin hook.\n * @param plugin The acutal plugin\n * @param replaceContext When passed, the plugin context can be overridden.\n */\n private runSync<H extends PluginLifecycleHooks>(hookName: H, parameters: Parameters<PluginLifecycle[H]>, plugin: KubbPlugin): ReturnType<PluginLifecycle[H]> {\n const hook = plugin[hookName]!\n\n // const context = this.pluginContexts.get(plugin)!;\n\n try {\n // eslint-disable-next-line @typescript-eslint/ban-types\n return (hook as Function).apply(this.core.api, parameters)\n } catch (error: any) {\n return error\n }\n }\n\n private catcher<H extends PluginLifecycleHooks>(e: Error, plugin: KubbPlugin, hookName: H) {\n const text = `${e.message} (plugin: ${plugin.name}, hook: ${hookName})\\n`\n\n if (this.logger?.spinner) {\n this.logger.spinner.fail(text)\n throw e\n }\n }\n}\n\n// eslint-disable-next-line @typescript-eslint/no-empty-function\nfunction noReturn() {}\n","import type { MaybePromise, KubbUserConfig, CLIOptions } from './types'\n\n/**\n * Type helper to make it easier to use kubb.config.ts\n * accepts a direct {@link KubbConfig} object, or a function that returns it.\n * The function receives a {@link ConfigEnv} object that exposes two properties:\n */\nexport const defineConfig = (\n options:\n | MaybePromise<KubbUserConfig>\n | ((\n /** The options derived from the CLI flags */\n cliOptions: CLIOptions\n ) => MaybePromise<KubbUserConfig>)\n) => options\n","/* eslint-disable @typescript-eslint/no-empty-interface */\nimport { build } from './build'\n\nexport * from './config'\nexport * from './build'\nexport { CorePluginOptions, createPlugin } from './plugin'\nexport * from './utils'\nexport * from './types'\nexport * from './managers'\nexport default build\n"]}
1
+ {"version":3,"sources":["../src/build.ts","../src/plugin.ts","../src/utils/isPromise.ts","../src/utils/write.ts","../src/utils/format.ts","../src/utils/cache.ts","../src/utils/read.ts","../src/managers/fileManager/FileManager.ts","../src/managers/fileManager/events.ts","../src/managers/fileManager/TreeNode.ts","../src/managers/pluginManager/PluginManager.ts","../src/config.ts","../src/index.ts"],"names":["fse","pathParser","options","file","argument0"],"mappings":";AAAA,OAAOA,UAAS;;;ACAhB,OAAOC,iBAAgB;;;ACEhB,IAAM,YAAY,CAAI,WAAkD;AAC7E,SAAO,OAAQ,QAAgB,SAAS;AAC1C;;;ACHA,OAAO,SAAS;;;ACDhB,SAAS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AAS;AAC3C,UAAM,EAAE,KAAK,IAAI;AACjB,QAAI,EAAE,QAAQ,KAAK,IAAI;AAEvB,UAAM,eAAe,MAAM,cAAc,UAAU,QAAQ,CAAC,IAAI,CAAC;AACjE,QAAI,cAAc;AAChB,aAAO;AAAA,IACT;AAEA,QAAI,MAAM;AACR,YAAM,kBAAkB,MAAM,cAAc,eAAe,aAAa,CAAC,MAAM,IAAI,GAAG,gBAAgB;AAEtG,YAAM,cAAc,aAAa,aAAa,CAAC,iBAAiB,IAAI,CAAC;AACrE,kBAAY,UAAU,IAAI,SAAS;AACnC,kBAAY,OAAO,EAAE;AAAA,IACvB;AAAA,EACF,CAAC;AAED,QAAM,cAAc,aAAa,cAAc,CAAC,MAAM,CAAC;AACzD;AAEO,SAAS,MAAM,SAA6C;AACjE,SAAO,IAAI,QAAQ,CAAC,SAAS,WAAW;AACtC,QAAI;AACF,0BAAoB,SAAS,OAAO;AAAA,IACtC,SAAS,GAAP;AACA,aAAO,CAAC;AAAA,IACV;AAAA,EACF,CAAC;AACH;;;AWxFO,IAAM,eAAe,CAC1B,YAMG;;;ACLL,IAAO,cAAQ","sourcesContent":["import fse from 'fs-extra'\n\nimport { PluginManager } from './managers/pluginManager'\n\nimport type { PluginContext, TransformResult, ValidationResult, LogLevel, KubbPlugin } from './types'\n\ntype BuildOutput = void\n\n// Same type as ora\ntype Spinner = {\n start: (text?: string) => Spinner\n succeed: (text: string) => Spinner\n fail: (text?: string) => Spinner\n stopAndPersist: (options: { text: string }) => Spinner\n render: () => Spinner\n text: string\n info: (text: string) => Spinner\n}\n\nexport type Logger = {\n log: (message: string, logLevel: LogLevel) => void\n spinner?: Spinner\n}\ntype BuildOptions = {\n config: PluginContext['config']\n mode: 'development' | 'production'\n logger?: Logger\n}\n\nasync function transformReducer(this: PluginContext, _previousCode: string, result: TransformResult, _plugin: KubbPlugin) {\n if (result === null) {\n return null\n }\n return result\n}\n\nasync function buildImplementation(options: BuildOptions, done: (output: BuildOutput) => void) {\n const { config, logger } = options\n\n if (config.output.clean) {\n await fse.remove(config.output.path)\n }\n\n const pluginManager = new PluginManager(config, { logger })\n const { plugins, fileManager } = pluginManager\n\n const validations = await pluginManager.hookParallel<'validate', ValidationResult>('validate', [plugins])\n const validationsWithMessage = validations.filter(Boolean)\n\n if (validationsWithMessage.some((validation) => typeof validation !== 'boolean')) {\n validationsWithMessage.forEach((validation) => {\n if (validation && typeof validation !== 'boolean' && validation?.message) {\n logger?.log(validation.message, 'warn')\n }\n })\n\n return\n }\n\n fileManager.events.onSuccess(async () => {\n await pluginManager.hookParallel('buildEnd')\n setTimeout(() => {\n done()\n }, 1000)\n })\n\n fileManager.events.onAdd(async (id, file) => {\n const { path } = file\n let { source: code } = file\n\n const loadedResult = await pluginManager.hookFirst('load', [path])\n if (loadedResult) {\n code = loadedResult\n }\n\n if (code) {\n const transformedCode = await pluginManager.hookReduceArg0('transform', [code, path], transformReducer)\n\n await pluginManager.hookParallel('writeFile', [transformedCode, path])\n fileManager.setStatus(id, 'success')\n fileManager.remove(id)\n }\n })\n\n await pluginManager.hookParallel('buildStart', [config])\n}\n\nexport function build(options: BuildOptions): Promise<BuildOutput> {\n return new Promise((resolve, reject) => {\n try {\n buildImplementation(options, resolve)\n } catch (e) {\n reject(e)\n }\n })\n}\n","import pathParser from 'path'\n\nimport { createPluginCache } from './utils'\n\nimport type { FileManager, EmittedFile, File } from './managers/fileManager'\nimport type { PluginContext, KubbPlugin, PluginFactoryOptions } from './types'\n\ntype KubbPluginFactory<T extends PluginFactoryOptions = PluginFactoryOptions> = (\n options: T['options']\n) => T['nested'] extends true ? Array<KubbPlugin<T>> : KubbPlugin<T>\n\nexport function createPlugin<T extends PluginFactoryOptions = PluginFactoryOptions>(factory: KubbPluginFactory<T>) {\n return (options: T['options']) => {\n const plugin = factory(options)\n if (Array.isArray(plugin)) {\n throw new Error('Not implemented')\n }\n\n // default transform\n if (!plugin.transform) {\n plugin.transform = function transform(code) {\n return code\n }\n }\n\n return plugin\n }\n}\n\ntype Options = {\n config: PluginContext['config']\n fileManager: FileManager\n resolveId: PluginContext['resolveId']\n load: PluginContext['load']\n}\n\n// not publicly exported\nexport type CorePluginOptions = PluginFactoryOptions<Options, false, PluginContext>\n\nexport const name = 'core' as const\n\nconst isEmittedFile = (result: EmittedFile | File): result is EmittedFile => {\n return !!(result as any).id\n}\n\nexport const definePlugin = createPlugin<CorePluginOptions>((options) => {\n const { fileManager, resolveId, load } = options\n const indexFiles: File[] = []\n\n const api: PluginContext = {\n get config() {\n return options.config\n },\n fileManager,\n async addFile(file, options) {\n if (isEmittedFile(file)) {\n const resolvedId = await resolveId({ fileName: file.id, directory: file.importer, options: file.options })\n const path = resolvedId || file.importer || file.id\n\n return fileManager.add({\n path,\n fileName: file.name || file.id,\n source: file.source || '',\n })\n }\n\n if (options?.root) {\n indexFiles.push(file)\n }\n\n return fileManager.addOrAppend(file)\n },\n resolveId,\n load,\n cache: createPluginCache(Object.create(null)),\n }\n\n return {\n name,\n api,\n resolveId(fileName, directory) {\n if (!directory) {\n return null\n }\n return pathParser.resolve(directory, fileName)\n },\n }\n})\n","import type { MaybePromise } from '../types'\n\nexport const isPromise = <T>(result: MaybePromise<T>): result is Promise<T> => {\n return typeof (result as any)?.then === 'function'\n}\n","/* eslint-disable consistent-return */\nimport fse from 'fs-extra'\n\nimport { format } from './format'\n\ntype WriteOptions = {\n format: boolean\n}\n\nexport const write = async (data: string, path: string, options: WriteOptions = { format: false }) => {\n const formattedData = options.format ? format(data) : data\n\n try {\n await fse.stat(path)\n const oldContent = await fse.readFile(path, { encoding: 'utf-8' })\n if (oldContent?.toString() === formattedData) {\n return\n }\n } catch (_err) {\n return fse.outputFile(path, formattedData)\n }\n\n return fse.outputFile(path, formattedData)\n}\n","import { format as prettierFormat } from 'prettier'\n\nimport type { Options } from 'prettier'\n\nconst formatOptions: Options = {\n tabWidth: 2,\n printWidth: 160,\n parser: 'typescript',\n singleQuote: true,\n semi: false,\n bracketSameLine: false,\n endOfLine: 'auto',\n}\nexport const format = (text: string) => {\n return prettierFormat(text, formatOptions)\n}\n","/* eslint-disable no-param-reassign */\n/* eslint-disable consistent-return */\n\nexport interface Cache<TCache = any> {\n delete(id: string): boolean\n get<T = TCache>(id: string): T\n has(id: string): boolean\n set<T = TCache>(id: string, value: T): void\n}\n\nexport function createPluginCache(cache: any): Cache {\n return {\n delete(id: string) {\n return delete cache[id]\n },\n get(id: string) {\n const item = cache[id]\n if (!item) return\n item[0] = 0\n return item[1]\n },\n has(id: string) {\n const item = cache[id]\n if (!item) return false\n item[0] = 0\n return true\n },\n set(id: string, value: any) {\n cache[id] = [0, value]\n },\n }\n}\n","import pathParser from 'path'\n\n// TODO check for a better way or resolving the relative path\nexport const getRelativePath = (root?: string | null, file?: string | null) => {\n if (!root || !file) {\n throw new Error('Root and file should be filled in when retrieving the relativePath')\n }\n const newPath = pathParser.relative(root, file).replace('../', '').replace('.ts', '').trimEnd()\n\n return `./${newPath}`\n}\n\nexport const getPathMode = (path: string | undefined | null) => {\n if (!path) {\n return undefined\n }\n return pathParser.extname(path) ? 'file' : 'directory'\n}\n","import EventEmitter from 'events'\nimport { randomUUID } from 'crypto'\n\nimport { getFileManagerEvents } from './events'\n\nimport type { CacheStore, UUID, Status, File } from './types'\n\nexport class FileManager {\n private cache: Map<CacheStore['id'], CacheStore> = new Map()\n\n emitter = new EventEmitter()\n\n events = getFileManagerEvents(this.emitter)\n\n constructor() {\n this.events.onStatusChange(() => {\n if (this.getCountByStatus('removed') === this.cache.size) {\n // all files are been resolved and written to the file system\n this.events.emitSuccess()\n }\n })\n }\n\n private getCache(id: UUID) {\n return this.cache.get(id)\n }\n\n private getCacheByPath(path: string | undefined): CacheStore | undefined {\n let cache\n\n this.cache.forEach((item) => {\n if (item.file.path === path) {\n cache = item\n }\n })\n return cache as CacheStore\n }\n\n private getCountByStatus(status: Status) {\n let count = 0\n\n this.cache.forEach((item) => {\n if (item.status === status) {\n count++\n }\n })\n return count\n }\n\n get files() {\n const files: File[] = []\n this.cache.forEach((item) => {\n files.push(item.file)\n })\n\n return files\n }\n\n add(file: File) {\n const cacheItem = { id: randomUUID(), file, status: 'new' as Status }\n\n this.cache.set(cacheItem.id, cacheItem)\n this.events.emitFile(cacheItem.id, file)\n\n return new Promise<File>((resolve) => {\n const unsubscribe = this.events.onRemove(cacheItem.id, (file) => {\n resolve(file)\n unsubscribe()\n })\n })\n }\n\n addOrAppend(file: File) {\n const previousCache = this.getCacheByPath(file.path)\n\n if (previousCache) {\n this.remove(previousCache.id)\n return this.add({\n ...file,\n source: `${previousCache.file.source}\\n${file.source}`,\n })\n }\n return this.add(file)\n }\n\n setStatus(id: UUID, status: Status) {\n const cacheItem = this.getCache(id)\n if (!cacheItem) {\n return\n }\n\n cacheItem.status = status\n this.cache.set(id, cacheItem)\n this.events.emitStatusChange(cacheItem.file)\n this.events.emitStatusChangeById(id, status)\n }\n\n get(id: UUID) {\n const cacheItem = this.getCache(id)\n return cacheItem?.file\n }\n\n remove(id: UUID) {\n const cacheItem = this.getCache(id)\n if (!cacheItem) {\n return\n }\n\n this.setStatus(id, 'removed')\n this.events.emitRemove(id, cacheItem.file)\n }\n}\n","import type EventEmitter from 'events'\nimport type { File, Status, UUID } from './types'\n\nconst keys = {\n getFileKey: () => `file`,\n getStatusChangeKey: () => `status-change`,\n getStatusChangeByIdKey: (id: string) => `${id}-status-change`,\n getSuccessKey: () => `success`,\n getRemoveKey: (id: string) => `${id}remove`,\n} as const\n\ntype VoidFunction = () => void\n\nexport const getFileManagerEvents = (emitter: EventEmitter) => {\n return {\n /**\n * Emiter\n */\n emitFile: (id: UUID, file: File): void => {\n emitter.emit(keys.getFileKey(), id, file)\n },\n emitStatusChange: (file: File): void => {\n emitter.emit(keys.getStatusChangeKey(), file)\n },\n emitStatusChangeById: (id: UUID, status: Status): void => {\n emitter.emit(keys.getStatusChangeByIdKey(id), status)\n },\n emitSuccess: (): void => {\n emitter.emit(keys.getSuccessKey())\n },\n emitRemove: (id: UUID, file: File): void => {\n emitter.emit(keys.getRemoveKey(id), file)\n },\n /**\n * Listeners\n */\n\n onAdd: (callback: (id: UUID, file: File) => void): VoidFunction => {\n emitter.on(keys.getFileKey(), callback)\n return () => emitter.removeListener(keys.getFileKey(), callback)\n },\n onStatusChange: (callback: (file: File) => void): VoidFunction => {\n emitter.on(keys.getStatusChangeKey(), callback)\n return () => emitter.removeListener(keys.getStatusChangeKey(), callback)\n },\n onStatusChangeById: (id: UUID, callback: (status: Status) => void): VoidFunction => {\n emitter.on(keys.getStatusChangeByIdKey(id), callback)\n return () => emitter.removeListener(keys.getStatusChangeByIdKey(id), callback)\n },\n onSuccess: (callback: () => void): VoidFunction => {\n emitter.on(keys.getSuccessKey(), callback)\n return () => emitter.removeListener(keys.getSuccessKey(), callback)\n },\n onRemove: (id: UUID, callback: (file: File) => void): VoidFunction => {\n emitter.on(keys.getRemoveKey(id), callback)\n return () => emitter.removeListener(keys.getRemoveKey(id), callback)\n },\n }\n}\n","import dirTree from 'directory-tree'\n\nimport type { DirectoryTree, DirectoryTreeOptions } from 'directory-tree'\n\nexport class TreeNode<T = unknown> {\n public data: T\n\n public parent?: TreeNode<T>\n\n public children: Array<TreeNode<T>>\n\n constructor(data: T, parent?: TreeNode<T>) {\n this.data = data\n this.parent = parent\n return this\n }\n\n addChild(data: T) {\n const child = new TreeNode(data, this)\n if (!this.children) {\n this.children = []\n }\n this.children.push(child)\n return child\n }\n\n find(data: T) {\n if (data === this.data) {\n return this\n }\n\n if (this.children) {\n for (let i = 0, { length } = this.children, target: any = null; i < length; i++) {\n target = this.children[i].find(data)\n if (target) {\n return target\n }\n }\n }\n\n return null\n }\n\n leaves() {\n if (!this.children || this.children.length === 0) {\n // this is a leaf\n return [this]\n }\n\n // if not a leaf, return all children's leaves recursively\n const leaves = []\n if (this.children) {\n for (let i = 0, { length } = this.children; i < length; i++) {\n // eslint-disable-next-line prefer-spread\n leaves.push.apply(leaves, this.children[i].leaves())\n }\n }\n return leaves\n }\n\n root() {\n if (!this.parent) {\n return this\n }\n return this.parent.root()\n }\n\n forEach(callback: (treeNode: TreeNode<T>) => void) {\n if (typeof callback !== 'function') {\n throw new TypeError('forEach() callback must be a function')\n }\n\n // run this node through function\n callback(this)\n\n // do the same for all children\n if (this.children) {\n for (let i = 0, { length } = this.children; i < length; i++) {\n this.children[i].forEach(callback)\n }\n }\n\n return this\n }\n\n public static generate(path: string, options: DirectoryTreeOptions = {}) {\n const filteredTree = dirTree(path, { extensions: options?.extensions, exclude: options.exclude })\n const treeNode = new TreeNode({ name: filteredTree.name, path: filteredTree.path, type: filteredTree.type })\n\n const recurse = (node: typeof treeNode, item: DirectoryTree) => {\n const subNode = node.addChild({ name: item.name, path: item.path, type: item.type })\n\n if (item.children?.length) {\n item.children?.forEach((child) => {\n recurse(subNode, child)\n })\n }\n }\n\n filteredTree.children?.forEach((child) => recurse(treeNode, child))\n\n return treeNode\n }\n}\n","/* eslint-disable no-await-in-loop */\n/* eslint-disable no-restricted-syntax */\n\nimport { definePlugin } from '../../plugin'\nimport { FileManager } from '../fileManager'\n\nimport type { Argument0, Strategy } from './types'\nimport type { KubbConfig, KubbPlugin, PluginLifecycleHooks, PluginLifecycle, MaybePromise, ResolveIdParams } from '../../types'\nimport type { Logger } from '../../build'\nimport type { CorePluginOptions } from '../../plugin'\n\n// inspired by: https://github.com/rollup/rollup/blob/master/src/utils/PluginDriver.ts#\n\n// This will make sure no input hook is omitted\nconst hookNames: {\n [P in PluginLifecycleHooks]: 1\n} = {\n validate: 1,\n buildStart: 1,\n resolveId: 1,\n load: 1,\n transform: 1,\n writeFile: 1,\n buildEnd: 1,\n}\nexport const hooks = Object.keys(hookNames) as [PluginLifecycleHooks]\n\nexport class PluginManager {\n public plugins: KubbPlugin[]\n\n public readonly fileManager: FileManager\n\n private readonly logger?: Logger\n\n private readonly config: KubbConfig\n\n public readonly core: KubbPlugin<CorePluginOptions>\n\n constructor(config: KubbConfig, options: { logger?: Logger }) {\n this.logger = options.logger\n this.config = config\n\n this.fileManager = new FileManager()\n this.core = definePlugin({\n config,\n fileManager: this.fileManager,\n load: this.load,\n resolveId: this.resolveId,\n }) as KubbPlugin<CorePluginOptions> & {\n api: CorePluginOptions['api']\n }\n this.plugins = [this.core, ...(config.plugins || [])]\n }\n\n resolveId = (params: ResolveIdParams) => {\n if (params.pluginName) {\n return this.hookForPlugin(params.pluginName, 'resolveId', [params.fileName, params.directory, params.options])\n }\n return this.hookFirst('resolveId', [params.fileName, params.directory, params.options])\n }\n\n load = async (id: string) => {\n return this.hookFirst('load', [id])\n }\n\n // run only hook for a specific plugin name\n hookForPlugin<H extends PluginLifecycleHooks>(\n pluginName: string,\n hookName: H,\n parameters: Parameters<PluginLifecycle[H]>,\n skipped?: ReadonlySet<KubbPlugin> | null\n ): Promise<ReturnType<PluginLifecycle[H]> | null> {\n let promise: Promise<ReturnType<PluginLifecycle[H]> | null> = Promise.resolve(null)\n for (const plugin of this.getSortedPlugins(hookName, pluginName)) {\n if (skipped && skipped.has(plugin)) continue\n promise = promise.then((result) => {\n if (result != null) return result\n return this.run('hookFirst', hookName, parameters, plugin) as any\n })\n }\n return promise\n }\n\n // chains, first non-null result stops and returns\n hookFirst<H extends PluginLifecycleHooks>(\n hookName: H,\n parameters: Parameters<PluginLifecycle[H]>,\n skipped?: ReadonlySet<KubbPlugin> | null\n ): Promise<ReturnType<PluginLifecycle[H]> | null> {\n let promise: Promise<ReturnType<PluginLifecycle[H]> | null> = Promise.resolve(null)\n for (const plugin of this.getSortedPlugins(hookName)) {\n if (skipped && skipped.has(plugin)) continue\n promise = promise.then((result) => {\n if (result != null) return result\n return this.run('hookFirst', hookName, parameters, plugin) as any\n })\n }\n return promise\n }\n\n // parallel\n async hookParallel<H extends PluginLifecycleHooks, TOuput = void>(hookName: H, parameters?: Parameters<PluginLifecycle[H]> | undefined) {\n const parallelPromises: Promise<TOuput>[] = []\n\n for (const plugin of this.getSortedPlugins(hookName)) {\n if ((plugin[hookName] as { sequential?: boolean })?.sequential) {\n await Promise.all(parallelPromises)\n parallelPromises.length = 0\n await this.run('hookParallel', hookName, parameters, plugin)\n } else {\n const promise: Promise<TOuput> = this.run('hookParallel', hookName, parameters, plugin)\n\n parallelPromises.push(promise)\n }\n }\n return Promise.all(parallelPromises)\n }\n\n // chains, reduces returned value, handling the reduced value as the first hook argument\n hookReduceArg0<H extends PluginLifecycleHooks>(\n hookName: H,\n [argument0, ...rest]: Parameters<PluginLifecycle[H]>,\n reduce: (reduction: Argument0<H>, result: ReturnType<PluginLifecycle[H]>, plugin: KubbPlugin) => MaybePromise<Argument0<H> | null>\n ): Promise<Argument0<H>> {\n let promise = Promise.resolve(argument0)\n for (const plugin of this.getSortedPlugins(hookName)) {\n promise = promise.then((argument0) =>\n this.run('hookReduceArg0', hookName, [argument0, ...rest] as Parameters<PluginLifecycle[H]>, plugin).then((result) =>\n reduce.call(this.core.api, argument0, result, plugin)\n )\n )\n }\n return promise\n }\n\n // chains\n\n hookSeq<H extends PluginLifecycleHooks>(hookName: H, parameters?: Parameters<PluginLifecycle[H]>) {\n let promise: Promise<void> = Promise.resolve()\n for (const plugin of this.getSortedPlugins(hookName)) {\n promise = promise.then(() => this.run('hookSeq', hookName, parameters, plugin))\n }\n return promise.then(noReturn)\n }\n\n private getSortedPlugins(hookName: keyof PluginLifecycle, pluginName?: string): KubbPlugin[] {\n const plugins = [...this.plugins]\n\n if (pluginName) {\n const pluginsByPluginName = plugins.filter((item) => item.name === pluginName && item[hookName])\n if (pluginsByPluginName.length === 0) {\n // fallback on the core plugin when there is no match\n if (this.config.logLevel === 'warn' && this.logger?.spinner) {\n this.logger.spinner.info(`Plugin hook with ${hookName} not found for plugin ${pluginName}`)\n }\n return [this.core]\n }\n return pluginsByPluginName\n }\n\n return plugins\n }\n\n /**\n * Run an async plugin hook and return the result.\n * @param hookName Name of the plugin hook. Must be either in `PluginHooks` or `OutputPluginValueHooks`.\n * @param args Arguments passed to the plugin hook.\n * @param plugin The actual pluginObject to run.\n */\n // Implementation signature\n private run<H extends PluginLifecycleHooks, TResult = void>(\n strategy: Strategy,\n hookName: H,\n parameters: unknown[] | undefined,\n plugin: KubbPlugin\n ): Promise<TResult> {\n const hook = plugin[hookName]!\n\n return Promise.resolve()\n .then(() => {\n if (typeof hook !== 'function') {\n return hook\n }\n\n if (this.config.logLevel === 'info' && this.logger?.spinner) {\n this.logger.spinner.text = `[${strategy}] ${hookName}: Excecuting task for plugin ${plugin.name} \\n`\n }\n\n const hookResult = (hook as any).apply(this.core.api, parameters)\n\n if (!hookResult?.then) {\n // short circuit for non-thenables and non-Promises\n if (this.config.logLevel === 'info' && this.logger?.spinner) {\n this.logger.spinner.succeed(`[${strategy}] ${hookName}: Excecuting task for plugin ${plugin.name} \\n`)\n }\n return hookResult\n }\n\n return Promise.resolve(hookResult).then((result) => {\n // action was fulfilled\n if (this.config.logLevel === 'info' && this.logger?.spinner) {\n this.logger.spinner.succeed(`[${strategy}] ${hookName}: Excecuting task for plugin ${plugin.name} \\n`)\n }\n return result\n })\n })\n .catch((e: Error) => this.catcher<H>(e, plugin, hookName))\n }\n\n /**\n * Run a sync plugin hook and return the result.\n * @param hookName Name of the plugin hook. Must be in `PluginHooks`.\n * @param args Arguments passed to the plugin hook.\n * @param plugin The acutal plugin\n * @param replaceContext When passed, the plugin context can be overridden.\n */\n private runSync<H extends PluginLifecycleHooks>(hookName: H, parameters: Parameters<PluginLifecycle[H]>, plugin: KubbPlugin): ReturnType<PluginLifecycle[H]> {\n const hook = plugin[hookName]!\n\n // const context = this.pluginContexts.get(plugin)!;\n\n try {\n // eslint-disable-next-line @typescript-eslint/ban-types\n return (hook as Function).apply(this.core.api, parameters)\n } catch (error: any) {\n return error\n }\n }\n\n private catcher<H extends PluginLifecycleHooks>(e: Error, plugin: KubbPlugin, hookName: H) {\n const text = `${e.message} (plugin: ${plugin.name}, hook: ${hookName})\\n`\n\n if (this.logger?.spinner) {\n this.logger.spinner.fail(text)\n throw e\n }\n }\n}\n\n// eslint-disable-next-line @typescript-eslint/no-empty-function\nfunction noReturn() {}\n","import type { MaybePromise, KubbUserConfig, CLIOptions } from './types'\n\n/**\n * Type helper to make it easier to use kubb.config.ts\n * accepts a direct {@link KubbConfig} object, or a function that returns it.\n * The function receives a {@link ConfigEnv} object that exposes two properties:\n */\nexport const defineConfig = (\n options:\n | MaybePromise<KubbUserConfig>\n | ((\n /** The options derived from the CLI flags */\n cliOptions: CLIOptions\n ) => MaybePromise<KubbUserConfig>)\n) => options\n","/* eslint-disable @typescript-eslint/no-empty-interface */\nimport { build } from './build'\n\nexport * from './config'\nexport * from './build'\nexport { CorePluginOptions, createPlugin } from './plugin'\nexport * from './utils'\nexport * from './types'\nexport * from './managers'\nexport default build\n"]}
package/dist/index.mjs CHANGED
@@ -78,6 +78,61 @@ var getPathMode = (path) => {
78
78
  return pathParser.extname(path) ? "file" : "directory";
79
79
  };
80
80
 
81
+ // src/plugin.ts
82
+ function createPlugin(factory) {
83
+ return (options) => {
84
+ const plugin = factory(options);
85
+ if (Array.isArray(plugin)) {
86
+ throw new Error("Not implemented");
87
+ }
88
+ if (!plugin.transform) {
89
+ plugin.transform = function transform(code) {
90
+ return code;
91
+ };
92
+ }
93
+ return plugin;
94
+ };
95
+ }
96
+ var name = "core";
97
+ var isEmittedFile = (result) => {
98
+ return !!result.id;
99
+ };
100
+ var definePlugin = createPlugin((options) => {
101
+ const { fileManager, resolveId, load } = options;
102
+ const api = {
103
+ get config() {
104
+ return options.config;
105
+ },
106
+ fileManager,
107
+ async addFile(file, options2) {
108
+ if (isEmittedFile(file)) {
109
+ const resolvedId = await resolveId({ fileName: file.id, directory: file.importer, options: file.options });
110
+ const path = resolvedId || file.importer || file.id;
111
+ return fileManager.add({
112
+ path,
113
+ fileName: file.name || file.id,
114
+ source: file.source || ""
115
+ });
116
+ }
117
+ if (options2?.root) ;
118
+ return fileManager.addOrAppend(file);
119
+ },
120
+ resolveId,
121
+ load,
122
+ cache: createPluginCache(/* @__PURE__ */ Object.create(null))
123
+ };
124
+ return {
125
+ name,
126
+ api,
127
+ resolveId(fileName, directory) {
128
+ if (!directory) {
129
+ return null;
130
+ }
131
+ return pathParser.resolve(directory, fileName);
132
+ }
133
+ };
134
+ });
135
+
81
136
  // src/managers/fileManager/events.ts
82
137
  var keys = {
83
138
  getFileKey: () => `file`,
@@ -125,82 +180,6 @@ var getFileManagerEvents = (emitter) => {
125
180
  }
126
181
  };
127
182
  };
128
- var TreeNode = class {
129
- data;
130
- parent;
131
- children;
132
- constructor(data, parent) {
133
- this.data = data;
134
- this.parent = parent;
135
- return this;
136
- }
137
- addChild(data) {
138
- const child = new TreeNode(data, this);
139
- if (!this.children) {
140
- this.children = [];
141
- }
142
- this.children.push(child);
143
- return child;
144
- }
145
- find(data) {
146
- if (data === this.data) {
147
- return this;
148
- }
149
- if (this.children) {
150
- for (let i = 0, { length } = this.children, target = null; i < length; i++) {
151
- target = this.children[i].find(data);
152
- if (target) {
153
- return target;
154
- }
155
- }
156
- }
157
- return null;
158
- }
159
- leaves() {
160
- if (!this.children || this.children.length === 0) {
161
- return [this];
162
- }
163
- const leaves = [];
164
- if (this.children) {
165
- for (let i = 0, { length } = this.children; i < length; i++) {
166
- leaves.push.apply(leaves, this.children[i].leaves());
167
- }
168
- }
169
- return leaves;
170
- }
171
- root() {
172
- if (!this.parent) {
173
- return this;
174
- }
175
- return this.parent.root();
176
- }
177
- forEach(callback) {
178
- if (typeof callback !== "function") {
179
- throw new TypeError("forEach() callback must be a function");
180
- }
181
- callback(this);
182
- if (this.children) {
183
- for (let i = 0, { length } = this.children; i < length; i++) {
184
- this.children[i].forEach(callback);
185
- }
186
- }
187
- return this;
188
- }
189
- static generate(path, options = {}) {
190
- const filteredTree = dirTree(path, { extensions: options?.extensions, exclude: options.exclude });
191
- const treeNode = new TreeNode({ name: filteredTree.name, path: filteredTree.path, type: filteredTree.type });
192
- const recurse = (node, item) => {
193
- const subNode = node.addChild({ name: item.name, path: item.path, type: item.type });
194
- if (item.children?.length) {
195
- item.children?.forEach((child) => {
196
- recurse(subNode, child);
197
- });
198
- }
199
- };
200
- filteredTree.children?.forEach((child) => recurse(treeNode, child));
201
- return treeNode;
202
- }
203
- };
204
183
 
205
184
  // src/managers/fileManager/FileManager.ts
206
185
  var FileManager = class {
@@ -287,109 +266,83 @@ ${file.source}`
287
266
  this.setStatus(id, "removed");
288
267
  this.events.emitRemove(id, cacheItem.file);
289
268
  }
290
- static writeIndexes(root, output, options) {
291
- const tree = TreeNode.generate(output, { extensions: /\.ts/, ...options });
292
- const fileReducer = (files2, item) => {
293
- if (!item.children) {
294
- return [];
269
+ };
270
+ var TreeNode = class {
271
+ data;
272
+ parent;
273
+ children;
274
+ constructor(data, parent) {
275
+ this.data = data;
276
+ this.parent = parent;
277
+ return this;
278
+ }
279
+ addChild(data) {
280
+ const child = new TreeNode(data, this);
281
+ if (!this.children) {
282
+ this.children = [];
283
+ }
284
+ this.children.push(child);
285
+ return child;
286
+ }
287
+ find(data) {
288
+ if (data === this.data) {
289
+ return this;
290
+ }
291
+ if (this.children) {
292
+ for (let i = 0, { length } = this.children, target = null; i < length; i++) {
293
+ target = this.children[i].find(data);
294
+ if (target) {
295
+ return target;
296
+ }
295
297
  }
296
- if (item.children?.length > 1) {
297
- const path = pathParser.resolve(root, item.data.path, "index.ts");
298
- const source = item.children.reduce((source2, file) => {
299
- if (!file) {
300
- return source2;
301
- }
302
- const importPath = file.data.type === "directory" ? `./${file.data.name}` : `./${file.data.name.replace(/\.[^.]*$/, "")}`;
303
- if (importPath.includes("index") && path.includes("index")) {
304
- return source2;
305
- }
306
- return `${source2}export * from "${importPath}";
307
- `;
308
- }, "");
309
- files2.push({
310
- path,
311
- fileName: "index.ts",
312
- source
313
- });
314
- } else {
315
- item.children?.forEach((child) => {
316
- const path = pathParser.resolve(root, item.data.path, "index.ts");
317
- const importPath = child.data.type === "directory" ? `./${child.data.name}` : `./${child.data.name.replace(/\.[^.]*$/, "")}`;
318
- files2.push({
319
- path,
320
- fileName: "index.ts",
321
- source: `export * from "${importPath}";
322
- `
323
- });
324
- });
298
+ }
299
+ return null;
300
+ }
301
+ leaves() {
302
+ if (!this.children || this.children.length === 0) {
303
+ return [this];
304
+ }
305
+ const leaves = [];
306
+ if (this.children) {
307
+ for (let i = 0, { length } = this.children; i < length; i++) {
308
+ leaves.push.apply(leaves, this.children[i].leaves());
325
309
  }
326
- item.children.forEach((childItem) => {
327
- fileReducer(files2, childItem);
328
- });
329
- return files2;
330
- };
331
- const files = fileReducer([], tree);
332
- return files.map((file) => write(file.source, file.path));
310
+ }
311
+ return leaves;
333
312
  }
334
- };
335
-
336
- // src/plugin.ts
337
- function createPlugin(factory) {
338
- return (options) => {
339
- const plugin = factory(options);
340
- if (Array.isArray(plugin)) {
341
- throw new Error("Not implemented");
313
+ root() {
314
+ if (!this.parent) {
315
+ return this;
342
316
  }
343
- if (!plugin.transform) {
344
- plugin.transform = function transform(code) {
345
- return code;
346
- };
317
+ return this.parent.root();
318
+ }
319
+ forEach(callback) {
320
+ if (typeof callback !== "function") {
321
+ throw new TypeError("forEach() callback must be a function");
347
322
  }
348
- return plugin;
349
- };
350
- }
351
- var name = "core";
352
- var isEmittedFile = (result) => {
353
- return !!result.id;
354
- };
355
- var definePlugin = createPlugin((options) => {
356
- const { fileManager, resolveId, load } = options;
357
- const api = {
358
- get config() {
359
- return options.config;
360
- },
361
- fileManager,
362
- async addFile(file, options2) {
363
- if (isEmittedFile(file)) {
364
- const resolvedId = await resolveId({ fileName: file.id, directory: file.importer, options: file.options });
365
- const path = resolvedId || file.importer || file.id;
366
- return fileManager.add({
367
- path,
368
- fileName: file.name || file.id,
369
- source: file.source || ""
370
- });
371
- }
372
- if (options2?.root) ;
373
- return fileManager.addOrAppend(file);
374
- },
375
- resolveId,
376
- load,
377
- cache: createPluginCache(/* @__PURE__ */ Object.create(null))
378
- };
379
- return {
380
- name,
381
- api,
382
- async buildEnd() {
383
- await FileManager.writeIndexes(this.config.root, this.config.output.path, { exclude: [/schemas/, /json/] });
384
- },
385
- resolveId(fileName, directory) {
386
- if (!directory) {
387
- return null;
323
+ callback(this);
324
+ if (this.children) {
325
+ for (let i = 0, { length } = this.children; i < length; i++) {
326
+ this.children[i].forEach(callback);
388
327
  }
389
- return pathParser.resolve(directory, fileName);
390
328
  }
391
- };
392
- });
329
+ return this;
330
+ }
331
+ static generate(path, options = {}) {
332
+ const filteredTree = dirTree(path, { extensions: options?.extensions, exclude: options.exclude });
333
+ const treeNode = new TreeNode({ name: filteredTree.name, path: filteredTree.path, type: filteredTree.type });
334
+ const recurse = (node, item) => {
335
+ const subNode = node.addChild({ name: item.name, path: item.path, type: item.type });
336
+ if (item.children?.length) {
337
+ item.children?.forEach((child) => {
338
+ recurse(subNode, child);
339
+ });
340
+ }
341
+ };
342
+ filteredTree.children?.forEach((child) => recurse(treeNode, child));
343
+ return treeNode;
344
+ }
345
+ };
393
346
 
394
347
  // src/managers/pluginManager/PluginManager.ts
395
348
  var hookNames = {
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/build.ts","../src/plugin.ts","../src/utils/isPromise.ts","../src/utils/write.ts","../src/utils/format.ts","../src/utils/cache.ts","../src/utils/read.ts","../src/managers/fileManager/FileManager.ts","../src/managers/fileManager/events.ts","../src/managers/fileManager/TreeNode.ts","../src/managers/pluginManager/PluginManager.ts","../src/config.ts","../src/index.ts"],"names":["fse","pathParser","file","files","source","options","argument0"],"mappings":";AAAA,OAAOA,UAAS;;;ACAhB,OAAOC,iBAAgB;;;ACEhB,IAAM,YAAY,CAAI,WAAkD;AAC7E,SAAO,OAAQ,QAAgB,SAAS;AAC1C;;;ACHA,OAAO,SAAS;;;ACDhB,SAAS,UAAU,sBAAsB;AAIzC,IAAM,gBAAyB;AAAA,EAC7B,UAAU;AAAA,EACV,YAAY;AAAA,EACZ,QAAQ;AAAA,EACR,aAAa;AAAA,EACb,MAAM;AAAA,EACN,iBAAiB;AAAA,EACjB,WAAW;AACb;AACO,IAAM,SAAS,CAAC,SAAiB;AACtC,SAAO,eAAe,MAAM,a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P,GAAG,GAAI;AAAA,EACT,CAAC;AAED,cAAY,OAAO,MAAM,OAAO,IAAI,SAAS;AAC3C,UAAM,EAAE,KAAK,IAAI;AACjB,QAAI,EAAE,QAAQ,KAAK,IAAI;AAEvB,UAAM,eAAe,MAAM,cAAc,UAAU,QAAQ,CAAC,IAAI,CAAC;AACjE,QAAI,cAAc;AAChB,aAAO;AAAA,IACT;AAEA,QAAI,MAAM;AACR,YAAM,kBAAkB,MAAM,cAAc,eAAe,aAAa,CAAC,MAAM,IAAI,GAAG,gBAAgB;AAEtG,YAAM,cAAc,aAAa,aAAa,CAAC,iBAAiB,IAAI,CAAC;AACrE,kBAAY,UAAU,IAAI,SAAS;AACnC,kBAAY,OAAO,EAAE;AAAA,IACvB;AAAA,EACF,CAAC;AAED,QAAM,cAAc,aAAa,cAAc,CAAC,MAAM,CAAC;AACzD;AAEO,SAAS,MAAM,SAA6C;AACjE,SAAO,IAAI,QAAQ,CAAC,SAAS,WAAW;AACtC,QAAI;AACF,0BAAoB,SAAS,OAAO;AAAA,IACtC,SAAS,GAAP;AACA,aAAO,CAAC;AAAA,IACV;AAAA,EACF,CAAC;AACH;;;AWxFO,IAAM,eAAe,CAC1B,YAMG;;;ACLL,IAAO,cAAQ","sourcesContent":["import fse from 'fs-extra'\n\nimport { PluginManager } from './managers/pluginManager'\n\nimport type { PluginContext, TransformResult, ValidationResult, LogLevel, KubbPlugin } from './types'\n\ntype BuildOutput = void\n\n// Same type as ora\ntype Spinner = {\n start: (text?: string) => Spinner\n succeed: (text: string) => Spinner\n fail: (text?: string) => Spinner\n stopAndPersist: (options: { text: string }) => Spinner\n render: () => Spinner\n text: string\n info: (text: string) => Spinner\n}\n\nexport type Logger = {\n log: (message: string, logLevel: LogLevel) => void\n spinner?: Spinner\n}\ntype BuildOptions = {\n config: PluginContext['config']\n mode: 'development' | 'production'\n logger?: Logger\n}\n\nasync function transformReducer(this: PluginContext, _previousCode: string, result: TransformResult, _plugin: KubbPlugin) {\n if (result === null) {\n return null\n }\n return result\n}\n\nasync function buildImplementation(options: BuildOptions, done: (output: BuildOutput) => void) {\n const { config, logger } = options\n\n if (config.output.clean) {\n await fse.remove(config.output.path)\n }\n\n const pluginManager = new PluginManager(config, { logger })\n const { plugins, fileManager } = pluginManager\n\n const validations = await pluginManager.hookParallel<'validate', ValidationResult>('validate', [plugins])\n const validationsWithMessage = validations.filter(Boolean)\n\n if (validationsWithMessage.some((validation) => typeof validation !== 'boolean')) {\n validationsWithMessage.forEach((validation) => {\n if (validation && typeof validation !== 'boolean' && validation?.message) {\n logger?.log(validation.message, 'warn')\n }\n })\n\n return\n }\n\n fileManager.events.onSuccess(async () => {\n await pluginManager.hookParallel('buildEnd')\n setTimeout(() => {\n done()\n }, 1000)\n })\n\n fileManager.events.onAdd(async (id, file) => {\n const { path } = file\n let { source: code } = file\n\n const loadedResult = await pluginManager.hookFirst('load', [path])\n if (loadedResult) {\n code = loadedResult\n }\n\n if (code) {\n const transformedCode = await pluginManager.hookReduceArg0('transform', [code, path], transformReducer)\n\n await pluginManager.hookParallel('writeFile', [transformedCode, path])\n fileManager.setStatus(id, 'success')\n fileManager.remove(id)\n }\n })\n\n await pluginManager.hookParallel('buildStart', [config])\n}\n\nexport function build(options: BuildOptions): Promise<BuildOutput> {\n return new Promise((resolve, reject) => {\n try {\n buildImplementation(options, resolve)\n } catch (e) {\n reject(e)\n }\n })\n}\n","import pathParser from 'path'\n\nimport { createPluginCache } from './utils'\nimport { FileManager } from './managers/fileManager'\n\nimport type { EmittedFile, File } from './managers/fileManager'\nimport type { PluginContext, KubbPlugin, PluginFactoryOptions } from './types'\n\ntype KubbPluginFactory<T extends PluginFactoryOptions = PluginFactoryOptions> = (\n options: T['options']\n) => T['nested'] extends true ? Array<KubbPlugin<T>> : KubbPlugin<T>\n\nexport function createPlugin<T extends PluginFactoryOptions = PluginFactoryOptions>(factory: KubbPluginFactory<T>) {\n return (options: T['options']) => {\n const plugin = factory(options)\n if (Array.isArray(plugin)) {\n throw new Error('Not implemented')\n }\n\n // default transform\n if (!plugin.transform) {\n plugin.transform = function transform(code) {\n return code\n }\n }\n\n return plugin\n }\n}\n\ntype Options = {\n config: PluginContext['config']\n fileManager: FileManager\n resolveId: PluginContext['resolveId']\n load: PluginContext['load']\n}\n\n// not publicly exported\nexport type CorePluginOptions = PluginFactoryOptions<Options, false, PluginContext>\n\nexport const name = 'core' as const\n\nconst isEmittedFile = (result: EmittedFile | File): result is EmittedFile => {\n return !!(result as any).id\n}\n\nexport const definePlugin = createPlugin<CorePluginOptions>((options) => {\n const { fileManager, resolveId, load } = options\n const indexFiles: File[] = []\n\n const api: PluginContext = {\n get config() {\n return options.config\n },\n fileManager,\n async addFile(file, options) {\n if (isEmittedFile(file)) {\n const resolvedId = await resolveId({ fileName: file.id, directory: file.importer, options: file.options })\n const path = resolvedId || file.importer || file.id\n\n return fileManager.add({\n path,\n fileName: file.name || file.id,\n source: file.source || '',\n })\n }\n\n if (options?.root) {\n indexFiles.push(file)\n }\n\n return fileManager.addOrAppend(file)\n },\n resolveId,\n load,\n cache: createPluginCache(Object.create(null)),\n }\n\n return {\n name,\n api,\n async buildEnd() {\n await FileManager.writeIndexes(this.config.root, this.config.output.path, { exclude: [/schemas/, /json/] })\n },\n resolveId(fileName, directory) {\n if (!directory) {\n return null\n }\n return pathParser.resolve(directory, fileName)\n },\n }\n})\n","import type { MaybePromise } from '../types'\n\nexport const isPromise = <T>(result: MaybePromise<T>): result is Promise<T> => {\n return typeof (result as any)?.then === 'function'\n}\n","/* eslint-disable consistent-return */\nimport fse from 'fs-extra'\n\nimport { format } from './format'\n\ntype WriteOptions = {\n format: boolean\n}\n\nexport const write = async (data: string, path: string, options: WriteOptions = { format: false }) => {\n const formattedData = options.format ? format(data) : data\n\n try {\n await fse.stat(path)\n const oldContent = await fse.readFile(path, { encoding: 'utf-8' })\n if (oldContent?.toString() === formattedData) {\n return\n }\n } catch (_err) {\n return fse.outputFile(path, formattedData)\n }\n\n return fse.outputFile(path, formattedData)\n}\n","import { format as prettierFormat } from 'prettier'\n\nimport type { Options } from 'prettier'\n\nconst formatOptions: Options = {\n tabWidth: 2,\n printWidth: 160,\n parser: 'typescript',\n singleQuote: true,\n semi: false,\n bracketSameLine: false,\n endOfLine: 'auto',\n}\nexport const format = (text: string) => {\n return prettierFormat(text, formatOptions)\n}\n","/* eslint-disable no-param-reassign */\n/* eslint-disable consistent-return */\n\nexport interface Cache<TCache = any> {\n delete(id: string): boolean\n get<T = TCache>(id: string): T\n has(id: string): boolean\n set<T = TCache>(id: string, value: T): void\n}\n\nexport function createPluginCache(cache: any): Cache {\n return {\n delete(id: string) {\n return delete cache[id]\n },\n get(id: string) {\n const item = cache[id]\n if (!item) return\n item[0] = 0\n return item[1]\n },\n has(id: string) {\n const item = cache[id]\n if (!item) return false\n item[0] = 0\n return true\n },\n set(id: string, value: any) {\n cache[id] = [0, value]\n },\n }\n}\n","import pathParser from 'path'\n\n// TODO check for a better way or resolving the relative path\nexport const getRelativePath = (root?: string | null, file?: string | null) => {\n if (!root || !file) {\n throw new Error('Root and file should be filled in when retrieving the relativePath')\n }\n const newPath = pathParser.relative(root, file).replace('../', '').replace('.ts', '').trimEnd()\n\n return `./${newPath}`\n}\n\nexport const getPathMode = (path: string | undefined | null) => {\n if (!path) {\n return undefined\n }\n return pathParser.extname(path) ? 'file' : 'directory'\n}\n","import EventEmitter from 'events'\nimport { randomUUID } from 'crypto'\nimport pathParser from 'path'\n\nimport { getFileManagerEvents } from './events'\nimport { TreeNode } from './TreeNode'\n\nimport { write } from '../../utils/write'\n\nimport type { CacheStore, UUID, Status, File } from './types'\n\nexport class FileManager {\n private cache: Map<CacheStore['id'], CacheStore> = new Map()\n\n emitter = new EventEmitter()\n\n events = getFileManagerEvents(this.emitter)\n\n constructor() {\n this.events.onStatusChange(() => {\n if (this.getCountByStatus('removed') === this.cache.size) {\n // all files are been resolved and written to the file system\n this.events.emitSuccess()\n }\n })\n }\n\n private getCache(id: UUID) {\n return this.cache.get(id)\n }\n\n private getCacheByPath(path: string | undefined): CacheStore | undefined {\n let cache\n\n this.cache.forEach((item) => {\n if (item.file.path === path) {\n cache = item\n }\n })\n return cache as CacheStore\n }\n\n private getCountByStatus(status: Status) {\n let count = 0\n\n this.cache.forEach((item) => {\n if (item.status === status) {\n count++\n }\n })\n return count\n }\n\n get files() {\n const files: File[] = []\n this.cache.forEach((item) => {\n files.push(item.file)\n })\n\n return files\n }\n\n add(file: File) {\n const cacheItem = { id: randomUUID(), file, status: 'new' as Status }\n\n this.cache.set(cacheItem.id, cacheItem)\n this.events.emitFile(cacheItem.id, file)\n\n return new Promise<File>((resolve) => {\n const unsubscribe = this.events.onRemove(cacheItem.id, (file) => {\n resolve(file)\n unsubscribe()\n })\n })\n }\n\n addOrAppend(file: File) {\n const previousCache = this.getCacheByPath(file.path)\n\n if (previousCache) {\n this.remove(previousCache.id)\n return this.add({\n ...file,\n source: `${previousCache.file.source}\\n${file.source}`,\n })\n }\n return this.add(file)\n }\n\n setStatus(id: UUID, status: Status) {\n const cacheItem = this.getCache(id)\n if (!cacheItem) {\n return\n }\n\n cacheItem.status = status\n this.cache.set(id, cacheItem)\n this.events.emitStatusChange(cacheItem.file)\n this.events.emitStatusChangeById(id, status)\n }\n\n get(id: UUID) {\n const cacheItem = this.getCache(id)\n return cacheItem?.file\n }\n\n remove(id: UUID) {\n const cacheItem = this.getCache(id)\n if (!cacheItem) {\n return\n }\n\n this.setStatus(id, 'removed')\n this.events.emitRemove(id, cacheItem.file)\n }\n\n public static writeIndexes(root: string, output: string, options: Parameters<typeof TreeNode.generate>[1]) {\n const tree = TreeNode.generate(output, { extensions: /\\.ts/, ...options })\n\n const fileReducer = (files: File[], item: typeof tree) => {\n if (!item.children) {\n return []\n }\n\n if (item.children?.length > 1) {\n const path = pathParser.resolve(root, item.data.path, 'index.ts')\n const source = item.children.reduce((source, file) => {\n if (!file) {\n return source\n }\n\n const importPath: string = file.data.type === 'directory' ? `./${file.data.name}` : `./${file.data.name.replace(/\\.[^.]*$/, '')}`\n\n // TODO weird hacky fix\n if (importPath.includes('index') && path.includes('index')) {\n return source\n }\n\n return `${source}export * from \"${importPath}\";\\n`\n }, '')\n\n files.push({\n path,\n fileName: 'index.ts',\n source,\n })\n } else {\n item.children?.forEach((child) => {\n const path = pathParser.resolve(root, item.data.path, 'index.ts')\n const importPath = child.data.type === 'directory' ? `./${child.data.name}` : `./${child.data.name.replace(/\\.[^.]*$/, '')}`\n\n files.push({\n path,\n fileName: 'index.ts',\n source: `export * from \"${importPath}\";\\n`,\n })\n })\n }\n\n item.children.forEach((childItem) => {\n fileReducer(files, childItem)\n })\n\n return files\n }\n\n const files = fileReducer([], tree)\n\n return files.map((file) => write(file.source, file.path))\n }\n}\n","import type EventEmitter from 'events'\nimport type { File, Status, UUID } from './types'\n\nconst keys = {\n getFileKey: () => `file`,\n getStatusChangeKey: () => `status-change`,\n getStatusChangeByIdKey: (id: string) => `${id}-status-change`,\n getSuccessKey: () => `success`,\n getRemoveKey: (id: string) => `${id}remove`,\n} as const\n\ntype VoidFunction = () => void\n\nexport const getFileManagerEvents = (emitter: EventEmitter) => {\n return {\n /**\n * Emiter\n */\n emitFile: (id: UUID, file: File): void => {\n emitter.emit(keys.getFileKey(), id, file)\n },\n emitStatusChange: (file: File): void => {\n emitter.emit(keys.getStatusChangeKey(), file)\n },\n emitStatusChangeById: (id: UUID, status: Status): void => {\n emitter.emit(keys.getStatusChangeByIdKey(id), status)\n },\n emitSuccess: (): void => {\n emitter.emit(keys.getSuccessKey())\n },\n emitRemove: (id: UUID, file: File): void => {\n emitter.emit(keys.getRemoveKey(id), file)\n },\n /**\n * Listeners\n */\n\n onAdd: (callback: (id: UUID, file: File) => void): VoidFunction => {\n emitter.on(keys.getFileKey(), callback)\n return () => emitter.removeListener(keys.getFileKey(), callback)\n },\n onStatusChange: (callback: (file: File) => void): VoidFunction => {\n emitter.on(keys.getStatusChangeKey(), callback)\n return () => emitter.removeListener(keys.getStatusChangeKey(), callback)\n },\n onStatusChangeById: (id: UUID, callback: (status: Status) => void): VoidFunction => {\n emitter.on(keys.getStatusChangeByIdKey(id), callback)\n return () => emitter.removeListener(keys.getStatusChangeByIdKey(id), callback)\n },\n onSuccess: (callback: () => void): VoidFunction => {\n emitter.on(keys.getSuccessKey(), callback)\n return () => emitter.removeListener(keys.getSuccessKey(), callback)\n },\n onRemove: (id: UUID, callback: (file: File) => void): VoidFunction => {\n emitter.on(keys.getRemoveKey(id), callback)\n return () => emitter.removeListener(keys.getRemoveKey(id), callback)\n },\n }\n}\n","import dirTree from 'directory-tree'\n\nimport type { DirectoryTree, DirectoryTreeOptions } from 'directory-tree'\n\nexport class TreeNode<T = unknown> {\n public data: T\n\n public parent?: TreeNode<T>\n\n public children: Array<TreeNode<T>>\n\n constructor(data: T, parent?: TreeNode<T>) {\n this.data = data\n this.parent = parent\n return this\n }\n\n addChild(data: T) {\n const child = new TreeNode(data, this)\n if (!this.children) {\n this.children = []\n }\n this.children.push(child)\n return child\n }\n\n find(data: T) {\n if (data === this.data) {\n return this\n }\n\n if (this.children) {\n for (let i = 0, { length } = this.children, target: any = null; i < length; i++) {\n target = this.children[i].find(data)\n if (target) {\n return target\n }\n }\n }\n\n return null\n }\n\n leaves() {\n if (!this.children || this.children.length === 0) {\n // this is a leaf\n return [this]\n }\n\n // if not a leaf, return all children's leaves recursively\n const leaves = []\n if (this.children) {\n for (let i = 0, { length } = this.children; i < length; i++) {\n // eslint-disable-next-line prefer-spread\n leaves.push.apply(leaves, this.children[i].leaves())\n }\n }\n return leaves\n }\n\n root() {\n if (!this.parent) {\n return this\n }\n return this.parent.root()\n }\n\n forEach(callback: (treeNode: TreeNode<T>) => void) {\n if (typeof callback !== 'function') {\n throw new TypeError('forEach() callback must be a function')\n }\n\n // run this node through function\n callback(this)\n\n // do the same for all children\n if (this.children) {\n for (let i = 0, { length } = this.children; i < length; i++) {\n this.children[i].forEach(callback)\n }\n }\n\n return this\n }\n\n public static generate(path: string, options: DirectoryTreeOptions = {}) {\n const filteredTree = dirTree(path, { extensions: options?.extensions, exclude: options.exclude })\n const treeNode = new TreeNode({ name: filteredTree.name, path: filteredTree.path, type: filteredTree.type })\n\n const recurse = (node: typeof treeNode, item: DirectoryTree) => {\n const subNode = node.addChild({ name: item.name, path: item.path, type: item.type })\n\n if (item.children?.length) {\n item.children?.forEach((child) => {\n recurse(subNode, child)\n })\n }\n }\n\n filteredTree.children?.forEach((child) => recurse(treeNode, child))\n\n return treeNode\n }\n}\n","/* eslint-disable no-await-in-loop */\n/* eslint-disable no-restricted-syntax */\n\nimport { definePlugin } from '../../plugin'\nimport { FileManager } from '../fileManager'\n\nimport type { Argument0, Strategy } from './types'\nimport type { KubbConfig, KubbPlugin, PluginLifecycleHooks, PluginLifecycle, MaybePromise, ResolveIdParams } from '../../types'\nimport type { Logger } from '../../build'\nimport type { CorePluginOptions } from '../../plugin'\n\n// inspired by: https://github.com/rollup/rollup/blob/master/src/utils/PluginDriver.ts#\n\n// This will make sure no input hook is omitted\nconst hookNames: {\n [P in PluginLifecycleHooks]: 1\n} = {\n validate: 1,\n buildStart: 1,\n resolveId: 1,\n load: 1,\n transform: 1,\n writeFile: 1,\n buildEnd: 1,\n}\nexport const hooks = Object.keys(hookNames) as [PluginLifecycleHooks]\n\nexport class PluginManager {\n public plugins: KubbPlugin[]\n\n public readonly fileManager: FileManager\n\n private readonly logger?: Logger\n\n private readonly config: KubbConfig\n\n public readonly core: KubbPlugin<CorePluginOptions>\n\n constructor(config: KubbConfig, options: { logger?: Logger }) {\n this.logger = options.logger\n this.config = config\n\n this.fileManager = new FileManager()\n this.core = definePlugin({\n config,\n fileManager: this.fileManager,\n load: this.load,\n resolveId: this.resolveId,\n }) as KubbPlugin<CorePluginOptions> & {\n api: CorePluginOptions['api']\n }\n this.plugins = [this.core, ...(config.plugins || [])]\n }\n\n resolveId = (params: ResolveIdParams) => {\n if (params.pluginName) {\n return this.hookForPlugin(params.pluginName, 'resolveId', [params.fileName, params.directory, params.options])\n }\n return this.hookFirst('resolveId', [params.fileName, params.directory, params.options])\n }\n\n load = async (id: string) => {\n return this.hookFirst('load', [id])\n }\n\n // run only hook for a specific plugin name\n hookForPlugin<H extends PluginLifecycleHooks>(\n pluginName: string,\n hookName: H,\n parameters: Parameters<PluginLifecycle[H]>,\n skipped?: ReadonlySet<KubbPlugin> | null\n ): Promise<ReturnType<PluginLifecycle[H]> | null> {\n let promise: Promise<ReturnType<PluginLifecycle[H]> | null> = Promise.resolve(null)\n for (const plugin of this.getSortedPlugins(hookName, pluginName)) {\n if (skipped && skipped.has(plugin)) continue\n promise = promise.then((result) => {\n if (result != null) return result\n return this.run('hookFirst', hookName, parameters, plugin) as any\n })\n }\n return promise\n }\n\n // chains, first non-null result stops and returns\n hookFirst<H extends PluginLifecycleHooks>(\n hookName: H,\n parameters: Parameters<PluginLifecycle[H]>,\n skipped?: ReadonlySet<KubbPlugin> | null\n ): Promise<ReturnType<PluginLifecycle[H]> | null> {\n let promise: Promise<ReturnType<PluginLifecycle[H]> | null> = Promise.resolve(null)\n for (const plugin of this.getSortedPlugins(hookName)) {\n if (skipped && skipped.has(plugin)) continue\n promise = promise.then((result) => {\n if (result != null) return result\n return this.run('hookFirst', hookName, parameters, plugin) as any\n })\n }\n return promise\n }\n\n // parallel\n async hookParallel<H extends PluginLifecycleHooks, TOuput = void>(hookName: H, parameters?: Parameters<PluginLifecycle[H]> | undefined) {\n const parallelPromises: Promise<TOuput>[] = []\n\n for (const plugin of this.getSortedPlugins(hookName)) {\n if ((plugin[hookName] as { sequential?: boolean })?.sequential) {\n await Promise.all(parallelPromises)\n parallelPromises.length = 0\n await this.run('hookParallel', hookName, parameters, plugin)\n } else {\n const promise: Promise<TOuput> = this.run('hookParallel', hookName, parameters, plugin)\n\n parallelPromises.push(promise)\n }\n }\n return Promise.all(parallelPromises)\n }\n\n // chains, reduces returned value, handling the reduced value as the first hook argument\n hookReduceArg0<H extends PluginLifecycleHooks>(\n hookName: H,\n [argument0, ...rest]: Parameters<PluginLifecycle[H]>,\n reduce: (reduction: Argument0<H>, result: ReturnType<PluginLifecycle[H]>, plugin: KubbPlugin) => MaybePromise<Argument0<H> | null>\n ): Promise<Argument0<H>> {\n let promise = Promise.resolve(argument0)\n for (const plugin of this.getSortedPlugins(hookName)) {\n promise = promise.then((argument0) =>\n this.run('hookReduceArg0', hookName, [argument0, ...rest] as Parameters<PluginLifecycle[H]>, plugin).then((result) =>\n reduce.call(this.core.api, argument0, result, plugin)\n )\n )\n }\n return promise\n }\n\n // chains\n\n hookSeq<H extends PluginLifecycleHooks>(hookName: H, parameters?: Parameters<PluginLifecycle[H]>) {\n let promise: Promise<void> = Promise.resolve()\n for (const plugin of this.getSortedPlugins(hookName)) {\n promise = promise.then(() => this.run('hookSeq', hookName, parameters, plugin))\n }\n return promise.then(noReturn)\n }\n\n private getSortedPlugins(hookName: keyof PluginLifecycle, pluginName?: string): KubbPlugin[] {\n const plugins = [...this.plugins]\n\n if (pluginName) {\n const pluginsByPluginName = plugins.filter((item) => item.name === pluginName && item[hookName])\n if (pluginsByPluginName.length === 0) {\n // fallback on the core plugin when there is no match\n if (this.config.logLevel === 'warn' && this.logger?.spinner) {\n this.logger.spinner.info(`Plugin hook with ${hookName} not found for plugin ${pluginName}`)\n }\n return [this.core]\n }\n return pluginsByPluginName\n }\n\n return plugins\n }\n\n /**\n * Run an async plugin hook and return the result.\n * @param hookName Name of the plugin hook. Must be either in `PluginHooks` or `OutputPluginValueHooks`.\n * @param args Arguments passed to the plugin hook.\n * @param plugin The actual pluginObject to run.\n */\n // Implementation signature\n private run<H extends PluginLifecycleHooks, TResult = void>(\n strategy: Strategy,\n hookName: H,\n parameters: unknown[] | undefined,\n plugin: KubbPlugin\n ): Promise<TResult> {\n const hook = plugin[hookName]!\n\n return Promise.resolve()\n .then(() => {\n if (typeof hook !== 'function') {\n return hook\n }\n\n if (this.config.logLevel === 'info' && this.logger?.spinner) {\n this.logger.spinner.text = `[${strategy}] ${hookName}: Excecuting task for plugin ${plugin.name} \\n`\n }\n\n const hookResult = (hook as any).apply(this.core.api, parameters)\n\n if (!hookResult?.then) {\n // short circuit for non-thenables and non-Promises\n if (this.config.logLevel === 'info' && this.logger?.spinner) {\n this.logger.spinner.succeed(`[${strategy}] ${hookName}: Excecuting task for plugin ${plugin.name} \\n`)\n }\n return hookResult\n }\n\n return Promise.resolve(hookResult).then((result) => {\n // action was fulfilled\n if (this.config.logLevel === 'info' && this.logger?.spinner) {\n this.logger.spinner.succeed(`[${strategy}] ${hookName}: Excecuting task for plugin ${plugin.name} \\n`)\n }\n return result\n })\n })\n .catch((e: Error) => this.catcher<H>(e, plugin, hookName))\n }\n\n /**\n * Run a sync plugin hook and return the result.\n * @param hookName Name of the plugin hook. Must be in `PluginHooks`.\n * @param args Arguments passed to the plugin hook.\n * @param plugin The acutal plugin\n * @param replaceContext When passed, the plugin context can be overridden.\n */\n private runSync<H extends PluginLifecycleHooks>(hookName: H, parameters: Parameters<PluginLifecycle[H]>, plugin: KubbPlugin): ReturnType<PluginLifecycle[H]> {\n const hook = plugin[hookName]!\n\n // const context = this.pluginContexts.get(plugin)!;\n\n try {\n // eslint-disable-next-line @typescript-eslint/ban-types\n return (hook as Function).apply(this.core.api, parameters)\n } catch (error: any) {\n return error\n }\n }\n\n private catcher<H extends PluginLifecycleHooks>(e: Error, plugin: KubbPlugin, hookName: H) {\n const text = `${e.message} (plugin: ${plugin.name}, hook: ${hookName})\\n`\n\n if (this.logger?.spinner) {\n this.logger.spinner.fail(text)\n throw e\n }\n }\n}\n\n// eslint-disable-next-line @typescript-eslint/no-empty-function\nfunction noReturn() {}\n","import type { MaybePromise, KubbUserConfig, CLIOptions } from './types'\n\n/**\n * Type helper to make it easier to use kubb.config.ts\n * accepts a direct {@link KubbConfig} object, or a function that returns it.\n * The function receives a {@link ConfigEnv} object that exposes two properties:\n */\nexport const defineConfig = (\n options:\n | MaybePromise<KubbUserConfig>\n | ((\n /** The options derived from the CLI flags */\n cliOptions: CLIOptions\n ) => MaybePromise<KubbUserConfig>)\n) => options\n","/* eslint-disable @typescript-eslint/no-empty-interface */\nimport { build } from './build'\n\nexport * from './config'\nexport * from './build'\nexport { CorePluginOptions, createPlugin } from './plugin'\nexport * from './utils'\nexport * from './types'\nexport * from './managers'\nexport default build\n"]}
1
+ {"version":3,"sources":["../src/build.ts","../src/plugin.ts","../src/utils/isPromise.ts","../src/utils/write.ts","../src/utils/format.ts","../src/utils/cache.ts","../src/utils/read.ts","../src/managers/fileManager/FileManager.ts","../src/managers/fileManager/events.ts","../src/managers/fileManager/TreeNode.ts","../src/managers/pluginManager/PluginManager.ts","../src/config.ts","../src/index.ts"],"names":["fse","pathParser","options","file","argument0"],"mappings":";AAAA,OAAOA,UAAS;;;ACAhB,OAAOC,iBAAgB;;;ACEhB,IAAM,YAAY,CAAI,WAAkD;AAC7E,SAAO,OAAQ,QAAgB,SAAS;AAC1C;;;ACHA,OAAO,SAAS;;;ACDhB,SAAS,UAAU,sBAAsB;AAIzC,IAAM,gBAAyB;AAAA,EAC7B,UAAU;AAAA,EACV,YAAY;AAAA,EACZ,QAAQ;AAAA,EACR,aAAa;AAAA,EACb,MAAM;AAAA,EACN,iBAAiB;AAAA,EACjB,WAAW;AACb;AACO,IAAM,SAAS,CAAC,SAAiB;AACtC,SAAO,eAAe,MAAM,aAAa;AAC3C;;;ADNO,IAAM,QAAQ,OAAO,MAAc,MAAc,UAAwB,EAAE,QAAQ,MAAM,MAAM;AACpG,QAAM,gBAAgB,QAAQ,SAAS,OAAO,IAAI,IAAI;AAEtD,MAAI;AACF,UAAM,IAAI,KAAK,IAAI;AACnB,UAAM,aAAa,MAAM,IAAI,SAAS,MAAM,EAAE,UAAU,QAAQ,CAAC;AACjE,QAAI,YAAY,SAAS,MAAM,eAAe;AAC5C;AAAA,IACF;AAAA,EACF,SAAS,MAAP;AACA,WAAO,IAAI,WAAW,MAAM,aAAa;AAAA,EAC3C;AAEA,SAAO,IAAI,WAAW,MAAM,aAAa;AAC3C;;;AEbO,SAAS,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FO,IAAM,eAAe,CAC1B,YAMG;;;ACLL,IAAO,cAAQ","sourcesContent":["import fse from 'fs-extra'\n\nimport { PluginManager } from './managers/pluginManager'\n\nimport type { PluginContext, TransformResult, ValidationResult, LogLevel, KubbPlugin } from './types'\n\ntype BuildOutput = void\n\n// Same type as ora\ntype Spinner = {\n start: (text?: string) => Spinner\n succeed: (text: string) => Spinner\n fail: (text?: string) => Spinner\n stopAndPersist: (options: { text: string }) => Spinner\n render: () => Spinner\n text: string\n info: (text: string) => Spinner\n}\n\nexport type Logger = {\n log: (message: string, logLevel: LogLevel) => void\n spinner?: Spinner\n}\ntype BuildOptions = {\n config: PluginContext['config']\n mode: 'development' | 'production'\n logger?: Logger\n}\n\nasync function transformReducer(this: PluginContext, _previousCode: string, result: TransformResult, _plugin: KubbPlugin) {\n if (result === null) {\n return null\n }\n return result\n}\n\nasync function buildImplementation(options: BuildOptions, done: (output: BuildOutput) => void) {\n const { config, logger } = options\n\n if (config.output.clean) {\n await fse.remove(config.output.path)\n }\n\n const pluginManager = new PluginManager(config, { logger })\n const { plugins, fileManager } = pluginManager\n\n const validations = await pluginManager.hookParallel<'validate', ValidationResult>('validate', [plugins])\n const validationsWithMessage = validations.filter(Boolean)\n\n if (validationsWithMessage.some((validation) => typeof validation !== 'boolean')) {\n validationsWithMessage.forEach((validation) => {\n if (validation && typeof validation !== 'boolean' && validation?.message) {\n logger?.log(validation.message, 'warn')\n }\n })\n\n return\n }\n\n fileManager.events.onSuccess(async () => {\n await pluginManager.hookParallel('buildEnd')\n setTimeout(() => {\n done()\n }, 1000)\n })\n\n fileManager.events.onAdd(async (id, file) => {\n const { path } = file\n let { source: code } = file\n\n const loadedResult = await pluginManager.hookFirst('load', [path])\n if (loadedResult) {\n code = loadedResult\n }\n\n if (code) {\n const transformedCode = await pluginManager.hookReduceArg0('transform', [code, path], transformReducer)\n\n await pluginManager.hookParallel('writeFile', [transformedCode, path])\n fileManager.setStatus(id, 'success')\n fileManager.remove(id)\n }\n })\n\n await pluginManager.hookParallel('buildStart', [config])\n}\n\nexport function build(options: BuildOptions): Promise<BuildOutput> {\n return new Promise((resolve, reject) => {\n try {\n buildImplementation(options, resolve)\n } catch (e) {\n reject(e)\n }\n })\n}\n","import pathParser from 'path'\n\nimport { createPluginCache } from './utils'\n\nimport type { FileManager, EmittedFile, File } from './managers/fileManager'\nimport type { PluginContext, KubbPlugin, PluginFactoryOptions } from './types'\n\ntype KubbPluginFactory<T extends PluginFactoryOptions = PluginFactoryOptions> = (\n options: T['options']\n) => T['nested'] extends true ? Array<KubbPlugin<T>> : KubbPlugin<T>\n\nexport function createPlugin<T extends PluginFactoryOptions = PluginFactoryOptions>(factory: KubbPluginFactory<T>) {\n return (options: T['options']) => {\n const plugin = factory(options)\n if (Array.isArray(plugin)) {\n throw new Error('Not implemented')\n }\n\n // default transform\n if (!plugin.transform) {\n plugin.transform = function transform(code) {\n return code\n }\n }\n\n return plugin\n }\n}\n\ntype Options = {\n config: PluginContext['config']\n fileManager: FileManager\n resolveId: PluginContext['resolveId']\n load: PluginContext['load']\n}\n\n// not publicly exported\nexport type CorePluginOptions = PluginFactoryOptions<Options, false, PluginContext>\n\nexport const name = 'core' as const\n\nconst isEmittedFile = (result: EmittedFile | File): result is EmittedFile => {\n return !!(result as any).id\n}\n\nexport const definePlugin = createPlugin<CorePluginOptions>((options) => {\n const { fileManager, resolveId, load } = options\n const indexFiles: File[] = []\n\n const api: PluginContext = {\n get config() {\n return options.config\n },\n fileManager,\n async addFile(file, options) {\n if (isEmittedFile(file)) {\n const resolvedId = await resolveId({ fileName: file.id, directory: file.importer, options: file.options })\n const path = resolvedId || file.importer || file.id\n\n return fileManager.add({\n path,\n fileName: file.name || file.id,\n source: file.source || '',\n })\n }\n\n if (options?.root) {\n indexFiles.push(file)\n }\n\n return fileManager.addOrAppend(file)\n },\n resolveId,\n load,\n cache: createPluginCache(Object.create(null)),\n }\n\n return {\n name,\n api,\n resolveId(fileName, directory) {\n if (!directory) {\n return null\n }\n return pathParser.resolve(directory, fileName)\n },\n }\n})\n","import type { MaybePromise } from '../types'\n\nexport const isPromise = <T>(result: MaybePromise<T>): result is Promise<T> => {\n return typeof (result as any)?.then === 'function'\n}\n","/* eslint-disable consistent-return */\nimport fse from 'fs-extra'\n\nimport { format } from './format'\n\ntype WriteOptions = {\n format: boolean\n}\n\nexport const write = async (data: string, path: string, options: WriteOptions = { format: false }) => {\n const formattedData = options.format ? format(data) : data\n\n try {\n await fse.stat(path)\n const oldContent = await fse.readFile(path, { encoding: 'utf-8' })\n if (oldContent?.toString() === formattedData) {\n return\n }\n } catch (_err) {\n return fse.outputFile(path, formattedData)\n }\n\n return fse.outputFile(path, formattedData)\n}\n","import { format as prettierFormat } from 'prettier'\n\nimport type { Options } from 'prettier'\n\nconst formatOptions: Options = {\n tabWidth: 2,\n printWidth: 160,\n parser: 'typescript',\n singleQuote: true,\n semi: false,\n bracketSameLine: false,\n endOfLine: 'auto',\n}\nexport const format = (text: string) => {\n return prettierFormat(text, formatOptions)\n}\n","/* eslint-disable no-param-reassign */\n/* eslint-disable consistent-return */\n\nexport interface Cache<TCache = any> {\n delete(id: string): boolean\n get<T = TCache>(id: string): T\n has(id: string): boolean\n set<T = TCache>(id: string, value: T): void\n}\n\nexport function createPluginCache(cache: any): Cache {\n return {\n delete(id: string) {\n return delete cache[id]\n },\n get(id: string) {\n const item = cache[id]\n if (!item) return\n item[0] = 0\n return item[1]\n },\n has(id: string) {\n const item = cache[id]\n if (!item) return false\n item[0] = 0\n return true\n },\n set(id: string, value: any) {\n cache[id] = [0, value]\n },\n }\n}\n","import pathParser from 'path'\n\n// TODO check for a better way or resolving the relative path\nexport const getRelativePath = (root?: string | null, file?: string | null) => {\n if (!root || !file) {\n throw new Error('Root and file should be filled in when retrieving the relativePath')\n }\n const newPath = pathParser.relative(root, file).replace('../', '').replace('.ts', '').trimEnd()\n\n return `./${newPath}`\n}\n\nexport const getPathMode = (path: string | undefined | null) => {\n if (!path) {\n return undefined\n }\n return pathParser.extname(path) ? 'file' : 'directory'\n}\n","import EventEmitter from 'events'\nimport { randomUUID } from 'crypto'\n\nimport { getFileManagerEvents } from './events'\n\nimport type { CacheStore, UUID, Status, File } from './types'\n\nexport class FileManager {\n private cache: Map<CacheStore['id'], CacheStore> = new Map()\n\n emitter = new EventEmitter()\n\n events = getFileManagerEvents(this.emitter)\n\n constructor() {\n this.events.onStatusChange(() => {\n if (this.getCountByStatus('removed') === this.cache.size) {\n // all files are been resolved and written to the file system\n this.events.emitSuccess()\n }\n })\n }\n\n private getCache(id: UUID) {\n return this.cache.get(id)\n }\n\n private getCacheByPath(path: string | undefined): CacheStore | undefined {\n let cache\n\n this.cache.forEach((item) => {\n if (item.file.path === path) {\n cache = item\n }\n })\n return cache as CacheStore\n }\n\n private getCountByStatus(status: Status) {\n let count = 0\n\n this.cache.forEach((item) => {\n if (item.status === status) {\n count++\n }\n })\n return count\n }\n\n get files() {\n const files: File[] = []\n this.cache.forEach((item) => {\n files.push(item.file)\n })\n\n return files\n }\n\n add(file: File) {\n const cacheItem = { id: randomUUID(), file, status: 'new' as Status }\n\n this.cache.set(cacheItem.id, cacheItem)\n this.events.emitFile(cacheItem.id, file)\n\n return new Promise<File>((resolve) => {\n const unsubscribe = this.events.onRemove(cacheItem.id, (file) => {\n resolve(file)\n unsubscribe()\n })\n })\n }\n\n addOrAppend(file: File) {\n const previousCache = this.getCacheByPath(file.path)\n\n if (previousCache) {\n this.remove(previousCache.id)\n return this.add({\n ...file,\n source: `${previousCache.file.source}\\n${file.source}`,\n })\n }\n return this.add(file)\n }\n\n setStatus(id: UUID, status: Status) {\n const cacheItem = this.getCache(id)\n if (!cacheItem) {\n return\n }\n\n cacheItem.status = status\n this.cache.set(id, cacheItem)\n this.events.emitStatusChange(cacheItem.file)\n this.events.emitStatusChangeById(id, status)\n }\n\n get(id: UUID) {\n const cacheItem = this.getCache(id)\n return cacheItem?.file\n }\n\n remove(id: UUID) {\n const cacheItem = this.getCache(id)\n if (!cacheItem) {\n return\n }\n\n this.setStatus(id, 'removed')\n this.events.emitRemove(id, cacheItem.file)\n }\n}\n","import type EventEmitter from 'events'\nimport type { File, Status, UUID } from './types'\n\nconst keys = {\n getFileKey: () => `file`,\n getStatusChangeKey: () => `status-change`,\n getStatusChangeByIdKey: (id: string) => `${id}-status-change`,\n getSuccessKey: () => `success`,\n getRemoveKey: (id: string) => `${id}remove`,\n} as const\n\ntype VoidFunction = () => void\n\nexport const getFileManagerEvents = (emitter: EventEmitter) => {\n return {\n /**\n * Emiter\n */\n emitFile: (id: UUID, file: File): void => {\n emitter.emit(keys.getFileKey(), id, file)\n },\n emitStatusChange: (file: File): void => {\n emitter.emit(keys.getStatusChangeKey(), file)\n },\n emitStatusChangeById: (id: UUID, status: Status): void => {\n emitter.emit(keys.getStatusChangeByIdKey(id), status)\n },\n emitSuccess: (): void => {\n emitter.emit(keys.getSuccessKey())\n },\n emitRemove: (id: UUID, file: File): void => {\n emitter.emit(keys.getRemoveKey(id), file)\n },\n /**\n * Listeners\n */\n\n onAdd: (callback: (id: UUID, file: File) => void): VoidFunction => {\n emitter.on(keys.getFileKey(), callback)\n return () => emitter.removeListener(keys.getFileKey(), callback)\n },\n onStatusChange: (callback: (file: File) => void): VoidFunction => {\n emitter.on(keys.getStatusChangeKey(), callback)\n return () => emitter.removeListener(keys.getStatusChangeKey(), callback)\n },\n onStatusChangeById: (id: UUID, callback: (status: Status) => void): VoidFunction => {\n emitter.on(keys.getStatusChangeByIdKey(id), callback)\n return () => emitter.removeListener(keys.getStatusChangeByIdKey(id), callback)\n },\n onSuccess: (callback: () => void): VoidFunction => {\n emitter.on(keys.getSuccessKey(), callback)\n return () => emitter.removeListener(keys.getSuccessKey(), callback)\n },\n onRemove: (id: UUID, callback: (file: File) => void): VoidFunction => {\n emitter.on(keys.getRemoveKey(id), callback)\n return () => emitter.removeListener(keys.getRemoveKey(id), callback)\n },\n }\n}\n","import dirTree from 'directory-tree'\n\nimport type { DirectoryTree, DirectoryTreeOptions } from 'directory-tree'\n\nexport class TreeNode<T = unknown> {\n public data: T\n\n public parent?: TreeNode<T>\n\n public children: Array<TreeNode<T>>\n\n constructor(data: T, parent?: TreeNode<T>) {\n this.data = data\n this.parent = parent\n return this\n }\n\n addChild(data: T) {\n const child = new TreeNode(data, this)\n if (!this.children) {\n this.children = []\n }\n this.children.push(child)\n return child\n }\n\n find(data: T) {\n if (data === this.data) {\n return this\n }\n\n if (this.children) {\n for (let i = 0, { length } = this.children, target: any = null; i < length; i++) {\n target = this.children[i].find(data)\n if (target) {\n return target\n }\n }\n }\n\n return null\n }\n\n leaves() {\n if (!this.children || this.children.length === 0) {\n // this is a leaf\n return [this]\n }\n\n // if not a leaf, return all children's leaves recursively\n const leaves = []\n if (this.children) {\n for (let i = 0, { length } = this.children; i < length; i++) {\n // eslint-disable-next-line prefer-spread\n leaves.push.apply(leaves, this.children[i].leaves())\n }\n }\n return leaves\n }\n\n root() {\n if (!this.parent) {\n return this\n }\n return this.parent.root()\n }\n\n forEach(callback: (treeNode: TreeNode<T>) => void) {\n if (typeof callback !== 'function') {\n throw new TypeError('forEach() callback must be a function')\n }\n\n // run this node through function\n callback(this)\n\n // do the same for all children\n if (this.children) {\n for (let i = 0, { length } = this.children; i < length; i++) {\n this.children[i].forEach(callback)\n }\n }\n\n return this\n }\n\n public static generate(path: string, options: DirectoryTreeOptions = {}) {\n const filteredTree = dirTree(path, { extensions: options?.extensions, exclude: options.exclude })\n const treeNode = new TreeNode({ name: filteredTree.name, path: filteredTree.path, type: filteredTree.type })\n\n const recurse = (node: typeof treeNode, item: DirectoryTree) => {\n const subNode = node.addChild({ name: item.name, path: item.path, type: item.type })\n\n if (item.children?.length) {\n item.children?.forEach((child) => {\n recurse(subNode, child)\n })\n }\n }\n\n filteredTree.children?.forEach((child) => recurse(treeNode, child))\n\n return treeNode\n }\n}\n","/* eslint-disable no-await-in-loop */\n/* eslint-disable no-restricted-syntax */\n\nimport { definePlugin } from '../../plugin'\nimport { FileManager } from '../fileManager'\n\nimport type { Argument0, Strategy } from './types'\nimport type { KubbConfig, KubbPlugin, PluginLifecycleHooks, PluginLifecycle, MaybePromise, ResolveIdParams } from '../../types'\nimport type { Logger } from '../../build'\nimport type { CorePluginOptions } from '../../plugin'\n\n// inspired by: https://github.com/rollup/rollup/blob/master/src/utils/PluginDriver.ts#\n\n// This will make sure no input hook is omitted\nconst hookNames: {\n [P in PluginLifecycleHooks]: 1\n} = {\n validate: 1,\n buildStart: 1,\n resolveId: 1,\n load: 1,\n transform: 1,\n writeFile: 1,\n buildEnd: 1,\n}\nexport const hooks = Object.keys(hookNames) as [PluginLifecycleHooks]\n\nexport class PluginManager {\n public plugins: KubbPlugin[]\n\n public readonly fileManager: FileManager\n\n private readonly logger?: Logger\n\n private readonly config: KubbConfig\n\n public readonly core: KubbPlugin<CorePluginOptions>\n\n constructor(config: KubbConfig, options: { logger?: Logger }) {\n this.logger = options.logger\n this.config = config\n\n this.fileManager = new FileManager()\n this.core = definePlugin({\n config,\n fileManager: this.fileManager,\n load: this.load,\n resolveId: this.resolveId,\n }) as KubbPlugin<CorePluginOptions> & {\n api: CorePluginOptions['api']\n }\n this.plugins = [this.core, ...(config.plugins || [])]\n }\n\n resolveId = (params: ResolveIdParams) => {\n if (params.pluginName) {\n return this.hookForPlugin(params.pluginName, 'resolveId', [params.fileName, params.directory, params.options])\n }\n return this.hookFirst('resolveId', [params.fileName, params.directory, params.options])\n }\n\n load = async (id: string) => {\n return this.hookFirst('load', [id])\n }\n\n // run only hook for a specific plugin name\n hookForPlugin<H extends PluginLifecycleHooks>(\n pluginName: string,\n hookName: H,\n parameters: Parameters<PluginLifecycle[H]>,\n skipped?: ReadonlySet<KubbPlugin> | null\n ): Promise<ReturnType<PluginLifecycle[H]> | null> {\n let promise: Promise<ReturnType<PluginLifecycle[H]> | null> = Promise.resolve(null)\n for (const plugin of this.getSortedPlugins(hookName, pluginName)) {\n if (skipped && skipped.has(plugin)) continue\n promise = promise.then((result) => {\n if (result != null) return result\n return this.run('hookFirst', hookName, parameters, plugin) as any\n })\n }\n return promise\n }\n\n // chains, first non-null result stops and returns\n hookFirst<H extends PluginLifecycleHooks>(\n hookName: H,\n parameters: Parameters<PluginLifecycle[H]>,\n skipped?: ReadonlySet<KubbPlugin> | null\n ): Promise<ReturnType<PluginLifecycle[H]> | null> {\n let promise: Promise<ReturnType<PluginLifecycle[H]> | null> = Promise.resolve(null)\n for (const plugin of this.getSortedPlugins(hookName)) {\n if (skipped && skipped.has(plugin)) continue\n promise = promise.then((result) => {\n if (result != null) return result\n return this.run('hookFirst', hookName, parameters, plugin) as any\n })\n }\n return promise\n }\n\n // parallel\n async hookParallel<H extends PluginLifecycleHooks, TOuput = void>(hookName: H, parameters?: Parameters<PluginLifecycle[H]> | undefined) {\n const parallelPromises: Promise<TOuput>[] = []\n\n for (const plugin of this.getSortedPlugins(hookName)) {\n if ((plugin[hookName] as { sequential?: boolean })?.sequential) {\n await Promise.all(parallelPromises)\n parallelPromises.length = 0\n await this.run('hookParallel', hookName, parameters, plugin)\n } else {\n const promise: Promise<TOuput> = this.run('hookParallel', hookName, parameters, plugin)\n\n parallelPromises.push(promise)\n }\n }\n return Promise.all(parallelPromises)\n }\n\n // chains, reduces returned value, handling the reduced value as the first hook argument\n hookReduceArg0<H extends PluginLifecycleHooks>(\n hookName: H,\n [argument0, ...rest]: Parameters<PluginLifecycle[H]>,\n reduce: (reduction: Argument0<H>, result: ReturnType<PluginLifecycle[H]>, plugin: KubbPlugin) => MaybePromise<Argument0<H> | null>\n ): Promise<Argument0<H>> {\n let promise = Promise.resolve(argument0)\n for (const plugin of this.getSortedPlugins(hookName)) {\n promise = promise.then((argument0) =>\n this.run('hookReduceArg0', hookName, [argument0, ...rest] as Parameters<PluginLifecycle[H]>, plugin).then((result) =>\n reduce.call(this.core.api, argument0, result, plugin)\n )\n )\n }\n return promise\n }\n\n // chains\n\n hookSeq<H extends PluginLifecycleHooks>(hookName: H, parameters?: Parameters<PluginLifecycle[H]>) {\n let promise: Promise<void> = Promise.resolve()\n for (const plugin of this.getSortedPlugins(hookName)) {\n promise = promise.then(() => this.run('hookSeq', hookName, parameters, plugin))\n }\n return promise.then(noReturn)\n }\n\n private getSortedPlugins(hookName: keyof PluginLifecycle, pluginName?: string): KubbPlugin[] {\n const plugins = [...this.plugins]\n\n if (pluginName) {\n const pluginsByPluginName = plugins.filter((item) => item.name === pluginName && item[hookName])\n if (pluginsByPluginName.length === 0) {\n // fallback on the core plugin when there is no match\n if (this.config.logLevel === 'warn' && this.logger?.spinner) {\n this.logger.spinner.info(`Plugin hook with ${hookName} not found for plugin ${pluginName}`)\n }\n return [this.core]\n }\n return pluginsByPluginName\n }\n\n return plugins\n }\n\n /**\n * Run an async plugin hook and return the result.\n * @param hookName Name of the plugin hook. Must be either in `PluginHooks` or `OutputPluginValueHooks`.\n * @param args Arguments passed to the plugin hook.\n * @param plugin The actual pluginObject to run.\n */\n // Implementation signature\n private run<H extends PluginLifecycleHooks, TResult = void>(\n strategy: Strategy,\n hookName: H,\n parameters: unknown[] | undefined,\n plugin: KubbPlugin\n ): Promise<TResult> {\n const hook = plugin[hookName]!\n\n return Promise.resolve()\n .then(() => {\n if (typeof hook !== 'function') {\n return hook\n }\n\n if (this.config.logLevel === 'info' && this.logger?.spinner) {\n this.logger.spinner.text = `[${strategy}] ${hookName}: Excecuting task for plugin ${plugin.name} \\n`\n }\n\n const hookResult = (hook as any).apply(this.core.api, parameters)\n\n if (!hookResult?.then) {\n // short circuit for non-thenables and non-Promises\n if (this.config.logLevel === 'info' && this.logger?.spinner) {\n this.logger.spinner.succeed(`[${strategy}] ${hookName}: Excecuting task for plugin ${plugin.name} \\n`)\n }\n return hookResult\n }\n\n return Promise.resolve(hookResult).then((result) => {\n // action was fulfilled\n if (this.config.logLevel === 'info' && this.logger?.spinner) {\n this.logger.spinner.succeed(`[${strategy}] ${hookName}: Excecuting task for plugin ${plugin.name} \\n`)\n }\n return result\n })\n })\n .catch((e: Error) => this.catcher<H>(e, plugin, hookName))\n }\n\n /**\n * Run a sync plugin hook and return the result.\n * @param hookName Name of the plugin hook. Must be in `PluginHooks`.\n * @param args Arguments passed to the plugin hook.\n * @param plugin The acutal plugin\n * @param replaceContext When passed, the plugin context can be overridden.\n */\n private runSync<H extends PluginLifecycleHooks>(hookName: H, parameters: Parameters<PluginLifecycle[H]>, plugin: KubbPlugin): ReturnType<PluginLifecycle[H]> {\n const hook = plugin[hookName]!\n\n // const context = this.pluginContexts.get(plugin)!;\n\n try {\n // eslint-disable-next-line @typescript-eslint/ban-types\n return (hook as Function).apply(this.core.api, parameters)\n } catch (error: any) {\n return error\n }\n }\n\n private catcher<H extends PluginLifecycleHooks>(e: Error, plugin: KubbPlugin, hookName: H) {\n const text = `${e.message} (plugin: ${plugin.name}, hook: ${hookName})\\n`\n\n if (this.logger?.spinner) {\n this.logger.spinner.fail(text)\n throw e\n }\n }\n}\n\n// eslint-disable-next-line @typescript-eslint/no-empty-function\nfunction noReturn() {}\n","import type { MaybePromise, KubbUserConfig, CLIOptions } from './types'\n\n/**\n * Type helper to make it easier to use kubb.config.ts\n * accepts a direct {@link KubbConfig} object, or a function that returns it.\n * The function receives a {@link ConfigEnv} object that exposes two properties:\n */\nexport const defineConfig = (\n options:\n | MaybePromise<KubbUserConfig>\n | ((\n /** The options derived from the CLI flags */\n cliOptions: CLIOptions\n ) => MaybePromise<KubbUserConfig>)\n) => options\n","/* eslint-disable @typescript-eslint/no-empty-interface */\nimport { build } from './build'\n\nexport * from './config'\nexport * from './build'\nexport { CorePluginOptions, createPlugin } from './plugin'\nexport * from './utils'\nexport * from './types'\nexport * from './managers'\nexport default build\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/core",
3
- "version": "0.30.0",
3
+ "version": "0.31.0",
4
4
  "description": "Generator core",
5
5
  "repository": {
6
6
  "type": "git",