@kubb/core 2.0.0-alpha.3 → 2.0.0-alpha.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +70 -75
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +198 -215
- package/dist/index.d.ts +198 -215
- package/dist/index.js +70 -73
- package/dist/index.js.map +1 -1
- package/dist/utils.cjs +19 -8
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +6 -2
- package/dist/utils.d.ts +6 -2
- package/dist/utils.js +19 -8
- package/dist/utils.js.map +1 -1
- package/package.json +7 -5
- package/src/BarrelManager.ts +123 -0
- package/src/FileManager.ts +483 -0
- package/src/Generator.ts +34 -0
- package/src/PackageManager.ts +163 -0
- package/src/PluginManager.ts +644 -0
- package/src/PromiseManager.ts +47 -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 +346 -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 +128 -0
- package/src/utils/cache.ts +35 -0
- package/src/utils/clean.ts +5 -0
- package/src/utils/executeStrategies.ts +71 -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.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
|
}
|
|
@@ -312,14 +312,19 @@ function combineCodes(codes) {
|
|
|
312
312
|
}
|
|
313
313
|
|
|
314
314
|
// src/utils/transformers/createJSDocBlockText.ts
|
|
315
|
-
function createJSDocBlockText({ comments }) {
|
|
315
|
+
function createJSDocBlockText({ comments, newLine }) {
|
|
316
316
|
const filteredComments = comments.filter(Boolean);
|
|
317
317
|
if (!filteredComments.length) {
|
|
318
318
|
return "";
|
|
319
319
|
}
|
|
320
|
-
|
|
320
|
+
const source = `/**
|
|
321
321
|
* ${filteredComments.join("\n * ")}
|
|
322
322
|
*/`;
|
|
323
|
+
if (newLine) {
|
|
324
|
+
return `${source}
|
|
325
|
+
`;
|
|
326
|
+
}
|
|
327
|
+
return source;
|
|
323
328
|
}
|
|
324
329
|
|
|
325
330
|
// src/utils/transformers/escape.ts
|
|
@@ -473,6 +478,11 @@ function transformReservedWord(word) {
|
|
|
473
478
|
return word;
|
|
474
479
|
}
|
|
475
480
|
|
|
481
|
+
// src/utils/transformers/trim.ts
|
|
482
|
+
function trim(text) {
|
|
483
|
+
return text.replaceAll(/\n/g, "").trim();
|
|
484
|
+
}
|
|
485
|
+
|
|
476
486
|
// src/utils/transformers/index.ts
|
|
477
487
|
var transformers = {
|
|
478
488
|
combineCodes,
|
|
@@ -482,6 +492,7 @@ var transformers = {
|
|
|
482
492
|
transformReservedWord,
|
|
483
493
|
nameSorter,
|
|
484
494
|
searchAndReplace,
|
|
495
|
+
trim,
|
|
485
496
|
JSDoc: {
|
|
486
497
|
createJSDocBlockText
|
|
487
498
|
}
|
|
@@ -663,12 +674,12 @@ var BarrelManager = class {
|
|
|
663
674
|
if (currentTree.children?.length > 1) {
|
|
664
675
|
const indexPath = path4__default.default.resolve(currentTree.data.path, "index.ts");
|
|
665
676
|
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") &&
|
|
677
|
+
const importPath = file.data.type === "directory" ? `./${file.data.name}/index` : `./${file.data.name.replace(/\.[^.]*$/, "")}`;
|
|
678
|
+
if (importPath.includes("index") && file.data.type === "file") {
|
|
668
679
|
return void 0;
|
|
669
680
|
}
|
|
670
681
|
return {
|
|
671
|
-
path: includeExt ?
|
|
682
|
+
path: includeExt ? `${importPath}${extName}` : importPath,
|
|
672
683
|
isTypeOnly
|
|
673
684
|
};
|
|
674
685
|
}).filter(Boolean);
|
|
@@ -683,10 +694,10 @@ var BarrelManager = class {
|
|
|
683
694
|
} else {
|
|
684
695
|
currentTree.children?.forEach((child) => {
|
|
685
696
|
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(/\.[^.]*$/, "")}`;
|
|
697
|
+
const importPath = child.data.type === "directory" ? `./${child.data.name}/index` : `./${child.data.name.replace(/\.[^.]*$/, "")}`;
|
|
687
698
|
const exports = [
|
|
688
699
|
{
|
|
689
|
-
path: includeExt ?
|
|
700
|
+
path: includeExt ? `${importPath}${extName}` : importPath,
|
|
690
701
|
isTypeOnly
|
|
691
702
|
}
|
|
692
703
|
];
|
|
@@ -1106,44 +1117,6 @@ function setUniqueName(originalName, data) {
|
|
|
1106
1117
|
}
|
|
1107
1118
|
|
|
1108
1119
|
// src/errors.ts
|
|
1109
|
-
var PluginError = class extends Error {
|
|
1110
|
-
constructor(message, options) {
|
|
1111
|
-
super(message, { cause: options.cause });
|
|
1112
|
-
this.name = "PluginError";
|
|
1113
|
-
this.cause = options.cause;
|
|
1114
|
-
this.pluginManager = options.pluginManager;
|
|
1115
|
-
}
|
|
1116
|
-
};
|
|
1117
|
-
var ParallelPluginError = class extends Error {
|
|
1118
|
-
constructor(message, options) {
|
|
1119
|
-
super(message, { cause: options.cause });
|
|
1120
|
-
this.errors = [];
|
|
1121
|
-
this.name = "ParallelPluginError";
|
|
1122
|
-
this.errors = options.errors;
|
|
1123
|
-
this.pluginManager = options.pluginManager;
|
|
1124
|
-
}
|
|
1125
|
-
findError(searchError) {
|
|
1126
|
-
if (!searchError) {
|
|
1127
|
-
return void 0;
|
|
1128
|
-
}
|
|
1129
|
-
return this.errors.find((error) => {
|
|
1130
|
-
if (error.cause) {
|
|
1131
|
-
if (error.cause.name == searchError.name) {
|
|
1132
|
-
return true;
|
|
1133
|
-
}
|
|
1134
|
-
return !!this.findError(error.cause);
|
|
1135
|
-
}
|
|
1136
|
-
return error.name === searchError.name;
|
|
1137
|
-
})?.cause;
|
|
1138
|
-
}
|
|
1139
|
-
};
|
|
1140
|
-
var SummaryError = class extends Error {
|
|
1141
|
-
constructor(message, options) {
|
|
1142
|
-
super(message, { cause: options.cause });
|
|
1143
|
-
this.name = "SummaryError";
|
|
1144
|
-
this.summary = options.summary || [];
|
|
1145
|
-
}
|
|
1146
|
-
};
|
|
1147
1120
|
var Warning = class extends Error {
|
|
1148
1121
|
constructor(message, options) {
|
|
1149
1122
|
super(message, { cause: options?.cause });
|
|
@@ -1360,6 +1333,7 @@ Names: ${JSON.stringify(names, void 0, 2)}`
|
|
|
1360
1333
|
}).result;
|
|
1361
1334
|
return transformReservedWord(name);
|
|
1362
1335
|
};
|
|
1336
|
+
this.config = config;
|
|
1363
1337
|
this.logger = options.logger;
|
|
1364
1338
|
this.queue = new Queue(100, this.logger.logLevel === LogLevel.debug);
|
|
1365
1339
|
this.fileManager = new FileManager({ task: options.task, queue: this.queue, timeout: options.writeTimeout });
|
|
@@ -1488,15 +1462,12 @@ Names: ${JSON.stringify(names, void 0, 2)}`
|
|
|
1488
1462
|
}
|
|
1489
1463
|
}
|
|
1490
1464
|
const results = await Promise.allSettled(parallelPromises);
|
|
1491
|
-
|
|
1492
|
-
if (isPromiseRejectedResult(result)
|
|
1493
|
-
|
|
1465
|
+
results.forEach((result, index) => {
|
|
1466
|
+
if (isPromiseRejectedResult(result)) {
|
|
1467
|
+
const plugin = __privateMethod(this, _getSortedPlugins, getSortedPlugins_fn).call(this)[index];
|
|
1468
|
+
__privateMethod(this, _catcher, catcher_fn).call(this, result.reason, plugin, hookName);
|
|
1494
1469
|
}
|
|
1495
|
-
|
|
1496
|
-
}).filter(Boolean);
|
|
1497
|
-
if (errors.length) {
|
|
1498
|
-
throw new ParallelPluginError("Error", { errors, pluginManager: this });
|
|
1499
|
-
}
|
|
1470
|
+
});
|
|
1500
1471
|
return results.filter((result) => result.status === "fulfilled").map((result) => result.value);
|
|
1501
1472
|
}
|
|
1502
1473
|
/**
|
|
@@ -1630,11 +1601,6 @@ execute_fn = function({
|
|
|
1630
1601
|
return hook;
|
|
1631
1602
|
}).then((result) => {
|
|
1632
1603
|
output = result;
|
|
1633
|
-
return result;
|
|
1634
|
-
}).catch((e) => {
|
|
1635
|
-
__privateMethod(this, _catcher, catcher_fn).call(this, e, plugin, hookName);
|
|
1636
|
-
return null;
|
|
1637
|
-
}).finally(() => {
|
|
1638
1604
|
__privateMethod(this, _addExecutedToCallStack, addExecutedToCallStack_fn).call(this, {
|
|
1639
1605
|
parameters,
|
|
1640
1606
|
output,
|
|
@@ -1642,6 +1608,10 @@ execute_fn = function({
|
|
|
1642
1608
|
hookName,
|
|
1643
1609
|
plugin
|
|
1644
1610
|
});
|
|
1611
|
+
return result;
|
|
1612
|
+
}).catch((e) => {
|
|
1613
|
+
__privateMethod(this, _catcher, catcher_fn).call(this, e, plugin, hookName);
|
|
1614
|
+
return null;
|
|
1645
1615
|
});
|
|
1646
1616
|
return task;
|
|
1647
1617
|
};
|
|
@@ -1665,11 +1635,6 @@ executeSync_fn = function({
|
|
|
1665
1635
|
return fn;
|
|
1666
1636
|
}
|
|
1667
1637
|
output = hook;
|
|
1668
|
-
return hook;
|
|
1669
|
-
} catch (e) {
|
|
1670
|
-
__privateMethod(this, _catcher, catcher_fn).call(this, e, plugin, hookName);
|
|
1671
|
-
return null;
|
|
1672
|
-
} finally {
|
|
1673
1638
|
__privateMethod(this, _addExecutedToCallStack, addExecutedToCallStack_fn).call(this, {
|
|
1674
1639
|
parameters,
|
|
1675
1640
|
output,
|
|
@@ -1677,15 +1642,18 @@ executeSync_fn = function({
|
|
|
1677
1642
|
hookName,
|
|
1678
1643
|
plugin
|
|
1679
1644
|
});
|
|
1645
|
+
return hook;
|
|
1646
|
+
} catch (e) {
|
|
1647
|
+
__privateMethod(this, _catcher, catcher_fn).call(this, e, plugin, hookName);
|
|
1648
|
+
return null;
|
|
1680
1649
|
}
|
|
1681
1650
|
};
|
|
1682
1651
|
_catcher = new WeakSet();
|
|
1683
1652
|
catcher_fn = function(e, plugin, hookName) {
|
|
1684
|
-
const text = `${e.message} (plugin: ${plugin
|
|
1653
|
+
const text = `${e.message} (plugin: ${plugin?.name || "unknown"}, hook: ${hookName || "unknown"})
|
|
1685
1654
|
`;
|
|
1686
|
-
|
|
1687
|
-
this.eventEmitter.emit("error",
|
|
1688
|
-
throw pluginError;
|
|
1655
|
+
this.logger.error(text);
|
|
1656
|
+
this.eventEmitter.emit("error", e);
|
|
1689
1657
|
};
|
|
1690
1658
|
_parse = new WeakSet();
|
|
1691
1659
|
parse_fn = function(plugin, pluginManager, context) {
|
|
@@ -1718,7 +1686,7 @@ parse_fn = function(plugin, pluginManager, context) {
|
|
|
1718
1686
|
async function transformReducer(_previousCode, result, _plugin) {
|
|
1719
1687
|
return result;
|
|
1720
1688
|
}
|
|
1721
|
-
async function
|
|
1689
|
+
async function setup(options) {
|
|
1722
1690
|
const { config, logger = createLogger({ logLevel: LogLevel.silent }) } = options;
|
|
1723
1691
|
try {
|
|
1724
1692
|
if (isInputPath(config) && !new URLPath(config.input.path).isURL) {
|
|
@@ -1772,7 +1740,6 @@ async function build(options) {
|
|
|
1772
1740
|
}
|
|
1773
1741
|
};
|
|
1774
1742
|
const pluginManager = new PluginManager(config, { logger, task: queueTask, writeTimeout: 0 });
|
|
1775
|
-
const { plugins, fileManager } = pluginManager;
|
|
1776
1743
|
pluginManager.on("execute", (executer) => {
|
|
1777
1744
|
const { hookName, parameters, plugin } = executer;
|
|
1778
1745
|
if (hookName === "writeFile" && logger.spinner) {
|
|
@@ -1810,13 +1777,18 @@ ${code}`);
|
|
|
1810
1777
|
console.log(logs.join("\n"));
|
|
1811
1778
|
}
|
|
1812
1779
|
});
|
|
1780
|
+
return pluginManager;
|
|
1781
|
+
}
|
|
1782
|
+
async function build(options) {
|
|
1783
|
+
const pluginManager = await setup(options);
|
|
1784
|
+
const { fileManager, logger } = pluginManager;
|
|
1813
1785
|
await pluginManager.hookParallel({
|
|
1814
1786
|
hookName: "validate",
|
|
1815
|
-
parameters: [plugins]
|
|
1787
|
+
parameters: [pluginManager.plugins]
|
|
1816
1788
|
});
|
|
1817
1789
|
await pluginManager.hookParallel({
|
|
1818
1790
|
hookName: "buildStart",
|
|
1819
|
-
parameters: [config]
|
|
1791
|
+
parameters: [options.config]
|
|
1820
1792
|
});
|
|
1821
1793
|
await pluginManager.hookParallel({ hookName: "buildEnd" });
|
|
1822
1794
|
if (!fileManager.isExecuting && logger.spinner) {
|
|
@@ -1825,6 +1797,28 @@ ${code}`);
|
|
|
1825
1797
|
}
|
|
1826
1798
|
return { files: fileManager.files.map((file) => ({ ...file, source: FileManager.getSource(file) })), pluginManager };
|
|
1827
1799
|
}
|
|
1800
|
+
async function safeBuild(options) {
|
|
1801
|
+
const pluginManager = await setup(options);
|
|
1802
|
+
const { fileManager, logger } = pluginManager;
|
|
1803
|
+
try {
|
|
1804
|
+
await pluginManager.hookParallel({
|
|
1805
|
+
hookName: "validate",
|
|
1806
|
+
parameters: [pluginManager.plugins]
|
|
1807
|
+
});
|
|
1808
|
+
await pluginManager.hookParallel({
|
|
1809
|
+
hookName: "buildStart",
|
|
1810
|
+
parameters: [options.config]
|
|
1811
|
+
});
|
|
1812
|
+
await pluginManager.hookParallel({ hookName: "buildEnd" });
|
|
1813
|
+
if (!fileManager.isExecuting && logger.spinner) {
|
|
1814
|
+
logger.spinner.suffixText = "";
|
|
1815
|
+
logger.spinner.succeed(`\u{1F4BE} Writing completed`);
|
|
1816
|
+
}
|
|
1817
|
+
} catch (e) {
|
|
1818
|
+
return { files: fileManager.files.map((file) => ({ ...file, source: FileManager.getSource(file) })), pluginManager, error: e };
|
|
1819
|
+
}
|
|
1820
|
+
return { files: fileManager.files.map((file) => ({ ...file, source: FileManager.getSource(file) })), pluginManager };
|
|
1821
|
+
}
|
|
1828
1822
|
|
|
1829
1823
|
// src/Generator.ts
|
|
1830
1824
|
var _options3, _context;
|
|
@@ -2212,6 +2206,9 @@ var _PackageManager = class _PackageManager {
|
|
|
2212
2206
|
if (!packageVersion) {
|
|
2213
2207
|
return false;
|
|
2214
2208
|
}
|
|
2209
|
+
if (packageVersion === version) {
|
|
2210
|
+
return true;
|
|
2211
|
+
}
|
|
2215
2212
|
const semVer = semver.coerce(packageVersion);
|
|
2216
2213
|
if (!semVer) {
|
|
2217
2214
|
throw new Error(`${packageVersion} is not valid`);
|
|
@@ -2246,12 +2243,9 @@ var src_default = build;
|
|
|
2246
2243
|
exports.FileManager = FileManager;
|
|
2247
2244
|
exports.Generator = Generator;
|
|
2248
2245
|
exports.PackageManager = PackageManager;
|
|
2249
|
-
exports.ParallelPluginError = ParallelPluginError;
|
|
2250
|
-
exports.PluginError = PluginError;
|
|
2251
2246
|
exports.PluginManager = PluginManager;
|
|
2252
2247
|
exports.PromiseManager = PromiseManager;
|
|
2253
2248
|
exports.SchemaGenerator = SchemaGenerator;
|
|
2254
|
-
exports.SummaryError = SummaryError;
|
|
2255
2249
|
exports.ValidationPluginError = ValidationPluginError;
|
|
2256
2250
|
exports.Warning = Warning;
|
|
2257
2251
|
exports.build = build;
|
|
@@ -2263,5 +2257,6 @@ exports.defineConfig = defineConfig;
|
|
|
2263
2257
|
exports.isInputPath = isInputPath;
|
|
2264
2258
|
exports.name = pluginName;
|
|
2265
2259
|
exports.pluginName = pluginName;
|
|
2260
|
+
exports.safeBuild = safeBuild;
|
|
2266
2261
|
//# sourceMappingURL=out.js.map
|
|
2267
2262
|
//# sourceMappingURL=index.cjs.map
|