Skip to content
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

fix: watch mode not working with external outDir #1266

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

MarkShawn2020
Copy link

Description

When using tsup's watch mode with an outDir that points to a location outside the current directory (e.g., ../../dist), file changes are not detected and the rebuild is not triggered. This PR fixes the issue by improving the path comparison logic in the watch mode.

Problem

The current implementation uses glob patterns to check if a file should be ignored, which doesn't handle external paths correctly. This leads to watch mode failing to detect changes when outDir is outside the current directory.

Solution

  • Convert all paths to absolute paths before comparison
  • Replace glob-based ignore check with direct path comparison using startsWith
  • Ensure consistent path handling for both local and external directories

Test Cases

  1. Watch mode with local outDir (./dist):

    export default defineConfig({
      outDir: 'dist',
      watch: true
    })

    ✅ Works as expected

  2. Watch mode with external outDir (../../dist):

    export default defineConfig({
      outDir: '../../dist',
      watch: true
    })

    ✅ Now works correctly

Breaking Changes

None. This is a bug fix that maintains backward compatibility.

When using tsup's watch mode with an outDir that points to a location
outside the current directory (e.g., ../../dist), file changes are not
detected and the rebuild is not triggered.

This commit fixes the issue by:
- Converting paths to absolute paths before comparison
- Replacing glob-based ignore check with direct path comparison
- Ensuring consistent path handling for both local and external directories
Copy link

codesandbox bot commented Dec 22, 2024

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

Copy link

vercel bot commented Dec 22, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
tsup ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 22, 2024 9:43pm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant