@kubb/core 0.8.0 → 0.9.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/ast/index.d.ts +1 -1
- package/dist/ast/index.js +8 -2
- package/dist/ast/index.js.map +1 -1
- package/dist/ast/index.mjs +8 -2
- package/dist/ast/index.mjs.map +1 -1
- package/dist/index.d.ts +25 -19
- package/dist/index.js +83 -46
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +83 -48
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/ast/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import ts from 'typescript';
|
|
|
3
3
|
declare const generateStringTemplate: <TParams = Record<string, string | ts.Node | undefined>>(templateStrings: string | TemplateStringsArray, ...placeholders: (string | ts.Node)[]) => (params?: TParams | undefined) => string | undefined;
|
|
4
4
|
declare const logDemoTemplate: () => Promise<void>;
|
|
5
5
|
|
|
6
|
-
declare const print: (elements: ts.Node[], fileName?: string) => string;
|
|
6
|
+
declare const print: (elements: ts.Node | ts.Node[], fileName?: string) => string;
|
|
7
7
|
|
|
8
8
|
declare const index_generateStringTemplate: typeof generateStringTemplate;
|
|
9
9
|
declare const index_logDemoTemplate: typeof logDemoTemplate;
|
package/dist/ast/index.js
CHANGED
|
@@ -17,10 +17,16 @@ __export(typescript_exports, {
|
|
|
17
17
|
print: () => print
|
|
18
18
|
});
|
|
19
19
|
var print = (elements, fileName = "print.ts") => {
|
|
20
|
-
|
|
20
|
+
let nodes = [];
|
|
21
|
+
if (Array.isArray(elements)) {
|
|
22
|
+
nodes = elements;
|
|
23
|
+
} else {
|
|
24
|
+
nodes = [elements];
|
|
25
|
+
}
|
|
26
|
+
const nodesArray = ts.factory.createNodeArray(nodes);
|
|
21
27
|
const sourceFile = ts.createSourceFile(fileName, "", ts.ScriptTarget.ESNext, true, ts.ScriptKind.TS);
|
|
22
28
|
const printer = ts.createPrinter();
|
|
23
|
-
const outputFile = printer.printList(ts.ListFormat.MultiLine,
|
|
29
|
+
const outputFile = printer.printList(ts.ListFormat.MultiLine, nodesArray, sourceFile);
|
|
24
30
|
return outputFile;
|
|
25
31
|
};
|
|
26
32
|
|
package/dist/ast/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/ast/typescript/index.ts","../../src/ast/typescript/generate.ts","../../src/ast/typescript/utils/print.ts"],"names":["ts"],"mappings":";;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACGA,OAAOA,SAAQ;AACf,SAAS,gBAAgB;;;ACJzB,OAAO,QAAQ;AAER,IAAM,QAAQ,CAAC,
|
|
1
|
+
{"version":3,"sources":["../../src/ast/typescript/index.ts","../../src/ast/typescript/generate.ts","../../src/ast/typescript/utils/print.ts"],"names":["ts"],"mappings":";;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACGA,OAAOA,SAAQ;AACf,SAAS,gBAAgB;;;ACJzB,OAAO,QAAQ;AAER,IAAM,QAAQ,CAAC,UAA+B,WAAW,eAAe;AAC7E,MAAI,QAAmB,CAAC;AACxB,MAAI,MAAM,QAAQ,QAAQ,GAAG;AAC3B,YAAQ;AAAA,EACV,OAAO;AACL,YAAQ,CAAC,QAAQ;AAAA,EACnB;AACA,QAAM,aAAa,GAAG,QAAQ,gBAAgB,KAAK;AACnD,QAAM,aAAa,GAAG,iBAAiB,UAAU,IAAI,GAAG,aAAa,QAAQ,MAAM,GAAG,WAAW,EAAE;AAEnG,QAAM,UAAU,GAAG,cAAc;AACjC,QAAM,aAAa,QAAQ,UAAU,GAAG,WAAW,WAAW,YAAY,UAAU;AAEpF,SAAO;AACT;;;ADRO,IAAM,yBAAyB,CACpC,oBACG,iBACA;AACH,QAAM,aAAa,SAAS,UAAU,iBAAiB,GAAG,YAAY;AACtE,SAAO,CAAC,WAAqB;AAC3B,QAAI,CAAC,QAAQ;AACX,aAAO;AAAA,IACT;AACA,UAAM,iBAA0C,CAAC;AAEjD,WAAO,KAAK,MAAM,EAAE,QAAQ,CAAC,QAAQ;AACnC,qBAAe,OAAO,OAAO,OAAO,OAAOA,IAAG,QAAQ,oBAAoB,OAAO,IAAI,IAAI,OAAO;AAAA,IAClG,CAAC;AAED,UAAM,eAAe,WAAW,cAAc;AAE9C,WAAO,MAAM,CAAC,YAAY,CAAC;AAAA,EAC7B;AACF;AAEO,IAAM,kBAAkB,YAAY;AACzC,QAAM,WAAW,SAAS,SAAS,2BAA2B,EAAE;AAGhE,QAAM,qBAAqB,SAAS;AAAA;AAAA;AAAA;AAAA,IAIlC;AAEF,UAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,CAAC;AAC/B","sourcesContent":["export * from './generate'\nexport * from './utils'\n","/* eslint-disable @typescript-eslint/no-unused-vars */\n/* eslint-disable no-console */\n\nimport ts from 'typescript'\nimport { template } from 'talt'\n\nimport { print } from './utils/print'\n\nexport const generateStringTemplate = <TParams = Record<string, ts.Node | string | undefined>>(\n templateStrings: string | TemplateStringsArray,\n ...placeholders: (string | ts.Node)[]\n) => {\n const compiledFn = template.statement(templateStrings, ...placeholders)\n return (params?: TParams) => {\n if (!params) {\n return undefined\n }\n const idPlaceholders: Record<string, ts.Node> = {}\n\n Object.keys(params).forEach((key) => {\n idPlaceholders[key] = typeof params[key] ? ts.factory.createStringLiteral(params[key]) : params[key]\n })\n\n const generatedAst = compiledFn(idPlaceholders)\n\n return print([generatedAst])\n }\n}\n\nexport const logDemoTemplate = async () => {\n const typeNode = template.typeNode('{ readonly test: string }')()\n\n // You can use `template` as tag function.\n const typeNodeUsingTagFn = template.typeNode`\n {\n readonly test: string;\n }\n `()\n\n console.log(print([typeNode]))\n}\n","import ts from 'typescript'\n\nexport const print = (elements: ts.Node | ts.Node[], fileName = 'print.ts') => {\n let nodes: ts.Node[] = []\n if (Array.isArray(elements)) {\n nodes = elements\n } else {\n nodes = [elements]\n }\n const nodesArray = ts.factory.createNodeArray(nodes)\n const sourceFile = ts.createSourceFile(fileName, '', ts.ScriptTarget.ESNext, true, ts.ScriptKind.TS)\n\n const printer = ts.createPrinter()\n const outputFile = printer.printList(ts.ListFormat.MultiLine, nodesArray, sourceFile)\n\n return outputFile\n}\n"]}
|
package/dist/ast/index.mjs
CHANGED
|
@@ -15,10 +15,16 @@ __export(typescript_exports, {
|
|
|
15
15
|
print: () => print
|
|
16
16
|
});
|
|
17
17
|
var print = (elements, fileName = "print.ts") => {
|
|
18
|
-
|
|
18
|
+
let nodes = [];
|
|
19
|
+
if (Array.isArray(elements)) {
|
|
20
|
+
nodes = elements;
|
|
21
|
+
} else {
|
|
22
|
+
nodes = [elements];
|
|
23
|
+
}
|
|
24
|
+
const nodesArray = ts.factory.createNodeArray(nodes);
|
|
19
25
|
const sourceFile = ts.createSourceFile(fileName, "", ts.ScriptTarget.ESNext, true, ts.ScriptKind.TS);
|
|
20
26
|
const printer = ts.createPrinter();
|
|
21
|
-
const outputFile = printer.printList(ts.ListFormat.MultiLine,
|
|
27
|
+
const outputFile = printer.printList(ts.ListFormat.MultiLine, nodesArray, sourceFile);
|
|
22
28
|
return outputFile;
|
|
23
29
|
};
|
|
24
30
|
|
package/dist/ast/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/ast/typescript/index.ts","../../src/ast/typescript/generate.ts","../../src/ast/typescript/utils/print.ts"],"names":["ts"],"mappings":";;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACGA,OAAOA,SAAQ;AACf,SAAS,gBAAgB;;;ACJzB,OAAO,QAAQ;AAER,IAAM,QAAQ,CAAC,
|
|
1
|
+
{"version":3,"sources":["../../src/ast/typescript/index.ts","../../src/ast/typescript/generate.ts","../../src/ast/typescript/utils/print.ts"],"names":["ts"],"mappings":";;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACGA,OAAOA,SAAQ;AACf,SAAS,gBAAgB;;;ACJzB,OAAO,QAAQ;AAER,IAAM,QAAQ,CAAC,UAA+B,WAAW,eAAe;AAC7E,MAAI,QAAmB,CAAC;AACxB,MAAI,MAAM,QAAQ,QAAQ,GAAG;AAC3B,YAAQ;AAAA,EACV,OAAO;AACL,YAAQ,CAAC,QAAQ;AAAA,EACnB;AACA,QAAM,aAAa,GAAG,QAAQ,gBAAgB,KAAK;AACnD,QAAM,aAAa,GAAG,iBAAiB,UAAU,IAAI,GAAG,aAAa,QAAQ,MAAM,GAAG,WAAW,EAAE;AAEnG,QAAM,UAAU,GAAG,cAAc;AACjC,QAAM,aAAa,QAAQ,UAAU,GAAG,WAAW,WAAW,YAAY,UAAU;AAEpF,SAAO;AACT;;;ADRO,IAAM,yBAAyB,CACpC,oBACG,iBACA;AACH,QAAM,aAAa,SAAS,UAAU,iBAAiB,GAAG,YAAY;AACtE,SAAO,CAAC,WAAqB;AAC3B,QAAI,CAAC,QAAQ;AACX,aAAO;AAAA,IACT;AACA,UAAM,iBAA0C,CAAC;AAEjD,WAAO,KAAK,MAAM,EAAE,QAAQ,CAAC,QAAQ;AACnC,qBAAe,OAAO,OAAO,OAAO,OAAOA,IAAG,QAAQ,oBAAoB,OAAO,IAAI,IAAI,OAAO;AAAA,IAClG,CAAC;AAED,UAAM,eAAe,WAAW,cAAc;AAE9C,WAAO,MAAM,CAAC,YAAY,CAAC;AAAA,EAC7B;AACF;AAEO,IAAM,kBAAkB,YAAY;AACzC,QAAM,WAAW,SAAS,SAAS,2BAA2B,EAAE;AAGhE,QAAM,qBAAqB,SAAS;AAAA;AAAA;AAAA;AAAA,IAIlC;AAEF,UAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,CAAC;AAC/B","sourcesContent":["export * from './generate'\nexport * from './utils'\n","/* eslint-disable @typescript-eslint/no-unused-vars */\n/* eslint-disable no-console */\n\nimport ts from 'typescript'\nimport { template } from 'talt'\n\nimport { print } from './utils/print'\n\nexport const generateStringTemplate = <TParams = Record<string, ts.Node | string | undefined>>(\n templateStrings: string | TemplateStringsArray,\n ...placeholders: (string | ts.Node)[]\n) => {\n const compiledFn = template.statement(templateStrings, ...placeholders)\n return (params?: TParams) => {\n if (!params) {\n return undefined\n }\n const idPlaceholders: Record<string, ts.Node> = {}\n\n Object.keys(params).forEach((key) => {\n idPlaceholders[key] = typeof params[key] ? ts.factory.createStringLiteral(params[key]) : params[key]\n })\n\n const generatedAst = compiledFn(idPlaceholders)\n\n return print([generatedAst])\n }\n}\n\nexport const logDemoTemplate = async () => {\n const typeNode = template.typeNode('{ readonly test: string }')()\n\n // You can use `template` as tag function.\n const typeNodeUsingTagFn = template.typeNode`\n {\n readonly test: string;\n }\n `()\n\n console.log(print([typeNode]))\n}\n","import ts from 'typescript'\n\nexport const print = (elements: ts.Node | ts.Node[], fileName = 'print.ts') => {\n let nodes: ts.Node[] = []\n if (Array.isArray(elements)) {\n nodes = elements\n } else {\n nodes = [elements]\n }\n const nodesArray = ts.factory.createNodeArray(nodes)\n const sourceFile = ts.createSourceFile(fileName, '', ts.ScriptTarget.ESNext, true, ts.ScriptKind.TS)\n\n const printer = ts.createPrinter()\n const outputFile = printer.printList(ts.ListFormat.MultiLine, nodesArray, sourceFile)\n\n return outputFile\n}\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -30,30 +30,30 @@ declare class Emitter<TValue = unknown, TTopics = unknown> {
|
|
|
30
30
|
constructor(topics?: TTopics[]);
|
|
31
31
|
emit(...params: [topic: TTopics, value?: TValue] | [value?: TValue]): void;
|
|
32
32
|
subscribe: (cb: Listener<TValue>) => () => void;
|
|
33
|
-
on(topic: TTopics, cb: Listener<TValue>):
|
|
33
|
+
on(topic: TTopics, cb: Listener<TValue>): () => boolean;
|
|
34
34
|
destroy: () => void;
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
interface EmittedFile {
|
|
38
38
|
id: string;
|
|
39
|
-
fileName: string | undefined;
|
|
40
|
-
name: string | undefined;
|
|
41
39
|
source: string | undefined;
|
|
42
|
-
|
|
40
|
+
name: string | undefined;
|
|
41
|
+
code: string | undefined;
|
|
42
|
+
meta?: Record<string, any>;
|
|
43
43
|
}
|
|
44
44
|
type EmitFile = (emittedFile: EmittedFile) => void;
|
|
45
|
-
type Topics = 'new' | 'delete' | '
|
|
45
|
+
type Topics = 'new' | 'delete' | 'end';
|
|
46
46
|
declare class FileEmitter {
|
|
47
47
|
private readonly emitter;
|
|
48
48
|
private readonly filesByReferenceId;
|
|
49
49
|
constructor(emitter?: Emitter<EmittedFile, Topics>);
|
|
50
|
-
emitFile(emitedFile: EmittedFile):
|
|
50
|
+
emitFile(emitedFile: EmittedFile): Promise<EmittedFile>;
|
|
51
51
|
delete(fileReferenceId: string): void;
|
|
52
52
|
subscribe(...params: Parameters<typeof this$1.emitter['subscribe']>): void;
|
|
53
53
|
on(...params: Parameters<typeof this$1.emitter['on']>): void;
|
|
54
54
|
private assignReferenceId;
|
|
55
|
-
getEmittedFile: (fileReferenceId
|
|
56
|
-
getFileName: (fileReferenceId: string) => string | undefined;
|
|
55
|
+
getEmittedFile: (fileReferenceId?: string | null) => EmittedFile | undefined;
|
|
56
|
+
getFileName: (fileReferenceId: string | null) => string | undefined;
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
/**
|
|
@@ -69,13 +69,14 @@ declare class PluginDriver {
|
|
|
69
69
|
private readonly logger?;
|
|
70
70
|
private readonly config;
|
|
71
71
|
private readonly sortedPlugins;
|
|
72
|
-
constructor(config:
|
|
72
|
+
constructor(config: Api['config'], pluginCache: Record<string, SerializablePluginCache> | undefined, options: {
|
|
73
73
|
logger: BuildContext['logger'];
|
|
74
74
|
});
|
|
75
75
|
get apis(): ReadonlyMap<Plugin<PluginOptions<unknown, false, any>>, PluginContext>;
|
|
76
76
|
get api(): PluginContext;
|
|
77
|
-
emitFile(...params: Parameters<FileEmitter['emitFile']>):
|
|
78
|
-
resolveId: (source: string,
|
|
77
|
+
emitFile(...params: Parameters<FileEmitter['emitFile']>): Promise<EmittedFile>;
|
|
78
|
+
resolveId: (source: string, importer: string, meta: Record<string, any> | undefined) => Promise<string | null | undefined>;
|
|
79
|
+
load: (id: string) => Promise<TransformResult>;
|
|
79
80
|
hookFirst<H extends PluginLifecycleHooks>(hookName: H, parameters: Parameters<PluginLifecycle[H]>, skipped?: ReadonlySet<Plugin> | null): Promise<ReturnType<PluginLifecycle[H]> | null>;
|
|
80
81
|
hookParallel<H extends PluginLifecycleHooks, TOuput = void>(hookName: H, parameters?: Parameters<PluginLifecycle[H]> | undefined): Promise<Awaited<TOuput>[]>;
|
|
81
82
|
hookReduceArg0<H extends PluginLifecycleHooks>(hookName: H, [argument0, ...rest]: Parameters<PluginLifecycle[H]>, reduce: (reduction: Argument0<H>, result: ReturnType<PluginLifecycle[H]>, plugin: Plugin) => WithPromise<Argument0<H> | null>): Promise<Argument0<H>>;
|
|
@@ -98,7 +99,10 @@ declare class PluginDriver {
|
|
|
98
99
|
private runHookSync;
|
|
99
100
|
}
|
|
100
101
|
|
|
101
|
-
declare const
|
|
102
|
+
declare const formatOptions: Options;
|
|
103
|
+
declare const format: (text: string) => string;
|
|
104
|
+
|
|
105
|
+
declare const getRelativePath: (from?: string | null, to?: string | null) => string;
|
|
102
106
|
|
|
103
107
|
type PluginOptions<UserOptions = unknown, Nested extends boolean = false, Api = any> = {
|
|
104
108
|
userOptions: UserOptions;
|
|
@@ -117,8 +121,8 @@ type PluginName = 'string';
|
|
|
117
121
|
type PluginLifecycle = {
|
|
118
122
|
validate: (this: PluginContext, plugins: Plugin[]) => WithPromise<ValidationResult>;
|
|
119
123
|
buildStart: (this: PluginContext) => WithPromise<void>;
|
|
120
|
-
resolveId: (this: PluginContext, source: string, importer: string | undefined) => string | null | undefined;
|
|
121
|
-
load: (this: PluginContext, id: string) => WithPromise<TransformResult |
|
|
124
|
+
resolveId: (this: PluginContext, source: string, importer: string | undefined, meta: Record<string, any> | undefined) => string | null | undefined;
|
|
125
|
+
load: (this: PluginContext, id: string) => WithPromise<TransformResult | null>;
|
|
122
126
|
transform: (this: PluginContext, code: string, id: string) => WithPromise<TransformResult>;
|
|
123
127
|
writeFile: (this: PluginContext, code: string | undefined, id: string) => WithPromise<void>;
|
|
124
128
|
buildEnd: (this: PluginContext) => WithPromise<void>;
|
|
@@ -130,9 +134,11 @@ type Api = {
|
|
|
130
134
|
};
|
|
131
135
|
schema: Schema;
|
|
132
136
|
emitFile: FileEmitter['emitFile'];
|
|
133
|
-
resolveId: (source: string, importer?: string) => WithPromise<string | null | undefined>;
|
|
137
|
+
resolveId: (source: string, importer?: string, meta?: Record<string, any>) => WithPromise<string | null | undefined>;
|
|
138
|
+
load: (id: string) => WithPromise<TransformResult | void>;
|
|
134
139
|
getFileName: FileEmitter['getFileName'];
|
|
135
140
|
getEmittedFile: FileEmitter['getEmittedFile'];
|
|
141
|
+
on: FileEmitter['on'];
|
|
136
142
|
};
|
|
137
143
|
type PluginContext = Api & {
|
|
138
144
|
cache: Cache;
|
|
@@ -173,7 +179,7 @@ interface UserConfig {
|
|
|
173
179
|
path: string;
|
|
174
180
|
};
|
|
175
181
|
/**
|
|
176
|
-
* Array of
|
|
182
|
+
* Array of kubb plugins to use.
|
|
177
183
|
*/
|
|
178
184
|
plugins?: Plugin[];
|
|
179
185
|
logLevel?: LogLevel;
|
|
@@ -181,7 +187,7 @@ interface UserConfig {
|
|
|
181
187
|
type UserConfigFn = (env: ConfigEnv) => WithPromise<UserConfig>;
|
|
182
188
|
type UserConfigExport = WithPromise<UserConfig> | UserConfigFn;
|
|
183
189
|
/**
|
|
184
|
-
* Type helper to make it easier to use
|
|
190
|
+
* Type helper to make it easier to use kubb.config.ts
|
|
185
191
|
* accepts a direct {@link UserConfig} object, or a function that returns it.
|
|
186
192
|
* The function receives a {@link ConfigEnv} object that exposes two properties:
|
|
187
193
|
*/
|
|
@@ -204,7 +210,7 @@ type BuildContext = {
|
|
|
204
210
|
spinner?: Spinner;
|
|
205
211
|
};
|
|
206
212
|
};
|
|
207
|
-
declare function build(this: BuildContext,
|
|
213
|
+
declare function build(this: BuildContext, userConfig: UserConfig, env: ConfigEnv): Promise<BuildOutput>;
|
|
208
214
|
|
|
209
215
|
declare function getPluginContext(this: PluginDriver, plugin: Plugin, pluginCache: Record<string, SerializablePluginCache> | void): {
|
|
210
216
|
cache: Cache<any>;
|
|
@@ -215,4 +221,4 @@ declare namespace Plugins {
|
|
|
215
221
|
}
|
|
216
222
|
}
|
|
217
223
|
|
|
218
|
-
export { Api, Argument0, BuildContext, Cache, ConfigEnv, EmitFile, EmittedFile, Emitter, FileEmitter, Id, Listener, LogLevel, LogType, Plugin, PluginContext, PluginDriver, PluginFactory, PluginLifecycle, PluginLifecycleHooks, PluginName, PluginOptions, Plugins, Schema, SerializablePluginCache, TransformResult, UserConfig, UserConfigExport, UserConfigFn, ValidationResult, WithPromise, build, createPlugin, createPluginCache, createQueue, build as default, defineConfig, format, getPluginContext, hooks, isPromise, write };
|
|
224
|
+
export { Api, Argument0, BuildContext, Cache, ConfigEnv, EmitFile, EmittedFile, Emitter, FileEmitter, Id, Listener, LogLevel, LogType, Plugin, PluginContext, PluginDriver, PluginFactory, PluginLifecycle, PluginLifecycleHooks, PluginName, PluginOptions, Plugins, Schema, SerializablePluginCache, TransformResult, UserConfig, UserConfigExport, UserConfigFn, ValidationResult, WithPromise, build, createPlugin, createPluginCache, createQueue, build as default, defineConfig, format, formatOptions, getPluginContext, getRelativePath, hooks, isPromise, write };
|
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var path2 = require('path');
|
|
6
6
|
var fse2 = require('fs-extra');
|
|
7
7
|
var prettier = require('prettier');
|
|
8
8
|
|
|
@@ -36,10 +36,12 @@ var Emitter = class {
|
|
|
36
36
|
return () => this.listeners.delete(listener);
|
|
37
37
|
};
|
|
38
38
|
on(topic, cb) {
|
|
39
|
-
|
|
39
|
+
const listener = {
|
|
40
40
|
topic,
|
|
41
41
|
cb
|
|
42
|
-
}
|
|
42
|
+
};
|
|
43
|
+
this.listeners.add(listener);
|
|
44
|
+
return () => this.listeners.delete(listener);
|
|
43
45
|
}
|
|
44
46
|
destroy = () => this.listeners.clear();
|
|
45
47
|
};
|
|
@@ -48,19 +50,29 @@ var Emitter = class {
|
|
|
48
50
|
var FileEmitter = class {
|
|
49
51
|
emitter;
|
|
50
52
|
filesByReferenceId = /* @__PURE__ */ new Map();
|
|
51
|
-
constructor(emitter = new Emitter(["delete", "
|
|
53
|
+
constructor(emitter = new Emitter(["delete", "end", "new"])) {
|
|
52
54
|
this.emitter = emitter;
|
|
53
55
|
}
|
|
54
56
|
emitFile(emitedFile) {
|
|
55
57
|
this.assignReferenceId(emitedFile, emitedFile.id);
|
|
56
|
-
|
|
58
|
+
this.emitter.emit("new", emitedFile);
|
|
59
|
+
return new Promise((resolve) => {
|
|
60
|
+
const subscribe = this.emitter.on("delete", (deletedFile) => {
|
|
61
|
+
if (deletedFile?.id === emitedFile.id) {
|
|
62
|
+
resolve(deletedFile);
|
|
63
|
+
return subscribe();
|
|
64
|
+
}
|
|
65
|
+
return void 0;
|
|
66
|
+
});
|
|
67
|
+
});
|
|
57
68
|
}
|
|
58
69
|
delete(fileReferenceId) {
|
|
70
|
+
const deletedFile = this.filesByReferenceId.get(fileReferenceId);
|
|
59
71
|
this.filesByReferenceId.delete(fileReferenceId);
|
|
60
72
|
if (this.filesByReferenceId.size === 0) {
|
|
61
|
-
this.emitter.emit("
|
|
73
|
+
this.emitter.emit("end");
|
|
62
74
|
}
|
|
63
|
-
return this.emitter.emit("delete");
|
|
75
|
+
return this.emitter.emit("delete", deletedFile);
|
|
64
76
|
}
|
|
65
77
|
subscribe(...params) {
|
|
66
78
|
this.emitter.subscribe(...params);
|
|
@@ -74,10 +86,16 @@ var FileEmitter = class {
|
|
|
74
86
|
}
|
|
75
87
|
}
|
|
76
88
|
getEmittedFile = (fileReferenceId) => {
|
|
89
|
+
if (!fileReferenceId) {
|
|
90
|
+
return void 0;
|
|
91
|
+
}
|
|
77
92
|
return this.filesByReferenceId.get(fileReferenceId);
|
|
78
93
|
};
|
|
79
94
|
getFileName = (fileReferenceId) => {
|
|
80
|
-
|
|
95
|
+
if (!fileReferenceId) {
|
|
96
|
+
return void 0;
|
|
97
|
+
}
|
|
98
|
+
return this.filesByReferenceId.get(fileReferenceId)?.source;
|
|
81
99
|
};
|
|
82
100
|
};
|
|
83
101
|
|
|
@@ -130,26 +148,25 @@ function createPlugin(factory) {
|
|
|
130
148
|
};
|
|
131
149
|
}
|
|
132
150
|
var createCorePlugin = createPlugin((options) => {
|
|
133
|
-
const { fileEmitter, resolveId } = options;
|
|
134
|
-
const
|
|
135
|
-
|
|
136
|
-
|
|
151
|
+
const { fileEmitter, resolveId, load } = options;
|
|
152
|
+
const schema = fse2.readFileSync(path2.resolve(options.config.root, options.config.input.schema), "utf-8");
|
|
153
|
+
const api = {
|
|
154
|
+
get config() {
|
|
155
|
+
return options.config;
|
|
156
|
+
},
|
|
157
|
+
get schema() {
|
|
158
|
+
return schema;
|
|
159
|
+
},
|
|
160
|
+
on: fileEmitter.on.bind(fileEmitter),
|
|
161
|
+
getFileName: fileEmitter.getFileName.bind(fileEmitter),
|
|
162
|
+
getEmittedFile: fileEmitter.getEmittedFile.bind(fileEmitter),
|
|
163
|
+
emitFile: fileEmitter.emitFile.bind(fileEmitter),
|
|
164
|
+
resolveId,
|
|
165
|
+
load
|
|
137
166
|
};
|
|
138
|
-
const schema = fse2.readFileSync(path.resolve(config.root, config.input.schema), "utf-8");
|
|
139
167
|
return {
|
|
140
168
|
name: "core",
|
|
141
|
-
api
|
|
142
|
-
get config() {
|
|
143
|
-
return config;
|
|
144
|
-
},
|
|
145
|
-
get schema() {
|
|
146
|
-
return schema;
|
|
147
|
-
},
|
|
148
|
-
getFileName: fileEmitter.getFileName.bind(fileEmitter),
|
|
149
|
-
getEmittedFile: fileEmitter.getEmittedFile.bind(fileEmitter),
|
|
150
|
-
emitFile: fileEmitter.emitFile.bind(fileEmitter),
|
|
151
|
-
resolveId
|
|
152
|
-
}
|
|
169
|
+
api
|
|
153
170
|
};
|
|
154
171
|
});
|
|
155
172
|
|
|
@@ -176,7 +193,7 @@ var PluginDriver = class {
|
|
|
176
193
|
this.config = config;
|
|
177
194
|
this.fileEmitter = new FileEmitter();
|
|
178
195
|
this.emitFile = this.fileEmitter.emitFile.bind(this.fileEmitter);
|
|
179
|
-
const corePlugin = createCorePlugin({ config, fileEmitter: this.fileEmitter, resolveId: this.resolveId });
|
|
196
|
+
const corePlugin = createCorePlugin({ config, fileEmitter: this.fileEmitter, load: this.load, resolveId: this.resolveId });
|
|
180
197
|
this.plugins = [corePlugin, ...config.plugins || []];
|
|
181
198
|
const coreApi = corePlugin.api;
|
|
182
199
|
this.pluginContexts = new Map(
|
|
@@ -202,8 +219,12 @@ var PluginDriver = class {
|
|
|
202
219
|
emitFile(...params) {
|
|
203
220
|
return this.fileEmitter.emitFile(...params);
|
|
204
221
|
}
|
|
205
|
-
resolveId = (source,
|
|
206
|
-
return this.hookFirst("resolveId", [source,
|
|
222
|
+
resolveId = (source, importer, meta) => {
|
|
223
|
+
return this.hookFirst("resolveId", [source, importer, meta]);
|
|
224
|
+
};
|
|
225
|
+
load = async (id) => {
|
|
226
|
+
const result = await this.hookFirst("load", [id]);
|
|
227
|
+
return result;
|
|
207
228
|
};
|
|
208
229
|
hookFirst(hookName, parameters, skipped) {
|
|
209
230
|
let promise = Promise.resolve(null);
|
|
@@ -320,32 +341,39 @@ async function buildImplementation(options, done) {
|
|
|
320
341
|
return;
|
|
321
342
|
}
|
|
322
343
|
pluginDriver.fileEmitter.on("new", async (emittedFile) => {
|
|
323
|
-
if (!emittedFile?.
|
|
344
|
+
if (!emittedFile?.source) {
|
|
324
345
|
return;
|
|
325
346
|
}
|
|
326
|
-
const resolvedId = await pluginDriver.hookFirst("resolveId", [emittedFile.
|
|
327
|
-
const id = resolvedId || emittedFile.
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
347
|
+
const resolvedId = await pluginDriver.hookFirst("resolveId", [emittedFile.source, path2.resolve(emittedFile.source), emittedFile.meta]);
|
|
348
|
+
const id = resolvedId || emittedFile.source;
|
|
349
|
+
let { code } = emittedFile;
|
|
350
|
+
const loadedResult = await pluginDriver.hookFirst("load", [id]);
|
|
351
|
+
if (loadedResult) {
|
|
352
|
+
code = loadedResult;
|
|
353
|
+
}
|
|
354
|
+
if (code) {
|
|
355
|
+
const result = await pluginDriver.hookReduceArg0("transform", [code, id], transformReducer);
|
|
331
356
|
await pluginDriver.hookParallel("writeFile", [result, id]);
|
|
332
357
|
pluginDriver.fileEmitter.delete(emittedFile.id);
|
|
333
358
|
}
|
|
334
359
|
});
|
|
335
360
|
await pluginDriver.hookParallel("buildStart");
|
|
336
361
|
pluginDriver.emitFile({
|
|
337
|
-
id: pluginDriver.api.config.root,
|
|
338
|
-
|
|
362
|
+
id: path2.resolve(pluginDriver.api.config.root, pluginDriver.api.config.input.schema),
|
|
363
|
+
source: pluginDriver.api.config.input.schema,
|
|
339
364
|
name: void 0,
|
|
340
|
-
|
|
341
|
-
type: "asset"
|
|
365
|
+
code: pluginDriver.api.schema
|
|
342
366
|
});
|
|
343
|
-
pluginDriver.fileEmitter.on("
|
|
367
|
+
pluginDriver.fileEmitter.on("end", async () => {
|
|
344
368
|
await pluginDriver.hookParallel("buildEnd");
|
|
345
369
|
done();
|
|
346
370
|
});
|
|
347
371
|
}
|
|
348
|
-
function build(
|
|
372
|
+
function build(userConfig, env) {
|
|
373
|
+
const config = {
|
|
374
|
+
...userConfig,
|
|
375
|
+
root: userConfig.root || process.cwd()
|
|
376
|
+
};
|
|
349
377
|
return new Promise((resolve) => {
|
|
350
378
|
buildImplementation.call(
|
|
351
379
|
this,
|
|
@@ -381,21 +409,22 @@ var createQueue = (arr, fun) => {
|
|
|
381
409
|
});
|
|
382
410
|
return Promise.all(promises);
|
|
383
411
|
};
|
|
384
|
-
|
|
385
|
-
// src/utils/format.ts
|
|
386
|
-
var format = {
|
|
412
|
+
var formatOptions = {
|
|
387
413
|
tabWidth: 2,
|
|
388
414
|
printWidth: 160,
|
|
389
415
|
parser: "typescript",
|
|
390
|
-
singleQuote:
|
|
391
|
-
semi:
|
|
416
|
+
singleQuote: true,
|
|
417
|
+
semi: false,
|
|
392
418
|
bracketSameLine: false,
|
|
393
419
|
endOfLine: "auto"
|
|
394
420
|
};
|
|
421
|
+
var format = (text) => {
|
|
422
|
+
return prettier.format(text, formatOptions);
|
|
423
|
+
};
|
|
395
424
|
|
|
396
425
|
// src/utils/write.ts
|
|
397
426
|
var write = async (data, path4, options = { format: false }) => {
|
|
398
|
-
const formattedData = options.format ?
|
|
427
|
+
const formattedData = options.format ? format(data) : data;
|
|
399
428
|
try {
|
|
400
429
|
await fse2.stat(path4);
|
|
401
430
|
const oldContent = await fse2.readFile(path4, { encoding: "utf-8" });
|
|
@@ -407,6 +436,12 @@ var write = async (data, path4, options = { format: false }) => {
|
|
|
407
436
|
}
|
|
408
437
|
return fse2.outputFile(path4, formattedData);
|
|
409
438
|
};
|
|
439
|
+
var getRelativePath = (from, to) => {
|
|
440
|
+
if (!from || !to) {
|
|
441
|
+
throw new Error("From and to should be filled in when retrieving the relativePath");
|
|
442
|
+
}
|
|
443
|
+
return path2.relative(from, to).replace("../", "").replace(".ts", "").trimEnd();
|
|
444
|
+
};
|
|
410
445
|
|
|
411
446
|
// src/index.ts
|
|
412
447
|
var src_default = build;
|
|
@@ -421,7 +456,9 @@ exports.createQueue = createQueue;
|
|
|
421
456
|
exports.default = src_default;
|
|
422
457
|
exports.defineConfig = defineConfig;
|
|
423
458
|
exports.format = format;
|
|
459
|
+
exports.formatOptions = formatOptions;
|
|
424
460
|
exports.getPluginContext = getPluginContext;
|
|
461
|
+
exports.getRelativePath = getRelativePath;
|
|
425
462
|
exports.hooks = hooks;
|
|
426
463
|
exports.isPromise = isPromise;
|
|
427
464
|
exports.write = write;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/build.ts","../src/utils/PluginDriver.ts","../src/utils/Emitter.ts","../src/utils/FileEmitter.ts","../src/utils/cache.ts","../src/context.ts","../src/plugin.ts","../src/config.ts","../src/utils/isPromise.ts","../src/utils/createQueue.ts","../src/utils/write.ts","../src/utils/format.ts","../src/index.ts"],"names":["path","argument0","fse"],"mappings":";AAIA,OAAOA,WAAU;;;ACGjB,OAAOA,WAAU;;;ACLV,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,SAAK,UAAU,IAAI;AAAA,MACjB;AAAA,MACA;AAAA,IACF,CAAC;AAAA,EACH;AAAA,EAEA,UAAsB,MAAM,KAAK,UAAU,MAAM;AACnD;;;ACjCO,IAAM,cAAN,MAAkB;AAAA,EACN;AAAA,EAEA,qBAA+C,oBAAI,IAAI;AAAA,EAExE,YAAY,UAAwC,IAAI,QAA6B,CAAC,UAAU,QAAQ,KA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BAAgB,QAAQ,SAAS,SAAS,OAAO,MAAM,MAAM,IAAI;AAEvE,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;;;AEdA,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 { PluginContext, TransformResult, ValidationResult } from './types'\nimport type { UserConfig, ConfigEnv } from './config'\nimport type { LogLevel } from './utils/logger'\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: UserConfig\n env: ConfigEnv\n}\n\nasync function buildImplementation(this: BuildContext, options: BuildImplementationOptions, done: (output: BuildOutput) => void) {\n const { config } = options\n if (config.lifeCycle && config.lifeCycle !== 'plugins') {\n throw new Error('Only lifeCycle plugins possible')\n }\n\n if (config.strategy && config.strategy !== 'lifo') {\n throw new Error('Only strategy fifo possible')\n }\n\n const pluginCache = Object.create(null)\n const pluginDriver = new PluginDriver(config, pluginCache, { logger: this.logger })\n\n const validations = await pluginDriver.hookParallel<'validate', ValidationResult>('validate', [pluginDriver.plugins])\n\n const validationsWithMessage = validations.filter(Boolean)\n\n if (validationsWithMessage.some((validation) => typeof validation !== 'boolean')) {\n validationsWithMessage.forEach((validation) => {\n if (validation && typeof validation !== 'boolean' && validation?.message) {\n this.logger?.log(validation.message, 'warn')\n }\n })\n\n return\n }\n\n pluginDriver.fileEmitter.on('new', async (emittedFile) => {\n if (!emittedFile?.fileName) {\n return\n }\n\n const resolvedId = await pluginDriver.hookFirst('resolveId', [emittedFile.fileName, path.resolve(emittedFile.fileName)])\n const id = resolvedId || emittedFile.fileName\n\n await pluginDriver.hookParallel('load', [id])\n\n if (emittedFile.source) {\n const result = await pluginDriver.hookReduceArg0('transform', [emittedFile.source, 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: pluginDriver.api.config.root,\n fileName: pluginDriver.api.config.root,\n name: undefined,\n source: pluginDriver.api.schema,\n type: 'asset',\n })\n\n pluginDriver.fileEmitter.on('done', async (d) => {\n await pluginDriver.hookParallel('buildEnd')\n done()\n })\n}\n\nexport function build(this: BuildContext, config: UserConfig, env: ConfigEnv): Promise<BuildOutput> {\n return new Promise((resolve) => {\n buildImplementation.call(\n this,\n {\n config,\n env,\n },\n resolve\n )\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 path from 'path'\n\nimport { FileEmitter } from './FileEmitter'\n\nimport { getPluginContext } from '../context'\nimport { createCorePlugin } from '../plugin'\n\nimport type { BuildContext } from '../build'\nimport type { SerializablePluginCache } from './cache'\nimport type { Plugin } from '../plugin'\nimport type { UserConfig } from '../config'\nimport type { PluginLifecycleHooks, PluginLifecycle, WithPromise, PluginContext } 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: UserConfig\n\n private readonly sortedPlugins = new Map<PluginLifecycleHooks, Plugin[]>()\n\n constructor(config: UserConfig, 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 = createCorePlugin({ config, fileEmitter: this.fileEmitter, 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 apis() {\n return this.pluginContexts\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 | undefined) => {\n return this.hookFirst('resolveId', [source, path.resolve(source)])\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","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 this.listeners.add({\n topic,\n cb,\n })\n }\n\n destroy: () => void = () => this.listeners.clear()\n}\n","import { Emitter } from './Emitter'\n\nexport interface EmittedFile {\n id: string\n fileName: string | undefined\n name: string | undefined\n source: string | undefined\n type: 'asset'\n}\n\nexport type EmitFile = (emittedFile: EmittedFile) => void\n\ntype Topics = 'new' | 'delete' | 'done'\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', 'done', 'new'])) {\n this.emitter = emitter\n }\n\n emitFile(emitedFile: EmittedFile) {\n // save locally in this class\n this.assignReferenceId(emitedFile, emitedFile.id)\n return this.emitter.emit('new', emitedFile)\n }\n\n delete(fileReferenceId: string) {\n this.filesByReferenceId.delete(fileReferenceId)\n if (this.filesByReferenceId.size === 0) {\n this.emitter.emit('done')\n }\n return this.emitter.emit('delete')\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): EmittedFile | undefined => {\n return this.filesByReferenceId.get(fileReferenceId)\n }\n\n getFileName = (fileReferenceId: string): string | undefined => {\n return this.filesByReferenceId.get(fileReferenceId)?.fileName\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'\nimport fse from 'fs-extra'\n\nimport type { FileEmitter } from './utils'\nimport type { PluginLifecycle, PluginName, Api } from './types'\nimport type { UserConfig } from './config'\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 config: UserConfig\n fileEmitter: FileEmitter\n resolveId: Api['resolveId']\n}\n\n// not exported\ntype CorePluginOptions = PluginOptions<Options, false, Api>\n\nexport const createCorePlugin = createPlugin<CorePluginOptions>((options) => {\n const { fileEmitter, resolveId } = options\n const config = {\n ...options.config,\n root: options.config.root || process.cwd(),\n }\n const schema = fse.readFileSync(path.resolve(config.root, config.input.schema), 'utf-8')\n\n return {\n name: 'core',\n api: {\n get config() {\n return config\n },\n get schema() {\n return schema\n },\n getFileName: fileEmitter.getFileName.bind(fileEmitter),\n getEmittedFile: fileEmitter.getEmittedFile.bind(fileEmitter),\n emitFile: fileEmitter.emitFile.bind(fileEmitter),\n resolveId,\n },\n }\n})\n","import type { WithPromise } from './types'\nimport type { LogLevel } from './utils/logger'\nimport type { Plugin } from './plugin'\n\nexport interface ConfigEnv {\n mode: string\n}\n// TODO revert to this to have multiple options like async, object, ...\n// export type PluginOption = PluginOptions | false | null | undefined | PluginOption[] | Promise<PluginOptions | false | null | undefined | PluginOption[]>;\n\nexport interface UserConfig {\n /**\n * Project root directory. Can be an absolute path, or a path relative from\n * the location of the config file itself.\n * @default process.cwd()\n */\n root?: string\n mode?: 'single'\n /**\n * plugins means it will run context, buildStart, transform and buildEnd based on order of the plugins array\n * Example of an order(plugin x does not have a buildEnd): [buildStart of plugin x, buildStart of plugin y, transform of plugin x, transform of plugin y, buildEnd of plugin y ]\n * Default: plugins\n */\n lifeCycle?: 'plugins'\n /**\n * Default: fifo\n */\n strategy?: 'fifo' | 'lifo'\n input: {\n schema: string\n }\n output: {\n path: string\n }\n /**\n * Array of regenerator plugins to use.\n */\n plugins?: Plugin[]\n\n logLevel?: LogLevel\n}\n\nexport type UserConfigFn = (env: ConfigEnv) => WithPromise<UserConfig>\nexport type UserConfigExport = WithPromise<UserConfig> | UserConfigFn\n\n/**\n * Type helper to make it easier to use regenerator.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","import type { WithPromise } from '../types'\n\nexport const isPromise = <T>(result: WithPromise<T>): result is Promise<T> => {\n return typeof (result as any)?.then === 'function'\n}\n","import { isPromise } from './isPromise'\n\nimport type { WithPromise } from '../types'\n\nexport const createQueue = <TArray extends readonly any[] = readonly any[], TInput = TArray[number], TOuput = void>(\n arr: TArray | undefined,\n fun: (item: TInput) => WithPromise<TOuput>\n) => {\n const promises: Promise<TOuput>[] = []\n\n arr?.forEach((item) => {\n const result = fun(item)\n if (isPromise<TOuput>(result)) {\n promises.push(result)\n } else {\n promises.push(Promise.resolve(result))\n }\n })\n\n return Promise.all(promises)\n}\n","/* eslint-disable consistent-return */\nimport fse from 'fs-extra'\nimport prettier from 'prettier'\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 ? prettier.format(data, format) : 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 type { Options } from 'prettier'\n\nexport const format: Options = {\n tabWidth: 2,\n printWidth: 160,\n parser: 'typescript',\n singleQuote: false,\n semi: true,\n bracketSameLine: false,\n endOfLine: 'auto',\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\nexport namespace Plugins {\n export interface Context {}\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/build.ts","../src/utils/Emitter.ts","../src/utils/FileEmitter.ts","../src/utils/cache.ts","../src/context.ts","../src/plugin.ts","../src/utils/PluginDriver.ts","../src/config.ts","../src/utils/isPromise.ts","../src/utils/createQueue.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,YAAk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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,SAAOA,MAAK,SAAS,MAAM,EAAE,EAAE,QAAQ,OAAO,EAAE,EAAE,QAAQ,OAAO,EAAE,EAAE,QAAQ;AAC/E;;;ACEA,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 } from './types'\nimport type { UserConfig, ConfigEnv } from './config'\nimport type { LogLevel } from './utils/logger'\nimport type { Plugin } from './plugin'\n\ntype BuildOutput = void\n\n// Same type as ora\ntype Spinner = {\n start: (text?: string) => Spinner\n succeed: (text: string) => Spinner\n stopAndPersist: (options: { text: string }) => Spinner\n render: () => Spinner\n text: string\n info: (text: string) => Spinner\n}\n\nexport type BuildContext = {\n logger?: {\n log: (message: string, logLevel: LogLevel) => void\n spinner?: Spinner\n }\n}\n\nasync function transformReducer(this: PluginContext, previousCode: string, result: TransformResult, _plugin: Plugin) {\n if (result === null) {\n return null\n }\n return result\n}\n\ntype BuildImplementationOptions = {\n config: Api['config']\n env: ConfigEnv\n}\n\nasync function buildImplementation(this: BuildContext, options: BuildImplementationOptions, done: (output: BuildOutput) => void) {\n const { config } = options\n if (config.lifeCycle && config.lifeCycle !== 'plugins') {\n throw new Error('Only lifeCycle plugins possible')\n }\n\n if (config.strategy && config.strategy !== 'lifo') {\n throw new Error('Only strategy fifo possible')\n }\n\n const pluginCache = Object.create(null)\n const pluginDriver = new PluginDriver(config, pluginCache, { logger: this.logger })\n\n const validations = await pluginDriver.hookParallel<'validate', ValidationResult>('validate', [pluginDriver.plugins])\n\n const validationsWithMessage = validations.filter(Boolean)\n\n if (validationsWithMessage.some((validation) => typeof validation !== 'boolean')) {\n validationsWithMessage.forEach((validation) => {\n if (validation && typeof validation !== 'boolean' && validation?.message) {\n this.logger?.log(validation.message, 'warn')\n }\n })\n\n return\n }\n\n pluginDriver.fileEmitter.on('new', async (emittedFile) => {\n if (!emittedFile?.source) {\n return\n }\n\n const resolvedId = await pluginDriver.hookFirst('resolveId', [emittedFile.source, path.resolve(emittedFile.source), emittedFile.meta])\n const id = resolvedId || emittedFile.source\n let { code } = emittedFile\n\n const loadedResult = await pluginDriver.hookFirst('load', [id])\n if (loadedResult) {\n code = loadedResult\n }\n\n if (code) {\n const result = await pluginDriver.hookReduceArg0('transform', [code, id], transformReducer)\n\n await pluginDriver.hookParallel('writeFile', [result, id])\n pluginDriver.fileEmitter.delete(emittedFile.id)\n }\n })\n\n await pluginDriver.hookParallel('buildStart')\n\n pluginDriver.emitFile({\n id: path.resolve(pluginDriver.api.config.root, pluginDriver.api.config.input.schema),\n source: pluginDriver.api.config.input.schema,\n name: undefined,\n code: pluginDriver.api.schema,\n })\n\n pluginDriver.fileEmitter.on('end', async () => {\n await pluginDriver.hookParallel('buildEnd')\n done()\n })\n}\n\nexport function build(this: BuildContext, userConfig: UserConfig, env: ConfigEnv): Promise<BuildOutput> {\n const config: UserConfig = {\n ...userConfig,\n root: userConfig.root || process.cwd(),\n }\n\n return new Promise((resolve) => {\n buildImplementation.call(\n this,\n {\n config,\n env,\n },\n resolve\n )\n })\n}\n","export type Listener<T> = (value?: T) => void\n\nexport class Emitter<TValue = unknown, TTopics = unknown> {\n private readonly listeners: Set<{\n topic?: TTopics\n cb: Listener<TValue>\n }> = new Set()\n\n private readonly topics?: TTopics[]\n\n constructor(topics?: TTopics[]) {\n this.topics = topics\n }\n\n emit(...params: [topic: TTopics, value?: TValue] | [value?: TValue]) {\n const isTopic = (value: any): value is TTopics => !!this.topics?.includes(value)\n\n if (isTopic(params[0])) {\n this.listeners.forEach((listener) => {\n if (listener.topic === params[0]) {\n listener.cb(params[1])\n }\n })\n return\n }\n this.listeners.forEach((listener) => listener.cb(params[0] as TValue))\n }\n\n subscribe: (cb: Listener<TValue>) => () => void = (cb) => {\n const listener = {\n topic: undefined,\n cb,\n }\n this.listeners.add(listener)\n // Unsubscribe\n return () => this.listeners.delete(listener)\n }\n\n on(topic: TTopics, cb: Listener<TValue>) {\n const listener = {\n topic,\n cb,\n }\n this.listeners.add(listener)\n return () => this.listeners.delete(listener)\n }\n\n destroy: () => void = () => this.listeners.clear()\n}\n","import { Emitter } from './Emitter'\n\nexport interface EmittedFile {\n id: string\n // this can be used as a dynamic path, also resolveId will use this as source(first parameter)\n source: string | undefined\n name: string | undefined\n code: string | undefined\n meta?: Record<string, any>\n}\n\nexport type EmitFile = (emittedFile: EmittedFile) => void\n\ntype Topics = 'new' | 'delete' | 'end'\nexport class FileEmitter {\n private readonly emitter: Emitter<EmittedFile, Topics>\n\n private readonly filesByReferenceId: Map<string, EmittedFile> = new Map()\n\n constructor(emitter: Emitter<EmittedFile, Topics> = new Emitter<EmittedFile, Topics>(['delete', 'end', 'new'])) {\n this.emitter = emitter\n }\n\n emitFile(emitedFile: EmittedFile) {\n // save locally in this class\n this.assignReferenceId(emitedFile, emitedFile.id)\n this.emitter.emit('new', emitedFile)\n return new Promise<EmittedFile>((resolve) => {\n const subscribe = this.emitter.on('delete', (deletedFile) => {\n if (deletedFile?.id === emitedFile.id) {\n resolve(deletedFile)\n return subscribe()\n }\n return undefined\n })\n })\n }\n\n delete(fileReferenceId: string) {\n const deletedFile = this.filesByReferenceId.get(fileReferenceId)\n this.filesByReferenceId.delete(fileReferenceId)\n if (this.filesByReferenceId.size === 0) {\n this.emitter.emit('end')\n }\n return this.emitter.emit('delete', deletedFile)\n }\n\n subscribe(...params: Parameters<typeof this.emitter['subscribe']>) {\n this.emitter.subscribe(...params)\n }\n\n on(...params: Parameters<typeof this.emitter['on']>) {\n this.emitter.on(...params)\n }\n\n private assignReferenceId(emittedFile: EmittedFile, fileReferenceId: string | undefined) {\n if (fileReferenceId) {\n this.filesByReferenceId.set(fileReferenceId, emittedFile)\n }\n }\n\n getEmittedFile = (fileReferenceId?: string | null): EmittedFile | undefined => {\n if (!fileReferenceId) {\n return undefined\n }\n return this.filesByReferenceId.get(fileReferenceId)\n }\n\n getFileName = (fileReferenceId: string | null): string | undefined => {\n if (!fileReferenceId) {\n return undefined\n }\n return this.filesByReferenceId.get(fileReferenceId)?.source\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 createCorePlugin = createPlugin<CorePluginOptions>((options) => {\n const { fileEmitter, resolveId, load } = options\n\n const schema = fse.readFileSync(path.resolve(options.config.root, options.config.input.schema), 'utf-8')\n\n const api: Api = {\n get config() {\n return options.config\n },\n get schema() {\n return schema\n },\n on: fileEmitter.on.bind(fileEmitter),\n getFileName: fileEmitter.getFileName.bind(fileEmitter),\n getEmittedFile: fileEmitter.getEmittedFile.bind(fileEmitter),\n emitFile: fileEmitter.emitFile.bind(fileEmitter),\n resolveId,\n load,\n }\n\n return {\n name: 'core',\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 { createCorePlugin } from '../plugin'\n\nimport type { BuildContext } from '../build'\nimport type { SerializablePluginCache } from './cache'\nimport type { Plugin } from '../plugin'\nimport type { PluginLifecycleHooks, PluginLifecycle, WithPromise, 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 = createCorePlugin({ 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 apis() {\n return this.pluginContexts\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 './types'\nimport type { LogLevel } from './utils/logger'\nimport type { Plugin } from './plugin'\n\nexport interface ConfigEnv {\n mode: string\n}\n// TODO revert to this to have multiple options like async, object, ...\n// export type PluginOption = PluginOptions | false | null | undefined | PluginOption[] | Promise<PluginOptions | false | null | undefined | PluginOption[]>;\n\nexport interface UserConfig {\n /**\n * Project root directory. Can be an absolute path, or a path relative from\n * the location of the config file itself.\n * @default process.cwd()\n */\n root?: string\n mode?: 'single'\n /**\n * plugins means it will run context, buildStart, transform and buildEnd based on order of the plugins array\n * Example of an order(plugin x does not have a buildEnd): [buildStart of plugin x, buildStart of plugin y, transform of plugin x, transform of plugin y, buildEnd of plugin y ]\n * Default: plugins\n */\n lifeCycle?: 'plugins'\n /**\n * Default: fifo\n */\n strategy?: 'fifo' | 'lifo'\n input: {\n schema: string\n }\n output: {\n path: string\n }\n /**\n * Array of kubb plugins to use.\n */\n plugins?: Plugin[]\n\n logLevel?: LogLevel\n}\n\nexport type UserConfigFn = (env: ConfigEnv) => WithPromise<UserConfig>\nexport type UserConfigExport = WithPromise<UserConfig> | UserConfigFn\n\n/**\n * Type helper to make it easier to use kubb.config.ts\n * accepts a direct {@link UserConfig} object, or a function that returns it.\n * The function receives a {@link ConfigEnv} object that exposes two properties:\n */\nexport function defineConfig(config: UserConfigExport): UserConfigExport {\n return config\n}\n","import type { WithPromise } from '../types'\n\nexport const isPromise = <T>(result: WithPromise<T>): result is Promise<T> => {\n return typeof (result as any)?.then === 'function'\n}\n","import { isPromise } from './isPromise'\n\nimport type { WithPromise } from '../types'\n\nexport const createQueue = <TArray extends readonly any[] = readonly any[], TInput = TArray[number], TOuput = void>(\n arr: TArray | undefined,\n fun: (item: TInput) => WithPromise<TOuput>\n) => {\n const promises: Promise<TOuput>[] = []\n\n arr?.forEach((item) => {\n const result = fun(item)\n if (isPromise<TOuput>(result)) {\n promises.push(result)\n } else {\n promises.push(Promise.resolve(result))\n }\n })\n\n return Promise.all(promises)\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\nexport const 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 return path.relative(from, to).replace('../', '').replace('.ts', '').trimEnd()\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\nexport namespace Plugins {\n export interface Context {}\n}\n"]}
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import path2 from 'path';
|
|
2
2
|
import fse2 from 'fs-extra';
|
|
3
|
-
import
|
|
3
|
+
import { format as format$1 } from 'prettier';
|
|
4
4
|
|
|
5
5
|
// src/build.ts
|
|
6
6
|
|
|
@@ -32,10 +32,12 @@ var Emitter = class {
|
|
|
32
32
|
return () => this.listeners.delete(listener);
|
|
33
33
|
};
|
|
34
34
|
on(topic, cb) {
|
|
35
|
-
|
|
35
|
+
const listener = {
|
|
36
36
|
topic,
|
|
37
37
|
cb
|
|
38
|
-
}
|
|
38
|
+
};
|
|
39
|
+
this.listeners.add(listener);
|
|
40
|
+
return () => this.listeners.delete(listener);
|
|
39
41
|
}
|
|
40
42
|
destroy = () => this.listeners.clear();
|
|
41
43
|
};
|
|
@@ -44,19 +46,29 @@ var Emitter = class {
|
|
|
44
46
|
var FileEmitter = class {
|
|
45
47
|
emitter;
|
|
46
48
|
filesByReferenceId = /* @__PURE__ */ new Map();
|
|
47
|
-
constructor(emitter = new Emitter(["delete", "
|
|
49
|
+
constructor(emitter = new Emitter(["delete", "end", "new"])) {
|
|
48
50
|
this.emitter = emitter;
|
|
49
51
|
}
|
|
50
52
|
emitFile(emitedFile) {
|
|
51
53
|
this.assignReferenceId(emitedFile, emitedFile.id);
|
|
52
|
-
|
|
54
|
+
this.emitter.emit("new", emitedFile);
|
|
55
|
+
return new Promise((resolve) => {
|
|
56
|
+
const subscribe = this.emitter.on("delete", (deletedFile) => {
|
|
57
|
+
if (deletedFile?.id === emitedFile.id) {
|
|
58
|
+
resolve(deletedFile);
|
|
59
|
+
return subscribe();
|
|
60
|
+
}
|
|
61
|
+
return void 0;
|
|
62
|
+
});
|
|
63
|
+
});
|
|
53
64
|
}
|
|
54
65
|
delete(fileReferenceId) {
|
|
66
|
+
const deletedFile = this.filesByReferenceId.get(fileReferenceId);
|
|
55
67
|
this.filesByReferenceId.delete(fileReferenceId);
|
|
56
68
|
if (this.filesByReferenceId.size === 0) {
|
|
57
|
-
this.emitter.emit("
|
|
69
|
+
this.emitter.emit("end");
|
|
58
70
|
}
|
|
59
|
-
return this.emitter.emit("delete");
|
|
71
|
+
return this.emitter.emit("delete", deletedFile);
|
|
60
72
|
}
|
|
61
73
|
subscribe(...params) {
|
|
62
74
|
this.emitter.subscribe(...params);
|
|
@@ -70,10 +82,16 @@ var FileEmitter = class {
|
|
|
70
82
|
}
|
|
71
83
|
}
|
|
72
84
|
getEmittedFile = (fileReferenceId) => {
|
|
85
|
+
if (!fileReferenceId) {
|
|
86
|
+
return void 0;
|
|
87
|
+
}
|
|
73
88
|
return this.filesByReferenceId.get(fileReferenceId);
|
|
74
89
|
};
|
|
75
90
|
getFileName = (fileReferenceId) => {
|
|
76
|
-
|
|
91
|
+
if (!fileReferenceId) {
|
|
92
|
+
return void 0;
|
|
93
|
+
}
|
|
94
|
+
return this.filesByReferenceId.get(fileReferenceId)?.source;
|
|
77
95
|
};
|
|
78
96
|
};
|
|
79
97
|
|
|
@@ -126,26 +144,25 @@ function createPlugin(factory) {
|
|
|
126
144
|
};
|
|
127
145
|
}
|
|
128
146
|
var createCorePlugin = createPlugin((options) => {
|
|
129
|
-
const { fileEmitter, resolveId } = options;
|
|
130
|
-
const
|
|
131
|
-
|
|
132
|
-
|
|
147
|
+
const { fileEmitter, resolveId, load } = options;
|
|
148
|
+
const schema = fse2.readFileSync(path2.resolve(options.config.root, options.config.input.schema), "utf-8");
|
|
149
|
+
const api = {
|
|
150
|
+
get config() {
|
|
151
|
+
return options.config;
|
|
152
|
+
},
|
|
153
|
+
get schema() {
|
|
154
|
+
return schema;
|
|
155
|
+
},
|
|
156
|
+
on: fileEmitter.on.bind(fileEmitter),
|
|
157
|
+
getFileName: fileEmitter.getFileName.bind(fileEmitter),
|
|
158
|
+
getEmittedFile: fileEmitter.getEmittedFile.bind(fileEmitter),
|
|
159
|
+
emitFile: fileEmitter.emitFile.bind(fileEmitter),
|
|
160
|
+
resolveId,
|
|
161
|
+
load
|
|
133
162
|
};
|
|
134
|
-
const schema = fse2.readFileSync(path.resolve(config.root, config.input.schema), "utf-8");
|
|
135
163
|
return {
|
|
136
164
|
name: "core",
|
|
137
|
-
api
|
|
138
|
-
get config() {
|
|
139
|
-
return config;
|
|
140
|
-
},
|
|
141
|
-
get schema() {
|
|
142
|
-
return schema;
|
|
143
|
-
},
|
|
144
|
-
getFileName: fileEmitter.getFileName.bind(fileEmitter),
|
|
145
|
-
getEmittedFile: fileEmitter.getEmittedFile.bind(fileEmitter),
|
|
146
|
-
emitFile: fileEmitter.emitFile.bind(fileEmitter),
|
|
147
|
-
resolveId
|
|
148
|
-
}
|
|
165
|
+
api
|
|
149
166
|
};
|
|
150
167
|
});
|
|
151
168
|
|
|
@@ -172,7 +189,7 @@ var PluginDriver = class {
|
|
|
172
189
|
this.config = config;
|
|
173
190
|
this.fileEmitter = new FileEmitter();
|
|
174
191
|
this.emitFile = this.fileEmitter.emitFile.bind(this.fileEmitter);
|
|
175
|
-
const corePlugin = createCorePlugin({ config, fileEmitter: this.fileEmitter, resolveId: this.resolveId });
|
|
192
|
+
const corePlugin = createCorePlugin({ config, fileEmitter: this.fileEmitter, load: this.load, resolveId: this.resolveId });
|
|
176
193
|
this.plugins = [corePlugin, ...config.plugins || []];
|
|
177
194
|
const coreApi = corePlugin.api;
|
|
178
195
|
this.pluginContexts = new Map(
|
|
@@ -198,8 +215,12 @@ var PluginDriver = class {
|
|
|
198
215
|
emitFile(...params) {
|
|
199
216
|
return this.fileEmitter.emitFile(...params);
|
|
200
217
|
}
|
|
201
|
-
resolveId = (source,
|
|
202
|
-
return this.hookFirst("resolveId", [source,
|
|
218
|
+
resolveId = (source, importer, meta) => {
|
|
219
|
+
return this.hookFirst("resolveId", [source, importer, meta]);
|
|
220
|
+
};
|
|
221
|
+
load = async (id) => {
|
|
222
|
+
const result = await this.hookFirst("load", [id]);
|
|
223
|
+
return result;
|
|
203
224
|
};
|
|
204
225
|
hookFirst(hookName, parameters, skipped) {
|
|
205
226
|
let promise = Promise.resolve(null);
|
|
@@ -316,32 +337,39 @@ async function buildImplementation(options, done) {
|
|
|
316
337
|
return;
|
|
317
338
|
}
|
|
318
339
|
pluginDriver.fileEmitter.on("new", async (emittedFile) => {
|
|
319
|
-
if (!emittedFile?.
|
|
340
|
+
if (!emittedFile?.source) {
|
|
320
341
|
return;
|
|
321
342
|
}
|
|
322
|
-
const resolvedId = await pluginDriver.hookFirst("resolveId", [emittedFile.
|
|
323
|
-
const id = resolvedId || emittedFile.
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
343
|
+
const resolvedId = await pluginDriver.hookFirst("resolveId", [emittedFile.source, path2.resolve(emittedFile.source), emittedFile.meta]);
|
|
344
|
+
const id = resolvedId || emittedFile.source;
|
|
345
|
+
let { code } = emittedFile;
|
|
346
|
+
const loadedResult = await pluginDriver.hookFirst("load", [id]);
|
|
347
|
+
if (loadedResult) {
|
|
348
|
+
code = loadedResult;
|
|
349
|
+
}
|
|
350
|
+
if (code) {
|
|
351
|
+
const result = await pluginDriver.hookReduceArg0("transform", [code, id], transformReducer);
|
|
327
352
|
await pluginDriver.hookParallel("writeFile", [result, id]);
|
|
328
353
|
pluginDriver.fileEmitter.delete(emittedFile.id);
|
|
329
354
|
}
|
|
330
355
|
});
|
|
331
356
|
await pluginDriver.hookParallel("buildStart");
|
|
332
357
|
pluginDriver.emitFile({
|
|
333
|
-
id: pluginDriver.api.config.root,
|
|
334
|
-
|
|
358
|
+
id: path2.resolve(pluginDriver.api.config.root, pluginDriver.api.config.input.schema),
|
|
359
|
+
source: pluginDriver.api.config.input.schema,
|
|
335
360
|
name: void 0,
|
|
336
|
-
|
|
337
|
-
type: "asset"
|
|
361
|
+
code: pluginDriver.api.schema
|
|
338
362
|
});
|
|
339
|
-
pluginDriver.fileEmitter.on("
|
|
363
|
+
pluginDriver.fileEmitter.on("end", async () => {
|
|
340
364
|
await pluginDriver.hookParallel("buildEnd");
|
|
341
365
|
done();
|
|
342
366
|
});
|
|
343
367
|
}
|
|
344
|
-
function build(
|
|
368
|
+
function build(userConfig, env) {
|
|
369
|
+
const config = {
|
|
370
|
+
...userConfig,
|
|
371
|
+
root: userConfig.root || process.cwd()
|
|
372
|
+
};
|
|
345
373
|
return new Promise((resolve) => {
|
|
346
374
|
buildImplementation.call(
|
|
347
375
|
this,
|
|
@@ -377,21 +405,22 @@ var createQueue = (arr, fun) => {
|
|
|
377
405
|
});
|
|
378
406
|
return Promise.all(promises);
|
|
379
407
|
};
|
|
380
|
-
|
|
381
|
-
// src/utils/format.ts
|
|
382
|
-
var format = {
|
|
408
|
+
var formatOptions = {
|
|
383
409
|
tabWidth: 2,
|
|
384
410
|
printWidth: 160,
|
|
385
411
|
parser: "typescript",
|
|
386
|
-
singleQuote:
|
|
387
|
-
semi:
|
|
412
|
+
singleQuote: true,
|
|
413
|
+
semi: false,
|
|
388
414
|
bracketSameLine: false,
|
|
389
415
|
endOfLine: "auto"
|
|
390
416
|
};
|
|
417
|
+
var format = (text) => {
|
|
418
|
+
return format$1(text, formatOptions);
|
|
419
|
+
};
|
|
391
420
|
|
|
392
421
|
// src/utils/write.ts
|
|
393
422
|
var write = async (data, path4, options = { format: false }) => {
|
|
394
|
-
const formattedData = options.format ?
|
|
423
|
+
const formattedData = options.format ? format(data) : data;
|
|
395
424
|
try {
|
|
396
425
|
await fse2.stat(path4);
|
|
397
426
|
const oldContent = await fse2.readFile(path4, { encoding: "utf-8" });
|
|
@@ -403,10 +432,16 @@ var write = async (data, path4, options = { format: false }) => {
|
|
|
403
432
|
}
|
|
404
433
|
return fse2.outputFile(path4, formattedData);
|
|
405
434
|
};
|
|
435
|
+
var getRelativePath = (from, to) => {
|
|
436
|
+
if (!from || !to) {
|
|
437
|
+
throw new Error("From and to should be filled in when retrieving the relativePath");
|
|
438
|
+
}
|
|
439
|
+
return path2.relative(from, to).replace("../", "").replace(".ts", "").trimEnd();
|
|
440
|
+
};
|
|
406
441
|
|
|
407
442
|
// src/index.ts
|
|
408
443
|
var src_default = build;
|
|
409
444
|
|
|
410
|
-
export { Emitter, FileEmitter, PluginDriver, build, createPlugin, createPluginCache, createQueue, src_default as default, defineConfig, format, getPluginContext, hooks, isPromise, write };
|
|
445
|
+
export { Emitter, FileEmitter, PluginDriver, build, createPlugin, createPluginCache, createQueue, src_default as default, defineConfig, format, formatOptions, getPluginContext, getRelativePath, hooks, isPromise, write };
|
|
411
446
|
//# sourceMappingURL=out.js.map
|
|
412
447
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/build.ts","../src/utils/PluginDriver.ts","../src/utils/Emitter.ts","../src/utils/FileEmitter.ts","../src/utils/cache.ts","../src/context.ts","../src/plugin.ts","../src/config.ts","../src/utils/isPromise.ts","../src/utils/createQueue.ts","../src/utils/write.ts","../src/utils/format.ts","../src/index.ts"],"names":["path","argument0","fse"],"mappings":";AAIA,OAAOA,WAAU;;;ACGjB,OAAOA,WAAU;;;ACLV,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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;AAC1C;;;ACAO,IAAM,cAAc,CACzB,KACA,QACG;AACH,QAAM,WAA8B,CAAC;AAErC,OAAK,QAAQ,CAAC,SAAS;AACrB,UAAM,SAAS,IAAI,IAAI;AACvB,QAAI,UAAkB,MAAM,GAAG;AAC7B,eAAS,KAAK,MAAM;AAAA,IACtB,OAAO;AACL,eAAS,KAAK,QAAQ,QAAQ,MAAM,CAAC;AAAA,IACvC;AAAA,EACF,CAAC;AAED,SAAO,QAAQ,IAAI,QAAQ;AAC7B;;;ACnBA,OAAOE,UAAS;AAChB,OAAO,cAAc;;;ACAd,IAAM,SAAkB;AAAA,EAC7B,UAAU;AAAA,EACV,YAAY;AAAA,EACZ,QAAQ;AAAA,EACR,aAAa;AAAA,EACb,MAAM;AAAA,EACN,iBAAiB;AAAA,EACjB,WAAW;AACb;;;ADAO,IAAM,QAAQ,OAAO,MAAcF,OAAc,UAAwB,EAAE,QAAQ,MAAM,MAAM;AACpG,QAAM,gBAAgB,QAAQ,SAAS,SAAS,OAAO,MAAM,MAAM,IAAI;AAEvE,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;;;AEdA,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 { PluginContext, TransformResult, ValidationResult } from './types'\nimport type { UserConfig, ConfigEnv } from './config'\nimport type { LogLevel } from './utils/logger'\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: UserConfig\n env: ConfigEnv\n}\n\nasync function buildImplementation(this: BuildContext, options: BuildImplementationOptions, done: (output: BuildOutput) => void) {\n const { config } = options\n if (config.lifeCycle && config.lifeCycle !== 'plugins') {\n throw new Error('Only lifeCycle plugins possible')\n }\n\n if (config.strategy && config.strategy !== 'lifo') {\n throw new Error('Only strategy fifo possible')\n }\n\n const pluginCache = Object.create(null)\n const pluginDriver = new PluginDriver(config, pluginCache, { logger: this.logger })\n\n const validations = await pluginDriver.hookParallel<'validate', ValidationResult>('validate', [pluginDriver.plugins])\n\n const validationsWithMessage = validations.filter(Boolean)\n\n if (validationsWithMessage.some((validation) => typeof validation !== 'boolean')) {\n validationsWithMessage.forEach((validation) => {\n if (validation && typeof validation !== 'boolean' && validation?.message) {\n this.logger?.log(validation.message, 'warn')\n }\n })\n\n return\n }\n\n pluginDriver.fileEmitter.on('new', async (emittedFile) => {\n if (!emittedFile?.fileName) {\n return\n }\n\n const resolvedId = await pluginDriver.hookFirst('resolveId', [emittedFile.fileName, path.resolve(emittedFile.fileName)])\n const id = resolvedId || emittedFile.fileName\n\n await pluginDriver.hookParallel('load', [id])\n\n if (emittedFile.source) {\n const result = await pluginDriver.hookReduceArg0('transform', [emittedFile.source, 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: pluginDriver.api.config.root,\n fileName: pluginDriver.api.config.root,\n name: undefined,\n source: pluginDriver.api.schema,\n type: 'asset',\n })\n\n pluginDriver.fileEmitter.on('done', async (d) => {\n await pluginDriver.hookParallel('buildEnd')\n done()\n })\n}\n\nexport function build(this: BuildContext, config: UserConfig, env: ConfigEnv): Promise<BuildOutput> {\n return new Promise((resolve) => {\n buildImplementation.call(\n this,\n {\n config,\n env,\n },\n resolve\n )\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 path from 'path'\n\nimport { FileEmitter } from './FileEmitter'\n\nimport { getPluginContext } from '../context'\nimport { createCorePlugin } from '../plugin'\n\nimport type { BuildContext } from '../build'\nimport type { SerializablePluginCache } from './cache'\nimport type { Plugin } from '../plugin'\nimport type { UserConfig } from '../config'\nimport type { PluginLifecycleHooks, PluginLifecycle, WithPromise, PluginContext } 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: UserConfig\n\n private readonly sortedPlugins = new Map<PluginLifecycleHooks, Plugin[]>()\n\n constructor(config: UserConfig, 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 = createCorePlugin({ config, fileEmitter: this.fileEmitter, 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 apis() {\n return this.pluginContexts\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 | undefined) => {\n return this.hookFirst('resolveId', [source, path.resolve(source)])\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","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 this.listeners.add({\n topic,\n cb,\n })\n }\n\n destroy: () => void = () => this.listeners.clear()\n}\n","import { Emitter } from './Emitter'\n\nexport interface EmittedFile {\n id: string\n fileName: string | undefined\n name: string | undefined\n source: string | undefined\n type: 'asset'\n}\n\nexport type EmitFile = (emittedFile: EmittedFile) => void\n\ntype Topics = 'new' | 'delete' | 'done'\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', 'done', 'new'])) {\n this.emitter = emitter\n }\n\n emitFile(emitedFile: EmittedFile) {\n // save locally in this class\n this.assignReferenceId(emitedFile, emitedFile.id)\n return this.emitter.emit('new', emitedFile)\n }\n\n delete(fileReferenceId: string) {\n this.filesByReferenceId.delete(fileReferenceId)\n if (this.filesByReferenceId.size === 0) {\n this.emitter.emit('done')\n }\n return this.emitter.emit('delete')\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): EmittedFile | undefined => {\n return this.filesByReferenceId.get(fileReferenceId)\n }\n\n getFileName = (fileReferenceId: string): string | undefined => {\n return this.filesByReferenceId.get(fileReferenceId)?.fileName\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'\nimport fse from 'fs-extra'\n\nimport type { FileEmitter } from './utils'\nimport type { PluginLifecycle, PluginName, Api } from './types'\nimport type { UserConfig } from './config'\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 config: UserConfig\n fileEmitter: FileEmitter\n resolveId: Api['resolveId']\n}\n\n// not exported\ntype CorePluginOptions = PluginOptions<Options, false, Api>\n\nexport const createCorePlugin = createPlugin<CorePluginOptions>((options) => {\n const { fileEmitter, resolveId } = options\n const config = {\n ...options.config,\n root: options.config.root || process.cwd(),\n }\n const schema = fse.readFileSync(path.resolve(config.root, config.input.schema), 'utf-8')\n\n return {\n name: 'core',\n api: {\n get config() {\n return config\n },\n get schema() {\n return schema\n },\n getFileName: fileEmitter.getFileName.bind(fileEmitter),\n getEmittedFile: fileEmitter.getEmittedFile.bind(fileEmitter),\n emitFile: fileEmitter.emitFile.bind(fileEmitter),\n resolveId,\n },\n }\n})\n","import type { WithPromise } from './types'\nimport type { LogLevel } from './utils/logger'\nimport type { Plugin } from './plugin'\n\nexport interface ConfigEnv {\n mode: string\n}\n// TODO revert to this to have multiple options like async, object, ...\n// export type PluginOption = PluginOptions | false | null | undefined | PluginOption[] | Promise<PluginOptions | false | null | undefined | PluginOption[]>;\n\nexport interface UserConfig {\n /**\n * Project root directory. Can be an absolute path, or a path relative from\n * the location of the config file itself.\n * @default process.cwd()\n */\n root?: string\n mode?: 'single'\n /**\n * plugins means it will run context, buildStart, transform and buildEnd based on order of the plugins array\n * Example of an order(plugin x does not have a buildEnd): [buildStart of plugin x, buildStart of plugin y, transform of plugin x, transform of plugin y, buildEnd of plugin y ]\n * Default: plugins\n */\n lifeCycle?: 'plugins'\n /**\n * Default: fifo\n */\n strategy?: 'fifo' | 'lifo'\n input: {\n schema: string\n }\n output: {\n path: string\n }\n /**\n * Array of regenerator plugins to use.\n */\n plugins?: Plugin[]\n\n logLevel?: LogLevel\n}\n\nexport type UserConfigFn = (env: ConfigEnv) => WithPromise<UserConfig>\nexport type UserConfigExport = WithPromise<UserConfig> | UserConfigFn\n\n/**\n * Type helper to make it easier to use regenerator.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","import type { WithPromise } from '../types'\n\nexport const isPromise = <T>(result: WithPromise<T>): result is Promise<T> => {\n return typeof (result as any)?.then === 'function'\n}\n","import { isPromise } from './isPromise'\n\nimport type { WithPromise } from '../types'\n\nexport const createQueue = <TArray extends readonly any[] = readonly any[], TInput = TArray[number], TOuput = void>(\n arr: TArray | undefined,\n fun: (item: TInput) => WithPromise<TOuput>\n) => {\n const promises: Promise<TOuput>[] = []\n\n arr?.forEach((item) => {\n const result = fun(item)\n if (isPromise<TOuput>(result)) {\n promises.push(result)\n } else {\n promises.push(Promise.resolve(result))\n }\n })\n\n return Promise.all(promises)\n}\n","/* eslint-disable consistent-return */\nimport fse from 'fs-extra'\nimport prettier from 'prettier'\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 ? prettier.format(data, format) : 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 type { Options } from 'prettier'\n\nexport const format: Options = {\n tabWidth: 2,\n printWidth: 160,\n parser: 'typescript',\n singleQuote: false,\n semi: true,\n bracketSameLine: false,\n endOfLine: 'auto',\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\nexport namespace Plugins {\n export interface Context {}\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/build.ts","../src/utils/Emitter.ts","../src/utils/FileEmitter.ts","../src/utils/cache.ts","../src/context.ts","../src/plugin.ts","../src/utils/PluginDriver.ts","../src/config.ts","../src/utils/isPromise.ts","../src/utils/createQueue.ts","../src/utils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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 } from './types'\nimport type { UserConfig, ConfigEnv } from './config'\nimport type { LogLevel } from './utils/logger'\nimport type { Plugin } from './plugin'\n\ntype BuildOutput = void\n\n// Same type as ora\ntype Spinner = {\n start: (text?: string) => Spinner\n succeed: (text: string) => Spinner\n stopAndPersist: (options: { text: string }) => Spinner\n render: () => Spinner\n text: string\n info: (text: string) => Spinner\n}\n\nexport type BuildContext = {\n logger?: {\n log: (message: string, logLevel: LogLevel) => void\n spinner?: Spinner\n }\n}\n\nasync function transformReducer(this: PluginContext, previousCode: string, result: TransformResult, _plugin: Plugin) {\n if (result === null) {\n return null\n }\n return result\n}\n\ntype BuildImplementationOptions = {\n config: Api['config']\n env: ConfigEnv\n}\n\nasync function buildImplementation(this: BuildContext, options: BuildImplementationOptions, done: (output: BuildOutput) => void) {\n const { config } = options\n if (config.lifeCycle && config.lifeCycle !== 'plugins') {\n throw new Error('Only lifeCycle plugins possible')\n }\n\n if (config.strategy && config.strategy !== 'lifo') {\n throw new Error('Only strategy fifo possible')\n }\n\n const pluginCache = Object.create(null)\n const pluginDriver = new PluginDriver(config, pluginCache, { logger: this.logger })\n\n const validations = await pluginDriver.hookParallel<'validate', ValidationResult>('validate', [pluginDriver.plugins])\n\n const validationsWithMessage = validations.filter(Boolean)\n\n if (validationsWithMessage.some((validation) => typeof validation !== 'boolean')) {\n validationsWithMessage.forEach((validation) => {\n if (validation && typeof validation !== 'boolean' && validation?.message) {\n this.logger?.log(validation.message, 'warn')\n }\n })\n\n return\n }\n\n pluginDriver.fileEmitter.on('new', async (emittedFile) => {\n if (!emittedFile?.source) {\n return\n }\n\n const resolvedId = await pluginDriver.hookFirst('resolveId', [emittedFile.source, path.resolve(emittedFile.source), emittedFile.meta])\n const id = resolvedId || emittedFile.source\n let { code } = emittedFile\n\n const loadedResult = await pluginDriver.hookFirst('load', [id])\n if (loadedResult) {\n code = loadedResult\n }\n\n if (code) {\n const result = await pluginDriver.hookReduceArg0('transform', [code, id], transformReducer)\n\n await pluginDriver.hookParallel('writeFile', [result, id])\n pluginDriver.fileEmitter.delete(emittedFile.id)\n }\n })\n\n await pluginDriver.hookParallel('buildStart')\n\n pluginDriver.emitFile({\n id: path.resolve(pluginDriver.api.config.root, pluginDriver.api.config.input.schema),\n source: pluginDriver.api.config.input.schema,\n name: undefined,\n code: pluginDriver.api.schema,\n })\n\n pluginDriver.fileEmitter.on('end', async () => {\n await pluginDriver.hookParallel('buildEnd')\n done()\n })\n}\n\nexport function build(this: BuildContext, userConfig: UserConfig, env: ConfigEnv): Promise<BuildOutput> {\n const config: UserConfig = {\n ...userConfig,\n root: userConfig.root || process.cwd(),\n }\n\n return new Promise((resolve) => {\n buildImplementation.call(\n this,\n {\n config,\n env,\n },\n resolve\n )\n })\n}\n","export type Listener<T> = (value?: T) => void\n\nexport class Emitter<TValue = unknown, TTopics = unknown> {\n private readonly listeners: Set<{\n topic?: TTopics\n cb: Listener<TValue>\n }> = new Set()\n\n private readonly topics?: TTopics[]\n\n constructor(topics?: TTopics[]) {\n this.topics = topics\n }\n\n emit(...params: [topic: TTopics, value?: TValue] | [value?: TValue]) {\n const isTopic = (value: any): value is TTopics => !!this.topics?.includes(value)\n\n if (isTopic(params[0])) {\n this.listeners.forEach((listener) => {\n if (listener.topic === params[0]) {\n listener.cb(params[1])\n }\n })\n return\n }\n this.listeners.forEach((listener) => listener.cb(params[0] as TValue))\n }\n\n subscribe: (cb: Listener<TValue>) => () => void = (cb) => {\n const listener = {\n topic: undefined,\n cb,\n }\n this.listeners.add(listener)\n // Unsubscribe\n return () => this.listeners.delete(listener)\n }\n\n on(topic: TTopics, cb: Listener<TValue>) {\n const listener = {\n topic,\n cb,\n }\n this.listeners.add(listener)\n return () => this.listeners.delete(listener)\n }\n\n destroy: () => void = () => this.listeners.clear()\n}\n","import { Emitter } from './Emitter'\n\nexport interface EmittedFile {\n id: string\n // this can be used as a dynamic path, also resolveId will use this as source(first parameter)\n source: string | undefined\n name: string | undefined\n code: string | undefined\n meta?: Record<string, any>\n}\n\nexport type EmitFile = (emittedFile: EmittedFile) => void\n\ntype Topics = 'new' | 'delete' | 'end'\nexport class FileEmitter {\n private readonly emitter: Emitter<EmittedFile, Topics>\n\n private readonly filesByReferenceId: Map<string, EmittedFile> = new Map()\n\n constructor(emitter: Emitter<EmittedFile, Topics> = new Emitter<EmittedFile, Topics>(['delete', 'end', 'new'])) {\n this.emitter = emitter\n }\n\n emitFile(emitedFile: EmittedFile) {\n // save locally in this class\n this.assignReferenceId(emitedFile, emitedFile.id)\n this.emitter.emit('new', emitedFile)\n return new Promise<EmittedFile>((resolve) => {\n const subscribe = this.emitter.on('delete', (deletedFile) => {\n if (deletedFile?.id === emitedFile.id) {\n resolve(deletedFile)\n return subscribe()\n }\n return undefined\n })\n })\n }\n\n delete(fileReferenceId: string) {\n const deletedFile = this.filesByReferenceId.get(fileReferenceId)\n this.filesByReferenceId.delete(fileReferenceId)\n if (this.filesByReferenceId.size === 0) {\n this.emitter.emit('end')\n }\n return this.emitter.emit('delete', deletedFile)\n }\n\n subscribe(...params: Parameters<typeof this.emitter['subscribe']>) {\n this.emitter.subscribe(...params)\n }\n\n on(...params: Parameters<typeof this.emitter['on']>) {\n this.emitter.on(...params)\n }\n\n private assignReferenceId(emittedFile: EmittedFile, fileReferenceId: string | undefined) {\n if (fileReferenceId) {\n this.filesByReferenceId.set(fileReferenceId, emittedFile)\n }\n }\n\n getEmittedFile = (fileReferenceId?: string | null): EmittedFile | undefined => {\n if (!fileReferenceId) {\n return undefined\n }\n return this.filesByReferenceId.get(fileReferenceId)\n }\n\n getFileName = (fileReferenceId: string | null): string | undefined => {\n if (!fileReferenceId) {\n return undefined\n }\n return this.filesByReferenceId.get(fileReferenceId)?.source\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 createCorePlugin = createPlugin<CorePluginOptions>((options) => {\n const { fileEmitter, resolveId, load } = options\n\n const schema = fse.readFileSync(path.resolve(options.config.root, options.config.input.schema), 'utf-8')\n\n const api: Api = {\n get config() {\n return options.config\n },\n get schema() {\n return schema\n },\n on: fileEmitter.on.bind(fileEmitter),\n getFileName: fileEmitter.getFileName.bind(fileEmitter),\n getEmittedFile: fileEmitter.getEmittedFile.bind(fileEmitter),\n emitFile: fileEmitter.emitFile.bind(fileEmitter),\n resolveId,\n load,\n }\n\n return {\n name: 'core',\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 { createCorePlugin } from '../plugin'\n\nimport type { BuildContext } from '../build'\nimport type { SerializablePluginCache } from './cache'\nimport type { Plugin } from '../plugin'\nimport type { PluginLifecycleHooks, PluginLifecycle, WithPromise, 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 = createCorePlugin({ 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 apis() {\n return this.pluginContexts\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 './types'\nimport type { LogLevel } from './utils/logger'\nimport type { Plugin } from './plugin'\n\nexport interface ConfigEnv {\n mode: string\n}\n// TODO revert to this to have multiple options like async, object, ...\n// export type PluginOption = PluginOptions | false | null | undefined | PluginOption[] | Promise<PluginOptions | false | null | undefined | PluginOption[]>;\n\nexport interface UserConfig {\n /**\n * Project root directory. Can be an absolute path, or a path relative from\n * the location of the config file itself.\n * @default process.cwd()\n */\n root?: string\n mode?: 'single'\n /**\n * plugins means it will run context, buildStart, transform and buildEnd based on order of the plugins array\n * Example of an order(plugin x does not have a buildEnd): [buildStart of plugin x, buildStart of plugin y, transform of plugin x, transform of plugin y, buildEnd of plugin y ]\n * Default: plugins\n */\n lifeCycle?: 'plugins'\n /**\n * Default: fifo\n */\n strategy?: 'fifo' | 'lifo'\n input: {\n schema: string\n }\n output: {\n path: string\n }\n /**\n * Array of kubb plugins to use.\n */\n plugins?: Plugin[]\n\n logLevel?: LogLevel\n}\n\nexport type UserConfigFn = (env: ConfigEnv) => WithPromise<UserConfig>\nexport type UserConfigExport = WithPromise<UserConfig> | UserConfigFn\n\n/**\n * Type helper to make it easier to use kubb.config.ts\n * accepts a direct {@link UserConfig} object, or a function that returns it.\n * The function receives a {@link ConfigEnv} object that exposes two properties:\n */\nexport function defineConfig(config: UserConfigExport): UserConfigExport {\n return config\n}\n","import type { WithPromise } from '../types'\n\nexport const isPromise = <T>(result: WithPromise<T>): result is Promise<T> => {\n return typeof (result as any)?.then === 'function'\n}\n","import { isPromise } from './isPromise'\n\nimport type { WithPromise } from '../types'\n\nexport const createQueue = <TArray extends readonly any[] = readonly any[], TInput = TArray[number], TOuput = void>(\n arr: TArray | undefined,\n fun: (item: TInput) => WithPromise<TOuput>\n) => {\n const promises: Promise<TOuput>[] = []\n\n arr?.forEach((item) => {\n const result = fun(item)\n if (isPromise<TOuput>(result)) {\n promises.push(result)\n } else {\n promises.push(Promise.resolve(result))\n }\n })\n\n return Promise.all(promises)\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\nexport const 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 return path.relative(from, to).replace('../', '').replace('.ts', '').trimEnd()\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\nexport namespace Plugins {\n export interface Context {}\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "Generator core",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"change-case": "^4.1.2",
|
|
45
45
|
"fs-extra": "^10.1.0",
|
|
46
|
-
"prettier": "^2.
|
|
46
|
+
"prettier": "^2.8.0",
|
|
47
47
|
"talt": "^2.4.0",
|
|
48
48
|
"typescript": "^4.9.3"
|
|
49
49
|
},
|