@kubb/core 0.11.2 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +54 -60
- package/dist/index.js +110 -128
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +110 -128
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -18,11 +18,24 @@ declare class Emitter<TValue = unknown, TTopics = unknown> {
|
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
interface EmittedFile {
|
|
21
|
+
/**
|
|
22
|
+
* equal to importee when getting passed through resolveId
|
|
23
|
+
*/
|
|
21
24
|
id: string;
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
25
|
+
/**
|
|
26
|
+
* The importer is the fully resolved id of the importing module.
|
|
27
|
+
*/
|
|
28
|
+
importer?: string;
|
|
29
|
+
/**
|
|
30
|
+
* Name to be used to dynamicly create the fileName(based on input.path)
|
|
31
|
+
*/
|
|
32
|
+
name?: string;
|
|
33
|
+
/**
|
|
34
|
+
* FileName will be the end result so no input.path will not be added
|
|
35
|
+
*/
|
|
36
|
+
fileName?: string;
|
|
37
|
+
source?: string;
|
|
38
|
+
options?: Record<string, any>;
|
|
26
39
|
}
|
|
27
40
|
type EmitFile = (emittedFile: EmittedFile) => void;
|
|
28
41
|
type Topics = 'new' | 'delete' | 'end';
|
|
@@ -38,17 +51,6 @@ declare class FileEmitter {
|
|
|
38
51
|
getEmittedFile: (fileReferenceId?: string | null) => EmittedFile | undefined;
|
|
39
52
|
}
|
|
40
53
|
|
|
41
|
-
interface SerializablePluginCache {
|
|
42
|
-
[key: string]: [number, any];
|
|
43
|
-
}
|
|
44
|
-
interface Cache<TCache = any> {
|
|
45
|
-
delete(id: string): boolean;
|
|
46
|
-
get<T = TCache>(id: string): T;
|
|
47
|
-
has(id: string): boolean;
|
|
48
|
-
set<T = TCache>(id: string, value: T): void;
|
|
49
|
-
}
|
|
50
|
-
declare function createPluginCache(cache: SerializablePluginCache): Cache;
|
|
51
|
-
|
|
52
54
|
/**
|
|
53
55
|
* Get the type of the first argument in a function.
|
|
54
56
|
* @example Arg0<(a: string, b: number) => void> -> string
|
|
@@ -56,16 +58,16 @@ declare function createPluginCache(cache: SerializablePluginCache): Cache;
|
|
|
56
58
|
type Argument0<H extends keyof PluginLifecycle> = Parameters<PluginLifecycle[H]>[0];
|
|
57
59
|
declare const hooks: [keyof PluginLifecycle];
|
|
58
60
|
declare class PluginDriver {
|
|
59
|
-
private readonly pluginContexts;
|
|
60
61
|
plugins: Plugin[];
|
|
61
62
|
readonly fileEmitter: FileEmitter;
|
|
62
63
|
private readonly logger?;
|
|
63
64
|
private readonly config;
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
65
|
+
readonly core: Plugin<CorePluginOptions> & {
|
|
66
|
+
api: CorePluginOptions['api'];
|
|
67
|
+
};
|
|
68
|
+
constructor(config: Api['config'], options: {
|
|
69
|
+
logger: BuildOptions['logger'];
|
|
67
70
|
});
|
|
68
|
-
get api(): PluginContext;
|
|
69
71
|
emitFile(...params: Parameters<FileEmitter['emitFile']>): Promise<EmittedFile>;
|
|
70
72
|
resolveId: (source: string, importer: string, meta: Record<string, any> | undefined) => Promise<string | null | undefined>;
|
|
71
73
|
load: (id: string) => Promise<TransformResult>;
|
|
@@ -80,7 +82,7 @@ declare class PluginDriver {
|
|
|
80
82
|
* @param args Arguments passed to the plugin hook.
|
|
81
83
|
* @param plugin The actual pluginObject to run.
|
|
82
84
|
*/
|
|
83
|
-
private
|
|
85
|
+
private run;
|
|
84
86
|
/**
|
|
85
87
|
* Run a sync plugin hook and return the result.
|
|
86
88
|
* @param hookName Name of the plugin hook. Must be in `PluginHooks`.
|
|
@@ -88,21 +90,20 @@ declare class PluginDriver {
|
|
|
88
90
|
* @param plugin The acutal plugin
|
|
89
91
|
* @param replaceContext When passed, the plugin context can be overridden.
|
|
90
92
|
*/
|
|
91
|
-
private
|
|
93
|
+
private runSync;
|
|
92
94
|
}
|
|
93
95
|
|
|
96
|
+
interface Cache<TCache = any> {
|
|
97
|
+
delete(id: string): boolean;
|
|
98
|
+
get<T = TCache>(id: string): T;
|
|
99
|
+
has(id: string): boolean;
|
|
100
|
+
set<T = TCache>(id: string, value: T): void;
|
|
101
|
+
}
|
|
102
|
+
declare function createPluginCache(cache: any): Cache;
|
|
103
|
+
|
|
94
104
|
declare const format: (text: string) => string;
|
|
95
105
|
|
|
96
|
-
declare const getRelativePath: (from?: string | null, to?: string | null) => string
|
|
97
|
-
(searchValue: string | RegExp, replaceValue: string): string;
|
|
98
|
-
(searchValue: string | RegExp, replacer: (substring: string, ...args: any[]) => string): string;
|
|
99
|
-
(searchValue: {
|
|
100
|
-
[Symbol.replace](string: string, replaceValue: string): string;
|
|
101
|
-
}, replaceValue: string): string;
|
|
102
|
-
(searchValue: {
|
|
103
|
-
[Symbol.replace](string: string, replacer: (substring: string, ...args: any[]) => string): string;
|
|
104
|
-
}, replacer: (substring: string, ...args: any[]) => string): string;
|
|
105
|
-
};
|
|
106
|
+
declare const getRelativePath: (from?: string | null, to?: string | null) => string;
|
|
106
107
|
|
|
107
108
|
type PluginOptions<UserOptions = unknown, Nested extends boolean = false, Api = any> = {
|
|
108
109
|
userOptions: UserOptions;
|
|
@@ -110,23 +111,26 @@ type PluginOptions<UserOptions = unknown, Nested extends boolean = false, Api =
|
|
|
110
111
|
api: Api;
|
|
111
112
|
};
|
|
112
113
|
type Plugin<TOptions extends PluginOptions = PluginOptions> = {
|
|
113
|
-
name:
|
|
114
|
-
cacheKey?: string;
|
|
114
|
+
name: string;
|
|
115
115
|
api?: TOptions['api'];
|
|
116
116
|
} & Partial<PluginLifecycle>;
|
|
117
117
|
type PluginFactory<TOptions extends PluginOptions = PluginOptions> = (options: TOptions['userOptions']) => TOptions['nested'] extends true ? Array<Plugin<TOptions>> : Plugin<TOptions>;
|
|
118
118
|
declare function createPlugin<TOptions extends PluginOptions = PluginOptions>(factory: PluginFactory<TOptions>): (userOptions: TOptions['userOptions']) => TOptions["nested"] extends true ? Plugin<TOptions>[] : Plugin<TOptions>;
|
|
119
|
+
type Options = {
|
|
120
|
+
config: Api['config'];
|
|
121
|
+
fileEmitter: FileEmitter;
|
|
122
|
+
resolveId: Api['resolveId'];
|
|
123
|
+
load: Api['load'];
|
|
124
|
+
};
|
|
125
|
+
type CorePluginOptions = PluginOptions<Options, false, Api>;
|
|
119
126
|
|
|
120
|
-
interface ConfigEnv {
|
|
121
|
-
mode: 'development';
|
|
122
|
-
}
|
|
123
127
|
interface UserConfig {
|
|
124
128
|
/**
|
|
125
129
|
* Project root directory. Can be an absolute path, or a path relative from
|
|
126
130
|
* the location of the config file itself.
|
|
127
131
|
* @default process.cwd()
|
|
128
132
|
*/
|
|
129
|
-
root
|
|
133
|
+
root: string;
|
|
130
134
|
mode?: 'single';
|
|
131
135
|
input: {
|
|
132
136
|
/**
|
|
@@ -149,8 +153,9 @@ interface UserConfig {
|
|
|
149
153
|
*/
|
|
150
154
|
logLevel?: LogLevel;
|
|
151
155
|
}
|
|
152
|
-
type UserConfigFn = (
|
|
156
|
+
type UserConfigFn = (options: BuildOptions) => WithPromise<UserConfig>;
|
|
153
157
|
type UserConfigExport = WithPromise<UserConfig> | UserConfigFn;
|
|
158
|
+
declare const defaultConfig: Partial<UserConfig>;
|
|
154
159
|
/**
|
|
155
160
|
* Type helper to make it easier to use kubb.config.ts
|
|
156
161
|
* accepts a direct {@link UserConfig} object, or a function that returns it.
|
|
@@ -158,11 +163,10 @@ type UserConfigExport = WithPromise<UserConfig> | UserConfigFn;
|
|
|
158
163
|
*/
|
|
159
164
|
declare function defineConfig(config: UserConfigExport): UserConfigExport;
|
|
160
165
|
|
|
161
|
-
type PluginName = string;
|
|
162
166
|
type PluginLifecycle = {
|
|
163
167
|
validate: (this: PluginContext, plugins: Plugin[]) => WithPromise<ValidationResult>;
|
|
164
168
|
buildStart: (this: PluginContext) => WithPromise<void>;
|
|
165
|
-
resolveId: (this: PluginContext,
|
|
169
|
+
resolveId: (this: PluginContext, importee: string, importer?: string, options?: Record<string, any>) => string | null | undefined;
|
|
166
170
|
load: (this: PluginContext, id: string) => WithPromise<TransformResult | null>;
|
|
167
171
|
transform: (this: PluginContext, code: string, id: string) => WithPromise<TransformResult>;
|
|
168
172
|
writeFile: (this: PluginContext, code: string | undefined, id: string) => WithPromise<void>;
|
|
@@ -170,25 +174,17 @@ type PluginLifecycle = {
|
|
|
170
174
|
};
|
|
171
175
|
type PluginLifecycleHooks = keyof PluginLifecycle;
|
|
172
176
|
type Api = {
|
|
173
|
-
config: UserConfig
|
|
174
|
-
|
|
175
|
-
};
|
|
176
|
-
input: Path;
|
|
177
|
+
config: UserConfig;
|
|
178
|
+
cache: Cache;
|
|
177
179
|
emitFile: FileEmitter['emitFile'];
|
|
178
|
-
resolveId: (
|
|
180
|
+
resolveId: (importee: string, importer?: string, options?: Record<string, any>) => WithPromise<string | null | undefined>;
|
|
179
181
|
load: (id: string) => WithPromise<TransformResult | void>;
|
|
180
|
-
getEmittedFile: FileEmitter['getEmittedFile'];
|
|
181
|
-
on: FileEmitter['on'];
|
|
182
|
-
};
|
|
183
|
-
type PluginContext = Api & {
|
|
184
|
-
cache: Cache;
|
|
185
182
|
};
|
|
183
|
+
type PluginContext = Api;
|
|
186
184
|
type ValidationResult = true | {
|
|
187
185
|
message: string;
|
|
188
186
|
};
|
|
189
187
|
type TransformResult = string | null;
|
|
190
|
-
type Id = string;
|
|
191
|
-
type Path = string;
|
|
192
188
|
type LogType = 'error' | 'warn' | 'info';
|
|
193
189
|
type LogLevel = LogType | 'silent';
|
|
194
190
|
|
|
@@ -203,16 +199,14 @@ type Spinner = {
|
|
|
203
199
|
text: string;
|
|
204
200
|
info: (text: string) => Spinner;
|
|
205
201
|
};
|
|
206
|
-
type
|
|
202
|
+
type BuildOptions = {
|
|
203
|
+
config: Api['config'];
|
|
204
|
+
mode: 'development' | 'production';
|
|
207
205
|
logger?: {
|
|
208
206
|
log: (message: string, logLevel: LogLevel) => void;
|
|
209
207
|
spinner?: Spinner;
|
|
210
208
|
};
|
|
211
209
|
};
|
|
212
|
-
declare function build(
|
|
213
|
-
|
|
214
|
-
declare function getPluginContext(this: PluginDriver, plugin: Plugin, pluginCache: Record<string, SerializablePluginCache> | void): {
|
|
215
|
-
cache: Cache<any>;
|
|
216
|
-
};
|
|
210
|
+
declare function build(options: BuildOptions): Promise<BuildOutput>;
|
|
217
211
|
|
|
218
|
-
export { Api, Argument0,
|
|
212
|
+
export { Api, Argument0, BuildOptions, Cache, EmitFile, EmittedFile, Emitter, FileEmitter, Listener, LogLevel, LogType, Plugin, PluginContext, PluginDriver, PluginFactory, PluginLifecycle, PluginLifecycleHooks, PluginOptions, TransformResult, UserConfig, UserConfigExport, UserConfigFn, ValidationResult, WithPromise, build, createPlugin, createPluginCache, build as default, defaultConfig, defineConfig, format, getRelativePath, hooks, isPromise, write };
|
package/dist/index.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var
|
|
6
|
-
var
|
|
5
|
+
var path = require('path');
|
|
6
|
+
var fse = require('fs-extra');
|
|
7
7
|
var prettier = require('prettier');
|
|
8
8
|
|
|
9
9
|
// src/build.ts
|
|
@@ -58,7 +58,7 @@ var FileEmitter = class {
|
|
|
58
58
|
this.emitter.emit("new", emitedFile);
|
|
59
59
|
return new Promise((resolve) => {
|
|
60
60
|
const subscribe = this.emitter.on("delete", (deletedFile) => {
|
|
61
|
-
if (deletedFile?.id === emitedFile.id) {
|
|
61
|
+
if (deletedFile?.id && deletedFile?.id === emitedFile.id) {
|
|
62
62
|
resolve(deletedFile);
|
|
63
63
|
return subscribe();
|
|
64
64
|
}
|
|
@@ -93,6 +93,38 @@ var FileEmitter = class {
|
|
|
93
93
|
};
|
|
94
94
|
};
|
|
95
95
|
|
|
96
|
+
// src/utils/isPromise.ts
|
|
97
|
+
var isPromise = (result) => {
|
|
98
|
+
return typeof result?.then === "function";
|
|
99
|
+
};
|
|
100
|
+
var formatOptions = {
|
|
101
|
+
tabWidth: 2,
|
|
102
|
+
printWidth: 160,
|
|
103
|
+
parser: "typescript",
|
|
104
|
+
singleQuote: true,
|
|
105
|
+
semi: false,
|
|
106
|
+
bracketSameLine: false,
|
|
107
|
+
endOfLine: "auto"
|
|
108
|
+
};
|
|
109
|
+
var format = (text) => {
|
|
110
|
+
return prettier.format(text, formatOptions);
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
// src/utils/write.ts
|
|
114
|
+
var write = async (data, path4, options = { format: false }) => {
|
|
115
|
+
const formattedData = options.format ? format(data) : data;
|
|
116
|
+
try {
|
|
117
|
+
await fse.stat(path4);
|
|
118
|
+
const oldContent = await fse.readFile(path4, { encoding: "utf-8" });
|
|
119
|
+
if (oldContent?.toString() === formattedData) {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
} catch (_err) {
|
|
123
|
+
return fse.outputFile(path4, formattedData);
|
|
124
|
+
}
|
|
125
|
+
return fse.outputFile(path4, formattedData);
|
|
126
|
+
};
|
|
127
|
+
|
|
96
128
|
// src/utils/cache.ts
|
|
97
129
|
function createPluginCache(cache) {
|
|
98
130
|
return {
|
|
@@ -118,15 +150,15 @@ function createPluginCache(cache) {
|
|
|
118
150
|
}
|
|
119
151
|
};
|
|
120
152
|
}
|
|
153
|
+
var getRelativePath = (from, to) => {
|
|
154
|
+
if (!from || !to) {
|
|
155
|
+
throw new Error("From and to should be filled in when retrieving the relativePath");
|
|
156
|
+
}
|
|
157
|
+
const newPath = path.relative(from, to).replace("../", "").replace(".ts", "").trimEnd();
|
|
158
|
+
return `./${newPath}`;
|
|
159
|
+
};
|
|
121
160
|
|
|
122
|
-
// src/
|
|
123
|
-
function getPluginContext(plugin, pluginCache) {
|
|
124
|
-
const cacheKey = plugin.cacheKey || plugin.name;
|
|
125
|
-
const cacheInstance = createPluginCache(pluginCache[cacheKey] || (pluginCache[cacheKey] = /* @__PURE__ */ Object.create(null)));
|
|
126
|
-
return {
|
|
127
|
-
cache: cacheInstance
|
|
128
|
-
};
|
|
129
|
-
}
|
|
161
|
+
// src/plugin.ts
|
|
130
162
|
function createPlugin(factory) {
|
|
131
163
|
return (userOptions) => {
|
|
132
164
|
const plugin = factory(userOptions);
|
|
@@ -144,23 +176,31 @@ function createPlugin(factory) {
|
|
|
144
176
|
var name = "core";
|
|
145
177
|
var definePlugin = createPlugin((options) => {
|
|
146
178
|
const { fileEmitter, resolveId, load } = options;
|
|
147
|
-
const schema = fse2.readFileSync(path2.resolve(options.config.root, options.config.input.path), "utf-8");
|
|
148
179
|
const api = {
|
|
149
180
|
get config() {
|
|
150
181
|
return options.config;
|
|
151
182
|
},
|
|
152
|
-
|
|
153
|
-
|
|
183
|
+
async emitFile(emittedFile) {
|
|
184
|
+
const resolvedId = await resolveId(emittedFile.id, emittedFile.importer, emittedFile.options);
|
|
185
|
+
const id = resolvedId || emittedFile.importer || emittedFile.id;
|
|
186
|
+
return fileEmitter.emitFile({
|
|
187
|
+
...emittedFile,
|
|
188
|
+
id
|
|
189
|
+
});
|
|
154
190
|
},
|
|
155
|
-
on: fileEmitter.on.bind(fileEmitter),
|
|
156
|
-
getEmittedFile: fileEmitter.getEmittedFile.bind(fileEmitter),
|
|
157
|
-
emitFile: fileEmitter.emitFile.bind(fileEmitter),
|
|
158
191
|
resolveId,
|
|
159
|
-
load
|
|
192
|
+
load,
|
|
193
|
+
cache: createPluginCache(/* @__PURE__ */ Object.create(null))
|
|
160
194
|
};
|
|
161
195
|
return {
|
|
162
196
|
name,
|
|
163
|
-
api
|
|
197
|
+
api,
|
|
198
|
+
resolveId(importee, importer) {
|
|
199
|
+
if (!importer) {
|
|
200
|
+
return null;
|
|
201
|
+
}
|
|
202
|
+
return path.resolve(importer, importee);
|
|
203
|
+
}
|
|
164
204
|
};
|
|
165
205
|
});
|
|
166
206
|
|
|
@@ -176,36 +216,17 @@ var hookNames = {
|
|
|
176
216
|
};
|
|
177
217
|
var hooks = Object.keys(hookNames);
|
|
178
218
|
var PluginDriver = class {
|
|
179
|
-
pluginContexts;
|
|
180
219
|
plugins;
|
|
181
|
-
fileEmitter;
|
|
220
|
+
fileEmitter = new FileEmitter();
|
|
182
221
|
logger;
|
|
183
222
|
config;
|
|
184
|
-
|
|
185
|
-
constructor(config,
|
|
223
|
+
core;
|
|
224
|
+
constructor(config, options) {
|
|
186
225
|
this.logger = options.logger;
|
|
187
226
|
this.config = config;
|
|
188
|
-
this.fileEmitter = new FileEmitter();
|
|
189
227
|
this.emitFile = this.fileEmitter.emitFile.bind(this.fileEmitter);
|
|
190
|
-
|
|
191
|
-
this.plugins = [
|
|
192
|
-
const coreApi = corePlugin.api;
|
|
193
|
-
this.pluginContexts = new Map(
|
|
194
|
-
this.plugins.map((plugin) => {
|
|
195
|
-
const context = {
|
|
196
|
-
...coreApi,
|
|
197
|
-
...getPluginContext.call(this, plugin, pluginCache)
|
|
198
|
-
};
|
|
199
|
-
return [plugin, context];
|
|
200
|
-
})
|
|
201
|
-
);
|
|
202
|
-
}
|
|
203
|
-
get api() {
|
|
204
|
-
let context = {};
|
|
205
|
-
this.pluginContexts.forEach((value) => {
|
|
206
|
-
context = { ...context, ...value };
|
|
207
|
-
});
|
|
208
|
-
return context;
|
|
228
|
+
this.core = definePlugin({ config, fileEmitter: this.fileEmitter, load: this.load, resolveId: this.resolveId });
|
|
229
|
+
this.plugins = [this.core, ...config.plugins || []];
|
|
209
230
|
}
|
|
210
231
|
emitFile(...params) {
|
|
211
232
|
return this.fileEmitter.emitFile(...params);
|
|
@@ -225,7 +246,7 @@ var PluginDriver = class {
|
|
|
225
246
|
promise = promise.then((result) => {
|
|
226
247
|
if (result != null)
|
|
227
248
|
return result;
|
|
228
|
-
return this.
|
|
249
|
+
return this.run("hookFirst", hookName, parameters, plugin);
|
|
229
250
|
});
|
|
230
251
|
}
|
|
231
252
|
return promise;
|
|
@@ -236,9 +257,9 @@ var PluginDriver = class {
|
|
|
236
257
|
if (plugin[hookName]?.sequential) {
|
|
237
258
|
await Promise.all(parallelPromises);
|
|
238
259
|
parallelPromises.length = 0;
|
|
239
|
-
await this.
|
|
260
|
+
await this.run("hookParallel", hookName, parameters, plugin);
|
|
240
261
|
} else {
|
|
241
|
-
const promise = this.
|
|
262
|
+
const promise = this.run("hookParallel", hookName, parameters, plugin);
|
|
242
263
|
parallelPromises.push(promise);
|
|
243
264
|
}
|
|
244
265
|
}
|
|
@@ -248,8 +269,8 @@ var PluginDriver = class {
|
|
|
248
269
|
let promise = Promise.resolve(argument0);
|
|
249
270
|
for (const plugin of this.getSortedPlugins(hookName)) {
|
|
250
271
|
promise = promise.then(
|
|
251
|
-
(argument02) => this.
|
|
252
|
-
(result) => reduce.call(this.api, argument02, result, plugin)
|
|
272
|
+
(argument02) => this.run("hookReduceArg0", hookName, [argument02, ...rest], plugin).then(
|
|
273
|
+
(result) => reduce.call(this.core.api, argument02, result, plugin)
|
|
253
274
|
)
|
|
254
275
|
);
|
|
255
276
|
}
|
|
@@ -258,14 +279,14 @@ var PluginDriver = class {
|
|
|
258
279
|
hookSeq(hookName, parameters) {
|
|
259
280
|
let promise = Promise.resolve();
|
|
260
281
|
for (const plugin of this.getSortedPlugins(hookName)) {
|
|
261
|
-
promise = promise.then(() => this.
|
|
282
|
+
promise = promise.then(() => this.run("hookSeq", hookName, parameters, plugin));
|
|
262
283
|
}
|
|
263
284
|
return promise.then(noReturn);
|
|
264
285
|
}
|
|
265
286
|
getSortedPlugins(_hookName) {
|
|
266
287
|
return [...this.plugins];
|
|
267
288
|
}
|
|
268
|
-
|
|
289
|
+
run(strategy, hookName, parameters, plugin) {
|
|
269
290
|
const hook = plugin[hookName];
|
|
270
291
|
return Promise.resolve().then(() => {
|
|
271
292
|
if (typeof hook !== "function") {
|
|
@@ -275,7 +296,7 @@ var PluginDriver = class {
|
|
|
275
296
|
this.logger.spinner.text = `[${strategy}] ${hookName}: Excecuting task for plugin ${plugin.name}
|
|
276
297
|
`;
|
|
277
298
|
}
|
|
278
|
-
const hookResult = hook.apply(this.api, parameters);
|
|
299
|
+
const hookResult = hook.apply(this.core.api, parameters);
|
|
279
300
|
if (!hookResult?.then) {
|
|
280
301
|
if (this.config.logLevel === "info" && this.logger?.spinner) {
|
|
281
302
|
this.logger.spinner.succeed(`[${strategy}] ${hookName}: Excecuting task for plugin ${plugin.name}
|
|
@@ -292,10 +313,10 @@ var PluginDriver = class {
|
|
|
292
313
|
});
|
|
293
314
|
});
|
|
294
315
|
}
|
|
295
|
-
|
|
316
|
+
runSync(hookName, parameters, plugin) {
|
|
296
317
|
const hook = plugin[hookName];
|
|
297
318
|
try {
|
|
298
|
-
return hook.apply(this.api, parameters);
|
|
319
|
+
return hook.apply(this.core.api, parameters);
|
|
299
320
|
} catch (error) {
|
|
300
321
|
return error;
|
|
301
322
|
}
|
|
@@ -304,6 +325,14 @@ var PluginDriver = class {
|
|
|
304
325
|
function noReturn() {
|
|
305
326
|
}
|
|
306
327
|
|
|
328
|
+
// src/config.ts
|
|
329
|
+
var defaultConfig = {
|
|
330
|
+
root: process.cwd()
|
|
331
|
+
};
|
|
332
|
+
function defineConfig(config) {
|
|
333
|
+
return config;
|
|
334
|
+
}
|
|
335
|
+
|
|
307
336
|
// src/build.ts
|
|
308
337
|
async function transformReducer(previousCode, result, _plugin) {
|
|
309
338
|
if (result === null) {
|
|
@@ -312,112 +341,65 @@ async function transformReducer(previousCode, result, _plugin) {
|
|
|
312
341
|
return result;
|
|
313
342
|
}
|
|
314
343
|
async function buildImplementation(options, done) {
|
|
315
|
-
const { config } = options;
|
|
316
|
-
const
|
|
317
|
-
|
|
344
|
+
const { config, logger } = options;
|
|
345
|
+
const pluginDriver = new PluginDriver(
|
|
346
|
+
{
|
|
347
|
+
...defaultConfig,
|
|
348
|
+
...config
|
|
349
|
+
},
|
|
350
|
+
{ logger }
|
|
351
|
+
);
|
|
352
|
+
const input = fse.readFileSync(path.resolve(config.root, config.input.path), "utf-8");
|
|
318
353
|
const validations = await pluginDriver.hookParallel("validate", [pluginDriver.plugins]);
|
|
319
354
|
const validationsWithMessage = validations.filter(Boolean);
|
|
320
355
|
if (validationsWithMessage.some((validation) => typeof validation !== "boolean")) {
|
|
321
356
|
validationsWithMessage.forEach((validation) => {
|
|
322
357
|
if (validation && typeof validation !== "boolean" && validation?.message) {
|
|
323
|
-
|
|
358
|
+
logger?.log(validation.message, "warn");
|
|
324
359
|
}
|
|
325
360
|
});
|
|
326
361
|
return;
|
|
327
362
|
}
|
|
328
363
|
pluginDriver.fileEmitter.on("new", async (emittedFile) => {
|
|
329
|
-
if (!emittedFile
|
|
364
|
+
if (!emittedFile) {
|
|
330
365
|
return;
|
|
331
366
|
}
|
|
332
|
-
const
|
|
333
|
-
|
|
334
|
-
|
|
367
|
+
const { id } = emittedFile;
|
|
368
|
+
if (!id) {
|
|
369
|
+
throw new Error("No id could be transformed, please add id to emitFile or use resolveId");
|
|
370
|
+
}
|
|
371
|
+
let { source: code } = emittedFile;
|
|
335
372
|
const loadedResult = await pluginDriver.hookFirst("load", [id]);
|
|
336
373
|
if (loadedResult) {
|
|
337
374
|
code = loadedResult;
|
|
338
375
|
}
|
|
339
376
|
if (code) {
|
|
340
|
-
const
|
|
341
|
-
await pluginDriver.hookParallel("writeFile", [
|
|
377
|
+
const transformedCode = await pluginDriver.hookReduceArg0("transform", [code, id], transformReducer);
|
|
378
|
+
await pluginDriver.hookParallel("writeFile", [transformedCode, id]);
|
|
342
379
|
pluginDriver.fileEmitter.delete(emittedFile.id);
|
|
343
380
|
}
|
|
344
381
|
});
|
|
345
382
|
await pluginDriver.hookParallel("buildStart");
|
|
346
383
|
pluginDriver.emitFile({
|
|
347
|
-
id:
|
|
348
|
-
source: pluginDriver.api.config.input.path,
|
|
384
|
+
id: config.input.path,
|
|
349
385
|
name: void 0,
|
|
350
|
-
|
|
386
|
+
source: input
|
|
351
387
|
});
|
|
352
388
|
pluginDriver.fileEmitter.on("end", async () => {
|
|
353
389
|
await pluginDriver.hookParallel("buildEnd");
|
|
354
390
|
done();
|
|
355
391
|
});
|
|
356
392
|
}
|
|
357
|
-
function build(
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
this,
|
|
365
|
-
{
|
|
366
|
-
config,
|
|
367
|
-
env
|
|
368
|
-
},
|
|
369
|
-
resolve
|
|
370
|
-
);
|
|
393
|
+
function build(options) {
|
|
394
|
+
return new Promise((resolve, reject) => {
|
|
395
|
+
try {
|
|
396
|
+
buildImplementation(options, resolve);
|
|
397
|
+
} catch (e) {
|
|
398
|
+
reject(e);
|
|
399
|
+
}
|
|
371
400
|
});
|
|
372
401
|
}
|
|
373
402
|
|
|
374
|
-
// src/config.ts
|
|
375
|
-
function defineConfig(config) {
|
|
376
|
-
return config;
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
// src/utils/isPromise.ts
|
|
380
|
-
var isPromise = (result) => {
|
|
381
|
-
return typeof result?.then === "function";
|
|
382
|
-
};
|
|
383
|
-
var formatOptions = {
|
|
384
|
-
tabWidth: 2,
|
|
385
|
-
printWidth: 160,
|
|
386
|
-
parser: "typescript",
|
|
387
|
-
singleQuote: true,
|
|
388
|
-
semi: false,
|
|
389
|
-
bracketSameLine: false,
|
|
390
|
-
endOfLine: "auto"
|
|
391
|
-
};
|
|
392
|
-
var format = (text) => {
|
|
393
|
-
return prettier.format(text, formatOptions);
|
|
394
|
-
};
|
|
395
|
-
|
|
396
|
-
// src/utils/write.ts
|
|
397
|
-
var write = async (data, path4, options = { format: false }) => {
|
|
398
|
-
const formattedData = options.format ? format(data) : data;
|
|
399
|
-
try {
|
|
400
|
-
await fse2.stat(path4);
|
|
401
|
-
const oldContent = await fse2.readFile(path4, { encoding: "utf-8" });
|
|
402
|
-
if (oldContent?.toString() === formattedData) {
|
|
403
|
-
return;
|
|
404
|
-
}
|
|
405
|
-
} catch (_err) {
|
|
406
|
-
return fse2.outputFile(path4, formattedData);
|
|
407
|
-
}
|
|
408
|
-
return fse2.outputFile(path4, formattedData);
|
|
409
|
-
};
|
|
410
|
-
var getRelativePath = (from, to) => {
|
|
411
|
-
if (!from || !to) {
|
|
412
|
-
throw new Error("From and to should be filled in when retrieving the relativePath");
|
|
413
|
-
}
|
|
414
|
-
const newPath = path2.relative(from, to).replace("../", "").replace(".ts", "").trimEnd();
|
|
415
|
-
if (newPath.startsWith("./") || newPath.startsWith("../")) {
|
|
416
|
-
return newPath.replace;
|
|
417
|
-
}
|
|
418
|
-
return `./${newPath}`;
|
|
419
|
-
};
|
|
420
|
-
|
|
421
403
|
// src/index.ts
|
|
422
404
|
var src_default = build;
|
|
423
405
|
|
|
@@ -428,9 +410,9 @@ exports.build = build;
|
|
|
428
410
|
exports.createPlugin = createPlugin;
|
|
429
411
|
exports.createPluginCache = createPluginCache;
|
|
430
412
|
exports.default = src_default;
|
|
413
|
+
exports.defaultConfig = defaultConfig;
|
|
431
414
|
exports.defineConfig = defineConfig;
|
|
432
415
|
exports.format = format;
|
|
433
|
-
exports.getPluginContext = getPluginContext;
|
|
434
416
|
exports.getRelativePath = getRelativePath;
|
|
435
417
|
exports.hooks = hooks;
|
|
436
418
|
exports.isPromise = isPromise;
|
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,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I,WAAWF,OAAM,aAAa;AAC3C;;;AEvBA,OAAOA,WAAU;AAGV,IAAM,kBAAkB,CAAC,MAAsB,OAAuB;AAC3E,MAAI,CAAC,QAAQ,CAAC,IAAI;AAChB,UAAM,IAAI,MAAM,kEAAkE;AAAA,EACpF;AACA,QAAM,UAAUA,MAAK,SAAS,MAAM,EAAE,EAAE,QAAQ,OAAO,EAAE,EAAE,QAAQ,OAAO,EAAE,EAAE,QAAQ;AAEtF,MAAI,QAAQ,WAAW,IAAI,KAAK,QAAQ,WAAW,KAAK,GAAG;AACzD,WAAO,QAAQ;AAAA,EACjB;AACA,SAAO,KAAK;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\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"]}
|
|
1
|
+
{"version":3,"sources":["../src/build.ts","../src/utils/Emitter.ts","../src/utils/FileEmitter.ts","../src/plugin.ts","../src/utils/isPromise.ts","../src/utils/write.ts","../src/utils/format.ts","../src/utils/cache.ts","../src/utils/read.ts","../src/utils/PluginDriver.ts","../src/config.ts","../src/index.ts"],"names":["path","fse","argument0"],"mappings":";AAIA,OAAOA,WAAU;AAEjB,OAAOC,UAAS;;;ACJT,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,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ACR,YAAM,kBAAkB,MAAM,aAAa,eAAe,aAAa,CAAC,MAAM,EAAE,GAAG,gBAAgB;AAEnG,YAAM,aAAa,aAAa,aAAa,CAAC,iBAAiB,EAAE,CAAC;AAClE,mBAAa,YAAY,OAAO,YAAY,EAAE;AAAA,IAChD;AAAA,EACF,CAAC;AAED,QAAM,aAAa,aAAa,YAAY;AAE5C,eAAa,SAAS;AAAA,IACpB,IAAI,OAAO,MAAM;AAAA,IACjB,MAAM;AAAA,IACN,QAAQ;AAAA,EACV,CAAC;AAED,eAAa,YAAY,GAAG,OAAO,YAAY;AAC7C,UAAM,aAAa,aAAa,UAAU;AAC1C,SAAK;AAAA,EACP,CAAC;AACH;AAEO,SAAS,MAAM,SAA6C;AACjE,SAAO,IAAI,QAAQ,CAAC,SAAS,WAAW;AACtC,QAAI;AACF,0BAAoB,SAAS,OAAO;AAAA,IACtC,SAAS,GAAP;AACA,aAAO,CAAC;AAAA,IACV;AAAA,EACF,CAAC;AACH;;;AWzGA,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 fse from 'fs-extra'\n\nimport { PluginDriver } from './utils/PluginDriver'\nimport { defaultConfig } from './config'\n\nimport type { Api, PluginContext, TransformResult, ValidationResult, LogLevel } from './types'\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 BuildOptions = {\n config: Api['config']\n mode: 'development' | 'production'\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\nasync function buildImplementation(options: BuildOptions, done: (output: BuildOutput) => void) {\n const { config, logger } = options\n\n const pluginDriver = new PluginDriver(\n {\n ...defaultConfig,\n ...config,\n },\n { logger }\n )\n const input = fse.readFileSync(path.resolve(config.root, config.input.path), 'utf-8')\n\n const validations = await pluginDriver.hookParallel<'validate', ValidationResult>('validate', [pluginDriver.plugins])\n const validationsWithMessage = validations.filter(Boolean)\n\n if (validationsWithMessage.some((validation) => typeof validation !== 'boolean')) {\n validationsWithMessage.forEach((validation) => {\n if (validation && typeof validation !== 'boolean' && validation?.message) {\n logger?.log(validation.message, 'warn')\n }\n })\n\n return\n }\n\n pluginDriver.fileEmitter.on('new', async (emittedFile) => {\n if (!emittedFile) {\n return\n }\n const { id } = emittedFile\n\n if (!id) {\n throw new Error('No id could be transformed, please add id to emitFile or use resolveId')\n }\n\n let { source: code } = emittedFile\n\n const loadedResult = await pluginDriver.hookFirst('load', [id])\n if (loadedResult) {\n code = loadedResult\n }\n\n if (code) {\n const transformedCode = await pluginDriver.hookReduceArg0('transform', [code, id], transformReducer)\n\n await pluginDriver.hookParallel('writeFile', [transformedCode, id])\n pluginDriver.fileEmitter.delete(emittedFile.id)\n }\n })\n\n await pluginDriver.hookParallel('buildStart')\n\n pluginDriver.emitFile({\n id: config.input.path,\n name: undefined,\n source: input,\n })\n\n pluginDriver.fileEmitter.on('end', async () => {\n await pluginDriver.hookParallel('buildEnd')\n done()\n })\n}\n\nexport function build(options: BuildOptions): Promise<BuildOutput> {\n return new Promise((resolve, reject) => {\n try {\n buildImplementation(options, resolve)\n } catch (e) {\n reject(e)\n }\n })\n}\n","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 /**\n * equal to importee when getting passed through resolveId\n */\n id: string\n /**\n * The importer is the fully resolved id of the importing module.\n */\n importer?: string\n /**\n * Name to be used to dynamicly create the fileName(based on input.path)\n */\n name?: string\n /**\n * FileName will be the end result so no input.path will not be added\n */\n fileName?: string\n source?: string\n options?: 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 // TODO add default resolveId in core that takes name or fileName to resolve the correct files\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 && 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","import path from 'path'\n\nimport { createPluginCache } from './utils'\n\nimport type { EmittedFile } from './utils/FileEmitter'\nimport type { FileEmitter } from './utils'\nimport type { PluginLifecycle, 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: 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 publicly exported\nexport type 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 api: Api = {\n get config() {\n return options.config\n },\n async emitFile(emittedFile: EmittedFile) {\n const resolvedId = await resolveId(emittedFile.id, emittedFile.importer, emittedFile.options)\n const id = resolvedId || emittedFile.importer || emittedFile.id\n\n return fileEmitter.emitFile({\n ...emittedFile,\n id,\n })\n },\n resolveId,\n load,\n cache: createPluginCache(Object.create(null)),\n }\n\n return {\n name,\n api,\n resolveId(importee, importer) {\n if (!importer) {\n return null\n }\n return path.resolve(importer, importee)\n },\n }\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","/* eslint-disable no-param-reassign */\n/* eslint-disable consistent-return */\n\nexport interface Cache<TCache = any> {\n delete(id: string): boolean\n get<T = TCache>(id: string): T\n has(id: string): boolean\n set<T = TCache>(id: string, value: T): void\n}\n\nexport function createPluginCache(cache: any): Cache {\n return {\n delete(id: string) {\n return delete cache[id]\n },\n get(id: string) {\n const item = cache[id]\n if (!item) return\n item[0] = 0\n return item[1]\n },\n has(id: string) {\n const item = cache[id]\n if (!item) return false\n item[0] = 0\n return true\n },\n set(id: string, value: any) {\n cache[id] = [0, value]\n },\n }\n}\n","import path from 'path'\n\n// TODO check for a better way or resolving the relative path\nexport const getRelativePath = (from?: string | null, to?: string | null) => {\n if (!from || !to) {\n throw new Error('From and to should be filled in when retrieving the relativePath')\n }\n const newPath = path.relative(from, to).replace('../', '').replace('.ts', '').trimEnd()\n\n return `./${newPath}`\n}\n","/* 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 { definePlugin } from '../plugin'\n\nimport type { WithPromise } from './isPromise'\nimport type { BuildOptions } from '../build'\nimport type { Plugin, CorePluginOptions } from '../plugin'\nimport type { PluginLifecycleHooks, PluginLifecycle, 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 public plugins: Plugin[]\n\n public readonly fileEmitter: FileEmitter = new FileEmitter()\n\n private readonly logger?: BuildOptions['logger']\n\n private readonly config: Api['config']\n\n public readonly core: Plugin<CorePluginOptions> & { api: CorePluginOptions['api'] }\n\n constructor(config: Api['config'], options: { logger: BuildOptions['logger'] }) {\n this.logger = options.logger\n this.config = config\n this.emitFile = this.fileEmitter.emitFile.bind(this.fileEmitter)\n\n this.core = definePlugin({ config, fileEmitter: this.fileEmitter, load: this.load, resolveId: this.resolveId }) as Plugin<CorePluginOptions> & {\n api: CorePluginOptions['api']\n }\n this.plugins = [this.core, ...(config.plugins || [])]\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.run('hookFirst', hookName, parameters, plugin) as any\n })\n }\n return promise\n }\n\n // parallel\n async hookParallel<H extends PluginLifecycleHooks, TOuput = void>(hookName: H, parameters?: Parameters<PluginLifecycle[H]> | undefined) {\n const parallelPromises: Promise<TOuput>[] = []\n\n for (const plugin of this.getSortedPlugins(hookName)) {\n if ((plugin[hookName] as { sequential?: boolean })?.sequential) {\n await Promise.all(parallelPromises)\n parallelPromises.length = 0\n await this.run('hookParallel', hookName, parameters, plugin)\n } else {\n const promise: Promise<TOuput> = this.run('hookParallel', hookName, parameters, plugin)\n\n parallelPromises.push(promise)\n }\n }\n return Promise.all(parallelPromises)\n }\n\n // chains, reduces returned value, handling the reduced value as the first hook argument\n hookReduceArg0<H extends PluginLifecycleHooks>(\n hookName: H,\n [argument0, ...rest]: Parameters<PluginLifecycle[H]>,\n reduce: (reduction: Argument0<H>, result: ReturnType<PluginLifecycle[H]>, plugin: 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.run('hookReduceArg0', hookName, [argument0, ...rest] as Parameters<PluginLifecycle[H]>, plugin).then((result) =>\n reduce.call(this.core.api, argument0, result, plugin)\n )\n )\n }\n return promise\n }\n\n // chains\n\n hookSeq<H extends PluginLifecycleHooks>(hookName: H, parameters?: Parameters<PluginLifecycle[H]>) {\n let promise: Promise<void> = Promise.resolve()\n for (const plugin of this.getSortedPlugins(hookName)) {\n promise = promise.then(() => this.run('hookSeq', hookName, parameters, plugin))\n }\n return promise.then(noReturn)\n }\n\n private getSortedPlugins(_hookName: keyof PluginLifecycle): 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 run<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.core.api, parameters)\n\n if (!hookResult?.then) {\n // short circuit for non-thenables and non-Promises\n if (this.config.logLevel === 'info' && this.logger?.spinner) {\n this.logger.spinner.succeed(`[${strategy}] ${hookName}: Excecuting task for plugin ${plugin.name} \\n`)\n }\n return hookResult\n }\n\n return Promise.resolve(hookResult).then((result) => {\n // action was fulfilled\n if (this.config.logLevel === 'info' && this.logger?.spinner) {\n this.logger.spinner.succeed(`[${strategy}] ${hookName}: Excecuting task for plugin ${plugin.name} \\n`)\n }\n return result\n })\n })\n }\n\n /**\n * Run a sync plugin hook and return the result.\n * @param hookName Name of the plugin hook. Must be in `PluginHooks`.\n * @param args Arguments passed to the plugin hook.\n * @param plugin The acutal plugin\n * @param replaceContext When passed, the plugin context can be overridden.\n */\n private runSync<H extends PluginLifecycleHooks>(hookName: H, parameters: Parameters<PluginLifecycle[H]>, plugin: 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.core.api, parameters)\n } catch (error: any) {\n return error\n }\n }\n}\n\n// eslint-disable-next-line @typescript-eslint/no-empty-function\nfunction noReturn() {}\n","import type { BuildOptions } from './build'\nimport type { WithPromise } from './utils/isPromise'\nimport type { LogLevel } from './types'\nimport type { Plugin } from './plugin'\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 = (options: BuildOptions) => WithPromise<UserConfig>\nexport type UserConfigExport = WithPromise<UserConfig> | UserConfigFn\n\nexport const defaultConfig: Partial<UserConfig> = {\n root: process.cwd(),\n}\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","/* 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'\n\nexport default build\n"]}
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import fse from 'fs-extra';
|
|
3
3
|
import { format as format$1 } from 'prettier';
|
|
4
4
|
|
|
5
5
|
// src/build.ts
|
|
@@ -54,7 +54,7 @@ var FileEmitter = class {
|
|
|
54
54
|
this.emitter.emit("new", emitedFile);
|
|
55
55
|
return new Promise((resolve) => {
|
|
56
56
|
const subscribe = this.emitter.on("delete", (deletedFile) => {
|
|
57
|
-
if (deletedFile?.id === emitedFile.id) {
|
|
57
|
+
if (deletedFile?.id && deletedFile?.id === emitedFile.id) {
|
|
58
58
|
resolve(deletedFile);
|
|
59
59
|
return subscribe();
|
|
60
60
|
}
|
|
@@ -89,6 +89,38 @@ var FileEmitter = class {
|
|
|
89
89
|
};
|
|
90
90
|
};
|
|
91
91
|
|
|
92
|
+
// src/utils/isPromise.ts
|
|
93
|
+
var isPromise = (result) => {
|
|
94
|
+
return typeof result?.then === "function";
|
|
95
|
+
};
|
|
96
|
+
var formatOptions = {
|
|
97
|
+
tabWidth: 2,
|
|
98
|
+
printWidth: 160,
|
|
99
|
+
parser: "typescript",
|
|
100
|
+
singleQuote: true,
|
|
101
|
+
semi: false,
|
|
102
|
+
bracketSameLine: false,
|
|
103
|
+
endOfLine: "auto"
|
|
104
|
+
};
|
|
105
|
+
var format = (text) => {
|
|
106
|
+
return format$1(text, formatOptions);
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
// src/utils/write.ts
|
|
110
|
+
var write = async (data, path4, options = { format: false }) => {
|
|
111
|
+
const formattedData = options.format ? format(data) : data;
|
|
112
|
+
try {
|
|
113
|
+
await fse.stat(path4);
|
|
114
|
+
const oldContent = await fse.readFile(path4, { encoding: "utf-8" });
|
|
115
|
+
if (oldContent?.toString() === formattedData) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
} catch (_err) {
|
|
119
|
+
return fse.outputFile(path4, formattedData);
|
|
120
|
+
}
|
|
121
|
+
return fse.outputFile(path4, formattedData);
|
|
122
|
+
};
|
|
123
|
+
|
|
92
124
|
// src/utils/cache.ts
|
|
93
125
|
function createPluginCache(cache) {
|
|
94
126
|
return {
|
|
@@ -114,15 +146,15 @@ function createPluginCache(cache) {
|
|
|
114
146
|
}
|
|
115
147
|
};
|
|
116
148
|
}
|
|
149
|
+
var getRelativePath = (from, to) => {
|
|
150
|
+
if (!from || !to) {
|
|
151
|
+
throw new Error("From and to should be filled in when retrieving the relativePath");
|
|
152
|
+
}
|
|
153
|
+
const newPath = path.relative(from, to).replace("../", "").replace(".ts", "").trimEnd();
|
|
154
|
+
return `./${newPath}`;
|
|
155
|
+
};
|
|
117
156
|
|
|
118
|
-
// src/
|
|
119
|
-
function getPluginContext(plugin, pluginCache) {
|
|
120
|
-
const cacheKey = plugin.cacheKey || plugin.name;
|
|
121
|
-
const cacheInstance = createPluginCache(pluginCache[cacheKey] || (pluginCache[cacheKey] = /* @__PURE__ */ Object.create(null)));
|
|
122
|
-
return {
|
|
123
|
-
cache: cacheInstance
|
|
124
|
-
};
|
|
125
|
-
}
|
|
157
|
+
// src/plugin.ts
|
|
126
158
|
function createPlugin(factory) {
|
|
127
159
|
return (userOptions) => {
|
|
128
160
|
const plugin = factory(userOptions);
|
|
@@ -140,23 +172,31 @@ function createPlugin(factory) {
|
|
|
140
172
|
var name = "core";
|
|
141
173
|
var definePlugin = createPlugin((options) => {
|
|
142
174
|
const { fileEmitter, resolveId, load } = options;
|
|
143
|
-
const schema = fse2.readFileSync(path2.resolve(options.config.root, options.config.input.path), "utf-8");
|
|
144
175
|
const api = {
|
|
145
176
|
get config() {
|
|
146
177
|
return options.config;
|
|
147
178
|
},
|
|
148
|
-
|
|
149
|
-
|
|
179
|
+
async emitFile(emittedFile) {
|
|
180
|
+
const resolvedId = await resolveId(emittedFile.id, emittedFile.importer, emittedFile.options);
|
|
181
|
+
const id = resolvedId || emittedFile.importer || emittedFile.id;
|
|
182
|
+
return fileEmitter.emitFile({
|
|
183
|
+
...emittedFile,
|
|
184
|
+
id
|
|
185
|
+
});
|
|
150
186
|
},
|
|
151
|
-
on: fileEmitter.on.bind(fileEmitter),
|
|
152
|
-
getEmittedFile: fileEmitter.getEmittedFile.bind(fileEmitter),
|
|
153
|
-
emitFile: fileEmitter.emitFile.bind(fileEmitter),
|
|
154
187
|
resolveId,
|
|
155
|
-
load
|
|
188
|
+
load,
|
|
189
|
+
cache: createPluginCache(/* @__PURE__ */ Object.create(null))
|
|
156
190
|
};
|
|
157
191
|
return {
|
|
158
192
|
name,
|
|
159
|
-
api
|
|
193
|
+
api,
|
|
194
|
+
resolveId(importee, importer) {
|
|
195
|
+
if (!importer) {
|
|
196
|
+
return null;
|
|
197
|
+
}
|
|
198
|
+
return path.resolve(importer, importee);
|
|
199
|
+
}
|
|
160
200
|
};
|
|
161
201
|
});
|
|
162
202
|
|
|
@@ -172,36 +212,17 @@ var hookNames = {
|
|
|
172
212
|
};
|
|
173
213
|
var hooks = Object.keys(hookNames);
|
|
174
214
|
var PluginDriver = class {
|
|
175
|
-
pluginContexts;
|
|
176
215
|
plugins;
|
|
177
|
-
fileEmitter;
|
|
216
|
+
fileEmitter = new FileEmitter();
|
|
178
217
|
logger;
|
|
179
218
|
config;
|
|
180
|
-
|
|
181
|
-
constructor(config,
|
|
219
|
+
core;
|
|
220
|
+
constructor(config, options) {
|
|
182
221
|
this.logger = options.logger;
|
|
183
222
|
this.config = config;
|
|
184
|
-
this.fileEmitter = new FileEmitter();
|
|
185
223
|
this.emitFile = this.fileEmitter.emitFile.bind(this.fileEmitter);
|
|
186
|
-
|
|
187
|
-
this.plugins = [
|
|
188
|
-
const coreApi = corePlugin.api;
|
|
189
|
-
this.pluginContexts = new Map(
|
|
190
|
-
this.plugins.map((plugin) => {
|
|
191
|
-
const context = {
|
|
192
|
-
...coreApi,
|
|
193
|
-
...getPluginContext.call(this, plugin, pluginCache)
|
|
194
|
-
};
|
|
195
|
-
return [plugin, context];
|
|
196
|
-
})
|
|
197
|
-
);
|
|
198
|
-
}
|
|
199
|
-
get api() {
|
|
200
|
-
let context = {};
|
|
201
|
-
this.pluginContexts.forEach((value) => {
|
|
202
|
-
context = { ...context, ...value };
|
|
203
|
-
});
|
|
204
|
-
return context;
|
|
224
|
+
this.core = definePlugin({ config, fileEmitter: this.fileEmitter, load: this.load, resolveId: this.resolveId });
|
|
225
|
+
this.plugins = [this.core, ...config.plugins || []];
|
|
205
226
|
}
|
|
206
227
|
emitFile(...params) {
|
|
207
228
|
return this.fileEmitter.emitFile(...params);
|
|
@@ -221,7 +242,7 @@ var PluginDriver = class {
|
|
|
221
242
|
promise = promise.then((result) => {
|
|
222
243
|
if (result != null)
|
|
223
244
|
return result;
|
|
224
|
-
return this.
|
|
245
|
+
return this.run("hookFirst", hookName, parameters, plugin);
|
|
225
246
|
});
|
|
226
247
|
}
|
|
227
248
|
return promise;
|
|
@@ -232,9 +253,9 @@ var PluginDriver = class {
|
|
|
232
253
|
if (plugin[hookName]?.sequential) {
|
|
233
254
|
await Promise.all(parallelPromises);
|
|
234
255
|
parallelPromises.length = 0;
|
|
235
|
-
await this.
|
|
256
|
+
await this.run("hookParallel", hookName, parameters, plugin);
|
|
236
257
|
} else {
|
|
237
|
-
const promise = this.
|
|
258
|
+
const promise = this.run("hookParallel", hookName, parameters, plugin);
|
|
238
259
|
parallelPromises.push(promise);
|
|
239
260
|
}
|
|
240
261
|
}
|
|
@@ -244,8 +265,8 @@ var PluginDriver = class {
|
|
|
244
265
|
let promise = Promise.resolve(argument0);
|
|
245
266
|
for (const plugin of this.getSortedPlugins(hookName)) {
|
|
246
267
|
promise = promise.then(
|
|
247
|
-
(argument02) => this.
|
|
248
|
-
(result) => reduce.call(this.api, argument02, result, plugin)
|
|
268
|
+
(argument02) => this.run("hookReduceArg0", hookName, [argument02, ...rest], plugin).then(
|
|
269
|
+
(result) => reduce.call(this.core.api, argument02, result, plugin)
|
|
249
270
|
)
|
|
250
271
|
);
|
|
251
272
|
}
|
|
@@ -254,14 +275,14 @@ var PluginDriver = class {
|
|
|
254
275
|
hookSeq(hookName, parameters) {
|
|
255
276
|
let promise = Promise.resolve();
|
|
256
277
|
for (const plugin of this.getSortedPlugins(hookName)) {
|
|
257
|
-
promise = promise.then(() => this.
|
|
278
|
+
promise = promise.then(() => this.run("hookSeq", hookName, parameters, plugin));
|
|
258
279
|
}
|
|
259
280
|
return promise.then(noReturn);
|
|
260
281
|
}
|
|
261
282
|
getSortedPlugins(_hookName) {
|
|
262
283
|
return [...this.plugins];
|
|
263
284
|
}
|
|
264
|
-
|
|
285
|
+
run(strategy, hookName, parameters, plugin) {
|
|
265
286
|
const hook = plugin[hookName];
|
|
266
287
|
return Promise.resolve().then(() => {
|
|
267
288
|
if (typeof hook !== "function") {
|
|
@@ -271,7 +292,7 @@ var PluginDriver = class {
|
|
|
271
292
|
this.logger.spinner.text = `[${strategy}] ${hookName}: Excecuting task for plugin ${plugin.name}
|
|
272
293
|
`;
|
|
273
294
|
}
|
|
274
|
-
const hookResult = hook.apply(this.api, parameters);
|
|
295
|
+
const hookResult = hook.apply(this.core.api, parameters);
|
|
275
296
|
if (!hookResult?.then) {
|
|
276
297
|
if (this.config.logLevel === "info" && this.logger?.spinner) {
|
|
277
298
|
this.logger.spinner.succeed(`[${strategy}] ${hookName}: Excecuting task for plugin ${plugin.name}
|
|
@@ -288,10 +309,10 @@ var PluginDriver = class {
|
|
|
288
309
|
});
|
|
289
310
|
});
|
|
290
311
|
}
|
|
291
|
-
|
|
312
|
+
runSync(hookName, parameters, plugin) {
|
|
292
313
|
const hook = plugin[hookName];
|
|
293
314
|
try {
|
|
294
|
-
return hook.apply(this.api, parameters);
|
|
315
|
+
return hook.apply(this.core.api, parameters);
|
|
295
316
|
} catch (error) {
|
|
296
317
|
return error;
|
|
297
318
|
}
|
|
@@ -300,6 +321,14 @@ var PluginDriver = class {
|
|
|
300
321
|
function noReturn() {
|
|
301
322
|
}
|
|
302
323
|
|
|
324
|
+
// src/config.ts
|
|
325
|
+
var defaultConfig = {
|
|
326
|
+
root: process.cwd()
|
|
327
|
+
};
|
|
328
|
+
function defineConfig(config) {
|
|
329
|
+
return config;
|
|
330
|
+
}
|
|
331
|
+
|
|
303
332
|
// src/build.ts
|
|
304
333
|
async function transformReducer(previousCode, result, _plugin) {
|
|
305
334
|
if (result === null) {
|
|
@@ -308,115 +337,68 @@ async function transformReducer(previousCode, result, _plugin) {
|
|
|
308
337
|
return result;
|
|
309
338
|
}
|
|
310
339
|
async function buildImplementation(options, done) {
|
|
311
|
-
const { config } = options;
|
|
312
|
-
const
|
|
313
|
-
|
|
340
|
+
const { config, logger } = options;
|
|
341
|
+
const pluginDriver = new PluginDriver(
|
|
342
|
+
{
|
|
343
|
+
...defaultConfig,
|
|
344
|
+
...config
|
|
345
|
+
},
|
|
346
|
+
{ logger }
|
|
347
|
+
);
|
|
348
|
+
const input = fse.readFileSync(path.resolve(config.root, config.input.path), "utf-8");
|
|
314
349
|
const validations = await pluginDriver.hookParallel("validate", [pluginDriver.plugins]);
|
|
315
350
|
const validationsWithMessage = validations.filter(Boolean);
|
|
316
351
|
if (validationsWithMessage.some((validation) => typeof validation !== "boolean")) {
|
|
317
352
|
validationsWithMessage.forEach((validation) => {
|
|
318
353
|
if (validation && typeof validation !== "boolean" && validation?.message) {
|
|
319
|
-
|
|
354
|
+
logger?.log(validation.message, "warn");
|
|
320
355
|
}
|
|
321
356
|
});
|
|
322
357
|
return;
|
|
323
358
|
}
|
|
324
359
|
pluginDriver.fileEmitter.on("new", async (emittedFile) => {
|
|
325
|
-
if (!emittedFile
|
|
360
|
+
if (!emittedFile) {
|
|
326
361
|
return;
|
|
327
362
|
}
|
|
328
|
-
const
|
|
329
|
-
|
|
330
|
-
|
|
363
|
+
const { id } = emittedFile;
|
|
364
|
+
if (!id) {
|
|
365
|
+
throw new Error("No id could be transformed, please add id to emitFile or use resolveId");
|
|
366
|
+
}
|
|
367
|
+
let { source: code } = emittedFile;
|
|
331
368
|
const loadedResult = await pluginDriver.hookFirst("load", [id]);
|
|
332
369
|
if (loadedResult) {
|
|
333
370
|
code = loadedResult;
|
|
334
371
|
}
|
|
335
372
|
if (code) {
|
|
336
|
-
const
|
|
337
|
-
await pluginDriver.hookParallel("writeFile", [
|
|
373
|
+
const transformedCode = await pluginDriver.hookReduceArg0("transform", [code, id], transformReducer);
|
|
374
|
+
await pluginDriver.hookParallel("writeFile", [transformedCode, id]);
|
|
338
375
|
pluginDriver.fileEmitter.delete(emittedFile.id);
|
|
339
376
|
}
|
|
340
377
|
});
|
|
341
378
|
await pluginDriver.hookParallel("buildStart");
|
|
342
379
|
pluginDriver.emitFile({
|
|
343
|
-
id:
|
|
344
|
-
source: pluginDriver.api.config.input.path,
|
|
380
|
+
id: config.input.path,
|
|
345
381
|
name: void 0,
|
|
346
|
-
|
|
382
|
+
source: input
|
|
347
383
|
});
|
|
348
384
|
pluginDriver.fileEmitter.on("end", async () => {
|
|
349
385
|
await pluginDriver.hookParallel("buildEnd");
|
|
350
386
|
done();
|
|
351
387
|
});
|
|
352
388
|
}
|
|
353
|
-
function build(
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
this,
|
|
361
|
-
{
|
|
362
|
-
config,
|
|
363
|
-
env
|
|
364
|
-
},
|
|
365
|
-
resolve
|
|
366
|
-
);
|
|
389
|
+
function build(options) {
|
|
390
|
+
return new Promise((resolve, reject) => {
|
|
391
|
+
try {
|
|
392
|
+
buildImplementation(options, resolve);
|
|
393
|
+
} catch (e) {
|
|
394
|
+
reject(e);
|
|
395
|
+
}
|
|
367
396
|
});
|
|
368
397
|
}
|
|
369
398
|
|
|
370
|
-
// src/config.ts
|
|
371
|
-
function defineConfig(config) {
|
|
372
|
-
return config;
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
// src/utils/isPromise.ts
|
|
376
|
-
var isPromise = (result) => {
|
|
377
|
-
return typeof result?.then === "function";
|
|
378
|
-
};
|
|
379
|
-
var formatOptions = {
|
|
380
|
-
tabWidth: 2,
|
|
381
|
-
printWidth: 160,
|
|
382
|
-
parser: "typescript",
|
|
383
|
-
singleQuote: true,
|
|
384
|
-
semi: false,
|
|
385
|
-
bracketSameLine: false,
|
|
386
|
-
endOfLine: "auto"
|
|
387
|
-
};
|
|
388
|
-
var format = (text) => {
|
|
389
|
-
return format$1(text, formatOptions);
|
|
390
|
-
};
|
|
391
|
-
|
|
392
|
-
// src/utils/write.ts
|
|
393
|
-
var write = async (data, path4, options = { format: false }) => {
|
|
394
|
-
const formattedData = options.format ? format(data) : data;
|
|
395
|
-
try {
|
|
396
|
-
await fse2.stat(path4);
|
|
397
|
-
const oldContent = await fse2.readFile(path4, { encoding: "utf-8" });
|
|
398
|
-
if (oldContent?.toString() === formattedData) {
|
|
399
|
-
return;
|
|
400
|
-
}
|
|
401
|
-
} catch (_err) {
|
|
402
|
-
return fse2.outputFile(path4, formattedData);
|
|
403
|
-
}
|
|
404
|
-
return fse2.outputFile(path4, formattedData);
|
|
405
|
-
};
|
|
406
|
-
var getRelativePath = (from, to) => {
|
|
407
|
-
if (!from || !to) {
|
|
408
|
-
throw new Error("From and to should be filled in when retrieving the relativePath");
|
|
409
|
-
}
|
|
410
|
-
const newPath = path2.relative(from, to).replace("../", "").replace(".ts", "").trimEnd();
|
|
411
|
-
if (newPath.startsWith("./") || newPath.startsWith("../")) {
|
|
412
|
-
return newPath.replace;
|
|
413
|
-
}
|
|
414
|
-
return `./${newPath}`;
|
|
415
|
-
};
|
|
416
|
-
|
|
417
399
|
// src/index.ts
|
|
418
400
|
var src_default = build;
|
|
419
401
|
|
|
420
|
-
export { Emitter, FileEmitter, PluginDriver, build, createPlugin, createPluginCache, src_default as default, defineConfig, format,
|
|
402
|
+
export { Emitter, FileEmitter, PluginDriver, build, createPlugin, createPluginCache, src_default as default, defaultConfig, defineConfig, format, getRelativePath, hooks, isPromise, write };
|
|
421
403
|
//# sourceMappingURL=out.js.map
|
|
422
404
|
//# sourceMappingURL=index.mjs.map
|
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,UAAM,WAAW;AAAA,MACf;AAAA,MACA;AAAA,IACF;AACA,SAAK,UAAU,IAAI,QAAQ;AAC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AM,gBAAyB;AAAA,EAC7B,UAAU;AAAA,EACV,YAAY;AAAA,EACZ,QAAQ;AAAA,EACR,aAAa;AAAA,EACb,MAAM;AAAA,EACN,iBAAiB;AAAA,EACjB,WAAW;AACb;AACO,IAAM,SAAS,CAAC,SAAiB;AACtC,SAAO,eAAe,MAAM,aAAa;AAC3C;;;ADNO,IAAM,QAAQ,OAAO,MAAcF,OAAc,UAAwB,EAAE,QAAQ,MAAM,MAAM;AACpG,QAAM,gBAAgB,QAAQ,SAAS,OAAO,IAAI,IAAI;AAEtD,MAAI;AACF,UAAME,KAAI,KAAKF,KAAI;AACnB,UAAM,aAAa,MAAME,KAAI,SAASF,OAAM,EAAE,UAAU,QAAQ,CAAC;AACjE,QAAI,YAAY,SAAS,MAAM,eAAe;AAC5C;AAAA,IACF;AAAA,EACF,SAAS,MAAP;AACA,WAAOE,KAAI,WAAWF,OAAM,aAAa;AAAA,EAC3C;AAEA,SAAOE,KAAI,WAAWF,OAAM,aAAa;AAC3C;;;AEvBA,OAAOA,WAAU;AAGV,IAAM,kBAAkB,CAAC,MAAsB,OAAuB;AAC3E,MAAI,CAAC,QAAQ,CAAC,IAAI;AAChB,UAAM,IAAI,MAAM,kEAAkE;AAAA,EACpF;AACA,QAAM,UAAUA,MAAK,SAAS,MAAM,EAAE,EAAE,QAAQ,OAAO,EAAE,EAAE,QAAQ,OAAO,EAAE,EAAE,QAAQ;AAEtF,MAAI,QAAQ,WAAW,IAAI,KAAK,QAAQ,WAAW,KAAK,GAAG;AACzD,WAAO,QAAQ;AAAA,EACjB;AACA,SAAO,KAAK;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\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"]}
|
|
1
|
+
{"version":3,"sources":["../src/build.ts","../src/utils/Emitter.ts","../src/utils/FileEmitter.ts","../src/plugin.ts","../src/utils/isPromise.ts","../src/utils/write.ts","../src/utils/format.ts","../src/utils/cache.ts","../src/utils/read.ts","../src/utils/PluginDriver.ts","../src/config.ts","../src/index.ts"],"names":["path","fse","argument0"],"mappings":";AAIA,OAAOA,WAAU;AAEjB,OAAOC,UAAS;;;ACJT,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,MACf;AAAA,MACA;AAAA,IACF;AACA,SAAK,UAAU,IAAI,QAAQ;AAC3B,WAAO,MAAM,KAAK,UAAU,OAAO,QAAQ;AAAA,EAC7C;AAAA,EAEA,UAAsB,MAAM,KAAK,UAAU,MAAM;AACnD;;;ACtBO,IAAM,cAAN,MAAkB;AAAA,EACN;AAAA,EAEA,qBAA+C,oBAAI,IAAI;AAAA,EAExE,YAAY,UAAwC,IAAI,QAA6B,CAAC,UAAU,OAAO,KAAK,CAAC,GAAG;AAC9G,SAAK,UAAU;AAAA,EACjB;AAAA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["/* 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 fse from 'fs-extra'\n\nimport { PluginDriver } from './utils/PluginDriver'\nimport { defaultConfig } from './config'\n\nimport type { Api, PluginContext, TransformResult, ValidationResult, LogLevel } from './types'\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 BuildOptions = {\n config: Api['config']\n mode: 'development' | 'production'\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\nasync function buildImplementation(options: BuildOptions, done: (output: BuildOutput) => void) {\n const { config, logger } = options\n\n const pluginDriver = new PluginDriver(\n {\n ...defaultConfig,\n ...config,\n },\n { logger }\n )\n const input = fse.readFileSync(path.resolve(config.root, config.input.path), 'utf-8')\n\n const validations = await pluginDriver.hookParallel<'validate', ValidationResult>('validate', [pluginDriver.plugins])\n const validationsWithMessage = validations.filter(Boolean)\n\n if (validationsWithMessage.some((validation) => typeof validation !== 'boolean')) {\n validationsWithMessage.forEach((validation) => {\n if (validation && typeof validation !== 'boolean' && validation?.message) {\n logger?.log(validation.message, 'warn')\n }\n })\n\n return\n }\n\n pluginDriver.fileEmitter.on('new', async (emittedFile) => {\n if (!emittedFile) {\n return\n }\n const { id } = emittedFile\n\n if (!id) {\n throw new Error('No id could be transformed, please add id to emitFile or use resolveId')\n }\n\n let { source: code } = emittedFile\n\n const loadedResult = await pluginDriver.hookFirst('load', [id])\n if (loadedResult) {\n code = loadedResult\n }\n\n if (code) {\n const transformedCode = await pluginDriver.hookReduceArg0('transform', [code, id], transformReducer)\n\n await pluginDriver.hookParallel('writeFile', [transformedCode, id])\n pluginDriver.fileEmitter.delete(emittedFile.id)\n }\n })\n\n await pluginDriver.hookParallel('buildStart')\n\n pluginDriver.emitFile({\n id: config.input.path,\n name: undefined,\n source: input,\n })\n\n pluginDriver.fileEmitter.on('end', async () => {\n await pluginDriver.hookParallel('buildEnd')\n done()\n })\n}\n\nexport function build(options: BuildOptions): Promise<BuildOutput> {\n return new Promise((resolve, reject) => {\n try {\n buildImplementation(options, resolve)\n } catch (e) {\n reject(e)\n }\n })\n}\n","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 /**\n * equal to importee when getting passed through resolveId\n */\n id: string\n /**\n * The importer is the fully resolved id of the importing module.\n */\n importer?: string\n /**\n * Name to be used to dynamicly create the fileName(based on input.path)\n */\n name?: string\n /**\n * FileName will be the end result so no input.path will not be added\n */\n fileName?: string\n source?: string\n options?: 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 // TODO add default resolveId in core that takes name or fileName to resolve the correct files\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 && 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","import path from 'path'\n\nimport { createPluginCache } from './utils'\n\nimport type { EmittedFile } from './utils/FileEmitter'\nimport type { FileEmitter } from './utils'\nimport type { PluginLifecycle, 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: 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 publicly exported\nexport type 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 api: Api = {\n get config() {\n return options.config\n },\n async emitFile(emittedFile: EmittedFile) {\n const resolvedId = await resolveId(emittedFile.id, emittedFile.importer, emittedFile.options)\n const id = resolvedId || emittedFile.importer || emittedFile.id\n\n return fileEmitter.emitFile({\n ...emittedFile,\n id,\n })\n },\n resolveId,\n load,\n cache: createPluginCache(Object.create(null)),\n }\n\n return {\n name,\n api,\n resolveId(importee, importer) {\n if (!importer) {\n return null\n }\n return path.resolve(importer, importee)\n },\n }\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","/* eslint-disable no-param-reassign */\n/* eslint-disable consistent-return */\n\nexport interface Cache<TCache = any> {\n delete(id: string): boolean\n get<T = TCache>(id: string): T\n has(id: string): boolean\n set<T = TCache>(id: string, value: T): void\n}\n\nexport function createPluginCache(cache: any): Cache {\n return {\n delete(id: string) {\n return delete cache[id]\n },\n get(id: string) {\n const item = cache[id]\n if (!item) return\n item[0] = 0\n return item[1]\n },\n has(id: string) {\n const item = cache[id]\n if (!item) return false\n item[0] = 0\n return true\n },\n set(id: string, value: any) {\n cache[id] = [0, value]\n },\n }\n}\n","import path from 'path'\n\n// TODO check for a better way or resolving the relative path\nexport const getRelativePath = (from?: string | null, to?: string | null) => {\n if (!from || !to) {\n throw new Error('From and to should be filled in when retrieving the relativePath')\n }\n const newPath = path.relative(from, to).replace('../', '').replace('.ts', '').trimEnd()\n\n return `./${newPath}`\n}\n","/* 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 { definePlugin } from '../plugin'\n\nimport type { WithPromise } from './isPromise'\nimport type { BuildOptions } from '../build'\nimport type { Plugin, CorePluginOptions } from '../plugin'\nimport type { PluginLifecycleHooks, PluginLifecycle, 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 public plugins: Plugin[]\n\n public readonly fileEmitter: FileEmitter = new FileEmitter()\n\n private readonly logger?: BuildOptions['logger']\n\n private readonly config: Api['config']\n\n public readonly core: Plugin<CorePluginOptions> & { api: CorePluginOptions['api'] }\n\n constructor(config: Api['config'], options: { logger: BuildOptions['logger'] }) {\n this.logger = options.logger\n this.config = config\n this.emitFile = this.fileEmitter.emitFile.bind(this.fileEmitter)\n\n this.core = definePlugin({ config, fileEmitter: this.fileEmitter, load: this.load, resolveId: this.resolveId }) as Plugin<CorePluginOptions> & {\n api: CorePluginOptions['api']\n }\n this.plugins = [this.core, ...(config.plugins || [])]\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.run('hookFirst', hookName, parameters, plugin) as any\n })\n }\n return promise\n }\n\n // parallel\n async hookParallel<H extends PluginLifecycleHooks, TOuput = void>(hookName: H, parameters?: Parameters<PluginLifecycle[H]> | undefined) {\n const parallelPromises: Promise<TOuput>[] = []\n\n for (const plugin of this.getSortedPlugins(hookName)) {\n if ((plugin[hookName] as { sequential?: boolean })?.sequential) {\n await Promise.all(parallelPromises)\n parallelPromises.length = 0\n await this.run('hookParallel', hookName, parameters, plugin)\n } else {\n const promise: Promise<TOuput> = this.run('hookParallel', hookName, parameters, plugin)\n\n parallelPromises.push(promise)\n }\n }\n return Promise.all(parallelPromises)\n }\n\n // chains, reduces returned value, handling the reduced value as the first hook argument\n hookReduceArg0<H extends PluginLifecycleHooks>(\n hookName: H,\n [argument0, ...rest]: Parameters<PluginLifecycle[H]>,\n reduce: (reduction: Argument0<H>, result: ReturnType<PluginLifecycle[H]>, plugin: 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.run('hookReduceArg0', hookName, [argument0, ...rest] as Parameters<PluginLifecycle[H]>, plugin).then((result) =>\n reduce.call(this.core.api, argument0, result, plugin)\n )\n )\n }\n return promise\n }\n\n // chains\n\n hookSeq<H extends PluginLifecycleHooks>(hookName: H, parameters?: Parameters<PluginLifecycle[H]>) {\n let promise: Promise<void> = Promise.resolve()\n for (const plugin of this.getSortedPlugins(hookName)) {\n promise = promise.then(() => this.run('hookSeq', hookName, parameters, plugin))\n }\n return promise.then(noReturn)\n }\n\n private getSortedPlugins(_hookName: keyof PluginLifecycle): 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 run<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.core.api, parameters)\n\n if (!hookResult?.then) {\n // short circuit for non-thenables and non-Promises\n if (this.config.logLevel === 'info' && this.logger?.spinner) {\n this.logger.spinner.succeed(`[${strategy}] ${hookName}: Excecuting task for plugin ${plugin.name} \\n`)\n }\n return hookResult\n }\n\n return Promise.resolve(hookResult).then((result) => {\n // action was fulfilled\n if (this.config.logLevel === 'info' && this.logger?.spinner) {\n this.logger.spinner.succeed(`[${strategy}] ${hookName}: Excecuting task for plugin ${plugin.name} \\n`)\n }\n return result\n })\n })\n }\n\n /**\n * Run a sync plugin hook and return the result.\n * @param hookName Name of the plugin hook. Must be in `PluginHooks`.\n * @param args Arguments passed to the plugin hook.\n * @param plugin The acutal plugin\n * @param replaceContext When passed, the plugin context can be overridden.\n */\n private runSync<H extends PluginLifecycleHooks>(hookName: H, parameters: Parameters<PluginLifecycle[H]>, plugin: 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.core.api, parameters)\n } catch (error: any) {\n return error\n }\n }\n}\n\n// eslint-disable-next-line @typescript-eslint/no-empty-function\nfunction noReturn() {}\n","import type { BuildOptions } from './build'\nimport type { WithPromise } from './utils/isPromise'\nimport type { LogLevel } from './types'\nimport type { Plugin } from './plugin'\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 = (options: BuildOptions) => WithPromise<UserConfig>\nexport type UserConfigExport = WithPromise<UserConfig> | UserConfigFn\n\nexport const defaultConfig: Partial<UserConfig> = {\n root: process.cwd(),\n}\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","/* 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'\n\nexport default build\n"]}
|