@kubb/core 0.11.1 → 0.11.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +15 -16
- package/dist/index.js +5 -11
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +5 -11
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/schemas/config.json +1 -13
package/dist/index.d.ts
CHANGED
|
@@ -118,7 +118,7 @@ type PluginFactory<TOptions extends PluginOptions = PluginOptions> = (options: T
|
|
|
118
118
|
declare function createPlugin<TOptions extends PluginOptions = PluginOptions>(factory: PluginFactory<TOptions>): (userOptions: TOptions['userOptions']) => TOptions["nested"] extends true ? Plugin<TOptions>[] : Plugin<TOptions>;
|
|
119
119
|
|
|
120
120
|
interface ConfigEnv {
|
|
121
|
-
mode:
|
|
121
|
+
mode: 'development';
|
|
122
122
|
}
|
|
123
123
|
interface UserConfig {
|
|
124
124
|
/**
|
|
@@ -128,26 +128,25 @@ interface UserConfig {
|
|
|
128
128
|
*/
|
|
129
129
|
root?: string;
|
|
130
130
|
mode?: 'single';
|
|
131
|
-
/**
|
|
132
|
-
* plugins means it will run context, buildStart, transform and buildEnd based on order of the plugins array
|
|
133
|
-
* Example of an order(plugin x does not have a buildEnd): [buildStart of plugin x, buildStart of plugin y, transform of plugin x, transform of plugin y, buildEnd of plugin y ]
|
|
134
|
-
* Default: plugins
|
|
135
|
-
*/
|
|
136
|
-
lifeCycle?: 'plugins';
|
|
137
|
-
/**
|
|
138
|
-
* Default: fifo
|
|
139
|
-
*/
|
|
140
|
-
strategy?: 'fifo' | 'lifo';
|
|
141
131
|
input: {
|
|
142
|
-
|
|
132
|
+
/**
|
|
133
|
+
* Path or link to the input file
|
|
134
|
+
*/
|
|
135
|
+
path: string;
|
|
143
136
|
};
|
|
144
137
|
output: {
|
|
138
|
+
/**
|
|
139
|
+
* Path to export folder
|
|
140
|
+
*/
|
|
145
141
|
path: string;
|
|
146
142
|
};
|
|
147
143
|
/**
|
|
148
|
-
* Array of
|
|
144
|
+
* Array of Kubb plugins to use.
|
|
149
145
|
*/
|
|
150
146
|
plugins?: Plugin[];
|
|
147
|
+
/**
|
|
148
|
+
* Log level to report when using the CLI
|
|
149
|
+
*/
|
|
151
150
|
logLevel?: LogLevel;
|
|
152
151
|
}
|
|
153
152
|
type UserConfigFn = (env: ConfigEnv) => WithPromise<UserConfig>;
|
|
@@ -174,7 +173,7 @@ type Api = {
|
|
|
174
173
|
config: UserConfig & {
|
|
175
174
|
root: string;
|
|
176
175
|
};
|
|
177
|
-
|
|
176
|
+
input: Path;
|
|
178
177
|
emitFile: FileEmitter['emitFile'];
|
|
179
178
|
resolveId: (source: string, importer?: string, meta?: Record<string, any>) => WithPromise<string | null | undefined>;
|
|
180
179
|
load: (id: string) => WithPromise<TransformResult | void>;
|
|
@@ -189,7 +188,7 @@ type ValidationResult = true | {
|
|
|
189
188
|
};
|
|
190
189
|
type TransformResult = string | null;
|
|
191
190
|
type Id = string;
|
|
192
|
-
type
|
|
191
|
+
type Path = string;
|
|
193
192
|
type LogType = 'error' | 'warn' | 'info';
|
|
194
193
|
type LogLevel = LogType | 'silent';
|
|
195
194
|
|
|
@@ -216,4 +215,4 @@ declare function getPluginContext(this: PluginDriver, plugin: Plugin, pluginCach
|
|
|
216
215
|
cache: Cache<any>;
|
|
217
216
|
};
|
|
218
217
|
|
|
219
|
-
export { Api, Argument0, BuildContext, Cache, ConfigEnv, EmitFile, EmittedFile, Emitter, FileEmitter, Id, Listener, LogLevel, LogType, Plugin, PluginContext, PluginDriver, PluginFactory, PluginLifecycle, PluginLifecycleHooks, PluginName, PluginOptions,
|
|
218
|
+
export { Api, Argument0, BuildContext, Cache, ConfigEnv, EmitFile, EmittedFile, Emitter, FileEmitter, Id, Listener, LogLevel, LogType, Path, Plugin, PluginContext, PluginDriver, PluginFactory, PluginLifecycle, PluginLifecycleHooks, PluginName, PluginOptions, SerializablePluginCache, TransformResult, UserConfig, UserConfigExport, UserConfigFn, ValidationResult, WithPromise, build, createPlugin, createPluginCache, build as default, defineConfig, format, getPluginContext, getRelativePath, hooks, isPromise, write };
|
package/dist/index.js
CHANGED
|
@@ -144,12 +144,12 @@ function createPlugin(factory) {
|
|
|
144
144
|
var name = "core";
|
|
145
145
|
var definePlugin = createPlugin((options) => {
|
|
146
146
|
const { fileEmitter, resolveId, load } = options;
|
|
147
|
-
const schema = fse2.readFileSync(path2.resolve(options.config.root, options.config.input.
|
|
147
|
+
const schema = fse2.readFileSync(path2.resolve(options.config.root, options.config.input.path), "utf-8");
|
|
148
148
|
const api = {
|
|
149
149
|
get config() {
|
|
150
150
|
return options.config;
|
|
151
151
|
},
|
|
152
|
-
get
|
|
152
|
+
get input() {
|
|
153
153
|
return schema;
|
|
154
154
|
},
|
|
155
155
|
on: fileEmitter.on.bind(fileEmitter),
|
|
@@ -313,12 +313,6 @@ async function transformReducer(previousCode, result, _plugin) {
|
|
|
313
313
|
}
|
|
314
314
|
async function buildImplementation(options, done) {
|
|
315
315
|
const { config } = options;
|
|
316
|
-
if (config.lifeCycle && config.lifeCycle !== "plugins") {
|
|
317
|
-
throw new Error("Only lifeCycle plugins possible");
|
|
318
|
-
}
|
|
319
|
-
if (config.strategy && config.strategy !== "lifo") {
|
|
320
|
-
throw new Error("Only strategy fifo possible");
|
|
321
|
-
}
|
|
322
316
|
const pluginCache = /* @__PURE__ */ Object.create(null);
|
|
323
317
|
const pluginDriver = new PluginDriver(config, pluginCache, { logger: this.logger });
|
|
324
318
|
const validations = await pluginDriver.hookParallel("validate", [pluginDriver.plugins]);
|
|
@@ -350,10 +344,10 @@ async function buildImplementation(options, done) {
|
|
|
350
344
|
});
|
|
351
345
|
await pluginDriver.hookParallel("buildStart");
|
|
352
346
|
pluginDriver.emitFile({
|
|
353
|
-
id: path2.resolve(pluginDriver.api.config.root, pluginDriver.api.config.input.
|
|
354
|
-
source: pluginDriver.api.config.input.
|
|
347
|
+
id: path2.resolve(pluginDriver.api.config.root, pluginDriver.api.config.input.path),
|
|
348
|
+
source: pluginDriver.api.config.input.path,
|
|
355
349
|
name: void 0,
|
|
356
|
-
code: pluginDriver.api.
|
|
350
|
+
code: pluginDriver.api.input
|
|
357
351
|
});
|
|
358
352
|
pluginDriver.fileEmitter.on("end", async () => {
|
|
359
353
|
await pluginDriver.hookParallel("buildEnd");
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/build.ts","../src/utils/Emitter.ts","../src/utils/FileEmitter.ts","../src/utils/cache.ts","../src/context.ts","../src/plugin.ts","../src/utils/PluginDriver.ts","../src/config.ts","../src/utils/isPromise.ts","../src/utils/write.ts","../src/utils/format.ts","../src/utils/read.ts","../src/index.ts"],"names":["path","argument0","fse"],"mappings":";AAIA,OAAOA,WAAU;;;ACFV,IAAM,UAAN,MAAmD;AAAA,EACvC,YAGZ,oBAAI,IAAI;AAAA,EAEI;AAAA,EAEjB,YAAY,QAAoB;AAC9B,SAAK,SAAS;AAAA,EAChB;AAAA,EAEA,QAAQ,QAA6D;AACnE,UAAM,UAAU,CAAC,UAAiC,CAAC,CAAC,KAAK,QAAQ,SAAS,KAAK;AAE/E,QAAI,QAAQ,OAAO,EAAE,GAAG;AACtB,WAAK,UAAU,QAAQ,CAAC,aAAa;AACnC,YAAI,SAAS,UAAU,OAAO,IAAI;AAChC,mBAAS,GAAG,OAAO,EAAE;AAAA,QACvB;AAAA,MACF,CAAC;AACD;AAAA,IACF;AACA,SAAK,UAAU,QAAQ,CAAC,aAAa,SAAS,GAAG,OAAO,EAAY,CAAC;AAAA,EACvE;AAAA,EAEA,YAAkD,CAAC,OAAO;AACxD,UAAM,WAAW;AAAA,MACf,OAAO;AAAA,MACP;AAAA,IACF;AACA,SAAK,UAAU,IAAI,QAAQ;AAE3B,WAAO,MAAM,KAAK,UAAU,OAAO,QAAQ;AAAA,EAC7C;AAAA,EAEA,GAAG,OAAgB,IAAsB;AACvC,UAAM,WAAW;AAAA,MAC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O,cAAQ","sourcesContent":["/* eslint-disable @typescript-eslint/no-unused-vars */\n/* eslint-disable @typescript-eslint/no-empty-function */\n/* eslint-disable no-console */\n\nimport path from 'path'\n\nimport { PluginDriver } from './utils/PluginDriver'\n\nimport type { Api, PluginContext, TransformResult, ValidationResult, LogLevel } from './types'\nimport type { UserConfig, ConfigEnv } from './config'\nimport type { Plugin } from './plugin'\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 BuildContext = {\n logger?: {\n log: (message: string, logLevel: LogLevel) => void\n spinner?: Spinner\n }\n}\n\nasync function transformReducer(this: PluginContext, previousCode: string, result: TransformResult, _plugin: Plugin) {\n if (result === null) {\n return null\n }\n return result\n}\n\ntype BuildImplementationOptions = {\n config: Api['config']\n env: ConfigEnv\n}\n\nasync function buildImplementation(this: BuildContext, options: BuildImplementationOptions, done: (output: BuildOutput) => void) {\n const { config } = options\n if (config.lifeCycle && config.lifeCycle !== 'plugins') {\n throw new Error('Only lifeCycle plugins possible')\n }\n\n if (config.strategy && config.strategy !== 'lifo') {\n throw new Error('Only strategy fifo possible')\n }\n\n const pluginCache = Object.create(null)\n const pluginDriver = new PluginDriver(config, pluginCache, { logger: this.logger })\n\n const validations = await pluginDriver.hookParallel<'validate', ValidationResult>('validate', [pluginDriver.plugins])\n\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 this.logger?.log(validation.message, 'warn')\n }\n })\n\n return\n }\n\n pluginDriver.fileEmitter.on('new', async (emittedFile) => {\n if (!emittedFile?.source) {\n return\n }\n\n const resolvedId = await pluginDriver.hookFirst('resolveId', [emittedFile.source, path.resolve(emittedFile.source), emittedFile.meta])\n const id = resolvedId || emittedFile.source\n let { code } = emittedFile\n\n const loadedResult = await pluginDriver.hookFirst('load', [id])\n if (loadedResult) {\n code = loadedResult\n }\n\n if (code) {\n const result = await pluginDriver.hookReduceArg0('transform', [code, id], transformReducer)\n\n await pluginDriver.hookParallel('writeFile', [result, id])\n pluginDriver.fileEmitter.delete(emittedFile.id)\n }\n })\n\n await pluginDriver.hookParallel('buildStart')\n\n pluginDriver.emitFile({\n id: path.resolve(pluginDriver.api.config.root, pluginDriver.api.config.input.schema),\n source: pluginDriver.api.config.input.schema,\n name: undefined,\n code: pluginDriver.api.schema,\n })\n\n pluginDriver.fileEmitter.on('end', async () => {\n await pluginDriver.hookParallel('buildEnd')\n done()\n })\n}\n\nexport function build(this: BuildContext, userConfig: UserConfig, env: ConfigEnv): Promise<BuildOutput> {\n const config: UserConfig = {\n ...userConfig,\n root: userConfig.root || process.cwd(),\n }\n\n return new Promise((resolve) => {\n buildImplementation.call(\n this,\n {\n config,\n env,\n },\n resolve\n )\n })\n}\n","export type Listener<T> = (value?: T) => void\n\nexport class Emitter<TValue = unknown, TTopics = unknown> {\n private readonly listeners: Set<{\n topic?: TTopics\n cb: Listener<TValue>\n }> = new Set()\n\n private readonly topics?: TTopics[]\n\n constructor(topics?: TTopics[]) {\n this.topics = topics\n }\n\n emit(...params: [topic: TTopics, value?: TValue] | [value?: TValue]) {\n const isTopic = (value: any): value is TTopics => !!this.topics?.includes(value)\n\n if (isTopic(params[0])) {\n this.listeners.forEach((listener) => {\n if (listener.topic === params[0]) {\n listener.cb(params[1])\n }\n })\n return\n }\n this.listeners.forEach((listener) => listener.cb(params[0] as TValue))\n }\n\n subscribe: (cb: Listener<TValue>) => () => void = (cb) => {\n const listener = {\n topic: undefined,\n cb,\n }\n this.listeners.add(listener)\n // Unsubscribe\n return () => this.listeners.delete(listener)\n }\n\n on(topic: TTopics, cb: Listener<TValue>) {\n const listener = {\n topic,\n cb,\n }\n this.listeners.add(listener)\n return () => this.listeners.delete(listener)\n }\n\n destroy: () => void = () => this.listeners.clear()\n}\n","import { Emitter } from './Emitter'\n\nexport interface EmittedFile {\n id: string\n // this can be used as a dynamic path, also resolveId will use this as source(first parameter)\n source: string | undefined\n name: string | undefined\n code: string | undefined\n meta?: Record<string, any>\n}\n\nexport type EmitFile = (emittedFile: EmittedFile) => void\n\ntype Topics = 'new' | 'delete' | 'end'\nexport class FileEmitter {\n private readonly emitter: Emitter<EmittedFile, Topics>\n\n private readonly filesByReferenceId: Map<string, EmittedFile> = new Map()\n\n constructor(emitter: Emitter<EmittedFile, Topics> = new Emitter<EmittedFile, Topics>(['delete', 'end', 'new'])) {\n this.emitter = emitter\n }\n\n emitFile(emitedFile: EmittedFile) {\n // save locally in this class\n this.assignReferenceId(emitedFile, emitedFile.id)\n this.emitter.emit('new', emitedFile)\n return new Promise<EmittedFile>((resolve) => {\n const subscribe = this.emitter.on('delete', (deletedFile) => {\n if (deletedFile?.id === emitedFile.id) {\n resolve(deletedFile)\n return subscribe()\n }\n return undefined\n })\n })\n }\n\n delete(fileReferenceId: string) {\n const deletedFile = this.filesByReferenceId.get(fileReferenceId)\n this.filesByReferenceId.delete(fileReferenceId)\n if (this.filesByReferenceId.size === 0) {\n this.emitter.emit('end')\n }\n return this.emitter.emit('delete', deletedFile)\n }\n\n subscribe(...params: Parameters<typeof this.emitter['subscribe']>) {\n this.emitter.subscribe(...params)\n }\n\n on(...params: Parameters<typeof this.emitter['on']>) {\n this.emitter.on(...params)\n }\n\n private assignReferenceId(emittedFile: EmittedFile, fileReferenceId: string | undefined) {\n if (fileReferenceId) {\n this.filesByReferenceId.set(fileReferenceId, emittedFile)\n }\n }\n\n getEmittedFile = (fileReferenceId?: string | null): EmittedFile | undefined => {\n if (!fileReferenceId) {\n return undefined\n }\n return this.filesByReferenceId.get(fileReferenceId)\n }\n}\n","/* eslint-disable no-param-reassign */\n/* eslint-disable consistent-return */\nexport interface SerializablePluginCache {\n [key: string]: [number, any]\n}\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: SerializablePluginCache): 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","/* eslint-disable no-param-reassign */\nimport { createPluginCache } from './utils/cache'\n\nimport type { PluginDriver } from './utils/PluginDriver'\nimport type { SerializablePluginCache } from './utils/cache'\nimport type { Plugin } from './plugin'\n\nexport function getPluginContext(this: PluginDriver, plugin: Plugin, pluginCache: Record<string, SerializablePluginCache> | void) {\n const cacheKey = plugin.cacheKey || (plugin.name as string)\n\n const cacheInstance = createPluginCache(pluginCache[cacheKey] || (pluginCache[cacheKey] = Object.create(null)))\n\n return {\n cache: cacheInstance,\n }\n}\n","/* eslint-disable no-console */\n\nimport path from 'path'\n\nimport fse from 'fs-extra'\n\nimport type { FileEmitter } from './utils'\nimport type { PluginLifecycle, PluginName, Api } from './types'\n\n// use of type objects\nexport type PluginOptions<UserOptions = unknown, Nested extends boolean = false, Api = any> = {\n userOptions: UserOptions\n nested: Nested\n api: Api\n}\n\nexport type Plugin<TOptions extends PluginOptions = PluginOptions> = {\n name: PluginName | Omit<string, PluginName>\n cacheKey?: string\n api?: TOptions['api']\n} & Partial<PluginLifecycle>\n\nexport type PluginFactory<TOptions extends PluginOptions = PluginOptions> = (\n options: TOptions['userOptions']\n) => TOptions['nested'] extends true ? Array<Plugin<TOptions>> : Plugin<TOptions>\n\nexport function createPlugin<TOptions extends PluginOptions = PluginOptions>(factory: PluginFactory<TOptions>) {\n return (userOptions: TOptions['userOptions']) => {\n const plugin = factory(userOptions)\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 // root will be filled in with a default value in build(process.cwd)\n config: Api['config']\n fileEmitter: FileEmitter\n resolveId: Api['resolveId']\n load: Api['load']\n}\n\n// not exported\ntype CorePluginOptions = PluginOptions<Options, false, Api>\n\nexport const name = 'core' as const\n\nexport const definePlugin = createPlugin<CorePluginOptions>((options) => {\n const { fileEmitter, resolveId, load } = options\n\n const schema = fse.readFileSync(path.resolve(options.config.root, options.config.input.schema), 'utf-8')\n\n const api: Api = {\n get config() {\n return options.config\n },\n get schema() {\n return schema\n },\n on: fileEmitter.on.bind(fileEmitter),\n getEmittedFile: fileEmitter.getEmittedFile.bind(fileEmitter),\n emitFile: fileEmitter.emitFile.bind(fileEmitter),\n resolveId,\n load,\n }\n\n return {\n name,\n api,\n }\n})\n","/* eslint-disable @typescript-eslint/no-non-null-assertion */\n/* eslint-disable @typescript-eslint/no-unused-vars */\n/* eslint-disable no-restricted-syntax */\n/* eslint-disable no-await-in-loop */\n/* eslint-disable no-undef */\n// inspired by: https://github.com/rollup/rollup/blob/master/src/utils/PluginDriver.ts#\n\nimport { FileEmitter } from './FileEmitter'\n\nimport { getPluginContext } from '../context'\nimport { definePlugin } from '../plugin'\n\nimport type { WithPromise } from './isPromise'\nimport type { BuildContext } from '../build'\nimport type { SerializablePluginCache } from './cache'\nimport type { Plugin } from '../plugin'\nimport type { PluginLifecycleHooks, PluginLifecycle, PluginContext, Api } from '../types'\n\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 private readonly pluginContexts: ReadonlyMap<Plugin, PluginContext>\n\n public plugins: Plugin[]\n\n public readonly fileEmitter: FileEmitter\n\n private readonly logger?: BuildContext['logger']\n\n private readonly config: Api['config']\n\n private readonly sortedPlugins = new Map<PluginLifecycleHooks, Plugin[]>()\n\n constructor(config: Api['config'], pluginCache: Record<string, SerializablePluginCache> | undefined, options: { logger: BuildContext['logger'] }) {\n this.logger = options.logger\n this.config = config\n\n this.fileEmitter = new FileEmitter()\n\n this.emitFile = this.fileEmitter.emitFile.bind(this.fileEmitter)\n\n const corePlugin = definePlugin({ config, fileEmitter: this.fileEmitter, load: this.load, resolveId: this.resolveId })\n this.plugins = [corePlugin, ...(config.plugins || [])]\n const coreApi = corePlugin.api\n this.pluginContexts = new Map(\n this.plugins.map((plugin) => {\n const context = {\n ...coreApi,\n ...getPluginContext.call(this, plugin, pluginCache),\n }\n return [plugin, context]\n })\n )\n }\n\n get api() {\n let context = {}\n this.pluginContexts.forEach((value) => {\n context = { ...context, ...value }\n })\n return context as PluginContext\n }\n\n emitFile(...params: Parameters<FileEmitter['emitFile']>) {\n return this.fileEmitter.emitFile(...params)\n }\n\n resolveId = (source: string, importer: string, meta: Record<string, any> | undefined) => {\n return this.hookFirst('resolveId', [source, importer, meta])\n }\n\n load = async (id: string) => {\n const result = await this.hookFirst('load', [id])\n return result\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<Plugin> | 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.runHook('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.runHook('hookParallel', hookName, parameters, plugin)\n } else {\n const promise: Promise<TOuput> = this.runHook('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: Plugin) => WithPromise<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.runHook('hookReduceArg0', hookName, [argument0, ...rest] as Parameters<PluginLifecycle[H]>, plugin).then((result) =>\n reduce.call(this.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.runHook('hookSeq', hookName, parameters, plugin))\n }\n return promise.then(noReturn)\n }\n\n private getSortedPlugins(_hookName: keyof PluginLifecycle): Plugin[] {\n return [...this.plugins]\n }\n\n /**\n * Run an async plugin hook and return the result.\n * @param hookName Name of the plugin hook. Must be either in `PluginHooks` or `OutputPluginValueHooks`.\n * @param args Arguments passed to the plugin hook.\n * @param plugin The actual pluginObject to run.\n */\n // Implementation signature\n private runHook<H extends PluginLifecycleHooks, TResult = void>(\n strategy: Strategy,\n hookName: H,\n parameters: unknown[] | undefined,\n plugin: Plugin\n ): Promise<TResult> {\n // We always filter for plugins that support the hook before running it\n const hook = plugin[hookName]!\n // const context = this.pluginContexts.get(plugin) || {};\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.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 runHookSync<H extends PluginLifecycleHooks>(hookName: H, parameters: Parameters<PluginLifecycle[H]>, plugin: Plugin): 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.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 { WithPromise } from './utils/isPromise'\nimport type { LogLevel } from './types'\nimport type { Plugin } from './plugin'\n\nexport interface ConfigEnv {\n mode: string\n}\n// TODO revert to this to have multiple options like async, object, ...\n// export type PluginOption = PluginOptions | false | null | undefined | PluginOption[] | Promise<PluginOptions | false | null | undefined | PluginOption[]>;\n\nexport interface UserConfig {\n /**\n * Project root directory. Can be an absolute path, or a path relative from\n * the location of the config file itself.\n * @default process.cwd()\n */\n root?: string\n mode?: 'single'\n /**\n * plugins means it will run context, buildStart, transform and buildEnd based on order of the plugins array\n * Example of an order(plugin x does not have a buildEnd): [buildStart of plugin x, buildStart of plugin y, transform of plugin x, transform of plugin y, buildEnd of plugin y ]\n * Default: plugins\n */\n lifeCycle?: 'plugins'\n /**\n * Default: fifo\n */\n strategy?: 'fifo' | 'lifo'\n input: {\n schema: string\n }\n output: {\n path: string\n }\n /**\n * Array of kubb plugins to use.\n */\n plugins?: Plugin[]\n\n logLevel?: LogLevel\n}\n\nexport type UserConfigFn = (env: ConfigEnv) => WithPromise<UserConfig>\nexport type UserConfigExport = WithPromise<UserConfig> | UserConfigFn\n\n/**\n * Type helper to make it easier to use kubb.config.ts\n * accepts a direct {@link UserConfig} object, or a function that returns it.\n * The function receives a {@link ConfigEnv} object that exposes two properties:\n */\nexport function defineConfig(config: UserConfigExport): UserConfigExport {\n return config\n}\n","export type WithPromise<T> = Promise<T> | T\n\nexport const isPromise = <T>(result: WithPromise<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","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 if (newPath.startsWith('./') || newPath.startsWith('../')) {\n return newPath.replace\n }\n return `./${newPath}`\n}\n","/* eslint-disable @typescript-eslint/no-empty-interface */\nimport { build } from './build'\n\nexport * from './config'\nexport * from './build'\nexport { Plugin, PluginOptions, PluginFactory, createPlugin } from './plugin'\nexport * from './utils'\nexport * from './types'\nexport * from './context'\n\nexport default build\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/build.ts","../src/utils/Emitter.ts","../src/utils/FileEmitter.ts","../src/utils/cache.ts","../src/context.ts","../src/plugin.ts","../src/utils/PluginDriver.ts","../src/config.ts","../src/utils/isPromise.ts","../src/utils/write.ts","../src/utils/format.ts","../src/utils/read.ts","../src/index.ts"],"names":["path","argument0","fse"],"mappings":";AAIA,OAAOA,WAAU;;;ACFV,IAAM,UAAN,MAAmD;AAAA,EACvC,YAGZ,oBAAI,IAAI;AAAA,EAEI;AAAA,EAEjB,YAAY,QAAoB;AAC9B,SAAK,SAAS;AAAA,EAChB;AAAA,EAEA,QAAQ,QAA6D;AACnE,UAAM,UAAU,CAAC,UAAiC,CAAC,CAAC,KAAK,QAAQ,SAAS,KAAK;AAE/E,QAAI,QAAQ,OAAO,EAAE,GAAG;AACtB,WAAK,UAAU,QAAQ,CAAC,aAAa;AACnC,YAAI,SAAS,UAAU,OAAO,IAAI;AAChC,mBAAS,GAAG,OAAO,EAAE;AAAA,QACvB;AAAA,MACF,CAAC;AACD;AAAA,IACF;AACA,SAAK,UAAU,QAAQ,CAAC,aAAa,SAAS,GAAG,OAAO,EAAY,CAAC;AAAA,EACvE;AAAA,EAEA,YAAkD,CAAC,OAAO;AACxD,UAAM,WAAW;AAAA,MACf,OAAO;AAAA,MACP;AAAA,IACF;AAC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@typescript-eslint/no-unused-vars */\n/* eslint-disable @typescript-eslint/no-empty-function */\n/* eslint-disable no-console */\n\nimport path from 'path'\n\nimport { PluginDriver } from './utils/PluginDriver'\n\nimport type { Api, PluginContext, TransformResult, ValidationResult, LogLevel } from './types'\nimport type { UserConfig, ConfigEnv } from './config'\nimport type { Plugin } from './plugin'\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 BuildContext = {\n logger?: {\n log: (message: string, logLevel: LogLevel) => void\n spinner?: Spinner\n }\n}\n\nasync function transformReducer(this: PluginContext, previousCode: string, result: TransformResult, _plugin: Plugin) {\n if (result === null) {\n return null\n }\n return result\n}\n\ntype BuildImplementationOptions = {\n config: Api['config']\n env: ConfigEnv\n}\n\nasync function buildImplementation(this: BuildContext, options: BuildImplementationOptions, done: (output: BuildOutput) => void) {\n const { config } = options\n\n const pluginCache = Object.create(null)\n const pluginDriver = new PluginDriver(config, pluginCache, { logger: this.logger })\n\n const validations = await pluginDriver.hookParallel<'validate', ValidationResult>('validate', [pluginDriver.plugins])\n\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 this.logger?.log(validation.message, 'warn')\n }\n })\n\n return\n }\n\n pluginDriver.fileEmitter.on('new', async (emittedFile) => {\n if (!emittedFile?.source) {\n return\n }\n\n const resolvedId = await pluginDriver.hookFirst('resolveId', [emittedFile.source, path.resolve(emittedFile.source), emittedFile.meta])\n const id = resolvedId || emittedFile.source\n let { code } = emittedFile\n\n const loadedResult = await pluginDriver.hookFirst('load', [id])\n if (loadedResult) {\n code = loadedResult\n }\n\n if (code) {\n const result = await pluginDriver.hookReduceArg0('transform', [code, id], transformReducer)\n\n await pluginDriver.hookParallel('writeFile', [result, id])\n pluginDriver.fileEmitter.delete(emittedFile.id)\n }\n })\n\n await pluginDriver.hookParallel('buildStart')\n\n pluginDriver.emitFile({\n id: path.resolve(pluginDriver.api.config.root, pluginDriver.api.config.input.path),\n source: pluginDriver.api.config.input.path,\n name: undefined,\n code: pluginDriver.api.input,\n })\n\n pluginDriver.fileEmitter.on('end', async () => {\n await pluginDriver.hookParallel('buildEnd')\n done()\n })\n}\n\nexport function build(this: BuildContext, userConfig: UserConfig, env: ConfigEnv): Promise<BuildOutput> {\n const config: UserConfig = {\n ...userConfig,\n root: userConfig.root || process.cwd(),\n }\n\n return new Promise((resolve) => {\n buildImplementation.call(\n this,\n {\n config,\n env,\n },\n resolve\n )\n })\n}\n","export type Listener<T> = (value?: T) => void\n\nexport class Emitter<TValue = unknown, TTopics = unknown> {\n private readonly listeners: Set<{\n topic?: TTopics\n cb: Listener<TValue>\n }> = new Set()\n\n private readonly topics?: TTopics[]\n\n constructor(topics?: TTopics[]) {\n this.topics = topics\n }\n\n emit(...params: [topic: TTopics, value?: TValue] | [value?: TValue]) {\n const isTopic = (value: any): value is TTopics => !!this.topics?.includes(value)\n\n if (isTopic(params[0])) {\n this.listeners.forEach((listener) => {\n if (listener.topic === params[0]) {\n listener.cb(params[1])\n }\n })\n return\n }\n this.listeners.forEach((listener) => listener.cb(params[0] as TValue))\n }\n\n subscribe: (cb: Listener<TValue>) => () => void = (cb) => {\n const listener = {\n topic: undefined,\n cb,\n }\n this.listeners.add(listener)\n // Unsubscribe\n return () => this.listeners.delete(listener)\n }\n\n on(topic: TTopics, cb: Listener<TValue>) {\n const listener = {\n topic,\n cb,\n }\n this.listeners.add(listener)\n return () => this.listeners.delete(listener)\n }\n\n destroy: () => void = () => this.listeners.clear()\n}\n","import { Emitter } from './Emitter'\n\nexport interface EmittedFile {\n id: string\n // this can be used as a dynamic path, also resolveId will use this as source(first parameter)\n source: string | undefined\n name: string | undefined\n code: string | undefined\n meta?: Record<string, any>\n}\n\nexport type EmitFile = (emittedFile: EmittedFile) => void\n\ntype Topics = 'new' | 'delete' | 'end'\nexport class FileEmitter {\n private readonly emitter: Emitter<EmittedFile, Topics>\n\n private readonly filesByReferenceId: Map<string, EmittedFile> = new Map()\n\n constructor(emitter: Emitter<EmittedFile, Topics> = new Emitter<EmittedFile, Topics>(['delete', 'end', 'new'])) {\n this.emitter = emitter\n }\n\n emitFile(emitedFile: EmittedFile) {\n // save locally in this class\n this.assignReferenceId(emitedFile, emitedFile.id)\n this.emitter.emit('new', emitedFile)\n return new Promise<EmittedFile>((resolve) => {\n const subscribe = this.emitter.on('delete', (deletedFile) => {\n if (deletedFile?.id === emitedFile.id) {\n resolve(deletedFile)\n return subscribe()\n }\n return undefined\n })\n })\n }\n\n delete(fileReferenceId: string) {\n const deletedFile = this.filesByReferenceId.get(fileReferenceId)\n this.filesByReferenceId.delete(fileReferenceId)\n if (this.filesByReferenceId.size === 0) {\n this.emitter.emit('end')\n }\n return this.emitter.emit('delete', deletedFile)\n }\n\n subscribe(...params: Parameters<typeof this.emitter['subscribe']>) {\n this.emitter.subscribe(...params)\n }\n\n on(...params: Parameters<typeof this.emitter['on']>) {\n this.emitter.on(...params)\n }\n\n private assignReferenceId(emittedFile: EmittedFile, fileReferenceId: string | undefined) {\n if (fileReferenceId) {\n this.filesByReferenceId.set(fileReferenceId, emittedFile)\n }\n }\n\n getEmittedFile = (fileReferenceId?: string | null): EmittedFile | undefined => {\n if (!fileReferenceId) {\n return undefined\n }\n return this.filesByReferenceId.get(fileReferenceId)\n }\n}\n","/* eslint-disable no-param-reassign */\n/* eslint-disable consistent-return */\nexport interface SerializablePluginCache {\n [key: string]: [number, any]\n}\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: SerializablePluginCache): 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","/* eslint-disable no-param-reassign */\nimport { createPluginCache } from './utils/cache'\n\nimport type { PluginDriver } from './utils/PluginDriver'\nimport type { SerializablePluginCache } from './utils/cache'\nimport type { Plugin } from './plugin'\n\nexport function getPluginContext(this: PluginDriver, plugin: Plugin, pluginCache: Record<string, SerializablePluginCache> | void) {\n const cacheKey = plugin.cacheKey || (plugin.name as string)\n\n const cacheInstance = createPluginCache(pluginCache[cacheKey] || (pluginCache[cacheKey] = Object.create(null)))\n\n return {\n cache: cacheInstance,\n }\n}\n","/* eslint-disable no-console */\n\nimport path from 'path'\n\nimport fse from 'fs-extra'\n\nimport type { FileEmitter } from './utils'\nimport type { PluginLifecycle, PluginName, Api } from './types'\n\n// use of type objects\nexport type PluginOptions<UserOptions = unknown, Nested extends boolean = false, Api = any> = {\n userOptions: UserOptions\n nested: Nested\n api: Api\n}\n\nexport type Plugin<TOptions extends PluginOptions = PluginOptions> = {\n name: PluginName | Omit<string, PluginName>\n cacheKey?: string\n api?: TOptions['api']\n} & Partial<PluginLifecycle>\n\nexport type PluginFactory<TOptions extends PluginOptions = PluginOptions> = (\n options: TOptions['userOptions']\n) => TOptions['nested'] extends true ? Array<Plugin<TOptions>> : Plugin<TOptions>\n\nexport function createPlugin<TOptions extends PluginOptions = PluginOptions>(factory: PluginFactory<TOptions>) {\n return (userOptions: TOptions['userOptions']) => {\n const plugin = factory(userOptions)\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 // root will be filled in with a default value in build(process.cwd)\n config: Api['config']\n fileEmitter: FileEmitter\n resolveId: Api['resolveId']\n load: Api['load']\n}\n\n// not exported\ntype CorePluginOptions = PluginOptions<Options, false, Api>\n\nexport const name = 'core' as const\n\nexport const definePlugin = createPlugin<CorePluginOptions>((options) => {\n const { fileEmitter, resolveId, load } = options\n\n const schema = fse.readFileSync(path.resolve(options.config.root, options.config.input.path), 'utf-8')\n\n const api: Api = {\n get config() {\n return options.config\n },\n get input() {\n return schema\n },\n on: fileEmitter.on.bind(fileEmitter),\n getEmittedFile: fileEmitter.getEmittedFile.bind(fileEmitter),\n emitFile: fileEmitter.emitFile.bind(fileEmitter),\n resolveId,\n load,\n }\n\n return {\n name,\n api,\n }\n})\n","/* eslint-disable @typescript-eslint/no-non-null-assertion */\n/* eslint-disable @typescript-eslint/no-unused-vars */\n/* eslint-disable no-restricted-syntax */\n/* eslint-disable no-await-in-loop */\n/* eslint-disable no-undef */\n// inspired by: https://github.com/rollup/rollup/blob/master/src/utils/PluginDriver.ts#\n\nimport { FileEmitter } from './FileEmitter'\n\nimport { getPluginContext } from '../context'\nimport { definePlugin } from '../plugin'\n\nimport type { WithPromise } from './isPromise'\nimport type { BuildContext } from '../build'\nimport type { SerializablePluginCache } from './cache'\nimport type { Plugin } from '../plugin'\nimport type { PluginLifecycleHooks, PluginLifecycle, PluginContext, Api } from '../types'\n\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 private readonly pluginContexts: ReadonlyMap<Plugin, PluginContext>\n\n public plugins: Plugin[]\n\n public readonly fileEmitter: FileEmitter\n\n private readonly logger?: BuildContext['logger']\n\n private readonly config: Api['config']\n\n private readonly sortedPlugins = new Map<PluginLifecycleHooks, Plugin[]>()\n\n constructor(config: Api['config'], pluginCache: Record<string, SerializablePluginCache> | undefined, options: { logger: BuildContext['logger'] }) {\n this.logger = options.logger\n this.config = config\n\n this.fileEmitter = new FileEmitter()\n\n this.emitFile = this.fileEmitter.emitFile.bind(this.fileEmitter)\n\n const corePlugin = definePlugin({ config, fileEmitter: this.fileEmitter, load: this.load, resolveId: this.resolveId })\n this.plugins = [corePlugin, ...(config.plugins || [])]\n const coreApi = corePlugin.api\n this.pluginContexts = new Map(\n this.plugins.map((plugin) => {\n const context = {\n ...coreApi,\n ...getPluginContext.call(this, plugin, pluginCache),\n }\n return [plugin, context]\n })\n )\n }\n\n get api() {\n let context = {}\n this.pluginContexts.forEach((value) => {\n context = { ...context, ...value }\n })\n return context as PluginContext\n }\n\n emitFile(...params: Parameters<FileEmitter['emitFile']>) {\n return this.fileEmitter.emitFile(...params)\n }\n\n resolveId = (source: string, importer: string, meta: Record<string, any> | undefined) => {\n return this.hookFirst('resolveId', [source, importer, meta])\n }\n\n load = async (id: string) => {\n const result = await this.hookFirst('load', [id])\n return result\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<Plugin> | 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.runHook('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.runHook('hookParallel', hookName, parameters, plugin)\n } else {\n const promise: Promise<TOuput> = this.runHook('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: Plugin) => WithPromise<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.runHook('hookReduceArg0', hookName, [argument0, ...rest] as Parameters<PluginLifecycle[H]>, plugin).then((result) =>\n reduce.call(this.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.runHook('hookSeq', hookName, parameters, plugin))\n }\n return promise.then(noReturn)\n }\n\n private getSortedPlugins(_hookName: keyof PluginLifecycle): Plugin[] {\n return [...this.plugins]\n }\n\n /**\n * Run an async plugin hook and return the result.\n * @param hookName Name of the plugin hook. Must be either in `PluginHooks` or `OutputPluginValueHooks`.\n * @param args Arguments passed to the plugin hook.\n * @param plugin The actual pluginObject to run.\n */\n // Implementation signature\n private runHook<H extends PluginLifecycleHooks, TResult = void>(\n strategy: Strategy,\n hookName: H,\n parameters: unknown[] | undefined,\n plugin: Plugin\n ): Promise<TResult> {\n // We always filter for plugins that support the hook before running it\n const hook = plugin[hookName]!\n // const context = this.pluginContexts.get(plugin) || {};\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.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 runHookSync<H extends PluginLifecycleHooks>(hookName: H, parameters: Parameters<PluginLifecycle[H]>, plugin: Plugin): 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.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 { WithPromise } from './utils/isPromise'\nimport type { LogLevel } from './types'\nimport type { Plugin } from './plugin'\n\nexport interface ConfigEnv {\n mode: 'development'\n}\n// TODO revert to this to have multiple options like async, object, ...\n// export type PluginOption = PluginOptions | false | null | undefined | PluginOption[] | Promise<PluginOptions | false | null | undefined | PluginOption[]>;\n\nexport interface UserConfig {\n /**\n * Project root directory. Can be an absolute path, or a path relative from\n * the location of the config file itself.\n * @default process.cwd()\n */\n root?: string\n mode?: 'single'\n input: {\n /**\n * Path or link to the input file\n */\n path: string\n }\n output: {\n /**\n * Path to export folder\n */\n path: string\n }\n /**\n * Array of Kubb plugins to use.\n */\n plugins?: Plugin[]\n /**\n * Log level to report when using the CLI\n */\n\n logLevel?: LogLevel\n}\n\nexport type UserConfigFn = (env: ConfigEnv) => WithPromise<UserConfig>\nexport type UserConfigExport = WithPromise<UserConfig> | UserConfigFn\n\n/**\n * Type helper to make it easier to use kubb.config.ts\n * accepts a direct {@link UserConfig} object, or a function that returns it.\n * The function receives a {@link ConfigEnv} object that exposes two properties:\n */\nexport function defineConfig(config: UserConfigExport): UserConfigExport {\n return config\n}\n","export type WithPromise<T> = Promise<T> | T\n\nexport const isPromise = <T>(result: WithPromise<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","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 if (newPath.startsWith('./') || newPath.startsWith('../')) {\n return newPath.replace\n }\n return `./${newPath}`\n}\n","/* eslint-disable @typescript-eslint/no-empty-interface */\nimport { build } from './build'\n\nexport * from './config'\nexport * from './build'\nexport { Plugin, PluginOptions, PluginFactory, createPlugin } from './plugin'\nexport * from './utils'\nexport * from './types'\nexport * from './context'\n\nexport default build\n"]}
|
package/dist/index.mjs
CHANGED
|
@@ -140,12 +140,12 @@ function createPlugin(factory) {
|
|
|
140
140
|
var name = "core";
|
|
141
141
|
var definePlugin = createPlugin((options) => {
|
|
142
142
|
const { fileEmitter, resolveId, load } = options;
|
|
143
|
-
const schema = fse2.readFileSync(path2.resolve(options.config.root, options.config.input.
|
|
143
|
+
const schema = fse2.readFileSync(path2.resolve(options.config.root, options.config.input.path), "utf-8");
|
|
144
144
|
const api = {
|
|
145
145
|
get config() {
|
|
146
146
|
return options.config;
|
|
147
147
|
},
|
|
148
|
-
get
|
|
148
|
+
get input() {
|
|
149
149
|
return schema;
|
|
150
150
|
},
|
|
151
151
|
on: fileEmitter.on.bind(fileEmitter),
|
|
@@ -309,12 +309,6 @@ async function transformReducer(previousCode, result, _plugin) {
|
|
|
309
309
|
}
|
|
310
310
|
async function buildImplementation(options, done) {
|
|
311
311
|
const { config } = options;
|
|
312
|
-
if (config.lifeCycle && config.lifeCycle !== "plugins") {
|
|
313
|
-
throw new Error("Only lifeCycle plugins possible");
|
|
314
|
-
}
|
|
315
|
-
if (config.strategy && config.strategy !== "lifo") {
|
|
316
|
-
throw new Error("Only strategy fifo possible");
|
|
317
|
-
}
|
|
318
312
|
const pluginCache = /* @__PURE__ */ Object.create(null);
|
|
319
313
|
const pluginDriver = new PluginDriver(config, pluginCache, { logger: this.logger });
|
|
320
314
|
const validations = await pluginDriver.hookParallel("validate", [pluginDriver.plugins]);
|
|
@@ -346,10 +340,10 @@ async function buildImplementation(options, done) {
|
|
|
346
340
|
});
|
|
347
341
|
await pluginDriver.hookParallel("buildStart");
|
|
348
342
|
pluginDriver.emitFile({
|
|
349
|
-
id: path2.resolve(pluginDriver.api.config.root, pluginDriver.api.config.input.
|
|
350
|
-
source: pluginDriver.api.config.input.
|
|
343
|
+
id: path2.resolve(pluginDriver.api.config.root, pluginDriver.api.config.input.path),
|
|
344
|
+
source: pluginDriver.api.config.input.path,
|
|
351
345
|
name: void 0,
|
|
352
|
-
code: pluginDriver.api.
|
|
346
|
+
code: pluginDriver.api.input
|
|
353
347
|
});
|
|
354
348
|
pluginDriver.fileEmitter.on("end", async () => {
|
|
355
349
|
await pluginDriver.hookParallel("buildEnd");
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/build.ts","../src/utils/Emitter.ts","../src/utils/FileEmitter.ts","../src/utils/cache.ts","../src/context.ts","../src/plugin.ts","../src/utils/PluginDriver.ts","../src/config.ts","../src/utils/isPromise.ts","../src/utils/write.ts","../src/utils/format.ts","../src/utils/read.ts","../src/index.ts"],"names":["path","argument0","fse"],"mappings":";AAIA,OAAOA,WAAU;;;ACFV,IAAM,UAAN,MAAmD;AAAA,EACvC,YAGZ,oBAAI,IAAI;AAAA,EAEI;AAAA,EAEjB,YAAY,QAAoB;AAC9B,SAAK,SAAS;AAAA,EAChB;AAAA,EAEA,QAAQ,QAA6D;AACnE,UAAM,UAAU,CAAC,UAAiC,CAAC,CAAC,KAAK,QAAQ,SAAS,KAAK;AAE/E,QAAI,QAAQ,OAAO,EAAE,GAAG;AACtB,WAAK,UAAU,QAAQ,CAAC,aAAa;AACnC,YAAI,SAAS,UAAU,OAAO,IAAI;AAChC,mBAAS,GAAG,OAAO,EAAE;AAAA,QACvB;AAAA,MACF,CAAC;AACD;AAAA,IACF;AACA,SAAK,UAAU,QAAQ,CAAC,aAAa,SAAS,GAAG,OAAO,EAAY,CAAC;AAAA,EACvE;AAAA,EAEA,YAAkD,CAAC,OAAO;AACxD,UAAM,WAAW;AAAA,MACf,OAAO;AAAA,MACP;AAAA,IACF;AACA,SAAK,UAAU,IAAI,QAAQ;AAE3B,WAAO,MAAM,KAAK,UAAU,OAAO,QAAQ;AAAA,EAC7C;AAAA,EAEA,GAAG,OAAgB,IAAsB;AACvC,U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K;AACd;;;ACHA,IAAO,cAAQ","sourcesContent":["/* eslint-disable @typescript-eslint/no-unused-vars */\n/* eslint-disable @typescript-eslint/no-empty-function */\n/* eslint-disable no-console */\n\nimport path from 'path'\n\nimport { PluginDriver } from './utils/PluginDriver'\n\nimport type { Api, PluginContext, TransformResult, ValidationResult, LogLevel } from './types'\nimport type { UserConfig, ConfigEnv } from './config'\nimport type { Plugin } from './plugin'\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 BuildContext = {\n logger?: {\n log: (message: string, logLevel: LogLevel) => void\n spinner?: Spinner\n }\n}\n\nasync function transformReducer(this: PluginContext, previousCode: string, result: TransformResult, _plugin: Plugin) {\n if (result === null) {\n return null\n }\n return result\n}\n\ntype BuildImplementationOptions = {\n config: Api['config']\n env: ConfigEnv\n}\n\nasync function buildImplementation(this: BuildContext, options: BuildImplementationOptions, done: (output: BuildOutput) => void) {\n const { config } = options\n if (config.lifeCycle && config.lifeCycle !== 'plugins') {\n throw new Error('Only lifeCycle plugins possible')\n }\n\n if (config.strategy && config.strategy !== 'lifo') {\n throw new Error('Only strategy fifo possible')\n }\n\n const pluginCache = Object.create(null)\n const pluginDriver = new PluginDriver(config, pluginCache, { logger: this.logger })\n\n const validations = await pluginDriver.hookParallel<'validate', ValidationResult>('validate', [pluginDriver.plugins])\n\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 this.logger?.log(validation.message, 'warn')\n }\n })\n\n return\n }\n\n pluginDriver.fileEmitter.on('new', async (emittedFile) => {\n if (!emittedFile?.source) {\n return\n }\n\n const resolvedId = await pluginDriver.hookFirst('resolveId', [emittedFile.source, path.resolve(emittedFile.source), emittedFile.meta])\n const id = resolvedId || emittedFile.source\n let { code } = emittedFile\n\n const loadedResult = await pluginDriver.hookFirst('load', [id])\n if (loadedResult) {\n code = loadedResult\n }\n\n if (code) {\n const result = await pluginDriver.hookReduceArg0('transform', [code, id], transformReducer)\n\n await pluginDriver.hookParallel('writeFile', [result, id])\n pluginDriver.fileEmitter.delete(emittedFile.id)\n }\n })\n\n await pluginDriver.hookParallel('buildStart')\n\n pluginDriver.emitFile({\n id: path.resolve(pluginDriver.api.config.root, pluginDriver.api.config.input.schema),\n source: pluginDriver.api.config.input.schema,\n name: undefined,\n code: pluginDriver.api.schema,\n })\n\n pluginDriver.fileEmitter.on('end', async () => {\n await pluginDriver.hookParallel('buildEnd')\n done()\n })\n}\n\nexport function build(this: BuildContext, userConfig: UserConfig, env: ConfigEnv): Promise<BuildOutput> {\n const config: UserConfig = {\n ...userConfig,\n root: userConfig.root || process.cwd(),\n }\n\n return new Promise((resolve) => {\n buildImplementation.call(\n this,\n {\n config,\n env,\n },\n resolve\n )\n })\n}\n","export type Listener<T> = (value?: T) => void\n\nexport class Emitter<TValue = unknown, TTopics = unknown> {\n private readonly listeners: Set<{\n topic?: TTopics\n cb: Listener<TValue>\n }> = new Set()\n\n private readonly topics?: TTopics[]\n\n constructor(topics?: TTopics[]) {\n this.topics = topics\n }\n\n emit(...params: [topic: TTopics, value?: TValue] | [value?: TValue]) {\n const isTopic = (value: any): value is TTopics => !!this.topics?.includes(value)\n\n if (isTopic(params[0])) {\n this.listeners.forEach((listener) => {\n if (listener.topic === params[0]) {\n listener.cb(params[1])\n }\n })\n return\n }\n this.listeners.forEach((listener) => listener.cb(params[0] as TValue))\n }\n\n subscribe: (cb: Listener<TValue>) => () => void = (cb) => {\n const listener = {\n topic: undefined,\n cb,\n }\n this.listeners.add(listener)\n // Unsubscribe\n return () => this.listeners.delete(listener)\n }\n\n on(topic: TTopics, cb: Listener<TValue>) {\n const listener = {\n topic,\n cb,\n }\n this.listeners.add(listener)\n return () => this.listeners.delete(listener)\n }\n\n destroy: () => void = () => this.listeners.clear()\n}\n","import { Emitter } from './Emitter'\n\nexport interface EmittedFile {\n id: string\n // this can be used as a dynamic path, also resolveId will use this as source(first parameter)\n source: string | undefined\n name: string | undefined\n code: string | undefined\n meta?: Record<string, any>\n}\n\nexport type EmitFile = (emittedFile: EmittedFile) => void\n\ntype Topics = 'new' | 'delete' | 'end'\nexport class FileEmitter {\n private readonly emitter: Emitter<EmittedFile, Topics>\n\n private readonly filesByReferenceId: Map<string, EmittedFile> = new Map()\n\n constructor(emitter: Emitter<EmittedFile, Topics> = new Emitter<EmittedFile, Topics>(['delete', 'end', 'new'])) {\n this.emitter = emitter\n }\n\n emitFile(emitedFile: EmittedFile) {\n // save locally in this class\n this.assignReferenceId(emitedFile, emitedFile.id)\n this.emitter.emit('new', emitedFile)\n return new Promise<EmittedFile>((resolve) => {\n const subscribe = this.emitter.on('delete', (deletedFile) => {\n if (deletedFile?.id === emitedFile.id) {\n resolve(deletedFile)\n return subscribe()\n }\n return undefined\n })\n })\n }\n\n delete(fileReferenceId: string) {\n const deletedFile = this.filesByReferenceId.get(fileReferenceId)\n this.filesByReferenceId.delete(fileReferenceId)\n if (this.filesByReferenceId.size === 0) {\n this.emitter.emit('end')\n }\n return this.emitter.emit('delete', deletedFile)\n }\n\n subscribe(...params: Parameters<typeof this.emitter['subscribe']>) {\n this.emitter.subscribe(...params)\n }\n\n on(...params: Parameters<typeof this.emitter['on']>) {\n this.emitter.on(...params)\n }\n\n private assignReferenceId(emittedFile: EmittedFile, fileReferenceId: string | undefined) {\n if (fileReferenceId) {\n this.filesByReferenceId.set(fileReferenceId, emittedFile)\n }\n }\n\n getEmittedFile = (fileReferenceId?: string | null): EmittedFile | undefined => {\n if (!fileReferenceId) {\n return undefined\n }\n return this.filesByReferenceId.get(fileReferenceId)\n }\n}\n","/* eslint-disable no-param-reassign */\n/* eslint-disable consistent-return */\nexport interface SerializablePluginCache {\n [key: string]: [number, any]\n}\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: SerializablePluginCache): 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","/* eslint-disable no-param-reassign */\nimport { createPluginCache } from './utils/cache'\n\nimport type { PluginDriver } from './utils/PluginDriver'\nimport type { SerializablePluginCache } from './utils/cache'\nimport type { Plugin } from './plugin'\n\nexport function getPluginContext(this: PluginDriver, plugin: Plugin, pluginCache: Record<string, SerializablePluginCache> | void) {\n const cacheKey = plugin.cacheKey || (plugin.name as string)\n\n const cacheInstance = createPluginCache(pluginCache[cacheKey] || (pluginCache[cacheKey] = Object.create(null)))\n\n return {\n cache: cacheInstance,\n }\n}\n","/* eslint-disable no-console */\n\nimport path from 'path'\n\nimport fse from 'fs-extra'\n\nimport type { FileEmitter } from './utils'\nimport type { PluginLifecycle, PluginName, Api } from './types'\n\n// use of type objects\nexport type PluginOptions<UserOptions = unknown, Nested extends boolean = false, Api = any> = {\n userOptions: UserOptions\n nested: Nested\n api: Api\n}\n\nexport type Plugin<TOptions extends PluginOptions = PluginOptions> = {\n name: PluginName | Omit<string, PluginName>\n cacheKey?: string\n api?: TOptions['api']\n} & Partial<PluginLifecycle>\n\nexport type PluginFactory<TOptions extends PluginOptions = PluginOptions> = (\n options: TOptions['userOptions']\n) => TOptions['nested'] extends true ? Array<Plugin<TOptions>> : Plugin<TOptions>\n\nexport function createPlugin<TOptions extends PluginOptions = PluginOptions>(factory: PluginFactory<TOptions>) {\n return (userOptions: TOptions['userOptions']) => {\n const plugin = factory(userOptions)\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 // root will be filled in with a default value in build(process.cwd)\n config: Api['config']\n fileEmitter: FileEmitter\n resolveId: Api['resolveId']\n load: Api['load']\n}\n\n// not exported\ntype CorePluginOptions = PluginOptions<Options, false, Api>\n\nexport const name = 'core' as const\n\nexport const definePlugin = createPlugin<CorePluginOptions>((options) => {\n const { fileEmitter, resolveId, load } = options\n\n const schema = fse.readFileSync(path.resolve(options.config.root, options.config.input.schema), 'utf-8')\n\n const api: Api = {\n get config() {\n return options.config\n },\n get schema() {\n return schema\n },\n on: fileEmitter.on.bind(fileEmitter),\n getEmittedFile: fileEmitter.getEmittedFile.bind(fileEmitter),\n emitFile: fileEmitter.emitFile.bind(fileEmitter),\n resolveId,\n load,\n }\n\n return {\n name,\n api,\n }\n})\n","/* eslint-disable @typescript-eslint/no-non-null-assertion */\n/* eslint-disable @typescript-eslint/no-unused-vars */\n/* eslint-disable no-restricted-syntax */\n/* eslint-disable no-await-in-loop */\n/* eslint-disable no-undef */\n// inspired by: https://github.com/rollup/rollup/blob/master/src/utils/PluginDriver.ts#\n\nimport { FileEmitter } from './FileEmitter'\n\nimport { getPluginContext } from '../context'\nimport { definePlugin } from '../plugin'\n\nimport type { WithPromise } from './isPromise'\nimport type { BuildContext } from '../build'\nimport type { SerializablePluginCache } from './cache'\nimport type { Plugin } from '../plugin'\nimport type { PluginLifecycleHooks, PluginLifecycle, PluginContext, Api } from '../types'\n\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 private readonly pluginContexts: ReadonlyMap<Plugin, PluginContext>\n\n public plugins: Plugin[]\n\n public readonly fileEmitter: FileEmitter\n\n private readonly logger?: BuildContext['logger']\n\n private readonly config: Api['config']\n\n private readonly sortedPlugins = new Map<PluginLifecycleHooks, Plugin[]>()\n\n constructor(config: Api['config'], pluginCache: Record<string, SerializablePluginCache> | undefined, options: { logger: BuildContext['logger'] }) {\n this.logger = options.logger\n this.config = config\n\n this.fileEmitter = new FileEmitter()\n\n this.emitFile = this.fileEmitter.emitFile.bind(this.fileEmitter)\n\n const corePlugin = definePlugin({ config, fileEmitter: this.fileEmitter, load: this.load, resolveId: this.resolveId })\n this.plugins = [corePlugin, ...(config.plugins || [])]\n const coreApi = corePlugin.api\n this.pluginContexts = new Map(\n this.plugins.map((plugin) => {\n const context = {\n ...coreApi,\n ...getPluginContext.call(this, plugin, pluginCache),\n }\n return [plugin, context]\n })\n )\n }\n\n get api() {\n let context = {}\n this.pluginContexts.forEach((value) => {\n context = { ...context, ...value }\n })\n return context as PluginContext\n }\n\n emitFile(...params: Parameters<FileEmitter['emitFile']>) {\n return this.fileEmitter.emitFile(...params)\n }\n\n resolveId = (source: string, importer: string, meta: Record<string, any> | undefined) => {\n return this.hookFirst('resolveId', [source, importer, meta])\n }\n\n load = async (id: string) => {\n const result = await this.hookFirst('load', [id])\n return result\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<Plugin> | 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.runHook('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.runHook('hookParallel', hookName, parameters, plugin)\n } else {\n const promise: Promise<TOuput> = this.runHook('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: Plugin) => WithPromise<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.runHook('hookReduceArg0', hookName, [argument0, ...rest] as Parameters<PluginLifecycle[H]>, plugin).then((result) =>\n reduce.call(this.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.runHook('hookSeq', hookName, parameters, plugin))\n }\n return promise.then(noReturn)\n }\n\n private getSortedPlugins(_hookName: keyof PluginLifecycle): Plugin[] {\n return [...this.plugins]\n }\n\n /**\n * Run an async plugin hook and return the result.\n * @param hookName Name of the plugin hook. Must be either in `PluginHooks` or `OutputPluginValueHooks`.\n * @param args Arguments passed to the plugin hook.\n * @param plugin The actual pluginObject to run.\n */\n // Implementation signature\n private runHook<H extends PluginLifecycleHooks, TResult = void>(\n strategy: Strategy,\n hookName: H,\n parameters: unknown[] | undefined,\n plugin: Plugin\n ): Promise<TResult> {\n // We always filter for plugins that support the hook before running it\n const hook = plugin[hookName]!\n // const context = this.pluginContexts.get(plugin) || {};\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.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 runHookSync<H extends PluginLifecycleHooks>(hookName: H, parameters: Parameters<PluginLifecycle[H]>, plugin: Plugin): 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.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 { WithPromise } from './utils/isPromise'\nimport type { LogLevel } from './types'\nimport type { Plugin } from './plugin'\n\nexport interface ConfigEnv {\n mode: string\n}\n// TODO revert to this to have multiple options like async, object, ...\n// export type PluginOption = PluginOptions | false | null | undefined | PluginOption[] | Promise<PluginOptions | false | null | undefined | PluginOption[]>;\n\nexport interface UserConfig {\n /**\n * Project root directory. Can be an absolute path, or a path relative from\n * the location of the config file itself.\n * @default process.cwd()\n */\n root?: string\n mode?: 'single'\n /**\n * plugins means it will run context, buildStart, transform and buildEnd based on order of the plugins array\n * Example of an order(plugin x does not have a buildEnd): [buildStart of plugin x, buildStart of plugin y, transform of plugin x, transform of plugin y, buildEnd of plugin y ]\n * Default: plugins\n */\n lifeCycle?: 'plugins'\n /**\n * Default: fifo\n */\n strategy?: 'fifo' | 'lifo'\n input: {\n schema: string\n }\n output: {\n path: string\n }\n /**\n * Array of kubb plugins to use.\n */\n plugins?: Plugin[]\n\n logLevel?: LogLevel\n}\n\nexport type UserConfigFn = (env: ConfigEnv) => WithPromise<UserConfig>\nexport type UserConfigExport = WithPromise<UserConfig> | UserConfigFn\n\n/**\n * Type helper to make it easier to use kubb.config.ts\n * accepts a direct {@link UserConfig} object, or a function that returns it.\n * The function receives a {@link ConfigEnv} object that exposes two properties:\n */\nexport function defineConfig(config: UserConfigExport): UserConfigExport {\n return config\n}\n","export type WithPromise<T> = Promise<T> | T\n\nexport const isPromise = <T>(result: WithPromise<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","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 if (newPath.startsWith('./') || newPath.startsWith('../')) {\n return newPath.replace\n }\n return `./${newPath}`\n}\n","/* eslint-disable @typescript-eslint/no-empty-interface */\nimport { build } from './build'\n\nexport * from './config'\nexport * from './build'\nexport { Plugin, PluginOptions, PluginFactory, createPlugin } from './plugin'\nexport * from './utils'\nexport * from './types'\nexport * from './context'\n\nexport default build\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/build.ts","../src/utils/Emitter.ts","../src/utils/FileEmitter.ts","../src/utils/cache.ts","../src/context.ts","../src/plugin.ts","../src/utils/PluginDriver.ts","../src/config.ts","../src/utils/isPromise.ts","../src/utils/write.ts","../src/utils/format.ts","../src/utils/read.ts","../src/index.ts"],"names":["path","argument0","fse"],"mappings":";AAIA,OAAOA,WAAU;;;ACFV,IAAM,UAAN,MAAmD;AAAA,EACvC,YAGZ,oBAAI,IAAI;AAAA,EAEI;AAAA,EAEjB,YAAY,QAAoB;AAC9B,SAAK,SAAS;AAAA,EAChB;AAAA,EAEA,QAAQ,QAA6D;AACnE,UAAM,UAAU,CAAC,UAAiC,CAAC,CAAC,KAAK,QAAQ,SAAS,KAAK;AAE/E,QAAI,QAAQ,OAAO,EAAE,GAAG;AACtB,WAAK,UAAU,QAAQ,CAAC,aAAa;AACnC,YAAI,SAAS,UAAU,OAAO,IAAI;AAChC,mBAAS,GAAG,OAAO,EAAE;AAAA,QACvB;AAAA,MACF,CAAC;AACD;AAAA,IACF;AACA,SAAK,UAAU,QAAQ,CAAC,aAAa,SAAS,GAAG,OAAO,EAAY,CAAC;AAAA,EACvE;AAAA,EAEA,YAAkD,CAAC,OAAO;AACxD,UAAM,WAAW;AAAA,MACf,OAAO;AAAA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sourcesContent":["/* eslint-disable @typescript-eslint/no-unused-vars */\n/* eslint-disable @typescript-eslint/no-empty-function */\n/* eslint-disable no-console */\n\nimport path from 'path'\n\nimport { PluginDriver } from './utils/PluginDriver'\n\nimport type { Api, PluginContext, TransformResult, ValidationResult, LogLevel } from './types'\nimport type { UserConfig, ConfigEnv } from './config'\nimport type { Plugin } from './plugin'\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 BuildContext = {\n logger?: {\n log: (message: string, logLevel: LogLevel) => void\n spinner?: Spinner\n }\n}\n\nasync function transformReducer(this: PluginContext, previousCode: string, result: TransformResult, _plugin: Plugin) {\n if (result === null) {\n return null\n }\n return result\n}\n\ntype BuildImplementationOptions = {\n config: Api['config']\n env: ConfigEnv\n}\n\nasync function buildImplementation(this: BuildContext, options: BuildImplementationOptions, done: (output: BuildOutput) => void) {\n const { config } = options\n\n const pluginCache = Object.create(null)\n const pluginDriver = new PluginDriver(config, pluginCache, { logger: this.logger })\n\n const validations = await pluginDriver.hookParallel<'validate', ValidationResult>('validate', [pluginDriver.plugins])\n\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 this.logger?.log(validation.message, 'warn')\n }\n })\n\n return\n }\n\n pluginDriver.fileEmitter.on('new', async (emittedFile) => {\n if (!emittedFile?.source) {\n return\n }\n\n const resolvedId = await pluginDriver.hookFirst('resolveId', [emittedFile.source, path.resolve(emittedFile.source), emittedFile.meta])\n const id = resolvedId || emittedFile.source\n let { code } = emittedFile\n\n const loadedResult = await pluginDriver.hookFirst('load', [id])\n if (loadedResult) {\n code = loadedResult\n }\n\n if (code) {\n const result = await pluginDriver.hookReduceArg0('transform', [code, id], transformReducer)\n\n await pluginDriver.hookParallel('writeFile', [result, id])\n pluginDriver.fileEmitter.delete(emittedFile.id)\n }\n })\n\n await pluginDriver.hookParallel('buildStart')\n\n pluginDriver.emitFile({\n id: path.resolve(pluginDriver.api.config.root, pluginDriver.api.config.input.path),\n source: pluginDriver.api.config.input.path,\n name: undefined,\n code: pluginDriver.api.input,\n })\n\n pluginDriver.fileEmitter.on('end', async () => {\n await pluginDriver.hookParallel('buildEnd')\n done()\n })\n}\n\nexport function build(this: BuildContext, userConfig: UserConfig, env: ConfigEnv): Promise<BuildOutput> {\n const config: UserConfig = {\n ...userConfig,\n root: userConfig.root || process.cwd(),\n }\n\n return new Promise((resolve) => {\n buildImplementation.call(\n this,\n {\n config,\n env,\n },\n resolve\n )\n })\n}\n","export type Listener<T> = (value?: T) => void\n\nexport class Emitter<TValue = unknown, TTopics = unknown> {\n private readonly listeners: Set<{\n topic?: TTopics\n cb: Listener<TValue>\n }> = new Set()\n\n private readonly topics?: TTopics[]\n\n constructor(topics?: TTopics[]) {\n this.topics = topics\n }\n\n emit(...params: [topic: TTopics, value?: TValue] | [value?: TValue]) {\n const isTopic = (value: any): value is TTopics => !!this.topics?.includes(value)\n\n if (isTopic(params[0])) {\n this.listeners.forEach((listener) => {\n if (listener.topic === params[0]) {\n listener.cb(params[1])\n }\n })\n return\n }\n this.listeners.forEach((listener) => listener.cb(params[0] as TValue))\n }\n\n subscribe: (cb: Listener<TValue>) => () => void = (cb) => {\n const listener = {\n topic: undefined,\n cb,\n }\n this.listeners.add(listener)\n // Unsubscribe\n return () => this.listeners.delete(listener)\n }\n\n on(topic: TTopics, cb: Listener<TValue>) {\n const listener = {\n topic,\n cb,\n }\n this.listeners.add(listener)\n return () => this.listeners.delete(listener)\n }\n\n destroy: () => void = () => this.listeners.clear()\n}\n","import { Emitter } from './Emitter'\n\nexport interface EmittedFile {\n id: string\n // this can be used as a dynamic path, also resolveId will use this as source(first parameter)\n source: string | undefined\n name: string | undefined\n code: string | undefined\n meta?: Record<string, any>\n}\n\nexport type EmitFile = (emittedFile: EmittedFile) => void\n\ntype Topics = 'new' | 'delete' | 'end'\nexport class FileEmitter {\n private readonly emitter: Emitter<EmittedFile, Topics>\n\n private readonly filesByReferenceId: Map<string, EmittedFile> = new Map()\n\n constructor(emitter: Emitter<EmittedFile, Topics> = new Emitter<EmittedFile, Topics>(['delete', 'end', 'new'])) {\n this.emitter = emitter\n }\n\n emitFile(emitedFile: EmittedFile) {\n // save locally in this class\n this.assignReferenceId(emitedFile, emitedFile.id)\n this.emitter.emit('new', emitedFile)\n return new Promise<EmittedFile>((resolve) => {\n const subscribe = this.emitter.on('delete', (deletedFile) => {\n if (deletedFile?.id === emitedFile.id) {\n resolve(deletedFile)\n return subscribe()\n }\n return undefined\n })\n })\n }\n\n delete(fileReferenceId: string) {\n const deletedFile = this.filesByReferenceId.get(fileReferenceId)\n this.filesByReferenceId.delete(fileReferenceId)\n if (this.filesByReferenceId.size === 0) {\n this.emitter.emit('end')\n }\n return this.emitter.emit('delete', deletedFile)\n }\n\n subscribe(...params: Parameters<typeof this.emitter['subscribe']>) {\n this.emitter.subscribe(...params)\n }\n\n on(...params: Parameters<typeof this.emitter['on']>) {\n this.emitter.on(...params)\n }\n\n private assignReferenceId(emittedFile: EmittedFile, fileReferenceId: string | undefined) {\n if (fileReferenceId) {\n this.filesByReferenceId.set(fileReferenceId, emittedFile)\n }\n }\n\n getEmittedFile = (fileReferenceId?: string | null): EmittedFile | undefined => {\n if (!fileReferenceId) {\n return undefined\n }\n return this.filesByReferenceId.get(fileReferenceId)\n }\n}\n","/* eslint-disable no-param-reassign */\n/* eslint-disable consistent-return */\nexport interface SerializablePluginCache {\n [key: string]: [number, any]\n}\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: SerializablePluginCache): 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","/* eslint-disable no-param-reassign */\nimport { createPluginCache } from './utils/cache'\n\nimport type { PluginDriver } from './utils/PluginDriver'\nimport type { SerializablePluginCache } from './utils/cache'\nimport type { Plugin } from './plugin'\n\nexport function getPluginContext(this: PluginDriver, plugin: Plugin, pluginCache: Record<string, SerializablePluginCache> | void) {\n const cacheKey = plugin.cacheKey || (plugin.name as string)\n\n const cacheInstance = createPluginCache(pluginCache[cacheKey] || (pluginCache[cacheKey] = Object.create(null)))\n\n return {\n cache: cacheInstance,\n }\n}\n","/* eslint-disable no-console */\n\nimport path from 'path'\n\nimport fse from 'fs-extra'\n\nimport type { FileEmitter } from './utils'\nimport type { PluginLifecycle, PluginName, Api } from './types'\n\n// use of type objects\nexport type PluginOptions<UserOptions = unknown, Nested extends boolean = false, Api = any> = {\n userOptions: UserOptions\n nested: Nested\n api: Api\n}\n\nexport type Plugin<TOptions extends PluginOptions = PluginOptions> = {\n name: PluginName | Omit<string, PluginName>\n cacheKey?: string\n api?: TOptions['api']\n} & Partial<PluginLifecycle>\n\nexport type PluginFactory<TOptions extends PluginOptions = PluginOptions> = (\n options: TOptions['userOptions']\n) => TOptions['nested'] extends true ? Array<Plugin<TOptions>> : Plugin<TOptions>\n\nexport function createPlugin<TOptions extends PluginOptions = PluginOptions>(factory: PluginFactory<TOptions>) {\n return (userOptions: TOptions['userOptions']) => {\n const plugin = factory(userOptions)\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 // root will be filled in with a default value in build(process.cwd)\n config: Api['config']\n fileEmitter: FileEmitter\n resolveId: Api['resolveId']\n load: Api['load']\n}\n\n// not exported\ntype CorePluginOptions = PluginOptions<Options, false, Api>\n\nexport const name = 'core' as const\n\nexport const definePlugin = createPlugin<CorePluginOptions>((options) => {\n const { fileEmitter, resolveId, load } = options\n\n const schema = fse.readFileSync(path.resolve(options.config.root, options.config.input.path), 'utf-8')\n\n const api: Api = {\n get config() {\n return options.config\n },\n get input() {\n return schema\n },\n on: fileEmitter.on.bind(fileEmitter),\n getEmittedFile: fileEmitter.getEmittedFile.bind(fileEmitter),\n emitFile: fileEmitter.emitFile.bind(fileEmitter),\n resolveId,\n load,\n }\n\n return {\n name,\n api,\n }\n})\n","/* eslint-disable @typescript-eslint/no-non-null-assertion */\n/* eslint-disable @typescript-eslint/no-unused-vars */\n/* eslint-disable no-restricted-syntax */\n/* eslint-disable no-await-in-loop */\n/* eslint-disable no-undef */\n// inspired by: https://github.com/rollup/rollup/blob/master/src/utils/PluginDriver.ts#\n\nimport { FileEmitter } from './FileEmitter'\n\nimport { getPluginContext } from '../context'\nimport { definePlugin } from '../plugin'\n\nimport type { WithPromise } from './isPromise'\nimport type { BuildContext } from '../build'\nimport type { SerializablePluginCache } from './cache'\nimport type { Plugin } from '../plugin'\nimport type { PluginLifecycleHooks, PluginLifecycle, PluginContext, Api } from '../types'\n\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 private readonly pluginContexts: ReadonlyMap<Plugin, PluginContext>\n\n public plugins: Plugin[]\n\n public readonly fileEmitter: FileEmitter\n\n private readonly logger?: BuildContext['logger']\n\n private readonly config: Api['config']\n\n private readonly sortedPlugins = new Map<PluginLifecycleHooks, Plugin[]>()\n\n constructor(config: Api['config'], pluginCache: Record<string, SerializablePluginCache> | undefined, options: { logger: BuildContext['logger'] }) {\n this.logger = options.logger\n this.config = config\n\n this.fileEmitter = new FileEmitter()\n\n this.emitFile = this.fileEmitter.emitFile.bind(this.fileEmitter)\n\n const corePlugin = definePlugin({ config, fileEmitter: this.fileEmitter, load: this.load, resolveId: this.resolveId })\n this.plugins = [corePlugin, ...(config.plugins || [])]\n const coreApi = corePlugin.api\n this.pluginContexts = new Map(\n this.plugins.map((plugin) => {\n const context = {\n ...coreApi,\n ...getPluginContext.call(this, plugin, pluginCache),\n }\n return [plugin, context]\n })\n )\n }\n\n get api() {\n let context = {}\n this.pluginContexts.forEach((value) => {\n context = { ...context, ...value }\n })\n return context as PluginContext\n }\n\n emitFile(...params: Parameters<FileEmitter['emitFile']>) {\n return this.fileEmitter.emitFile(...params)\n }\n\n resolveId = (source: string, importer: string, meta: Record<string, any> | undefined) => {\n return this.hookFirst('resolveId', [source, importer, meta])\n }\n\n load = async (id: string) => {\n const result = await this.hookFirst('load', [id])\n return result\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<Plugin> | 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.runHook('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.runHook('hookParallel', hookName, parameters, plugin)\n } else {\n const promise: Promise<TOuput> = this.runHook('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: Plugin) => WithPromise<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.runHook('hookReduceArg0', hookName, [argument0, ...rest] as Parameters<PluginLifecycle[H]>, plugin).then((result) =>\n reduce.call(this.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.runHook('hookSeq', hookName, parameters, plugin))\n }\n return promise.then(noReturn)\n }\n\n private getSortedPlugins(_hookName: keyof PluginLifecycle): Plugin[] {\n return [...this.plugins]\n }\n\n /**\n * Run an async plugin hook and return the result.\n * @param hookName Name of the plugin hook. Must be either in `PluginHooks` or `OutputPluginValueHooks`.\n * @param args Arguments passed to the plugin hook.\n * @param plugin The actual pluginObject to run.\n */\n // Implementation signature\n private runHook<H extends PluginLifecycleHooks, TResult = void>(\n strategy: Strategy,\n hookName: H,\n parameters: unknown[] | undefined,\n plugin: Plugin\n ): Promise<TResult> {\n // We always filter for plugins that support the hook before running it\n const hook = plugin[hookName]!\n // const context = this.pluginContexts.get(plugin) || {};\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.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 runHookSync<H extends PluginLifecycleHooks>(hookName: H, parameters: Parameters<PluginLifecycle[H]>, plugin: Plugin): 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.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 { WithPromise } from './utils/isPromise'\nimport type { LogLevel } from './types'\nimport type { Plugin } from './plugin'\n\nexport interface ConfigEnv {\n mode: 'development'\n}\n// TODO revert to this to have multiple options like async, object, ...\n// export type PluginOption = PluginOptions | false | null | undefined | PluginOption[] | Promise<PluginOptions | false | null | undefined | PluginOption[]>;\n\nexport interface UserConfig {\n /**\n * Project root directory. Can be an absolute path, or a path relative from\n * the location of the config file itself.\n * @default process.cwd()\n */\n root?: string\n mode?: 'single'\n input: {\n /**\n * Path or link to the input file\n */\n path: string\n }\n output: {\n /**\n * Path to export folder\n */\n path: string\n }\n /**\n * Array of Kubb plugins to use.\n */\n plugins?: Plugin[]\n /**\n * Log level to report when using the CLI\n */\n\n logLevel?: LogLevel\n}\n\nexport type UserConfigFn = (env: ConfigEnv) => WithPromise<UserConfig>\nexport type UserConfigExport = WithPromise<UserConfig> | UserConfigFn\n\n/**\n * Type helper to make it easier to use kubb.config.ts\n * accepts a direct {@link UserConfig} object, or a function that returns it.\n * The function receives a {@link ConfigEnv} object that exposes two properties:\n */\nexport function defineConfig(config: UserConfigExport): UserConfigExport {\n return config\n}\n","export type WithPromise<T> = Promise<T> | T\n\nexport const isPromise = <T>(result: WithPromise<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","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 if (newPath.startsWith('./') || newPath.startsWith('../')) {\n return newPath.replace\n }\n return `./${newPath}`\n}\n","/* eslint-disable @typescript-eslint/no-empty-interface */\nimport { build } from './build'\n\nexport * from './config'\nexport * from './build'\nexport { Plugin, PluginOptions, PluginFactory, createPlugin } from './plugin'\nexport * from './utils'\nexport * from './types'\nexport * from './context'\n\nexport default build\n"]}
|
package/package.json
CHANGED
package/schemas/config.json
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"type": "object",
|
|
14
14
|
"description": "Input type",
|
|
15
15
|
"properties": {
|
|
16
|
-
"
|
|
16
|
+
"path": {
|
|
17
17
|
"type": "string",
|
|
18
18
|
"description": "Your JSON schema"
|
|
19
19
|
}
|
|
@@ -47,18 +47,6 @@
|
|
|
47
47
|
},
|
|
48
48
|
"description": "Plugins"
|
|
49
49
|
},
|
|
50
|
-
"lifeCycle": {
|
|
51
|
-
"type": "string",
|
|
52
|
-
"description": "lifeCycle, default will be plugins",
|
|
53
|
-
"enum": ["plugins"],
|
|
54
|
-
"default": "plugins"
|
|
55
|
-
},
|
|
56
|
-
"strategy": {
|
|
57
|
-
"type": "string",
|
|
58
|
-
"description": "Strategy, default will be fifo",
|
|
59
|
-
"enum": ["fifo", "lifo"],
|
|
60
|
-
"default": "fifo"
|
|
61
|
-
},
|
|
62
50
|
"logLevel": {
|
|
63
51
|
"type": "string",
|
|
64
52
|
"description": "Log level",
|