@kubb/core 0.8.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/LICENSE +21 -0
- package/README.md +1 -0
- package/dist/ast/index.d.ts +19 -0
- package/dist/ast/index.js +54 -0
- package/dist/ast/index.js.map +1 -0
- package/dist/ast/index.mjs +52 -0
- package/dist/ast/index.mjs.map +1 -0
- package/dist/index.d.ts +218 -0
- package/dist/index.js +429 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +412 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +72 -0
- package/schemas/config.json +68 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Stijn Van Hulle
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# Demo
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
|
|
3
|
+
declare const generateStringTemplate: <TParams = Record<string, string | ts.Node | undefined>>(templateStrings: string | TemplateStringsArray, ...placeholders: (string | ts.Node)[]) => (params?: TParams | undefined) => string | undefined;
|
|
4
|
+
declare const logDemoTemplate: () => Promise<void>;
|
|
5
|
+
|
|
6
|
+
declare const print: (elements: ts.Node[], fileName?: string) => string;
|
|
7
|
+
|
|
8
|
+
declare const index_generateStringTemplate: typeof generateStringTemplate;
|
|
9
|
+
declare const index_logDemoTemplate: typeof logDemoTemplate;
|
|
10
|
+
declare const index_print: typeof print;
|
|
11
|
+
declare namespace index {
|
|
12
|
+
export {
|
|
13
|
+
index_generateStringTemplate as generateStringTemplate,
|
|
14
|
+
index_logDemoTemplate as logDemoTemplate,
|
|
15
|
+
index_print as print,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export { index as typescript };
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var ts = require('typescript');
|
|
4
|
+
var talt = require('talt');
|
|
5
|
+
|
|
6
|
+
var __defProp = Object.defineProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
// src/ast/typescript/index.ts
|
|
13
|
+
var typescript_exports = {};
|
|
14
|
+
__export(typescript_exports, {
|
|
15
|
+
generateStringTemplate: () => generateStringTemplate,
|
|
16
|
+
logDemoTemplate: () => logDemoTemplate,
|
|
17
|
+
print: () => print
|
|
18
|
+
});
|
|
19
|
+
var print = (elements, fileName = "print.ts") => {
|
|
20
|
+
const nodes = ts.factory.createNodeArray(elements);
|
|
21
|
+
const sourceFile = ts.createSourceFile(fileName, "", ts.ScriptTarget.ESNext, true, ts.ScriptKind.TS);
|
|
22
|
+
const printer = ts.createPrinter();
|
|
23
|
+
const outputFile = printer.printList(ts.ListFormat.MultiLine, nodes, sourceFile);
|
|
24
|
+
return outputFile;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
// src/ast/typescript/generate.ts
|
|
28
|
+
var generateStringTemplate = (templateStrings, ...placeholders) => {
|
|
29
|
+
const compiledFn = talt.template.statement(templateStrings, ...placeholders);
|
|
30
|
+
return (params) => {
|
|
31
|
+
if (!params) {
|
|
32
|
+
return void 0;
|
|
33
|
+
}
|
|
34
|
+
const idPlaceholders = {};
|
|
35
|
+
Object.keys(params).forEach((key) => {
|
|
36
|
+
idPlaceholders[key] = typeof params[key] ? ts.factory.createStringLiteral(params[key]) : params[key];
|
|
37
|
+
});
|
|
38
|
+
const generatedAst = compiledFn(idPlaceholders);
|
|
39
|
+
return print([generatedAst]);
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
var logDemoTemplate = async () => {
|
|
43
|
+
const typeNode = talt.template.typeNode("{ readonly test: string }")();
|
|
44
|
+
talt.template.typeNode`
|
|
45
|
+
{
|
|
46
|
+
readonly test: string;
|
|
47
|
+
}
|
|
48
|
+
`();
|
|
49
|
+
console.log(print([typeNode]));
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
exports.typescript = typescript_exports;
|
|
53
|
+
//# sourceMappingURL=out.js.map
|
|
54
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +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,UAAqB,WAAW,eAAe;AACnE,QAAM,QAAQ,GAAG,QAAQ,gBAAgB,QAAQ;AACjD,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,OAAO,UAAU;AAE/E,SAAO;AACT;;;ADFO,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[], fileName = 'print.ts') => {\n const nodes = ts.factory.createNodeArray(elements)\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, nodes, sourceFile)\n\n return outputFile\n}\n"]}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
import { template } from 'talt';
|
|
3
|
+
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
// src/ast/typescript/index.ts
|
|
11
|
+
var typescript_exports = {};
|
|
12
|
+
__export(typescript_exports, {
|
|
13
|
+
generateStringTemplate: () => generateStringTemplate,
|
|
14
|
+
logDemoTemplate: () => logDemoTemplate,
|
|
15
|
+
print: () => print
|
|
16
|
+
});
|
|
17
|
+
var print = (elements, fileName = "print.ts") => {
|
|
18
|
+
const nodes = ts.factory.createNodeArray(elements);
|
|
19
|
+
const sourceFile = ts.createSourceFile(fileName, "", ts.ScriptTarget.ESNext, true, ts.ScriptKind.TS);
|
|
20
|
+
const printer = ts.createPrinter();
|
|
21
|
+
const outputFile = printer.printList(ts.ListFormat.MultiLine, nodes, sourceFile);
|
|
22
|
+
return outputFile;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
// src/ast/typescript/generate.ts
|
|
26
|
+
var generateStringTemplate = (templateStrings, ...placeholders) => {
|
|
27
|
+
const compiledFn = template.statement(templateStrings, ...placeholders);
|
|
28
|
+
return (params) => {
|
|
29
|
+
if (!params) {
|
|
30
|
+
return void 0;
|
|
31
|
+
}
|
|
32
|
+
const idPlaceholders = {};
|
|
33
|
+
Object.keys(params).forEach((key) => {
|
|
34
|
+
idPlaceholders[key] = typeof params[key] ? ts.factory.createStringLiteral(params[key]) : params[key];
|
|
35
|
+
});
|
|
36
|
+
const generatedAst = compiledFn(idPlaceholders);
|
|
37
|
+
return print([generatedAst]);
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
var logDemoTemplate = async () => {
|
|
41
|
+
const typeNode = template.typeNode("{ readonly test: string }")();
|
|
42
|
+
template.typeNode`
|
|
43
|
+
{
|
|
44
|
+
readonly test: string;
|
|
45
|
+
}
|
|
46
|
+
`();
|
|
47
|
+
console.log(print([typeNode]));
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export { typescript_exports as typescript };
|
|
51
|
+
//# sourceMappingURL=out.js.map
|
|
52
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +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,UAAqB,WAAW,eAAe;AACnE,QAAM,QAAQ,GAAG,QAAQ,gBAAgB,QAAQ;AACjD,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,OAAO,UAAU;AAE/E,SAAO;AACT;;;ADFO,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[], fileName = 'print.ts') => {\n const nodes = ts.factory.createNodeArray(elements)\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, nodes, sourceFile)\n\n return outputFile\n}\n"]}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import { Options } from 'prettier';
|
|
2
|
+
|
|
3
|
+
interface SerializablePluginCache {
|
|
4
|
+
[key: string]: [number, any];
|
|
5
|
+
}
|
|
6
|
+
interface Cache<TCache = any> {
|
|
7
|
+
delete(id: string): boolean;
|
|
8
|
+
get<T = TCache>(id: string): T;
|
|
9
|
+
has(id: string): boolean;
|
|
10
|
+
set<T = TCache>(id: string, value: T): void;
|
|
11
|
+
}
|
|
12
|
+
declare function createPluginCache(cache: SerializablePluginCache): Cache;
|
|
13
|
+
|
|
14
|
+
declare const isPromise: <T>(result: WithPromise<T>) => result is Promise<T>;
|
|
15
|
+
|
|
16
|
+
declare const createQueue: <TArray extends readonly any[] = readonly any[], TInput = TArray[number], TOuput = void>(arr: TArray | undefined, fun: (item: TInput) => WithPromise<TOuput>) => Promise<Awaited<TOuput>[]>;
|
|
17
|
+
|
|
18
|
+
type LogType = 'error' | 'warn' | 'info';
|
|
19
|
+
type LogLevel = LogType | 'silent';
|
|
20
|
+
|
|
21
|
+
type WriteOptions = {
|
|
22
|
+
format: boolean;
|
|
23
|
+
};
|
|
24
|
+
declare const write: (data: string, path: string, options?: WriteOptions) => Promise<void>;
|
|
25
|
+
|
|
26
|
+
type Listener<T> = (value?: T) => void;
|
|
27
|
+
declare class Emitter<TValue = unknown, TTopics = unknown> {
|
|
28
|
+
private readonly listeners;
|
|
29
|
+
private readonly topics?;
|
|
30
|
+
constructor(topics?: TTopics[]);
|
|
31
|
+
emit(...params: [topic: TTopics, value?: TValue] | [value?: TValue]): void;
|
|
32
|
+
subscribe: (cb: Listener<TValue>) => () => void;
|
|
33
|
+
on(topic: TTopics, cb: Listener<TValue>): void;
|
|
34
|
+
destroy: () => void;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
interface EmittedFile {
|
|
38
|
+
id: string;
|
|
39
|
+
fileName: string | undefined;
|
|
40
|
+
name: string | undefined;
|
|
41
|
+
source: string | undefined;
|
|
42
|
+
type: 'asset';
|
|
43
|
+
}
|
|
44
|
+
type EmitFile = (emittedFile: EmittedFile) => void;
|
|
45
|
+
type Topics = 'new' | 'delete' | 'done';
|
|
46
|
+
declare class FileEmitter {
|
|
47
|
+
private readonly emitter;
|
|
48
|
+
private readonly filesByReferenceId;
|
|
49
|
+
constructor(emitter?: Emitter<EmittedFile, Topics>);
|
|
50
|
+
emitFile(emitedFile: EmittedFile): void;
|
|
51
|
+
delete(fileReferenceId: string): void;
|
|
52
|
+
subscribe(...params: Parameters<typeof this$1.emitter['subscribe']>): void;
|
|
53
|
+
on(...params: Parameters<typeof this$1.emitter['on']>): void;
|
|
54
|
+
private assignReferenceId;
|
|
55
|
+
getEmittedFile: (fileReferenceId: string) => EmittedFile | undefined;
|
|
56
|
+
getFileName: (fileReferenceId: string) => string | undefined;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Get the type of the first argument in a function.
|
|
61
|
+
* @example Arg0<(a: string, b: number) => void> -> string
|
|
62
|
+
*/
|
|
63
|
+
type Argument0<H extends keyof PluginLifecycle> = Parameters<PluginLifecycle[H]>[0];
|
|
64
|
+
declare const hooks: [keyof PluginLifecycle];
|
|
65
|
+
declare class PluginDriver {
|
|
66
|
+
private readonly pluginContexts;
|
|
67
|
+
plugins: Plugin[];
|
|
68
|
+
readonly fileEmitter: FileEmitter;
|
|
69
|
+
private readonly logger?;
|
|
70
|
+
private readonly config;
|
|
71
|
+
private readonly sortedPlugins;
|
|
72
|
+
constructor(config: UserConfig, pluginCache: Record<string, SerializablePluginCache> | undefined, options: {
|
|
73
|
+
logger: BuildContext['logger'];
|
|
74
|
+
});
|
|
75
|
+
get apis(): ReadonlyMap<Plugin<PluginOptions<unknown, false, any>>, PluginContext>;
|
|
76
|
+
get api(): PluginContext;
|
|
77
|
+
emitFile(...params: Parameters<FileEmitter['emitFile']>): void;
|
|
78
|
+
resolveId: (source: string, _importer: string | undefined) => Promise<string | null | undefined>;
|
|
79
|
+
hookFirst<H extends PluginLifecycleHooks>(hookName: H, parameters: Parameters<PluginLifecycle[H]>, skipped?: ReadonlySet<Plugin> | null): Promise<ReturnType<PluginLifecycle[H]> | null>;
|
|
80
|
+
hookParallel<H extends PluginLifecycleHooks, TOuput = void>(hookName: H, parameters?: Parameters<PluginLifecycle[H]> | undefined): Promise<Awaited<TOuput>[]>;
|
|
81
|
+
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>>;
|
|
82
|
+
hookSeq<H extends PluginLifecycleHooks>(hookName: H, parameters?: Parameters<PluginLifecycle[H]>): Promise<void>;
|
|
83
|
+
private getSortedPlugins;
|
|
84
|
+
/**
|
|
85
|
+
* Run an async plugin hook and return the result.
|
|
86
|
+
* @param hookName Name of the plugin hook. Must be either in `PluginHooks` or `OutputPluginValueHooks`.
|
|
87
|
+
* @param args Arguments passed to the plugin hook.
|
|
88
|
+
* @param plugin The actual pluginObject to run.
|
|
89
|
+
*/
|
|
90
|
+
private runHook;
|
|
91
|
+
/**
|
|
92
|
+
* Run a sync plugin hook and return the result.
|
|
93
|
+
* @param hookName Name of the plugin hook. Must be in `PluginHooks`.
|
|
94
|
+
* @param args Arguments passed to the plugin hook.
|
|
95
|
+
* @param plugin The acutal plugin
|
|
96
|
+
* @param replaceContext When passed, the plugin context can be overridden.
|
|
97
|
+
*/
|
|
98
|
+
private runHookSync;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
declare const format: Options;
|
|
102
|
+
|
|
103
|
+
type PluginOptions<UserOptions = unknown, Nested extends boolean = false, Api = any> = {
|
|
104
|
+
userOptions: UserOptions;
|
|
105
|
+
nested: Nested;
|
|
106
|
+
api: Api;
|
|
107
|
+
};
|
|
108
|
+
type Plugin<TOptions extends PluginOptions = PluginOptions> = {
|
|
109
|
+
name: PluginName | Omit<string, PluginName>;
|
|
110
|
+
cacheKey?: string;
|
|
111
|
+
api?: TOptions['api'];
|
|
112
|
+
} & Partial<PluginLifecycle>;
|
|
113
|
+
type PluginFactory<TOptions extends PluginOptions = PluginOptions> = (options: TOptions['userOptions']) => TOptions['nested'] extends true ? Array<Plugin<TOptions>> : Plugin<TOptions>;
|
|
114
|
+
declare function createPlugin<TOptions extends PluginOptions = PluginOptions>(factory: PluginFactory<TOptions>): (userOptions: TOptions['userOptions']) => TOptions["nested"] extends true ? Plugin<TOptions>[] : Plugin<TOptions>;
|
|
115
|
+
|
|
116
|
+
type PluginName = 'string';
|
|
117
|
+
type PluginLifecycle = {
|
|
118
|
+
validate: (this: PluginContext, plugins: Plugin[]) => WithPromise<ValidationResult>;
|
|
119
|
+
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 | void>;
|
|
122
|
+
transform: (this: PluginContext, code: string, id: string) => WithPromise<TransformResult>;
|
|
123
|
+
writeFile: (this: PluginContext, code: string | undefined, id: string) => WithPromise<void>;
|
|
124
|
+
buildEnd: (this: PluginContext) => WithPromise<void>;
|
|
125
|
+
};
|
|
126
|
+
type PluginLifecycleHooks = keyof PluginLifecycle;
|
|
127
|
+
type Api = {
|
|
128
|
+
config: UserConfig & {
|
|
129
|
+
root: string;
|
|
130
|
+
};
|
|
131
|
+
schema: Schema;
|
|
132
|
+
emitFile: FileEmitter['emitFile'];
|
|
133
|
+
resolveId: (source: string, importer?: string) => WithPromise<string | null | undefined>;
|
|
134
|
+
getFileName: FileEmitter['getFileName'];
|
|
135
|
+
getEmittedFile: FileEmitter['getEmittedFile'];
|
|
136
|
+
};
|
|
137
|
+
type PluginContext = Api & {
|
|
138
|
+
cache: Cache;
|
|
139
|
+
};
|
|
140
|
+
type ValidationResult = true | {
|
|
141
|
+
message: string;
|
|
142
|
+
};
|
|
143
|
+
type TransformResult = string | null;
|
|
144
|
+
type WithPromise<T> = Promise<T> | T;
|
|
145
|
+
type Id = string;
|
|
146
|
+
type Schema = string;
|
|
147
|
+
|
|
148
|
+
interface ConfigEnv {
|
|
149
|
+
mode: string;
|
|
150
|
+
}
|
|
151
|
+
interface UserConfig {
|
|
152
|
+
/**
|
|
153
|
+
* Project root directory. Can be an absolute path, or a path relative from
|
|
154
|
+
* the location of the config file itself.
|
|
155
|
+
* @default process.cwd()
|
|
156
|
+
*/
|
|
157
|
+
root?: string;
|
|
158
|
+
mode?: 'single';
|
|
159
|
+
/**
|
|
160
|
+
* plugins means it will run context, buildStart, transform and buildEnd based on order of the plugins array
|
|
161
|
+
* 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 ]
|
|
162
|
+
* Default: plugins
|
|
163
|
+
*/
|
|
164
|
+
lifeCycle?: 'plugins';
|
|
165
|
+
/**
|
|
166
|
+
* Default: fifo
|
|
167
|
+
*/
|
|
168
|
+
strategy?: 'fifo' | 'lifo';
|
|
169
|
+
input: {
|
|
170
|
+
schema: string;
|
|
171
|
+
};
|
|
172
|
+
output: {
|
|
173
|
+
path: string;
|
|
174
|
+
};
|
|
175
|
+
/**
|
|
176
|
+
* Array of regenerator plugins to use.
|
|
177
|
+
*/
|
|
178
|
+
plugins?: Plugin[];
|
|
179
|
+
logLevel?: LogLevel;
|
|
180
|
+
}
|
|
181
|
+
type UserConfigFn = (env: ConfigEnv) => WithPromise<UserConfig>;
|
|
182
|
+
type UserConfigExport = WithPromise<UserConfig> | UserConfigFn;
|
|
183
|
+
/**
|
|
184
|
+
* Type helper to make it easier to use regenerator.config.ts
|
|
185
|
+
* accepts a direct {@link UserConfig} object, or a function that returns it.
|
|
186
|
+
* The function receives a {@link ConfigEnv} object that exposes two properties:
|
|
187
|
+
*/
|
|
188
|
+
declare function defineConfig(config: UserConfigExport): UserConfigExport;
|
|
189
|
+
|
|
190
|
+
type BuildOutput = void;
|
|
191
|
+
type Spinner = {
|
|
192
|
+
start: (text?: string) => Spinner;
|
|
193
|
+
succeed: (text: string) => Spinner;
|
|
194
|
+
stopAndPersist: (options: {
|
|
195
|
+
text: string;
|
|
196
|
+
}) => Spinner;
|
|
197
|
+
render: () => Spinner;
|
|
198
|
+
text: string;
|
|
199
|
+
info: (text: string) => Spinner;
|
|
200
|
+
};
|
|
201
|
+
type BuildContext = {
|
|
202
|
+
logger?: {
|
|
203
|
+
log: (message: string, logLevel: LogLevel) => void;
|
|
204
|
+
spinner?: Spinner;
|
|
205
|
+
};
|
|
206
|
+
};
|
|
207
|
+
declare function build(this: BuildContext, config: UserConfig, env: ConfigEnv): Promise<BuildOutput>;
|
|
208
|
+
|
|
209
|
+
declare function getPluginContext(this: PluginDriver, plugin: Plugin, pluginCache: Record<string, SerializablePluginCache> | void): {
|
|
210
|
+
cache: Cache<any>;
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
declare namespace Plugins {
|
|
214
|
+
interface Context {
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
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 };
|