Skip to content

Commit 0581193

Browse files
authored
Merge pull request #19 from rescript-lang/monorepo-support
Monorepo support (e.g. yarn workspaces)
2 parents e57a8ac + b6a40dc commit 0581193

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1271
-111
lines changed

.gitignore

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
.bsb.lock
2828
lib/bs
29-
/node_modules
29+
node_modules
3030
test/**/*.js
3131
doc/tags
3232

@@ -37,3 +37,8 @@ doc/tags
3737
!rescript-vscode/extension/server/win32/rescript-editor-support.exe
3838

3939
rescript-vscode/extension/server/node_modules/.bin/
40+
41+
examples/**/node_modules
42+
examples/**/lib
43+
examples/**/src/*.js
44+
examples/**/.merlin

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,18 @@
22

33
## master
44

5+
** Improvements: **
6+
7+
- Upgrade to `rescript-vscode@1.4.0` (see changes [here](https://github.com/rescript-lang/rescript-vscode/blob/1.0.4/HISTORY.md#104))
8+
- Add proper monorepo support (`e.g. yarn workspaces`)
9+
- Detects `bsb` / `bsc` correctly for each buffer separately.
10+
- Heuristic for detecting the binaries: For the current file, find the nearest `node_modules/bs-platform` folder for the binaries
11+
- Adds an `augroup RescriptAutoProjectEnv` that sets the environment on every `.res` / `.resi` related read / write / new file event
12+
- Will also update the environment on each `format` and `build` call to make it sync up for all non-rescript buffers
13+
- On each env update, it updates the local working directory to the updated project root path as well
514
- Fixes issue with long template strings breaking the syntax highlighting
15+
- Fixes an issue where `:RescriptBuild` would fail in non-rescript buffers due to a wrongly scoped script variable (was buffer only)
16+
- Add new commands `:RescriptBuildWorld` and `:RescriptCleanWorld` for cleaning / building all sources + dependencies
617

718
## 1.1.0
819

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
- Filetype detection for `.res`, `.resi`
1616
- Basic automatic indentation
1717
- Includes LSP for coc-vim usage
18+
- Proper tooling detection for monorepo like setups (yarn workspaces)
1819

1920
**Provided by vim-rescript commands:**
2021
- Formatting `.res` files w/ syntax error diagnostics in VIM quickfix
@@ -24,6 +25,12 @@
2425
- Building the current projec w/ build diagnostics in VIM quickfix
2526
- Autocompletion w/ Vim's omnicomplete
2627

28+
**Monorepo support:**
29+
30+
The vim-rescript plugin automatically updates its project environment on each file open separately.
31+
- Tested for yarn workspaces (see [./examples/monorepo-yarn-workspaces])
32+
- **Note for non-LSP usage:** Always make sure to switch to a `.res` file **within the project you want to compile** before running `:RescriptBuild` etc.
33+
2734
See `:h rescript` for the detailed [helpfile](./doc/rescript.txt).
2835

2936
## Requirements

autoload/rescript.vim

Lines changed: 45 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,12 @@ function! s:ShowInPreview(fname, fileType, lines)
2121
endif
2222
endfunction
2323

24-
" Inits the plugin variables, e.g. finding all the necessary binaries
25-
function! rescript#Init()
26-
if has('macunix')
27-
let b:rescript_arch = "darwin"
28-
elseif has('win32')
29-
let b:rescript_arch = "win32"
30-
elseif has('unix')
31-
let b:rescript_arch = "linux"
32-
endif
33-
24+
" Configures the project related globals based on the current buffer location
25+
" This is needed for supporting monorepos with multiple projects / multiple
26+
" bs-platform setups
27+
function! rescript#UpdateProjectEnv()
3428
" Looks for the nearest node_modules directory
35-
let l:res_bin_dir = finddir('node_modules', ".;") . "/bs-platform/" . b:rescript_arch
29+
let l:res_bin_dir = finddir('node_modules/bs-platform/', ".;") . s:rescript_arch
3630

3731
"if !exists("g:rescript_compile_exe")
3832
let g:rescript_compile_exe = l:res_bin_dir . "/bsc.exe"
@@ -42,24 +36,41 @@ function! rescript#Init()
4236
let g:rescript_build_exe = l:res_bin_dir . "/bsb.exe"
4337
"endif
4438

45-
" Needed for state tracking of the formatting error state
46-
let s:got_format_err = 0
47-
let s:got_build_err = 0
48-
49-
if !exists("g:rescript_editor_support_exe")
50-
let g:rescript_editor_support_exe = s:rescript_plugin_dir . "/rescript-vscode/extension/server/" . b:rescript_arch . "/rescript-editor-support.exe"
51-
endif
52-
53-
" Not sure why, but adding a ".;" doesn't find bsconfig when
54-
" the editor was started without a specific file within the project
55-
let g:rescript_project_config = findfile("bsconfig.json")
39+
" Note that this doesn't find bsconfig when the editor was started without a
40+
" specific file within the project
41+
let g:rescript_project_config = findfile("bsconfig.json", ".;")
5642

5743
" Try to find the nearest .git folder instead
5844
if g:rescript_project_config == ""
5945
let g:rescript_project_root = finddir(".git/..", expand('%:p:h').';')
6046
else
6147
let g:rescript_project_root = fnamemodify(g:rescript_project_config, ":p:h")
6248
endif
49+
50+
" Make sure that our local working directory is in the rescript_project_root
51+
exe "lcd " . g:rescript_project_root
52+
endfunction
53+
54+
" Inits the plugin variables, e.g. finding all the plugin related binaries
55+
" and initialising some internal state for UI (error window etc.)
56+
function! rescript#Init()
57+
if has('macunix')
58+
let s:rescript_arch = "darwin"
59+
elseif has('win32')
60+
let s:rescript_arch = "win32"
61+
elseif has('unix')
62+
let s:rescript_arch = "linux"
63+
endif
64+
65+
" Needed for state tracking of the formatting error state
66+
let s:got_format_err = 0
67+
let s:got_build_err = 0
68+
69+
if !exists("g:rescript_editor_support_exe")
70+
let g:rescript_editor_support_exe = s:rescript_plugin_dir . "/rescript-vscode/extension/server/" . s:rescript_arch . "/rescript-editor-support.exe"
71+
endif
72+
73+
call rescript#UpdateProjectEnv()
6374
endfunction
6475

6576
function! s:DeleteLines(start, end) abort
@@ -79,6 +90,7 @@ function! rescript#GetRescriptVscodeVersion()
7990
endfunction
8091

8192
function! rescript#DetectVersion()
93+
call rescript#UpdateProjectEnv()
8294
let l:command = g:rescript_compile_exe . " -version"
8395

8496
silent let l:output = system(l:command)
@@ -96,6 +108,8 @@ function! rescript#DetectVersion()
96108
endfunction
97109

98110
function! rescript#Format()
111+
call rescript#UpdateProjectEnv()
112+
99113
let l:ext = expand("%:e")
100114

101115
if matchstr(l:ext, 'resi\?') == ""
@@ -376,8 +390,15 @@ function! rescript#Complete(findstart, base)
376390
return l:ret
377391
endfunction
378392

379-
function! rescript#BuildProject()
380-
let out = system(g:rescript_build_exe)
393+
function! rescript#BuildProject(...)
394+
call rescript#UpdateProjectEnv()
395+
396+
let l:cmd = g:rescript_build_exe
397+
if a:0 ==? 1
398+
let l:cmd = g:rescript_build_exe . " " . a:1
399+
endif
400+
401+
let out = system(l:cmd)
381402

382403
" We don't rely too heavily on exit codes. If there's a compiler.log,
383404
" then there is either an error or a warning, so we rely on the existence

doc/rescript.txt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,16 @@ COMMANDS *rescript-commands*
118118
after writing your new .res file, otherwise the compiler will not compile.
119119

120120
*:RescriptBuild*
121-
Builds your current project with g:rescript_build_exe
121+
Builds your current project with g:rescript_build_exe (without -make-world
122+
flag)
123+
124+
*:RescriptBuildWorld*
125+
Builds your current project with g:rescript_build_exe (with -make-world).
126+
This is useful for building your ReScript dependencies as well.
127+
128+
*:RescriptCleanWorld*
129+
Cleans all project files + all ReScript dependencies. This is useful for
130+
fixing stale caches (e.g. when upgrading ReScript versions).
122131

123132
*:RescriptTypeHint*
124133
Uses the g:rescript_editor_support_exe executable to extract
File renamed without changes.

examples/basic/package-lock.json

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/basic/package.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "basic",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"keywords": [],
10+
"author": "",
11+
"license": "ISC",
12+
"devDependencies": {
13+
"bs-platform": "8.4.2",
14+
"reason-react": "0.9.1"
15+
}
16+
}

examples/basic/src/Button.res

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
@react.component
2+
let make = () => {
3+
<div className="text-white bg-red">
4+
{React.string("Click me")}
5+
</div>
6+
}

0 commit comments

Comments
 (0)