bun-plugin-dtsx 0.9.26 → 0.10.2
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 +32 -12
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -4,9 +4,9 @@ var __require = import.meta.require;
|
|
|
4
4
|
// src/index.ts
|
|
5
5
|
import { createHash } from "crypto";
|
|
6
6
|
import { existsSync, readFileSync, writeFileSync } from "fs";
|
|
7
|
-
import {
|
|
7
|
+
import { dirname, join, relative, resolve, sep } from "path";
|
|
8
8
|
import process from "process";
|
|
9
|
-
import { generate } from "@stacksjs/dtsx";
|
|
9
|
+
import { generate } from "@stacksjs/dtsx/generator";
|
|
10
10
|
var PluginErrorCodes = {
|
|
11
11
|
CONFIG_ERROR: "CONFIG_ERROR",
|
|
12
12
|
GENERATION_ERROR: "GENERATION_ERROR",
|
|
@@ -235,28 +235,48 @@ function wrapError(error) {
|
|
|
235
235
|
}
|
|
236
236
|
return new DtsxPluginError(String(error), "GENERATION_ERROR");
|
|
237
237
|
}
|
|
238
|
+
function commonParentDir(paths) {
|
|
239
|
+
const dirs = paths.map((p) => dirname(p).split(sep));
|
|
240
|
+
let common = dirs[0];
|
|
241
|
+
for (const parts of dirs.slice(1)) {
|
|
242
|
+
let i = 0;
|
|
243
|
+
while (i < common.length && i < parts.length && common[i] === parts[i])
|
|
244
|
+
i++;
|
|
245
|
+
common = common.slice(0, i);
|
|
246
|
+
}
|
|
247
|
+
return common.join(sep) || sep;
|
|
248
|
+
}
|
|
238
249
|
function normalizeConfig(options, build) {
|
|
239
|
-
const
|
|
250
|
+
const cwd = options.cwd || process.cwd();
|
|
251
|
+
const bunEntrypoints = build?.config?.entrypoints;
|
|
240
252
|
const outdir = options.outdir || options.build?.config.outdir || build?.config.outdir || "./dist";
|
|
241
|
-
|
|
242
|
-
|
|
253
|
+
let root = options.root || options.build?.config.root || build?.config.root;
|
|
254
|
+
if (!root && bunEntrypoints?.length) {
|
|
255
|
+
const ancestor = commonParentDir(bunEntrypoints.map((ep) => resolve(cwd, ep)));
|
|
256
|
+
root = relative(cwd, ancestor) || ".";
|
|
243
257
|
}
|
|
258
|
+
root = root || "./src";
|
|
244
259
|
let entrypoints = options.entrypoints;
|
|
245
260
|
if (!entrypoints) {
|
|
246
|
-
const bunEntrypoints = build?.config?.entrypoints;
|
|
247
261
|
if (bunEntrypoints?.length) {
|
|
248
|
-
const resolvedRoot = resolve(
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
262
|
+
const resolvedRoot = resolve(cwd, root);
|
|
263
|
+
const inside = [];
|
|
264
|
+
for (const ep of bunEntrypoints) {
|
|
265
|
+
const resolved = resolve(cwd, ep);
|
|
266
|
+
if (resolved === resolvedRoot || resolved.startsWith(resolvedRoot + sep)) {
|
|
267
|
+
inside.push(relative(resolvedRoot, resolved));
|
|
268
|
+
} else {
|
|
269
|
+
console.warn(`[bun-plugin-dtsx] Skipping entrypoint outside root "${root}": ${ep}`);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
entrypoints = inside.length ? inside : ["index.ts"];
|
|
253
273
|
} else {
|
|
254
274
|
entrypoints = ["index.ts"];
|
|
255
275
|
}
|
|
256
276
|
}
|
|
257
277
|
return {
|
|
258
278
|
...options,
|
|
259
|
-
cwd
|
|
279
|
+
cwd,
|
|
260
280
|
root,
|
|
261
281
|
entrypoints,
|
|
262
282
|
outdir,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bun-plugin-dtsx",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.10.2",
|
|
5
5
|
"description": "A Bun Bundler plugin that auto generates your DTS types extremely fast.",
|
|
6
6
|
"author": "Chris Breuer <chris@ow3.org>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -51,6 +51,6 @@
|
|
|
51
51
|
"lint:fix": "bun x --bun pickier . --fix"
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
|
-
"@stacksjs/dtsx": "0.
|
|
54
|
+
"@stacksjs/dtsx": "0.10.2"
|
|
55
55
|
}
|
|
56
56
|
}
|