Skip to content

Fix/cli external modules watch#1487

Open
devhd9 wants to merge 3 commits intofacebook:mainfrom
devhd9:fix/cli-external-modules-watch
Open

Fix/cli external modules watch#1487
devhd9 wants to merge 3 commits intofacebook:mainfrom
devhd9:fix/cli-external-modules-watch

Conversation

@devhd9
Copy link

@devhd9 devhd9 commented Feb 21, 2026

What changed / motivation ?

The StyleX CLI had two issues related to modules_EXPERIMENTAL support:

1. Bug in fetchModule

fetchModule was calling fs.rmSync on the entire stylex_compiled_modules directory before copying each module.

When multiple external modules were configured, this caused destructive overwrite behavior:

  • Each module copy deleted previously compiled modules.
  • Only the last configured module remained in the output.

2. No watch mode support for external modules

The CLI’s --watch mode only tracked changes inside the input source directory.

Changes inside external modules (modules_EXPERIMENTAL) were not detected, requiring a manual restart to re-fetch and recompile them.

Linked PR/Issues

Fixes #731

Additional Context

Added tests in compile-stylex-folder-test.js to verify that copyNodeModules correctly preserves:

  • Multiple configured modules
  • A single module
  • The empty-module case

No breaking changes — the fix and added functionality are additive and only affect modules_EXPERIMENTAL behavior.

Pre-flight checklist

It was removing stylex_compiled_modules during each call which is not expected since in case of multiple external modules, only the last one remains and previous one would be deleted while copying next one.
Refactor subscription logic with dedicated functions (registerSubscription, compileAndCleanup) and add module watching capabilities to track changes in external dependencies.
Export COMPILED_MODULES_DIR_NAME from modules.js and update references across the CLI codebase to ensure consistency in the directory name used for compiled modules.
@vercel
Copy link

vercel bot commented Feb 21, 2026

@devhd9 is attempting to deploy a commit to the Meta Open Source Team on Vercel.

A member of the Team first needs to authorize it.

@meta-cla meta-cla bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Feb 21, 2026
Copy link
Member

@mellyeliu mellyeliu left a comment

Choose a reason for hiding this comment

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

Thanks for the fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[cli] Fix issues with StyleX usage within external packages

2 participants