Skip to content

Commit b730d9f

Browse files
committed
fix: wrong path to rescript executable
refactor `cli.rs` to remove duplication of docstrings
1 parent 7faf311 commit b730d9f

File tree

7 files changed

+256
-155
lines changed

7 files changed

+256
-155
lines changed

rewatch/src/build.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ pub struct CompilerArgs {
5959
pub fn get_compiler_args(
6060
path: &Path,
6161
rescript_version: Option<String>,
62-
bsc_path: &Option<PathBuf>,
62+
bsc_path: Option<PathBuf>,
6363
build_dev_deps: bool,
6464
) -> Result<String> {
6565
let filename = &helpers::get_abs_path(path);
@@ -501,7 +501,7 @@ pub fn build(
501501
show_progress: bool,
502502
no_timing: bool,
503503
create_sourcedirs: bool,
504-
bsc_path: &Option<PathBuf>,
504+
bsc_path: Option<PathBuf>,
505505
build_dev_deps: bool,
506506
snapshot_output: bool,
507507
) -> Result<BuildState> {
@@ -516,7 +516,7 @@ pub fn build(
516516
filter,
517517
show_progress,
518518
path,
519-
bsc_path,
519+
&bsc_path,
520520
build_dev_deps,
521521
snapshot_output,
522522
)
@@ -558,9 +558,9 @@ pub fn pass_through_legacy(args: Vec<OsString>) -> i32 {
558558
let project_root = helpers::get_abs_path(Path::new("."));
559559
let workspace_root = helpers::get_workspace_root(&project_root);
560560

561-
let bsb_path = helpers::get_rescript_legacy(&project_root, workspace_root);
561+
let rescript_legacy_path = helpers::get_rescript_legacy(&project_root, workspace_root);
562562

563-
let status = std::process::Command::new(bsb_path)
563+
let status = std::process::Command::new(rescript_legacy_path)
564564
.args(args)
565565
.stdout(Stdio::inherit())
566566
.stderr(Stdio::inherit())

rewatch/src/build/clean.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ pub fn cleanup_after_build(build_state: &BuildState) {
334334
pub fn clean(
335335
path: &Path,
336336
show_progress: bool,
337-
bsc_path: &Option<PathBuf>,
337+
bsc_path: Option<PathBuf>,
338338
snapshot_output: bool,
339339
) -> Result<()> {
340340
let project_root = helpers::get_abs_path(path);

rewatch/src/cli.rs

Lines changed: 136 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::ffi::OsString;
1+
use std::{ffi::OsString, ops::Deref};
22

33
use clap::{Args, Parser, Subcommand};
44
use clap_verbosity_flag::InfoLevel;
@@ -24,23 +24,29 @@ pub struct Cli {
2424
#[command(subcommand)]
2525
pub command: Option<Command>,
2626

27+
#[command(flatten)]
28+
pub build_args: BuildArgs,
29+
}
30+
31+
#[derive(Args, Debug, Clone)]
32+
pub struct FolderArg {
2733
/// The relative path to where the main rescript.json resides. IE - the root of your project.
2834
#[arg(default_value = ".")]
2935
pub folder: String,
30-
31-
#[command(flatten)]
32-
pub build_args: BuildArgs,
3336
}
3437

3538
#[derive(Args, Debug, Clone)]
36-
pub struct BuildArgs {
39+
pub struct FilterArg {
3740
/// Filter files by regex
3841
///
3942
/// Filter allows for a regex to be supplied which will filter the files to be compiled. For
4043
/// instance, to filter out test files for compilation while doing feature work.
4144
#[arg(short, long)]
4245
pub filter: Option<String>,
46+
}
4347

48+
#[derive(Args, Debug, Clone)]
49+
pub struct AfterBuildArg {
4450
/// Action after build
4551
///
4652
/// This allows one to pass an additional command to the watcher, which allows it to run when
@@ -49,14 +55,20 @@ pub struct BuildArgs {
4955
/// color as well
5056
#[arg(short, long)]
5157
pub after_build: Option<String>,
58+
}
5259

60+
#[derive(Args, Debug, Clone, Copy)]
61+
pub struct CreateSourceDirsArg {
5362
/// Create source_dirs.json
5463
///
5564
/// This creates a source_dirs.json file at the root of the monorepo, which is needed when you
5665
/// want to use Reanalyze
5766
#[arg(short, long, default_value_t = false, num_args = 0..=1)]
5867
pub create_sourcedirs: bool,
68+
}
5969

70+
#[derive(Args, Debug, Clone, Copy)]
71+
pub struct DevArg {
6072
/// Build development dependencies
6173
///
6274
/// This is the flag to also compile development dependencies
@@ -65,61 +77,72 @@ pub struct BuildArgs {
6577
/// _all_ packages
6678
#[arg(long, default_value_t = false, num_args = 0..=1)]
6779
pub dev: bool,
80+
}
6881

69-
/// Disable timing on the output
70-
#[arg(short, long, default_value_t = false, num_args = 0..=1)]
71-
pub no_timing: bool,
82+
#[derive(Args, Debug, Clone)]
83+
pub struct BscPathArg {
84+
/// Custom path to bsc
85+
#[arg(long)]
86+
pub bsc_path: Option<String>,
87+
}
7288

89+
#[derive(Args, Debug, Clone, Copy)]
90+
pub struct SnapshotOutputArg {
7391
/// simple output for snapshot testing
7492
#[arg(short, long, default_value = "false", num_args = 0..=1)]
7593
pub snapshot_output: bool,
94+
}
7695

77-
/// Path to bsc
78-
#[arg(long)]
79-
pub bsc_path: Option<String>,
96+
#[derive(Args, Debug, Clone)]
97+
pub struct BuildArgs {
98+
#[command(flatten)]
99+
pub folder: FolderArg,
100+
101+
#[command(flatten)]
102+
pub filter: FilterArg,
103+
104+
#[command(flatten)]
105+
pub after_build: AfterBuildArg,
106+
107+
#[command(flatten)]
108+
pub create_sourcedirs: CreateSourceDirsArg,
109+
110+
#[command(flatten)]
111+
pub dev: DevArg,
112+
113+
/// Disable timing on the output
114+
#[arg(short, long, default_value_t = false, num_args = 0..=1)]
115+
pub no_timing: bool,
116+
117+
#[command(flatten)]
118+
pub snapshot_output: SnapshotOutputArg,
119+
120+
#[command(flatten)]
121+
pub bsc_path: BscPathArg,
80122
}
81123

82124
#[derive(Args, Clone, Debug)]
83125
pub struct WatchArgs {
84-
/// Filter files by regex
85-
///
86-
/// Filter allows for a regex to be supplied which will filter the files to be compiled. For
87-
/// instance, to filter out test files for compilation while doing feature work.
88-
#[arg(short, long)]
89-
pub filter: Option<String>,
126+
#[command(flatten)]
127+
pub folder: FolderArg,
90128

91-
/// Action after build
92-
///
93-
/// This allows one to pass an additional command to the watcher, which allows it to run when
94-
/// finished. For instance, to play a sound when done compiling, or to run a test suite.
95-
/// NOTE - You may need to add '--color=always' to your subcommand in case you want to output
96-
/// color as well
97-
#[arg(short, long)]
98-
pub after_build: Option<String>,
129+
#[command(flatten)]
130+
pub filter: FilterArg,
99131

100-
/// Create source_dirs.json
101-
///
102-
/// This creates a source_dirs.json file at the root of the monorepo, which is needed when you
103-
/// want to use Reanalyze
104-
#[arg(short, long, default_value_t = false, num_args = 0..=1)]
105-
pub create_sourcedirs: bool,
132+
#[command(flatten)]
133+
pub after_build: AfterBuildArg,
106134

107-
/// Build development dependencies
108-
///
109-
/// This is the flag to also compile development dependencies
110-
/// It's important to know that we currently do not discern between project src, and
111-
/// dependencies. So enabling this flag will enable building _all_ development dependencies of
112-
/// _all_ packages
113-
#[arg(long, default_value_t = false, num_args = 0..=1)]
114-
pub dev: bool,
135+
#[command(flatten)]
136+
pub create_sourcedirs: CreateSourceDirsArg,
115137

116-
/// simple output for snapshot testing
117-
#[arg(short, long, default_value = "false", num_args = 0..=1)]
118-
pub snapshot_output: bool,
138+
#[command(flatten)]
139+
pub dev: DevArg,
119140

120-
/// Path to bsc
121-
#[arg(long)]
122-
pub bsc_path: Option<String>,
141+
#[command(flatten)]
142+
pub snapshot_output: SnapshotOutputArg,
143+
144+
#[command(flatten)]
145+
pub bsc_path: BscPathArg,
123146
}
124147

125148
#[derive(Subcommand, Clone, Debug)]
@@ -130,13 +153,14 @@ pub enum Command {
130153
Watch(WatchArgs),
131154
/// Clean the build artifacts
132155
Clean {
133-
/// Path to bsc
134-
#[arg(long)]
135-
bsc_path: Option<String>,
156+
#[command(flatten)]
157+
folder: FolderArg,
158+
159+
#[command(flatten)]
160+
bsc_path: BscPathArg,
136161

137-
/// simple output for snapshot testing
138-
#[arg(short, long, default_value = "false", num_args = 0..=1)]
139-
snapshot_output: bool,
162+
#[command(flatten)]
163+
snapshot_output: SnapshotOutputArg,
140164
},
141165
/// Alias to `legacy format`.
142166
#[command(disable_help_flag = true)]
@@ -156,23 +180,78 @@ pub enum Command {
156180
#[command()]
157181
path: String,
158182

159-
#[arg(long, default_value_t = false, num_args = 0..=1)]
160-
dev: bool,
183+
#[command(flatten)]
184+
dev: DevArg,
161185

162186
/// To be used in conjunction with compiler_args
163187
#[arg(long)]
164188
rescript_version: Option<String>,
165189

166-
/// A custom path to bsc
167-
#[arg(long)]
168-
bsc_path: Option<String>,
190+
#[command(flatten)]
191+
bsc_path: BscPathArg,
169192
},
170193
/// Use the legacy build system.
171194
///
172195
/// After this command is encountered, the rest of the arguments are passed to the legacy build system.
173-
#[command(disable_help_flag = true)]
196+
#[command(disable_help_flag = true, external_subcommand = true)]
174197
Legacy {
175198
#[arg(allow_hyphen_values = true, num_args = 0..)]
176199
legacy_args: Vec<OsString>,
177200
},
178201
}
202+
203+
impl Deref for FolderArg {
204+
type Target = str;
205+
206+
fn deref(&self) -> &Self::Target {
207+
&self.folder
208+
}
209+
}
210+
211+
impl Deref for FilterArg {
212+
type Target = Option<String>;
213+
214+
fn deref(&self) -> &Self::Target {
215+
&self.filter
216+
}
217+
}
218+
219+
impl Deref for AfterBuildArg {
220+
type Target = Option<String>;
221+
222+
fn deref(&self) -> &Self::Target {
223+
&self.after_build
224+
}
225+
}
226+
227+
impl Deref for CreateSourceDirsArg {
228+
type Target = bool;
229+
230+
fn deref(&self) -> &Self::Target {
231+
&self.create_sourcedirs
232+
}
233+
}
234+
235+
impl Deref for DevArg {
236+
type Target = bool;
237+
238+
fn deref(&self) -> &Self::Target {
239+
&self.dev
240+
}
241+
}
242+
243+
impl Deref for BscPathArg {
244+
type Target = Option<String>;
245+
246+
fn deref(&self) -> &Self::Target {
247+
&self.bsc_path
248+
}
249+
}
250+
251+
impl Deref for SnapshotOutputArg {
252+
type Target = bool;
253+
254+
fn deref(&self) -> &Self::Target {
255+
&self.snapshot_output
256+
}
257+
}

rewatch/src/helpers.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,18 +222,18 @@ pub fn get_bsc(root_path: &Path, workspace_root: &Option<PathBuf>) -> PathBuf {
222222
}
223223

224224
pub fn get_rescript_legacy(root_path: &Path, workspace_root: Option<PathBuf>) -> PathBuf {
225-
let bin_dir = get_bin_dir();
225+
let bin_dir = Path::new("node_modules").join("rescript").join("cli");
226226

227227
match (
228228
root_path
229229
.join(&bin_dir)
230-
.join("rescript.exe")
230+
.join("rescript.js")
231231
.canonicalize()
232232
.map(StrippedVerbatimPath::to_stripped_verbatim_path),
233233
workspace_root.map(|workspace_root| {
234234
workspace_root
235235
.join(&bin_dir)
236-
.join("rescript.exe")
236+
.join("rescript.js")
237237
.canonicalize()
238238
.map(StrippedVerbatimPath::to_stripped_verbatim_path)
239239
}),

0 commit comments

Comments
 (0)