Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: is dev for packages installed under npm and pnpm #9000

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
11 changes: 10 additions & 1 deletion crates/turborepo-lib/src/hash/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ impl From<LockFilePackages> for Builder<HeapAllocator> {

{
let mut packages_builder = builder.reborrow().init_packages(packages.len() as u32);
for (i, turborepo_lockfiles::Package { key, version }) in packages.iter().enumerate() {
for (i, turborepo_lockfiles::Package { key, version, .. }) in
packages.iter().enumerate()
{
let mut package = packages_builder.reborrow().get(i as u32);
package.set_key(key);
package.set_version(version);
Expand Down Expand Up @@ -441,24 +443,30 @@ mod test {
#[test_case(vec![Package {
key: "key".to_string(),
version: "version".to_string(),
is_dev: false,
}], "1b266409f3ae154e" ; "non-empty")]
#[test_case(vec![Package {
key: "key".to_string(),
version: "".to_string(),
is_dev: false,
}], "bde280722f61644a" ; "empty version")]
#[test_case(vec![Package {
key: "key".to_string(),
version: "version".to_string(),
is_dev: false,
}, Package {
key: "zey".to_string(),
version: "version".to_string(),
is_dev: false,
}], "6c0185544234b6dc" ; "multiple in-order")]
#[test_case(vec![Package {
key: "zey".to_string(),
version: "version".to_string(),
is_dev: false,
}, Package {
key: "key".to_string(),
version: "version".to_string(),
is_dev: false,
}], "26a67c9beeb0d16f" ; "care about order")]
fn lock_file_packages(vec: Vec<Package>, expected: &str) {
let packages = LockFilePackages(vec);
Expand All @@ -470,6 +478,7 @@ mod test {
let packages = (0..100).map(|i| Package {
key: format!("key{}", i),
version: format!("version{}", i),
is_dev: false,
});

lock_file_packages(packages.collect(), "4fd770c37194168e");
Expand Down
33 changes: 23 additions & 10 deletions crates/turborepo-lockfiles/src/berry/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,7 @@ impl Lockfile for BerryLockfile {
Ok(Some(crate::Package {
key: locator.to_string(),
version: package.version.clone(),
is_dev: false,
}))
}

Expand Down Expand Up @@ -641,7 +642,8 @@ mod test {
.unwrap(),
Some(Package {
key: "js-tokens@npm:4.0.0".into(),
version: "4.0.0".into()
version: "4.0.0".into(),
is_dev: false,
}),
);
assert_eq!(
Expand All @@ -650,7 +652,8 @@ mod test {
.unwrap(),
Some(Package {
key: "js-tokens@npm:4.0.0".into(),
version: "4.0.0".into()
version: "4.0.0".into(),
is_dev: false,
}),
);
assert_eq!(
Expand All @@ -659,7 +662,8 @@ mod test {
.unwrap(),
Some(Package {
key: "eslint-config-custom@workspace:packages/eslint-config-custom".into(),
version: "0.0.0-use.local".into()
version: "0.0.0-use.local".into(),
is_dev: false,
}),
);
assert_eq!(
Expand Down Expand Up @@ -790,7 +794,8 @@ mod test {

assert!(closure.contains(&Package {
key: "lodash@npm:4.17.21".into(),
version: "4.17.21".into()
version: "4.17.21".into(),
is_dev: false,
}));
}

Expand Down Expand Up @@ -818,7 +823,8 @@ mod test {
pkg,
Package {
key: "debug@npm:1.0.0".into(),
version: "1.0.0".into()
version: "1.0.0".into(),
is_dev: false,
}
);
}
Expand Down Expand Up @@ -862,7 +868,8 @@ mod test {
pkg,
Package {
key: "ms@npm:0.6.0".into(),
version: "0.6.0".into()
version: "0.6.0".into(),
is_dev: false,
}
);
}
Expand Down Expand Up @@ -898,11 +905,13 @@ mod test {

assert!(closure.contains(&Package {
key: "ajv@npm:8.11.2".into(),
version: "8.11.2".into()
version: "8.11.2".into(),
is_dev: false,
}));
assert!(closure.contains(&Package {
key: "uri-js@npm:4.4.1".into(),
version: "4.4.1".into()
version: "4.4.1".into(),
is_dev: false,
}));
}

Expand All @@ -927,6 +936,7 @@ mod test {
let expected = Package {
key: "react@npm:18.1.0".into(),
version: "18.1.0".into(),
is_dev: false,
};
assert_eq!(actual, expected,);

Expand Down Expand Up @@ -1061,6 +1071,7 @@ mod test {
crate::Package {
key: expected_key.into(),
version: "3.0.1".into(),
is_dev: false,
}
);

Expand All @@ -1083,11 +1094,13 @@ mod test {
vec![
crate::Package {
key: expected_key.into(),
version: "3.0.1".into()
version: "3.0.1".into(),
is_dev: false,
},
crate::Package {
key: "is-number@npm:6.0.0".into(),
version: "6.0.0".into()
version: "6.0.0".into(),
is_dev: false,
}
]
.into_iter()
Expand Down
1 change: 1 addition & 0 deletions crates/turborepo-lockfiles/src/bun/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ impl Lockfile for BunLockfile {
return Ok(Some(crate::Package {
key,
version: entry.version.clone(),
is_dev: false,
}));
}
}
Expand Down
8 changes: 7 additions & 1 deletion crates/turborepo-lockfiles/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pub use yarn1::{yarn_subgraph, Yarn1Lockfile};
pub struct Package {
pub key: String,
pub version: String,
pub is_dev: bool,
}

// This trait will only be used when migrating the Go lockfile implementations
Expand Down Expand Up @@ -156,6 +157,11 @@ impl Package {
pub fn new(key: impl Into<String>, version: impl Into<String>) -> Self {
let key = key.into();
let version = version.into();
Self { key, version }
let is_dev: bool = false;
Self {
key,
version,
is_dev,
}
}
}
26 changes: 21 additions & 5 deletions crates/turborepo-lockfiles/src/npm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub struct NpmLockfile {
struct NpmPackage {
version: Option<String>,
resolved: Option<String>,
dev: Option<bool>,
#[serde(default)]
dependencies: Map<String, String>,
#[serde(default)]
Expand Down Expand Up @@ -72,7 +73,12 @@ impl Lockfile for NpmLockfile {
.filter_map(|key| {
self.packages.get(&key).map(|pkg| {
let version = pkg.version.clone().unwrap_or_default();
Ok(Package { key, version })
let is_dev: bool = pkg.dev.clone().unwrap_or(false);
Ok(Package {
key,
version,
is_dev,
})
})
})
.next()
Expand Down Expand Up @@ -305,28 +311,37 @@ mod test {
fn test_resolve_package() -> Result<(), Error> {
let lockfile = NpmLockfile::load(include_bytes!("../fixtures/npm-lock.json"))?;
let tests = [
("", "turbo", "node_modules/turbo", "1.5.5"),
("", "turbo", "node_modules/turbo", "1.5.5", true),
(
"apps/web",
"lodash",
"apps/web/node_modules/lodash",
"4.17.21",
false,
),
(
"apps/docs",
"lodash",
"node_modules/lodash",
"3.10.1",
false,
),
("apps/docs", "lodash", "node_modules/lodash", "3.10.1"),
(
"apps/docs",
"node_modules/@babel/generator/node_modules/@jridgewell/gen-mapping",
"node_modules/@babel/generator/node_modules/@jridgewell/gen-mapping",
"0.3.2",
true,
),
];

for (workspace, name, key, version) in &tests {
for (workspace, name, key, version, is_dev) in &tests {
let pkg = lockfile.resolve_package(workspace, name, "")?;
assert!(pkg.is_some());
let pkg = pkg.unwrap();
assert_eq!(pkg.key, *key);
assert_eq!(pkg.version, *version);
assert_eq!(pkg.is_dev, *is_dev)
}

Ok(())
Expand Down Expand Up @@ -449,7 +464,8 @@ mod test {
)?;
assert!(closures.get("packages/a").unwrap().contains(&Package {
key: "node_modules/eslint-plugin-turbo".into(),
version: "1.9.3".into()
version: "1.9.3".into(),
is_dev: false,
}));
assert!(closures.get("packages/b").unwrap().is_empty());
assert!(closures.get("packages/c").unwrap().is_empty());
Expand Down
Loading
Loading