@kubb/core 0.21.0 → 0.21.1

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
@@ -161,8 +161,12 @@ type PluginContext = {
161
161
  config: KubbConfig;
162
162
  cache: Cache;
163
163
  emitFile: (emitedFile: EmittedFile) => Promise<File>;
164
- resolveId: (importee: string, importer?: string, options?: Record<string, any>) => MaybePromise<string | null | undefined>;
165
- resolveIdForPlugin: (pluginName: string) => PluginContext['resolveId'];
164
+ resolveId: (params: {
165
+ importee: string;
166
+ importer?: string | undefined;
167
+ options?: Record<string, any>;
168
+ pluginName?: string;
169
+ }) => MaybePromise<string | null | undefined>;
166
170
  load: (id: string) => MaybePromise<TransformResult | void>;
167
171
  addToRoot: (file: File) => void;
168
172
  };
@@ -208,7 +212,6 @@ type Options = {
208
212
  config: PluginContext['config'];
209
213
  fileManager: FileManager;
210
214
  resolveId: PluginContext['resolveId'];
211
- resolveIdForPlugin: PluginContext['resolveIdForPlugin'];
212
215
  load: PluginContext['load'];
213
216
  };
214
217
  type CorePluginOptions = PluginFactoryOptions<Options, false, PluginContext>;
