Skip to content

fix(dts-plugin): prevent sibling package path prefix false positive in getDependentFiles#4804

Open
hpello wants to merge 1 commit into
module-federation:mainfrom
hpello:fix/dts-plugin-get-dependent-files-path-prefix
Open

fix(dts-plugin): prevent sibling package path prefix false positive in getDependentFiles#4804
hpello wants to merge 1 commit into
module-federation:mainfrom
hpello:fix/dts-plugin-get-dependent-files-path-prefix

Conversation

@hpello

@hpello hpello commented Jun 9, 2026

Copy link
Copy Markdown

Description

getDependentFiles filters the TypeScript program's source files to only keep those that live under the project's rootDir:

.filter((file) => !file.endsWith('.d.ts') && file.startsWith(rootDir));

rootDir is an absolute path with no trailing separator, e.g. /path/to/packages/business-package. The startsWith check is a plain string prefix match, which means any sibling package whose name shares the same prefix will incorrectly pass the filter.

Concrete example from our monorepo

packages/business-package/        ← rootDir
packages/business-package-api/    ← sibling, different package

'/…/packages/business-package-api/src/index.ts'.startsWith('/…/packages/business-package')true

All source files from business-package-api end up in filesToCompile. The generated temp tsconfig then lists them under files but with rootDir set to packages/business-package/. TypeScript considers those files outside rootDir and emits their .d.ts declarations next to their source files instead of into outDir — polluting the sibling package's src/ directory with untracked build artefacts.

Fix

Append '/' to rootDir before the startsWith check so the comparison is a true path-prefix match rather than a string-prefix match.

Note: path.sep is not used here because TypeScript normalises all file paths to forward slashes internally regardless of OS, so hardcoding '/' is both correct and portable.

Related Issue

No existing issue — discovered while migrating a Module Federation producer from Vite to Rsbuild and enabling DTS generation in build mode.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

Checklist

  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • I have updated the documentation.

@changeset-bot

changeset-bot Bot commented Jun 9, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 8af267d

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@netlify

netlify Bot commented Jun 9, 2026

Copy link
Copy Markdown

Deploy Preview for module-federation-docs ready!

Name Link
🔨 Latest commit 8af267d
🔍 Latest deploy log https://app.netlify.com/projects/module-federation-docs/deploys/6a27e84c389b4c0008cc3d3b
😎 Deploy Preview https://deploy-preview-4804--module-federation-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@hpello hpello marked this pull request as ready for review June 9, 2026 11:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant