@kubb/core 0.38.0 → 0.39.1
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.d.ts +7 -0
- package/dist/index.global.js +27 -2
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +27 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +27 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -202,6 +202,11 @@ type EmittedFile = {
|
|
|
202
202
|
source?: string;
|
|
203
203
|
options?: Record<string, any>;
|
|
204
204
|
};
|
|
205
|
+
type Import = {
|
|
206
|
+
name: string | string[];
|
|
207
|
+
path: string;
|
|
208
|
+
type?: boolean;
|
|
209
|
+
};
|
|
205
210
|
type File = {
|
|
206
211
|
/**
|
|
207
212
|
* Name to be used to dynamicly create the fileName(based on input.path)
|
|
@@ -212,6 +217,7 @@ type File = {
|
|
|
212
217
|
*/
|
|
213
218
|
path: string;
|
|
214
219
|
source: string;
|
|
220
|
+
imports?: Import[];
|
|
215
221
|
};
|
|
216
222
|
type UUID = string;
|
|
217
223
|
type CacheStore = {
|
|
@@ -242,6 +248,7 @@ declare class FileManager {
|
|
|
242
248
|
private getCountByStatus;
|
|
243
249
|
get files(): File[];
|
|
244
250
|
add(file: File): Promise<File>;
|
|
251
|
+
build(file: File): string;
|
|
245
252
|
addOrAppend(file: File): Promise<File>;
|
|
246
253
|
setStatus(id: UUID, status: Status): void;
|
|
247
254
|
get(id: UUID): File | undefined;
|
package/dist/index.global.js
CHANGED
|
@@ -16901,6 +16901,30 @@ var kubb = (function (exports) {
|
|
|
16901
16901
|
});
|
|
16902
16902
|
});
|
|
16903
16903
|
}
|
|
16904
|
+
build(file) {
|
|
16905
|
+
const imports = [];
|
|
16906
|
+
file.imports?.forEach((curr) => {
|
|
16907
|
+
const exists = imports.find((imp) => imp.path === curr.path);
|
|
16908
|
+
if (exists) {
|
|
16909
|
+
exists.name = [...exists.name, ...curr.name];
|
|
16910
|
+
} else {
|
|
16911
|
+
imports.push(curr);
|
|
16912
|
+
}
|
|
16913
|
+
});
|
|
16914
|
+
const importSource = imports.reduce((prev, curr) => {
|
|
16915
|
+
if (Array.isArray(curr.name)) {
|
|
16916
|
+
return `${prev}
|
|
16917
|
+
import ${curr.type ? "type " : ""}{ ${curr.name.join(",")} } from "${curr.path}";`;
|
|
16918
|
+
}
|
|
16919
|
+
return `${prev}
|
|
16920
|
+
import ${curr.type ? "type " : ""}${curr.name} from "${curr.path}";`;
|
|
16921
|
+
}, "");
|
|
16922
|
+
if (importSource) {
|
|
16923
|
+
return `${importSource}
|
|
16924
|
+
${file.source}`;
|
|
16925
|
+
}
|
|
16926
|
+
return file.source;
|
|
16927
|
+
}
|
|
16904
16928
|
addOrAppend(file) {
|
|
16905
16929
|
const previousCache = this.getCacheByPath(file.path);
|
|
16906
16930
|
if (previousCache) {
|
|
@@ -16908,7 +16932,8 @@ var kubb = (function (exports) {
|
|
|
16908
16932
|
return this.add({
|
|
16909
16933
|
...file,
|
|
16910
16934
|
source: `${previousCache.file.source}
|
|
16911
|
-
${file.source}
|
|
16935
|
+
${file.source}`,
|
|
16936
|
+
imports: [...previousCache.file.imports || [], ...file.imports || []]
|
|
16912
16937
|
});
|
|
16913
16938
|
}
|
|
16914
16939
|
return this.add(file);
|
|
@@ -17244,7 +17269,7 @@ ${file.source}`
|
|
|
17244
17269
|
});
|
|
17245
17270
|
fileManager.events.onAdd(async (id, file) => {
|
|
17246
17271
|
const { path } = file;
|
|
17247
|
-
let
|
|
17272
|
+
let code = fileManager.build(file);
|
|
17248
17273
|
const loadedResult = await pluginManager.hookFirst("load", [path]);
|
|
17249
17274
|
if (loadedResult) {
|
|
17250
17275
|
code = loadedResult;
|