How to setup a root bsconfig for rewatch?

Running into build issues in a monorepo and I’ve seen rewatch mentioned as a good alternative builder. But the docs only mention running npx rewatch build with a “root bsconfig”, but has no mention of what a root config is and I can’t find any examples.

If I have:

app/
  client/
    rescript.json
package/
  utils/
    rescript.json

What does rewatch expect the root config to be?

1 Like

There’s a testrepo folder that has examples config files in it rewatch/testrepo at master · teamwalnut/rewatch · GitHub

2 Likes

Thanks, that does help a little, though I think there’s a step missing as I’m getting this error:

[1/7]📦 Building package tree...[1/2] ️🛑  Error building package tree. The package "@app/client" is not found (are node_modules up-to-date?)...%                                                                                                   
{
   "name": "my-monorepo",
   "sources": [],
   "package-specs": [{ "module": "es6", "in-source": true }],
   "bs-dependencies": ["@app/client"],
   "pinned-dependencies": ["@app/client"],
   "suffix": ".res.js"
}

It seems like rewatch is searching for my packages within node_modules, and I don’t see a way to nudge it towards “app” or “packages”. Is there another step or is this due to some difference between the way pnpm and yarn manage workspaces?

Looks like it works if I add the package as a dev dependency to the root, but I don’t see that in the example (and would rather not if I can avoid it)

it works fine for me with pnpm workspaces

instead of bsconfig.json I use rescript.json

{
  "name": "ventas",
  "sources": [
    { "dir": "src/components", "subdirs": false },
    {
      "dir": "tests",
      "subdirs": false // I had to remove dev mode for tests because rewatch doesnt compile dev
    }
  ],
  "package-specs": [
    {
      "module": "esmodule", // changed es6 to esmodule when upgraded to rescript v11.1
      "in-source": true
    }
  ],
  "bs-dependencies": ["@rescript/react", "@packages/bz-core"],
  "bs-dev-dependencies": ["@packages/bz-core"], // this module comes from my monorepo
  "suffix": ".res.js",
  "reanalyze": {
    "analysis": ["dce", "exception"]
  },
  "jsx": { "version": 4, "mode": "automatic" },
  "uncurried": false,
  "warnings": {
    "number": "-44-102",
    "error": "+5"
  },
  "namespace": true
}

Could you describe the desired logic of finding packages? I’ve added the pnpm support recently and am familiar with the part of the code. I can add support for this case if I understand the problem better. Do you have pnpm-workspace.yaml or something like this?

2 Likes

Yeah, I list a few directories in the workspace.yaml file any any pnpm command I use always first checks these directories:

packages:
  - app/client
  - packages/*

I wouldn’t be opposed to adding workspaces in package.json to follow official npm convention, though I think ideally I’d like to just pass project dirs directly into pinned dependencies

"pinned-dependencies": [
  "./app/client",
  "./packages/utils"
]

(Don’t think that’s supported, right?)

1 Like

The pinned-dependencies are actually useless right now and don’t have any effect. You can ignore them.

Could you create an issue in the rewatch repo and a minimal reproduction repository with your setup?

1 Like

A bit late here but running into monorepo build problems again and found myself from google.

I’ve created an issue in rewatch and included a testrepo

Noticed a PR from @rolandpeelen for adding a pnpm testrepo to the repository:

This sample needs to pnpm install every package to the root repo, was hoping I could avoid that

Found out that pnpm has a way to hoist local packages to node_modules without needing to explicitly pnpm add them:

hoist-workspace-packages=true
public-hoist-pattern[]=@testrepo/*
3 Likes