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 watching relative dirs in @swc/cli due to change in chokidar@v4 #82

Merged
merged 3 commits into from
Feb 25, 2025

Conversation

aaronhuggins
Copy link
Contributor

@aaronhuggins aaronhuggins commented Jan 31, 2025

When watching on --out-dir, @swc/cli would compile the sources when a relative path was passed, but watching would immediately exit instead of watch for changes.

Chokidar version 4.x removes globbing support, which means that it does not recursively watch unresolved relative paths with either globbing or cwd. The documentation recommends resolving the glob(s) before passing to watch, and has some examples.

Weighing the options, it appeared to be more ergonomic to use globSources to resolve the files to watch rather than create a new method of globbing or directly glob the files. This pull request makes a very small change to the parameters of watchSources, as I could not cause the error to occur on individual files and wanted to leave that signature alone. However, when watching on --out-dir, watching would immediately exit as a relative file did not exist and was not being resolved via globbing anymore.

This restores the ability to pass relative paths and globs to the swc command of @swc/cli and successfully watch for changes of the source files.

Chokidar is no longer globbing as of v4. This means that passing relative URLs no longer watches for changes, e.g. `.` as the filename argument.

- Modify `watchSources` to accept additional arguments as needed by `globSources`
- Pass arguments to `globSources` to get the source list for chokidar to watch
- Give the result to chokidar
Copy link

changeset-bot bot commented Jan 31, 2025

🦋 Changeset detected

Latest commit: 0195279

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@swc/cli Patch

Not sure what this means? Click here to learn what changesets are.

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

@CLAassistant
Copy link

CLAassistant commented Jan 31, 2025

CLA assistant check
All committers have signed the CLA.

@kdy1 kdy1 self-assigned this Feb 3, 2025
@kdy1 kdy1 merged commit 4a15691 into swc-project:main Feb 25, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants