Skip to content

Commit abc1c6b

Browse files
fix: d.ts refferences escaping to ts files
1 parent 4fc23e9 commit abc1c6b

2 files changed

Lines changed: 29 additions & 10 deletions

File tree

build-dist.ts

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,29 @@ import { resolve } from "@std/path";
1717

1818
const configPath = resolve(Deno.cwd(), "./deno.json");
1919

20-
async function stripExtensionsInDts(path: string): Promise<void> {
21-
if (!path.endsWith(".d.ts")) return;
22-
const src = await Deno.readTextFile(path);
23-
// Replace .tsx and .ts extensions in relative import/export paths so that
24-
// TypeScript resolves to companion .d.ts files rather than source files.
25-
const out = src.replace(/(from\s+["'])(\.\.?\/[^"']*)\.(tsx?)(?=["'])/g, "$1$2");
26-
if (out !== src) await Deno.writeTextFile(path, out);
20+
async function stripExtensionsInDts(filePath: string): Promise<void> {
21+
if (!filePath.endsWith(".d.ts")) return;
22+
let src = await Deno.readTextFile(filePath);
23+
24+
// Rewrite paths that escape dist back into src/ (e.g. ../../src/state-builder/index.ts)
25+
// to their companion .d.ts locations inside dist/ (e.g. ../state-builder/index).
26+
// This happens because tsc resolves @molstar/state-builder path aliases to the
27+
// absolute source path and encodes them as relative paths in the emitted .d.ts.
28+
src = src.replace(
29+
/(from\s+["'])((?:\.\.\/)+)src\/state-builder\/([^"']+)(?=["'])/g,
30+
(_match, from, upSegments, subPath) => {
31+
const depth = (upSegments.match(/\.\.\//g) ?? []).length;
32+
const newUp = "../".repeat(depth - 1);
33+
const cleanPath = subPath.replace(/\.tsx?$/, "");
34+
return `${from}${newUp}state-builder/${cleanPath}`;
35+
},
36+
);
37+
38+
// Strip any remaining .ts/.tsx extensions from relative import/export paths so
39+
// that TypeScript resolves to companion .d.ts files rather than source files.
40+
src = src.replace(/(from\s+["'])(\.\.?\/[^"']*)\.(tsx?)(?=["'])/g, "$1$2");
41+
42+
await Deno.writeTextFile(filePath, src);
2743
}
2844

2945
async function walkAndStrip(dir: string): Promise<void> {

deno.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@molstar/molstar-components",
3-
"version": "0.6.0-experimental.13",
3+
"version": "0.6.0-experimental.14",
44
"license": "MIT",
55
"exports": "./dist/index.js",
66
"imports": {
@@ -66,9 +66,12 @@
6666
"serve": "deno run --allow-net --allow-read jsr:@std/http/file-server --host 127.0.0.1 -p 8000 docs",
6767
"dev": "deno task build && deno task build:dist && deno task serve"
6868
},
69-
"exclude": ["docs/", ".github/", "context/", ".claude/", "CLAUDE.md", "docs/superpowers/", "src/state-builder/compiler/__tests__", "src/state-builder/types/__tests__", "!dist/"],
69+
"exclude": ["docs/", ".github/", "context/", ".claude/", "CLAUDE.md", "docs/superpowers/", "src/state-builder/compiler/__tests__", "src/state-builder/types/__tests__"],
70+
"publish": {
71+
"include": ["src/", "dist/", "deno.json", "tsconfig.json", "tsconfig.declarations.json", "build-dist.ts", "LICENSE", "README.md"]
72+
},
7073
"lint": {
71-
"exclude": ["src/state-builder/", "src/state-builder-ui/", "scripts/"]
74+
"exclude": ["dist/", "src/state-builder/", "src/state-builder-ui/", "scripts/"]
7275
},
7376
"nodeModulesDir": "auto",
7477
"compilerOptions": {

0 commit comments

Comments
 (0)