@kubb/core 0.41.1 → 0.42.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 CHANGED
@@ -183,7 +183,7 @@ declare const clean: (path: string) => Promise<unknown>;
183
183
 
184
184
  declare const getRelativePath: (root?: string | null, file?: string | null) => string;
185
185
  type PathMode = 'file' | 'directory';
186
- declare const getPathMode: (path: string | undefined | null) => PathMode | undefined;
186
+ declare const getPathMode: (path: string | undefined | null) => PathMode;
187
187
  declare const read: (path: string) => Promise<string>;
188
188
 
189
189
  type Import = {
@@ -230,20 +230,11 @@ declare class FileManager {
230
230
  private getCache;
231
231
  private getCacheByPath;
232
232
  private getCountByStatus;
233
- private getSource;
233
+ getSource(file: File): string;
234
234
  get files(): File[];
235
235
  add(file: File): Promise<File>;
236
- build(file: File): {
237
- source: string;
238
- fileName: string;
239
- path: string;
240
- imports?: {
241
- name: string | string[];
242
- path: string;
243
- type?: boolean | undefined;
244
- }[] | undefined;
245
- };
246
236
  addOrAppend(file: File): Promise<File>;
237
+ combine(files: Array<File | null>): File[];
247
238
  setStatus(id: UUID, status: Status): void;
248
239
  get(id: UUID): File | undefined;
249
240
  remove(id: UUID): void;
@@ -16991,7 +16991,7 @@ var kubb = (function (exports) {
16991
16991
  };
16992
16992
  var getPathMode = (path) => {
16993
16993
  if (!path) {
16994
- return void 0;
16994
+ return "directory";
16995
16995
  }
16996
16996
  return import_path2.default.extname(path) ? "file" : "directory";
16997
16997
  };
@@ -17204,6 +17204,9 @@ var kubb = (function (exports) {
17204
17204
  return count;
17205
17205
  }
17206
17206
  getSource(file) {
17207
+ if (!file.fileName.endsWith(".ts")) {
17208
+ return file.source;
17209
+ }
17207
17210
  const imports = [];
17208
17211
  file.imports?.forEach((curr) => {
17209
17212
  const exists = imports.find((imp) => imp.path === curr.path);
@@ -17247,12 +17250,6 @@ ${file.source}`;
17247
17250
  });
17248
17251
  });
17249
17252
  }
17250
- build(file) {
17251
- return {
17252
- ...file,
17253
- source: this.getSource(file)
17254
- };
17255
- }
17256
17253
  addOrAppend(file) {
17257
17254
  const previousCache = this.getCacheByPath(file.path);
17258
17255
  if (previousCache) {
@@ -17266,6 +17263,23 @@ ${file.source}`,
17266
17263
  }
17267
17264
  return this.add(file);
17268
17265
  }
17266
+ combine(files) {
17267
+ return files.filter(Boolean).reduce((acc, curr) => {
17268
+ const prevIndex = acc.findIndex((item) => item.path === curr.path);
17269
+ if (prevIndex !== -1) {
17270
+ const prev = acc[prevIndex];
17271
+ acc[prevIndex] = {
17272
+ ...curr,
17273
+ source: `${prev.source}
17274
+ ${curr.source}`,
17275
+ imports: [...prev.imports || [], ...curr.imports || []]
17276
+ };
17277
+ } else {
17278
+ acc.push(curr);
17279
+ }
17280
+ return acc;
17281
+ }, []);
17282
+ }
17269
17283
  setStatus(id, status) {
17270
17284
  const cacheItem = this.getCache(id);
17271
17285
  if (!cacheItem) {
@@ -17592,12 +17606,12 @@ ${file.source}`,
17592
17606
  fileManager.events.onSuccess(async () => {
17593
17607
  await pluginManager.hookParallel("buildEnd");
17594
17608
  setTimeout(() => {
17595
- done({ files: fileManager.files.map((file) => fileManager.build(file)) });
17609
+ done({ files: fileManager.files.map((file) => ({ ...file, source: fileManager.getSource(file) })) });
17596
17610
  }, 1e3);
17597
17611
  });
17598
17612
  fileManager.events.onAdd(async (id, file) => {
17599
17613
  const { path } = file;
17600
- let { source: code } = fileManager.build(file);
17614
+ let code = fileManager.getSource(file);
17601
17615
  const loadedResult = await pluginManager.hookFirst("load", [path]);
17602
17616
  if (loadedResult) {
17603
17617
  code = loadedResult;