@bunup/dts 0.14.46 → 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 +31 -20
- 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",
|
|
@@ -691,7 +696,7 @@ async function runTypescriptCompiler(root, tsgo, tsconfig) {
|
|
|
691
696
|
// src/generate.ts
|
|
692
697
|
async function generateDts(entrypoints, options = {}) {
|
|
693
698
|
const { resolve, preferredTsconfig, naming } = options;
|
|
694
|
-
const cwd = options.cwd ?
|
|
699
|
+
const cwd = options.cwd ? path3.resolve(options.cwd) : process.cwd();
|
|
695
700
|
const tsconfig = await loadTsConfig(cwd, preferredTsconfig);
|
|
696
701
|
if (options.inferTypes && !tsconfig.filepath) {
|
|
697
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:
|
|
@@ -707,14 +712,14 @@ async function generateDts(entrypoints, options = {}) {
|
|
|
707
712
|
|
|
708
713
|
` + 'Alternatively, you can specify a custom path using the "preferredTsconfig" option.');
|
|
709
714
|
}
|
|
710
|
-
const nonAbsoluteEntrypoints = entrypoints.filter((entrypoint) => !
|
|
715
|
+
const nonAbsoluteEntrypoints = entrypoints.filter((entrypoint) => !path3.isAbsolute(entrypoint));
|
|
711
716
|
const resolvedEntrypoints = await getFilesFromGlobs(nonAbsoluteEntrypoints, cwd);
|
|
712
|
-
const absoluteEntrypoints = entrypoints.filter((entrypoint) =>
|
|
717
|
+
const absoluteEntrypoints = entrypoints.filter((entrypoint) => path3.isAbsolute(entrypoint));
|
|
713
718
|
if (!filterTypescriptFiles([...resolvedEntrypoints, ...absoluteEntrypoints]).length) {
|
|
714
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.");
|
|
715
720
|
}
|
|
716
721
|
const finalEntryPoints = [
|
|
717
|
-
...filterTypescriptFiles(resolvedEntrypoints).map((entry) =>
|
|
722
|
+
...filterTypescriptFiles(resolvedEntrypoints).map((entry) => path3.resolve(path3.join(cwd, entry))),
|
|
718
723
|
...filterTypescriptFiles(absoluteEntrypoints)
|
|
719
724
|
];
|
|
720
725
|
const collectedErrors = [];
|
|
@@ -760,8 +765,8 @@ async function generateDts(entrypoints, options = {}) {
|
|
|
760
765
|
declaration = sourceText;
|
|
761
766
|
} else {
|
|
762
767
|
if (options.inferTypes && tsCompiledDist) {
|
|
763
|
-
const relativePath =
|
|
764
|
-
const declarationPath = replaceExtension(
|
|
768
|
+
const relativePath = path3.relative(cwd, args.path);
|
|
769
|
+
const declarationPath = replaceExtension(path3.join(tsCompiledDist, relativePath), ".d.ts");
|
|
765
770
|
declaration = await Bun.file(declarationPath).text();
|
|
766
771
|
} else {
|
|
767
772
|
const isolatedDeclarationResult = isolatedDeclaration(args.path, sourceText);
|
|
@@ -804,7 +809,8 @@ async function generateDts(entrypoints, options = {}) {
|
|
|
804
809
|
minify: options.minify,
|
|
805
810
|
root: options.root,
|
|
806
811
|
throw: false,
|
|
807
|
-
tsconfig: options.preferredTsconfig ?
|
|
812
|
+
tsconfig: options.preferredTsconfig ? path3.resolve(cwd, options.preferredTsconfig) : undefined,
|
|
813
|
+
metafile: true
|
|
808
814
|
});
|
|
809
815
|
if (!result.success) {
|
|
810
816
|
const logsStr = `${result.logs}`;
|
|
@@ -813,7 +819,7 @@ async function generateDts(entrypoints, options = {}) {
|
|
|
813
819
|
|
|
814
820
|
`;
|
|
815
821
|
if (tsconfig.filepath) {
|
|
816
|
-
errorMsg += `Using: ${
|
|
822
|
+
errorMsg += `Using: ${path3.relative(cwd, tsconfig.filepath)}
|
|
817
823
|
|
|
818
824
|
`;
|
|
819
825
|
}
|
|
@@ -846,13 +852,18 @@ Ensure all your entrypoints match these patterns, or add them explicitly.
|
|
|
846
852
|
for (const output of outputs) {
|
|
847
853
|
const bundledFakeJsContent = await output.text();
|
|
848
854
|
const dtsContent = await fakeJsToDts(bundledFakeJsContent);
|
|
849
|
-
const entrypoint = output.kind === "entry-point" ?
|
|
850
|
-
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;
|
|
851
857
|
const outputPath = cleanPath(replaceExtension(cleanPath(output.path), getDeclarationExtensionFromJsExtension(getExtension(output.path))));
|
|
852
858
|
const treeshakedDts = isolatedDeclaration(`${generateRandomString()}.d.ts`, dtsContent);
|
|
853
859
|
if (!treeshakedDts.code.length && !treeshakedDts.errors.length) {
|
|
854
860
|
continue;
|
|
855
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
|
+
}
|
|
856
867
|
bundledFiles.push({
|
|
857
868
|
kind: output.kind === "entry-point" ? "entry-point" : "chunk",
|
|
858
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
|
},
|