bunup 0.1.3 → 0.1.4
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/README.md +13 -2
- package/build/cli.js +157 -85
- package/build/cli.mjs +155 -83
- package/build/dtsWorker.js +1 -1
- package/build/index.d.mts +1 -14
- package/build/index.d.ts +1 -14
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -1,7 +1,18 @@
|
|
|
1
|
-
# Bunup
|
|
1
|
+
# Bunup
|
|
2
2
|
|
|
3
3
|
> A extremely fast, zero-config bundler for TypeScript & JavaScript, powered by Bun.
|
|
4
4
|
|
|
5
5
|
Built with speed in mind, Bunup aims to provide the fastest bundling experience possible. This project is currently a work in progress and will be ready for production use soon.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
## Benchmarks
|
|
8
|
+
|
|
9
|
+
Bunup outperforms other popular bundlers by a significant margin:
|
|
10
|
+
|
|
11
|
+
| Bundler | Format | Build Time | Relative Speed |
|
|
12
|
+
| ------------- | -------- | ------------ | ---------------- |
|
|
13
|
+
| bunup | esm, cjs | **3.65ms** | **16.0x faster** |
|
|
14
|
+
| bunup (+ dts) | esm, cjs | **149.51ms** | **5.0x faster** |
|
|
15
|
+
| tsup | esm, cjs | 58.36ms | baseline |
|
|
16
|
+
| tsup (+ dts) | esm, cjs | 745.23ms | baseline |
|
|
17
|
+
|
|
18
|
+
_Lower build time is better. Benchmark run on the same code with identical output formats._
|
package/build/cli.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
|
-
var
|
|
4
|
+
var fs2 = require('fs');
|
|
5
5
|
var path2 = require('path');
|
|
6
|
+
var oxc = require('oxc-transform');
|
|
6
7
|
var rollup = require('rollup');
|
|
7
8
|
var dtsPlugin = require('rollup-plugin-dts');
|
|
8
|
-
var ts = require('typescript');
|
|
9
9
|
var chokidar = require('chokidar');
|
|
10
10
|
|
|
11
11
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
12
|
|
|
13
|
-
var
|
|
13
|
+
var fs2__default = /*#__PURE__*/_interopDefault(fs2);
|
|
14
14
|
var path2__default = /*#__PURE__*/_interopDefault(path2);
|
|
15
|
+
var oxc__default = /*#__PURE__*/_interopDefault(oxc);
|
|
15
16
|
var dtsPlugin__default = /*#__PURE__*/_interopDefault(dtsPlugin);
|
|
16
|
-
var ts__default = /*#__PURE__*/_interopDefault(ts);
|
|
17
17
|
var chokidar__default = /*#__PURE__*/_interopDefault(chokidar);
|
|
18
18
|
|
|
19
19
|
// src/errors.ts
|
|
@@ -206,10 +206,10 @@ async function loadConfigs(cwd) {
|
|
|
206
206
|
]) {
|
|
207
207
|
const filePath = path2__default.default.join(cwd, `bunup.config${ext}`);
|
|
208
208
|
try {
|
|
209
|
-
if (!
|
|
209
|
+
if (!fs2__default.default.existsSync(filePath)) continue;
|
|
210
210
|
let content;
|
|
211
211
|
if (ext === ".json" || ext === ".jsonc") {
|
|
212
|
-
const text =
|
|
212
|
+
const text = fs2__default.default.readFileSync(filePath, "utf8");
|
|
213
213
|
content = JSON.parse(text);
|
|
214
214
|
} else {
|
|
215
215
|
const imported = await import(`file://${filePath}`);
|
|
@@ -245,10 +245,10 @@ async function loadConfigs(cwd) {
|
|
|
245
245
|
function loadPackageJson(cwd) {
|
|
246
246
|
const packageJsonPath = path2__default.default.join(cwd, "package.json");
|
|
247
247
|
try {
|
|
248
|
-
if (!
|
|
248
|
+
if (!fs2__default.default.existsSync(packageJsonPath)) {
|
|
249
249
|
return null;
|
|
250
250
|
}
|
|
251
|
-
const text =
|
|
251
|
+
const text = fs2__default.default.readFileSync(packageJsonPath, "utf8");
|
|
252
252
|
const content = JSON.parse(text);
|
|
253
253
|
return content;
|
|
254
254
|
} catch (error) {
|
|
@@ -258,86 +258,177 @@ function loadPackageJson(cwd) {
|
|
|
258
258
|
return null;
|
|
259
259
|
}
|
|
260
260
|
}
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
261
|
+
|
|
262
|
+
// src/dts/index.ts
|
|
263
|
+
async function generateDts(rootDir, entry, format, options) {
|
|
264
|
+
const { absoluteRootDir, absoluteEntry } = validateInputs(rootDir, entry);
|
|
265
|
+
const tsFiles = await collectTsFiles(absoluteEntry);
|
|
266
|
+
const dtsMap = await generateDtsContent(tsFiles);
|
|
267
|
+
return bundleDtsContent(
|
|
268
|
+
absoluteEntry,
|
|
269
|
+
dtsMap,
|
|
270
|
+
format,
|
|
271
|
+
options,
|
|
272
|
+
absoluteRootDir
|
|
273
|
+
);
|
|
274
|
+
}
|
|
275
|
+
async function collectTsFiles(entry) {
|
|
276
|
+
const visited = /* @__PURE__ */ new Set();
|
|
277
|
+
const toVisit = [entry];
|
|
278
|
+
while (toVisit.length > 0) {
|
|
279
|
+
const current = toVisit.pop();
|
|
280
|
+
if (!current || visited.has(current)) continue;
|
|
281
|
+
visited.add(current);
|
|
282
|
+
try {
|
|
283
|
+
const sourceText = await fs2__default.default.promises.readFile(current, "utf8");
|
|
284
|
+
const relativeImports = extractRelativeImports(sourceText);
|
|
285
|
+
for (const relImport of relativeImports) {
|
|
286
|
+
const importDir = path2__default.default.dirname(current);
|
|
287
|
+
const absImport = path2__default.default.resolve(importDir, relImport);
|
|
288
|
+
const possiblePaths = [
|
|
289
|
+
absImport,
|
|
290
|
+
`${absImport}.ts`,
|
|
291
|
+
`${absImport}.tsx`,
|
|
292
|
+
`${absImport}/index.ts`,
|
|
293
|
+
`${absImport}/index.tsx`
|
|
294
|
+
];
|
|
295
|
+
for (const tsFile of possiblePaths) {
|
|
296
|
+
if (fs2__default.default.existsSync(tsFile) && tsFile.endsWith(".ts") && !visited.has(tsFile)) {
|
|
297
|
+
toVisit.push(tsFile);
|
|
298
|
+
break;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
} catch (error) {
|
|
303
|
+
logger.warn(
|
|
304
|
+
`Error processing ${current}: ${error instanceof Error ? error.message : String(error)}`
|
|
305
|
+
);
|
|
306
|
+
}
|
|
264
307
|
}
|
|
308
|
+
return visited;
|
|
309
|
+
}
|
|
310
|
+
function extractRelativeImports(sourceText) {
|
|
311
|
+
const imports = /* @__PURE__ */ new Set();
|
|
265
312
|
try {
|
|
266
|
-
const
|
|
267
|
-
|
|
268
|
-
|
|
313
|
+
const importExportRegex = /(?:import|export)(?:(?:[\s\n]*(?:type[\s\n]+)?(?:\*|\{[^}]*\}|[\w$]+)[\s\n]+from[\s\n]*)|[\s\n]+)(["'`])([^'"]+)\1/g;
|
|
314
|
+
let match;
|
|
315
|
+
while ((match = importExportRegex.exec(sourceText)) !== null) {
|
|
316
|
+
const importPath = match[2];
|
|
317
|
+
if (importPath.startsWith(".")) {
|
|
318
|
+
imports.add(importPath);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
const sideEffectImportRegex = /import\s+(["'`])([^'"]+)\1\s*;?/g;
|
|
322
|
+
while ((match = sideEffectImportRegex.exec(sourceText)) !== null) {
|
|
323
|
+
const importPath = match[2];
|
|
324
|
+
if (importPath.startsWith(".")) {
|
|
325
|
+
imports.add(importPath);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
const dynamicImportRegex = /import\s*\(\s*(["'`])([^'"]+)\1\s*\)/g;
|
|
329
|
+
while ((match = dynamicImportRegex.exec(sourceText)) !== null) {
|
|
330
|
+
const importPath = match[2];
|
|
331
|
+
if (importPath.startsWith(".")) {
|
|
332
|
+
imports.add(importPath);
|
|
333
|
+
}
|
|
334
|
+
}
|
|
269
335
|
} catch (error) {
|
|
270
336
|
logger.warn(
|
|
271
|
-
`
|
|
337
|
+
`Error extracting imports: ${error instanceof Error ? error.message : String(error)}`
|
|
272
338
|
);
|
|
273
|
-
return {};
|
|
274
339
|
}
|
|
340
|
+
return Array.from(imports);
|
|
275
341
|
}
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
342
|
+
async function generateDtsContent(tsFiles) {
|
|
343
|
+
const dtsMap = /* @__PURE__ */ new Map();
|
|
344
|
+
await Promise.all(
|
|
345
|
+
Array.from(tsFiles).map(async (tsFile) => {
|
|
346
|
+
try {
|
|
347
|
+
const dtsPath = tsFile.replace(/\.tsx?$/, ".d.ts");
|
|
348
|
+
const sourceText = await fs2__default.default.promises.readFile(tsFile, "utf8");
|
|
349
|
+
const { code: declaration } = oxc__default.default.isolatedDeclaration(
|
|
350
|
+
tsFile,
|
|
351
|
+
sourceText
|
|
352
|
+
);
|
|
353
|
+
if (declaration) {
|
|
354
|
+
dtsMap.set(dtsPath, declaration);
|
|
355
|
+
}
|
|
356
|
+
} catch (error) {
|
|
357
|
+
logger.warn(
|
|
358
|
+
`Failed to generate declaration for ${tsFile}: ${error instanceof Error ? error.message : String(error)}`
|
|
359
|
+
);
|
|
360
|
+
}
|
|
361
|
+
})
|
|
362
|
+
);
|
|
363
|
+
return dtsMap;
|
|
364
|
+
}
|
|
365
|
+
async function bundleDtsContent(entryFile, dtsMap, format, options, rootDir) {
|
|
366
|
+
const VIRTUAL_PREFIX = "\0virtual:";
|
|
367
|
+
const entryDtsPath = entryFile.replace(/\.tsx?$/, ".d.ts");
|
|
368
|
+
const virtualEntry = `${VIRTUAL_PREFIX}${entryDtsPath}`;
|
|
369
|
+
const virtualPlugin = {
|
|
370
|
+
name: "virtual-dts",
|
|
371
|
+
resolveId(source, importer) {
|
|
372
|
+
if (source.startsWith(VIRTUAL_PREFIX)) {
|
|
373
|
+
return source;
|
|
374
|
+
}
|
|
375
|
+
if (importer?.startsWith(VIRTUAL_PREFIX)) {
|
|
376
|
+
const importerPath = importer.slice(VIRTUAL_PREFIX.length);
|
|
377
|
+
const importerDir = path2__default.default.dirname(importerPath);
|
|
378
|
+
if (source.startsWith(".")) {
|
|
379
|
+
const resolvedPath = path2__default.default.resolve(importerDir, source);
|
|
380
|
+
for (const ext of ["", ".d.ts", "/index.d.ts"]) {
|
|
381
|
+
const fullPath = `${resolvedPath}${ext}`;
|
|
382
|
+
if (dtsMap.has(fullPath)) {
|
|
383
|
+
return `${VIRTUAL_PREFIX}${fullPath}`;
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
return null;
|
|
389
|
+
},
|
|
390
|
+
load(id) {
|
|
391
|
+
if (id.startsWith(VIRTUAL_PREFIX)) {
|
|
392
|
+
const actualPath = id.slice(VIRTUAL_PREFIX.length);
|
|
393
|
+
return dtsMap.get(actualPath) || null;
|
|
394
|
+
}
|
|
395
|
+
return null;
|
|
396
|
+
}
|
|
397
|
+
};
|
|
398
|
+
const packageJson = loadPackageJson(rootDir);
|
|
284
399
|
const externalPatterns = getExternalPatterns(options, packageJson);
|
|
285
400
|
const noExternalPatterns = getNoExternalPatterns(options);
|
|
286
401
|
let bundle;
|
|
287
|
-
let result;
|
|
288
402
|
try {
|
|
289
403
|
bundle = await rollup.rollup({
|
|
290
|
-
input:
|
|
404
|
+
input: virtualEntry,
|
|
291
405
|
onwarn(warning, handler) {
|
|
292
406
|
if (warning.code === "UNRESOLVED_IMPORT" || warning.code === "CIRCULAR_DEPENDENCY" || warning.code === "EMPTY_BUNDLE") {
|
|
293
407
|
return;
|
|
294
408
|
}
|
|
295
|
-
|
|
409
|
+
handler(warning);
|
|
296
410
|
},
|
|
297
|
-
plugins: [
|
|
298
|
-
dtsPlugin__default.default({
|
|
299
|
-
tsconfig: tsconfigPath,
|
|
300
|
-
compilerOptions: {
|
|
301
|
-
...compilerOptions ? ts__default.default.parseJsonConfigFileContent(
|
|
302
|
-
{ compilerOptions },
|
|
303
|
-
ts__default.default.sys,
|
|
304
|
-
"./"
|
|
305
|
-
).options : {},
|
|
306
|
-
declaration: true,
|
|
307
|
-
noEmit: false,
|
|
308
|
-
emitDeclarationOnly: true,
|
|
309
|
-
noEmitOnError: true,
|
|
310
|
-
checkJs: false,
|
|
311
|
-
declarationMap: false,
|
|
312
|
-
skipLibCheck: true,
|
|
313
|
-
preserveSymlinks: false,
|
|
314
|
-
target: ts.ScriptTarget.ESNext
|
|
315
|
-
}
|
|
316
|
-
})
|
|
317
|
-
],
|
|
411
|
+
plugins: [virtualPlugin, dtsPlugin__default.default()],
|
|
318
412
|
external: (source) => externalPatterns.some((re) => re.test(source)) && !noExternalPatterns.some((re) => re.test(source))
|
|
319
413
|
});
|
|
320
414
|
const { output } = await bundle.generate({ format });
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
415
|
+
if (!output[0]?.code) {
|
|
416
|
+
throw new Error("Generated bundle is empty");
|
|
417
|
+
}
|
|
418
|
+
return output[0].code;
|
|
419
|
+
} catch (error) {
|
|
420
|
+
throw new Error(`DTS bundling failed: ${parseErrorMessage(error)}`);
|
|
326
421
|
} finally {
|
|
327
422
|
if (bundle) await bundle.close();
|
|
328
423
|
}
|
|
329
|
-
if (!result) {
|
|
330
|
-
throw new Error("Failed to generate bundled DTS content");
|
|
331
|
-
}
|
|
332
|
-
return result;
|
|
333
424
|
}
|
|
334
425
|
function validateInputs(rootDir, entry) {
|
|
335
426
|
const absoluteRootDir = path2__default.default.resolve(rootDir);
|
|
336
427
|
const absoluteEntry = path2__default.default.resolve(absoluteRootDir, entry);
|
|
337
|
-
if (!
|
|
428
|
+
if (!fs2__default.default.existsSync(absoluteRootDir)) {
|
|
338
429
|
throw new Error(`Root directory does not exist: ${absoluteRootDir}`);
|
|
339
430
|
}
|
|
340
|
-
if (!
|
|
431
|
+
if (!fs2__default.default.existsSync(absoluteEntry)) {
|
|
341
432
|
throw new Error(`Entry file does not exist: ${absoluteEntry}`);
|
|
342
433
|
}
|
|
343
434
|
if (!absoluteEntry.endsWith(".ts")) {
|
|
@@ -353,24 +444,9 @@ function validateInputs(rootDir, entry) {
|
|
|
353
444
|
|
|
354
445
|
// src/dts/worker.ts
|
|
355
446
|
self.onmessage = async (event) => {
|
|
356
|
-
const {
|
|
357
|
-
name,
|
|
358
|
-
rootDir,
|
|
359
|
-
outDir,
|
|
360
|
-
entry,
|
|
361
|
-
format,
|
|
362
|
-
packageType,
|
|
363
|
-
dtsOptions,
|
|
364
|
-
options
|
|
365
|
-
} = event.data;
|
|
447
|
+
const { name, rootDir, outDir, entry, format, packageType, options } = event.data;
|
|
366
448
|
try {
|
|
367
|
-
const content = await generateDts(
|
|
368
|
-
rootDir,
|
|
369
|
-
entry,
|
|
370
|
-
format,
|
|
371
|
-
options,
|
|
372
|
-
dtsOptions
|
|
373
|
-
);
|
|
449
|
+
const content = await generateDts(rootDir, entry, format, options);
|
|
374
450
|
const entryName = getEntryNameOnly(entry);
|
|
375
451
|
const extension = getDefaultDtsExtention(format, packageType);
|
|
376
452
|
const outputRelativePath = `${outDir}/${entryName}${extension}`;
|
|
@@ -541,8 +617,6 @@ async function build(options, rootDir) {
|
|
|
541
617
|
if (options.dts) {
|
|
542
618
|
const dtsStartTime = performance.now();
|
|
543
619
|
logger.progress("DTS", "Bundling types");
|
|
544
|
-
const dtsOptions = typeof options.dts === "object" ? options.dts : {};
|
|
545
|
-
const entries = dtsOptions.entry || options.entry;
|
|
546
620
|
const formatsToProcess = options.format.filter((fmt) => {
|
|
547
621
|
if (fmt === "iife" && !isModulePackage(packageType) && options.format.includes("cjs")) {
|
|
548
622
|
return false;
|
|
@@ -552,14 +626,13 @@ async function build(options, rootDir) {
|
|
|
552
626
|
const dtsWorker = new DtsWorker();
|
|
553
627
|
try {
|
|
554
628
|
const dtsPromises = formatsToProcess.flatMap(
|
|
555
|
-
(fmt) =>
|
|
629
|
+
(fmt) => options.entry.map(
|
|
556
630
|
(entry) => generateDtsForEntry(
|
|
557
631
|
options,
|
|
558
632
|
rootDir,
|
|
559
633
|
entry,
|
|
560
634
|
fmt,
|
|
561
635
|
packageType,
|
|
562
|
-
dtsOptions,
|
|
563
636
|
dtsWorker
|
|
564
637
|
)
|
|
565
638
|
)
|
|
@@ -574,7 +647,7 @@ async function build(options, rootDir) {
|
|
|
574
647
|
await dtsWorker.cleanup();
|
|
575
648
|
}
|
|
576
649
|
}
|
|
577
|
-
async function generateDtsForEntry(options, rootDir, entry, fmt, packageType,
|
|
650
|
+
async function generateDtsForEntry(options, rootDir, entry, fmt, packageType, dtsWorker) {
|
|
578
651
|
const task = {
|
|
579
652
|
name: options.name,
|
|
580
653
|
rootDir,
|
|
@@ -582,7 +655,6 @@ async function generateDtsForEntry(options, rootDir, entry, fmt, packageType, dt
|
|
|
582
655
|
entry,
|
|
583
656
|
format: fmt,
|
|
584
657
|
packageType,
|
|
585
|
-
dtsOptions,
|
|
586
658
|
options
|
|
587
659
|
};
|
|
588
660
|
await dtsWorker.process(task);
|
|
@@ -810,14 +882,14 @@ async function handleBuild(options, rootDir) {
|
|
|
810
882
|
}
|
|
811
883
|
function cleanOutDir(rootDir, outdir) {
|
|
812
884
|
const outdirPath = path2__default.default.join(rootDir, outdir);
|
|
813
|
-
if (
|
|
885
|
+
if (fs2__default.default.existsSync(outdirPath)) {
|
|
814
886
|
try {
|
|
815
|
-
|
|
887
|
+
fs2__default.default.rmSync(outdirPath, { recursive: true, force: true });
|
|
816
888
|
} catch (error) {
|
|
817
889
|
logger.error(`Failed to clean output directory: ${error}`);
|
|
818
890
|
}
|
|
819
891
|
}
|
|
820
|
-
|
|
892
|
+
fs2__default.default.mkdirSync(outdirPath, { recursive: true });
|
|
821
893
|
}
|
|
822
894
|
main().catch((error) => {
|
|
823
895
|
handleError(error);
|
package/build/cli.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
|
-
import
|
|
2
|
+
import fs2 from 'fs';
|
|
3
3
|
import path2 from 'path';
|
|
4
|
+
import oxc from 'oxc-transform';
|
|
4
5
|
import { rollup } from 'rollup';
|
|
5
6
|
import dtsPlugin from 'rollup-plugin-dts';
|
|
6
|
-
import ts, { ScriptTarget } from 'typescript';
|
|
7
7
|
import chokidar from 'chokidar';
|
|
8
8
|
|
|
9
9
|
// src/errors.ts
|
|
@@ -196,10 +196,10 @@ async function loadConfigs(cwd) {
|
|
|
196
196
|
]) {
|
|
197
197
|
const filePath = path2.join(cwd, `bunup.config${ext}`);
|
|
198
198
|
try {
|
|
199
|
-
if (!
|
|
199
|
+
if (!fs2.existsSync(filePath)) continue;
|
|
200
200
|
let content;
|
|
201
201
|
if (ext === ".json" || ext === ".jsonc") {
|
|
202
|
-
const text =
|
|
202
|
+
const text = fs2.readFileSync(filePath, "utf8");
|
|
203
203
|
content = JSON.parse(text);
|
|
204
204
|
} else {
|
|
205
205
|
const imported = await import(`file://${filePath}`);
|
|
@@ -235,10 +235,10 @@ async function loadConfigs(cwd) {
|
|
|
235
235
|
function loadPackageJson(cwd) {
|
|
236
236
|
const packageJsonPath = path2.join(cwd, "package.json");
|
|
237
237
|
try {
|
|
238
|
-
if (!
|
|
238
|
+
if (!fs2.existsSync(packageJsonPath)) {
|
|
239
239
|
return null;
|
|
240
240
|
}
|
|
241
|
-
const text =
|
|
241
|
+
const text = fs2.readFileSync(packageJsonPath, "utf8");
|
|
242
242
|
const content = JSON.parse(text);
|
|
243
243
|
return content;
|
|
244
244
|
} catch (error) {
|
|
@@ -248,86 +248,177 @@ function loadPackageJson(cwd) {
|
|
|
248
248
|
return null;
|
|
249
249
|
}
|
|
250
250
|
}
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
251
|
+
|
|
252
|
+
// src/dts/index.ts
|
|
253
|
+
async function generateDts(rootDir, entry, format, options) {
|
|
254
|
+
const { absoluteRootDir, absoluteEntry } = validateInputs(rootDir, entry);
|
|
255
|
+
const tsFiles = await collectTsFiles(absoluteEntry);
|
|
256
|
+
const dtsMap = await generateDtsContent(tsFiles);
|
|
257
|
+
return bundleDtsContent(
|
|
258
|
+
absoluteEntry,
|
|
259
|
+
dtsMap,
|
|
260
|
+
format,
|
|
261
|
+
options,
|
|
262
|
+
absoluteRootDir
|
|
263
|
+
);
|
|
264
|
+
}
|
|
265
|
+
async function collectTsFiles(entry) {
|
|
266
|
+
const visited = /* @__PURE__ */ new Set();
|
|
267
|
+
const toVisit = [entry];
|
|
268
|
+
while (toVisit.length > 0) {
|
|
269
|
+
const current = toVisit.pop();
|
|
270
|
+
if (!current || visited.has(current)) continue;
|
|
271
|
+
visited.add(current);
|
|
272
|
+
try {
|
|
273
|
+
const sourceText = await fs2.promises.readFile(current, "utf8");
|
|
274
|
+
const relativeImports = extractRelativeImports(sourceText);
|
|
275
|
+
for (const relImport of relativeImports) {
|
|
276
|
+
const importDir = path2.dirname(current);
|
|
277
|
+
const absImport = path2.resolve(importDir, relImport);
|
|
278
|
+
const possiblePaths = [
|
|
279
|
+
absImport,
|
|
280
|
+
`${absImport}.ts`,
|
|
281
|
+
`${absImport}.tsx`,
|
|
282
|
+
`${absImport}/index.ts`,
|
|
283
|
+
`${absImport}/index.tsx`
|
|
284
|
+
];
|
|
285
|
+
for (const tsFile of possiblePaths) {
|
|
286
|
+
if (fs2.existsSync(tsFile) && tsFile.endsWith(".ts") && !visited.has(tsFile)) {
|
|
287
|
+
toVisit.push(tsFile);
|
|
288
|
+
break;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
} catch (error) {
|
|
293
|
+
logger.warn(
|
|
294
|
+
`Error processing ${current}: ${error instanceof Error ? error.message : String(error)}`
|
|
295
|
+
);
|
|
296
|
+
}
|
|
254
297
|
}
|
|
298
|
+
return visited;
|
|
299
|
+
}
|
|
300
|
+
function extractRelativeImports(sourceText) {
|
|
301
|
+
const imports = /* @__PURE__ */ new Set();
|
|
255
302
|
try {
|
|
256
|
-
const
|
|
257
|
-
|
|
258
|
-
|
|
303
|
+
const importExportRegex = /(?:import|export)(?:(?:[\s\n]*(?:type[\s\n]+)?(?:\*|\{[^}]*\}|[\w$]+)[\s\n]+from[\s\n]*)|[\s\n]+)(["'`])([^'"]+)\1/g;
|
|
304
|
+
let match;
|
|
305
|
+
while ((match = importExportRegex.exec(sourceText)) !== null) {
|
|
306
|
+
const importPath = match[2];
|
|
307
|
+
if (importPath.startsWith(".")) {
|
|
308
|
+
imports.add(importPath);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
const sideEffectImportRegex = /import\s+(["'`])([^'"]+)\1\s*;?/g;
|
|
312
|
+
while ((match = sideEffectImportRegex.exec(sourceText)) !== null) {
|
|
313
|
+
const importPath = match[2];
|
|
314
|
+
if (importPath.startsWith(".")) {
|
|
315
|
+
imports.add(importPath);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
const dynamicImportRegex = /import\s*\(\s*(["'`])([^'"]+)\1\s*\)/g;
|
|
319
|
+
while ((match = dynamicImportRegex.exec(sourceText)) !== null) {
|
|
320
|
+
const importPath = match[2];
|
|
321
|
+
if (importPath.startsWith(".")) {
|
|
322
|
+
imports.add(importPath);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
259
325
|
} catch (error) {
|
|
260
326
|
logger.warn(
|
|
261
|
-
`
|
|
327
|
+
`Error extracting imports: ${error instanceof Error ? error.message : String(error)}`
|
|
262
328
|
);
|
|
263
|
-
return {};
|
|
264
329
|
}
|
|
330
|
+
return Array.from(imports);
|
|
265
331
|
}
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
332
|
+
async function generateDtsContent(tsFiles) {
|
|
333
|
+
const dtsMap = /* @__PURE__ */ new Map();
|
|
334
|
+
await Promise.all(
|
|
335
|
+
Array.from(tsFiles).map(async (tsFile) => {
|
|
336
|
+
try {
|
|
337
|
+
const dtsPath = tsFile.replace(/\.tsx?$/, ".d.ts");
|
|
338
|
+
const sourceText = await fs2.promises.readFile(tsFile, "utf8");
|
|
339
|
+
const { code: declaration } = oxc.isolatedDeclaration(
|
|
340
|
+
tsFile,
|
|
341
|
+
sourceText
|
|
342
|
+
);
|
|
343
|
+
if (declaration) {
|
|
344
|
+
dtsMap.set(dtsPath, declaration);
|
|
345
|
+
}
|
|
346
|
+
} catch (error) {
|
|
347
|
+
logger.warn(
|
|
348
|
+
`Failed to generate declaration for ${tsFile}: ${error instanceof Error ? error.message : String(error)}`
|
|
349
|
+
);
|
|
350
|
+
}
|
|
351
|
+
})
|
|
352
|
+
);
|
|
353
|
+
return dtsMap;
|
|
354
|
+
}
|
|
355
|
+
async function bundleDtsContent(entryFile, dtsMap, format, options, rootDir) {
|
|
356
|
+
const VIRTUAL_PREFIX = "\0virtual:";
|
|
357
|
+
const entryDtsPath = entryFile.replace(/\.tsx?$/, ".d.ts");
|
|
358
|
+
const virtualEntry = `${VIRTUAL_PREFIX}${entryDtsPath}`;
|
|
359
|
+
const virtualPlugin = {
|
|
360
|
+
name: "virtual-dts",
|
|
361
|
+
resolveId(source, importer) {
|
|
362
|
+
if (source.startsWith(VIRTUAL_PREFIX)) {
|
|
363
|
+
return source;
|
|
364
|
+
}
|
|
365
|
+
if (importer?.startsWith(VIRTUAL_PREFIX)) {
|
|
366
|
+
const importerPath = importer.slice(VIRTUAL_PREFIX.length);
|
|
367
|
+
const importerDir = path2.dirname(importerPath);
|
|
368
|
+
if (source.startsWith(".")) {
|
|
369
|
+
const resolvedPath = path2.resolve(importerDir, source);
|
|
370
|
+
for (const ext of ["", ".d.ts", "/index.d.ts"]) {
|
|
371
|
+
const fullPath = `${resolvedPath}${ext}`;
|
|
372
|
+
if (dtsMap.has(fullPath)) {
|
|
373
|
+
return `${VIRTUAL_PREFIX}${fullPath}`;
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
return null;
|
|
379
|
+
},
|
|
380
|
+
load(id) {
|
|
381
|
+
if (id.startsWith(VIRTUAL_PREFIX)) {
|
|
382
|
+
const actualPath = id.slice(VIRTUAL_PREFIX.length);
|
|
383
|
+
return dtsMap.get(actualPath) || null;
|
|
384
|
+
}
|
|
385
|
+
return null;
|
|
386
|
+
}
|
|
387
|
+
};
|
|
388
|
+
const packageJson = loadPackageJson(rootDir);
|
|
274
389
|
const externalPatterns = getExternalPatterns(options, packageJson);
|
|
275
390
|
const noExternalPatterns = getNoExternalPatterns(options);
|
|
276
391
|
let bundle;
|
|
277
|
-
let result;
|
|
278
392
|
try {
|
|
279
393
|
bundle = await rollup({
|
|
280
|
-
input:
|
|
394
|
+
input: virtualEntry,
|
|
281
395
|
onwarn(warning, handler) {
|
|
282
396
|
if (warning.code === "UNRESOLVED_IMPORT" || warning.code === "CIRCULAR_DEPENDENCY" || warning.code === "EMPTY_BUNDLE") {
|
|
283
397
|
return;
|
|
284
398
|
}
|
|
285
|
-
|
|
399
|
+
handler(warning);
|
|
286
400
|
},
|
|
287
|
-
plugins: [
|
|
288
|
-
dtsPlugin({
|
|
289
|
-
tsconfig: tsconfigPath,
|
|
290
|
-
compilerOptions: {
|
|
291
|
-
...compilerOptions ? ts.parseJsonConfigFileContent(
|
|
292
|
-
{ compilerOptions },
|
|
293
|
-
ts.sys,
|
|
294
|
-
"./"
|
|
295
|
-
).options : {},
|
|
296
|
-
declaration: true,
|
|
297
|
-
noEmit: false,
|
|
298
|
-
emitDeclarationOnly: true,
|
|
299
|
-
noEmitOnError: true,
|
|
300
|
-
checkJs: false,
|
|
301
|
-
declarationMap: false,
|
|
302
|
-
skipLibCheck: true,
|
|
303
|
-
preserveSymlinks: false,
|
|
304
|
-
target: ScriptTarget.ESNext
|
|
305
|
-
}
|
|
306
|
-
})
|
|
307
|
-
],
|
|
401
|
+
plugins: [virtualPlugin, dtsPlugin()],
|
|
308
402
|
external: (source) => externalPatterns.some((re) => re.test(source)) && !noExternalPatterns.some((re) => re.test(source))
|
|
309
403
|
});
|
|
310
404
|
const { output } = await bundle.generate({ format });
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
405
|
+
if (!output[0]?.code) {
|
|
406
|
+
throw new Error("Generated bundle is empty");
|
|
407
|
+
}
|
|
408
|
+
return output[0].code;
|
|
409
|
+
} catch (error) {
|
|
410
|
+
throw new Error(`DTS bundling failed: ${parseErrorMessage(error)}`);
|
|
316
411
|
} finally {
|
|
317
412
|
if (bundle) await bundle.close();
|
|
318
413
|
}
|
|
319
|
-
if (!result) {
|
|
320
|
-
throw new Error("Failed to generate bundled DTS content");
|
|
321
|
-
}
|
|
322
|
-
return result;
|
|
323
414
|
}
|
|
324
415
|
function validateInputs(rootDir, entry) {
|
|
325
416
|
const absoluteRootDir = path2.resolve(rootDir);
|
|
326
417
|
const absoluteEntry = path2.resolve(absoluteRootDir, entry);
|
|
327
|
-
if (!
|
|
418
|
+
if (!fs2.existsSync(absoluteRootDir)) {
|
|
328
419
|
throw new Error(`Root directory does not exist: ${absoluteRootDir}`);
|
|
329
420
|
}
|
|
330
|
-
if (!
|
|
421
|
+
if (!fs2.existsSync(absoluteEntry)) {
|
|
331
422
|
throw new Error(`Entry file does not exist: ${absoluteEntry}`);
|
|
332
423
|
}
|
|
333
424
|
if (!absoluteEntry.endsWith(".ts")) {
|
|
@@ -343,24 +434,9 @@ function validateInputs(rootDir, entry) {
|
|
|
343
434
|
|
|
344
435
|
// src/dts/worker.ts
|
|
345
436
|
self.onmessage = async (event) => {
|
|
346
|
-
const {
|
|
347
|
-
name,
|
|
348
|
-
rootDir,
|
|
349
|
-
outDir,
|
|
350
|
-
entry,
|
|
351
|
-
format,
|
|
352
|
-
packageType,
|
|
353
|
-
dtsOptions,
|
|
354
|
-
options
|
|
355
|
-
} = event.data;
|
|
437
|
+
const { name, rootDir, outDir, entry, format, packageType, options } = event.data;
|
|
356
438
|
try {
|
|
357
|
-
const content = await generateDts(
|
|
358
|
-
rootDir,
|
|
359
|
-
entry,
|
|
360
|
-
format,
|
|
361
|
-
options,
|
|
362
|
-
dtsOptions
|
|
363
|
-
);
|
|
439
|
+
const content = await generateDts(rootDir, entry, format, options);
|
|
364
440
|
const entryName = getEntryNameOnly(entry);
|
|
365
441
|
const extension = getDefaultDtsExtention(format, packageType);
|
|
366
442
|
const outputRelativePath = `${outDir}/${entryName}${extension}`;
|
|
@@ -531,8 +607,6 @@ async function build(options, rootDir) {
|
|
|
531
607
|
if (options.dts) {
|
|
532
608
|
const dtsStartTime = performance.now();
|
|
533
609
|
logger.progress("DTS", "Bundling types");
|
|
534
|
-
const dtsOptions = typeof options.dts === "object" ? options.dts : {};
|
|
535
|
-
const entries = dtsOptions.entry || options.entry;
|
|
536
610
|
const formatsToProcess = options.format.filter((fmt) => {
|
|
537
611
|
if (fmt === "iife" && !isModulePackage(packageType) && options.format.includes("cjs")) {
|
|
538
612
|
return false;
|
|
@@ -542,14 +616,13 @@ async function build(options, rootDir) {
|
|
|
542
616
|
const dtsWorker = new DtsWorker();
|
|
543
617
|
try {
|
|
544
618
|
const dtsPromises = formatsToProcess.flatMap(
|
|
545
|
-
(fmt) =>
|
|
619
|
+
(fmt) => options.entry.map(
|
|
546
620
|
(entry) => generateDtsForEntry(
|
|
547
621
|
options,
|
|
548
622
|
rootDir,
|
|
549
623
|
entry,
|
|
550
624
|
fmt,
|
|
551
625
|
packageType,
|
|
552
|
-
dtsOptions,
|
|
553
626
|
dtsWorker
|
|
554
627
|
)
|
|
555
628
|
)
|
|
@@ -564,7 +637,7 @@ async function build(options, rootDir) {
|
|
|
564
637
|
await dtsWorker.cleanup();
|
|
565
638
|
}
|
|
566
639
|
}
|
|
567
|
-
async function generateDtsForEntry(options, rootDir, entry, fmt, packageType,
|
|
640
|
+
async function generateDtsForEntry(options, rootDir, entry, fmt, packageType, dtsWorker) {
|
|
568
641
|
const task = {
|
|
569
642
|
name: options.name,
|
|
570
643
|
rootDir,
|
|
@@ -572,7 +645,6 @@ async function generateDtsForEntry(options, rootDir, entry, fmt, packageType, dt
|
|
|
572
645
|
entry,
|
|
573
646
|
format: fmt,
|
|
574
647
|
packageType,
|
|
575
|
-
dtsOptions,
|
|
576
648
|
options
|
|
577
649
|
};
|
|
578
650
|
await dtsWorker.process(task);
|
|
@@ -800,14 +872,14 @@ async function handleBuild(options, rootDir) {
|
|
|
800
872
|
}
|
|
801
873
|
function cleanOutDir(rootDir, outdir) {
|
|
802
874
|
const outdirPath = path2.join(rootDir, outdir);
|
|
803
|
-
if (
|
|
875
|
+
if (fs2.existsSync(outdirPath)) {
|
|
804
876
|
try {
|
|
805
|
-
|
|
877
|
+
fs2.rmSync(outdirPath, { recursive: true, force: true });
|
|
806
878
|
} catch (error) {
|
|
807
879
|
logger.error(`Failed to clean output directory: ${error}`);
|
|
808
880
|
}
|
|
809
881
|
}
|
|
810
|
-
|
|
882
|
+
fs2.mkdirSync(outdirPath, { recursive: true });
|
|
811
883
|
}
|
|
812
884
|
main().catch((error) => {
|
|
813
885
|
handleError(error);
|
package/build/dtsWorker.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';var h=require('path'),
|
|
1
|
+
'use strict';var h=require('path'),y=require('fs'),N=require('oxc-transform'),rollup=require('rollup'),L=require('rollup-plugin-dts');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var h__default=/*#__PURE__*/_interopDefault(h);var y__default=/*#__PURE__*/_interopDefault(y);var N__default=/*#__PURE__*/_interopDefault(N);var L__default=/*#__PURE__*/_interopDefault(L);var f=r=>r instanceof Error?r.message:String(r);function w(r){return r.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function $(r,t){switch(r){case "esm":return ".d.mts";case "cjs":return C(t)?".d.cts":".d.ts";case "iife":return ".d.ts"}}function C(r){return r==="module"}function b(r){return r.split("/").pop()?.split(".").slice(0,-1).join(".")||""}function D(r){return r?Array.from(new Set([...Object.keys(r.dependencies||{}),...Object.keys(r.peerDependencies||{})])):[]}function v(r){return r.map(t=>typeof t=="string"?new RegExp(`^${w(t)}($|\\/|\\\\)`):t)}function P(r,t){return v(r.external||[]).concat(D(t).map(e=>new RegExp(`^${w(e)}($|\\/|\\\\)`)))}function W(r){return v(r.noExternal||[])}var p={MAX_LABEL_LENGTH:5,colors:{cli:"183",info:"240",warn:"221",error:"203",progress:{ESM:"214",CJS:"114",IIFE:"105",DTS:"75"},default:"255"},labels:{cli:"BUNUP",info:"INFO",warn:"WARN",error:"ERROR"},formatMessage(r,t,e){let s=" ".repeat(Math.max(0,this.MAX_LABEL_LENGTH-t.length));return `\x1B[38;5;${r}m[${t}]\x1B[0m ${s}${e}`},cli(r){let t=this.labels.cli;console.log(this.formatMessage(this.colors.cli,t,r));},info(r){let t=this.labels.info;console.log(this.formatMessage(this.colors.info,t,r));},warn(r){let t=this.labels.warn;console.warn(this.formatMessage(this.colors.warn,t,r));},error(r){let t=this.labels.error;console.error(this.formatMessage(this.colors.error,t,r));},progress(r,t){let e=String(r),s=this.colors.default;for(let[n,o]of Object.entries(this.colors.progress))if(e.includes(n)){s=o;break}console.log(this.formatMessage(s,e,t));}};function S(r,t){return `${t?`${t.replace(/-/g,"_")}_`:""}${r}`.toUpperCase()}function O(r){let t=h__default.default.join(r,"package.json");try{if(!y__default.default.existsSync(t))return null;let e=y__default.default.readFileSync(t,"utf8");return JSON.parse(e)}catch(e){return p.error(`Failed to load package.json at ${t}: ${f(e)}`),null}}async function M(r,t,e,s){let{absoluteRootDir:n,absoluteEntry:o}=V(r,t),i=await _(o),a=await J(i);return q(o,a,e,s,n)}async function _(r){let t=new Set,e=[r];for(;e.length>0;){let s=e.pop();if(!(!s||t.has(s))){t.add(s);try{let n=await y__default.default.promises.readFile(s,"utf8"),o=U(n);for(let i of o){let a=h__default.default.dirname(s),l=h__default.default.resolve(a,i),m=[l,`${l}.ts`,`${l}.tsx`,`${l}/index.ts`,`${l}/index.tsx`];for(let g of m)if(y__default.default.existsSync(g)&&g.endsWith(".ts")&&!t.has(g)){e.push(g);break}}}catch(n){p.warn(`Error processing ${s}: ${n instanceof Error?n.message:String(n)}`);}}}return t}function U(r){let t=new Set;try{let e=/(?:import|export)(?:(?:[\s\n]*(?:type[\s\n]+)?(?:\*|\{[^}]*\}|[\w$]+)[\s\n]+from[\s\n]*)|[\s\n]+)(["'`])([^'"]+)\1/g,s;for(;(s=e.exec(r))!==null;){let i=s[2];i.startsWith(".")&&t.add(i);}let n=/import\s+(["'`])([^'"]+)\1\s*;?/g;for(;(s=n.exec(r))!==null;){let i=s[2];i.startsWith(".")&&t.add(i);}let o=/import\s*\(\s*(["'`])([^'"]+)\1\s*\)/g;for(;(s=o.exec(r))!==null;){let i=s[2];i.startsWith(".")&&t.add(i);}}catch(e){p.warn(`Error extracting imports: ${e instanceof Error?e.message:String(e)}`);}return Array.from(t)}async function J(r){let t=new Map;return await Promise.all(Array.from(r).map(async e=>{try{let s=e.replace(/\.tsx?$/,".d.ts"),n=await y__default.default.promises.readFile(e,"utf8"),{code:o}=N__default.default.isolatedDeclaration(e,n);o&&t.set(s,o);}catch(s){p.warn(`Failed to generate declaration for ${e}: ${s instanceof Error?s.message:String(s)}`);}})),t}async function q(r,t,e,s,n){let o="\0virtual:",i=r.replace(/\.tsx?$/,".d.ts"),a=`${o}${i}`,l={name:"virtual-dts",resolveId(c,u){if(c.startsWith(o))return c;if(u?.startsWith(o)){let d=u.slice(o.length),T=h__default.default.dirname(d);if(c.startsWith(".")){let F=h__default.default.resolve(T,c);for(let j of ["",".d.ts","/index.d.ts"]){let k=`${F}${j}`;if(t.has(k))return `${o}${k}`}}}return null},load(c){if(c.startsWith(o)){let u=c.slice(o.length);return t.get(u)||null}return null}},m=O(n),g=P(s,m),E=W(s),x;try{x=await rollup.rollup({input:a,onwarn(u,d){u.code==="UNRESOLVED_IMPORT"||u.code==="CIRCULAR_DEPENDENCY"||u.code==="EMPTY_BUNDLE"||d(u);},plugins:[l,L__default.default()],external:u=>g.some(d=>d.test(u))&&!E.some(d=>d.test(u))});let{output:c}=await x.generate({format:e});if(!c[0]?.code)throw new Error("Generated bundle is empty");return c[0].code}catch(c){throw new Error(`DTS bundling failed: ${f(c)}`)}finally{x&&await x.close();}}function V(r,t){let e=h__default.default.resolve(r),s=h__default.default.resolve(e,t);if(!y__default.default.existsSync(e))throw new Error(`Root directory does not exist: ${e}`);if(!y__default.default.existsSync(s))throw new Error(`Entry file does not exist: ${s}`);if(!s.endsWith(".ts"))throw new Error(`Entry file must be a TypeScript file (.ts): ${s}`);if(h__default.default.relative(e,s).startsWith(".."))throw new Error(`Entry file must be within rootDir: ${s}`);return {absoluteRootDir:e,absoluteEntry:s}}self.onmessage=async r=>{let{name:t,rootDir:e,outDir:s,entry:n,format:o,packageType:i,options:a}=r.data;try{let l=await M(e,n,o,a),m=b(n),g=$(o,i),E=`${s}/${m}${g}`,x=`${e}/${E}`;await Bun.write(x,l);let c={name:t,success:!0,outputRelativePath:E};self.postMessage(c);}catch(l){let m={success:false,error:f(l)};self.postMessage(m);}};var B=class{constructor(t=navigator.hardwareConcurrency||4){this.workers=[];this.queue=[];this.busyWorkers=new Set;this.isShuttingDown=false;this.maxWorkers=t;}async process(t){if(this.isShuttingDown)throw new Error("Worker pool is shutting down");return new Promise((e,s)=>{this.queue.push({task:t,resolve:e,reject:s}),this.processQueue();})}processQueue(){if(!(this.queue.length===0||this.isShuttingDown))if(this.workers.length<this.maxWorkers){let t=new Worker(h__default.default.join(__dirname,"./dtsWorker.js"));this.workers.push(t),this.assignTaskToWorker(t);}else {let t=this.workers.find(e=>!this.busyWorkers.has(e));t&&this.assignTaskToWorker(t);}}assignTaskToWorker(t){let e=this.queue.shift();if(!e)return;let{task:s,resolve:n,reject:o}=e;this.busyWorkers.add(t);let i=()=>{this.busyWorkers.delete(t),this.isShuttingDown&&this.busyWorkers.size===0?this.terminateAllWorkers():this.processQueue();};t.onmessage=a=>{a.data.success?(p.progress(S("DTS",a.data.name),a.data.outputRelativePath),n()):(p.error(`DTS generation failed: ${a.data.error}`),o(new Error(a.data.error))),i();},t.onerror=a=>{let l=f(a);p.error(`Worker error: ${l}`),o(a),i();},t.postMessage(s);}terminateAllWorkers(){this.workers.forEach(t=>{try{t.terminate();}catch(e){p.error(`Error terminating worker: ${f(e)}`);}}),this.workers=[],this.busyWorkers.clear();}async cleanup(){if(this.isShuttingDown=true,this.busyWorkers.size===0){this.terminateAllWorkers();return}return new Promise(t=>{let e=setInterval(()=>{this.busyWorkers.size===0&&(clearInterval(e),this.terminateAllWorkers(),t());},100);setTimeout(()=>{clearInterval(e),this.terminateAllWorkers(),t();},5e3);})}};exports.DtsWorker=B;
|
package/build/index.d.mts
CHANGED
|
@@ -3,18 +3,6 @@ type WithOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
|
3
3
|
type Format = 'esm' | 'cjs' | 'iife';
|
|
4
4
|
type Target = 'bun' | 'node' | 'browser';
|
|
5
5
|
type External = string[];
|
|
6
|
-
interface DtsOptions {
|
|
7
|
-
/**
|
|
8
|
-
* Entry files to generate declaration files for
|
|
9
|
-
* If not specified, the main entry points will be used
|
|
10
|
-
*/
|
|
11
|
-
entry?: string[];
|
|
12
|
-
/**
|
|
13
|
-
* Path to a specific tsconfig.json file to use for declaration generation
|
|
14
|
-
* If not specified, the default tsconfig.json will be used
|
|
15
|
-
*/
|
|
16
|
-
preferredTsconfigPath?: string;
|
|
17
|
-
}
|
|
18
6
|
interface BunupOptions {
|
|
19
7
|
/**
|
|
20
8
|
* Name of the build configuration
|
|
@@ -68,9 +56,8 @@ interface BunupOptions {
|
|
|
68
56
|
watch?: boolean;
|
|
69
57
|
/**
|
|
70
58
|
* Whether to generate TypeScript declaration files (.d.ts)
|
|
71
|
-
* Can be a boolean or a DtsOptions object for more control
|
|
72
59
|
*/
|
|
73
|
-
dts?: boolean
|
|
60
|
+
dts?: boolean;
|
|
74
61
|
/**
|
|
75
62
|
* External packages that should not be bundled
|
|
76
63
|
* Useful for dependencies that should be kept as external imports
|
package/build/index.d.ts
CHANGED
|
@@ -3,18 +3,6 @@ type WithOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
|
3
3
|
type Format = 'esm' | 'cjs' | 'iife';
|
|
4
4
|
type Target = 'bun' | 'node' | 'browser';
|
|
5
5
|
type External = string[];
|
|
6
|
-
interface DtsOptions {
|
|
7
|
-
/**
|
|
8
|
-
* Entry files to generate declaration files for
|
|
9
|
-
* If not specified, the main entry points will be used
|
|
10
|
-
*/
|
|
11
|
-
entry?: string[];
|
|
12
|
-
/**
|
|
13
|
-
* Path to a specific tsconfig.json file to use for declaration generation
|
|
14
|
-
* If not specified, the default tsconfig.json will be used
|
|
15
|
-
*/
|
|
16
|
-
preferredTsconfigPath?: string;
|
|
17
|
-
}
|
|
18
6
|
interface BunupOptions {
|
|
19
7
|
/**
|
|
20
8
|
* Name of the build configuration
|
|
@@ -68,9 +56,8 @@ interface BunupOptions {
|
|
|
68
56
|
watch?: boolean;
|
|
69
57
|
/**
|
|
70
58
|
* Whether to generate TypeScript declaration files (.d.ts)
|
|
71
|
-
* Can be a boolean or a DtsOptions object for more control
|
|
72
59
|
*/
|
|
73
|
-
dts?: boolean
|
|
60
|
+
dts?: boolean;
|
|
74
61
|
/**
|
|
75
62
|
* External packages that should not be bundled
|
|
76
63
|
* Useful for dependencies that should be kept as external imports
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bunup",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "A extremely fast, zero-config bundler for TypeScript & JavaScript, powered by Bun.",
|
|
5
5
|
"main": "./build/index.js",
|
|
6
6
|
"types": "./build/index.d.ts",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"tsup": "^8.0.2",
|
|
25
25
|
"typescript": "^5.4.3",
|
|
26
26
|
"vitest": "^2.0.5",
|
|
27
|
-
"bunup": "0.1.
|
|
27
|
+
"bunup": "0.1.4"
|
|
28
28
|
},
|
|
29
29
|
"peerDependencies": {
|
|
30
30
|
"typescript": ">=4.5.0"
|
|
@@ -54,6 +54,7 @@
|
|
|
54
54
|
"author": "Arshad Yaseen <m@arshadyaseen.com> (https://arshadyaseen.com)",
|
|
55
55
|
"dependencies": {
|
|
56
56
|
"chokidar": "^4.0.3",
|
|
57
|
+
"oxc-transform": "^0.58.1",
|
|
57
58
|
"rollup": "^4.35.0",
|
|
58
59
|
"rollup-plugin-dts": "^6.1.1"
|
|
59
60
|
},
|