@kubb/core 3.0.0-alpha.4 → 3.0.0-alpha.6

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.
Files changed (73) hide show
  1. package/dist/{FileManager-CaejIVBd.d.ts → FileManager-Ceski1W9.d.ts} +47 -47
  2. package/dist/{FileManager--scIq4y4.d.cts → FileManager-wyXRkgIk.d.cts} +47 -47
  3. package/dist/chunk-2EU7DMPM.js +97 -0
  4. package/dist/chunk-2EU7DMPM.js.map +1 -0
  5. package/dist/chunk-5HN4LW3R.cjs +102 -0
  6. package/dist/chunk-5HN4LW3R.cjs.map +1 -0
  7. package/dist/{chunk-EFQPHF4E.js → chunk-76UEJFFE.js} +1 -4
  8. package/dist/chunk-76UEJFFE.js.map +1 -0
  9. package/dist/{chunk-5JZNFPUP.js → chunk-AWAZR3D5.js} +61 -10
  10. package/dist/chunk-AWAZR3D5.js.map +1 -0
  11. package/dist/{chunk-V5THHXXQ.cjs → chunk-DCZQYCCO.cjs} +218 -299
  12. package/dist/chunk-DCZQYCCO.cjs.map +1 -0
  13. package/dist/{chunk-YTSNYMHW.cjs → chunk-L3JJLZ5Q.cjs} +62 -11
  14. package/dist/chunk-L3JJLZ5Q.cjs.map +1 -0
  15. package/dist/{chunk-QRIDQ4RG.cjs → chunk-LOLEBOMW.cjs} +1 -4
  16. package/dist/chunk-LOLEBOMW.cjs.map +1 -0
  17. package/dist/chunk-RIEGCND2.js +525 -0
  18. package/dist/chunk-RIEGCND2.js.map +1 -0
  19. package/dist/index.cjs +81 -75
  20. package/dist/index.cjs.map +1 -1
  21. package/dist/index.d.cts +4 -6
  22. package/dist/index.d.ts +4 -6
  23. package/dist/index.js +68 -64
  24. package/dist/index.js.map +1 -1
  25. package/dist/{logger-dzAcLeAA.d.cts → logger-BWFeedRk.d.cts} +17 -2
  26. package/dist/{logger-dzAcLeAA.d.ts → logger-BWFeedRk.d.ts} +17 -2
  27. package/dist/logger.cjs +2 -2
  28. package/dist/logger.d.cts +1 -1
  29. package/dist/logger.d.ts +1 -1
  30. package/dist/logger.js +1 -1
  31. package/dist/mocks.cjs +4 -6
  32. package/dist/mocks.cjs.map +1 -1
  33. package/dist/mocks.d.cts +3 -5
  34. package/dist/mocks.d.ts +3 -5
  35. package/dist/mocks.js +5 -7
  36. package/dist/mocks.js.map +1 -1
  37. package/dist/transformers.cjs +189 -33
  38. package/dist/transformers.cjs.map +1 -1
  39. package/dist/transformers.d.cts +1 -3
  40. package/dist/transformers.d.ts +1 -3
  41. package/dist/transformers.js +156 -14
  42. package/dist/transformers.js.map +1 -1
  43. package/dist/utils.cjs +6 -2
  44. package/dist/utils.cjs.map +1 -1
  45. package/dist/utils.d.cts +30 -3
  46. package/dist/utils.d.ts +30 -3
  47. package/dist/utils.js +7 -3
  48. package/package.json +9 -8
  49. package/src/BarrelManager.ts +27 -93
  50. package/src/FileManager.ts +165 -266
  51. package/src/PackageManager.ts +1 -1
  52. package/src/PluginManager.ts +89 -57
  53. package/src/build.ts +7 -26
  54. package/src/logger.ts +6 -7
  55. package/src/transformers/index.ts +2 -3
  56. package/src/transformers/trim.ts +0 -4
  57. package/src/types.ts +1 -1
  58. package/src/utils/TreeNode.ts +91 -26
  59. package/src/utils/executeStrategies.ts +1 -1
  60. package/src/utils/index.ts +2 -1
  61. package/src/utils/parser.ts +96 -0
  62. package/dist/chunk-5JZNFPUP.js.map +0 -1
  63. package/dist/chunk-EFQPHF4E.js.map +0 -1
  64. package/dist/chunk-JKZG2IJR.js +0 -283
  65. package/dist/chunk-JKZG2IJR.js.map +0 -1
  66. package/dist/chunk-PZT4CTBV.cjs +0 -299
  67. package/dist/chunk-PZT4CTBV.cjs.map +0 -1
  68. package/dist/chunk-QRIDQ4RG.cjs.map +0 -1
  69. package/dist/chunk-UUBPTMRW.js +0 -608
  70. package/dist/chunk-UUBPTMRW.js.map +0 -1
  71. package/dist/chunk-V5THHXXQ.cjs.map +0 -1
  72. package/dist/chunk-YTSNYMHW.cjs.map +0 -1
  73. package/src/utils/getParser.ts +0 -17
