Skip to content

Commit 0882238

Browse files
authored
Compile dev deps (#159)
1 parent 1a9e894 commit 0882238

23 files changed

+165
-34
lines changed

src/build.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ pub fn initialize_build(
134134
show_progress: bool,
135135
path: &str,
136136
bsc_path: Option<String>,
137+
build_dev_deps: bool,
137138
) -> Result<BuildState> {
138139
let project_root = helpers::get_abs_path(path);
139140
let workspace_root = helpers::get_workspace_root(&project_root);
@@ -150,7 +151,13 @@ pub fn initialize_build(
150151
}
151152

152153
let timing_package_tree = Instant::now();
153-
let packages = packages::make(filter, &project_root, &workspace_root, show_progress)?;
154+
let packages = packages::make(
155+
filter,
156+
&project_root,
157+
&workspace_root,
158+
show_progress,
159+
build_dev_deps,
160+
)?;
154161
let timing_package_tree_elapsed = timing_package_tree.elapsed();
155162

156163
if show_progress {
@@ -476,8 +483,15 @@ pub fn build(
476483
None
477484
};
478485
let timing_total = Instant::now();
479-
let mut build_state = initialize_build(default_timing, filter, show_progress, path, bsc_path)
480-
.map_err(|e| anyhow!("Could not initialize build. Error: {e}"))?;
486+
let mut build_state = initialize_build(
487+
default_timing,
488+
filter,
489+
show_progress,
490+
path,
491+
bsc_path,
492+
build_dev_deps,
493+
)
494+
.map_err(|e| anyhow!("Could not initialize build. Error: {e}"))?;
481495

482496
match incremental_build(
483497
&mut build_state,

src/build/clean.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,14 @@ pub fn cleanup_after_build(build_state: &BuildState) {
326326
pub fn clean(path: &str, show_progress: bool, bsc_path: Option<String>) -> Result<()> {
327327
let project_root = helpers::get_abs_path(path);
328328
let workspace_root = helpers::get_workspace_root(&project_root);
329-
let packages = packages::make(&None, &project_root, &workspace_root, show_progress)?;
329+
let packages = packages::make(
330+
&None,
331+
&project_root,
332+
&workspace_root,
333+
show_progress,
334+
// Always clean dev dependencies
335+
true,
336+
)?;
330337
let root_config_name = packages::read_package_name(&project_root)?;
331338
let bsc_path = match bsc_path {
332339
Some(bsc_path) => bsc_path,

src/build/compile.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ pub fn compile(
148148
"cmi",
149149
);
150150

151-
let cmi_digest = helpers::compute_file_hash(&Path::new(&cmi_path));
151+
let cmi_digest = helpers::compute_file_hash(Path::new(&cmi_path));
152152

153153
let package = build_state
154154
.get_package(&module.package_name)
@@ -189,7 +189,7 @@ pub fn compile(
189189
&build_state.workspace_root,
190190
build_dev_deps,
191191
);
192-
let cmi_digest_after = helpers::compute_file_hash(&Path::new(&cmi_path));
192+
let cmi_digest_after = helpers::compute_file_hash(Path::new(&cmi_path));
193193

194194
// we want to compare both the hash of interface and the implementation
195195
// compile assets to verify that nothing changed. We also need to checke the interface
@@ -326,7 +326,7 @@ pub fn compile(
326326
if files_total_count == compile_universe_count {
327327
break;
328328
}
329-
if in_progress_modules.len() == 0 || in_progress_modules.eq(&current_in_progres_modules) {
329+
if in_progress_modules.is_empty() || in_progress_modules.eq(&current_in_progres_modules) {
330330
// find the dependency cycle
331331
let cycle = dependency_cycle::find(
332332
&compile_universe

src/build/packages.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,7 @@ pub fn get_source_files(
480480
package_dir: &Path,
481481
filter: &Option<regex::Regex>,
482482
source: &config::PackageSource,
483+
build_dev_deps: bool,
483484
) -> AHashMap<String, SourceFileMeta> {
484485
let mut map: AHashMap<String, SourceFileMeta> = AHashMap::new();
485486

@@ -493,16 +494,9 @@ pub fn get_source_files(
493494
};
494495

495496
let path_dir = Path::new(&source.dir);
496-
// don't include dev sources for now
497-
if type_ != &Some("dev".to_string()) {
497+
if (build_dev_deps && type_ == &Some("dev".to_string())) || type_ != &Some("dev".to_string()) {
498498
match read_folders(filter, package_dir, path_dir, recurse) {
499499
Ok(files) => map.extend(files),
500-
// Err(_e) if type_ == &Some("dev".to_string()) => {
501-
// log::warn!(
502-
// "Could not read folder: {}... Probably ok as type is dev",
503-
// path_dir.to_string_lossy()
504-
// )
505-
// }
506500
Err(_e) => log::error!(
507501
"Could not read folder: {:?}. Specified in dependency: {}, located {:?}...",
508502
path_dir.to_path_buf().into_os_string(),
@@ -520,13 +514,22 @@ pub fn get_source_files(
520514
fn extend_with_children(
521515
filter: &Option<regex::Regex>,
522516
mut build: AHashMap<String, Package>,
517+
build_dev_deps: bool,
523518
) -> AHashMap<String, Package> {
524519
for (_key, package) in build.iter_mut() {
525520
let mut map: AHashMap<String, SourceFileMeta> = AHashMap::new();
526521
package
527522
.source_folders
528523
.par_iter()
529-
.map(|source| get_source_files(&package.name, Path::new(&package.path), filter, source))
524+
.map(|source| {
525+
get_source_files(
526+
&package.name,
527+
Path::new(&package.path),
528+
filter,
529+
source,
530+
build_dev_deps,
531+
)
532+
})
530533
.collect::<Vec<AHashMap<String, SourceFileMeta>>>()
531534
.into_iter()
532535
.for_each(|source| map.extend(source));
@@ -568,12 +571,13 @@ pub fn make(
568571
root_folder: &str,
569572
workspace_root: &Option<String>,
570573
show_progress: bool,
574+
build_dev_deps: bool,
571575
) -> Result<AHashMap<String, Package>> {
572576
let map = read_packages(root_folder, workspace_root.to_owned(), show_progress)?;
573577

574578
/* Once we have the deduplicated packages, we can add the source files for each - to minimize
575579
* the IO */
576-
let result = extend_with_children(filter, map);
580+
let result = extend_with_children(filter, map, build_dev_deps);
577581

578582
Ok(result)
579583
}

src/config.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,40 @@ mod tests {
505505
}
506506
}
507507

508+
#[test]
509+
fn test_dev_sources_multiple() {
510+
let json = r#"
511+
{
512+
"name": "@rescript/core",
513+
"version": "0.5.0",
514+
"sources": [
515+
{ "dir": "src" },
516+
{ "dir": "test", "type": "dev" }
517+
],
518+
"package-specs": {
519+
"module": "esmodule",
520+
"in-source": true
521+
},
522+
"bs-dev-dependencies": ["@rescript/tools"],
523+
"suffix": ".mjs",
524+
"warnings": {
525+
"error": "+101"
526+
}
527+
}
528+
"#;
529+
530+
let config = serde_json::from_str::<Config>(json).unwrap();
531+
if let Some(OneOrMore::Multiple(sources)) = config.sources {
532+
let src_dir = sources[0].to_qualified_without_children(None);
533+
let test_dir = sources[1].to_qualified_without_children(None);
534+
535+
assert_eq!(test_dir.type_, Some(String::from("dev")));
536+
} else {
537+
dbg!(config.sources);
538+
unreachable!()
539+
}
540+
}
541+
508542
#[test]
509543
fn test_detect_gentypeconfig() {
510544
let json = r#"

src/watcher.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ async fn async_watch(
5555
create_sourcedirs: bool,
5656
build_dev_deps: bool,
5757
) -> notify::Result<()> {
58-
let mut build_state =
59-
build::initialize_build(None, filter, show_progress, path, None).expect("Can't initialize build");
58+
let mut build_state = build::initialize_build(None, filter, show_progress, path, None, build_dev_deps)
59+
.expect("Can't initialize build");
6060
let mut needs_compile_type = CompileType::Incremental;
6161
// create a mutex to capture if ctrl-c was pressed
6262
let ctrlc_pressed = Arc::new(Mutex::new(false));
@@ -214,8 +214,9 @@ async fn async_watch(
214214
}
215215
CompileType::Full => {
216216
let timing_total = Instant::now();
217-
build_state = build::initialize_build(None, filter, show_progress, path, None)
218-
.expect("Can't initialize build");
217+
build_state =
218+
build::initialize_build(None, filter, show_progress, path, None, build_dev_deps)
219+
.expect("Can't initialize build");
219220
let _ = build::incremental_build(
220221
&mut build_state,
221222
None,

testrepo/bsconfig.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,16 @@
1919
"@testrepo/dep01",
2020
"@testrepo/dep02",
2121
"@testrepo/new-namespace",
22-
"@testrepo/namespace-casing"
23-
22+
"@testrepo/namespace-casing",
23+
"@testrepo/with-dev-deps"
2424
],
2525
"bs-dependencies": [
2626
"@testrepo/main",
2727
"@testrepo/dep01",
2828
"@testrepo/dep02",
2929
"@testrepo/new-namespace",
30-
"@testrepo/namespace-casing"
30+
"@testrepo/namespace-casing",
31+
"@testrepo/with-dev-deps"
3132
],
3233
"reason": {
3334
"react-jsx": 3

testrepo/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
"packages/dep01",
88
"packages/dep02",
99
"packages/new-namespace",
10-
"packages/namespace-casing"
10+
"packages/namespace-casing",
11+
"packages/with-dev-deps"
1112
]
1213
},
1314
"scripts": {
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "@testrepo/with-dev-deps",
3+
"version": "0.0.1",
4+
"keywords": [
5+
"rescript"
6+
],
7+
"author": "",
8+
"license": "MIT",
9+
"dependencies": {
10+
"rescript": "*"
11+
}
12+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "@testrepo/with-dev-deps",
3+
"sources": [
4+
{
5+
"dir": "src"
6+
},
7+
{
8+
"dir": "test",
9+
"type": "dev"
10+
}
11+
],
12+
"package-specs": {
13+
"module": "es6",
14+
"in-source": true
15+
},
16+
"suffix": ".res.js"
17+
}

0 commit comments

Comments
 (0)