@bunup/dts 0.14.20 → 0.14.22
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/LICENSE +21 -0
- package/dist/index.d.ts +6 -1
- package/dist/index.js +176 -128
- package/package.json +51 -34
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 bunup
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ type GenerateDtsOptions = {
|
|
|
18
18
|
* Path to the preferred tsconfig.json file
|
|
19
19
|
* By default, the closest tsconfig.json file will be used
|
|
20
20
|
*/
|
|
21
|
-
|
|
21
|
+
preferredTsconfig?: string;
|
|
22
22
|
/**
|
|
23
23
|
* Controls which external modules should be resolved
|
|
24
24
|
* - `true` to resolve all external modules
|
|
@@ -44,6 +44,11 @@ type GenerateDtsOptions = {
|
|
|
44
44
|
* Whether to minify the generated declaration files to reduce the size of the declaration file.
|
|
45
45
|
*/
|
|
46
46
|
minify?: boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Whether to use typescript native compiler for generating declaration files.
|
|
49
|
+
* When enabled, you won't need explicit type annotations for exports (which are required by default when using isolated declarations).
|
|
50
|
+
*/
|
|
51
|
+
inferTypes?: boolean;
|
|
47
52
|
};
|
|
48
53
|
type GenerateDtsResultFile = {
|
|
49
54
|
/**
|
package/dist/index.js
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
//
|
|
2
|
-
import
|
|
1
|
+
// src/generate.ts
|
|
2
|
+
import { rm } from "node:fs/promises";
|
|
3
|
+
import path2 from "node:path";
|
|
3
4
|
import { isolatedDeclaration } from "oxc-transform";
|
|
4
5
|
import { resolveTsImportPath } from "ts-import-resolver";
|
|
5
6
|
|
|
6
|
-
//
|
|
7
|
+
// src/constants.ts
|
|
7
8
|
var EMPTY_EXPORT = "export {};";
|
|
8
9
|
|
|
9
|
-
//
|
|
10
|
+
// src/fake-js.ts
|
|
10
11
|
import { parse } from "@babel/parser";
|
|
11
12
|
|
|
12
|
-
//
|
|
13
|
+
// src/re.ts
|
|
13
14
|
var IMPORT_TYPE_RE = /import\s+type\s+/g;
|
|
14
15
|
var EXPORT_TYPE_RE = /export\s+type\s+/g;
|
|
15
16
|
var IMPORT_EXPORT_NAMES_RE = /(import|export)\s*{([^}]*)}/g;
|
|
@@ -24,7 +25,7 @@ var TS_RE = /\.[cm]?tsx?$|\.d\.[cm]?ts$/;
|
|
|
24
25
|
var EXTENSION_REGEX = /\.(d\.(ts|cts|mts)|[cm]?[jt]s)$/;
|
|
25
26
|
var NODE_MODULES_RE = /node_modules/;
|
|
26
27
|
|
|
27
|
-
//
|
|
28
|
+
// src/ast.ts
|
|
28
29
|
function isLikelyVariableOrTypeName(token) {
|
|
29
30
|
return CAPITAL_LETTER_RE.test(token) && !token.startsWith("/*") && !token.startsWith("@") && !token.startsWith('"') && !token.startsWith("'") && !token.startsWith("`");
|
|
30
31
|
}
|
|
@@ -82,7 +83,7 @@ function getName(node, source) {
|
|
|
82
83
|
break;
|
|
83
84
|
case "VariableDeclaration": {
|
|
84
85
|
const declarations = node.declarations;
|
|
85
|
-
if (declarations?.length === 1 && declarations[0]
|
|
86
|
+
if (declarations?.length === 1 && declarations[0]?.id?.type === "Identifier") {
|
|
86
87
|
return declarations[0].id.name;
|
|
87
88
|
}
|
|
88
89
|
break;
|
|
@@ -119,7 +120,7 @@ function getAllImportNames(body) {
|
|
|
119
120
|
return importNames;
|
|
120
121
|
}
|
|
121
122
|
|
|
122
|
-
//
|
|
123
|
+
// src/utils.ts
|
|
123
124
|
import { existsSync } from "node:fs";
|
|
124
125
|
import { normalize } from "node:path";
|
|
125
126
|
import { loadConfig } from "coffi";
|
|
@@ -220,7 +221,7 @@ function minifyDts(dts) {
|
|
|
220
221
|
}).code;
|
|
221
222
|
}
|
|
222
223
|
|
|
223
|
-
//
|
|
224
|
+
// src/fake-js.ts
|
|
224
225
|
async function dtsToFakeJs(dtsContent) {
|
|
225
226
|
const parsed = parse(dtsContent, {
|
|
226
227
|
sourceType: "module",
|
|
@@ -242,8 +243,9 @@ async function dtsToFakeJs(dtsContent) {
|
|
|
242
243
|
referencedNames.add(name);
|
|
243
244
|
}
|
|
244
245
|
const isDefaultExport = hasDefaultExportModifier(statement, statementText);
|
|
246
|
+
const varName = name || generateRandomString();
|
|
245
247
|
if (isDefaultExport) {
|
|
246
|
-
result.push(`export { ${
|
|
248
|
+
result.push(`export { ${varName} as default };`);
|
|
247
249
|
if (isDefaultReExport(statement)) {
|
|
248
250
|
continue;
|
|
249
251
|
}
|
|
@@ -265,7 +267,6 @@ async function dtsToFakeJs(dtsContent) {
|
|
|
265
267
|
statementTextWithCommentsAttatched = removeExportSyntaxes(statementTextWithCommentsAttatched);
|
|
266
268
|
}
|
|
267
269
|
const tokens = tokenizeText(statementTextWithCommentsAttatched, referencedNames);
|
|
268
|
-
const varName = name || generateRandomString();
|
|
269
270
|
result.push(`var ${varName} = [${tokens.join(", ")}];`);
|
|
270
271
|
if (isExported && !isDefaultExport && !exportedNames.has(varName)) {
|
|
271
272
|
result.push(`export { ${varName} };`);
|
|
@@ -368,7 +369,7 @@ function processTokenElement(element) {
|
|
|
368
369
|
parts.push(unescapeNewlinesAndTabs(element.quasis[0]?.value?.raw || ""));
|
|
369
370
|
for (let i = 0;i < element.expressions.length; i++) {
|
|
370
371
|
const expr = element.expressions[i];
|
|
371
|
-
if (expr
|
|
372
|
+
if (expr?.type === "Identifier") {
|
|
372
373
|
parts.push(expr.name);
|
|
373
374
|
}
|
|
374
375
|
parts.push(unescapeNewlinesAndTabs(element.quasis[i + 1]?.value?.raw || ""));
|
|
@@ -386,7 +387,7 @@ function unescapeNewlinesAndTabs(text) {
|
|
|
386
387
|
}
|
|
387
388
|
function handleNamespace(stmt) {
|
|
388
389
|
const expr = stmt.expression;
|
|
389
|
-
if (!expr || expr.type !== "CallExpression" || expr.callee?.type !== "Identifier" || expr.arguments?.length !== 2 || expr.arguments[0]
|
|
390
|
+
if (!expr || expr.type !== "CallExpression" || expr.callee?.type !== "Identifier" || expr.arguments?.length !== 2 || expr.arguments[0]?.type !== "Identifier" || expr.arguments[1]?.type !== "ObjectExpression") {
|
|
390
391
|
return null;
|
|
391
392
|
}
|
|
392
393
|
const namespaceName = expr.arguments[0].name;
|
|
@@ -406,7 +407,7 @@ function handleNamespace(stmt) {
|
|
|
406
407
|
}`;
|
|
407
408
|
}
|
|
408
409
|
|
|
409
|
-
//
|
|
410
|
+
// src/resolver.ts
|
|
410
411
|
import { dirname } from "node:path";
|
|
411
412
|
import process2 from "node:process";
|
|
412
413
|
import { ResolverFactory } from "oxc-resolver";
|
|
@@ -421,20 +422,18 @@ function createResolver({
|
|
|
421
422
|
extensions: [".d.ts", ".d.mts", ".d.cts", ".ts", ".mts", ".cts"],
|
|
422
423
|
tsconfig: tsconfig ? { configFile: tsconfig, references: "auto" } : undefined
|
|
423
424
|
});
|
|
424
|
-
const resolutionCache = new Map;
|
|
425
425
|
return (importSource, importer) => {
|
|
426
426
|
if (importSource === "bun")
|
|
427
427
|
return null;
|
|
428
|
-
const cacheKey = `${importSource}:${importer || ""}`;
|
|
429
|
-
if (resolutionCache.has(cacheKey)) {
|
|
430
|
-
return resolutionCache.get(cacheKey) || null;
|
|
431
|
-
}
|
|
432
428
|
let shouldResolve = false;
|
|
433
429
|
if (resolveOption !== undefined) {
|
|
434
430
|
if (typeof resolveOption === "boolean") {
|
|
435
431
|
shouldResolve = resolveOption;
|
|
436
432
|
} else if (Array.isArray(resolveOption)) {
|
|
437
433
|
shouldResolve = resolveOption.some((resolver2) => {
|
|
434
|
+
if (importer?.includes(resolver2.toString())) {
|
|
435
|
+
return true;
|
|
436
|
+
}
|
|
438
437
|
if (typeof resolver2 === "string") {
|
|
439
438
|
return resolver2 === importSource;
|
|
440
439
|
}
|
|
@@ -443,36 +442,56 @@ function createResolver({
|
|
|
443
442
|
}
|
|
444
443
|
}
|
|
445
444
|
if (!shouldResolve) {
|
|
446
|
-
resolutionCache.set(cacheKey, null);
|
|
447
445
|
return null;
|
|
448
446
|
}
|
|
449
447
|
const directory = importer ? dirname(importer) : cwd;
|
|
450
448
|
const resolution = resolver.sync(directory, importSource);
|
|
451
449
|
if (!resolution.path) {
|
|
452
|
-
resolutionCache.set(cacheKey, null);
|
|
453
450
|
return null;
|
|
454
451
|
}
|
|
455
452
|
const resolved = resolution.path;
|
|
456
453
|
if (JS_RE.test(resolved)) {
|
|
457
454
|
const dts = returnPathIfExists(resolved.replace(JS_RE, ".d.ts")) || returnPathIfExists(resolved.replace(JS_RE, ".d.mts")) || returnPathIfExists(resolved.replace(JS_RE, ".d.cts"));
|
|
458
|
-
|
|
459
|
-
resolutionCache.set(cacheKey, result2);
|
|
460
|
-
return result2;
|
|
455
|
+
return isTypeScriptFile(dts) ? dts : null;
|
|
461
456
|
}
|
|
462
|
-
|
|
463
|
-
resolutionCache.set(cacheKey, result);
|
|
464
|
-
return result;
|
|
457
|
+
return isTypeScriptFile(resolved) ? resolved : null;
|
|
465
458
|
};
|
|
466
459
|
}
|
|
467
460
|
|
|
468
|
-
//
|
|
461
|
+
// src/tsgo.ts
|
|
462
|
+
import { mkdtemp } from "node:fs/promises";
|
|
463
|
+
import { tmpdir } from "node:os";
|
|
464
|
+
import path from "node:path";
|
|
465
|
+
async function runTsgo(root, tsconfig) {
|
|
466
|
+
const tsgoPackage = import.meta.resolve("@typescript/native-preview/package.json");
|
|
467
|
+
const { default: getExePath } = await import(new URL("lib/getExePath.js", tsgoPackage).href);
|
|
468
|
+
const tsgo = getExePath();
|
|
469
|
+
const dist = await mkdtemp(path.join(tmpdir(), "bunup-dts-"));
|
|
470
|
+
const proc = Bun.spawn([
|
|
471
|
+
tsgo,
|
|
472
|
+
"--noEmit",
|
|
473
|
+
"false",
|
|
474
|
+
"--declaration",
|
|
475
|
+
"--emitDeclarationOnly",
|
|
476
|
+
...tsconfig ? ["-p", tsconfig] : [],
|
|
477
|
+
"--outDir",
|
|
478
|
+
dist,
|
|
479
|
+
"--rootDir",
|
|
480
|
+
root,
|
|
481
|
+
"--noCheck"
|
|
482
|
+
]);
|
|
483
|
+
await proc.exited;
|
|
484
|
+
return dist;
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
// src/generate.ts
|
|
469
488
|
async function generateDts(entrypoints, options = {}) {
|
|
470
|
-
const { resolve,
|
|
471
|
-
const cwd = options.cwd ?
|
|
472
|
-
const tsconfig = await loadTsConfig(cwd,
|
|
473
|
-
const nonAbsoluteEntrypoints = entrypoints.filter((entrypoint) => !
|
|
489
|
+
const { resolve, preferredTsconfig, naming } = options;
|
|
490
|
+
const cwd = options.cwd ? path2.resolve(options.cwd) : process.cwd();
|
|
491
|
+
const tsconfig = await loadTsConfig(cwd, preferredTsconfig);
|
|
492
|
+
const nonAbsoluteEntrypoints = entrypoints.filter((entrypoint) => !path2.isAbsolute(entrypoint));
|
|
474
493
|
const resolvedEntrypoints = await getFilesFromGlobs(nonAbsoluteEntrypoints, cwd);
|
|
475
|
-
const absoluteEntrypoints = entrypoints.filter((entrypoint) =>
|
|
494
|
+
const absoluteEntrypoints = entrypoints.filter((entrypoint) => path2.isAbsolute(entrypoint));
|
|
476
495
|
if (!filterTypescriptFiles([...resolvedEntrypoints, ...absoluteEntrypoints]).length) {
|
|
477
496
|
throw new Error("One or more of the entrypoints you provided do not exist. Please check that each entrypoint points to a valid file.");
|
|
478
497
|
}
|
|
@@ -482,107 +501,133 @@ async function generateDts(entrypoints, options = {}) {
|
|
|
482
501
|
resolveOption: resolve,
|
|
483
502
|
tsconfig: tsconfig.filepath
|
|
484
503
|
});
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
return { path: resolved };
|
|
498
|
-
}
|
|
499
|
-
}
|
|
500
|
-
const resolvedFromNodeModules = resolver(args.path, args.importer);
|
|
501
|
-
if (resolvedFromNodeModules) {
|
|
502
|
-
return { path: resolvedFromNodeModules };
|
|
503
|
-
}
|
|
504
|
-
return {
|
|
505
|
-
path: args.path,
|
|
506
|
-
external: true
|
|
507
|
-
};
|
|
508
|
-
});
|
|
509
|
-
build.onLoad({ filter: /\.(ts|tsx|d\.ts|d\.mts|d\.cts)$/ }, async (args) => {
|
|
510
|
-
const sourceText = await Bun.file(args.path).text();
|
|
511
|
-
const declarationResult = isolatedDeclaration(args.path, sourceText);
|
|
512
|
-
let fakeJsContent = "";
|
|
513
|
-
if (!collectedErrors.some((e) => e.file === args.path)) {
|
|
514
|
-
for (const error of declarationResult.errors) {
|
|
515
|
-
collectedErrors.push({
|
|
516
|
-
error,
|
|
517
|
-
file: args.path,
|
|
518
|
-
content: sourceText
|
|
504
|
+
let tsgoDist;
|
|
505
|
+
try {
|
|
506
|
+
const fakeJsPlugin = {
|
|
507
|
+
name: "fake-js",
|
|
508
|
+
async setup(build) {
|
|
509
|
+
build.onResolve({ filter: /.*/ }, (args) => {
|
|
510
|
+
if (!NODE_MODULES_RE.test(args.importer)) {
|
|
511
|
+
const resolved = resolveTsImportPath({
|
|
512
|
+
importer: args.importer,
|
|
513
|
+
path: args.path,
|
|
514
|
+
cwd,
|
|
515
|
+
tsconfig: tsconfig.config
|
|
519
516
|
});
|
|
517
|
+
if (resolved && isTypeScriptFile(resolved)) {
|
|
518
|
+
return { path: resolved };
|
|
519
|
+
}
|
|
520
520
|
}
|
|
521
|
+
const resolvedFromNodeModules = resolver(args.path, args.importer);
|
|
522
|
+
if (resolvedFromNodeModules) {
|
|
523
|
+
return { path: resolvedFromNodeModules };
|
|
524
|
+
}
|
|
525
|
+
return {
|
|
526
|
+
path: args.path,
|
|
527
|
+
external: true
|
|
528
|
+
};
|
|
529
|
+
});
|
|
530
|
+
if (options.inferTypes) {
|
|
531
|
+
tsgoDist = await runTsgo(cwd, tsconfig.filepath ?? undefined);
|
|
521
532
|
}
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
533
|
+
build.onLoad({ filter: /\.(ts|tsx|d\.ts|d\.mts|d\.cts)$/ }, async (args) => {
|
|
534
|
+
const sourceText = await Bun.file(args.path).text();
|
|
535
|
+
let declaration = "";
|
|
536
|
+
let isolatedDeclarationErrors = [];
|
|
537
|
+
if (NODE_MODULES_RE.test(args.path)) {
|
|
538
|
+
declaration = sourceText;
|
|
539
|
+
} else {
|
|
540
|
+
if (options.inferTypes && tsgoDist) {
|
|
541
|
+
const declarationPath = replaceExtension(path2.join(tsgoDist, args.path.replace(cwd, "")), ".d.ts");
|
|
542
|
+
declaration = await Bun.file(declarationPath).text();
|
|
543
|
+
} else {
|
|
544
|
+
const isolatedDeclarationResult = isolatedDeclaration(args.path, sourceText);
|
|
545
|
+
declaration = isolatedDeclarationResult.code;
|
|
546
|
+
if (isolatedDeclarationResult.errors) {
|
|
547
|
+
isolatedDeclarationErrors = isolatedDeclarationResult.errors;
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
let fakeJsContent = "";
|
|
552
|
+
if (!collectedErrors.some((e) => e.file === args.path)) {
|
|
553
|
+
for (const error of isolatedDeclarationErrors) {
|
|
554
|
+
collectedErrors.push({
|
|
555
|
+
error,
|
|
556
|
+
file: args.path,
|
|
557
|
+
content: sourceText
|
|
558
|
+
});
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
if (declaration) {
|
|
562
|
+
fakeJsContent = await dtsToFakeJs(declaration);
|
|
563
|
+
} else {
|
|
564
|
+
fakeJsContent = EMPTY_EXPORT;
|
|
565
|
+
}
|
|
566
|
+
return {
|
|
567
|
+
loader: "js",
|
|
568
|
+
contents: fakeJsContent
|
|
569
|
+
};
|
|
570
|
+
});
|
|
571
|
+
}
|
|
572
|
+
};
|
|
573
|
+
const result = await Bun.build({
|
|
574
|
+
entrypoints: [
|
|
575
|
+
...filterTypescriptFiles(resolvedEntrypoints).map((entry) => path2.resolve(path2.join(cwd, entry))),
|
|
576
|
+
...filterTypescriptFiles(absoluteEntrypoints)
|
|
577
|
+
],
|
|
578
|
+
format: "esm",
|
|
579
|
+
target: "node",
|
|
580
|
+
naming,
|
|
581
|
+
splitting: options.splitting,
|
|
582
|
+
plugins: [fakeJsPlugin],
|
|
583
|
+
packages: "external",
|
|
584
|
+
minify: options.minify,
|
|
585
|
+
throw: false,
|
|
586
|
+
tsconfig: options.preferredTsconfig ? path2.resolve(cwd, options.preferredTsconfig) : undefined
|
|
587
|
+
});
|
|
588
|
+
if (!result.success) {
|
|
589
|
+
throw new Error(`DTS bundling failed: ${result.logs}`);
|
|
562
590
|
}
|
|
563
|
-
|
|
564
|
-
|
|
591
|
+
const outputs = result.outputs.filter((output) => output.kind === "chunk" || output.kind === "entry-point");
|
|
592
|
+
const bundledFiles = [];
|
|
593
|
+
for (const output of outputs) {
|
|
594
|
+
const bundledFakeJsContent = await output.text();
|
|
595
|
+
const dtsContent = await fakeJsToDts(bundledFakeJsContent);
|
|
596
|
+
const entrypoint = output.kind === "entry-point" ? entrypoints[bundledFiles.length] : undefined;
|
|
597
|
+
const chunkFileName = output.kind === "chunk" ? replaceExtension(path2.basename(output.path), getDeclarationExtensionFromJsExtension(getExtension(output.path))) : undefined;
|
|
598
|
+
const outputPath = cleanPath(replaceExtension(cleanPath(output.path), getDeclarationExtensionFromJsExtension(getExtension(output.path))));
|
|
599
|
+
const treeshakedDts = isolatedDeclaration(`${generateRandomString()}.d.ts`, dtsContent);
|
|
600
|
+
if (!treeshakedDts.code.length && !treeshakedDts.errors.length) {
|
|
601
|
+
continue;
|
|
602
|
+
}
|
|
603
|
+
if (treeshakedDts.errors.length && !treeshakedDts.code) {
|
|
604
|
+
throw new Error(`DTS treeshaking failed for ${entrypoint || outputPath}
|
|
565
605
|
|
|
566
606
|
${JSON.stringify(treeshakedDts.errors, null, 2)}`);
|
|
567
|
-
}
|
|
568
|
-
bundledFiles.push({
|
|
569
|
-
kind: output.kind === "entry-point" ? "entry-point" : "chunk",
|
|
570
|
-
entrypoint,
|
|
571
|
-
chunkFileName,
|
|
572
|
-
outputPath,
|
|
573
|
-
dts: options.minify ? minifyDts(treeshakedDts.code) : treeshakedDts.code,
|
|
574
|
-
pathInfo: {
|
|
575
|
-
outputPathWithoutExtension: deleteExtension(outputPath),
|
|
576
|
-
ext: getExtension(outputPath)
|
|
577
607
|
}
|
|
578
|
-
|
|
608
|
+
bundledFiles.push({
|
|
609
|
+
kind: output.kind === "entry-point" ? "entry-point" : "chunk",
|
|
610
|
+
entrypoint,
|
|
611
|
+
chunkFileName,
|
|
612
|
+
outputPath,
|
|
613
|
+
dts: options.minify ? minifyDts(treeshakedDts.code) : treeshakedDts.code,
|
|
614
|
+
pathInfo: {
|
|
615
|
+
outputPathWithoutExtension: deleteExtension(outputPath),
|
|
616
|
+
ext: getExtension(outputPath)
|
|
617
|
+
}
|
|
618
|
+
});
|
|
619
|
+
}
|
|
620
|
+
return {
|
|
621
|
+
files: bundledFiles,
|
|
622
|
+
errors: collectedErrors
|
|
623
|
+
};
|
|
624
|
+
} finally {
|
|
625
|
+
if (tsgoDist) {
|
|
626
|
+
await rm(tsgoDist, { recursive: true, force: true });
|
|
627
|
+
}
|
|
579
628
|
}
|
|
580
|
-
return {
|
|
581
|
-
files: bundledFiles,
|
|
582
|
-
errors: collectedErrors
|
|
583
|
-
};
|
|
584
629
|
}
|
|
585
|
-
//
|
|
630
|
+
// src/isolated-decl-logger.ts
|
|
586
631
|
import pc from "picocolors";
|
|
587
632
|
var SEVERITY_CONFIG = {
|
|
588
633
|
dev: {
|
|
@@ -651,7 +696,7 @@ ${pc.gray(codeFrame)}
|
|
|
651
696
|
`);
|
|
652
697
|
}
|
|
653
698
|
function extractErrorCode(message) {
|
|
654
|
-
return message.split(":")[0];
|
|
699
|
+
return message.split(":")[0] ?? "";
|
|
655
700
|
}
|
|
656
701
|
function getSeverityFormatting(severity) {
|
|
657
702
|
const config = SEVERITY_CONFIG[isDev() ? "dev" : "prod"];
|
|
@@ -663,7 +708,10 @@ function calculatePosition(sourceText, labelStart) {
|
|
|
663
708
|
const lines = sourceText.slice(0, labelStart).split(`
|
|
664
709
|
`);
|
|
665
710
|
const lineNumber = lines.length;
|
|
666
|
-
const
|
|
711
|
+
const lastLine = lines[lines.length - 1];
|
|
712
|
+
if (!lastLine)
|
|
713
|
+
return "";
|
|
714
|
+
const columnStart = lastLine.length + 1;
|
|
667
715
|
return ` (${lineNumber}:${columnStart})`;
|
|
668
716
|
}
|
|
669
717
|
function generateOxcCodeFrame(sourceText, start, end) {
|
|
@@ -675,7 +723,7 @@ function generateOxcCodeFrame(sourceText, start, end) {
|
|
|
675
723
|
const lastNewlineIndex = sourceText.slice(0, start).lastIndexOf(`
|
|
676
724
|
`);
|
|
677
725
|
const startCol = start - lastNewlineIndex - 1;
|
|
678
|
-
const endCol = end ? Math.min(end - lastNewlineIndex - 1, lineContent
|
|
726
|
+
const endCol = end ? Math.min(end - lastNewlineIndex - 1, lineContent?.length ?? 0) : startCol + 1;
|
|
679
727
|
const underlineLength = Math.max(1, endCol - startCol);
|
|
680
728
|
const arrowLine = " ".repeat(startCol) + pc.dim(pc.blue("⎯".repeat(underlineLength)));
|
|
681
729
|
return `${lineContent}
|
package/package.json
CHANGED
|
@@ -1,24 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bunup/dts",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.14.22",
|
|
4
|
+
"description": "An extremely fast TypeScript declaration bundler built on Bun's native bundler.",
|
|
5
|
+
"homepage": "https://github.com/bunup/dts#readme",
|
|
6
|
+
"bugs": {
|
|
7
|
+
"url": "https://github.com/bunup/dts/issues"
|
|
8
|
+
},
|
|
9
|
+
"license": "MIT",
|
|
6
10
|
"files": [
|
|
7
11
|
"dist"
|
|
8
12
|
],
|
|
9
|
-
"
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
".": {
|
|
13
|
-
"import": {
|
|
14
|
-
"types": "./dist/index.d.ts",
|
|
15
|
-
"default": "./dist/index.js"
|
|
16
|
-
}
|
|
17
|
-
},
|
|
18
|
-
"./package.json": "./package.json"
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://github.com/bunup/dts.git"
|
|
19
16
|
},
|
|
20
17
|
"dependencies": {
|
|
21
18
|
"@babel/parser": "^7.28.4",
|
|
19
|
+
"@typescript/native-preview": "^7.0.0-dev.20251016.1",
|
|
22
20
|
"coffi": "^0.1.37",
|
|
23
21
|
"oxc-minify": "^0.93.0",
|
|
24
22
|
"oxc-resolver": "^11.9.0",
|
|
@@ -27,15 +25,31 @@
|
|
|
27
25
|
"std-env": "^3.9.0",
|
|
28
26
|
"ts-import-resolver": "^0.1.23"
|
|
29
27
|
},
|
|
30
|
-
"
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
28
|
+
"scripts": {
|
|
29
|
+
"build": "bunup",
|
|
30
|
+
"dev": "bunup --watch",
|
|
31
|
+
"postinstall": "bun simple-git-hooks",
|
|
32
|
+
"lint": "biome check .",
|
|
33
|
+
"lint:fix": "biome check --write .",
|
|
34
|
+
"release": "bumpp --commit --push --tag",
|
|
35
|
+
"test": "bun test",
|
|
36
|
+
"test:coverage": "bun test --coverage",
|
|
37
|
+
"test:watch": "bun test --watch",
|
|
38
|
+
"type-check": "tsc --noEmit"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@biomejs/biome": "^2.2.6",
|
|
42
|
+
"@types/bun": "^1.3.0",
|
|
43
|
+
"bumpp": "^10.3.1",
|
|
44
|
+
"bunup": "^0.14.21",
|
|
45
|
+
"simple-git-hooks": "^2.13.1",
|
|
46
|
+
"type-fest": "^5.1.0",
|
|
47
|
+
"typescript": "^5.9.3",
|
|
48
|
+
"zod": "^4.1.12"
|
|
49
|
+
},
|
|
50
|
+
"peerDependencies": {
|
|
51
|
+
"typescript": ">=4.5.0"
|
|
52
|
+
},
|
|
39
53
|
"keywords": [
|
|
40
54
|
"typescript",
|
|
41
55
|
"dts",
|
|
@@ -44,21 +58,24 @@
|
|
|
44
58
|
"bun",
|
|
45
59
|
"bun dts"
|
|
46
60
|
],
|
|
47
|
-
"repository": {
|
|
48
|
-
"type": "git",
|
|
49
|
-
"url": "git+https://github.com/bunup/bunup.git"
|
|
50
|
-
},
|
|
51
|
-
"funding": "https://github.com/sponsors/arshad-yaseen",
|
|
52
|
-
"homepage": "https://bunup.dev",
|
|
53
|
-
"peerDependencies": {
|
|
54
|
-
"typescript": "latest"
|
|
55
|
-
},
|
|
56
61
|
"peerDependenciesMeta": {
|
|
57
62
|
"typescript": {
|
|
58
63
|
"optional": true
|
|
59
64
|
}
|
|
60
65
|
},
|
|
61
|
-
"
|
|
62
|
-
|
|
63
|
-
|
|
66
|
+
"type": "module",
|
|
67
|
+
"exports": {
|
|
68
|
+
".": {
|
|
69
|
+
"import": {
|
|
70
|
+
"types": "./dist/index.d.ts",
|
|
71
|
+
"default": "./dist/index.js"
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
"./package.json": "./package.json"
|
|
75
|
+
},
|
|
76
|
+
"module": "./dist/index.js",
|
|
77
|
+
"simple-git-hooks": {
|
|
78
|
+
"pre-commit": "bun run lint && bun run type-check"
|
|
79
|
+
},
|
|
80
|
+
"types": "./dist/index.d.ts"
|
|
64
81
|
}
|