@kubb/core 2.0.0-alpha.1 → 2.0.0-alpha.11
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/README.md +1 -1
- package/dist/index.cjs +138 -111
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +266 -223
- package/dist/index.d.ts +266 -223
- package/dist/index.js +138 -109
- package/dist/index.js.map +1 -1
- package/dist/utils.cjs +25 -13
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +7 -3
- package/dist/utils.d.ts +7 -3
- package/dist/utils.js +25 -13
- package/dist/utils.js.map +1 -1
- package/package.json +12 -10
- package/src/BarrelManager.ts +123 -0
- package/src/FileManager.ts +524 -0
- package/src/Generator.ts +34 -0
- package/src/PackageManager.ts +178 -0
- package/src/PluginManager.ts +629 -0
- package/src/PromiseManager.ts +51 -0
- package/src/SchemaGenerator.ts +8 -0
- package/src/build.ts +207 -0
- package/src/config.ts +22 -0
- package/src/errors.ts +12 -0
- package/src/index.ts +28 -0
- package/src/plugin.ts +80 -0
- package/src/types.ts +353 -0
- package/src/utils/EventEmitter.ts +24 -0
- package/src/utils/FunctionParams.ts +85 -0
- package/src/utils/Queue.ts +110 -0
- package/src/utils/TreeNode.ts +122 -0
- package/src/utils/URLPath.ts +133 -0
- package/src/utils/cache.ts +35 -0
- package/src/utils/clean.ts +5 -0
- package/src/utils/executeStrategies.ts +83 -0
- package/src/utils/index.ts +19 -0
- package/src/utils/logger.ts +76 -0
- package/src/utils/promise.ts +13 -0
- package/src/utils/randomColour.ts +39 -0
- package/src/utils/read.ts +68 -0
- package/src/utils/renderTemplate.ts +31 -0
- package/src/utils/throttle.ts +30 -0
- package/src/utils/timeout.ts +7 -0
- package/src/utils/transformers/combineCodes.ts +3 -0
- package/src/utils/transformers/createJSDocBlockText.ts +15 -0
- package/src/utils/transformers/escape.ts +31 -0
- package/src/utils/transformers/indent.ts +3 -0
- package/src/utils/transformers/index.ts +22 -0
- package/src/utils/transformers/nameSorter.ts +9 -0
- package/src/utils/transformers/searchAndReplace.ts +25 -0
- package/src/utils/transformers/transformReservedWord.ts +97 -0
- package/src/utils/transformers/trim.ts +3 -0
- package/src/utils/uniqueName.ts +20 -0
- package/src/utils/write.ts +63 -0
package/dist/index.js
CHANGED
|
@@ -85,7 +85,7 @@ function createLogger({ logLevel, name, spinner }) {
|
|
|
85
85
|
}
|
|
86
86
|
};
|
|
87
87
|
const info = (message) => {
|
|
88
|
-
if (message && spinner) {
|
|
88
|
+
if (message && spinner && logLevel !== LogLevel.silent) {
|
|
89
89
|
spinner.info(message);
|
|
90
90
|
logs.push(message);
|
|
91
91
|
}
|
|
@@ -198,10 +198,13 @@ var URLPath = class {
|
|
|
198
198
|
params: this.getParams()
|
|
199
199
|
};
|
|
200
200
|
if (stringify) {
|
|
201
|
-
if (type
|
|
202
|
-
|
|
201
|
+
if (type === "template") {
|
|
202
|
+
return JSON.stringify(object).replaceAll("'", "").replaceAll(`"`, "");
|
|
203
|
+
}
|
|
204
|
+
if (object.params) {
|
|
205
|
+
return `{ url: '${object.url}', params: ${JSON.stringify(object.params).replaceAll("'", "").replaceAll(`"`, "")} }`;
|
|
203
206
|
}
|
|
204
|
-
return
|
|
207
|
+
return `{ url: '${object.url}' }`;
|
|
205
208
|
}
|
|
206
209
|
return object;
|
|
207
210
|
}
|
|
@@ -270,14 +273,19 @@ function combineCodes(codes) {
|
|
|
270
273
|
}
|
|
271
274
|
|
|
272
275
|
// src/utils/transformers/createJSDocBlockText.ts
|
|
273
|
-
function createJSDocBlockText({ comments }) {
|
|
276
|
+
function createJSDocBlockText({ comments, newLine }) {
|
|
274
277
|
const filteredComments = comments.filter(Boolean);
|
|
275
278
|
if (!filteredComments.length) {
|
|
276
279
|
return "";
|
|
277
280
|
}
|
|
278
|
-
|
|
281
|
+
const source = `/**
|
|
279
282
|
* ${filteredComments.join("\n * ")}
|
|
280
283
|
*/`;
|
|
284
|
+
if (newLine) {
|
|
285
|
+
return `${source}
|
|
286
|
+
`;
|
|
287
|
+
}
|
|
288
|
+
return source;
|
|
281
289
|
}
|
|
282
290
|
|
|
283
291
|
// src/utils/transformers/escape.ts
|
|
@@ -431,6 +439,11 @@ function transformReservedWord(word) {
|
|
|
431
439
|
return word;
|
|
432
440
|
}
|
|
433
441
|
|
|
442
|
+
// src/utils/transformers/trim.ts
|
|
443
|
+
function trim(text) {
|
|
444
|
+
return text.replaceAll(/\n/g, "").trim();
|
|
445
|
+
}
|
|
446
|
+
|
|
434
447
|
// src/utils/transformers/index.ts
|
|
435
448
|
var transformers = {
|
|
436
449
|
combineCodes,
|
|
@@ -440,6 +453,7 @@ var transformers = {
|
|
|
440
453
|
transformReservedWord,
|
|
441
454
|
nameSorter,
|
|
442
455
|
searchAndReplace,
|
|
456
|
+
trim,
|
|
443
457
|
JSDoc: {
|
|
444
458
|
createJSDocBlockText
|
|
445
459
|
}
|
|
@@ -621,12 +635,12 @@ var BarrelManager = class {
|
|
|
621
635
|
if (currentTree.children?.length > 1) {
|
|
622
636
|
const indexPath = path.resolve(currentTree.data.path, "index.ts");
|
|
623
637
|
const exports = currentTree.children.filter(Boolean).map((file) => {
|
|
624
|
-
const importPath = file.data.type === "directory" ? `./${file.data.name}` : `./${file.data.name.replace(/\.[^.]*$/, "")}`;
|
|
625
|
-
if (importPath.includes("index") &&
|
|
638
|
+
const importPath = file.data.type === "directory" ? `./${file.data.name}/index` : `./${file.data.name.replace(/\.[^.]*$/, "")}`;
|
|
639
|
+
if (importPath.includes("index") && file.data.type === "file") {
|
|
626
640
|
return void 0;
|
|
627
641
|
}
|
|
628
642
|
return {
|
|
629
|
-
path: includeExt ?
|
|
643
|
+
path: includeExt ? `${importPath}${extName}` : importPath,
|
|
630
644
|
isTypeOnly
|
|
631
645
|
};
|
|
632
646
|
}).filter(Boolean);
|
|
@@ -641,10 +655,10 @@ var BarrelManager = class {
|
|
|
641
655
|
} else {
|
|
642
656
|
currentTree.children?.forEach((child) => {
|
|
643
657
|
const indexPath = path.resolve(currentTree.data.path, "index.ts");
|
|
644
|
-
const importPath = child.data.type === "directory" ? `./${child.data.name}` : `./${child.data.name.replace(/\.[^.]*$/, "")}`;
|
|
658
|
+
const importPath = child.data.type === "directory" ? `./${child.data.name}/index` : `./${child.data.name.replace(/\.[^.]*$/, "")}`;
|
|
645
659
|
const exports = [
|
|
646
660
|
{
|
|
647
|
-
path: includeExt ?
|
|
661
|
+
path: includeExt ? `${importPath}${extName}` : importPath,
|
|
648
662
|
isTypeOnly
|
|
649
663
|
}
|
|
650
664
|
];
|
|
@@ -671,6 +685,9 @@ var BarrelManager = class {
|
|
|
671
685
|
_options = new WeakMap();
|
|
672
686
|
|
|
673
687
|
// src/FileManager.ts
|
|
688
|
+
var KubbFile;
|
|
689
|
+
((KubbFile2) => {
|
|
690
|
+
})(KubbFile || (KubbFile = {}));
|
|
674
691
|
var _cache, _task, _isWriting, _timeout, _queue, _validate, validate_fn, _add, add_fn, _addOrAppend, addOrAppend_fn;
|
|
675
692
|
var _FileManager = class _FileManager {
|
|
676
693
|
constructor(options) {
|
|
@@ -1061,44 +1078,6 @@ function setUniqueName(originalName, data) {
|
|
|
1061
1078
|
}
|
|
1062
1079
|
|
|
1063
1080
|
// src/errors.ts
|
|
1064
|
-
var PluginError = class extends Error {
|
|
1065
|
-
constructor(message, options) {
|
|
1066
|
-
super(message, { cause: options.cause });
|
|
1067
|
-
this.name = "PluginError";
|
|
1068
|
-
this.cause = options.cause;
|
|
1069
|
-
this.pluginManager = options.pluginManager;
|
|
1070
|
-
}
|
|
1071
|
-
};
|
|
1072
|
-
var ParallelPluginError = class extends Error {
|
|
1073
|
-
constructor(message, options) {
|
|
1074
|
-
super(message, { cause: options.cause });
|
|
1075
|
-
this.errors = [];
|
|
1076
|
-
this.name = "ParallelPluginError";
|
|
1077
|
-
this.errors = options.errors;
|
|
1078
|
-
this.pluginManager = options.pluginManager;
|
|
1079
|
-
}
|
|
1080
|
-
findError(searchError) {
|
|
1081
|
-
if (!searchError) {
|
|
1082
|
-
return void 0;
|
|
1083
|
-
}
|
|
1084
|
-
return this.errors.find((error) => {
|
|
1085
|
-
if (error.cause) {
|
|
1086
|
-
if (error.cause.name == searchError.name) {
|
|
1087
|
-
return true;
|
|
1088
|
-
}
|
|
1089
|
-
return !!this.findError(error.cause);
|
|
1090
|
-
}
|
|
1091
|
-
return error.name === searchError.name;
|
|
1092
|
-
})?.cause;
|
|
1093
|
-
}
|
|
1094
|
-
};
|
|
1095
|
-
var SummaryError = class extends Error {
|
|
1096
|
-
constructor(message, options) {
|
|
1097
|
-
super(message, { cause: options.cause });
|
|
1098
|
-
this.name = "SummaryError";
|
|
1099
|
-
this.summary = options.summary || [];
|
|
1100
|
-
}
|
|
1101
|
-
};
|
|
1102
1081
|
var Warning = class extends Error {
|
|
1103
1082
|
constructor(message, options) {
|
|
1104
1083
|
super(message, { cause: options?.cause });
|
|
@@ -1188,21 +1167,37 @@ var definePlugin = createPlugin((options) => {
|
|
|
1188
1167
|
|
|
1189
1168
|
// src/utils/executeStrategies.ts
|
|
1190
1169
|
function hookSeq(promises) {
|
|
1191
|
-
return promises.reduce(
|
|
1170
|
+
return promises.filter(Boolean).reduce(
|
|
1192
1171
|
(promise, func) => {
|
|
1193
|
-
if (
|
|
1172
|
+
if (typeof func !== "function") {
|
|
1194
1173
|
throw new Error("HookSeq needs a function that returns a promise `() => Promise<unknown>`");
|
|
1195
1174
|
}
|
|
1196
|
-
return promise.then((
|
|
1197
|
-
const calledFunc = func();
|
|
1175
|
+
return promise.then((state) => {
|
|
1176
|
+
const calledFunc = func(state);
|
|
1198
1177
|
if (calledFunc) {
|
|
1199
|
-
return calledFunc.then(Array.prototype.concat.bind(
|
|
1178
|
+
return calledFunc.then(Array.prototype.concat.bind(state));
|
|
1200
1179
|
}
|
|
1201
1180
|
});
|
|
1202
1181
|
},
|
|
1203
1182
|
Promise.resolve([])
|
|
1204
1183
|
);
|
|
1205
1184
|
}
|
|
1185
|
+
function hookFirst(promises, nullCheck = (state) => state !== null) {
|
|
1186
|
+
let promise = Promise.resolve(null);
|
|
1187
|
+
for (const func of promises.filter(Boolean)) {
|
|
1188
|
+
promise = promise.then((state) => {
|
|
1189
|
+
if (nullCheck(state)) {
|
|
1190
|
+
return state;
|
|
1191
|
+
}
|
|
1192
|
+
const calledFunc = func(state);
|
|
1193
|
+
return calledFunc;
|
|
1194
|
+
});
|
|
1195
|
+
}
|
|
1196
|
+
return promise;
|
|
1197
|
+
}
|
|
1198
|
+
function hookParallel(promises) {
|
|
1199
|
+
return Promise.allSettled(promises.filter(Boolean).map((promise) => promise()));
|
|
1200
|
+
}
|
|
1206
1201
|
|
|
1207
1202
|
// src/PromiseManager.ts
|
|
1208
1203
|
var _options2;
|
|
@@ -1216,6 +1211,12 @@ var PromiseManager = class {
|
|
|
1216
1211
|
if (strategy === "seq") {
|
|
1217
1212
|
return hookSeq(promises);
|
|
1218
1213
|
}
|
|
1214
|
+
if (strategy === "first") {
|
|
1215
|
+
return hookFirst(promises, __privateGet(this, _options2).nullCheck);
|
|
1216
|
+
}
|
|
1217
|
+
if (strategy === "parallel") {
|
|
1218
|
+
return hookParallel(promises);
|
|
1219
|
+
}
|
|
1219
1220
|
throw new Error(`${strategy} not implemented`);
|
|
1220
1221
|
}
|
|
1221
1222
|
};
|
|
@@ -1299,10 +1300,11 @@ Names: ${JSON.stringify(names, void 0, 2)}`
|
|
|
1299
1300
|
}).result;
|
|
1300
1301
|
return transformReservedWord(name);
|
|
1301
1302
|
};
|
|
1303
|
+
this.config = config;
|
|
1302
1304
|
this.logger = options.logger;
|
|
1303
1305
|
this.queue = new Queue(100, this.logger.logLevel === LogLevel.debug);
|
|
1304
1306
|
this.fileManager = new FileManager({ task: options.task, queue: this.queue, timeout: options.writeTimeout });
|
|
1305
|
-
__privateSet(this, _promiseManager, new PromiseManager());
|
|
1307
|
+
__privateSet(this, _promiseManager, new PromiseManager({ nullCheck: (state) => !!state?.result }));
|
|
1306
1308
|
const plugins = config.plugins || [];
|
|
1307
1309
|
const core = definePlugin({
|
|
1308
1310
|
config,
|
|
@@ -1359,20 +1361,15 @@ Names: ${JSON.stringify(names, void 0, 2)}`
|
|
|
1359
1361
|
/**
|
|
1360
1362
|
* Chains, first non-null result stops and returns
|
|
1361
1363
|
*/
|
|
1362
|
-
hookFirst({
|
|
1364
|
+
async hookFirst({
|
|
1363
1365
|
hookName,
|
|
1364
1366
|
parameters,
|
|
1365
1367
|
skipped
|
|
1366
1368
|
}) {
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
}
|
|
1372
|
-
promise = promise.then(async (parseResult) => {
|
|
1373
|
-
if (parseResult?.result != null) {
|
|
1374
|
-
return parseResult;
|
|
1375
|
-
}
|
|
1369
|
+
const promises = __privateMethod(this, _getSortedPlugins, getSortedPlugins_fn).call(this).filter((plugin) => {
|
|
1370
|
+
return skipped ? skipped.has(plugin) : true;
|
|
1371
|
+
}).map((plugin) => {
|
|
1372
|
+
return async () => {
|
|
1376
1373
|
const value = await __privateMethod(this, _execute, execute_fn).call(this, {
|
|
1377
1374
|
strategy: "hookFirst",
|
|
1378
1375
|
hookName,
|
|
@@ -1385,9 +1382,9 @@ Names: ${JSON.stringify(names, void 0, 2)}`
|
|
|
1385
1382
|
result: value
|
|
1386
1383
|
}
|
|
1387
1384
|
);
|
|
1388
|
-
}
|
|
1389
|
-
}
|
|
1390
|
-
return
|
|
1385
|
+
};
|
|
1386
|
+
});
|
|
1387
|
+
return __privateGet(this, _promiseManager).run("first", promises);
|
|
1391
1388
|
}
|
|
1392
1389
|
/**
|
|
1393
1390
|
* Chains, first non-null result stops and returns
|
|
@@ -1424,23 +1421,16 @@ Names: ${JSON.stringify(names, void 0, 2)}`
|
|
|
1424
1421
|
hookName,
|
|
1425
1422
|
parameters
|
|
1426
1423
|
}) {
|
|
1427
|
-
const
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
const errors = results.map((result) => {
|
|
1436
|
-
if (isPromiseRejectedResult(result) && result.reason instanceof PluginError) {
|
|
1437
|
-
return result.reason;
|
|
1424
|
+
const promises = __privateMethod(this, _getSortedPlugins, getSortedPlugins_fn).call(this).map((plugin) => {
|
|
1425
|
+
return () => __privateMethod(this, _execute, execute_fn).call(this, { strategy: "hookParallel", hookName, parameters, plugin });
|
|
1426
|
+
});
|
|
1427
|
+
const results = await __privateGet(this, _promiseManager).run("parallel", promises);
|
|
1428
|
+
results.forEach((result, index) => {
|
|
1429
|
+
if (isPromiseRejectedResult(result)) {
|
|
1430
|
+
const plugin = __privateMethod(this, _getSortedPlugins, getSortedPlugins_fn).call(this)[index];
|
|
1431
|
+
__privateMethod(this, _catcher, catcher_fn).call(this, result.reason, plugin, hookName);
|
|
1438
1432
|
}
|
|
1439
|
-
|
|
1440
|
-
}).filter(Boolean);
|
|
1441
|
-
if (errors.length) {
|
|
1442
|
-
throw new ParallelPluginError("Error", { errors, pluginManager: this });
|
|
1443
|
-
}
|
|
1433
|
+
});
|
|
1444
1434
|
return results.filter((result) => result.status === "fulfilled").map((result) => result.value);
|
|
1445
1435
|
}
|
|
1446
1436
|
/**
|
|
@@ -1469,7 +1459,7 @@ Names: ${JSON.stringify(names, void 0, 2)}`
|
|
|
1469
1459
|
/**
|
|
1470
1460
|
* Chains plugins
|
|
1471
1461
|
*/
|
|
1472
|
-
hookSeq({ hookName, parameters }) {
|
|
1462
|
+
async hookSeq({ hookName, parameters }) {
|
|
1473
1463
|
const promises = __privateMethod(this, _getSortedPlugins, getSortedPlugins_fn).call(this).map((plugin) => {
|
|
1474
1464
|
return () => __privateMethod(this, _execute, execute_fn).call(this, {
|
|
1475
1465
|
strategy: "hookSeq",
|
|
@@ -1574,11 +1564,6 @@ execute_fn = function({
|
|
|
1574
1564
|
return hook;
|
|
1575
1565
|
}).then((result) => {
|
|
1576
1566
|
output = result;
|
|
1577
|
-
return result;
|
|
1578
|
-
}).catch((e) => {
|
|
1579
|
-
__privateMethod(this, _catcher, catcher_fn).call(this, e, plugin, hookName);
|
|
1580
|
-
return null;
|
|
1581
|
-
}).finally(() => {
|
|
1582
1567
|
__privateMethod(this, _addExecutedToCallStack, addExecutedToCallStack_fn).call(this, {
|
|
1583
1568
|
parameters,
|
|
1584
1569
|
output,
|
|
@@ -1586,6 +1571,10 @@ execute_fn = function({
|
|
|
1586
1571
|
hookName,
|
|
1587
1572
|
plugin
|
|
1588
1573
|
});
|
|
1574
|
+
return result;
|
|
1575
|
+
}).catch((e) => {
|
|
1576
|
+
__privateMethod(this, _catcher, catcher_fn).call(this, e, plugin, hookName);
|
|
1577
|
+
return null;
|
|
1589
1578
|
});
|
|
1590
1579
|
return task;
|
|
1591
1580
|
};
|
|
@@ -1609,11 +1598,6 @@ executeSync_fn = function({
|
|
|
1609
1598
|
return fn;
|
|
1610
1599
|
}
|
|
1611
1600
|
output = hook;
|
|
1612
|
-
return hook;
|
|
1613
|
-
} catch (e) {
|
|
1614
|
-
__privateMethod(this, _catcher, catcher_fn).call(this, e, plugin, hookName);
|
|
1615
|
-
return null;
|
|
1616
|
-
} finally {
|
|
1617
1601
|
__privateMethod(this, _addExecutedToCallStack, addExecutedToCallStack_fn).call(this, {
|
|
1618
1602
|
parameters,
|
|
1619
1603
|
output,
|
|
@@ -1621,15 +1605,18 @@ executeSync_fn = function({
|
|
|
1621
1605
|
hookName,
|
|
1622
1606
|
plugin
|
|
1623
1607
|
});
|
|
1608
|
+
return hook;
|
|
1609
|
+
} catch (e) {
|
|
1610
|
+
__privateMethod(this, _catcher, catcher_fn).call(this, e, plugin, hookName);
|
|
1611
|
+
return null;
|
|
1624
1612
|
}
|
|
1625
1613
|
};
|
|
1626
1614
|
_catcher = new WeakSet();
|
|
1627
1615
|
catcher_fn = function(e, plugin, hookName) {
|
|
1628
|
-
const text = `${e.message} (plugin: ${plugin
|
|
1616
|
+
const text = `${e.message} (plugin: ${plugin?.name || "unknown"}, hook: ${hookName || "unknown"})
|
|
1629
1617
|
`;
|
|
1630
|
-
|
|
1631
|
-
this.eventEmitter.emit("error",
|
|
1632
|
-
throw pluginError;
|
|
1618
|
+
this.logger.error(text);
|
|
1619
|
+
this.eventEmitter.emit("error", e);
|
|
1633
1620
|
};
|
|
1634
1621
|
_parse = new WeakSet();
|
|
1635
1622
|
parse_fn = function(plugin, pluginManager, context) {
|
|
@@ -1662,7 +1649,7 @@ parse_fn = function(plugin, pluginManager, context) {
|
|
|
1662
1649
|
async function transformReducer(_previousCode, result, _plugin) {
|
|
1663
1650
|
return result;
|
|
1664
1651
|
}
|
|
1665
|
-
async function
|
|
1652
|
+
async function setup(options) {
|
|
1666
1653
|
const { config, logger = createLogger({ logLevel: LogLevel.silent }) } = options;
|
|
1667
1654
|
try {
|
|
1668
1655
|
if (isInputPath(config) && !new URLPath(config.input.path).isURL) {
|
|
@@ -1716,7 +1703,6 @@ async function build(options) {
|
|
|
1716
1703
|
}
|
|
1717
1704
|
};
|
|
1718
1705
|
const pluginManager = new PluginManager(config, { logger, task: queueTask, writeTimeout: 0 });
|
|
1719
|
-
const { plugins, fileManager } = pluginManager;
|
|
1720
1706
|
pluginManager.on("execute", (executer) => {
|
|
1721
1707
|
const { hookName, parameters, plugin } = executer;
|
|
1722
1708
|
if (hookName === "writeFile" && logger.spinner) {
|
|
@@ -1754,13 +1740,18 @@ ${code}`);
|
|
|
1754
1740
|
console.log(logs.join("\n"));
|
|
1755
1741
|
}
|
|
1756
1742
|
});
|
|
1743
|
+
return pluginManager;
|
|
1744
|
+
}
|
|
1745
|
+
async function build(options) {
|
|
1746
|
+
const pluginManager = await setup(options);
|
|
1747
|
+
const { fileManager, logger } = pluginManager;
|
|
1757
1748
|
await pluginManager.hookParallel({
|
|
1758
1749
|
hookName: "validate",
|
|
1759
|
-
parameters: [plugins]
|
|
1750
|
+
parameters: [pluginManager.plugins]
|
|
1760
1751
|
});
|
|
1761
1752
|
await pluginManager.hookParallel({
|
|
1762
1753
|
hookName: "buildStart",
|
|
1763
|
-
parameters: [config]
|
|
1754
|
+
parameters: [options.config]
|
|
1764
1755
|
});
|
|
1765
1756
|
await pluginManager.hookParallel({ hookName: "buildEnd" });
|
|
1766
1757
|
if (!fileManager.isExecuting && logger.spinner) {
|
|
@@ -1769,6 +1760,28 @@ ${code}`);
|
|
|
1769
1760
|
}
|
|
1770
1761
|
return { files: fileManager.files.map((file) => ({ ...file, source: FileManager.getSource(file) })), pluginManager };
|
|
1771
1762
|
}
|
|
1763
|
+
async function safeBuild(options) {
|
|
1764
|
+
const pluginManager = await setup(options);
|
|
1765
|
+
const { fileManager, logger } = pluginManager;
|
|
1766
|
+
try {
|
|
1767
|
+
await pluginManager.hookParallel({
|
|
1768
|
+
hookName: "validate",
|
|
1769
|
+
parameters: [pluginManager.plugins]
|
|
1770
|
+
});
|
|
1771
|
+
await pluginManager.hookParallel({
|
|
1772
|
+
hookName: "buildStart",
|
|
1773
|
+
parameters: [options.config]
|
|
1774
|
+
});
|
|
1775
|
+
await pluginManager.hookParallel({ hookName: "buildEnd" });
|
|
1776
|
+
if (!fileManager.isExecuting && logger.spinner) {
|
|
1777
|
+
logger.spinner.suffixText = "";
|
|
1778
|
+
logger.spinner.succeed(`\u{1F4BE} Writing completed`);
|
|
1779
|
+
}
|
|
1780
|
+
} catch (e) {
|
|
1781
|
+
return { files: fileManager.files.map((file) => ({ ...file, source: FileManager.getSource(file) })), pluginManager, error: e };
|
|
1782
|
+
}
|
|
1783
|
+
return { files: fileManager.files.map((file) => ({ ...file, source: FileManager.getSource(file) })), pluginManager };
|
|
1784
|
+
}
|
|
1772
1785
|
|
|
1773
1786
|
// src/Generator.ts
|
|
1774
1787
|
var _options3, _context;
|
|
@@ -1796,9 +1809,10 @@ var Generator = class {
|
|
|
1796
1809
|
};
|
|
1797
1810
|
_options3 = new WeakMap();
|
|
1798
1811
|
_context = new WeakMap();
|
|
1799
|
-
var _cache2, _cwd, _SLASHES;
|
|
1812
|
+
var _cache2, _cwd, _SLASHES, _match, match_fn;
|
|
1800
1813
|
var _PackageManager = class _PackageManager {
|
|
1801
1814
|
constructor(workspace) {
|
|
1815
|
+
__privateAdd(this, _match);
|
|
1802
1816
|
__privateAdd(this, _cwd, void 0);
|
|
1803
1817
|
__privateAdd(this, _SLASHES, /* @__PURE__ */ new Set(["/", "\\"]));
|
|
1804
1818
|
if (workspace) {
|
|
@@ -1861,30 +1875,33 @@ var _PackageManager = class _PackageManager {
|
|
|
1861
1875
|
__privateGet(_PackageManager, _cache2)[dependency] = version;
|
|
1862
1876
|
}
|
|
1863
1877
|
async getVersion(dependency) {
|
|
1864
|
-
if (__privateGet(_PackageManager, _cache2)[dependency]) {
|
|
1878
|
+
if (typeof dependency === "string" && __privateGet(_PackageManager, _cache2)[dependency]) {
|
|
1865
1879
|
return __privateGet(_PackageManager, _cache2)[dependency];
|
|
1866
1880
|
}
|
|
1867
1881
|
const packageJSON = await this.getPackageJSON();
|
|
1868
1882
|
if (!packageJSON) {
|
|
1869
1883
|
return void 0;
|
|
1870
1884
|
}
|
|
1871
|
-
return
|
|
1885
|
+
return __privateMethod(this, _match, match_fn).call(this, packageJSON, dependency);
|
|
1872
1886
|
}
|
|
1873
1887
|
getVersionSync(dependency) {
|
|
1874
|
-
if (__privateGet(_PackageManager, _cache2)[dependency]) {
|
|
1888
|
+
if (typeof dependency === "string" && __privateGet(_PackageManager, _cache2)[dependency]) {
|
|
1875
1889
|
return __privateGet(_PackageManager, _cache2)[dependency];
|
|
1876
1890
|
}
|
|
1877
1891
|
const packageJSON = this.getPackageJSONSync();
|
|
1878
1892
|
if (!packageJSON) {
|
|
1879
1893
|
return void 0;
|
|
1880
1894
|
}
|
|
1881
|
-
return
|
|
1895
|
+
return __privateMethod(this, _match, match_fn).call(this, packageJSON, dependency);
|
|
1882
1896
|
}
|
|
1883
1897
|
async isValid(dependency, version) {
|
|
1884
1898
|
const packageVersion = await this.getVersion(dependency);
|
|
1885
1899
|
if (!packageVersion) {
|
|
1886
1900
|
return false;
|
|
1887
1901
|
}
|
|
1902
|
+
if (packageVersion === version) {
|
|
1903
|
+
return true;
|
|
1904
|
+
}
|
|
1888
1905
|
const semVer = coerce(packageVersion);
|
|
1889
1906
|
if (!semVer) {
|
|
1890
1907
|
throw new Error(`${packageVersion} is not valid`);
|
|
@@ -1906,6 +1923,18 @@ var _PackageManager = class _PackageManager {
|
|
|
1906
1923
|
_cache2 = new WeakMap();
|
|
1907
1924
|
_cwd = new WeakMap();
|
|
1908
1925
|
_SLASHES = new WeakMap();
|
|
1926
|
+
_match = new WeakSet();
|
|
1927
|
+
match_fn = function(packageJSON, dependency) {
|
|
1928
|
+
const dependencies = {
|
|
1929
|
+
...packageJSON["dependencies"] || {},
|
|
1930
|
+
...packageJSON["devDependencies"] || {}
|
|
1931
|
+
};
|
|
1932
|
+
if (typeof dependency === "string" && dependencies[dependency]) {
|
|
1933
|
+
return dependencies[dependency];
|
|
1934
|
+
}
|
|
1935
|
+
const matchedDependency = Object.keys(dependencies).find((dep) => dep.match(dependency));
|
|
1936
|
+
return matchedDependency ? dependencies[matchedDependency] : void 0;
|
|
1937
|
+
};
|
|
1909
1938
|
__privateAdd(_PackageManager, _cache2, {});
|
|
1910
1939
|
var PackageManager = _PackageManager;
|
|
1911
1940
|
|
|
@@ -1916,6 +1945,6 @@ var SchemaGenerator = class extends Generator {
|
|
|
1916
1945
|
// src/index.ts
|
|
1917
1946
|
var src_default = build;
|
|
1918
1947
|
|
|
1919
|
-
export { FileManager, Generator,
|
|
1948
|
+
export { FileManager, Generator, KubbFile, PackageManager, PluginManager, PromiseManager, SchemaGenerator, ValidationPluginError, Warning, build, combineExports, combineImports, createPlugin, src_default as default, defineConfig, isInputPath, pluginName as name, pluginName, safeBuild };
|
|
1920
1949
|
//# sourceMappingURL=out.js.map
|
|
1921
1950
|
//# sourceMappingURL=index.js.map
|