@kubb/core 0.41.1 → 0.42.0

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 = {
@@ -233,6 +233,7 @@ declare class FileManager {
233
233
  private getSource;
234
234
  get files(): File[];
235
235
  add(file: File): Promise<File>;
236
+ addOrAppend(file: File): Promise<File>;
236
237
  build(file: File): {
237
238
  source: string;
238
239
  fileName: string;
@@ -243,7 +244,7 @@ declare class FileManager {
243
244
  type?: boolean | undefined;
244
245
  }[] | undefined;
245
246
  };
246
- addOrAppend(file: File): Promise<File>;
247
+ combine(files: Array<File | null>): File[];
247
248
  setStatus(id: UUID, status: Status): void;
248
249
  get(id: UUID): File | undefined;
249
250
  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,29 @@ ${file.source}`,
17266
17263
  }
17267
17264
  return this.add(file);
17268
17265
  }
17266
+ build(file) {
17267
+ return {
17268
+ ...file,
17269
+ source: this.getSource(file)
17270
+ };
17271
+ }
17272
+ combine(files) {
17273
+ return files.filter(Boolean).reduce((acc, curr) => {
17274
+ const prevIndex = acc.findIndex((item) => item.path === curr.path);
17275
+ if (prevIndex !== -1) {
17276
+ const prev = acc[prevIndex];
17277
+ acc[prevIndex] = {
17278
+ ...curr,
17279
+ source: `${prev.source}
17280
+ ${curr.source}`,
17281
+ imports: [...prev.imports || [], ...curr.imports || []]
17282
+ };
17283
+ } else {
17284
+ acc.push(curr);
17285
+ }
17286
+ return acc;
17287
+ }, []);
17288
+ }
17269
17289
  setStatus(id, status) {
17270
17290
  const cacheItem = this.getCache(id);
17271
17291
  if (!cacheItem) {