reasonbucklescriptreason-react

How to ignore sources in bsconfig.json file (reasonml)?


I want to use the "subdirs": true option in sources of my bsconfig.json file, but ignore a specific folder. (rather than doing the opposite and adding each subfolder to sources besides the one I want to ignore)

Extra info (if you wondering why I am asking for this):

I have tried to introduce unit tests to create-react-app + reason-react codebase using bs-jest.

Since I am using create-react-app and I want to use its configuration as much as possible, I need the tests to appear in the src directory.

I have gotten the whole thing to work using the following bsconfig.json file. But I wanted to put @glennsl/bs-jest in bs-dev-dependencies.

{
  "name": "wild-cards",
  "reason": {
    "react-jsx": 3
  },
  "bsc-flags": [
    "-bs-super-errors"
  ],
  "sources": [
    {
      "dir": "src",
      "subdirs": true
    }
  ],
  "package-specs": [
    {
      "module": "es6",
      "in-source": true
    }
  ],
  "suffix": ".bs.js",
  "namespace": true,
  "bs-dependencies": [
    "reason-react",
    ...
    "@glennsl/bs-jest"
  ],
  "bs-dev-dependencies": [],
  "ppx-flags": [],
  "refmt": 3
}

The below is more along the lines of what I would like.

{
  "name": "wild-cards",
  "reason": {
    "react-jsx": 3
  },
  "bsc-flags": [
    "-bs-super-errors"
  ],
  "sources": [
    {
      "dir": "src",
      "subdirs": true
    },
    {
      "dir": "src/__tests__",
      "type": "dev"
    }
  ],
  "package-specs": [
    {
      "module": "es6",
      "in-source": true
    }
  ],
  "suffix": ".bs.js",
  "namespace": true,
  "bs-dependencies": [
    "reason-react",
    ...
  ],
  "bs-dev-dependencies": [
    "@glennsl/bs-jest"
  ],
  "ppx-flags": [],
  "refmt": 3
}

But with the above config I get this error:

Error: Accounting_test found in two directories: (src/__tests__, src/__tests__) File names must be unique per project


Solution

  • As far as I know there is not a way to ignore subdirs by name in the sources key of bsconfig.json. Here you can see a full description of bsconfig. Usually what I do is put __tests__ at the top level.

    "sources": [
        {
          "dir": "src",
          "subdirs": true
        },
        {
          "dir": "__tests__",
          "type": "dev"
        }
      ],