Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#### :bug: Bug fix

- Fix error message that falsely suggested using coercion when it wouldn't work. https://github.com/rescript-lang/rescript/pull/7721
- Rewatch: don't compile dev-dependencies of non local dependencies with `--dev`. https://github.com/rescript-lang/rescript/pull/7736

# 12.0.0-beta.3

Expand Down
19 changes: 10 additions & 9 deletions rewatch/src/build/packages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ struct Dependency {
config: config::Config,
path: PathBuf,
dependencies: Vec<Dependency>,
is_local_dep: bool,
}

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -359,6 +360,10 @@ fn read_dependencies(
}
};

let is_local_dep = {
canonical_path.starts_with(project_root)
&& !canonical_path.components().any(|c| c.as_os_str() == "node_modules")
};

let dependencies = read_dependencies(
&mut registered_dependencies_set.to_owned(),
Expand All @@ -367,14 +372,15 @@ fn read_dependencies(
project_root,
workspace_root,
show_progress,
build_dev_deps,
is_local_dep && build_dev_deps,
);

Dependency {
name: package_name.to_owned(),
config,
path: canonical_path,
dependencies,
is_local_dep
}
})
.collect()
Expand Down Expand Up @@ -405,7 +411,7 @@ pub fn read_package_name(package_dir: &Path) -> Result<String> {
.ok_or_else(|| anyhow!("No name field found in package.json"))
}

fn make_package(config: config::Config, package_path: &Path, is_root: bool, project_root: &Path) -> Package {
fn make_package(config: config::Config, package_path: &Path, is_root: bool, is_local_dep: bool) -> Package {
let source_folders = match config.sources.to_owned() {
Some(config::OneOrMore::Single(source)) => get_source_dirs(source, None),
Some(config::OneOrMore::Multiple(sources)) => {
Expand Down Expand Up @@ -444,11 +450,6 @@ This inconsistency will cause issues with package resolution.\n",
);
}

let is_local_dep = {
package_path.starts_with(project_root)
&& !package_path.components().any(|c| c.as_os_str() == "node_modules")
};

Package {
name: package_name,
config: config.to_owned(),
Expand Down Expand Up @@ -477,7 +478,7 @@ fn read_packages(

// Store all packages and completely deduplicate them
let mut map: AHashMap<String, Package> = AHashMap::new();
let root_package = make_package(root_config.to_owned(), project_root, true, project_root);
let root_package = make_package(root_config.to_owned(), project_root, true, true);
map.insert(root_package.name.to_string(), root_package);

let mut registered_dependencies_set: AHashSet<String> = AHashSet::new();
Expand All @@ -492,7 +493,7 @@ fn read_packages(
));
dependencies.iter().for_each(|d| {
if !map.contains_key(&d.name) {
let package = make_package(d.config.to_owned(), &d.path, false, project_root);
let package = make_package(d.config.to_owned(), &d.path, false, d.is_local_dep);
map.insert(d.name.to_string(), package);
}
});
Expand Down
3 changes: 3 additions & 0 deletions rewatch/testrepo/packages/with-dev-deps/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,8 @@
"license": "MIT",
"devDependencies": {
"@rescript/webapi": "0.1.0-experimental-73e6a0d"
},
"dependencies": {
"rescript-nodejs": "16.1.0"
}
}
1 change: 1 addition & 0 deletions rewatch/testrepo/packages/with-dev-deps/rescript.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"type": "dev"
}
],
"dependencies": ["rescript-nodejs"],
"dev-dependencies": ["@rescript/webapi"],
"package-specs": {
"module": "es6",
Expand Down
8 changes: 8 additions & 0 deletions rewatch/testrepo/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,17 @@ __metadata:
resolution: "@testrepo/with-dev-deps@workspace:packages/with-dev-deps"
dependencies:
"@rescript/webapi": "npm:0.1.0-experimental-73e6a0d"
rescript-nodejs: "npm:16.1.0"
languageName: unknown
linkType: soft

"rescript-nodejs@npm:16.1.0":
version: 16.1.0
resolution: "rescript-nodejs@npm:16.1.0"
checksum: 10c0/2ea271dbddebdceec79bf5ee6089c15474f2c014cb22c1cc39d43ef27fd363fcb1cd8e1244d0cb998cd6b426d7474e3055e41277951fb01ee1eeecf68bbe01ab
languageName: node
linkType: hard

"rescript@npm:12.0.0-beta.1, rescript@npm:^12.0.0-alpha.13":
version: 12.0.0-beta.1
resolution: "rescript@npm:12.0.0-beta.1"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Cleaned 0/16
Cleaned 0/56
Parsed 2 source files
Compiled 2 modules

Expand Down
2 changes: 1 addition & 1 deletion rewatch/tests/snapshots/dependency-cycle.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Cleaned 0/16
Cleaned 0/56
Parsed 1 source files
Compiled 0 modules

Expand Down
2 changes: 1 addition & 1 deletion rewatch/tests/snapshots/remove-file.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Cleaned 1/16
Cleaned 1/56
Parsed 0 source files
Compiled 1 modules

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Cleaned 2/16
Cleaned 2/56
Parsed 2 source files
Compiled 3 modules

Expand Down
2 changes: 1 addition & 1 deletion rewatch/tests/snapshots/rename-file-internal-dep.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Cleaned 2/16
Cleaned 2/56
Parsed 2 source files
Compiled 2 modules

Expand Down
2 changes: 1 addition & 1 deletion rewatch/tests/snapshots/rename-file-with-interface.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
 No implementation file found for interface file (skipping): src/ModuleWithInterface.resi
Cleaned 2/16
Cleaned 2/56
Parsed 1 source files
Compiled 2 modules

Expand Down
2 changes: 1 addition & 1 deletion rewatch/tests/snapshots/rename-file.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Cleaned 1/16
Cleaned 1/56
Parsed 1 source files
Compiled 1 modules

Expand Down
2 changes: 1 addition & 1 deletion rewatch/tests/snapshots/rename-interface-file.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
 No implementation file found for interface file (skipping): src/ModuleWithInterface2.resi
Cleaned 1/16
Cleaned 1/56
Parsed 1 source files
Compiled 2 modules

Expand Down