Skip to content

Monorepo support (e.g. yarn workspaces) #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 23 commits into from
Jan 6, 2021
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,8 @@ doc/tags
!rescript-vscode/extension/server/win32/rescript-editor-support.exe

rescript-vscode/extension/server/node_modules/.bin/

examples/**/node_modules
examples/**/lib
examples/**/src/*.js
examples/**/.merlin
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## master

- Improves tooling detection (`bsc`, `bsb`) in a monorepo like setup (`yarn workspaces`)
- Fixes issue with long template strings breaking the syntax highlighting

## 1.1.0
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
- Filetype detection for `.res`, `.resi`
- Basic automatic indentation
- Includes LSP for coc-vim usage
- Proper tooling detection for monorepo like setups (yarn workspaces)

**Provided by vim-rescript commands:**
- Formatting `.res` files w/ syntax error diagnostics in VIM quickfix
Expand Down
2 changes: 1 addition & 1 deletion autoload/rescript.vim
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function! rescript#Init()
endif

" Looks for the nearest node_modules directory
let l:res_bin_dir = finddir('node_modules', ".;") . "/bs-platform/" . b:rescript_arch
let l:res_bin_dir = finddir('node_modules/bs-platform/', ".;") . b:rescript_arch

"if !exists("g:rescript_compile_exe")
let g:rescript_compile_exe = l:res_bin_dir . "/bsc.exe"
Expand Down
23 changes: 23 additions & 0 deletions examples/monorepo-yarn-workspaces/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# yarn workspaces monorepo example

This example setup is using the `yarn workspace` feature in combination with ReScript's `pinned-dependencies`.

**Expected IDE plugin behavior:**

When the editor is opened in one of the subprojects `app` or `common`, the editor extension should correctly detect the `bsc` and `bsb` binary in the monorepo root's `node_modules` directory.

```
cd app
nvim .
```

## Setup

```
cd examples/monorepo-yarn-workspaces
yarn

# Build the full project
cd app
yarn run build
```
26 changes: 26 additions & 0 deletions examples/monorepo-yarn-workspaces/app/bsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"$schema": "https://raw.githubusercontent.com/rescript-lang/rescript-compiler/master/docs/docson/build-schema.json",
"name": "app",
"version": "1.0.0",
"sources": {
"dir" : "src",
"subdirs" : true
},
"package-specs": {
"module": "commonjs",
"in-source": true
},
"suffix": ".js",
"bs-dependencies": [
"reason-react",
"common"
],
"pinned-dependencies": ["common"],
"ppx-flags": [],
"bsc-flags": ["-bs-super-errors", "-bs-no-version-header"],
"warnings": {
"number": "-44",
"error": "+8+26+27+101"
},
"reason": {"react-jsx": 3}
}
16 changes: 16 additions & 0 deletions examples/monorepo-yarn-workspaces/app/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "app",
"version": "0.1.0",
"private": true,
"dependencies": {
"common": "1.0.0"
},
"scripts": {
"clean": "bsb -clean-world",
"build": "bsb -make-world",
"watch": "bsb -make-world -w"
},
"devDependencies": {
"bs-platform": "^8.4.2"
}
}
9 changes: 9 additions & 0 deletions examples/monorepo-yarn-workspaces/app/src/App.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@react.component
let make = () => {
Common.Header.make(Js.Obj.empty())->Js.log
Common.Footer.make(Js.Obj.empty())->Js.log

<> <Common.Header /> <div> {React.string("Main content")} <Common.Footer /> </div> </>
}

make(Js.Obj.empty())->Js.log
25 changes: 25 additions & 0 deletions examples/monorepo-yarn-workspaces/common/bsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"$schema": "https://raw.githubusercontent.com/rescript-lang/rescript-compiler/master/docs/docson/build-schema.json",
"name": "common",
"namespace": "Common",
"version": "0.0.1",
"sources": {
"dir" : "src",
"subdirs" : true
},
"package-specs": {
"module": "commonjs",
"in-source": true
},
"suffix": ".js",
"bs-dependencies": [
"reason-react"
],
"ppx-flags": [],
"bsc-flags": ["-bs-super-errors", "-bs-no-version-header"],
"warnings": {
"number": "-44",
"error": "+8+26+27+101"
},
"reason": {"react-jsx": 3}
}
17 changes: 17 additions & 0 deletions examples/monorepo-yarn-workspaces/common/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "common",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"scripts": {
"clean": "bsb -clean-world",
"build": "bsb -make-world",
"watch": "bsb -make-world -w"
},
"dependencies": {
"reason-react": "^0.9.1"
},
"devDependencies": {
"bs-platform": "^8.4.2"
}
}
4 changes: 4 additions & 0 deletions examples/monorepo-yarn-workspaces/common/src/Footer.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@react.component
let make = () => {
<div> {React.string("Footer")} </div>
}
4 changes: 4 additions & 0 deletions examples/monorepo-yarn-workspaces/common/src/Header.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@react.component
let make = () => {
<div> {"Header"->React.string} </div>
}
10 changes: 10 additions & 0 deletions examples/monorepo-yarn-workspaces/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "rescript-yarn-workspaces-example",
"private": true,
"workspaces": {
"packages": [
"app",
"common"
]
}
}
13 changes: 13 additions & 0 deletions examples/monorepo-yarn-workspaces/yarn.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1


bs-platform@^8.4.2:
version "8.4.2"
resolved "https://registry.yarnpkg.com/bs-platform/-/bs-platform-8.4.2.tgz#778dabd1dfb3bc95e0086c58dabae74e4ebdee8a"
integrity sha512-9q7S4/LLV/a68CweN382NJdCCr/lOSsJR3oQYnmPK98ChfO/AdiA3lYQkQTp6T+U0I5Z5RypUAUprNstwDtMDQ==

reason-react@^0.9.1:
version "0.9.1"
resolved "https://registry.yarnpkg.com/reason-react/-/reason-react-0.9.1.tgz#30a887158200b659aa03e2d75ff4cc54dc462bb0"
integrity sha512-nlH0O2TDy9KzOLOW+vlEQk4ExHOeciyzFdoLcsmmiit6hx6H5+CVDrwJ+8aiaLT/kqK5xFOjy4PS7PftWz4plA==