@bunup/dts 0.14.20 → 0.14.21
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 +1 -1
- package/dist/index.js +12 -8
- package/package.json +4 -1
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
|
package/dist/index.js
CHANGED
|
@@ -82,7 +82,7 @@ function getName(node, source) {
|
|
|
82
82
|
break;
|
|
83
83
|
case "VariableDeclaration": {
|
|
84
84
|
const declarations = node.declarations;
|
|
85
|
-
if (declarations?.length === 1 && declarations[0]
|
|
85
|
+
if (declarations?.length === 1 && declarations[0]?.id?.type === "Identifier") {
|
|
86
86
|
return declarations[0].id.name;
|
|
87
87
|
}
|
|
88
88
|
break;
|
|
@@ -386,7 +386,7 @@ function unescapeNewlinesAndTabs(text) {
|
|
|
386
386
|
}
|
|
387
387
|
function handleNamespace(stmt) {
|
|
388
388
|
const expr = stmt.expression;
|
|
389
|
-
if (!expr || expr.type !== "CallExpression" || expr.callee?.type !== "Identifier" || expr.arguments?.length !== 2 || expr.arguments[0]
|
|
389
|
+
if (!expr || expr.type !== "CallExpression" || expr.callee?.type !== "Identifier" || expr.arguments?.length !== 2 || expr.arguments[0]?.type !== "Identifier" || expr.arguments[1]?.type !== "ObjectExpression") {
|
|
390
390
|
return null;
|
|
391
391
|
}
|
|
392
392
|
const namespaceName = expr.arguments[0].name;
|
|
@@ -467,9 +467,9 @@ function createResolver({
|
|
|
467
467
|
|
|
468
468
|
// packages/dts/src/generate.ts
|
|
469
469
|
async function generateDts(entrypoints, options = {}) {
|
|
470
|
-
const { resolve,
|
|
470
|
+
const { resolve, preferredTsconfig, naming } = options;
|
|
471
471
|
const cwd = options.cwd ? path.resolve(options.cwd) : process.cwd();
|
|
472
|
-
const tsconfig = await loadTsConfig(cwd,
|
|
472
|
+
const tsconfig = await loadTsConfig(cwd, preferredTsconfig);
|
|
473
473
|
const nonAbsoluteEntrypoints = entrypoints.filter((entrypoint) => !path.isAbsolute(entrypoint));
|
|
474
474
|
const resolvedEntrypoints = await getFilesFromGlobs(nonAbsoluteEntrypoints, cwd);
|
|
475
475
|
const absoluteEntrypoints = entrypoints.filter((entrypoint) => path.isAbsolute(entrypoint));
|
|
@@ -543,7 +543,8 @@ async function generateDts(entrypoints, options = {}) {
|
|
|
543
543
|
plugins: [fakeJsPlugin],
|
|
544
544
|
packages: "external",
|
|
545
545
|
minify: options.minify,
|
|
546
|
-
throw: false
|
|
546
|
+
throw: false,
|
|
547
|
+
tsconfig: options.preferredTsconfig ? path.resolve(cwd, options.preferredTsconfig) : undefined
|
|
547
548
|
});
|
|
548
549
|
if (!result.success) {
|
|
549
550
|
throw new Error(`DTS bundling failed: ${result.logs}`);
|
|
@@ -651,7 +652,7 @@ ${pc.gray(codeFrame)}
|
|
|
651
652
|
`);
|
|
652
653
|
}
|
|
653
654
|
function extractErrorCode(message) {
|
|
654
|
-
return message.split(":")[0];
|
|
655
|
+
return message.split(":")[0] ?? "";
|
|
655
656
|
}
|
|
656
657
|
function getSeverityFormatting(severity) {
|
|
657
658
|
const config = SEVERITY_CONFIG[isDev() ? "dev" : "prod"];
|
|
@@ -663,7 +664,10 @@ function calculatePosition(sourceText, labelStart) {
|
|
|
663
664
|
const lines = sourceText.slice(0, labelStart).split(`
|
|
664
665
|
`);
|
|
665
666
|
const lineNumber = lines.length;
|
|
666
|
-
const
|
|
667
|
+
const lastLine = lines[lines.length - 1];
|
|
668
|
+
if (!lastLine)
|
|
669
|
+
return "";
|
|
670
|
+
const columnStart = lastLine.length + 1;
|
|
667
671
|
return ` (${lineNumber}:${columnStart})`;
|
|
668
672
|
}
|
|
669
673
|
function generateOxcCodeFrame(sourceText, start, end) {
|
|
@@ -675,7 +679,7 @@ function generateOxcCodeFrame(sourceText, start, end) {
|
|
|
675
679
|
const lastNewlineIndex = sourceText.slice(0, start).lastIndexOf(`
|
|
676
680
|
`);
|
|
677
681
|
const startCol = start - lastNewlineIndex - 1;
|
|
678
|
-
const endCol = end ? Math.min(end - lastNewlineIndex - 1, lineContent
|
|
682
|
+
const endCol = end ? Math.min(end - lastNewlineIndex - 1, lineContent?.length ?? 0) : startCol + 1;
|
|
679
683
|
const underlineLength = Math.max(1, endCol - startCol);
|
|
680
684
|
const arrowLine = " ".repeat(startCol) + pc.dim(pc.blue("⎯".repeat(underlineLength)));
|
|
681
685
|
return `${lineContent}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bunup/dts",
|
|
3
3
|
"description": "An extremely fast TypeScript declaration file generator and bundler that outputs to a single file.",
|
|
4
|
-
"version": "0.14.
|
|
4
|
+
"version": "0.14.21",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
7
7
|
"dist"
|
|
@@ -17,6 +17,9 @@
|
|
|
17
17
|
},
|
|
18
18
|
"./package.json": "./package.json"
|
|
19
19
|
},
|
|
20
|
+
"scripts": {
|
|
21
|
+
"type-check": "tsc --noEmit"
|
|
22
|
+
},
|
|
20
23
|
"dependencies": {
|
|
21
24
|
"@babel/parser": "^7.28.4",
|
|
22
25
|
"coffi": "^0.1.37",
|