-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
Dts: Ensure .tsx files emit .d.ts type files
#32461
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
View your CI Pipeline Execution ↗ for commit 1ba5f24
☁️ Nx Cloud last updated this comment at |
Package BenchmarksCommit: No significant changes detected, all good. 👏 |
WalkthroughRefines 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
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing touches
🧪 Generate unit tests
Comment |
.tsx files emit .d.ts type files
There was a problem hiding this 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
📒 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'); |
There was a problem hiding this comment.
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 || trueLength 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.
Closes #32460
What I did
Ensure
.tsxfiles generate.d.tsfiles instead of.d.tsxfiles.Checklist for Contributors
Testing
The changes in this PR are covered in the following automated tests:
Manual testing
This section is mandatory for all contributions. If you believe no manual test is necessary, please state so explicitly. Thanks!
Documentation
MIGRATION.MD
Checklist for Maintainers
When this PR is ready for testing, make sure to add
ci:normal,ci:mergedorci:dailyGH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found incode/lib/cli-storybook/src/sandbox-templates.tsMake 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/coreteam 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
Bug Fixes
Documentation
Refactor
Tests
Chores
Revert