这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
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
31 changes: 31 additions & 0 deletions crates/turborepo-lockfiles/fixtures/pnpm-inject-workspace.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
lockfileVersion: "9.0"

settings:
autoInstallPeers: true
excludeLinksFromLockfile: false
injectWorkspacePackages: true

importers:
.:
devDependencies:
prettier:
specifier: ^3.5.3
version: 3.5.3

apps/web:
dependencies:
lodash:
specifier: ^4.17.21
version: 4.17.21

packages:
/lodash@4.17.21:
resolution:
integrity: sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==

/prettier@3.5.3:
resolution:
integrity: sha512-e/BBvVnJaW3c/+vgULvKzeXo8LBbFhIF8MkHl1q2L6MvfjSXRIHW5xBM7U2m9GH9A+3keuLDolOgzL4u2p3Mw==
engines: {node: '>=14'}
hasBin: true
dev: true
66 changes: 66 additions & 0 deletions crates/turborepo-lockfiles/src/pnpm/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ pub struct PackageResolution {
struct LockfileSettings {
auto_install_peers: Option<bool>,
exclude_links_from_lockfile: Option<bool>,
inject_workspace_packages: Option<bool>,
}

impl PnpmLockfile {
Expand Down Expand Up @@ -649,6 +650,8 @@ mod tests {
const PNPM6_TURBO: &[u8] = include_bytes!("../../fixtures/pnpm6turbo.yaml").as_slice();
const PNPM8_TURBO: &[u8] = include_bytes!("../../fixtures/pnpm8turbo.yaml").as_slice();
const PNPM10_PATCH: &[u8] = include_bytes!("../../fixtures/pnpm-10-patch.lock").as_slice();
const PNPM_INJECT_WORKSPACE: &[u8] =
include_bytes!("../../fixtures/pnpm-inject-workspace.yaml").as_slice();

use super::*;
use crate::{Lockfile, Package};
Expand Down Expand Up @@ -1562,4 +1565,67 @@ c:
.unwrap();
assert!(workspace_dep.is_none());
}

#[test]
fn test_inject_workspace_packages_preservation() {
let lockfile = PnpmLockfile::from_bytes(PNPM_INJECT_WORKSPACE).unwrap();

// Verify the original lockfile has injectWorkspacePackages set to true
assert_eq!(
lockfile
.settings
.as_ref()
.unwrap()
.inject_workspace_packages,
Some(true)
);

// Create a subgraph to simulate turbo prune operation
let pruned_lockfile = lockfile
.subgraph(
&["apps/web".into()],
&["/lodash@4.17.21".into(), "/prettier@3.5.3".into()],
)
.unwrap();

// Downcast to access the settings
let pruned_pnpm = (pruned_lockfile.as_ref() as &dyn Any)
.downcast_ref::<PnpmLockfile>()
.unwrap();

// Verify that injectWorkspacePackages is preserved in the pruned lockfile
assert_eq!(
pruned_pnpm
.settings
.as_ref()
.unwrap()
.inject_workspace_packages,
Some(true),
"injectWorkspacePackages setting should be preserved in pruned lockfile"
);

// Verify other settings are also preserved
assert_eq!(
pruned_pnpm.settings.as_ref().unwrap().auto_install_peers,
Some(true)
);
assert_eq!(
pruned_pnpm
.settings
.as_ref()
.unwrap()
.exclude_links_from_lockfile,
Some(false)
);

// Verify that the pruned lockfile can be encoded back to YAML
let encoded = pruned_lockfile.encode().unwrap();
let encoded_str = String::from_utf8(encoded).unwrap();

// Verify the encoded YAML contains the injectWorkspacePackages setting
assert!(
encoded_str.contains("injectWorkspacePackages: true"),
"Encoded lockfile should contain injectWorkspacePackages setting"
);
}
}
Loading