keq 2.9.0 → 2.10.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/CHANGELOG.md +7 -0
- package/dist/esm/src/constant.d.ts +2 -0
- package/dist/esm/src/constant.js +2 -0
- package/dist/esm/src/core.d.ts +30 -0
- package/dist/esm/src/core.js +162 -53
- package/dist/esm/src/exception/abort.exception.d.ts +3 -0
- package/dist/esm/src/exception/abort.exception.js +6 -0
- package/dist/esm/src/index.d.ts +1 -0
- package/dist/esm/src/index.js +1 -0
- package/dist/esm/src/is/is-abort-signal.d.ts +1 -0
- package/dist/esm/src/is/is-abort-signal.js +8 -0
- package/dist/esm/src/middlewares/fetch-arguments-middleware.js +5 -1
- package/dist/esm/src/middlewares/retry-middleware.js +20 -3
- package/dist/esm/src/middlewares/timeout-middleware.js +3 -1
- package/dist/esm/src/types/keq-context.d.ts +10 -1
- package/dist/esm/src/types/keq-context.js +1 -1
- package/dist/umd/src/constant.d.ts +2 -0
- package/dist/umd/src/constant.js +3 -1
- package/dist/umd/src/core.d.ts +30 -0
- package/dist/umd/src/core.js +162 -53
- package/dist/umd/src/exception/abort.exception.d.ts +3 -0
- package/dist/umd/src/exception/abort.exception.js +20 -0
- package/dist/umd/src/index.d.ts +1 -0
- package/dist/umd/src/index.js +4 -2
- package/dist/umd/src/is/is-abort-signal.d.ts +1 -0
- package/dist/umd/src/is/is-abort-signal.js +22 -0
- package/dist/umd/src/middlewares/fetch-arguments-middleware.js +4 -0
- package/dist/umd/src/middlewares/retry-middleware.js +21 -4
- package/dist/umd/src/middlewares/timeout-middleware.js +4 -2
- package/dist/umd/src/types/keq-context.d.ts +10 -1
- package/package.json +10 -13
- package/.claude/settings.local.json +0 -26
- package/packages/cache/.turbo/turbo-build.log +0 -29
- package/packages/cache/dist/index.d.mts +0 -354
- package/packages/cache/dist/index.d.mts.map +0 -1
- package/packages/cache/dist/index.d.ts +0 -353
- package/packages/cache/dist/index.d.ts.map +0 -1
- package/packages/cache/dist/index.js +0 -1271
- package/packages/cache/dist/index.js.map +0 -1
- package/packages/cache/dist/index.mjs +0 -1237
- package/packages/cache/dist/index.mjs.map +0 -1
- package/packages/cli/.turbo/turbo-build.log +0 -91
- package/packages/cli/dist/cli.cjs +0 -1364
- package/packages/cli/dist/cli.cjs.map +0 -1
- package/packages/cli/dist/cli.d.cts +0 -1
- package/packages/cli/dist/cli.d.mts +0 -1
- package/packages/cli/dist/cli.mjs +0 -1359
- package/packages/cli/dist/cli.mjs.map +0 -1
- package/packages/cli/dist/compiler-0Kli6UCr.cjs +0 -738
- package/packages/cli/dist/compiler-0Kli6UCr.cjs.map +0 -1
- package/packages/cli/dist/compiler-C3AE8j54.mjs +0 -715
- package/packages/cli/dist/compiler-C3AE8j54.mjs.map +0 -1
- package/packages/cli/dist/index.cjs +0 -20
- package/packages/cli/dist/index.cjs.map +0 -1
- package/packages/cli/dist/index.d.cts +0 -17
- package/packages/cli/dist/index.d.cts.map +0 -1
- package/packages/cli/dist/index.d.mts +0 -17
- package/packages/cli/dist/index.d.mts.map +0 -1
- package/packages/cli/dist/index.mjs +0 -10
- package/packages/cli/dist/index.mjs.map +0 -1
- package/packages/cli/dist/init-BNhD2oCI.mjs +0 -168
- package/packages/cli/dist/init-BNhD2oCI.mjs.map +0 -1
- package/packages/cli/dist/init-DqxLcRSQ.cjs +0 -170
- package/packages/cli/dist/init-DqxLcRSQ.cjs.map +0 -1
- package/packages/cli/dist/logger-D7PyVZo3.cjs +0 -46
- package/packages/cli/dist/logger-D7PyVZo3.cjs.map +0 -1
- package/packages/cli/dist/logger-QLBHySQ3.mjs +0 -12
- package/packages/cli/dist/logger-QLBHySQ3.mjs.map +0 -1
- package/packages/cli/dist/micro-function.translator-BmJZzkKh.cjs +0 -16
- package/packages/cli/dist/micro-function.translator-BmJZzkKh.cjs.map +0 -1
- package/packages/cli/dist/micro-function.translator-CDfkj4Tt.mjs +0 -11
- package/packages/cli/dist/micro-function.translator-CDfkj4Tt.mjs.map +0 -1
- package/packages/cli/dist/mock-command-Bp1LxSls.mjs +0 -350
- package/packages/cli/dist/mock-command-Bp1LxSls.mjs.map +0 -1
- package/packages/cli/dist/mock-command-WZcfy5Iq.cjs +0 -353
- package/packages/cli/dist/mock-command-WZcfy5Iq.cjs.map +0 -1
- package/packages/cli/dist/plugins-CgMhaNZq.cjs +0 -3558
- package/packages/cli/dist/plugins-CgMhaNZq.cjs.map +0 -1
- package/packages/cli/dist/plugins-DCvJ8iHR.mjs +0 -3280
- package/packages/cli/dist/plugins-DCvJ8iHR.mjs.map +0 -1
- package/packages/cli/dist/plugins.cjs +0 -36
- package/packages/cli/dist/plugins.d.cts +0 -2
- package/packages/cli/dist/plugins.d.mts +0 -2
- package/packages/cli/dist/plugins.mjs +0 -2
- package/packages/cli/dist/runtime-config-BWQlPhiB.d.cts +0 -780
- package/packages/cli/dist/runtime-config-BWQlPhiB.d.cts.map +0 -1
- package/packages/cli/dist/runtime-config-CrzK-Ucf.d.mts +0 -780
- package/packages/cli/dist/runtime-config-CrzK-Ucf.d.mts.map +0 -1
- package/packages/cli/dist/translators.cjs +0 -14
- package/packages/cli/dist/translators.cjs.map +0 -1
- package/packages/cli/dist/translators.d.cts +0 -14
- package/packages/cli/dist/translators.d.cts.map +0 -1
- package/packages/cli/dist/translators.d.mts +0 -14
- package/packages/cli/dist/translators.d.mts.map +0 -1
- package/packages/cli/dist/translators.mjs +0 -12
- package/packages/cli/dist/translators.mjs.map +0 -1
- package/packages/cli/node_modules/.bin/eslint +0 -21
- package/packages/cli/node_modules/.bin/jiti +0 -21
- package/packages/cli/node_modules/.bin/js-yaml +0 -21
- package/packages/cli/node_modules/.bin/jsf +0 -21
- package/packages/cli/node_modules/.bin/jsonpath +0 -21
- package/packages/cli/node_modules/.bin/jsonpath-plus +0 -21
- package/packages/cli/node_modules/.bin/semver +0 -21
- package/packages/cli/node_modules/.bin/tsc +0 -21
- package/packages/cli/node_modules/.bin/tsserver +0 -21
- package/packages/exception/.turbo/turbo-build.log +0 -29
- package/packages/exception/dist/index.d.mts +0 -21
- package/packages/exception/dist/index.d.mts.map +0 -1
- package/packages/exception/dist/index.d.ts +0 -21
- package/packages/exception/dist/index.d.ts.map +0 -1
- package/packages/exception/dist/index.js +0 -104
- package/packages/exception/dist/index.js.map +0 -1
- package/packages/exception/dist/index.mjs +0 -99
- package/packages/exception/dist/index.mjs.map +0 -1
- package/packages/headers/.turbo/turbo-build.log +0 -29
- package/packages/headers/dist/index.d.mts +0 -46
- package/packages/headers/dist/index.d.mts.map +0 -1
- package/packages/headers/dist/index.d.ts +0 -46
- package/packages/headers/dist/index.d.ts.map +0 -1
- package/packages/headers/dist/index.js +0 -81
- package/packages/headers/dist/index.js.map +0 -1
- package/packages/headers/dist/index.mjs +0 -75
- package/packages/headers/dist/index.mjs.map +0 -1
- package/packages/keq/.turbo/turbo-build.log +0 -29
- package/packages/keq/dist/index.d.mts +0 -962
- package/packages/keq/dist/index.d.mts.map +0 -1
- package/packages/keq/dist/index.d.ts +0 -962
- package/packages/keq/dist/index.d.ts.map +0 -1
- package/packages/keq/dist/index.js +0 -1876
- package/packages/keq/dist/index.js.map +0 -1
- package/packages/keq/dist/index.mjs +0 -1814
- package/packages/keq/dist/index.mjs.map +0 -1
- package/packages/nestjs/.turbo/turbo-build.log +0 -29
- package/packages/nestjs/dist/index.d.mts +0 -52
- package/packages/nestjs/dist/index.d.mts.map +0 -1
- package/packages/nestjs/dist/index.d.ts +0 -52
- package/packages/nestjs/dist/index.d.ts.map +0 -1
- package/packages/nestjs/dist/index.js +0 -166
- package/packages/nestjs/dist/index.js.map +0 -1
- package/packages/nestjs/dist/index.mjs +0 -136
- package/packages/nestjs/dist/index.mjs.map +0 -1
- package/packages/test/.turbo/turbo-build.log +0 -6
- package/packages/url/.turbo/turbo-build.log +0 -29
- package/packages/url/dist/index.d.mts +0 -9
- package/packages/url/dist/index.d.mts.map +0 -1
- package/packages/url/dist/index.d.ts +0 -9
- package/packages/url/dist/index.d.ts.map +0 -1
- package/packages/url/dist/index.js +0 -43
- package/packages/url/dist/index.js.map +0 -1
- package/packages/url/dist/index.mjs +0 -40
- package/packages/url/dist/index.mjs.map +0 -1
|
@@ -1,715 +0,0 @@
|
|
|
1
|
-
import { B as ModuleDefinition, I as Asset, L as ApiDocumentV3_1, N as Exception, P as OpenapiUtils, c as InitializePlugin } from "./plugins-DCvJ8iHR.mjs";
|
|
2
|
-
import { t as MicroFunctionTranslator } from "./micro-function.translator-CDfkj4Tt.mjs";
|
|
3
|
-
import { Listr, PRESET_TIMER } from "listr2";
|
|
4
|
-
import { AsyncParallelHook, AsyncSeriesBailHook, AsyncSeriesHook, SyncHook } from "tapable";
|
|
5
|
-
import fs from "fs-extra";
|
|
6
|
-
import * as path$2 from "path";
|
|
7
|
-
import path from "path";
|
|
8
|
-
import { cosmiconfig } from "cosmiconfig";
|
|
9
|
-
import * as R from "ramda";
|
|
10
|
-
import picomatch from "picomatch";
|
|
11
|
-
import fs$1 from "node:fs";
|
|
12
|
-
import path$1 from "node:path";
|
|
13
|
-
import { Value } from "@sinclair/typebox/value";
|
|
14
|
-
import { Type } from "@sinclair/typebox";
|
|
15
|
-
import { validate } from "@scalar/openapi-parser";
|
|
16
|
-
//#region src/constants/file-naming-style.ts
|
|
17
|
-
/**
|
|
18
|
-
* File naming style options
|
|
19
|
-
*/
|
|
20
|
-
let FileNamingStyle = /* @__PURE__ */ function(FileNamingStyle) {
|
|
21
|
-
/** Camel case style (e.g., myFileName) */
|
|
22
|
-
FileNamingStyle["camelCase"] = "camelCase";
|
|
23
|
-
/** Capital case style (e.g., My File Name) */
|
|
24
|
-
FileNamingStyle["capitalCase"] = "capitalCase";
|
|
25
|
-
/** Constant case style (e.g., MY_FILE_NAME) */
|
|
26
|
-
FileNamingStyle["constantCase"] = "constantCase";
|
|
27
|
-
/** Dot case style (e.g., my.file.name) */
|
|
28
|
-
FileNamingStyle["dotCase"] = "dotCase";
|
|
29
|
-
/** Header case style (e.g., My-File-Name) */
|
|
30
|
-
FileNamingStyle["headerCase"] = "headerCase";
|
|
31
|
-
/** No case style (e.g., my file name) */
|
|
32
|
-
FileNamingStyle["noCase"] = "noCase";
|
|
33
|
-
/** Param case style (e.g., my-file-name) */
|
|
34
|
-
FileNamingStyle["paramCase"] = "paramCase";
|
|
35
|
-
/** Pascal case style (e.g., MyFileName) */
|
|
36
|
-
FileNamingStyle["pascalCase"] = "pascalCase";
|
|
37
|
-
/** Path case style (e.g., my/file/name) */
|
|
38
|
-
FileNamingStyle["pathCase"] = "pathCase";
|
|
39
|
-
/** Sentence case style (e.g., My file name) */
|
|
40
|
-
FileNamingStyle["sentenceCase"] = "sentenceCase";
|
|
41
|
-
/** Snake case style (e.g., my_file_name) */
|
|
42
|
-
FileNamingStyle["snakeCase"] = "snakeCase";
|
|
43
|
-
/** Kebab case style (e.g., my-file-name) */
|
|
44
|
-
FileNamingStyle["kebabCase"] = "kebabCase";
|
|
45
|
-
return FileNamingStyle;
|
|
46
|
-
}({});
|
|
47
|
-
//#endregion
|
|
48
|
-
//#region src/utils/matcher.ts
|
|
49
|
-
const ALL_HTTP_METHODS = [
|
|
50
|
-
"get",
|
|
51
|
-
"post",
|
|
52
|
-
"put",
|
|
53
|
-
"delete",
|
|
54
|
-
"patch",
|
|
55
|
-
"head",
|
|
56
|
-
"options"
|
|
57
|
-
];
|
|
58
|
-
function deduplicateRules(rules) {
|
|
59
|
-
const sorted = R.sortBy(R.prop("deny"), rules);
|
|
60
|
-
return R.uniqWith((a, b) => a.moduleName === b.moduleName && a.operationMethod === b.operationMethod && a.operationPathname === b.operationPathname, sorted);
|
|
61
|
-
}
|
|
62
|
-
function sortRulesForOutput(rules) {
|
|
63
|
-
return [...rules].sort((a, b) => {
|
|
64
|
-
if (a.moduleName === "*" && b.moduleName !== "*") return -1;
|
|
65
|
-
if (a.moduleName !== "*" && b.moduleName === "*") return 1;
|
|
66
|
-
if (a.moduleName !== b.moduleName) return a.moduleName.localeCompare(b.moduleName);
|
|
67
|
-
if (a.operationMethod === "*" && b.operationMethod !== "*") return -1;
|
|
68
|
-
if (a.operationMethod !== "*" && b.operationMethod === "*") return 1;
|
|
69
|
-
if (a.operationMethod !== b.operationMethod) return a.operationMethod.localeCompare(b.operationMethod);
|
|
70
|
-
return a.operationPathname.localeCompare(b.operationPathname);
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
function renderBlock(section, rules) {
|
|
74
|
-
if (rules.length === 0) return "";
|
|
75
|
-
const maxMethodLen = Math.max(...rules.map((r) => r.operationMethod.toUpperCase().length));
|
|
76
|
-
const lines = [];
|
|
77
|
-
for (const r of rules) {
|
|
78
|
-
if (r.leadingComments && r.leadingComments.length > 0) lines.push(...r.leadingComments);
|
|
79
|
-
const ruleLine = `${r.operationMethod.toUpperCase().padEnd(maxMethodLen + 2)}${r.moduleName}:${r.operationPathname}`;
|
|
80
|
-
lines.push(r.inlineComment ? `${ruleLine} ${r.inlineComment}` : ruleLine);
|
|
81
|
-
}
|
|
82
|
-
return `[${section}]\n${lines.join("\n")}`;
|
|
83
|
-
}
|
|
84
|
-
function compileRule(rule) {
|
|
85
|
-
return {
|
|
86
|
-
rule,
|
|
87
|
-
matchModuleName: picomatch(rule.moduleName),
|
|
88
|
-
matchMethod: picomatch(rule.operationMethod),
|
|
89
|
-
matchPathname: picomatch(rule.operationPathname)
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Matches API operations and modules against `.keqfilter` rules to determine
|
|
94
|
-
* which should be denied (excluded) or allowed during code generation.
|
|
95
|
-
* Supports glob patterns (via picomatch) for module names, HTTP methods, and pathnames.
|
|
96
|
-
*/
|
|
97
|
-
var Matcher = class Matcher {
|
|
98
|
-
compiled;
|
|
99
|
-
preambleComments;
|
|
100
|
-
trailingComments;
|
|
101
|
-
constructor(rules, meta = {}) {
|
|
102
|
-
this.compiled = rules.map(compileRule);
|
|
103
|
-
this.preambleComments = meta.preambleComments ?? [];
|
|
104
|
-
this.trailingComments = meta.trailingComments ?? [];
|
|
105
|
-
}
|
|
106
|
-
get rules() {
|
|
107
|
-
return this.compiled.map((c) => c.rule);
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Parse `.keqfilter` file content into a Matcher instance.
|
|
111
|
-
*
|
|
112
|
-
* File format:
|
|
113
|
-
* ```
|
|
114
|
-
* [deny]
|
|
115
|
-
* GET petStore:/pets
|
|
116
|
-
* * userService:/**
|
|
117
|
-
*
|
|
118
|
-
* [allow]
|
|
119
|
-
* GET petStore:/pets/details
|
|
120
|
-
* ```
|
|
121
|
-
*
|
|
122
|
-
* Line format: `METHOD module:/pathname`
|
|
123
|
-
* - method: HTTP method or `*`, case-insensitive
|
|
124
|
-
* - module:/pathname: module name + `:` + path pattern (glob supported)
|
|
125
|
-
*/
|
|
126
|
-
static parse(content) {
|
|
127
|
-
const normalized = content.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
|
|
128
|
-
const rules = [];
|
|
129
|
-
let currentDeny = null;
|
|
130
|
-
let firstSectionSeen = false;
|
|
131
|
-
let preambleComments = [];
|
|
132
|
-
const pendingComments = [];
|
|
133
|
-
for (const rawLine of normalized.split("\n")) {
|
|
134
|
-
const line = rawLine.replace(/#.*$/, "").trim();
|
|
135
|
-
if (!line) {
|
|
136
|
-
pendingComments.push(rawLine);
|
|
137
|
-
continue;
|
|
138
|
-
}
|
|
139
|
-
if (line === "[deny]") {
|
|
140
|
-
if (!firstSectionSeen) {
|
|
141
|
-
preambleComments = [...pendingComments];
|
|
142
|
-
pendingComments.length = 0;
|
|
143
|
-
firstSectionSeen = true;
|
|
144
|
-
} else while (pendingComments.length > 0 && pendingComments[0].trim() === "") pendingComments.shift();
|
|
145
|
-
currentDeny = true;
|
|
146
|
-
continue;
|
|
147
|
-
}
|
|
148
|
-
if (line === "[allow]") {
|
|
149
|
-
if (!firstSectionSeen) {
|
|
150
|
-
preambleComments = [...pendingComments];
|
|
151
|
-
pendingComments.length = 0;
|
|
152
|
-
firstSectionSeen = true;
|
|
153
|
-
} else while (pendingComments.length > 0 && pendingComments[0].trim() === "") pendingComments.shift();
|
|
154
|
-
currentDeny = false;
|
|
155
|
-
continue;
|
|
156
|
-
}
|
|
157
|
-
if (currentDeny === null) continue;
|
|
158
|
-
const matched = line.match(/^([^\s]+)\s+([^:\s]+):(.*)$/);
|
|
159
|
-
if (!matched) throw new Error(`Invalid filter rule: "${line}"`);
|
|
160
|
-
const [, operationMethod, moduleName, operationPathname] = matched;
|
|
161
|
-
const inlineCommentMatch = rawLine.match(/\s+(#.*)$/);
|
|
162
|
-
const inlineComment = inlineCommentMatch ? inlineCommentMatch[1] : void 0;
|
|
163
|
-
rules.push({
|
|
164
|
-
persist: true,
|
|
165
|
-
deny: currentDeny,
|
|
166
|
-
moduleName,
|
|
167
|
-
operationMethod: operationMethod.toLowerCase(),
|
|
168
|
-
operationPathname,
|
|
169
|
-
leadingComments: pendingComments.length > 0 ? [...pendingComments] : void 0,
|
|
170
|
-
inlineComment
|
|
171
|
-
});
|
|
172
|
-
pendingComments.length = 0;
|
|
173
|
-
}
|
|
174
|
-
const trailingComments = [...pendingComments];
|
|
175
|
-
while (trailingComments.length > 0 && trailingComments[trailingComments.length - 1].trim() === "") trailingComments.pop();
|
|
176
|
-
while (preambleComments.length > 0 && preambleComments[preambleComments.length - 1].trim() === "") preambleComments.pop();
|
|
177
|
-
return new Matcher(deduplicateRules(rules), {
|
|
178
|
-
preambleComments,
|
|
179
|
-
trailingComments
|
|
180
|
-
});
|
|
181
|
-
}
|
|
182
|
-
static async read(filepath) {
|
|
183
|
-
const content = await fs.readFile(filepath, "utf-8");
|
|
184
|
-
return Matcher.parse(content);
|
|
185
|
-
}
|
|
186
|
-
async write(filepath) {
|
|
187
|
-
const persistRules = R.compose(R.reverse, R.uniqWith((a, b) => a.moduleName === b.moduleName && a.operationMethod === b.operationMethod && a.operationPathname === b.operationPathname), R.filter((rule) => rule.persist))(this.rules);
|
|
188
|
-
const denyRules = sortRulesForOutput(persistRules.filter((r) => r.deny));
|
|
189
|
-
const allowRules = sortRulesForOutput(persistRules.filter((r) => !r.deny));
|
|
190
|
-
const blocks = [renderBlock("deny", denyRules), renderBlock("allow", allowRules)].filter(Boolean);
|
|
191
|
-
if (blocks.length === 0) return;
|
|
192
|
-
const blockContent = blocks.join("\n\n");
|
|
193
|
-
const mainContent = this.preambleComments.length > 0 ? `${this.preambleComments.join("\n")}\n${blockContent}` : blockContent;
|
|
194
|
-
const output = this.trailingComments.length > 0 ? `${mainContent}\n\n${this.trailingComments.join("\n")}` : mainContent;
|
|
195
|
-
await fs.writeFile(filepath, output, "utf-8");
|
|
196
|
-
}
|
|
197
|
-
append(rule) {
|
|
198
|
-
this.compiled.unshift(compileRule(rule));
|
|
199
|
-
}
|
|
200
|
-
isOperationDenied(operationDefinition) {
|
|
201
|
-
const moduleName = operationDefinition.module.name;
|
|
202
|
-
const operationMethod = operationDefinition.method.toLowerCase();
|
|
203
|
-
const operationPathname = operationDefinition.pathname;
|
|
204
|
-
for (const { rule, matchModuleName, matchMethod, matchPathname } of this.compiled) {
|
|
205
|
-
if (!matchModuleName(moduleName)) continue;
|
|
206
|
-
if (!matchMethod(operationMethod)) continue;
|
|
207
|
-
if (!matchPathname(operationPathname)) continue;
|
|
208
|
-
return rule.deny;
|
|
209
|
-
}
|
|
210
|
-
return false;
|
|
211
|
-
}
|
|
212
|
-
isModuleDenied(moduleDefinition) {
|
|
213
|
-
const moduleName = moduleDefinition.name;
|
|
214
|
-
for (const { rule, matchModuleName, matchMethod, matchPathname } of this.compiled) {
|
|
215
|
-
if (!matchModuleName(moduleName)) continue;
|
|
216
|
-
if (!rule.deny) return false;
|
|
217
|
-
if (!ALL_HTTP_METHODS.every((m) => matchMethod(m))) continue;
|
|
218
|
-
if (!matchPathname("/a/b/c/d")) continue;
|
|
219
|
-
return true;
|
|
220
|
-
}
|
|
221
|
-
return false;
|
|
222
|
-
}
|
|
223
|
-
};
|
|
224
|
-
//#endregion
|
|
225
|
-
//#region src/compiler/tasks/setup/utils/find-nearest-package-json.ts
|
|
226
|
-
function findNearestPackageJson(startDir = process.cwd()) {
|
|
227
|
-
let dir = startDir;
|
|
228
|
-
while (true) {
|
|
229
|
-
const pkgPath = path$1.join(dir, "package.json");
|
|
230
|
-
if (fs$1.existsSync(pkgPath)) return {
|
|
231
|
-
json: JSON.parse(fs$1.readFileSync(pkgPath, "utf8")),
|
|
232
|
-
path: pkgPath
|
|
233
|
-
};
|
|
234
|
-
const parent = path$1.dirname(dir);
|
|
235
|
-
if (parent === dir) break;
|
|
236
|
-
dir = parent;
|
|
237
|
-
}
|
|
238
|
-
return null;
|
|
239
|
-
}
|
|
240
|
-
//#endregion
|
|
241
|
-
//#region src/compiler/tasks/setup/utils/get-project-module-system.ts
|
|
242
|
-
function getProjectModuleSystem(pkgInfo) {
|
|
243
|
-
if (!pkgInfo?.json) return "cjs";
|
|
244
|
-
const { json } = pkgInfo;
|
|
245
|
-
if (json.type === "module") return "esm";
|
|
246
|
-
return "cjs";
|
|
247
|
-
}
|
|
248
|
-
//#endregion
|
|
249
|
-
//#region src/types/address.ts
|
|
250
|
-
const Address = Type.Object({
|
|
251
|
-
url: Type.String(),
|
|
252
|
-
headers: Type.Optional(Type.Record(Type.String(), Type.String(), { default: {} })),
|
|
253
|
-
encoding: Type.Optional(Type.Union([Type.Literal("utf8"), Type.Literal("ascii")], { default: "utf8" }))
|
|
254
|
-
});
|
|
255
|
-
//#endregion
|
|
256
|
-
//#region src/utils/is-valid-url.ts
|
|
257
|
-
/**
|
|
258
|
-
* 通用 URL 验证正则表达式,支持任意协议
|
|
259
|
-
*
|
|
260
|
-
* 格式: protocol://[user:password@][host][:port][/path][?query][#fragment]
|
|
261
|
-
*
|
|
262
|
-
* 支持的协议示例:
|
|
263
|
-
* - http://, https://
|
|
264
|
-
* - file:// (支持 file:///path 和 file://host/path 两种格式)
|
|
265
|
-
* - ftp://, sftp://
|
|
266
|
-
* - ws://, wss://
|
|
267
|
-
* - 以及任何其他自定义协议
|
|
268
|
-
*/
|
|
269
|
-
const URL_REGEX = /^[a-zA-Z][a-zA-Z0-9+.-]*:\/\/(?:[^\s@]+@)?[^\s/:?#]*(?::\d+)?(?:\/[^\s?#]*)?(?:\?[^\s#]*)?(?:#[^\s]*)?$/;
|
|
270
|
-
/**
|
|
271
|
-
* 验证是否为有效的 URL
|
|
272
|
-
*
|
|
273
|
-
* @param url - 待验证的 URL 字符串
|
|
274
|
-
* @returns 如果是有效的 URL 返回 true,否则返回 false
|
|
275
|
-
*
|
|
276
|
-
* @example
|
|
277
|
-
* ```typescript
|
|
278
|
-
* isValidURL('http://example.com') // true
|
|
279
|
-
* isValidURL('https://example.com:8080/path?query=1#fragment') // true
|
|
280
|
-
* isValidURL('file:///path/to/file.json') // true
|
|
281
|
-
* isValidURL('not a url') // false
|
|
282
|
-
* ```
|
|
283
|
-
*/
|
|
284
|
-
function isValidURL(url) {
|
|
285
|
-
return URL_REGEX.test(url);
|
|
286
|
-
}
|
|
287
|
-
//#endregion
|
|
288
|
-
//#region src/types/runtime-config.ts
|
|
289
|
-
const Modules = Type.Transform(Type.Record(Type.String(), Type.Union([Type.String(), Address]))).Decode((value) => {
|
|
290
|
-
const keys = Object.keys(value);
|
|
291
|
-
for (const key of keys) if (!/^[A-Za-z_][A-Za-z0-9_$]*$/.test(key)) throw new Error(`Module name "${key}" is not valid. It must start with a letter or underscore, and can only contain letters, numbers, and underscores.`);
|
|
292
|
-
const keysGroupByLowerCase = R.groupBy(R.toLower, keys);
|
|
293
|
-
for (const groupKey in keysGroupByLowerCase) {
|
|
294
|
-
const keys = keysGroupByLowerCase[groupKey] || [];
|
|
295
|
-
if (keys.length > 1) throw new Error(`Module names ${keys.map((name) => `"${name}"`).join(", ")} are case-insensitively duplicated.`);
|
|
296
|
-
}
|
|
297
|
-
for (const key in value) {
|
|
298
|
-
const url = typeof value[key] === "string" ? value[key] : value[key].url;
|
|
299
|
-
if (isValidURL(url)) continue;
|
|
300
|
-
throw new Error(`The ${JSON.stringify(url)} of module "${key}" is not a valid URL.`);
|
|
301
|
-
}
|
|
302
|
-
return R.map((item) => typeof item !== "string" ? item : {
|
|
303
|
-
url: item,
|
|
304
|
-
headers: {},
|
|
305
|
-
encoding: "utf8"
|
|
306
|
-
}, value);
|
|
307
|
-
}).Encode((value) => value);
|
|
308
|
-
const RawConfig = Type.Object({
|
|
309
|
-
/**
|
|
310
|
-
* Output directory for generated files
|
|
311
|
-
*/
|
|
312
|
-
outdir: Type.String({ default: `${process.cwd()}/api` }),
|
|
313
|
-
/**
|
|
314
|
-
* Rendering options that directly control code generation output
|
|
315
|
-
*/
|
|
316
|
-
rendering: Type.Object({
|
|
317
|
-
/**
|
|
318
|
-
* Whether to generate ES Module code
|
|
319
|
-
*
|
|
320
|
-
* If not specified, the module system will be inferred from the nearest package.json "type" field
|
|
321
|
-
* or defaults to "cjs" if no package.json is found.
|
|
322
|
-
*/
|
|
323
|
-
esm: Type.Optional(Type.Boolean({ default: false })),
|
|
324
|
-
/**
|
|
325
|
-
* File naming style for generated files
|
|
326
|
-
*/
|
|
327
|
-
fileNamingStyle: Type.Enum(FileNamingStyle, { default: "snakeCase" }),
|
|
328
|
-
/**
|
|
329
|
-
* Controls how `additionalProperties: true` (or undefined) is rendered in generated TypeScript types.
|
|
330
|
-
*
|
|
331
|
-
* - `'unknown'` (default): renders as `unknown`, which is stricter and type-safe
|
|
332
|
-
* - `'any'`: renders as `any`, which is more permissive
|
|
333
|
-
*/
|
|
334
|
-
additionalPropertiesType: Type.Optional(Type.Union([Type.Literal("unknown"), Type.Literal("any")], { default: "unknown" })),
|
|
335
|
-
/**
|
|
336
|
-
* Whether to generate entrypoint (index) files that re-export all generated modules.
|
|
337
|
-
*
|
|
338
|
-
* Disable this to avoid merge conflicts in multi-branch collaborative development,
|
|
339
|
-
* as auto-generated index files change frequently.
|
|
340
|
-
*/
|
|
341
|
-
entrypoint: Type.Optional(Type.Boolean({ default: false }))
|
|
342
|
-
}, { default: {} }),
|
|
343
|
-
/**
|
|
344
|
-
* OpenAPI/Swagger document sources
|
|
345
|
-
*
|
|
346
|
-
* A map of module names to their document URLs or Address objects.
|
|
347
|
-
* The module name must be a valid JavaScript identifier.
|
|
348
|
-
*/
|
|
349
|
-
modules: Modules,
|
|
350
|
-
/**
|
|
351
|
-
* Enable debug mode to output detailed logs during compilation
|
|
352
|
-
*/
|
|
353
|
-
debug: Type.Optional(Type.Boolean({ default: false })),
|
|
354
|
-
/**
|
|
355
|
-
* Whether to tolerate wrong openapi/swagger structure
|
|
356
|
-
*/
|
|
357
|
-
tolerant: Type.Optional(Type.Boolean({ default: false })),
|
|
358
|
-
/**
|
|
359
|
-
* Translators to transform generated code
|
|
360
|
-
*
|
|
361
|
-
* Used to customize the code generation process for different frameworks or patterns.
|
|
362
|
-
* Can be a single translator or an array of translators.
|
|
363
|
-
*/
|
|
364
|
-
translators: Type.Optional(Type.Transform(Type.Union([Type.Unsafe(Type.Any()), Type.Array(Type.Unsafe(Type.Any()))], { default: [] })).Decode((value) => {
|
|
365
|
-
if (value === void 0) return [];
|
|
366
|
-
if (Array.isArray(value)) return value;
|
|
367
|
-
return [value];
|
|
368
|
-
}).Encode((value) => value)),
|
|
369
|
-
/**
|
|
370
|
-
* Plugins to extend code generation functionality
|
|
371
|
-
*
|
|
372
|
-
* An array of plugin instances that can hook into various stages of the compilation process,
|
|
373
|
-
* such as code transformation, formatting, linting, or custom file generation.
|
|
374
|
-
*/
|
|
375
|
-
plugins: Type.Optional(Type.Array(Type.Unsafe(Type.Any()), { default: [] }))
|
|
376
|
-
});
|
|
377
|
-
//#endregion
|
|
378
|
-
//#region src/compiler/tasks/setup/utils/parse-runtime-config.ts
|
|
379
|
-
function parseRuntimeConfig(data) {
|
|
380
|
-
try {
|
|
381
|
-
const record = typeof data === "object" && data !== null ? data : void 0;
|
|
382
|
-
const originalPlugins = record && "plugins" in record ? record.plugins : void 0;
|
|
383
|
-
const originalTranslators = record && "translators" in record ? record.translators : void 0;
|
|
384
|
-
const sanitized = record ? { ...record } : data;
|
|
385
|
-
if (record) {
|
|
386
|
-
delete sanitized.plugins;
|
|
387
|
-
delete sanitized.translators;
|
|
388
|
-
}
|
|
389
|
-
const parsed = Value.Parse(RawConfig, sanitized);
|
|
390
|
-
if (originalPlugins !== void 0) parsed.plugins = originalPlugins;
|
|
391
|
-
if (originalTranslators !== void 0) parsed.translators = originalTranslators;
|
|
392
|
-
return parsed;
|
|
393
|
-
} catch (error) {
|
|
394
|
-
if (error instanceof Error) error.message = `Invalid Config: ${error.message}`;
|
|
395
|
-
throw error;
|
|
396
|
-
}
|
|
397
|
-
}
|
|
398
|
-
//#endregion
|
|
399
|
-
//#region src/compiler/tasks/setup/index.ts
|
|
400
|
-
const explore = cosmiconfig("keq");
|
|
401
|
-
function main$3(compiler, options) {
|
|
402
|
-
return { task: async (context, task) => {
|
|
403
|
-
const result = options?.config ? await explore.load(options.config) : await explore.search();
|
|
404
|
-
if (!result || "isEmpty" in result && result.isEmpty) throw new Error("Cannot find config file.");
|
|
405
|
-
const rc = parseRuntimeConfig(result.config);
|
|
406
|
-
if (options?.debug) {
|
|
407
|
-
await fs.ensureDir(".keq");
|
|
408
|
-
rc.debug = true;
|
|
409
|
-
}
|
|
410
|
-
rc.tolerant = Boolean(rc.tolerant || options?.tolerant);
|
|
411
|
-
if (!rc.translators || !rc.translators.length) rc.translators = [new MicroFunctionTranslator()];
|
|
412
|
-
const packageJsonInfo = findNearestPackageJson();
|
|
413
|
-
if (packageJsonInfo) {
|
|
414
|
-
const moduleSystem = getProjectModuleSystem(packageJsonInfo);
|
|
415
|
-
rc.rendering.esm = moduleSystem === "esm";
|
|
416
|
-
}
|
|
417
|
-
context.rc = rc;
|
|
418
|
-
let matcher = new Matcher([]);
|
|
419
|
-
if (options.filter !== false && result.filepath) {
|
|
420
|
-
const filterFilepath = path.resolve(path.dirname(result.filepath), ".keqfilter");
|
|
421
|
-
if (await fs.exists(filterFilepath)) matcher = await Matcher.read(filterFilepath);
|
|
422
|
-
}
|
|
423
|
-
const filterRules = options.filter === false ? [] : options.filter?.rules || [];
|
|
424
|
-
for (const rule of filterRules) matcher.append({
|
|
425
|
-
persist: !!rule.persist,
|
|
426
|
-
deny: rule.deny,
|
|
427
|
-
moduleName: rule.moduleName,
|
|
428
|
-
operationMethod: rule.operationMethod,
|
|
429
|
-
operationPathname: rule.operationPathname
|
|
430
|
-
});
|
|
431
|
-
context.matcher = matcher;
|
|
432
|
-
await compiler.hooks.setup.promise(task);
|
|
433
|
-
} };
|
|
434
|
-
}
|
|
435
|
-
function createSetupTask(compiler, options) {
|
|
436
|
-
return {
|
|
437
|
-
title: "Setup",
|
|
438
|
-
enabled: options?.enabled,
|
|
439
|
-
skip: options?.skip,
|
|
440
|
-
task: (context, task) => task.newListr([main$3(compiler, options), { task: (context, task) => compiler.hooks.afterSetup.promise(task) }], { concurrent: false })
|
|
441
|
-
};
|
|
442
|
-
}
|
|
443
|
-
//#endregion
|
|
444
|
-
//#region src/compiler/tasks/download/validate-spec.ts
|
|
445
|
-
async function validateSpec(spec, options) {
|
|
446
|
-
const { valid, errors } = await validate(spec);
|
|
447
|
-
if (valid) return { valid: true };
|
|
448
|
-
const errorLines = errors?.map((e) => {
|
|
449
|
-
const path = e.path;
|
|
450
|
-
if (path) {
|
|
451
|
-
const readablePath = path.replace(/~1/g, "/").replace(/~0/g, "~");
|
|
452
|
-
return ` - ${e.message}\n at: ${readablePath}`;
|
|
453
|
-
}
|
|
454
|
-
return ` - ${e.message}`;
|
|
455
|
-
}).join("\n");
|
|
456
|
-
let message = `${options.moduleDefinition.name} module openapi/swagger file does not conform to the openapi specifications or have grammatical errors, which may cause unexpected errors: \n${errorLines}`;
|
|
457
|
-
if (errors?.some((e) => e.message?.includes("Error-ModelName"))) message += "\n\n [Hint] \"Error-ModelName\" in $ref indicates that SpringDoc failed to resolve a Java class. Check that the referenced class (e.g. cn.dotfashion.soa.api.vo.Response) is on the classpath and properly annotated with @Schema.";
|
|
458
|
-
if (errors?.some((e) => e.message?.includes("Property extensions is not expected to be here"))) message += "\n\n [Hint] \"Property extensions is not expected to be here\" is typically caused by SpringDoc/Swagger wrapping x- extensions in an \"extensions\" object. Add SpringdocCompatPlugin to your config plugins to fix this automatically.";
|
|
459
|
-
if (options.tolerant) return {
|
|
460
|
-
valid: false,
|
|
461
|
-
warning: message
|
|
462
|
-
};
|
|
463
|
-
throw new Exception(options.moduleDefinition, message);
|
|
464
|
-
}
|
|
465
|
-
//#endregion
|
|
466
|
-
//#region src/compiler/tasks/download/index.ts
|
|
467
|
-
function main$2(compiler, options) {
|
|
468
|
-
return { task: (context, task) => {
|
|
469
|
-
if (!context.rc || !context.matcher) throw new Error("Please run setup task first.");
|
|
470
|
-
const rc = context.rc;
|
|
471
|
-
const matcher = context.matcher;
|
|
472
|
-
context.documents = [];
|
|
473
|
-
return task.newListr(Object.entries(rc.modules).map(([moduleName, address]) => new ModuleDefinition(moduleName, address)).map((moduleDefinition) => ({
|
|
474
|
-
title: moduleDefinition.name,
|
|
475
|
-
task: async (ctx, task) => {
|
|
476
|
-
if (options?.skipFilteredModules && matcher.isModuleDenied(moduleDefinition)) {
|
|
477
|
-
task.skip(`(${moduleDefinition.name}) is filtered`);
|
|
478
|
-
return;
|
|
479
|
-
}
|
|
480
|
-
task.output = `Downloaded from ${moduleDefinition.address.url}`;
|
|
481
|
-
const content = await compiler.hooks.download.promise(moduleDefinition.address, moduleDefinition, task);
|
|
482
|
-
if (!content) throw new Exception(moduleDefinition, `Cannot download document from ${moduleDefinition.address.url}`);
|
|
483
|
-
const spec = JSON.parse(content);
|
|
484
|
-
await compiler.hooks.beforeValidate.promise(spec, moduleDefinition);
|
|
485
|
-
const result = await validateSpec(spec, {
|
|
486
|
-
moduleDefinition,
|
|
487
|
-
tolerant: !!compiler.options.tolerant
|
|
488
|
-
});
|
|
489
|
-
if (result.warning) task.output = result.warning;
|
|
490
|
-
OpenapiUtils.dereferenceOperation(spec);
|
|
491
|
-
const document = new ApiDocumentV3_1(spec, moduleDefinition);
|
|
492
|
-
ctx.documents?.push(document);
|
|
493
|
-
}
|
|
494
|
-
})), {
|
|
495
|
-
concurrent: true,
|
|
496
|
-
exitOnError: !compiler.options.tolerant,
|
|
497
|
-
collectErrors: compiler.options.tolerant ? "minimal" : false,
|
|
498
|
-
rendererOptions: {
|
|
499
|
-
collapseSubtasks: false,
|
|
500
|
-
suffixSkips: true,
|
|
501
|
-
timer: PRESET_TIMER
|
|
502
|
-
}
|
|
503
|
-
});
|
|
504
|
-
} };
|
|
505
|
-
}
|
|
506
|
-
function createDownloadTask(compiler, options) {
|
|
507
|
-
return {
|
|
508
|
-
title: "Download",
|
|
509
|
-
enabled: options?.enabled,
|
|
510
|
-
skip: options?.skip,
|
|
511
|
-
task: (_, task) => task.newListr([main$2(compiler, options), { task: (context, task) => compiler.hooks.afterDownload.promise(task) }], { concurrent: false })
|
|
512
|
-
};
|
|
513
|
-
}
|
|
514
|
-
//#endregion
|
|
515
|
-
//#region src/compiler/tasks/persist/index.ts
|
|
516
|
-
function createPersistArtifactTask() {
|
|
517
|
-
return {
|
|
518
|
-
title: "Write files",
|
|
519
|
-
task: async (context, task) => {
|
|
520
|
-
if (!context.rc) throw new Error("Please run setup task first.");
|
|
521
|
-
if (!context.artifacts || context.artifacts.length === 0) {
|
|
522
|
-
task.skip("No compiled artifacts to persist.");
|
|
523
|
-
return;
|
|
524
|
-
}
|
|
525
|
-
const rc = context.rc;
|
|
526
|
-
const artifacts = context.artifacts;
|
|
527
|
-
const total = artifacts.length;
|
|
528
|
-
let completed = 0;
|
|
529
|
-
context.assets = await Promise.all(artifacts.map(async (artifact) => {
|
|
530
|
-
const realpath = `./${path$2.join(rc.outdir, artifact.filepath)}`;
|
|
531
|
-
await fs.ensureFile(realpath);
|
|
532
|
-
await fs.writeFile(realpath, artifact.renderer());
|
|
533
|
-
completed += 1;
|
|
534
|
-
task.output = `Persisted ${completed}/${total} files`;
|
|
535
|
-
return new Asset(path$2.resolve(realpath));
|
|
536
|
-
}));
|
|
537
|
-
}
|
|
538
|
-
};
|
|
539
|
-
}
|
|
540
|
-
function createPersistFilterTask() {
|
|
541
|
-
return {
|
|
542
|
-
title: "Update .keqfilter",
|
|
543
|
-
task: async (context, task) => {
|
|
544
|
-
if (!context.matcher) throw new Error("Please run setup task first.");
|
|
545
|
-
await context.matcher.write(".keqfilter");
|
|
546
|
-
}
|
|
547
|
-
};
|
|
548
|
-
}
|
|
549
|
-
function main$1() {
|
|
550
|
-
return { task: (context, task) => task.newListr([createPersistArtifactTask(), createPersistFilterTask()], {
|
|
551
|
-
concurrent: true,
|
|
552
|
-
rendererOptions: { collapseSubtasks: true }
|
|
553
|
-
}) };
|
|
554
|
-
}
|
|
555
|
-
function createPersistTask(compiler, options) {
|
|
556
|
-
return {
|
|
557
|
-
title: "Persist",
|
|
558
|
-
enabled: options?.enabled,
|
|
559
|
-
skip: options?.skip,
|
|
560
|
-
task: (context, task) => task.newListr([
|
|
561
|
-
{ task: (context, task) => compiler.hooks.beforePersist.promise(task) },
|
|
562
|
-
main$1(),
|
|
563
|
-
{ task: (context, task) => compiler.hooks.afterPersist.promise(task) }
|
|
564
|
-
], { concurrent: false })
|
|
565
|
-
};
|
|
566
|
-
}
|
|
567
|
-
//#endregion
|
|
568
|
-
//#region src/compiler/tasks/compile/index.ts
|
|
569
|
-
function main(compiler) {
|
|
570
|
-
return { task: async (context, task) => {
|
|
571
|
-
if (!context.rc) throw new Error("Please run setup task first.");
|
|
572
|
-
if (!context.documents) throw new Error("Please run shaking task first.");
|
|
573
|
-
context.artifacts = [];
|
|
574
|
-
await compiler.hooks.compile.promise(task);
|
|
575
|
-
} };
|
|
576
|
-
}
|
|
577
|
-
function createCompileTask(compiler, options) {
|
|
578
|
-
return {
|
|
579
|
-
title: "Compile",
|
|
580
|
-
enabled: options?.enabled,
|
|
581
|
-
skip: options?.skip,
|
|
582
|
-
task: (context, task) => task.newListr([
|
|
583
|
-
{ task: (context, task) => compiler.hooks.beforeCompile.promise(task) },
|
|
584
|
-
main(compiler),
|
|
585
|
-
{ task: (context, task) => compiler.hooks.afterCompile.promise(task) }
|
|
586
|
-
], { concurrent: false })
|
|
587
|
-
};
|
|
588
|
-
}
|
|
589
|
-
//#endregion
|
|
590
|
-
//#region src/compiler/intercepter/print-information.ts
|
|
591
|
-
function proxyTaskWrapper(pluginName, task) {
|
|
592
|
-
return new Proxy(task, { set(target, prop, value) {
|
|
593
|
-
if (prop !== "output") return Reflect.set(target, prop, value);
|
|
594
|
-
target.output = `[Plugin: ${pluginName}] ${value}`;
|
|
595
|
-
return true;
|
|
596
|
-
} });
|
|
597
|
-
}
|
|
598
|
-
function printInformation(taskIndex) {
|
|
599
|
-
return { register: (tap) => {
|
|
600
|
-
const fn = tap.fn;
|
|
601
|
-
if (tap.type === "promise") tap.fn = (...args) => {
|
|
602
|
-
const task = args[taskIndex];
|
|
603
|
-
const proxyTask = proxyTaskWrapper(tap.name, task);
|
|
604
|
-
args[taskIndex] = proxyTask;
|
|
605
|
-
proxyTask.output = "Processing...";
|
|
606
|
-
return fn(...args);
|
|
607
|
-
};
|
|
608
|
-
if (tap.type === "sync") tap.fn = (...args) => {
|
|
609
|
-
const task = args[taskIndex];
|
|
610
|
-
const proxyTask = proxyTaskWrapper(tap.name, task);
|
|
611
|
-
args[taskIndex] = proxyTask;
|
|
612
|
-
proxyTask.output = "Processing...";
|
|
613
|
-
return fn(...args);
|
|
614
|
-
};
|
|
615
|
-
if (tap.type === "async") tap.fn = (...args) => {
|
|
616
|
-
const task = args[taskIndex];
|
|
617
|
-
const proxyTask = proxyTaskWrapper(tap.name, task);
|
|
618
|
-
args[taskIndex] = proxyTask;
|
|
619
|
-
proxyTask.output = "Processing...";
|
|
620
|
-
return fn(...args);
|
|
621
|
-
};
|
|
622
|
-
return tap;
|
|
623
|
-
} };
|
|
624
|
-
}
|
|
625
|
-
//#endregion
|
|
626
|
-
//#region src/compiler/intercepter/perfect-error-message.ts
|
|
627
|
-
function perfectErrorMessage() {
|
|
628
|
-
return { register: (tap) => {
|
|
629
|
-
const fn = tap.fn;
|
|
630
|
-
function prefix(err) {
|
|
631
|
-
if (err instanceof Error) err.message = `[Plugin: ${tap.name}] ${err.message}`;
|
|
632
|
-
}
|
|
633
|
-
if (tap.type === "promise") tap.fn = async (...args) => {
|
|
634
|
-
try {
|
|
635
|
-
return await fn(...args);
|
|
636
|
-
} catch (err) {
|
|
637
|
-
prefix(err);
|
|
638
|
-
throw err;
|
|
639
|
-
}
|
|
640
|
-
};
|
|
641
|
-
if (tap.type === "sync") tap.fn = (...args) => {
|
|
642
|
-
try {
|
|
643
|
-
return fn(...args);
|
|
644
|
-
} catch (err) {
|
|
645
|
-
prefix(err);
|
|
646
|
-
throw err;
|
|
647
|
-
}
|
|
648
|
-
};
|
|
649
|
-
if (tap.type === "async") tap.fn = (...args) => {
|
|
650
|
-
const callback = R.last(args);
|
|
651
|
-
return fn(...R.init(args), (err, result) => {
|
|
652
|
-
prefix(err);
|
|
653
|
-
return callback(err, result);
|
|
654
|
-
});
|
|
655
|
-
};
|
|
656
|
-
return tap;
|
|
657
|
-
} };
|
|
658
|
-
}
|
|
659
|
-
//#endregion
|
|
660
|
-
//#region src/compiler/compiler.ts
|
|
661
|
-
var Compiler = class {
|
|
662
|
-
context = {};
|
|
663
|
-
hooks = {
|
|
664
|
-
setup: new AsyncParallelHook(["task"]),
|
|
665
|
-
afterSetup: new AsyncSeriesHook(["task"]),
|
|
666
|
-
beforeDownload: new AsyncSeriesHook(["task"]),
|
|
667
|
-
download: new AsyncSeriesBailHook([
|
|
668
|
-
"address",
|
|
669
|
-
"moduleDefinition",
|
|
670
|
-
"task"
|
|
671
|
-
]),
|
|
672
|
-
beforeValidate: new AsyncSeriesHook(["spec", "moduleDefinition"]),
|
|
673
|
-
afterDownload: new AsyncSeriesHook(["task"]),
|
|
674
|
-
beforeCompile: new AsyncSeriesHook(["task"]),
|
|
675
|
-
compile: new AsyncParallelHook(["task"]),
|
|
676
|
-
afterCompile: new AsyncSeriesHook(["task"]),
|
|
677
|
-
beforePersist: new AsyncSeriesHook(["task"]),
|
|
678
|
-
persist: new AsyncParallelHook(["task"]),
|
|
679
|
-
afterPersist: new AsyncSeriesHook(["task"]),
|
|
680
|
-
done: new SyncHook()
|
|
681
|
-
};
|
|
682
|
-
constructor(options) {
|
|
683
|
-
this.options = options;
|
|
684
|
-
for (const hook of Object.values(this.hooks)) hook.intercept(perfectErrorMessage());
|
|
685
|
-
this.hooks.afterSetup.intercept(printInformation(0));
|
|
686
|
-
this.hooks.afterPersist.intercept(printInformation(0));
|
|
687
|
-
new InitializePlugin({
|
|
688
|
-
build: options.build,
|
|
689
|
-
fresh: options.fresh,
|
|
690
|
-
interactive: options.interactive
|
|
691
|
-
}).apply(this);
|
|
692
|
-
}
|
|
693
|
-
async run() {
|
|
694
|
-
const options = this.options;
|
|
695
|
-
await new Listr([
|
|
696
|
-
createSetupTask(this, options),
|
|
697
|
-
createDownloadTask(this, { skipFilteredModules: !options.interactive }),
|
|
698
|
-
createCompileTask(this, { enabled: !!options.build }),
|
|
699
|
-
createPersistTask(this, { enabled: !!options.persist })
|
|
700
|
-
], {
|
|
701
|
-
concurrent: false,
|
|
702
|
-
renderer: options.silent ? "silent" : "default",
|
|
703
|
-
rendererOptions: {
|
|
704
|
-
suffixSkips: true,
|
|
705
|
-
collapseSubtasks: false,
|
|
706
|
-
collapseErrors: false
|
|
707
|
-
}
|
|
708
|
-
}).run(this.context);
|
|
709
|
-
await this.hooks.done.promise();
|
|
710
|
-
}
|
|
711
|
-
};
|
|
712
|
-
//#endregion
|
|
713
|
-
export { Matcher as n, FileNamingStyle as r, Compiler as t };
|
|
714
|
-
|
|
715
|
-
//# sourceMappingURL=compiler-C3AE8j54.mjs.map
|