@bunup/dts 0.14.45 → 0.14.47
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.js +36 -23
- package/package.json +9 -9
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// src/generate.ts
|
|
2
2
|
import { rm } from "node:fs/promises";
|
|
3
|
-
import
|
|
3
|
+
import path3 from "node:path";
|
|
4
4
|
import { isolatedDeclaration } from "oxc-transform";
|
|
5
5
|
import { resolveTsImportPath } from "ts-import-resolver";
|
|
6
6
|
|
|
@@ -155,13 +155,14 @@ import { normalize } from "node:path";
|
|
|
155
155
|
import { loadConfig } from "coffi";
|
|
156
156
|
import { minify } from "oxc-minify";
|
|
157
157
|
import { isCI, isDevelopment } from "std-env";
|
|
158
|
-
|
|
159
|
-
|
|
158
|
+
import path from "node:path";
|
|
159
|
+
function isTypeScriptFile(path2) {
|
|
160
|
+
if (!path2)
|
|
160
161
|
return false;
|
|
161
|
-
return TS_RE.test(
|
|
162
|
+
return TS_RE.test(path2);
|
|
162
163
|
}
|
|
163
|
-
function returnPathIfExists(
|
|
164
|
-
return existsSync(
|
|
164
|
+
function returnPathIfExists(path2) {
|
|
165
|
+
return existsSync(path2) ? path2 : null;
|
|
165
166
|
}
|
|
166
167
|
function getExtension(filename) {
|
|
167
168
|
const match = filename.match(EXTENSION_REGEX);
|
|
@@ -208,8 +209,8 @@ function isDev() {
|
|
|
208
209
|
function isNullOrUndefined(value) {
|
|
209
210
|
return value === undefined || value === null;
|
|
210
211
|
}
|
|
211
|
-
function cleanPath(
|
|
212
|
-
let cleaned = normalize(
|
|
212
|
+
function cleanPath(path2) {
|
|
213
|
+
let cleaned = normalize(path2).replace(/\\/g, "/");
|
|
213
214
|
cleaned = cleaned.replace(/^[a-zA-Z]:\//, "");
|
|
214
215
|
cleaned = cleaned.replace(/^\/+/, "");
|
|
215
216
|
cleaned = cleaned.replace(/\/+/g, "/");
|
|
@@ -255,6 +256,10 @@ function minifyDts(dts) {
|
|
|
255
256
|
sourcemap: false
|
|
256
257
|
}).code;
|
|
257
258
|
}
|
|
259
|
+
function getOriginalEntrypointFromOutputPath(metafile, outputPath, rootDir) {
|
|
260
|
+
const entryPoint = metafile?.outputs[outputPath]?.entryPoint;
|
|
261
|
+
return path.relative(rootDir, entryPoint);
|
|
262
|
+
}
|
|
258
263
|
|
|
259
264
|
// src/fake/utils.ts
|
|
260
265
|
var MARKERS = {
|
|
@@ -654,7 +659,7 @@ function createResolver({
|
|
|
654
659
|
// src/typescript-compiler.ts
|
|
655
660
|
import { mkdtemp } from "node:fs/promises";
|
|
656
661
|
import { tmpdir } from "node:os";
|
|
657
|
-
import
|
|
662
|
+
import path2 from "node:path";
|
|
658
663
|
async function runTypescriptCompiler(root, tsgo, tsconfig) {
|
|
659
664
|
let executable = "tsc";
|
|
660
665
|
if (tsgo) {
|
|
@@ -662,7 +667,7 @@ async function runTypescriptCompiler(root, tsgo, tsconfig) {
|
|
|
662
667
|
const { default: getExePath } = await import(new URL("lib/getExePath.js", tsgoPackage).href);
|
|
663
668
|
executable = getExePath();
|
|
664
669
|
}
|
|
665
|
-
const dist = await mkdtemp(
|
|
670
|
+
const dist = await mkdtemp(path2.join(tmpdir(), "bunup-dts-"));
|
|
666
671
|
const proc = Bun.spawn([
|
|
667
672
|
executable,
|
|
668
673
|
"--noEmit",
|
|
@@ -671,13 +676,15 @@ async function runTypescriptCompiler(root, tsgo, tsconfig) {
|
|
|
671
676
|
"--emitDeclarationOnly",
|
|
672
677
|
"--isolatedDeclarations",
|
|
673
678
|
"false",
|
|
679
|
+
"--rootDir",
|
|
680
|
+
root,
|
|
674
681
|
...tsconfig ? ["-p", tsconfig] : [],
|
|
675
682
|
"--outDir",
|
|
676
683
|
dist,
|
|
677
|
-
"--rootDir",
|
|
678
|
-
root,
|
|
679
684
|
"--noCheck"
|
|
680
|
-
]
|
|
685
|
+
], {
|
|
686
|
+
cwd: root
|
|
687
|
+
});
|
|
681
688
|
const exitCode = await proc.exited;
|
|
682
689
|
if (exitCode !== 0) {
|
|
683
690
|
const stderr = await new Response(proc.stdout).text();
|
|
@@ -689,7 +696,7 @@ async function runTypescriptCompiler(root, tsgo, tsconfig) {
|
|
|
689
696
|
// src/generate.ts
|
|
690
697
|
async function generateDts(entrypoints, options = {}) {
|
|
691
698
|
const { resolve, preferredTsconfig, naming } = options;
|
|
692
|
-
const cwd = options.cwd ?
|
|
699
|
+
const cwd = options.cwd ? path3.resolve(options.cwd) : process.cwd();
|
|
693
700
|
const tsconfig = await loadTsConfig(cwd, preferredTsconfig);
|
|
694
701
|
if (options.inferTypes && !tsconfig.filepath) {
|
|
695
702
|
throw new Error(`The "inferTypes" option requires a tsconfig.json file. Please create a tsconfig.json file in your project root with at least a basic configuration:
|
|
@@ -705,14 +712,14 @@ async function generateDts(entrypoints, options = {}) {
|
|
|
705
712
|
|
|
706
713
|
` + 'Alternatively, you can specify a custom path using the "preferredTsconfig" option.');
|
|
707
714
|
}
|
|
708
|
-
const nonAbsoluteEntrypoints = entrypoints.filter((entrypoint) => !
|
|
715
|
+
const nonAbsoluteEntrypoints = entrypoints.filter((entrypoint) => !path3.isAbsolute(entrypoint));
|
|
709
716
|
const resolvedEntrypoints = await getFilesFromGlobs(nonAbsoluteEntrypoints, cwd);
|
|
710
|
-
const absoluteEntrypoints = entrypoints.filter((entrypoint) =>
|
|
717
|
+
const absoluteEntrypoints = entrypoints.filter((entrypoint) => path3.isAbsolute(entrypoint));
|
|
711
718
|
if (!filterTypescriptFiles([...resolvedEntrypoints, ...absoluteEntrypoints]).length) {
|
|
712
719
|
throw new Error("One or more of the entrypoints you provided do not exist. Please check that each entrypoint points to a valid file.");
|
|
713
720
|
}
|
|
714
721
|
const finalEntryPoints = [
|
|
715
|
-
...filterTypescriptFiles(resolvedEntrypoints).map((entry) =>
|
|
722
|
+
...filterTypescriptFiles(resolvedEntrypoints).map((entry) => path3.resolve(path3.join(cwd, entry))),
|
|
716
723
|
...filterTypescriptFiles(absoluteEntrypoints)
|
|
717
724
|
];
|
|
718
725
|
const collectedErrors = [];
|
|
@@ -758,8 +765,8 @@ async function generateDts(entrypoints, options = {}) {
|
|
|
758
765
|
declaration = sourceText;
|
|
759
766
|
} else {
|
|
760
767
|
if (options.inferTypes && tsCompiledDist) {
|
|
761
|
-
const relativePath =
|
|
762
|
-
const declarationPath = replaceExtension(
|
|
768
|
+
const relativePath = path3.relative(cwd, args.path);
|
|
769
|
+
const declarationPath = replaceExtension(path3.join(tsCompiledDist, relativePath), ".d.ts");
|
|
763
770
|
declaration = await Bun.file(declarationPath).text();
|
|
764
771
|
} else {
|
|
765
772
|
const isolatedDeclarationResult = isolatedDeclaration(args.path, sourceText);
|
|
@@ -802,7 +809,8 @@ async function generateDts(entrypoints, options = {}) {
|
|
|
802
809
|
minify: options.minify,
|
|
803
810
|
root: options.root,
|
|
804
811
|
throw: false,
|
|
805
|
-
tsconfig: options.preferredTsconfig ?
|
|
812
|
+
tsconfig: options.preferredTsconfig ? path3.resolve(cwd, options.preferredTsconfig) : undefined,
|
|
813
|
+
metafile: true
|
|
806
814
|
});
|
|
807
815
|
if (!result.success) {
|
|
808
816
|
const logsStr = `${result.logs}`;
|
|
@@ -811,7 +819,7 @@ async function generateDts(entrypoints, options = {}) {
|
|
|
811
819
|
|
|
812
820
|
`;
|
|
813
821
|
if (tsconfig.filepath) {
|
|
814
|
-
errorMsg += `Using: ${
|
|
822
|
+
errorMsg += `Using: ${path3.relative(cwd, tsconfig.filepath)}
|
|
815
823
|
|
|
816
824
|
`;
|
|
817
825
|
}
|
|
@@ -844,13 +852,18 @@ Ensure all your entrypoints match these patterns, or add them explicitly.
|
|
|
844
852
|
for (const output of outputs) {
|
|
845
853
|
const bundledFakeJsContent = await output.text();
|
|
846
854
|
const dtsContent = await fakeJsToDts(bundledFakeJsContent);
|
|
847
|
-
const entrypoint = output.kind === "entry-point" ?
|
|
848
|
-
const chunkFileName = output.kind === "chunk" ? replaceExtension(
|
|
855
|
+
const entrypoint = output.kind === "entry-point" ? getOriginalEntrypointFromOutputPath(result.metafile, output.path, cwd) : undefined;
|
|
856
|
+
const chunkFileName = output.kind === "chunk" ? replaceExtension(path3.basename(output.path), getDeclarationExtensionFromJsExtension(getExtension(output.path))) : undefined;
|
|
849
857
|
const outputPath = cleanPath(replaceExtension(cleanPath(output.path), getDeclarationExtensionFromJsExtension(getExtension(output.path))));
|
|
850
858
|
const treeshakedDts = isolatedDeclaration(`${generateRandomString()}.d.ts`, dtsContent);
|
|
851
859
|
if (!treeshakedDts.code.length && !treeshakedDts.errors.length) {
|
|
852
860
|
continue;
|
|
853
861
|
}
|
|
862
|
+
if (treeshakedDts.errors.length && !treeshakedDts.code) {
|
|
863
|
+
throw new Error(`DTS treeshaking failed for ${entrypoint || outputPath}
|
|
864
|
+
|
|
865
|
+
${JSON.stringify(treeshakedDts.errors, null, 2)}`);
|
|
866
|
+
}
|
|
854
867
|
bundledFiles.push({
|
|
855
868
|
kind: output.kind === "entry-point" ? "entry-point" : "chunk",
|
|
856
869
|
entrypoint,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bunup/dts",
|
|
3
|
-
"version": "0.14.
|
|
3
|
+
"version": "0.14.47",
|
|
4
4
|
"description": "An extremely fast TypeScript declaration bundler built on Bun's native bundler.",
|
|
5
5
|
"homepage": "https://github.com/bunup/dts#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -15,13 +15,13 @@
|
|
|
15
15
|
"url": "git+https://github.com/bunup/dts.git"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@babel/parser": "^7.28.
|
|
18
|
+
"@babel/parser": "^7.28.6",
|
|
19
19
|
"coffi": "^0.1.37",
|
|
20
20
|
"oxc-minify": "^0.93.0",
|
|
21
|
-
"oxc-resolver": "^11.
|
|
21
|
+
"oxc-resolver": "^11.16.2",
|
|
22
22
|
"oxc-transform": "^0.93.0",
|
|
23
23
|
"picocolors": "^1.1.1",
|
|
24
|
-
"std-env": "^3.
|
|
24
|
+
"std-env": "^3.10.0",
|
|
25
25
|
"ts-import-resolver": "^0.1.23"
|
|
26
26
|
},
|
|
27
27
|
"scripts": {
|
|
@@ -37,11 +37,11 @@
|
|
|
37
37
|
"type-check": "tsc --noEmit"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@biomejs/biome": "^2.
|
|
41
|
-
"@types/bun": "^1.3.
|
|
42
|
-
"@typescript/native-preview": "^7.0.0-dev.
|
|
43
|
-
"bumpp": "^10.
|
|
44
|
-
"bunup": "^0.
|
|
40
|
+
"@biomejs/biome": "^2.3.11",
|
|
41
|
+
"@types/bun": "^1.3.6",
|
|
42
|
+
"@typescript/native-preview": "^7.0.0-dev.20260114.1",
|
|
43
|
+
"bumpp": "^10.4.0",
|
|
44
|
+
"bunup": "^0.16.17",
|
|
45
45
|
"simple-git-hooks": "^2.13.1",
|
|
46
46
|
"typescript": "^5.9.3"
|
|
47
47
|
},
|