rescript-lang / rescript-lang/rescript

Rebuild source dependencies when package output settings change

Aperta
#8,539 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Lingua principale
OCaml
Stelle
7.5k
Fork
485
Merge medio
1g 2h
PR unite (30g)
55

Descrizione

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.

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia tracciando l’invalidazione esistente delle dipendenze per gli argomenti source-map radice durante l’inizializzazione ed esamina compiler-info.json insieme agli artefatti .cmj generati. Poi esamina la configurazione del test di integrazione per i due progetti che condividono una dipendenza sorgente. Il lavoro è completato quando la modifica delle impostazioni di output del pacchetto fa sì che Rewatch ricostruisca la dipendenza ed entrambi gli scenari di ordinamento dei moduli vengano compilati correttamente.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
ocaml
Ambito
build-system, compilers
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Tranquilla
Chiarezza
Abbastanza chiara
Idoneità per principianti
48/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.