Skip to content

Commit d82a5f6

Browse files
committed
Try to read dependency from the current package.
1 parent e92879e commit d82a5f6

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

rewatch/src/build/packages.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -250,13 +250,25 @@ pub fn read_config(package_dir: &Path) -> Result<Config> {
250250
}
251251
}
252252

253-
pub fn read_dependency(package_name: &str, project_context: &ProjectContext) -> Result<PathBuf, String> {
253+
pub fn read_dependency(package_name: &str, project_context: &ProjectContext) -> Result<PathBuf> {
254+
// current folder + node_modules + package_name
255+
let path_from_current_config = {
256+
match project_context.current_config.path.parent() {
257+
None => Err(anyhow!(
258+
"Expected {} to have a parent folder",
259+
project_context.current_config.path.to_string_lossy()
260+
)),
261+
Some(parent_path) => Ok(helpers::package_path(parent_path, package_name)),
262+
}
263+
}?;
254264
// root folder + node_modules + package_name
255265
let path_from_root = helpers::package_path(project_context.get_root_path(), package_name);
256-
let path = (if path_from_root.exists() {
266+
let path = (if path_from_current_config.exists() {
267+
Ok(path_from_current_config)
268+
} else if path_from_root.exists() {
257269
Ok(path_from_root)
258270
} else {
259-
Err(format!(
271+
Err(anyhow!(
260272
"The package \"{package_name}\" is not found (are node_modules up-to-date?)..."
261273
))
262274
})?;
@@ -266,7 +278,7 @@ pub fn read_dependency(package_name: &str, project_context: &ProjectContext) ->
266278
.map(StrippedVerbatimPath::to_stripped_verbatim_path)
267279
{
268280
Ok(canonical_path) => Ok(canonical_path),
269-
Err(e) => Err(format!(
281+
Err(e) => Err(anyhow!(
270282
"Failed canonicalizing the package \"{}\" path \"{}\" (are node_modules up-to-date?)...\nMore details: {}",
271283
package_name,
272284
path.to_string_lossy(),

0 commit comments

Comments
 (0)