@@ -237,8 +240,8 @@ declare class PluginDriver {
237
240
  constructor(config: KubbConfig, options: {
238
241
  logger?: Logger;
239
242
  });
240
- resolveId: (importee: string, importer: string, options: Record<string, any> | undefined) => Promise<string | null | undefined>;
241
- resolveIdForPlugin: (pluginName: string) => (importee: string, importer: string, options: Record<string, any> | undefined) => Promise<string | null | undefined>;
243
+ resolveId: (importee: string, importer?: string, options?: Record<string, any> | undefined) => Promise<string | null | undefined>;
244
+ resolveIdForPlugin: (pluginName: string) => (importee: string, importer?: string, options?: Record<string, any> | undefined) => Promise<string | null | undefined>;
242
245
  load: (id: string) => Promise<TransformResult>;
243
246
  hookForPlugin<H extends PluginLifecycleHooks>(pluginName: string, hookName: H, parameters: Parameters<PluginLifecycle[H]>, skipped?: ReadonlySet<KubbPlugin> | null): Promise<ReturnType<PluginLifecycle[H]> | null>;
244
247
  hookFirst<H extends PluginLifecycleHooks>(hookName: H, parameters: Parameters<PluginLifecycle[H]>, skipped?: ReadonlySet<KubbPlugin> | null): Promise<ReturnType<PluginLifecycle[H]> | null>;
package/dist/index.js CHANGED
@@ -92,14 +92,14 @@ function createPlugin(factory) {
92
92
  }
93
93
  var name = "core";
94
94
  var definePlugin = createPlugin((options) => {
95
- const { fileManager, resolveId, resolveIdForPlugin, load } = options;
95
+ const { fileManager, resolveId, load } = options;
96
96
  const indexFiles = [];
97
97
  const api = {
98
98
  get config() {
99
99
  return options.config;
100
100
  },
101
101
  async emitFile(emittedFile) {
102
- const resolvedId = await resolveId(emittedFile.id, emittedFile.importer, emittedFile.options);
102
+ const resolvedId = await resolveId({ importee: emittedFile.id, importer: emittedFile.importer, options: emittedFile.options });
103
103
  const fileName = resolvedId || emittedFile.importer || emittedFile.id;
104
104
  return fileManager.add({
105
105
  fileName,
@@ -111,7 +111,6 @@ var definePlugin = createPlugin((options) => {
111
111
  indexFiles.push(file);
112
112
  },
113
113
  resolveId,
114
- resolveIdForPlugin,
115
114
  load,
116
115
  cache: createPluginCache(/* @__PURE__ */ Object.create(null))
117
116
  };
@@ -272,8 +271,12 @@ var PluginDriver = class {
272
271
  config,
273
272
  fileManager: this.fileManager,
274
273
  load: this.load,
275
- resolveId: this.resolveId,
276
- resolveIdForPlugin: this.resolveIdForPlugin
274
+ resolveId: (params) => {
275
+ if (params.pluginName) {
276
+ return this.resolveIdForPlugin(params.pluginName)(params.importee, params.importer, params.options);
277
+ }
278
+ return this.resolveId(params.importee, params.importer, params.options);
279
+ }
277
280
  });
278
281
  this.plugins = [this.core, ...config.plugins || []];
279
282
  }
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.ts","../src/managers/utils/getFileManagerEvents.ts","../src/utils/PluginDriver.ts","../src/config.ts","../src/index.ts"],"names":["path","fse","file","argument0","name"],"mappings":";AAAA,OAAOA,WAAU;AAEjB,OAAOC,UAAS;;;ACFhB,OAAOD,WAAU;;;ACEV,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,MAAcA,OAAc,UAAwB,EAAE,QAAQ,MAAM,MAAM;AACpG,QAAM,gBAAgB,QAAQ,SAAS,OAAO,IAAI,IAAI;AAEtD,MAAI;AACF,UAAM,IAAI,KAAKA,KAAI;AACnB,UAAM,aAAa,MAAM,IAAI,SAASA,OAAM,EAAE,UAAU,QAAQ,CAAC;AACjE,QAAI,YAAY,SAAS,MAAM,eAAe;AAC5C;AAAA,IACF;AAAA,EACF,SAAS,MAAP;AACA,WAAO,IAAI,WAAWA,OAAM,aAAa;AAAA,EAC3C;AAEA,SAAO,IAAI,WAAWA,OAAM,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;AAAM;AACX,WAAK,KAAK;AACV,aAAO,KAAK;AAAA,IACd;AAAA,IACA,IAAI,IAAY;AACd,YAAM,OAAO,MAAM;AACnB,UAAI,CAAC;AAAM,eAAO;AAClB,WAAK,KAAK;AACV,aAAO;AAAA,IACT;AAAA,IACA,I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AAa,CAAC,MAAM,QAAQ,GAAG,gBAAgB;AAEzG,YAAM,aAAa,aAAa,aAAa,CAAC,iBAAiB,QAAQ,CAAC;AACxE,mBAAa,YAAY,UAAU,IAAI,SAAS;AAChD,mBAAa,YAAY,OAAO,EAAE;AAAA,IACpC;AAAA,EACF,CAAC;AAED,QAAM,aAAa,aAAa,cAAc,CAAC,MAAM,CAAC;AAEtD,eAAa,YAAY,IAAI;AAAA,IAC3B,UAAUJ,MAAK,QAAQ,OAAO,MAAM,OAAO,MAAM,IAAI;AAAA,IACrD,QAAQ;AAAA,EACV,CAAC;AAED,eAAa,YAAY,OAAO,UAAU,YAAY;AACpD,UAAM,aAAa,aAAa,UAAU;AAC1C,eAAW,MAAM;AACf,WAAK;AAAA,IACP,GAAG,GAAI;AAAA,EACT,CAAC;AACH;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;;;AUlGO,IAAM,eAAe,CAC1B,YAMG;;;ACLL,IAAO,cAAQ","sourcesContent":["import path from 'path'\n\nimport fse from 'fs-extra'\n\nimport { PluginDriver } from './utils/PluginDriver'\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 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 pluginDriver = new PluginDriver(config, { logger })\n const input = fse.readFileSync(path.resolve(config.root, config.input.path), 'utf-8')\n\n const validations = await pluginDriver.hookParallel<'validate', ValidationResult>('validate', [pluginDriver.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 pluginDriver.fileManager.events.onAdd(async (id, file) => {\n let fileName = file.fileName as string\n let { name, source: code } = file\n\n if (!fileName && name) {\n fileName = path.resolve(config.root, config.output.path, name)\n }\n\n const loadedResult = await pluginDriver.hookFirst('load', [fileName])\n if (loadedResult) {\n code = loadedResult\n }\n\n if (code) {\n const transformedCode = await pluginDriver.hookReduceArg0('transform', [code, fileName], transformReducer)\n\n await pluginDriver.hookParallel('writeFile', [transformedCode, fileName])\n pluginDriver.fileManager.setStatus(id, 'success')\n pluginDriver.fileManager.remove(id)\n }\n })\n\n await pluginDriver.hookParallel('buildStart', [config])\n\n pluginDriver.fileManager.add({\n fileName: path.resolve(config.root, config.input.path),\n source: input,\n })\n\n pluginDriver.fileManager.events.onSuccess(async () => {\n await pluginDriver.hookParallel('buildEnd')\n setTimeout(() => {\n done()\n }, 1000)\n })\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 path from 'path'\n\nimport { createPluginCache, getRelativePath, write } from './utils'\n\nimport { FileManager, File } from './managers'\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 resolveIdForPlugin: PluginContext['resolveIdForPlugin']\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\nexport const definePlugin = createPlugin<CorePluginOptions>((options) => {\n const { fileManager, resolveId, resolveIdForPlugin, load } = options\n const indexFiles: File[] = []\n\n const api: PluginContext = {\n get config() {\n return options.config\n },\n async emitFile(emittedFile) {\n const resolvedId = await resolveId(emittedFile.id, emittedFile.importer, emittedFile.options)\n const fileName = resolvedId || emittedFile.importer || emittedFile.id\n\n return fileManager.add({\n fileName: fileName,\n name: emittedFile.name,\n source: emittedFile.source,\n })\n },\n addToRoot: (file: File) => {\n indexFiles.push(file)\n },\n resolveId,\n resolveIdForPlugin,\n load,\n cache: createPluginCache(Object.create(null)),\n }\n\n return {\n name,\n api,\n async buildEnd() {\n if (!indexFiles.length) {\n return\n }\n\n let index = ``\n\n indexFiles.forEach((item) => {\n index += `export * from \"${getRelativePath(path.resolve(this.config.root, this.config.output.path), item.fileName)}\";\\n`\n })\n\n await write(index, path.resolve(this.config.root, this.config.output.path, 'index.ts'), { format: true })\n },\n resolveId(importee, importer) {\n if (!importer) {\n return null\n }\n return path.resolve(importer, importee)\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 path from 'path'\n\n// TODO check for a better way or resolving the relative path\nexport const getRelativePath = (from?: string | null, to?: string | null) => {\n if (!from || !to) {\n throw new Error('From and to should be filled in when retrieving the relativePath')\n }\n const newPath = path.relative(from, to).replace('../', '').replace('.ts', '').trimEnd()\n\n return `./${newPath}`\n}\n","import EventEmitter from 'events'\nimport { randomUUID } from 'crypto'\nimport type { CacheStore, UUID, Status, File, UserFile } from './types'\nimport { getFileManagerEvents } from './utils/getFileManagerEvents'\n\nexport class FileManager {\n private cache: Map<CacheStore['id'], CacheStore> = new Map()\n emitter = new EventEmitter()\n events = getFileManagerEvents(this.emitter)\n\n constructor() {\n this.events.onStatusChange(() => {\n if (this.getCountOfStatus('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 private getCountOfStatus(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 add(userFile: UserFile) {\n const file: File = {\n ...userFile,\n } as 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 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 EventEmitter from 'events'\n\nimport type { File, Status, UUID } from '../types'\n\nconst keys = {\n getEmitFileKey: () => `emit-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\nexport const getFileManagerEvents = (emitter: EventEmitter) => {\n return {\n /**\n * Emiter\n */\n emitFile: (id: UUID, file: File): void => {\n emitter.emit(keys.getEmitFileKey(), 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.getEmitFileKey(), callback)\n return () => emitter.removeListener(keys.getEmitFileKey(), 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","/* eslint-disable no-await-in-loop */\n/* eslint-disable no-restricted-syntax */\n\nimport { definePlugin } from '../plugin'\n\nimport type { KubbConfig, KubbPlugin, PluginLifecycleHooks, PluginLifecycle, MaybePromise } from '../types'\nimport type { Logger } from '../build'\nimport type { CorePluginOptions } from '../plugin'\nimport { FileManager } from '../managers'\n\n// inspired by: https://github.com/rollup/rollup/blob/master/src/utils/PluginDriver.ts#\n/**\n * Get the type of the first argument in a function.\n * @example Arg0<(a: string, b: number) => void> -> string\n */\nexport type Argument0<H extends keyof PluginLifecycle> = Parameters<PluginLifecycle[H]>[0]\n\ntype Strategy = 'hookFirst' | 'hookParallel' | 'hookReduceArg0' | 'hookSeq'\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 PluginDriver {\n public plugins: KubbPlugin[]\n\n public readonly fileManager: FileManager = new FileManager()\n\n private readonly logger?: Logger\n\n private readonly config: KubbConfig\n\n public readonly core: KubbPlugin<CorePluginOptions> & { api: CorePluginOptions['api'] }\n\n constructor(config: KubbConfig, options: { logger?: Logger }) {\n this.logger = options.logger\n this.config = config\n\n this.core = definePlugin({\n config,\n fileManager: this.fileManager,\n load: this.load,\n resolveId: this.resolveId,\n resolveIdForPlugin: this.resolveIdForPlugin,\n }) as KubbPlugin<CorePluginOptions> & {\n api: CorePluginOptions['api']\n }\n this.plugins = [this.core, ...(config.plugins || [])]\n }\n\n resolveId = (importee: string, importer: string, options: Record<string, any> | undefined) => {\n return this.hookFirst('resolveId', [importee, importer, options])\n }\n resolveIdForPlugin = (pluginName: string) => (importee: string, importer: string, options: Record<string, any> | undefined) => {\n return this.hookForPlugin(pluginName, 'resolveId', [importee, importer, 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 sortedPlugins = [...this.plugins]\n\n if (pluginName) {\n return sortedPlugins.filter((item) => item.name === pluginName)\n }\n return sortedPlugins\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().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 }\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\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 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.ts","../src/managers/utils/getFileManagerEvents.ts","../src/utils/PluginDriver.ts","../src/config.ts","../src/index.ts"],"names":["path","fse","file","argument0","name"],"mappings":";AAAA,OAAOA,WAAU;AAEjB,OAAOC,UAAS;;;ACFhB,OAAOD,WAAU;;;ACEV,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,MAAcA,OAAc,UAAwB,EAAE,QAAQ,MAAM,MAAM;AACpG,QAAM,gBAAgB,QAAQ,SAAS,OAAO,IAAI,IAAI;AAEtD,MAAI;AACF,UAAM,IAAI,KAAKA,KAAI;AACnB,UAAM,aAAa,MAAM,IAAI,SAASA,OAAM,EAAE,UAAU,QAAQ,CAAC;AACjE,QAAI,YAAY,SAAS,MAAM,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AAW;AACtC,QAAI;AACF,0BAAoB,SAAS,OAAO;AAAA,IACtC,SAAS,GAAP;AACA,aAAO,CAAC;AAAA,IACV;AAAA,EACF,CAAC;AACH;;;AUlGO,IAAM,eAAe,CAC1B,YAMG;;;ACLL,IAAO,cAAQ","sourcesContent":["import path from 'path'\n\nimport fse from 'fs-extra'\n\nimport { PluginDriver } from './utils/PluginDriver'\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 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 pluginDriver = new PluginDriver(config, { logger })\n const input = fse.readFileSync(path.resolve(config.root, config.input.path), 'utf-8')\n\n const validations = await pluginDriver.hookParallel<'validate', ValidationResult>('validate', [pluginDriver.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 pluginDriver.fileManager.events.onAdd(async (id, file) => {\n let fileName = file.fileName as string\n let { name, source: code } = file\n\n if (!fileName && name) {\n fileName = path.resolve(config.root, config.output.path, name)\n }\n\n const loadedResult = await pluginDriver.hookFirst('load', [fileName])\n if (loadedResult) {\n code = loadedResult\n }\n\n if (code) {\n const transformedCode = await pluginDriver.hookReduceArg0('transform', [code, fileName], transformReducer)\n\n await pluginDriver.hookParallel('writeFile', [transformedCode, fileName])\n pluginDriver.fileManager.setStatus(id, 'success')\n pluginDriver.fileManager.remove(id)\n }\n })\n\n await pluginDriver.hookParallel('buildStart', [config])\n\n pluginDriver.fileManager.add({\n fileName: path.resolve(config.root, config.input.path),\n source: input,\n })\n\n pluginDriver.fileManager.events.onSuccess(async () => {\n await pluginDriver.hookParallel('buildEnd')\n setTimeout(() => {\n done()\n }, 1000)\n })\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 path from 'path'\n\nimport { createPluginCache, getRelativePath, write } from './utils'\n\nimport { FileManager, File } from './managers'\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\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 async emitFile(emittedFile) {\n const resolvedId = await resolveId({ importee: emittedFile.id, importer: emittedFile.importer, options: emittedFile.options })\n const fileName = resolvedId || emittedFile.importer || emittedFile.id\n\n return fileManager.add({\n fileName: fileName,\n name: emittedFile.name,\n source: emittedFile.source,\n })\n },\n addToRoot: (file: File) => {\n indexFiles.push(file)\n },\n resolveId,\n load,\n cache: createPluginCache(Object.create(null)),\n }\n\n return {\n name,\n api,\n async buildEnd() {\n if (!indexFiles.length) {\n return\n }\n\n let index = ``\n\n indexFiles.forEach((item) => {\n index += `export * from \"${getRelativePath(path.resolve(this.config.root, this.config.output.path), item.fileName)}\";\\n`\n })\n\n await write(index, path.resolve(this.config.root, this.config.output.path, 'index.ts'), { format: true })\n },\n resolveId(importee, importer) {\n if (!importer) {\n return null\n }\n return path.resolve(importer, importee)\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 path from 'path'\n\n// TODO check for a better way or resolving the relative path\nexport const getRelativePath = (from?: string | null, to?: string | null) => {\n if (!from || !to) {\n throw new Error('From and to should be filled in when retrieving the relativePath')\n }\n const newPath = path.relative(from, to).replace('../', '').replace('.ts', '').trimEnd()\n\n return `./${newPath}`\n}\n","import EventEmitter from 'events'\nimport { randomUUID } from 'crypto'\nimport type { CacheStore, UUID, Status, File, UserFile } from './types'\nimport { getFileManagerEvents } from './utils/getFileManagerEvents'\n\nexport class FileManager {\n private cache: Map<CacheStore['id'], CacheStore> = new Map()\n emitter = new EventEmitter()\n events = getFileManagerEvents(this.emitter)\n\n constructor() {\n this.events.onStatusChange(() => {\n if (this.getCountOfStatus('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 private getCountOfStatus(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 add(userFile: UserFile) {\n const file: File = {\n ...userFile,\n } as 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 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 EventEmitter from 'events'\n\nimport type { File, Status, UUID } from '../types'\n\nconst keys = {\n getEmitFileKey: () => `emit-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\nexport const getFileManagerEvents = (emitter: EventEmitter) => {\n return {\n /**\n * Emiter\n */\n emitFile: (id: UUID, file: File): void => {\n emitter.emit(keys.getEmitFileKey(), 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.getEmitFileKey(), callback)\n return () => emitter.removeListener(keys.getEmitFileKey(), 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","/* eslint-disable no-await-in-loop */\n/* eslint-disable no-restricted-syntax */\n\nimport { definePlugin } from '../plugin'\n\nimport type { KubbConfig, KubbPlugin, PluginLifecycleHooks, PluginLifecycle, MaybePromise } from '../types'\nimport type { Logger } from '../build'\nimport type { CorePluginOptions } from '../plugin'\nimport { FileManager } from '../managers'\n\n// inspired by: https://github.com/rollup/rollup/blob/master/src/utils/PluginDriver.ts#\n/**\n * Get the type of the first argument in a function.\n * @example Arg0<(a: string, b: number) => void> -> string\n */\nexport type Argument0<H extends keyof PluginLifecycle> = Parameters<PluginLifecycle[H]>[0]\n\ntype Strategy = 'hookFirst' | 'hookParallel' | 'hookReduceArg0' | 'hookSeq'\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 PluginDriver {\n public plugins: KubbPlugin[]\n\n public readonly fileManager: FileManager = new FileManager()\n\n private readonly logger?: Logger\n\n private readonly config: KubbConfig\n\n public readonly core: KubbPlugin<CorePluginOptions> & { api: CorePluginOptions['api'] }\n\n constructor(config: KubbConfig, options: { logger?: Logger }) {\n this.logger = options.logger\n this.config = config\n\n this.core = definePlugin({\n config,\n fileManager: this.fileManager,\n load: this.load,\n resolveId: (params) => {\n if (params.pluginName) {\n return this.resolveIdForPlugin(params.pluginName)(params.importee, params.importer, params.options)\n }\n return this.resolveId(params.importee, params.importer, params.options)\n },\n }) as KubbPlugin<CorePluginOptions> & {\n api: CorePluginOptions['api']\n }\n this.plugins = [this.core, ...(config.plugins || [])]\n }\n\n resolveId = (importee: string, importer?: string, options?: Record<string, any> | undefined) => {\n return this.hookFirst('resolveId', [importee, importer, options])\n }\n resolveIdForPlugin = (pluginName: string) => (importee: string, importer?: string, options?: Record<string, any> | undefined) => {\n return this.hookForPlugin(pluginName, 'resolveId', [importee, importer, 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 sortedPlugins = [...this.plugins]\n\n if (pluginName) {\n return sortedPlugins.filter((item) => item.name === pluginName)\n }\n return sortedPlugins\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().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 }\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\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 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
@@ -88,14 +88,14 @@ function createPlugin(factory) {
88
88
  }
89
89
  var name = "core";
90
90
  var definePlugin = createPlugin((options) => {
91
- const { fileManager, resolveId, resolveIdForPlugin, load } = options;
91
+ const { fileManager, resolveId, load } = options;
92
92
  const indexFiles = [];
93
93
  const api = {
94
94
  get config() {
95
95
  return options.config;
96
96
  },
97
97
  async emitFile(emittedFile) {
98
- const resolvedId = await resolveId(emittedFile.id, emittedFile.importer, emittedFile.options);
98
+ const resolvedId = await resolveId({ importee: emittedFile.id, importer: emittedFile.importer, options: emittedFile.options });
99
99
  const fileName = resolvedId || emittedFile.importer || emittedFile.id;
100
100
  return fileManager.add({
101
101
  fileName,
@@ -107,7 +107,6 @@ var definePlugin = createPlugin((options) => {
107
107
  indexFiles.push(file);
108
108
  },
109
109
  resolveId,
110
- resolveIdForPlugin,
111
110
  load,
112
111
  cache: createPluginCache(/* @__PURE__ */ Object.create(null))
113
112
  };
@@ -268,8 +267,12 @@ var PluginDriver = class {
268
267
  config,
269
268
  fileManager: this.fileManager,
270
269
  load: this.load,
271
- resolveId: this.resolveId,
272
- resolveIdForPlugin: this.resolveIdForPlugin
270
+ resolveId: (params) => {
271
+ if (params.pluginName) {
272
+ return this.resolveIdForPlugin(params.pluginName)(params.importee, params.importer, params.options);
273
+ }
274
+ return this.resolveId(params.importee, params.importer, params.options);
275
+ }
273
276
  });
274
277
  this.plugins = [this.core, ...config.plugins || []];
275
278
  }
@@ -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.ts","../src/managers/utils/getFileManagerEvents.ts","../src/utils/PluginDriver.ts","../src/config.ts","../src/index.ts"],"names":["path","fse","file","argument0","name"],"mappings":";AAAA,OAAOA,WAAU;AAEjB,OAAOC,UAAS;;;ACFhB,OAAOD,WAAU;;;ACEV,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,i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OAAO,UAAU,YAAY;AACpD,UAAM,aAAa,aAAa,UAAU;AAC1C,eAAW,MAAM;AACf,WAAK;AAAA,IACP,GAAG,GAAI;AAAA,EACT,CAAC;AACH;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;;;AUlGO,IAAM,eAAe,CAC1B,YAMG;;;ACLL,IAAO,cAAQ","sourcesContent":["import path from 'path'\n\nimport fse from 'fs-extra'\n\nimport { PluginDriver } from './utils/PluginDriver'\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 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 pluginDriver = new PluginDriver(config, { logger })\n const input = fse.readFileSync(path.resolve(config.root, config.input.path), 'utf-8')\n\n const validations = await pluginDriver.hookParallel<'validate', ValidationResult>('validate', [pluginDriver.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 pluginDriver.fileManager.events.onAdd(async (id, file) => {\n let fileName = file.fileName as string\n let { name, source: code } = file\n\n if (!fileName && name) {\n fileName = path.resolve(config.root, config.output.path, name)\n }\n\n const loadedResult = await pluginDriver.hookFirst('load', [fileName])\n if (loadedResult) {\n code = loadedResult\n }\n\n if (code) {\n const transformedCode = await pluginDriver.hookReduceArg0('transform', [code, fileName], transformReducer)\n\n await pluginDriver.hookParallel('writeFile', [transformedCode, fileName])\n pluginDriver.fileManager.setStatus(id, 'success')\n pluginDriver.fileManager.remove(id)\n }\n })\n\n await pluginDriver.hookParallel('buildStart', [config])\n\n pluginDriver.fileManager.add({\n fileName: path.resolve(config.root, config.input.path),\n source: input,\n })\n\n pluginDriver.fileManager.events.onSuccess(async () => {\n await pluginDriver.hookParallel('buildEnd')\n setTimeout(() => {\n done()\n }, 1000)\n })\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 path from 'path'\n\nimport { createPluginCache, getRelativePath, write } from './utils'\n\nimport { FileManager, File } from './managers'\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 resolveIdForPlugin: PluginContext['resolveIdForPlugin']\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\nexport const definePlugin = createPlugin<CorePluginOptions>((options) => {\n const { fileManager, resolveId, resolveIdForPlugin, load } = options\n const indexFiles: File[] = []\n\n const api: PluginContext = {\n get config() {\n return options.config\n },\n async emitFile(emittedFile) {\n const resolvedId = await resolveId(emittedFile.id, emittedFile.importer, emittedFile.options)\n const fileName = resolvedId || emittedFile.importer || emittedFile.id\n\n return fileManager.add({\n fileName: fileName,\n name: emittedFile.name,\n source: emittedFile.source,\n })\n },\n addToRoot: (file: File) => {\n indexFiles.push(file)\n },\n resolveId,\n resolveIdForPlugin,\n load,\n cache: createPluginCache(Object.create(null)),\n }\n\n return {\n name,\n api,\n async buildEnd() {\n if (!indexFiles.length) {\n return\n }\n\n let index = ``\n\n indexFiles.forEach((item) => {\n index += `export * from \"${getRelativePath(path.resolve(this.config.root, this.config.output.path), item.fileName)}\";\\n`\n })\n\n await write(index, path.resolve(this.config.root, this.config.output.path, 'index.ts'), { format: true })\n },\n resolveId(importee, importer) {\n if (!importer) {\n return null\n }\n return path.resolve(importer, importee)\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 path from 'path'\n\n// TODO check for a better way or resolving the relative path\nexport const getRelativePath = (from?: string | null, to?: string | null) => {\n if (!from || !to) {\n throw new Error('From and to should be filled in when retrieving the relativePath')\n }\n const newPath = path.relative(from, to).replace('../', '').replace('.ts', '').trimEnd()\n\n return `./${newPath}`\n}\n","import EventEmitter from 'events'\nimport { randomUUID } from 'crypto'\nimport type { CacheStore, UUID, Status, File, UserFile } from './types'\nimport { getFileManagerEvents } from './utils/getFileManagerEvents'\n\nexport class FileManager {\n private cache: Map<CacheStore['id'], CacheStore> = new Map()\n emitter = new EventEmitter()\n events = getFileManagerEvents(this.emitter)\n\n constructor() {\n this.events.onStatusChange(() => {\n if (this.getCountOfStatus('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 private getCountOfStatus(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 add(userFile: UserFile) {\n const file: File = {\n ...userFile,\n } as 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 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 EventEmitter from 'events'\n\nimport type { File, Status, UUID } from '../types'\n\nconst keys = {\n getEmitFileKey: () => `emit-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\nexport const getFileManagerEvents = (emitter: EventEmitter) => {\n return {\n /**\n * Emiter\n */\n emitFile: (id: UUID, file: File): void => {\n emitter.emit(keys.getEmitFileKey(), 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.getEmitFileKey(), callback)\n return () => emitter.removeListener(keys.getEmitFileKey(), 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","/* eslint-disable no-await-in-loop */\n/* eslint-disable no-restricted-syntax */\n\nimport { definePlugin } from '../plugin'\n\nimport type { KubbConfig, KubbPlugin, PluginLifecycleHooks, PluginLifecycle, MaybePromise } from '../types'\nimport type { Logger } from '../build'\nimport type { CorePluginOptions } from '../plugin'\nimport { FileManager } from '../managers'\n\n// inspired by: https://github.com/rollup/rollup/blob/master/src/utils/PluginDriver.ts#\n/**\n * Get the type of the first argument in a function.\n * @example Arg0<(a: string, b: number) => void> -> string\n */\nexport type Argument0<H extends keyof PluginLifecycle> = Parameters<PluginLifecycle[H]>[0]\n\ntype Strategy = 'hookFirst' | 'hookParallel' | 'hookReduceArg0' | 'hookSeq'\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 PluginDriver {\n public plugins: KubbPlugin[]\n\n public readonly fileManager: FileManager = new FileManager()\n\n private readonly logger?: Logger\n\n private readonly config: KubbConfig\n\n public readonly core: KubbPlugin<CorePluginOptions> & { api: CorePluginOptions['api'] }\n\n constructor(config: KubbConfig, options: { logger?: Logger }) {\n this.logger = options.logger\n this.config = config\n\n this.core = definePlugin({\n config,\n fileManager: this.fileManager,\n load: this.load,\n resolveId: this.resolveId,\n resolveIdForPlugin: this.resolveIdForPlugin,\n }) as KubbPlugin<CorePluginOptions> & {\n api: CorePluginOptions['api']\n }\n this.plugins = [this.core, ...(config.plugins || [])]\n }\n\n resolveId = (importee: string, importer: string, options: Record<string, any> | undefined) => {\n return this.hookFirst('resolveId', [importee, importer, options])\n }\n resolveIdForPlugin = (pluginName: string) => (importee: string, importer: string, options: Record<string, any> | undefined) => {\n return this.hookForPlugin(pluginName, 'resolveId', [importee, importer, 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 sortedPlugins = [...this.plugins]\n\n if (pluginName) {\n return sortedPlugins.filter((item) => item.name === pluginName)\n }\n return sortedPlugins\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().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 }\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\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 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.ts","../src/managers/utils/getFileManagerEvents.ts","../src/utils/PluginDriver.ts","../src/config.ts","../src/index.ts"],"names":["path","fse","file","argument0","name"],"mappings":";AAAA,OAAOA,WAAU;AAEjB,OAAOC,UAAS;;;ACFhB,OAAOD,WAAU;;;ACEV,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,MAAcA,OAAc,UAAwB,EAAE,QAAQ,MAAM,MAAM;AACpG,QAAM,gBAAgB,QAAQ,SAAS,OAAO,IAAI,IAAI;AAEtD,MAAI;AACF,UAAM,IAAI,KAAKA,KAAI;AACnB,UAAM,aAAa,MAAM,IAAI,SAASA,OAAM,EAAE,UAAU,QAAQ,CAAC;AACjE,QAAI,YAAY,SAAS,MAAM,eAAe;AAC5C;AAAA,IACF;AAAA,EACF,SAAS,MAAP;AACA,WAAO,IAAI,WAAWA,OAAM,aAAa;AAAA,EAC3C;AAEA,SAAO,IAAI,WAAWA,OAAM,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;AAAM;AACX,WAAK,KAAK;AACV,aAAO,KAAK;AAAA,IACd;AAAA,IACA,IAAI,IAAY;AACd,Y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AI;AAE7B,QAAI,CAAC,YAAYA,OAAM;AACrB,iBAAWJ,MAAK,QAAQ,OAAO,MAAM,OAAO,OAAO,MAAMI,KAAI;AAAA,IAC/D;AAEA,UAAM,eAAe,MAAM,aAAa,UAAU,QAAQ,CAAC,QAAQ,CAAC;AACpE,QAAI,cAAc;AAChB,aAAO;AAAA,IACT;AAEA,QAAI,MAAM;AACR,YAAM,kBAAkB,MAAM,aAAa,eAAe,aAAa,CAAC,MAAM,QAAQ,GAAG,gBAAgB;AAEzG,YAAM,aAAa,aAAa,aAAa,CAAC,iBAAiB,QAAQ,CAAC;AACxE,mBAAa,YAAY,UAAU,IAAI,SAAS;AAChD,mBAAa,YAAY,OAAO,EAAE;AAAA,IACpC;AAAA,EACF,CAAC;AAED,QAAM,aAAa,aAAa,cAAc,CAAC,MAAM,CAAC;AAEtD,eAAa,YAAY,IAAI;AAAA,IAC3B,UAAUJ,MAAK,QAAQ,OAAO,MAAM,OAAO,MAAM,IAAI;AAAA,IACrD,QAAQ;AAAA,EACV,CAAC;AAED,eAAa,YAAY,OAAO,UAAU,YAAY;AACpD,UAAM,aAAa,aAAa,UAAU;AAC1C,eAAW,MAAM;AACf,WAAK;AAAA,IACP,GAAG,GAAI;AAAA,EACT,CAAC;AACH;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;;;AUlGO,IAAM,eAAe,CAC1B,YAMG;;;ACLL,IAAO,cAAQ","sourcesContent":["import path from 'path'\n\nimport fse from 'fs-extra'\n\nimport { PluginDriver } from './utils/PluginDriver'\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 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 pluginDriver = new PluginDriver(config, { logger })\n const input = fse.readFileSync(path.resolve(config.root, config.input.path), 'utf-8')\n\n const validations = await pluginDriver.hookParallel<'validate', ValidationResult>('validate', [pluginDriver.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 pluginDriver.fileManager.events.onAdd(async (id, file) => {\n let fileName = file.fileName as string\n let { name, source: code } = file\n\n if (!fileName && name) {\n fileName = path.resolve(config.root, config.output.path, name)\n }\n\n const loadedResult = await pluginDriver.hookFirst('load', [fileName])\n if (loadedResult) {\n code = loadedResult\n }\n\n if (code) {\n const transformedCode = await pluginDriver.hookReduceArg0('transform', [code, fileName], transformReducer)\n\n await pluginDriver.hookParallel('writeFile', [transformedCode, fileName])\n pluginDriver.fileManager.setStatus(id, 'success')\n pluginDriver.fileManager.remove(id)\n }\n })\n\n await pluginDriver.hookParallel('buildStart', [config])\n\n pluginDriver.fileManager.add({\n fileName: path.resolve(config.root, config.input.path),\n source: input,\n })\n\n pluginDriver.fileManager.events.onSuccess(async () => {\n await pluginDriver.hookParallel('buildEnd')\n setTimeout(() => {\n done()\n }, 1000)\n })\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 path from 'path'\n\nimport { createPluginCache, getRelativePath, write } from './utils'\n\nimport { FileManager, File } from './managers'\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\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 async emitFile(emittedFile) {\n const resolvedId = await resolveId({ importee: emittedFile.id, importer: emittedFile.importer, options: emittedFile.options })\n const fileName = resolvedId || emittedFile.importer || emittedFile.id\n\n return fileManager.add({\n fileName: fileName,\n name: emittedFile.name,\n source: emittedFile.source,\n })\n },\n addToRoot: (file: File) => {\n indexFiles.push(file)\n },\n resolveId,\n load,\n cache: createPluginCache(Object.create(null)),\n }\n\n return {\n name,\n api,\n async buildEnd() {\n if (!indexFiles.length) {\n return\n }\n\n let index = ``\n\n indexFiles.forEach((item) => {\n index += `export * from \"${getRelativePath(path.resolve(this.config.root, this.config.output.path), item.fileName)}\";\\n`\n })\n\n await write(index, path.resolve(this.config.root, this.config.output.path, 'index.ts'), { format: true })\n },\n resolveId(importee, importer) {\n if (!importer) {\n return null\n }\n return path.resolve(importer, importee)\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 path from 'path'\n\n// TODO check for a better way or resolving the relative path\nexport const getRelativePath = (from?: string | null, to?: string | null) => {\n if (!from || !to) {\n throw new Error('From and to should be filled in when retrieving the relativePath')\n }\n const newPath = path.relative(from, to).replace('../', '').replace('.ts', '').trimEnd()\n\n return `./${newPath}`\n}\n","import EventEmitter from 'events'\nimport { randomUUID } from 'crypto'\nimport type { CacheStore, UUID, Status, File, UserFile } from './types'\nimport { getFileManagerEvents } from './utils/getFileManagerEvents'\n\nexport class FileManager {\n private cache: Map<CacheStore['id'], CacheStore> = new Map()\n emitter = new EventEmitter()\n events = getFileManagerEvents(this.emitter)\n\n constructor() {\n this.events.onStatusChange(() => {\n if (this.getCountOfStatus('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 private getCountOfStatus(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 add(userFile: UserFile) {\n const file: File = {\n ...userFile,\n } as 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 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 EventEmitter from 'events'\n\nimport type { File, Status, UUID } from '../types'\n\nconst keys = {\n getEmitFileKey: () => `emit-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\nexport const getFileManagerEvents = (emitter: EventEmitter) => {\n return {\n /**\n * Emiter\n */\n emitFile: (id: UUID, file: File): void => {\n emitter.emit(keys.getEmitFileKey(), 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.getEmitFileKey(), callback)\n return () => emitter.removeListener(keys.getEmitFileKey(), 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","/* eslint-disable no-await-in-loop */\n/* eslint-disable no-restricted-syntax */\n\nimport { definePlugin } from '../plugin'\n\nimport type { KubbConfig, KubbPlugin, PluginLifecycleHooks, PluginLifecycle, MaybePromise } from '../types'\nimport type { Logger } from '../build'\nimport type { CorePluginOptions } from '../plugin'\nimport { FileManager } from '../managers'\n\n// inspired by: https://github.com/rollup/rollup/blob/master/src/utils/PluginDriver.ts#\n/**\n * Get the type of the first argument in a function.\n * @example Arg0<(a: string, b: number) => void> -> string\n */\nexport type Argument0<H extends keyof PluginLifecycle> = Parameters<PluginLifecycle[H]>[0]\n\ntype Strategy = 'hookFirst' | 'hookParallel' | 'hookReduceArg0' | 'hookSeq'\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 PluginDriver {\n public plugins: KubbPlugin[]\n\n public readonly fileManager: FileManager = new FileManager()\n\n private readonly logger?: Logger\n\n private readonly config: KubbConfig\n\n public readonly core: KubbPlugin<CorePluginOptions> & { api: CorePluginOptions['api'] }\n\n constructor(config: KubbConfig, options: { logger?: Logger }) {\n this.logger = options.logger\n this.config = config\n\n this.core = definePlugin({\n config,\n fileManager: this.fileManager,\n load: this.load,\n resolveId: (params) => {\n if (params.pluginName) {\n return this.resolveIdForPlugin(params.pluginName)(params.importee, params.importer, params.options)\n }\n return this.resolveId(params.importee, params.importer, params.options)\n },\n }) as KubbPlugin<CorePluginOptions> & {\n api: CorePluginOptions['api']\n }\n this.plugins = [this.core, ...(config.plugins || [])]\n }\n\n resolveId = (importee: string, importer?: string, options?: Record<string, any> | undefined) => {\n return this.hookFirst('resolveId', [importee, importer, options])\n }\n resolveIdForPlugin = (pluginName: string) => (importee: string, importer?: string, options?: Record<string, any> | undefined) => {\n return this.hookForPlugin(pluginName, 'resolveId', [importee, importer, 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 sortedPlugins = [...this.plugins]\n\n if (pluginName) {\n return sortedPlugins.filter((item) => item.name === pluginName)\n }\n return sortedPlugins\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().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 }\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\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 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.21.0",
3
+ "version": "0.21.1",
4
4
  "description": "Generator core",
5
5
  "repository": {
6
6
  "type": "git",