@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.js
CHANGED
|
@@ -14,6 +14,7 @@ import pc3 from 'picocolors';
|
|
|
14
14
|
export { default as pc } from 'picocolors';
|
|
15
15
|
import seedrandom from 'seedrandom';
|
|
16
16
|
import { createImportDeclaration, print, createExportDeclaration } from '@kubb/ts-codegen';
|
|
17
|
+
import isEqual from 'lodash.isequal';
|
|
17
18
|
import { EventEmitter as EventEmitter$1 } from 'node:events';
|
|
18
19
|
|
|
19
20
|
createRequire(import.meta.url);
|
|
@@ -753,56 +754,78 @@ var extensions = [".js", ".ts", ".tsx"];
|
|
|
753
754
|
function isExtensionAllowed(fileName) {
|
|
754
755
|
return extensions.some((extension) => fileName.endsWith(extension));
|
|
755
756
|
}
|
|
756
|
-
function
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
if (!existingImport) {
|
|
766
|
-
imports.push({
|
|
767
|
-
...curr,
|
|
768
|
-
name: Array.isArray(curr.name) ? [...new Set(curr.name)] : curr.name
|
|
769
|
-
});
|
|
757
|
+
function combineExports(exports) {
|
|
758
|
+
return exports.reduce((prev, curr) => {
|
|
759
|
+
const name = curr.name;
|
|
760
|
+
const prevByPath = prev.findLast((imp) => imp.path === curr.path);
|
|
761
|
+
const uniquePrev = prev.findLast(
|
|
762
|
+
(imp) => imp.path === curr.path && isEqual(imp.name, name) && imp.isTypeOnly === curr.isTypeOnly && imp.asAlias === curr.asAlias
|
|
763
|
+
);
|
|
764
|
+
if (uniquePrev || Array.isArray(name) && !name.length || prevByPath?.asAlias && !curr.asAlias) {
|
|
765
|
+
return prev;
|
|
770
766
|
}
|
|
771
|
-
if (
|
|
772
|
-
|
|
767
|
+
if (!prevByPath) {
|
|
768
|
+
return [
|
|
769
|
+
...prev,
|
|
770
|
+
{
|
|
771
|
+
...curr,
|
|
772
|
+
name: Array.isArray(name) ? [...new Set(name)] : name
|
|
773
|
+
}
|
|
774
|
+
];
|
|
773
775
|
}
|
|
774
|
-
if (
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
}
|
|
776
|
+
if (prevByPath && Array.isArray(prevByPath.name) && Array.isArray(curr.name) && prevByPath.isTypeOnly === curr.isTypeOnly) {
|
|
777
|
+
prevByPath.name = [.../* @__PURE__ */ new Set([...prevByPath.name, ...curr.name])];
|
|
778
|
+
return prev;
|
|
778
779
|
}
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
});
|
|
780
|
+
return [...prev, curr];
|
|
781
|
+
}, []);
|
|
782
|
+
}
|
|
783
|
+
function combineImports(imports, exports, source) {
|
|
784
|
+
return imports.reduce((prev, curr) => {
|
|
785
|
+
let name = Array.isArray(curr.name) ? [...new Set(curr.name)] : curr.name;
|
|
786
|
+
const hasImportInSource = (importName) => {
|
|
787
|
+
const checker = (name2) => name2 && !!source.includes(`${name2}`);
|
|
788
|
+
return checker(importName) || exports.some(({ name: name2 }) => Array.isArray(name2) ? name2.some(checker) : checker(name2));
|
|
789
|
+
};
|
|
790
|
+
if (Array.isArray(name)) {
|
|
791
|
+
name = name.filter((item) => hasImportInSource(item));
|
|
787
792
|
}
|
|
788
|
-
|
|
789
|
-
|
|
793
|
+
const prevByPath = prev.findLast((imp) => imp.path === curr.path && imp.isTypeOnly === curr.isTypeOnly);
|
|
794
|
+
const uniquePrev = prev.findLast((imp) => imp.path === curr.path && isEqual(imp.name, name) && imp.isTypeOnly === curr.isTypeOnly);
|
|
795
|
+
if (uniquePrev || Array.isArray(name) && !name.length) {
|
|
796
|
+
return prev;
|
|
790
797
|
}
|
|
791
|
-
if (
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
798
|
+
if (!prevByPath) {
|
|
799
|
+
return [
|
|
800
|
+
...prev,
|
|
801
|
+
{
|
|
802
|
+
...curr,
|
|
803
|
+
name
|
|
804
|
+
}
|
|
805
|
+
];
|
|
795
806
|
}
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
807
|
+
if (prevByPath && Array.isArray(prevByPath.name) && Array.isArray(name) && prevByPath.isTypeOnly === curr.isTypeOnly) {
|
|
808
|
+
prevByPath.name = [.../* @__PURE__ */ new Set([...prevByPath.name, ...name])];
|
|
809
|
+
return prev;
|
|
810
|
+
}
|
|
811
|
+
if (!Array.isArray(name) && name && !hasImportInSource(name)) {
|
|
812
|
+
return prev;
|
|
813
|
+
}
|
|
814
|
+
return [...prev, curr];
|
|
799
815
|
}, []);
|
|
816
|
+
}
|
|
817
|
+
function createFileSource(file) {
|
|
818
|
+
let { source } = file;
|
|
819
|
+
if (!isExtensionAllowed(file.fileName)) {
|
|
820
|
+
return file.source;
|
|
821
|
+
}
|
|
822
|
+
const exports = file.exports ? combineExports(file.exports) : [];
|
|
823
|
+
const imports = file.imports ? combineImports(file.imports, exports, source) : [];
|
|
824
|
+
const importNodes = imports.map((item) => createImportDeclaration({ name: item.name, path: item.path, isTypeOnly: item.isTypeOnly }));
|
|
800
825
|
const importSource = print(importNodes);
|
|
801
|
-
const exportNodes = exports.
|
|
802
|
-
return [...prev, createExportDeclaration({ name: curr.name, path: curr.path, isTypeOnly: curr.isTypeOnly, asAlias: curr.asAlias })];
|
|
803
|
-
}, []);
|
|
826
|
+
const exportNodes = exports.map((item) => createExportDeclaration({ name: item.name, path: item.path, isTypeOnly: item.isTypeOnly, asAlias: item.asAlias }));
|
|
804
827
|
const exportSource = print(exportNodes);
|
|
805
|
-
source = getEnvSource(source, file.env);
|
|
828
|
+
source = getEnvSource(file.source, file.env);
|
|
806
829
|
if (importSource) {
|
|
807
830
|
source = `${importSource}
|
|
808
831
|
${source}`;
|
|
@@ -1462,7 +1485,7 @@ async function build(options) {
|
|
|
1462
1485
|
}
|
|
1463
1486
|
const queueTask = async (file) => {
|
|
1464
1487
|
const { path } = file;
|
|
1465
|
-
let code =
|
|
1488
|
+
let code = createFileSource(file);
|
|
1466
1489
|
const { result: loadedResult } = await pluginManager.hookFirst({
|
|
1467
1490
|
hookName: "load",
|
|
1468
1491
|
parameters: [path]
|
|
@@ -1517,7 +1540,7 @@ async function build(options) {
|
|
|
1517
1540
|
parameters: [config]
|
|
1518
1541
|
});
|
|
1519
1542
|
await pluginManager.hookParallel({ hookName: "buildEnd" });
|
|
1520
|
-
return { files: fileManager.files.map((file) => ({ ...file, source:
|
|
1543
|
+
return { files: fileManager.files.map((file) => ({ ...file, source: createFileSource(file) })), pluginManager };
|
|
1521
1544
|
}
|
|
1522
1545
|
|
|
1523
1546
|
// src/config.ts
|
|
@@ -1549,6 +1572,6 @@ var SchemaGenerator = class extends Generator {
|
|
|
1549
1572
|
// src/index.ts
|
|
1550
1573
|
var src_default = build;
|
|
1551
1574
|
|
|
1552
|
-
export { FileManager, Generator, LogLevel, ParallelPluginError, PluginError, PluginManager, Queue, SchemaGenerator, SummaryError, TreeNode, URLPath, ValidationPluginError, Warning, build, clean, combineCodes, combineFiles, createFunctionParams, createJSDocBlockText, createLogger, createPlugin, createPluginCache, src_default as default, defaultColours, defineConfig, escape, extensions, getDependedPlugins,
|
|
1575
|
+
export { FileManager, Generator, LogLevel, ParallelPluginError, PluginError, PluginManager, Queue, SchemaGenerator, SummaryError, TreeNode, URLPath, ValidationPluginError, Warning, build, clean, combineCodes, combineExports, combineFiles, combineImports, createFileSource, createFunctionParams, createJSDocBlockText, createLogger, createPlugin, createPluginCache, src_default as default, defaultColours, defineConfig, escape, extensions, getDependedPlugins, getIndexes, getLocation, getPathMode, getRelativePath, getUniqueName, hooks, importModule, isExtensionAllowed, isPromise, isPromiseFulfilledResult, isPromiseRejectedResult, jsStringEscape, pluginName as name, nameSorter, normalizeDirectory, pluginName, randomColour, randomPicoColour, read, renderTemplate, throttle, timeout, transformReservedWord, uniqueIdFactory, write };
|
|
1553
1576
|
//# sourceMappingURL=out.js.map
|
|
1554
1577
|
//# sourceMappingURL=index.js.map
|