Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion scripts/build/utils/dts-process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ async function run() {
const { typesExternal: external } = await getExternal(process.cwd());

const dir = dirname(entryPoint).replace('src', 'dist');
const outputFile = entryPoint.replace('src', 'dist').replace('.ts', '.d.ts');
const outputFile = entryPoint.replace('src', 'dist').replace(/\.tsx?/, '.d.ts');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

🧩 Analysis chain

Good fix; tighten extension match and make src→dist replacement segment-aware.

Anchoring the regex avoids accidental mid‑path matches (e.g., a folder named "foo.tsx"). Replacing only the src path segment avoids clobbering strings like "sources".

Apply this diff:

-  const outputFile = entryPoint.replace('src', 'dist').replace(/\.tsx?/, '.d.ts');
+  const outputFile = entryPoint
+    .replace(`${sep}src${sep}`, `${sep}dist${sep}`)
+    .replace(/\.tsx?$/, '.d.ts');

Run after a full build to ensure no stray .d.tsx files remain:


🏁 Script executed:

#!/bin/bash
# From repo root, after building all packages
fd -uu -t f -g "**/*.d.tsx" packages dist || true

Length of output: 146


🏁 Script executed:

#!/bin/bash
# Show first 50 lines of the DTS processing utility to verify sep usage and context
if [ -f scripts/build/utils/dts-process.ts ]; then
  echo "=== scripts/build/utils/dts-process.ts (lines 1–50) ==="
  sed -n '1,50p' scripts/build/utils/dts-process.ts
else
  echo "ERROR: scripts/build/utils/dts-process.ts not found"
fi

# List top-level directories to determine where build outputs reside
echo "=== Root-level directories (depth=2) ==="
find . -maxdepth 2 -type d

# Search for any .d.tsx files (ignoring .gitignore) across the repo
echo "=== .d.tsx files in repo ==="
fd -uu -t f -g "*.d.tsx" .

Length of output: 2867


Make src→dist replacement segment-aware and anchor the extension match.

scripts/build/utils/dts-process.ts — replace the two assignments that set dir and outputFile so you only replace a path segment named "src" (including when it's the first segment) and anchor the extension replacement with /.tsx?$/. Compute outputFile from the adjusted path and derive dir via dirname(outputFile).

🤖 Prompt for AI Agents
In scripts/build/utils/dts-process.ts around line 21, the current replacements
naively replace any "src" substring and use an unanchored extension match;
update the implementation so you first replace only a path segment named "src"
(including when it's the first segment) — e.g. split path on path.sep, replace a
segment equal to "src" with "dist", join back — then compute outputFile by
replacing the file extension using the anchored regex /\.tsx?$/ (so it only
matches the end), and finally derive dir via path.dirname(outputFile); replace
the two existing assignments with this corrected flow.

const out = await rollup({
input: entryPoint,
external: (id) => {
Expand Down
Loading