@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/README.md
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
</p>
|
|
19
19
|
|
|
20
20
|
<h4>
|
|
21
|
-
<a href="https://codesandbox.io/s/github/kubb-project/kubb/tree/
|
|
21
|
+
<a href="https://codesandbox.io/s/github/kubb-project/kubb/tree/alpha/examples/typescript" target="_blank">View Demo</a>
|
|
22
22
|
<span> · </span>
|
|
23
23
|
<a href="https://kubb.dev/" target="_blank">Documentation</a>
|
|
24
24
|
<span> · </span>
|
package/dist/index.cjs
CHANGED
|
@@ -127,7 +127,7 @@ function createLogger({ logLevel, name, spinner }) {
|
|
|
127
127
|
}
|
|
128
128
|
};
|
|
129
129
|
const info = (message) => {
|
|
130
|
-
if (message && spinner) {
|
|
130
|
+
if (message && spinner && logLevel !== LogLevel.silent) {
|
|
131
131
|
spinner.info(message);
|
|
132
132
|
logs.push(message);
|
|
133
133
|
}
|
|
@@ -240,10 +240,13 @@ var URLPath = class {
|
|
|
240
240
|
params: this.getParams()
|
|
241
241
|
};
|
|
242
242
|
if (stringify) {
|
|
243
|
-
if (type
|
|
244
|
-
|
|
243
|
+
if (type === "template") {
|
|
244
|
+
return JSON.stringify(object).replaceAll("'", "").replaceAll(`"`, "");
|
|
245
|
+
}
|
|
246
|
+
if (object.params) {
|
|
247
|
+
return `{ url: '${object.url}', params: ${JSON.stringify(object.params).replaceAll("'", "").replaceAll(`"`, "")} }`;
|
|
245
248
|
}
|
|
246
|
-
return
|
|
249
|
+
return `{ url: '${object.url}' }`;
|
|
247
250
|
}
|
|
248
251
|
return object;
|
|
249
252
|
}
|
|
@@ -312,14 +315,19 @@ function combineCodes(codes) {
|
|
|
312
315
|
}
|
|
313
316
|
|
|
314
317
|
// src/utils/transformers/createJSDocBlockText.ts
|
|
315
|
-
function createJSDocBlockText({ comments }) {
|
|
318
|
+
function createJSDocBlockText({ comments, newLine }) {
|
|
316
319
|
const filteredComments = comments.filter(Boolean);
|
|
317
320
|
if (!filteredComments.length) {
|
|
318
321
|
return "";
|
|
319
322
|
}
|
|
320
|
-
|
|
323
|
+
const source = `/**
|
|
321
324
|
* ${filteredComments.join("\n * ")}
|
|
322
325
|
*/`;
|
|
326
|
+
if (newLine) {
|
|
327
|
+
return `${source}
|
|
328
|
+
`;
|
|
329
|
+
}
|
|
330
|
+
return source;
|
|
323
331
|
}
|
|
324
332
|
|
|
325
333
|
// src/utils/transformers/escape.ts
|
|
@@ -473,6 +481,11 @@ function transformReservedWord(word) {
|
|
|
473
481
|
return word;
|
|
474
482
|
}
|
|
475
483
|
|
|
484
|
+
// src/utils/transformers/trim.ts
|
|
485
|
+
function trim(text) {
|
|
486
|
+
return text.replaceAll(/\n/g, "").trim();
|
|
487
|
+
}
|
|
488
|
+
|
|
476
489
|
// src/utils/transformers/index.ts
|
|
477
490
|
var transformers = {
|
|
478
491
|
combineCodes,
|
|
@@ -482,6 +495,7 @@ var transformers = {
|
|
|
482
495
|
transformReservedWord,
|
|
483
496
|
nameSorter,
|
|
484
497
|
searchAndReplace,
|
|
498
|
+
trim,
|
|
485
499
|
JSDoc: {
|
|
486
500
|
createJSDocBlockText
|
|
487
501
|
}
|
|
@@ -663,12 +677,12 @@ var BarrelManager = class {
|
|
|
663
677
|
if (currentTree.children?.length > 1) {
|
|
664
678
|
const indexPath = path4__default.default.resolve(currentTree.data.path, "index.ts");
|
|
665
679
|
const exports = currentTree.children.filter(Boolean).map((file) => {
|
|
666
|
-
const importPath = file.data.type === "directory" ? `./${file.data.name}` : `./${file.data.name.replace(/\.[^.]*$/, "")}`;
|
|
667
|
-
if (importPath.includes("index") &&
|
|
680
|
+
const importPath = file.data.type === "directory" ? `./${file.data.name}/index` : `./${file.data.name.replace(/\.[^.]*$/, "")}`;
|
|
681
|
+
if (importPath.includes("index") && file.data.type === "file") {
|
|
668
682
|
return void 0;
|
|
669
683
|
}
|
|
670
684
|
return {
|
|
671
|
-
path: includeExt ?
|
|
685
|
+
path: includeExt ? `${importPath}${extName}` : importPath,
|
|
672
686
|
isTypeOnly
|
|
673
687
|
};
|
|
674
688
|
}).filter(Boolean);
|
|
@@ -683,10 +697,10 @@ var BarrelManager = class {
|
|
|
683
697
|
} else {
|
|
684
698
|
currentTree.children?.forEach((child) => {
|
|
685
699
|
const indexPath = path4__default.default.resolve(currentTree.data.path, "index.ts");
|
|
686
|
-
const importPath = child.data.type === "directory" ? `./${child.data.name}` : `./${child.data.name.replace(/\.[^.]*$/, "")}`;
|
|
700
|
+
const importPath = child.data.type === "directory" ? `./${child.data.name}/index` : `./${child.data.name.replace(/\.[^.]*$/, "")}`;
|
|
687
701
|
const exports = [
|
|
688
702
|
{
|
|
689
|
-
path: includeExt ?
|
|
703
|
+
path: includeExt ? `${importPath}${extName}` : importPath,
|
|
690
704
|
isTypeOnly
|
|
691
705
|
}
|
|
692
706
|
];
|
|
@@ -713,6 +727,9 @@ var BarrelManager = class {
|
|
|
713
727
|
_options = new WeakMap();
|
|
714
728
|
|
|
715
729
|
// src/FileManager.ts
|
|
730
|
+
exports.KubbFile = void 0;
|
|
731
|
+
((KubbFile2) => {
|
|
732
|
+
})(exports.KubbFile || (exports.KubbFile = {}));
|
|
716
733
|
var _cache, _task, _isWriting, _timeout, _queue, _validate, validate_fn, _add, add_fn, _addOrAppend, addOrAppend_fn;
|
|
717
734
|
var _FileManager = class _FileManager {
|
|
718
735
|
constructor(options) {
|
|
@@ -1103,44 +1120,6 @@ function setUniqueName(originalName, data) {
|
|
|
1103
1120
|
}
|
|
1104
1121
|
|
|
1105
1122
|
// src/errors.ts
|
|
1106
|
-
var PluginError = class extends Error {
|
|
1107
|
-
constructor(message, options) {
|
|
1108
|
-
super(message, { cause: options.cause });
|
|
1109
|
-
this.name = "PluginError";
|
|
1110
|
-
this.cause = options.cause;
|
|
1111
|
-
this.pluginManager = options.pluginManager;
|
|
1112
|
-
}
|
|
1113
|
-
};
|
|
1114
|
-
var ParallelPluginError = class extends Error {
|
|
1115
|
-
constructor(message, options) {
|
|
1116
|
-
super(message, { cause: options.cause });
|
|
1117
|
-
this.errors = [];
|
|
1118
|
-
this.name = "ParallelPluginError";
|
|
1119
|
-
this.errors = options.errors;
|
|
1120
|
-
this.pluginManager = options.pluginManager;
|
|
1121
|
-
}
|
|
1122
|
-
findError(searchError) {
|
|
1123
|
-
if (!searchError) {
|
|
1124
|
-
return void 0;
|
|
1125
|
-
}
|
|
1126
|
-
return this.errors.find((error) => {
|
|
1127
|
-
if (error.cause) {
|
|
1128
|
-
if (error.cause.name == searchError.name) {
|
|
1129
|
-
return true;
|
|
1130
|
-
}
|
|
1131
|
-
return !!this.findError(error.cause);
|
|
1132
|
-
}
|
|
1133
|
-
return error.name === searchError.name;
|
|
1134
|
-
})?.cause;
|
|
1135
|
-
}
|
|
1136
|
-
};
|
|
1137
|
-
var SummaryError = class extends Error {
|
|
1138
|
-
constructor(message, options) {
|
|
1139
|
-
super(message, { cause: options.cause });
|
|
1140
|
-
this.name = "SummaryError";
|
|
1141
|
-
this.summary = options.summary || [];
|
|
1142
|
-
}
|
|
1143
|
-
};
|
|
1144
1123
|
var Warning = class extends Error {
|
|
1145
1124
|
constructor(message, options) {
|
|
1146
1125
|
super(message, { cause: options?.cause });
|
|
@@ -1230,21 +1209,37 @@ var definePlugin = createPlugin((options) => {
|
|
|
1230
1209
|
|
|
1231
1210
|
// src/utils/executeStrategies.ts
|
|
1232
1211
|
function hookSeq(promises) {
|
|
1233
|
-
return promises.reduce(
|
|
1212
|
+
return promises.filter(Boolean).reduce(
|
|
1234
1213
|
(promise, func) => {
|
|
1235
|
-
if (
|
|
1214
|
+
if (typeof func !== "function") {
|
|
1236
1215
|
throw new Error("HookSeq needs a function that returns a promise `() => Promise<unknown>`");
|
|
1237
1216
|
}
|
|
1238
|
-
return promise.then((
|
|
1239
|
-
const calledFunc = func();
|
|
1217
|
+
return promise.then((state) => {
|
|
1218
|
+
const calledFunc = func(state);
|
|
1240
1219
|
if (calledFunc) {
|
|
1241
|
-
return calledFunc.then(Array.prototype.concat.bind(
|
|
1220
|
+
return calledFunc.then(Array.prototype.concat.bind(state));
|
|
1242
1221
|
}
|
|
1243
1222
|
});
|
|
1244
1223
|
},
|
|
1245
1224
|
Promise.resolve([])
|
|
1246
1225
|
);
|
|
1247
1226
|
}
|
|
1227
|
+
function hookFirst(promises, nullCheck = (state) => state !== null) {
|
|
1228
|
+
let promise = Promise.resolve(null);
|
|
1229
|
+
for (const func of promises.filter(Boolean)) {
|
|
1230
|
+
promise = promise.then((state) => {
|
|
1231
|
+
if (nullCheck(state)) {
|
|
1232
|
+
return state;
|
|
1233
|
+
}
|
|
1234
|
+
const calledFunc = func(state);
|
|
1235
|
+
return calledFunc;
|
|
1236
|
+
});
|
|
1237
|
+
}
|
|
1238
|
+
return promise;
|
|
1239
|
+
}
|
|
1240
|
+
function hookParallel(promises) {
|
|
1241
|
+
return Promise.allSettled(promises.filter(Boolean).map((promise) => promise()));
|
|
1242
|
+
}
|
|
1248
1243
|
|
|
1249
1244
|
// src/PromiseManager.ts
|
|
1250
1245
|
var _options2;
|
|
@@ -1258,6 +1253,12 @@ var PromiseManager = class {
|
|
|
1258
1253
|
if (strategy === "seq") {
|
|
1259
1254
|
return hookSeq(promises);
|
|
1260
1255
|
}
|
|
1256
|
+
if (strategy === "first") {
|
|
1257
|
+
return hookFirst(promises, __privateGet(this, _options2).nullCheck);
|
|
1258
|
+
}
|
|
1259
|
+
if (strategy === "parallel") {
|
|
1260
|
+
return hookParallel(promises);
|
|
1261
|
+
}
|
|
1261
1262
|
throw new Error(`${strategy} not implemented`);
|
|
1262
1263
|
}
|
|
1263
1264
|
};
|
|
@@ -1341,10 +1342,11 @@ Names: ${JSON.stringify(names, void 0, 2)}`
|
|
|
1341
1342
|
}).result;
|
|
1342
1343
|
return transformReservedWord(name);
|
|
1343
1344
|
};
|
|
1345
|
+
this.config = config;
|
|
1344
1346
|
this.logger = options.logger;
|
|
1345
1347
|
this.queue = new Queue(100, this.logger.logLevel === LogLevel.debug);
|
|
1346
1348
|
this.fileManager = new FileManager({ task: options.task, queue: this.queue, timeout: options.writeTimeout });
|
|
1347
|
-
__privateSet(this, _promiseManager, new PromiseManager());
|
|
1349
|
+
__privateSet(this, _promiseManager, new PromiseManager({ nullCheck: (state) => !!state?.result }));
|
|
1348
1350
|
const plugins = config.plugins || [];
|
|
1349
1351
|
const core = definePlugin({
|
|
1350
1352
|
config,
|
|
@@ -1401,20 +1403,15 @@ Names: ${JSON.stringify(names, void 0, 2)}`
|
|
|
1401
1403
|
/**
|
|
1402
1404
|
* Chains, first non-null result stops and returns
|
|
1403
1405
|
*/
|
|
1404
|
-
hookFirst({
|
|
1406
|
+
async hookFirst({
|
|
1405
1407
|
hookName,
|
|
1406
1408
|
parameters,
|
|
1407
1409
|
skipped
|
|
1408
1410
|
}) {
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
}
|
|
1414
|
-
promise = promise.then(async (parseResult) => {
|
|
1415
|
-
if (parseResult?.result != null) {
|
|
1416
|
-
return parseResult;
|
|
1417
|
-
}
|
|
1411
|
+
const promises = __privateMethod(this, _getSortedPlugins, getSortedPlugins_fn).call(this).filter((plugin) => {
|
|
1412
|
+
return skipped ? skipped.has(plugin) : true;
|
|
1413
|
+
}).map((plugin) => {
|
|
1414
|
+
return async () => {
|
|
1418
1415
|
const value = await __privateMethod(this, _execute, execute_fn).call(this, {
|
|
1419
1416
|
strategy: "hookFirst",
|
|
1420
1417
|
hookName,
|
|
@@ -1427,9 +1424,9 @@ Names: ${JSON.stringify(names, void 0, 2)}`
|
|
|
1427
1424
|
result: value
|
|
1428
1425
|
}
|
|
1429
1426
|
);
|
|
1430
|
-
}
|
|
1431
|
-
}
|
|
1432
|
-
return
|
|
1427
|
+
};
|
|
1428
|
+
});
|
|
1429
|
+
return __privateGet(this, _promiseManager).run("first", promises);
|
|
1433
1430
|
}
|
|
1434
1431
|
/**
|
|
1435
1432
|
* Chains, first non-null result stops and returns
|
|
@@ -1466,23 +1463,16 @@ Names: ${JSON.stringify(names, void 0, 2)}`
|
|
|
1466
1463
|
hookName,
|
|
1467
1464
|
parameters
|
|
1468
1465
|
}) {
|
|
1469
|
-
const
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
const errors = results.map((result) => {
|
|
1478
|
-
if (isPromiseRejectedResult(result) && result.reason instanceof PluginError) {
|
|
1479
|
-
return result.reason;
|
|
1466
|
+
const promises = __privateMethod(this, _getSortedPlugins, getSortedPlugins_fn).call(this).map((plugin) => {
|
|
1467
|
+
return () => __privateMethod(this, _execute, execute_fn).call(this, { strategy: "hookParallel", hookName, parameters, plugin });
|
|
1468
|
+
});
|
|
1469
|
+
const results = await __privateGet(this, _promiseManager).run("parallel", promises);
|
|
1470
|
+
results.forEach((result, index) => {
|
|
1471
|
+
if (isPromiseRejectedResult(result)) {
|
|
1472
|
+
const plugin = __privateMethod(this, _getSortedPlugins, getSortedPlugins_fn).call(this)[index];
|
|
1473
|
+
__privateMethod(this, _catcher, catcher_fn).call(this, result.reason, plugin, hookName);
|
|
1480
1474
|
}
|
|
1481
|
-
|
|
1482
|
-
}).filter(Boolean);
|
|
1483
|
-
if (errors.length) {
|
|
1484
|
-
throw new ParallelPluginError("Error", { errors, pluginManager: this });
|
|
1485
|
-
}
|
|
1475
|
+
});
|
|
1486
1476
|
return results.filter((result) => result.status === "fulfilled").map((result) => result.value);
|
|
1487
1477
|
}
|
|
1488
1478
|
/**
|
|
@@ -1511,7 +1501,7 @@ Names: ${JSON.stringify(names, void 0, 2)}`
|
|
|
1511
1501
|
/**
|
|
1512
1502
|
* Chains plugins
|
|
1513
1503
|
*/
|
|
1514
|
-
hookSeq({ hookName, parameters }) {
|
|
1504
|
+
async hookSeq({ hookName, parameters }) {
|
|
1515
1505
|
const promises = __privateMethod(this, _getSortedPlugins, getSortedPlugins_fn).call(this).map((plugin) => {
|
|
1516
1506
|
return () => __privateMethod(this, _execute, execute_fn).call(this, {
|
|
1517
1507
|
strategy: "hookSeq",
|
|
@@ -1616,11 +1606,6 @@ execute_fn = function({
|
|
|
1616
1606
|
return hook;
|
|
1617
1607
|
}).then((result) => {
|
|
1618
1608
|
output = result;
|
|
1619
|
-
return result;
|
|
1620
|
-
}).catch((e) => {
|
|
1621
|
-
__privateMethod(this, _catcher, catcher_fn).call(this, e, plugin, hookName);
|
|
1622
|
-
return null;
|
|
1623
|
-
}).finally(() => {
|
|
1624
1609
|
__privateMethod(this, _addExecutedToCallStack, addExecutedToCallStack_fn).call(this, {
|
|
1625
1610
|
parameters,
|
|
1626
1611
|
output,
|
|
@@ -1628,6 +1613,10 @@ execute_fn = function({
|
|
|
1628
1613
|
hookName,
|
|
1629
1614
|
plugin
|
|
1630
1615
|
});
|
|
1616
|
+
return result;
|
|
1617
|
+
}).catch((e) => {
|
|
1618
|
+
__privateMethod(this, _catcher, catcher_fn).call(this, e, plugin, hookName);
|
|
1619
|
+
return null;
|
|
1631
1620
|
});
|
|
1632
1621
|
return task;
|
|
1633
1622
|
};
|
|
@@ -1651,11 +1640,6 @@ executeSync_fn = function({
|
|
|
1651
1640
|
return fn;
|
|
1652
1641
|
}
|
|
1653
1642
|
output = hook;
|
|
1654
|
-
return hook;
|
|
1655
|
-
} catch (e) {
|
|
1656
|
-
__privateMethod(this, _catcher, catcher_fn).call(this, e, plugin, hookName);
|
|
1657
|
-
return null;
|
|
1658
|
-
} finally {
|
|
1659
1643
|
__privateMethod(this, _addExecutedToCallStack, addExecutedToCallStack_fn).call(this, {
|
|
1660
1644
|
parameters,
|
|
1661
1645
|
output,
|
|
@@ -1663,15 +1647,18 @@ executeSync_fn = function({
|
|
|
1663
1647
|
hookName,
|
|
1664
1648
|
plugin
|
|
1665
1649
|
});
|
|
1650
|
+
return hook;
|
|
1651
|
+
} catch (e) {
|
|
1652
|
+
__privateMethod(this, _catcher, catcher_fn).call(this, e, plugin, hookName);
|
|
1653
|
+
return null;
|
|
1666
1654
|
}
|
|
1667
1655
|
};
|
|
1668
1656
|
_catcher = new WeakSet();
|
|
1669
1657
|
catcher_fn = function(e, plugin, hookName) {
|
|
1670
|
-
const text = `${e.message} (plugin: ${plugin
|
|
1658
|
+
const text = `${e.message} (plugin: ${plugin?.name || "unknown"}, hook: ${hookName || "unknown"})
|
|
1671
1659
|
`;
|
|
1672
|
-
|
|
1673
|
-
this.eventEmitter.emit("error",
|
|
1674
|
-
throw pluginError;
|
|
1660
|
+
this.logger.error(text);
|
|
1661
|
+
this.eventEmitter.emit("error", e);
|
|
1675
1662
|
};
|
|
1676
1663
|
_parse = new WeakSet();
|
|
1677
1664
|
parse_fn = function(plugin, pluginManager, context) {
|
|
@@ -1704,7 +1691,7 @@ parse_fn = function(plugin, pluginManager, context) {
|
|
|
1704
1691
|
async function transformReducer(_previousCode, result, _plugin) {
|
|
1705
1692
|
return result;
|
|
1706
1693
|
}
|
|
1707
|
-
async function
|
|
1694
|
+
async function setup(options) {
|
|
1708
1695
|
const { config, logger = createLogger({ logLevel: LogLevel.silent }) } = options;
|
|
1709
1696
|
try {
|
|
1710
1697
|
if (isInputPath(config) && !new URLPath(config.input.path).isURL) {
|
|
@@ -1758,7 +1745,6 @@ async function build(options) {
|
|
|
1758
1745
|
}
|
|
1759
1746
|
};
|
|
1760
1747
|
const pluginManager = new PluginManager(config, { logger, task: queueTask, writeTimeout: 0 });
|
|
1761
|
-
const { plugins, fileManager } = pluginManager;
|
|
1762
1748
|
pluginManager.on("execute", (executer) => {
|
|
1763
1749
|
const { hookName, parameters, plugin } = executer;
|
|
1764
1750
|
if (hookName === "writeFile" && logger.spinner) {
|
|
@@ -1796,13 +1782,18 @@ ${code}`);
|
|
|
1796
1782
|
console.log(logs.join("\n"));
|
|
1797
1783
|
}
|
|
1798
1784
|
});
|
|
1785
|
+
return pluginManager;
|
|
1786
|
+
}
|
|
1787
|
+
async function build(options) {
|
|
1788
|
+
const pluginManager = await setup(options);
|
|
1789
|
+
const { fileManager, logger } = pluginManager;
|
|
1799
1790
|
await pluginManager.hookParallel({
|
|
1800
1791
|
hookName: "validate",
|
|
1801
|
-
parameters: [plugins]
|
|
1792
|
+
parameters: [pluginManager.plugins]
|
|
1802
1793
|
});
|
|
1803
1794
|
await pluginManager.hookParallel({
|
|
1804
1795
|
hookName: "buildStart",
|
|
1805
|
-
parameters: [config]
|
|
1796
|
+
parameters: [options.config]
|
|
1806
1797
|
});
|
|
1807
1798
|
await pluginManager.hookParallel({ hookName: "buildEnd" });
|
|
1808
1799
|
if (!fileManager.isExecuting && logger.spinner) {
|
|
@@ -1811,6 +1802,28 @@ ${code}`);
|
|
|
1811
1802
|
}
|
|
1812
1803
|
return { files: fileManager.files.map((file) => ({ ...file, source: FileManager.getSource(file) })), pluginManager };
|
|
1813
1804
|
}
|
|
1805
|
+
async function safeBuild(options) {
|
|
1806
|
+
const pluginManager = await setup(options);
|
|
1807
|
+
const { fileManager, logger } = pluginManager;
|
|
1808
|
+
try {
|
|
1809
|
+
await pluginManager.hookParallel({
|
|
1810
|
+
hookName: "validate",
|
|
1811
|
+
parameters: [pluginManager.plugins]
|
|
1812
|
+
});
|
|
1813
|
+
await pluginManager.hookParallel({
|
|
1814
|
+
hookName: "buildStart",
|
|
1815
|
+
parameters: [options.config]
|
|
1816
|
+
});
|
|
1817
|
+
await pluginManager.hookParallel({ hookName: "buildEnd" });
|
|
1818
|
+
if (!fileManager.isExecuting && logger.spinner) {
|
|
1819
|
+
logger.spinner.suffixText = "";
|
|
1820
|
+
logger.spinner.succeed(`\u{1F4BE} Writing completed`);
|
|
1821
|
+
}
|
|
1822
|
+
} catch (e) {
|
|
1823
|
+
return { files: fileManager.files.map((file) => ({ ...file, source: FileManager.getSource(file) })), pluginManager, error: e };
|
|
1824
|
+
}
|
|
1825
|
+
return { files: fileManager.files.map((file) => ({ ...file, source: FileManager.getSource(file) })), pluginManager };
|
|
1826
|
+
}
|
|
1814
1827
|
|
|
1815
1828
|
// src/Generator.ts
|
|
1816
1829
|
var _options3, _context;
|
|
@@ -2109,9 +2122,10 @@ function findUpSync(name, options = {}) {
|
|
|
2109
2122
|
const matches = findUpMultipleSync(name, { ...options, limit: 1 });
|
|
2110
2123
|
return matches[0];
|
|
2111
2124
|
}
|
|
2112
|
-
var _cache2, _cwd, _SLASHES;
|
|
2125
|
+
var _cache2, _cwd, _SLASHES, _match, match_fn;
|
|
2113
2126
|
var _PackageManager = class _PackageManager {
|
|
2114
2127
|
constructor(workspace) {
|
|
2128
|
+
__privateAdd(this, _match);
|
|
2115
2129
|
__privateAdd(this, _cwd, void 0);
|
|
2116
2130
|
__privateAdd(this, _SLASHES, /* @__PURE__ */ new Set(["/", "\\"]));
|
|
2117
2131
|
if (workspace) {
|
|
@@ -2174,30 +2188,33 @@ var _PackageManager = class _PackageManager {
|
|
|
2174
2188
|
__privateGet(_PackageManager, _cache2)[dependency] = version;
|
|
2175
2189
|
}
|
|
2176
2190
|
async getVersion(dependency) {
|
|
2177
|
-
if (__privateGet(_PackageManager, _cache2)[dependency]) {
|
|
2191
|
+
if (typeof dependency === "string" && __privateGet(_PackageManager, _cache2)[dependency]) {
|
|
2178
2192
|
return __privateGet(_PackageManager, _cache2)[dependency];
|
|
2179
2193
|
}
|
|
2180
2194
|
const packageJSON = await this.getPackageJSON();
|
|
2181
2195
|
if (!packageJSON) {
|
|
2182
2196
|
return void 0;
|
|
2183
2197
|
}
|
|
2184
|
-
return
|
|
2198
|
+
return __privateMethod(this, _match, match_fn).call(this, packageJSON, dependency);
|
|
2185
2199
|
}
|
|
2186
2200
|
getVersionSync(dependency) {
|
|
2187
|
-
if (__privateGet(_PackageManager, _cache2)[dependency]) {
|
|
2201
|
+
if (typeof dependency === "string" && __privateGet(_PackageManager, _cache2)[dependency]) {
|
|
2188
2202
|
return __privateGet(_PackageManager, _cache2)[dependency];
|
|
2189
2203
|
}
|
|
2190
2204
|
const packageJSON = this.getPackageJSONSync();
|
|
2191
2205
|
if (!packageJSON) {
|
|
2192
2206
|
return void 0;
|
|
2193
2207
|
}
|
|
2194
|
-
return
|
|
2208
|
+
return __privateMethod(this, _match, match_fn).call(this, packageJSON, dependency);
|
|
2195
2209
|
}
|
|
2196
2210
|
async isValid(dependency, version) {
|
|
2197
2211
|
const packageVersion = await this.getVersion(dependency);
|
|
2198
2212
|
if (!packageVersion) {
|
|
2199
2213
|
return false;
|
|
2200
2214
|
}
|
|
2215
|
+
if (packageVersion === version) {
|
|
2216
|
+
return true;
|
|
2217
|
+
}
|
|
2201
2218
|
const semVer = semver.coerce(packageVersion);
|
|
2202
2219
|
if (!semVer) {
|
|
2203
2220
|
throw new Error(`${packageVersion} is not valid`);
|
|
@@ -2219,6 +2236,18 @@ var _PackageManager = class _PackageManager {
|
|
|
2219
2236
|
_cache2 = new WeakMap();
|
|
2220
2237
|
_cwd = new WeakMap();
|
|
2221
2238
|
_SLASHES = new WeakMap();
|
|
2239
|
+
_match = new WeakSet();
|
|
2240
|
+
match_fn = function(packageJSON, dependency) {
|
|
2241
|
+
const dependencies = {
|
|
2242
|
+
...packageJSON["dependencies"] || {},
|
|
2243
|
+
...packageJSON["devDependencies"] || {}
|
|
2244
|
+
};
|
|
2245
|
+
if (typeof dependency === "string" && dependencies[dependency]) {
|
|
2246
|
+
return dependencies[dependency];
|
|
2247
|
+
}
|
|
2248
|
+
const matchedDependency = Object.keys(dependencies).find((dep) => dep.match(dependency));
|
|
2249
|
+
return matchedDependency ? dependencies[matchedDependency] : void 0;
|
|
2250
|
+
};
|
|
2222
2251
|
__privateAdd(_PackageManager, _cache2, {});
|
|
2223
2252
|
var PackageManager = _PackageManager;
|
|
2224
2253
|
|
|
@@ -2232,12 +2261,9 @@ var src_default = build;
|
|
|
2232
2261
|
exports.FileManager = FileManager;
|
|
2233
2262
|
exports.Generator = Generator;
|
|
2234
2263
|
exports.PackageManager = PackageManager;
|
|
2235
|
-
exports.ParallelPluginError = ParallelPluginError;
|
|
2236
|
-
exports.PluginError = PluginError;
|
|
2237
2264
|
exports.PluginManager = PluginManager;
|
|
2238
2265
|
exports.PromiseManager = PromiseManager;
|
|
2239
2266
|
exports.SchemaGenerator = SchemaGenerator;
|
|
2240
|
-
exports.SummaryError = SummaryError;
|
|
2241
2267
|
exports.ValidationPluginError = ValidationPluginError;
|
|
2242
2268
|
exports.Warning = Warning;
|
|
2243
2269
|
exports.build = build;
|
|
@@ -2249,5 +2275,6 @@ exports.defineConfig = defineConfig;
|
|
|
2249
2275
|
exports.isInputPath = isInputPath;
|
|
2250
2276
|
exports.name = pluginName;
|
|
2251
2277
|
exports.pluginName = pluginName;
|
|
2278
|
+
exports.safeBuild = safeBuild;
|
|
2252
2279
|
//# sourceMappingURL=out.js.map
|
|
2253
2280
|
//# sourceMappingURL=index.cjs.map
|