Skip to content

Conversation

nojaf
Copy link
Member

@nojaf nojaf commented Sep 17, 2025

This resolves the upwards traversal as discussed in #7117 (comment)

Copy link

pkg-pr-new bot commented Sep 17, 2025

Open in StackBlitz

rescript

npm i https://pkg.pr.new/rescript-lang/rescript@7896

@rescript/darwin-arm64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/darwin-arm64@7896

@rescript/darwin-x64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/darwin-x64@7896

@rescript/linux-arm64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/linux-arm64@7896

@rescript/linux-x64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/linux-x64@7896

@rescript/runtime

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/runtime@7896

@rescript/win32-x64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/win32-x64@7896

commit: bdac509

@nojaf nojaf marked this pull request as ready for review September 17, 2025 12:58
@nojaf nojaf requested a review from Copilot September 18, 2025 13:25
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements upward directory traversal for package resolution in single context projects, allowing ReScript to find dependencies in parent node_modules directories when building standalone packages in workspace setups.

Key changes include:

  • Added upward traversal logic that searches parent directories for node_modules when dependencies aren't found locally
  • Implemented caching mechanism to optimize repeated path existence checks during traversal
  • Added comprehensive test coverage for standalone package builds

Reviewed Changes

Copilot reviewed 8 out of 9 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
rewatch/src/helpers.rs Core implementation of upward traversal logic with caching for package resolution
rewatch/tests/compile.sh Added test case for standalone package building via rescript command
rewatch/testrepo/packages/standalone/* Test fixtures for standalone package with dependency on @testrepo/dep01
rewatch/testrepo/package.json Added standalone package to workspace and updated scripts to use rescript instead of rewatch
CHANGELOG.md Documented the new upward traversal feature

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@nojaf nojaf added the build label Sep 26, 2025
Copy link
Member

@cknitt cknitt left a comment

Choose a reason for hiding this comment

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

👍 LGTM, but would be great if someone else could review, too.

@cknitt
Copy link
Member

cknitt commented Sep 26, 2025

@codex review

Copy link

Codex Review: Didn't find any major issues. Keep them coming!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.


// Cache existence checks for candidate node_modules paths during upward traversal.
// Keyed by the absolute candidate path; value is the existence boolean.
static NODE_MODULES_EXIST_CACHE: LazyLock<RwLock<ahash::AHashMap<PathBuf, bool>>> =
Copy link
Contributor

Choose a reason for hiding this comment

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

can we not put this in the build state instead of a static value?

Copy link
Member Author

Choose a reason for hiding this comment

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

It is used before BuildState is created, packages::make already needs it.
I was able to move it to ProjectContext:

  • Key point: ProjectContext exists before BuildState. We resolve packages (e.g. helpers::try_package_path) during config/dependency reading, which happens pre-BuildState, and those call sites already have a &ProjectContext.

  • Correct scope/lifetime: The cache models workspace layout (node_modules existence), not per-build artifacts. BuildState may be recreated in watch cycles; ProjectContext persists, so the cache isn’t thrown away.

  • Concurrency and isolation: A per-ProjectContext RwLock allows concurrent reads and avoids process-wide statics and cross-project cache bleed.

  • Lower coupling/less churn: Callers already pass ProjectContext; using it avoids threading BuildState through config.rs and build/packages.rs and reduces borrow/contention with the highly mutable BuildState.

Copy link
Contributor

@jfrolich jfrolich left a comment

Choose a reason for hiding this comment

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

Great!

@nojaf nojaf enabled auto-merge (squash) September 26, 2025 11:14
@nojaf nojaf disabled auto-merge September 26, 2025 11:30
@nojaf nojaf requested a review from Copilot September 26, 2025 11:59
@nojaf
Copy link
Member Author

nojaf commented Sep 26, 2025

I'm also incorporating the changes of #7890 as it is a similar cache.

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 10 out of 11 changed files in this pull request and generated 3 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@nojaf nojaf enabled auto-merge (squash) September 26, 2025 12:15
@nojaf nojaf merged commit 84e45c5 into rescript-lang:master Sep 26, 2025
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants