rescript-lang / rescript-lang/rescript

Rebuild source dependencies when package output settings change

Open
#8,539 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
OCaml
Stars
7.5k
Forks
485
Avg merge
1d 2h
Merged PRs (30d)
55

Description

Problem

Rewatch can reuse stale dependency build artifacts when projects with different package-specs build the same source dependency.

We encountered this while working on moving Belt into the separate @rescript/belt package in the ReScript compiler repository:

  1. The regular analysis tests build @rescript/belt through a CommonJS test project.
  2. The reanalyze tests subsequently use the same package through an ES module test project.
  3. Both projects reference the same source dependency and therefore share its build artifacts.
  4. Rewatch considers the existing Belt artifacts current and does not rebuild them for the second project.
  5. The reanalyze tests fail with a misleading Missing dependency Belt_* error.

This is not a particularly common project setup, but the compiler repository exposes the underlying invalidation problem because multiple test projects with different output formats build the same source dependency in sequence.

Dependencies are compiled using the consuming root project's package output settings. However, these settings are not recorded in lib/bs/compiler-info.json. Belt's .cmj files therefore still contain only the CommonJS package-output metadata when the ES module project is built.

The dependency files and compiler search path are present; it is the package-output metadata inside the .cmj files that is stale.

Proposed solution

Include the effective root package output settings in each package's compiler-info.json.

The stored value should contain a normalized representation of every effective package spec, including:

  • Module format
  • in-source
  • Resolved suffix, including the root-level suffix fallback

During initialization, compare the current package output settings with those stored in compiler-info.json. If they differ, clean and rebuild the affected dependency.

This follows the existing mechanism that invalidates dependency builds when root source-map arguments change.

Testing

Add an integration test with two projects sharing a source dependency:

  1. Build the dependency through a CommonJS project.
  2. Build it through an ES module project without explicitly cleaning the dependency.
  3. Verify that Rewatch rebuilds the dependency and that the second project compiles successfully.

Ideally, test the reverse order as well.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the existing dependency invalidation for root source-map arguments during initialization and inspect compiler-info.json alongside the generated .cmj artifacts. Then examine the integration-test setup for the two projects sharing a source dependency. Done means changing package output settings causes Rewatch to rebuild the dependency and both module-order scenarios compile successfully.

Written by the indexing model from the issue text.

Assessment

Tech stack
ocaml
Domain
build-system, compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.