Skip to content

Conversation

@mrginglymus
Copy link
Contributor

@mrginglymus mrginglymus commented Sep 15, 2025

Closes #32460

What I did

Ensure .tsx files generate .d.ts files instead of .d.tsx files.

Checklist for Contributors

Testing

The changes in this PR are covered in the following automated tests:

  • stories
  • unit tests
  • integration tests
  • end-to-end tests

Manual testing

This section is mandatory for all contributions. If you believe no manual test is necessary, please state so explicitly. Thanks!

Documentation

  • Add or update documentation reflecting your changes
  • If you are deprecating/removing a feature, make sure to update
    MIGRATION.MD

Checklist for Maintainers

  • When this PR is ready for testing, make sure to add ci:normal, ci:merged or ci:daily GH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found in code/lib/cli-storybook/src/sandbox-templates.ts

  • Make sure this PR contains one of the labels below:

    Available labels
    • bug: Internal changes that fixes incorrect behavior.
    • maintenance: User-facing maintenance tasks.
    • dependencies: Upgrading (sometimes downgrading) dependencies.
    • build: Internal-facing build tooling & test updates. Will not show up in release changelog.
    • cleanup: Minor cleanup style change. Will not show up in release changelog.
    • documentation: Documentation only changes. Will not show up in release changelog.
    • feature request: Introducing a new feature.
    • BREAKING CHANGE: Changes that break compatibility in some way with current major version.
    • other: Changes that don't fit in the above categories.

🦋 Canary release

This PR does not have a canary release associated. You can request a canary release of this pull request by mentioning the @storybookjs/core team here.

core team members can create a canary release here or locally with gh workflow run --repo storybookjs/storybook canary-release-pr.yml --field pr=<PR_NUMBER>

Summary by CodeRabbit

  • New Features

    • None.
  • Bug Fixes

    • Corrects generation of TypeScript declaration files for both .ts and .tsx sources, ensuring accurate .d.ts outputs in builds.
    • Resolves cases where declaration files could be misnamed or missing, improving IDE IntelliSense and package consumers’ experience.
  • Documentation

    • No changes.
  • Refactor

    • None.
  • Tests

    • None.
  • Chores

    • None.
  • Revert

    • None.

@nx-cloud
Copy link

nx-cloud bot commented Sep 15, 2025

View your CI Pipeline Execution ↗ for commit 1ba5f24

Command Status Duration Result
nx run-many -t build --parallel=3 ✅ Succeeded 56s View ↗

☁️ Nx Cloud last updated this comment at 2025-09-22 14:37:36 UTC

@storybook-app-bot
Copy link

storybook-app-bot bot commented Sep 22, 2025

Package Benchmarks

Commit: 1ba5f24, ran on 22 September 2025 at 14:24:50 UTC

No significant changes detected, all good. 👏

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 22, 2025

Walkthrough

Refines declaration file path generation in the build script to replace both .ts and .tsx extensions with .d.ts, ensuring .tsx inputs do not produce .d.tsx outputs.

Changes

Cohort / File(s) Summary
Build DTS mapping update
scripts/build/utils/dts-process.ts
Updates extension replacement from ".ts" to a regex /\.tsx?/ to map .ts and .tsx to .d.ts, preventing .d.tsx outputs. No exported/public API changes.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

I nibble on paths in the TypeScript glade,
Turning .ts and .tsx to tidy .d.ts shade.
No stray .d.tsx crumbs on the trail,
The build hops cleanly, without a fail.
Thump-thump—release is ready, carrots prevail! 🥕🐇

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The PR title "Dts: Ensure .tsx files emit .d.ts type files" is concise, specific, and directly reflects the primary code change to scripts/build/utils/dts-process.ts that ensures .tsx sources map to .d.ts outputs rather than producing .d.tsx artifacts.
Linked Issues Check ✅ Passed The modification updates the output-path replacement to use /.tsx?/ → ".d.ts", which directly addresses linked issue #32460 by preventing .tsx sources from producing extra .d.tsx files and thus satisfies the linked issue's coding objective.
Out of Scope Changes Check ✅ Passed The provided raw_summary shows a single, focused change to scripts/build/utils/dts-process.ts limited to extension-replacement logic; there are no other modified files or unrelated changes apparent, so no out-of-scope changes are detected.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Comment @coderabbitai help to get the list of available commands and usage tips.

@ndelangen ndelangen changed the title Ensure .tsx files emit .d.ts type files Dts: Ensure .tsx files emit .d.ts type files Sep 22, 2025
@ndelangen ndelangen added typescript build Internal-facing build tooling & test updates labels Sep 22, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
scripts/build/utils/dts-process.ts (2)

20-20: Make dir computation segment-aware too.

Current replace() can misfire on paths containing “src” as a substring (e.g., “sources”). Derive dir from a segment-safe entry path.

Apply this diff:

-  const dir = dirname(entryPoint).replace('src', 'dist');
+  const dir = dirname(entryPoint.replace(`${sep}src${sep}`, `${sep}dist${sep}`));

21-21: Optional: future-proof for .mts/.cts entry points.

If you ever pass .mts/.cts as entry points, map to .d.mts/.d.cts instead of .d.ts.

Outside this hunk, a simple helper could be:

function mapDeclExt(p: string) {
  return p.replace(/\.(cts|mts|tsx?|ts)$/i, (m) =>
    m === '.cts' ? '.d.cts' : m === '.mts' ? '.d.mts' : '.d.ts'
  );
}

Then:

const distEntry = entryPoint.replace(`${sep}src${sep}`, `${sep}dist${sep}`);
const outputFile = mapDeclExt(distEntry);
const dir = dirname(distEntry);
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8fdeb1a and 1ba5f24.

📒 Files selected for processing (1)
  • scripts/build/utils/dts-process.ts (1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: CR
PR: storybookjs/storybook#0
File: .cursorrules:0-0
Timestamp: 2025-09-17T08:11:04.275Z
Learning: Applies to code/**/*.{test,spec}.{ts,tsx} : Name test files as *.test.ts, *.test.tsx, *.spec.ts, or *.spec.tsx
📚 Learning: 2025-09-17T08:11:04.275Z
Learnt from: CR
PR: storybookjs/storybook#0
File: .cursorrules:0-0
Timestamp: 2025-09-17T08:11:04.275Z
Learning: Applies to code/**/*.{test,spec}.{ts,tsx} : Name test files as *.test.ts, *.test.tsx, *.spec.ts, or *.spec.tsx

Applied to files:

  • scripts/build/utils/dts-process.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: normal
  • GitHub Check: Core Unit Tests, windows-latest


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.

@ndelangen ndelangen merged commit 488d8bc into storybookjs:next Sep 22, 2025
30 of 40 checks passed
@github-actions github-actions bot mentioned this pull request Sep 22, 2025
18 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug build Internal-facing build tooling & test updates ci:normal typescript

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Bonus preview.d.tsx files

3 participants