Skip to content

Commit b452b3e

Browse files
committed
Build Dev Dependencies with flag
1 parent 7c85771 commit b452b3e

File tree

5 files changed

+49
-25
lines changed

5 files changed

+49
-25
lines changed

src/build.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ pub fn get_compiler_args(
5959
path: &str,
6060
rescript_version: Option<String>,
6161
bsc_path: Option<String>,
62+
build_dev_deps: bool,
6263
) -> Result<String> {
6364
let filename = &helpers::get_abs_path(path);
6465
let package_root = helpers::get_abs_path(
@@ -115,6 +116,7 @@ pub fn get_compiler_args(
115116
&package_root,
116117
&workspace_root,
117118
&None,
119+
build_dev_deps,
118120
);
119121

120122
let result = serde_json::to_string_pretty(&CompilerArgs {
@@ -277,6 +279,7 @@ pub fn incremental_build(
277279
show_progress: bool,
278280
only_incremental: bool,
279281
create_sourcedirs: bool,
282+
build_dev_deps: bool,
280283
) -> Result<(), IncrementalBuildError> {
281284
logs::initialize(&build_state.packages);
282285
let num_dirty_modules = build_state.modules.values().filter(|m| is_dirty(m)).count() as u64;
@@ -389,6 +392,7 @@ pub fn incremental_build(
389392
show_progress,
390393
|| pb.inc(1),
391394
|size| pb.set_length(size),
395+
build_dev_deps,
392396
)
393397
.map_err(|e| IncrementalBuildError::CompileError(Some(e.to_string())))?;
394398

@@ -460,6 +464,7 @@ pub fn build(
460464
no_timing: bool,
461465
create_sourcedirs: bool,
462466
bsc_path: Option<String>,
467+
build_dev_deps: bool,
463468
) -> Result<BuildState> {
464469
let default_timing: Option<std::time::Duration> = if no_timing {
465470
Some(std::time::Duration::new(0.0 as u64, 0.0 as u32))
@@ -477,6 +482,7 @@ pub fn build(
477482
show_progress,
478483
false,
479484
create_sourcedirs,
485+
build_dev_deps,
480486
) {
481487
Ok(_) => {
482488
if show_progress {

src/build/compile.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ pub fn compile(
2121
show_progress: bool,
2222
inc: impl Fn() + std::marker::Sync,
2323
set_length: impl Fn(u64),
24+
build_dev_deps: bool,
2425
) -> Result<(String, String, usize)> {
2526
let mut compiled_modules = AHashSet::<String>::new();
2627
let dirty_modules = build_state
@@ -169,6 +170,7 @@ pub fn compile(
169170
&build_state.packages,
170171
&build_state.project_root,
171172
&build_state.workspace_root,
173+
build_dev_deps,
172174
);
173175
Some(result)
174176
}
@@ -185,6 +187,7 @@ pub fn compile(
185187
&build_state.packages,
186188
&build_state.project_root,
187189
&build_state.workspace_root,
190+
build_dev_deps,
188191
);
189192
let cmi_digest_after = helpers::compute_file_hash(&cmi_path);
190193

@@ -359,20 +362,19 @@ pub fn compiler_args(
359362
// if packages are known, we pass a reference here
360363
// this saves us a scan to find their paths
361364
packages: &Option<&AHashMap<String, packages::Package>>,
365+
build_dev_deps: bool,
362366
) -> Vec<String> {
363367
let normal_deps = config.bs_dependencies.as_ref().unwrap_or(&vec![]).to_owned();
364368

365369
let bsc_flags = config::flatten_flags(&config.bsc_flags);
366370
// don't compile dev-deps yet
367-
// let dev_deps = source
368-
// .package
369-
// .config
370-
// .bs_dev_dependencies
371-
// .as_ref()
372-
// .unwrap_or(&vec![])
373-
// .to_owned();
374-
375-
let deps = [normal_deps]
371+
let dev_deps = if build_dev_deps {
372+
config.bs_dev_dependencies.as_ref().unwrap_or(&vec![]).to_owned()
373+
} else {
374+
vec![]
375+
};
376+
377+
let deps = [dev_deps, normal_deps]
376378
.concat()
377379
.par_iter()
378380
.map(|package_name| {
@@ -511,6 +513,7 @@ fn compile_file(
511513
packages: &AHashMap<String, packages::Package>,
512514
project_root: &str,
513515
workspace_root: &Option<String>,
516+
build_dev_deps: bool,
514517
) -> Result<Option<String>> {
515518
let build_path_abs = package.get_build_path();
516519
let implementation_file_path = match &module.source_type {
@@ -534,6 +537,7 @@ fn compile_file(
534537
project_root,
535538
workspace_root,
536539
&Some(packages),
540+
build_dev_deps,
537541
);
538542

539543
let to_mjs = Command::new(bsc_path)

src/build/packages.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -803,7 +803,7 @@ fn get_unallowed_dependents(
803803
struct UnallowedDependency {
804804
bs_deps: Vec<String>,
805805
pinned_deps: Vec<String>,
806-
bs_dev_deps: Vec<String>,
806+
bs_build_dev_deps: Vec<String>,
807807
}
808808

809809
pub fn validate_packages_dependencies(packages: &AHashMap<String, Package>) -> bool {
@@ -827,15 +827,15 @@ pub fn validate_packages_dependencies(packages: &AHashMap<String, Package>) -> b
827827
let empty_unallowed_deps = UnallowedDependency {
828828
bs_deps: vec![],
829829
pinned_deps: vec![],
830-
bs_dev_deps: vec![],
830+
bs_build_dev_deps: vec![],
831831
};
832832

833833
let unallowed_dependency = detected_unallowed_dependencies.entry(String::from(package_name));
834834
let value = unallowed_dependency.or_insert_with(|| empty_unallowed_deps);
835835
match *dependency_type {
836836
"bs-dependencies" => value.bs_deps.push(unallowed_dependency_name),
837837
"pinned-dependencies" => value.pinned_deps.push(unallowed_dependency_name),
838-
"bs-dev-dependencies" => value.bs_dev_deps.push(unallowed_dependency_name),
838+
"bs-dev-dependencies" => value.bs_build_dev_deps.push(unallowed_dependency_name),
839839
_ => (),
840840
}
841841
}
@@ -851,7 +851,7 @@ pub fn validate_packages_dependencies(packages: &AHashMap<String, Package>) -> b
851851
[
852852
("bs-dependencies", unallowed_deps.bs_deps.to_owned()),
853853
("pinned-dependencies", unallowed_deps.pinned_deps.to_owned()),
854-
("bs-dev-dependencies", unallowed_deps.bs_dev_deps.to_owned()),
854+
("bs-dev-dependencies", unallowed_deps.bs_build_dev_deps.to_owned()),
855855
]
856856
.iter()
857857
.for_each(|(deps_type, map)| {
@@ -887,7 +887,7 @@ mod test {
887887
name: String,
888888
bs_deps: Vec<String>,
889889
pinned_deps: Vec<String>,
890-
dev_deps: Vec<String>,
890+
build_dev_deps: Vec<String>,
891891
allowed_dependents: Option<Vec<String>>,
892892
) -> Package {
893893
Package {
@@ -902,7 +902,7 @@ mod test {
902902
suffix: None,
903903
pinned_dependencies: Some(pinned_deps),
904904
bs_dependencies: Some(bs_deps),
905-
bs_dev_dependencies: Some(dev_deps),
905+
bs_dev_dependencies: Some(build_dev_deps),
906906
ppx_flags: None,
907907
bsc_flags: None,
908908
reason: None,

src/main.rs

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,29 +41,36 @@ struct Args {
4141
#[arg(short, long)]
4242
after_build: Option<String>,
4343

44-
#[arg(short, long)]
45-
no_timing: Option<bool>,
44+
#[arg(short, long, default_value = "false")]
45+
no_timing: bool,
4646

4747
/// Verbosity:
4848
/// -v -> Debug
4949
/// -vv -> Trace
5050
/// -q -> Warn
51-
/// -qq -> Error
52-
/// -qqq -> Off.
51+
/// -qq -> Error
52+
/// -qqq -> Off.
5353
/// Default (/ no argument given): 'info'
5454
#[command(flatten)]
5555
verbose: clap_verbosity_flag::Verbosity<InfoLevel>,
5656

5757
/// This creates a source_dirs.json file at the root of the monorepo, which is needed when you
5858
/// want to use Reanalyze
59-
#[arg(short, long)]
60-
create_sourcedirs: Option<bool>,
59+
#[arg(short, long, default_value = "false")]
60+
create_sourcedirs: bool,
6161

6262
/// This prints the compiler arguments. It expects the path to a rescript.json file.
6363
/// This also requires --bsc-path and --rescript-version to be present
6464
#[arg(long)]
6565
compiler_args: Option<String>,
6666

67+
/// This is the flag to also compile development dependencies
68+
/// It's important to know that we currently do not discern between project src, and
69+
/// dependencies. So enabling this flag will enable building _all_ development dependencies of
70+
/// _all_ packages
71+
#[arg(long, default_value = "false")]
72+
dev: bool,
73+
6774
/// To be used in conjunction with compiler_args
6875
#[arg(long)]
6976
rescript_version: Option<String>,
@@ -94,7 +101,7 @@ fn main() -> Result<()> {
94101
Some(path) => {
95102
println!(
96103
"{}",
97-
build::get_compiler_args(&path, args.rescript_version, args.bsc_path)?
104+
build::get_compiler_args(&path, args.rescript_version, args.bsc_path, args.dev)?
98105
);
99106
std::process::exit(0);
100107
}
@@ -116,9 +123,10 @@ fn main() -> Result<()> {
116123
&filter,
117124
&folder,
118125
show_progress,
119-
args.no_timing.unwrap_or(false),
120-
args.create_sourcedirs.unwrap_or(false),
126+
args.no_timing,
127+
args.create_sourcedirs,
121128
args.bsc_path,
129+
args.dev,
122130
) {
123131
Err(e) => {
124132
log::error!("{e}");
@@ -138,7 +146,8 @@ fn main() -> Result<()> {
138146
show_progress,
139147
&folder,
140148
args.after_build,
141-
args.create_sourcedirs.unwrap_or(false),
149+
args.create_sourcedirs,
150+
args.dev,
142151
);
143152

144153
Ok(())

src/watcher.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ async fn async_watch(
5353
filter: &Option<regex::Regex>,
5454
after_build: Option<String>,
5555
create_sourcedirs: bool,
56+
build_dev_deps: bool,
5657
) -> notify::Result<()> {
5758
let mut build_state =
5859
build::initialize_build(None, filter, show_progress, path, None).expect("Can't initialize build");
@@ -190,6 +191,7 @@ async fn async_watch(
190191
show_progress,
191192
!initial_build,
192193
create_sourcedirs,
194+
build_dev_deps,
193195
)
194196
.is_ok()
195197
{
@@ -221,6 +223,7 @@ async fn async_watch(
221223
show_progress,
222224
false,
223225
create_sourcedirs,
226+
build_dev_deps,
224227
);
225228
if let Some(a) = after_build.clone() {
226229
cmd::run(a)
@@ -255,6 +258,7 @@ pub fn start(
255258
folder: &str,
256259
after_build: Option<String>,
257260
create_sourcedirs: bool,
261+
build_dev_deps: bool,
258262
) {
259263
futures::executor::block_on(async {
260264
let queue = Arc::new(FifoQueue::<Result<Event, Error>>::new());
@@ -274,6 +278,7 @@ pub fn start(
274278
filter,
275279
after_build,
276280
create_sourcedirs,
281+
build_dev_deps,
277282
)
278283
.await
279284
{

0 commit comments

Comments
 (0)