@@ -1,608 +0,0 @@
1
- import {
2
- searchAndReplace,
3
- transformers_default,
4
- trimExtName
5
- } from "./chunk-JKZG2IJR.js";
6
- import {
7
- getParser
8
- } from "./chunk-5JZNFPUP.js";
9
- import {
10
- orderBy
11
- } from "./chunk-4X5FFJPJ.js";
12
- import {
13
- __privateAdd,
14
- __privateGet,
15
- __privateMethod,
16
- __privateSet
17
- } from "./chunk-HMLY7DHA.js";
18
-
19
- // src/FileManager.ts
20
- import crypto from "crypto";
21
- import { extname, resolve } from "path";
22
- import { isDeepEqual } from "remeda";
23
- import { getRelativePath, read, write } from "@kubb/fs";
24
-
25
- // src/BarrelManager.ts
26
- import { getExports } from "@kubb/parser-ts";
27
- import path from "path";
28
-
29
- // src/utils/TreeNode.ts
30
- import dirTree from "directory-tree";
31
- var TreeNode = class _TreeNode {
32
- constructor(data, parent) {
33
- this.children = [];
34
- this.data = data;
35
- this.parent = parent;
36
- return this;
37
- }
38
- addChild(data) {
39
- const child = new _TreeNode(data, this);
40
- if (!this.children) {
41
- this.children = [];
42
- }
43
- this.children.push(child);
44
- return child;
45
- }
46
- find(data) {
47
- if (!data) {
48
- return null;
49
- }
50
- if (data === this.data) {
51
- return this;
52
- }
53
- if (this.children?.length) {
54
- for (let i = 0, { length } = this.children, target = null; i < length; i++) {
55
- target = this.children[i].find(data);
56
- if (target) {
57
- return target;
58
- }
59
- }
60
- }
61
- return null;
62
- }
63
- get leaves() {
64
- if (!this.children || this.children.length === 0) {
65
- return [this];
66
- }
67
- const leaves = [];
68
- if (this.children) {
69
- for (let i = 0, { length } = this.children; i < length; i++) {
70
- leaves.push.apply(leaves, this.children[i].leaves);
71
- }
72
- }
73
- return leaves;
74
- }
75
- get root() {
76
- if (!this.parent) {
77
- return this;
78
- }
79
- return this.parent.root;
80
- }
81
- forEach(callback) {
82
- if (typeof callback !== "function") {
83
- throw new TypeError("forEach() callback must be a function");
84
- }
85
- callback(this);
86
- if (this.children) {
87
- for (let i = 0, { length } = this.children; i < length; i++) {
88
- this.children[i]?.forEach(callback);
89
- }
90
- }
91
- return this;
92
- }
93
- static build(path2, options = {}) {
94
- try {
95
- const exclude = Array.isArray(options.exclude) ? options.exclude : [options.exclude].filter(Boolean);
96
- const filteredTree = dirTree(path2, {
97
- extensions: options.extensions,
98
- exclude: [/node_modules/, ...exclude]
99
- });
100
- if (!filteredTree) {
101
- return null;
102
- }
103
- const treeNode = new _TreeNode({
104
- name: filteredTree.name,
105
- path: filteredTree.path,
106
- type: FileManager.getMode(filteredTree.path)
107
- });
108
- const recurse = (node, item) => {
109
- const subNode = node.addChild({
110
- name: item.name,
111
- path: item.path,
112
- type: FileManager.getMode(item.path)
113
- });
114
- if (item.children?.length) {
115
- item.children?.forEach((child) => {
116
- recurse(subNode, child);
117
- });
118
- }
119
- };
120
- filteredTree.children?.forEach((child) => recurse(treeNode, child));
121
- return treeNode;
122
- } catch (e) {
123
- throw new Error("Something went wrong with creating index files with the TreehNode class", { cause: e });
124
- }
125
- }
126
- };
127
-
128
- // src/BarrelManager.ts
129
- var _options;
130
- var BarrelManager = class {
131
- constructor(options = {}) {
132
- __privateAdd(this, _options);
133
- __privateSet(this, _options, options);
134
- return this;
135
- }
136
- getNamedExport(root, item) {
137
- const exportedNames = getExports(path.resolve(root, item.path));
138
- if (!exportedNames) {
139
- return [item];
140
- }
141
- return exportedNames.reduce(
142
- (prev, curr) => {
143
- if (!prev[0]?.name || !prev[1]?.name) {
144
- return prev;
145
- }
146
- if (curr.isTypeOnly) {
147
- prev[1] = { ...prev[1], name: [...prev[1].name, curr.name] };
148
- } else {
149
- prev[0] = { ...prev[0], name: [...prev[0].name, curr.name] };
150
- }
151
- return prev;
152
- },
153
- [
154
- {
155
- ...item,
156
- name: [],
157
- isTypeOnly: false
158
- },
159
- {
160
- ...item,
161
- name: [],
162
- isTypeOnly: true
163
- }
164
- ]
165
- );
166
- }
167
- getNamedExports(root, exports) {
168
- return exports?.flatMap((item) => {
169
- return this.getNamedExport(root, item);
170
- });
171
- }
172
- getIndexes(root) {
173
- const { treeNode = {}, isTypeOnly, extName } = __privateGet(this, _options);
174
- const tree = TreeNode.build(root, treeNode);
175
- if (!tree) {
176
- return null;
177
- }
178
- const fileReducer = (files, treeNode2) => {
179
- if (!treeNode2.children) {
180
- return [];
181
- }
182
- if (treeNode2.children.length > 1) {
183
- const indexPath = path.resolve(treeNode2.data.path, "index.ts");
184
- const exports = treeNode2.children.filter(Boolean).map((file) => {
185
- const importPath = file.data.type === "split" ? `./${file.data.name}/index` : `./${trimExtName(file.data.name)}`;
186
- if (importPath.endsWith("index") && file.data.type === "single") {
187
- return void 0;
188
- }
189
- return {
190
- path: extName ? `${importPath}${extName}` : importPath,
191
- isTypeOnly
192
- };
193
- }).filter(Boolean);
194
- files.push({
195
- path: indexPath,
196
- baseName: "index.ts",
197
- source: "",
198
- exports,
199
- exportable: true
200
- });
201
- } else if (treeNode2.children.length === 1) {
202
- const [treeNodeChild] = treeNode2.children;
203
- const indexPath = path.resolve(treeNode2.data.path, "index.ts");
204
- const importPath = treeNodeChild.data.type === "split" ? `./${treeNodeChild.data.name}/index` : `./${trimExtName(treeNodeChild.data.name)}`;
205
- const exports = [
206
- {
207
- path: extName ? `${importPath}${extName}` : importPath,
208
- isTypeOnly
209
- }
210
- ];
211
- files.push({
212
- path: indexPath,
213
- baseName: "index.ts",
214
- source: "",
215
- exports,
216
- exportable: true
217
- });
218
- }
219
- treeNode2.children.forEach((childItem) => {
220
- fileReducer(files, childItem);
221
- });
222
- return files;
223
- };
224
- return fileReducer([], tree).reverse();
225
- }
226
- };
227
- _options = new WeakMap();
228
-
229
- // src/FileManager.ts
230
- import PQueue from "p-queue";
231
- var _cache, _FileManager_instances, add_fn, addOrAppend_fn;
232
- var _FileManager = class _FileManager {
233
- constructor() {
234
- __privateAdd(this, _FileManager_instances);
235
- __privateAdd(this, _cache, /* @__PURE__ */ new Map());
236
- return this;
237
- }
238
- get files() {
239
- const files = [];
240
- __privateGet(this, _cache).forEach((item) => {
241
- files.push(...item.flat(1));
242
- });
243
- return files;
244
- }
245
- async add(...files) {
246
- const promises = combineFiles(files).map((file) => {
247
- if (file.override) {
248
- return __privateMethod(this, _FileManager_instances, add_fn).call(this, file);
249
- }
250
- return __privateMethod(this, _FileManager_instances, addOrAppend_fn).call(this, file);
251
- });
252
- const resolvedFiles = await Promise.all(promises);
253
- if (files.length > 1) {
254
- return resolvedFiles;
255
- }
256
- return resolvedFiles[0];
257
- }
258
- async getIndexFiles({ root, output, meta, logger, options = {} }) {
259
- const { exportType = "barrel" } = output;
260
- if (exportType === false) {
261
- return [];
262
- }
263
- const pathToBuildFrom = resolve(root, output.path);
264
- if (transformers_default.trimExtName(pathToBuildFrom).endsWith("index")) {
265
- logger.emit("warning", "Output has the same fileName as the barrelFiles, please disable barrel generation");
266
- return [];
267
- }
268
- const exportPath = output.path.startsWith("./") ? trimExtName(output.path) : `./${trimExtName(output.path)}`;
269
- const mode = _FileManager.getMode(output.path);
270
- const barrelManager = new BarrelManager({
271
- extName: output.extName,
272
- ...options
273
- });
274
- let files = barrelManager.getIndexes(pathToBuildFrom);
275
- if (!files) {
276
- return [];
277
- }
278
- if (exportType === "barrelNamed") {
279
- files = files.map((file) => {
280
- if (file.exports) {
281
- return {
282
- ...file,
283
- exports: barrelManager.getNamedExports(pathToBuildFrom, file.exports)
284
- };
285
- }
286
- return file;
287
- });
288
- }
289
- const rootPath = mode === "split" ? `${exportPath}/index${output.extName || ""}` : `${exportPath}${output.extName || ""}`;
290
- const rootFile = {
291
- path: resolve(root, "index.ts"),
292
- baseName: "index.ts",
293
- source: "",
294
- exports: [
295
- output.exportAs ? {
296
- name: output.exportAs,
297
- asAlias: true,
298
- path: rootPath,
299
- isTypeOnly: options.isTypeOnly
300
- } : {
301
- path: rootPath,
302
- isTypeOnly: options.isTypeOnly
303
- }
304
- ],
305
- exportable: true
306
- };
307
- if (exportType === "barrelNamed" && !output.exportAs && rootFile.exports?.[0]) {
308
- rootFile.exports = barrelManager.getNamedExport(root, rootFile.exports[0]);
309
- }
310
- return [
311
- ...await Promise.all(
312
- files.map((file) => {
313
- return __privateMethod(this, _FileManager_instances, addOrAppend_fn).call(this, {
314
- ...file,
315
- meta: meta ? meta : file.meta
316
- });
317
- })
318
- ),
319
- await __privateMethod(this, _FileManager_instances, addOrAppend_fn).call(this, {
320
- ...rootFile,
321
- meta: meta ? meta : rootFile.meta
322
- })
323
- ];
324
- }
325
- getCacheByUUID(UUID) {
326
- let cache;
327
- __privateGet(this, _cache).forEach((files) => {
328
- cache = files.find((item) => item.id === UUID);
329
- });
330
- return cache;
331
- }
332
- get(path2) {
333
- return __privateGet(this, _cache).get(path2);
334
- }
335
- remove(path2) {
336
- const cacheItem = this.get(path2);
337
- if (!cacheItem) {
338
- return;
339
- }
340
- __privateGet(this, _cache).delete(path2);
341
- }
342
- async write(...params) {
343
- return write(...params);
344
- }
345
- async read(...params) {
346
- return read(...params);
347
- }
348
- async processFiles(...params) {
349
- return processFiles(...params);
350
- }
351
- // statics
352
- static async getSource(file) {
353
- return getSource(file);
354
- }
355
- static combineFiles(files) {
356
- return combineFiles(files);
357
- }
358
- static getMode(path2) {
359
- if (!path2) {
360
- return "split";
361
- }
362
- return extname(path2) ? "single" : "split";
363
- }
364
- static get extensions() {
365
- return [".js", ".ts", ".tsx"];
366
- }
367
- static isJavascript(baseName) {
368
- return _FileManager.extensions.some((extension) => baseName.endsWith(extension));
369
- }
370
- };
371
- _cache = new WeakMap();
372
- _FileManager_instances = new WeakSet();
373
- add_fn = async function(file) {
374
- const controller = new AbortController();
375
- const resolvedFile = {
376
- id: crypto.randomUUID(),
377
- name: trimExtName(file.baseName),
378
- ...file
379
- };
380
- if (resolvedFile.exports?.length) {
381
- const folder = resolvedFile.path.replace(resolvedFile.baseName, "");
382
- resolvedFile.exports = resolvedFile.exports.filter((exportItem) => {
383
- const exportedFile = this.files.find((file2) => file2.path.includes(resolve(folder, exportItem.path)));
384
- if (exportedFile) {
385
- return exportedFile.exportable;
386
- }
387
- return true;
388
- });
389
- }
390
- __privateGet(this, _cache).set(resolvedFile.path, [{ cancel: () => controller.abort(), ...resolvedFile }]);
391
- return resolvedFile;
392
- };
393
- addOrAppend_fn = async function(file) {
394
- const previousCaches = __privateGet(this, _cache).get(file.path);
395
- const previousCache = previousCaches ? previousCaches.at(previousCaches.length - 1) : void 0;
396
- if (previousCache) {
397
- __privateGet(this, _cache).delete(previousCache.path);
398
- return __privateMethod(this, _FileManager_instances, add_fn).call(this, {
399
- ...file,
400
- source: previousCache.source && file.source ? `${previousCache.source}
401
- ${file.source}` : "",
402
- imports: [...previousCache.imports || [], ...file.imports || []],
403
- exports: [...previousCache.exports || [], ...file.exports || []],
404
- env: { ...previousCache.env || {}, ...file.env || {} }
405
- });
406
- }
407
- return __privateMethod(this, _FileManager_instances, add_fn).call(this, file);
408
- };
409
- var FileManager = _FileManager;
410
- function combineFiles(files) {
411
- return files.filter(Boolean).reduce(
412
- (acc, file) => {
413
- const prevIndex = acc.findIndex((item) => item.path === file.path);
414
- if (prevIndex === -1) {
415
- return [...acc, file];
416
- }
417
- const prev = acc[prevIndex];
418
- if (prev && file.override) {
419
- acc[prevIndex] = {
420
- imports: [],
421
- exports: [],
422
- ...file
423
- };
424
- return acc;
425
- }
426
- if (prev) {
427
- acc[prevIndex] = {
428
- ...file,
429
- source: prev.source && file.source ? `${prev.source}
430
- ${file.source}` : "",
431
- imports: [...prev.imports || [], ...file.imports || []],
432
- exports: [...prev.exports || [], ...file.exports || []],
433
- env: { ...prev.env || {}, ...file.env || {} }
434
- };
435
- }
436
- return acc;
437
- },
438
- []
439
- );
440
- }
441
- async function getSource(file) {
442
- if (file.language ? !["typescript", "javascript"].includes(file.language) : !FileManager.isJavascript(file.baseName)) {
443
- return file.source;
444
- }
445
- const parser = await getParser(file.language);
446
- const exports = file.exports ? combineExports(file.exports) : [];
447
- const imports = file.imports && file.source ? combineImports(file.imports, exports, file.source) : [];
448
- const importNodes = imports.filter((item) => {
449
- const path2 = item.root ? getRelativePath(item.root, item.path) : item.path;
450
- return path2 !== trimExtName(file.path);
451
- }).map((item) => {
452
- const path2 = item.root ? getRelativePath(item.root, item.path) : item.path;
453
- return parser.factory.createImportDeclaration({
454
- name: item.name,
455
- path: item.extName ? `${path2}${item.extName}` : path2,
456
- isTypeOnly: item.isTypeOnly
457
- });
458
- });
459
- const exportNodes = exports.map(
460
- (item) => parser.factory.createExportDeclaration({
461
- name: item.name,
462
- path: item.extName ? `${item.path}${item.extName}` : item.path,
463
- isTypeOnly: item.isTypeOnly,
464
- asAlias: item.asAlias
465
- })
466
- );
467
- const source = [parser.print([...importNodes, ...exportNodes]), getEnvSource(file.source, file.env)].join("\n");
468
- return parser.print([], { source, noEmitHelpers: false });
469
- }
470
- function combineExports(exports) {
471
- const combinedExports = orderBy(exports, [(v) => !v.isTypeOnly], ["asc"]).reduce(
472
- (prev, curr) => {
473
- const name = curr.name;
474
- const prevByPath = prev.findLast((imp) => imp.path === curr.path);
475
- const prevByPathAndIsTypeOnly = prev.findLast((imp) => imp.path === curr.path && isDeepEqual(imp.name, name) && imp.isTypeOnly);
476
- if (prevByPathAndIsTypeOnly) {
477
- return prev;
478
- }
479
- const uniquePrev = prev.findLast(
480
- (imp) => imp.path === curr.path && isDeepEqual(imp.name, name) && imp.isTypeOnly === curr.isTypeOnly && imp.asAlias === curr.asAlias
481
- );
482
- if (uniquePrev || Array.isArray(name) && !name.length || prevByPath?.asAlias && !curr.asAlias) {
483
- return prev;
484
- }
485
- if (!prevByPath) {
486
- return [
487
- ...prev,
488
- {
489
- ...curr,
490
- name: Array.isArray(name) ? [...new Set(name)] : name
491
- }
492
- ];
493
- }
494
- if (prevByPath && Array.isArray(prevByPath.name) && Array.isArray(curr.name) && prevByPath.isTypeOnly === curr.isTypeOnly) {
495
- prevByPath.name = [.../* @__PURE__ */ new Set([...prevByPath.name, ...curr.name])];
496
- return prev;
497
- }
498
- return [...prev, curr];
499
- },
500
- []
501
- );
502
- return orderBy(combinedExports, [(v) => !v.isTypeOnly, (v) => v.asAlias], ["desc", "desc"]);
503
- }
504
- function combineImports(imports, exports, source) {
505
- const combinedImports = orderBy(imports, [(v) => !v.isTypeOnly], ["asc"]).reduce(
506
- (prev, curr) => {
507
- let name = Array.isArray(curr.name) ? [...new Set(curr.name)] : curr.name;
508
- const hasImportInSource = (importName) => {
509
- if (!source) {
510
- return true;
511
- }
512
- const checker = (name2) => name2 && !!source.includes(name2);
513
- return checker(importName) || exports.some(({ name: name2 }) => Array.isArray(name2) ? name2.some(checker) : checker(name2));
514
- };
515
- if (curr.path === curr.root) {
516
- return prev;
517
- }
518
- if (Array.isArray(name)) {
519
- name = name.filter((item) => typeof item === "string" ? hasImportInSource(item) : hasImportInSource(item.propertyName));
520
- }
521
- const prevByPath = prev.findLast((imp) => imp.path === curr.path && imp.isTypeOnly === curr.isTypeOnly);
522
- const uniquePrev = prev.findLast((imp) => imp.path === curr.path && isDeepEqual(imp.name, name) && imp.isTypeOnly === curr.isTypeOnly);
523
- const prevByPathNameAndIsTypeOnly = prev.findLast((imp) => imp.path === curr.path && isDeepEqual(imp.name, name) && imp.isTypeOnly);
524
- if (prevByPathNameAndIsTypeOnly) {
525
- return prev;
526
- }
527
- if (uniquePrev || Array.isArray(name) && !name.length) {
528
- return prev;
529
- }
530
- if (!prevByPath) {
531
- return [
532
- ...prev,
533
- {
534
- ...curr,
535
- name
536
- }
537
- ];
538
- }
539
- if (prevByPath && Array.isArray(prevByPath.name) && Array.isArray(name) && prevByPath.isTypeOnly === curr.isTypeOnly) {
540
- prevByPath.name = [.../* @__PURE__ */ new Set([...prevByPath.name, ...name])];
541
- return prev;
542
- }
543
- if (!Array.isArray(name) && name && !hasImportInSource(name)) {
544
- return prev;
545
- }
546
- return [...prev, curr];
547
- },
548
- []
549
- );
550
- return orderBy(combinedImports, [(v) => !v.isTypeOnly], ["desc"]);
551
- }
552
- function getEnvSource(source, env) {
553
- if (!env) {
554
- return source;
555
- }
556
- const keys = Object.keys(env);
557
- if (!keys.length) {
558
- return source;
559
- }
560
- return keys.reduce((prev, key) => {
561
- const environmentValue = env[key];
562
- const replaceBy = environmentValue ? `'${environmentValue.replaceAll('"', "")?.replaceAll("'", "")}'` : "undefined";
563
- if (key.toUpperCase() !== key) {
564
- throw new TypeError(`Environment should be in upperCase for ${key}`);
565
- }
566
- if (typeof replaceBy === "string") {
567
- prev = searchAndReplace({
568
- text: prev.replaceAll(`process.env.${key}`, replaceBy),
569
- replaceBy,
570
- prefix: "process.env",
571
- key
572
- });
573
- prev = searchAndReplace({
574
- text: prev.replaceAll(/(declare const).*\n/gi, ""),
575
- replaceBy,
576
- key
577
- });
578
- }
579
- return prev;
580
- }, source);
581
- }
582
- var queue = new PQueue({ concurrency: 1 });
583
- async function processFiles({ dryRun, logger, files }) {
584
- const mergedFiles = await Promise.all(
585
- files.map(async (file) => ({
586
- ...file,
587
- source: await FileManager.getSource(file)
588
- }))
589
- );
590
- if (!dryRun) {
591
- logger.consola?.pauseLogs();
592
- const filePromises = mergedFiles.map(async (file, index) => {
593
- await queue.add(() => {
594
- logger.emit("progress", index, mergedFiles.length);
595
- return write(file.path, file.source, { sanity: false });
596
- });
597
- });
598
- await Promise.all(filePromises);
599
- logger.consola?.resumeLogs();
600
- }
601
- return mergedFiles;
602
- }
603
-
604
- export {
605
- FileManager,
606
- processFiles
607
- };
608
- //# sourceMappingURL=chunk-UUBPTMRW.js.map