@kubb/core 1.10.0-canary.20230929T105611 → 1.10.0-canary.20231006T194337
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 -44
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -2
- package/dist/index.d.ts +4 -2
- package/dist/index.js +67 -44
- package/dist/index.js.map +1 -1
- package/package.json +4 -2
package/dist/index.cjs
CHANGED
|
@@ -16,6 +16,7 @@ var os = require('os');
|
|
|
16
16
|
var pc3 = require('picocolors');
|
|
17
17
|
var seedrandom = require('seedrandom');
|
|
18
18
|
var tsCodegen = require('@kubb/ts-codegen');
|
|
19
|
+
var isEqual = require('lodash.isequal');
|
|
19
20
|
var events = require('events');
|
|
20
21
|
|
|
21
22
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
@@ -28,6 +29,7 @@ var mod__default = /*#__PURE__*/_interopDefault(mod);
|
|
|
28
29
|
var os__default = /*#__PURE__*/_interopDefault(os);
|
|
29
30
|
var pc3__default = /*#__PURE__*/_interopDefault(pc3);
|
|
30
31
|
var seedrandom__default = /*#__PURE__*/_interopDefault(seedrandom);
|
|
32
|
+
var isEqual__default = /*#__PURE__*/_interopDefault(isEqual);
|
|
31
33
|
|
|
32
34
|
// src/managers/fileManager/FileManager.ts
|
|
33
35
|
|
|
@@ -766,56 +768,78 @@ var extensions = [".js", ".ts", ".tsx"];
|
|
|
766
768
|
function isExtensionAllowed(fileName) {
|
|
767
769
|
return extensions.some((extension) => fileName.endsWith(extension));
|
|
768
770
|
}
|
|
769
|
-
function
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
if (!existingImport) {
|
|
779
|
-
imports.push({
|
|
780
|
-
...curr,
|
|
781
|
-
name: Array.isArray(curr.name) ? [...new Set(curr.name)] : curr.name
|
|
782
|
-
});
|
|
771
|
+
function combineExports(exports) {
|
|
772
|
+
return exports.reduce((prev, curr) => {
|
|
773
|
+
const name = curr.name;
|
|
774
|
+
const prevByPath = prev.findLast((imp) => imp.path === curr.path);
|
|
775
|
+
const uniquePrev = prev.findLast(
|
|
776
|
+
(imp) => imp.path === curr.path && isEqual__default.default(imp.name, name) && imp.isTypeOnly === curr.isTypeOnly && imp.asAlias === curr.asAlias
|
|
777
|
+
);
|
|
778
|
+
if (uniquePrev || Array.isArray(name) && !name.length || prevByPath?.asAlias && !curr.asAlias) {
|
|
779
|
+
return prev;
|
|
783
780
|
}
|
|
784
|
-
if (
|
|
785
|
-
|
|
781
|
+
if (!prevByPath) {
|
|
782
|
+
return [
|
|
783
|
+
...prev,
|
|
784
|
+
{
|
|
785
|
+
...curr,
|
|
786
|
+
name: Array.isArray(name) ? [...new Set(name)] : name
|
|
787
|
+
}
|
|
788
|
+
];
|
|
786
789
|
}
|
|
787
|
-
if (
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
}
|
|
790
|
+
if (prevByPath && Array.isArray(prevByPath.name) && Array.isArray(curr.name) && prevByPath.isTypeOnly === curr.isTypeOnly) {
|
|
791
|
+
prevByPath.name = [.../* @__PURE__ */ new Set([...prevByPath.name, ...curr.name])];
|
|
792
|
+
return prev;
|
|
791
793
|
}
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
});
|
|
794
|
+
return [...prev, curr];
|
|
795
|
+
}, []);
|
|
796
|
+
}
|
|
797
|
+
function combineImports(imports, exports, source) {
|
|
798
|
+
return imports.reduce((prev, curr) => {
|
|
799
|
+
let name = Array.isArray(curr.name) ? [...new Set(curr.name)] : curr.name;
|
|
800
|
+
const hasImportInSource = (importName) => {
|
|
801
|
+
const checker = (name2) => name2 && !!source.includes(`${name2}`);
|
|
802
|
+
return checker(importName) || exports.some(({ name: name2 }) => Array.isArray(name2) ? name2.some(checker) : checker(name2));
|
|
803
|
+
};
|
|
804
|
+
if (Array.isArray(name)) {
|
|
805
|
+
name = name.filter((item) => hasImportInSource(item));
|
|
800
806
|
}
|
|
801
|
-
|
|
802
|
-
|
|
807
|
+
const prevByPath = prev.findLast((imp) => imp.path === curr.path && imp.isTypeOnly === curr.isTypeOnly);
|
|
808
|
+
const uniquePrev = prev.findLast((imp) => imp.path === curr.path && isEqual__default.default(imp.name, name) && imp.isTypeOnly === curr.isTypeOnly);
|
|
809
|
+
if (uniquePrev || Array.isArray(name) && !name.length) {
|
|
810
|
+
return prev;
|
|
803
811
|
}
|
|
804
|
-
if (
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
812
|
+
if (!prevByPath) {
|
|
813
|
+
return [
|
|
814
|
+
...prev,
|
|
815
|
+
{
|
|
816
|
+
...curr,
|
|
817
|
+
name
|
|
818
|
+
}
|
|
819
|
+
];
|
|
808
820
|
}
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
821
|
+
if (prevByPath && Array.isArray(prevByPath.name) && Array.isArray(name) && prevByPath.isTypeOnly === curr.isTypeOnly) {
|
|
822
|
+
prevByPath.name = [.../* @__PURE__ */ new Set([...prevByPath.name, ...name])];
|
|
823
|
+
return prev;
|
|
824
|
+
}
|
|
825
|
+
if (!Array.isArray(name) && name && !hasImportInSource(name)) {
|
|
826
|
+
return prev;
|
|
827
|
+
}
|
|
828
|
+
return [...prev, curr];
|
|
812
829
|
}, []);
|
|
830
|
+
}
|
|
831
|
+
function createFileSource(file) {
|
|
832
|
+
let { source } = file;
|
|
833
|
+
if (!isExtensionAllowed(file.fileName)) {
|
|
834
|
+
return file.source;
|
|
835
|
+
}
|
|
836
|
+
const exports = file.exports ? combineExports(file.exports) : [];
|
|
837
|
+
const imports = file.imports ? combineImports(file.imports, exports, source) : [];
|
|
838
|
+
const importNodes = imports.map((item) => tsCodegen.createImportDeclaration({ name: item.name, path: item.path, isTypeOnly: item.isTypeOnly }));
|
|
813
839
|
const importSource = tsCodegen.print(importNodes);
|
|
814
|
-
const exportNodes = exports.
|
|
815
|
-
return [...prev, tsCodegen.createExportDeclaration({ name: curr.name, path: curr.path, isTypeOnly: curr.isTypeOnly, asAlias: curr.asAlias })];
|
|
816
|
-
}, []);
|
|
840
|
+
const exportNodes = exports.map((item) => tsCodegen.createExportDeclaration({ name: item.name, path: item.path, isTypeOnly: item.isTypeOnly, asAlias: item.asAlias }));
|
|
817
841
|
const exportSource = tsCodegen.print(exportNodes);
|
|
818
|
-
source = getEnvSource(source, file.env);
|
|
842
|
+
source = getEnvSource(file.source, file.env);
|
|
819
843
|
if (importSource) {
|
|
820
844
|
source = `${importSource}
|
|
821
845
|
${source}`;
|
|
@@ -1475,7 +1499,7 @@ async function build(options) {
|
|
|
1475
1499
|
}
|
|
1476
1500
|
const queueTask = async (file) => {
|
|
1477
1501
|
const { path } = file;
|
|
1478
|
-
let code =
|
|
1502
|
+
let code = createFileSource(file);
|
|
1479
1503
|
const { result: loadedResult } = await pluginManager.hookFirst({
|
|
1480
1504
|
hookName: "load",
|
|
1481
1505
|
parameters: [path]
|
|
@@ -1530,7 +1554,7 @@ async function build(options) {
|
|
|
1530
1554
|
parameters: [config]
|
|
1531
1555
|
});
|
|
1532
1556
|
await pluginManager.hookParallel({ hookName: "buildEnd" });
|
|
1533
|
-
return { files: fileManager.files.map((file) => ({ ...file, source:
|
|
1557
|
+
return { files: fileManager.files.map((file) => ({ ...file, source: createFileSource(file) })), pluginManager };
|
|
1534
1558
|
}
|
|
1535
1559
|
|
|
1536
1560
|
// src/config.ts
|
|
@@ -1582,7 +1606,10 @@ exports.Warning = Warning;
|
|
|
1582
1606
|
exports.build = build;
|
|
1583
1607
|
exports.clean = clean;
|
|
1584
1608
|
exports.combineCodes = combineCodes;
|
|
1609
|
+
exports.combineExports = combineExports;
|
|
1585
1610
|
exports.combineFiles = combineFiles;
|
|
1611
|
+
exports.combineImports = combineImports;
|
|
1612
|
+
exports.createFileSource = createFileSource;
|
|
1586
1613
|
exports.createFunctionParams = createFunctionParams;
|
|
1587
1614
|
exports.createJSDocBlockText = createJSDocBlockText;
|
|
1588
1615
|
exports.createLogger = createLogger;
|
|
@@ -1594,7 +1621,6 @@ exports.defineConfig = defineConfig;
|
|
|
1594
1621
|
exports.escape = escape;
|
|
1595
1622
|
exports.extensions = extensions;
|
|
1596
1623
|
exports.getDependedPlugins = getDependedPlugins;
|
|
1597
|
-
exports.getFileSource = getFileSource;
|
|
1598
1624
|
exports.getIndexes = getIndexes;
|
|
1599
1625
|
exports.getLocation = getLocation;
|
|
1600
1626
|
exports.getPathMode = getPathMode;
|