-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: require packageManager in package.json (#8017)
### Description With 2.0 we will now be requiring a `packageManager` field in `package.json` as this is a best practice and it helps us behave in a deterministic manner. The actual code change is very straightforward as we remove our package manager inference code and return an error if reading package manager from `package.json` fails. Most of the PR is updating tests. ### Testing Instructions Updated unit tests
- Loading branch information
1 parent
d893fde
commit f8bea45
Showing
20 changed files
with
99 additions
and
419 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1 @@ | ||
use turbopath::AbsoluteSystemPath; | ||
|
||
use crate::package_manager::{Error, PackageManager}; | ||
|
||
pub const LOCKFILE: &str = "bun.lockb"; | ||
|
||
pub struct BunDetector<'a> { | ||
repo_root: &'a AbsoluteSystemPath, | ||
found: bool, | ||
} | ||
|
||
impl<'a> BunDetector<'a> { | ||
pub fn new(repo_root: &'a AbsoluteSystemPath) -> Self { | ||
Self { | ||
repo_root, | ||
found: false, | ||
} | ||
} | ||
} | ||
|
||
impl<'a> Iterator for BunDetector<'a> { | ||
type Item = Result<PackageManager, Error>; | ||
|
||
fn next(&mut self) -> Option<Self::Item> { | ||
if self.found { | ||
return None; | ||
} | ||
|
||
self.found = true; | ||
let package_json = self.repo_root.join_component(LOCKFILE); | ||
|
||
if package_json.exists() { | ||
Some(Ok(PackageManager::Bun)) | ||
} else { | ||
None | ||
} | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use std::fs::File; | ||
|
||
use anyhow::Result; | ||
use tempfile::tempdir; | ||
use turbopath::AbsoluteSystemPathBuf; | ||
|
||
use super::LOCKFILE; | ||
use crate::package_manager::PackageManager; | ||
|
||
#[test] | ||
fn test_detect_bun() -> Result<()> { | ||
let repo_root = tempdir()?; | ||
let repo_root_path = AbsoluteSystemPathBuf::try_from(repo_root.path())?; | ||
|
||
let lockfile_path = repo_root.path().join(LOCKFILE); | ||
File::create(lockfile_path)?; | ||
let package_manager = PackageManager::detect_package_manager(&repo_root_path)?; | ||
assert_eq!(package_manager, PackageManager::Bun); | ||
|
||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.