Skip to content

Commit b75ede0

Browse files
committed
got yarn PnP working + tested for unix
1 parent 67efa91 commit b75ede0

File tree

12 files changed

+476
-34
lines changed

12 files changed

+476
-34
lines changed

crates/volta-core/fixtures/plug-n-play/pnp-cjs/.pnp.cjs

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "plug-n-play-cjs",
3+
"version": "2.0.0",
4+
"description": "Testing that Plug-n-Play things work",
5+
"license": "To Ill",
6+
"volta": {
7+
"node": "6.11.1",
8+
"npm": "3.10.10",
9+
"yarn": "3.2.0"
10+
}
11+
}

crates/volta-core/fixtures/plug-n-play/pnp-js/.pnp.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "plug-n-play-js",
3+
"version": "2.0.0",
4+
"description": "Testing that Plug-n-Play things work",
5+
"license": "To Ill",
6+
"volta": {
7+
"node": "6.11.1",
8+
"npm": "3.10.10",
9+
"yarn": "2.4.0"
10+
}
11+
}

crates/volta-core/src/project/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,14 @@ impl Project {
171171
})
172172
}
173173

174+
/// Does this project use Plug-n-Play?
175+
// (Do either of the files '.pnp.js' or '.pnp.cjs' exist?)
176+
pub fn is_plug_n_play(&self) -> bool {
177+
self.manifest_file.parent().map_or(false, |base_dir| {
178+
base_dir.join(".pnp.js").exists() || base_dir.join(".pnp.cjs").exists()
179+
})
180+
}
181+
174182
/// Pins the Node version in this project's manifest file
175183
pub fn pin_node(&mut self, version: Version) -> Fallible<()> {
176184
update_manifest(&self.manifest_file, ManifestKey::Node, Some(&version))?;

crates/volta-core/src/project/tests.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,3 +217,28 @@ mod project {
217217
}
218218
}
219219
}
220+
221+
mod plug_n_play {
222+
use super::*;
223+
224+
#[test]
225+
fn project_is_not_pnp() {
226+
let project_path = fixture_path(&["basic"]);
227+
let test_project = Project::for_dir(project_path).unwrap().unwrap();
228+
assert_eq!(test_project.is_plug_n_play(), false);
229+
}
230+
231+
#[test]
232+
fn project_has_pnp_js() {
233+
let project_path = fixture_path(&["plug-n-play", "pnp-js"]);
234+
let test_project = Project::for_dir(project_path).unwrap().unwrap();
235+
assert_eq!(test_project.is_plug_n_play(), true);
236+
}
237+
238+
#[test]
239+
fn project_has_pnp_cjs() {
240+
let project_path = fixture_path(&["plug-n-play", "pnp-cjs"]);
241+
let test_project = Project::for_dir(project_path).unwrap().unwrap();
242+
assert_eq!(test_project.is_plug_n_play(), true);
243+
}
244+
}

crates/volta-core/src/run/binary.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,17 @@ pub(super) fn command(exe: &OsStr, args: &[OsString], session: &mut Session) ->
2020
if let Some(project) = session.project()? {
2121
// Check if the executable is a direct dependency
2222
if project.has_direct_bin(exe)? {
23+
if project
24+
.platform()
25+
.map_or(false, |platform| platform.yarn.is_some())
26+
&& project.is_plug_n_play()
27+
{
28+
debug!("Project uses Yarn PnP, calling {} with 'yarn'", bin);
29+
let platform = Platform::current(session)?;
30+
let mut exe_and_args = vec![exe.to_os_string()];
31+
exe_and_args.extend_from_slice(args);
32+
return Ok(ToolCommand::new("yarn", exe_and_args, platform, ToolKind::Yarn).into());
33+
}
2334
let path_to_bin =
2435
project
2536
.find_bin(exe)

tests/acceptance/direct_uninstall.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ fn npm_uninstall_uses_volta_logic() {
121121
.binary_config("cowthink", &bin_config("cowthink", "cowsay"))
122122
.shim("cowsay")
123123
.shim("cowthink")
124-
.package_image("cowsay", "1.4.0")
124+
.package_image("cowsay", "1.4.0", None)
125125
.env("VOLTA_LOGLEVEL", "info")
126126
.build();
127127

@@ -141,7 +141,7 @@ fn npm_uninstall_uses_volta_logic() {
141141
assert!(!Sandbox::bin_config_exists("cowthink"));
142142
assert!(!Sandbox::shim_exists("cowsay"));
143143
assert!(!Sandbox::shim_exists("cowthink"));
144-
assert!(!Sandbox::package_image_exists("cowsay", "1.4.0"));
144+
assert!(!Sandbox::package_image_exists("cowsay"));
145145
}
146146

147147
#[test]
@@ -153,13 +153,13 @@ fn npm_uninstall_supports_multiples() {
153153
.binary_config("cowthink", &bin_config("cowthink", "cowsay"))
154154
.shim("cowsay")
155155
.shim("cowthink")
156-
.package_image("cowsay", "1.4.0")
156+
.package_image("cowsay", "1.4.0", None)
157157
.package_config("typescript", PKG_CONFIG_TYPESCRIPT)
158158
.binary_config("tsc", &bin_config("tsc", "typescript"))
159159
.binary_config("tsserver", &bin_config("tsserver", "typescript"))
160160
.shim("tsc")
161161
.shim("tsserver")
162-
.package_image("typescript", "1.4.0")
162+
.package_image("typescript", "1.4.0", None)
163163
.env("VOLTA_LOGLEVEL", "info")
164164
.build();
165165

@@ -183,14 +183,14 @@ fn npm_uninstall_supports_multiples() {
183183
assert!(!Sandbox::bin_config_exists("cowthink"));
184184
assert!(!Sandbox::shim_exists("cowsay"));
185185
assert!(!Sandbox::shim_exists("cowthink"));
186-
assert!(!Sandbox::package_image_exists("cowsay", "1.4.0"));
186+
assert!(!Sandbox::package_image_exists("cowsay"));
187187

188188
assert!(!Sandbox::package_config_exists("typescript"));
189189
assert!(!Sandbox::bin_config_exists("tsc"));
190190
assert!(!Sandbox::bin_config_exists("tsserver"));
191191
assert!(!Sandbox::shim_exists("tsc"));
192192
assert!(!Sandbox::shim_exists("tsserver"));
193-
assert!(!Sandbox::package_image_exists("typescript", "1.4.0"));
193+
assert!(!Sandbox::package_image_exists("typescript"));
194194
}
195195

196196
#[test]
@@ -218,7 +218,7 @@ fn yarn_remove_uses_volta_logic() {
218218
.binary_config("cowthink", &bin_config("cowthink", "cowsay"))
219219
.shim("cowsay")
220220
.shim("cowthink")
221-
.package_image("cowsay", "1.4.0")
221+
.package_image("cowsay", "1.4.0", None)
222222
.env("VOLTA_LOGLEVEL", "info")
223223
.build();
224224

@@ -238,7 +238,7 @@ fn yarn_remove_uses_volta_logic() {
238238
assert!(!Sandbox::bin_config_exists("cowthink"));
239239
assert!(!Sandbox::shim_exists("cowsay"));
240240
assert!(!Sandbox::shim_exists("cowthink"));
241-
assert!(!Sandbox::package_image_exists("cowsay", "1.4.0"));
241+
assert!(!Sandbox::package_image_exists("cowsay"));
242242
}
243243

244244
#[test]
@@ -250,13 +250,13 @@ fn yarn_remove_supports_multiples() {
250250
.binary_config("cowthink", &bin_config("cowthink", "cowsay"))
251251
.shim("cowsay")
252252
.shim("cowthink")
253-
.package_image("cowsay", "1.4.0")
253+
.package_image("cowsay", "1.4.0", None)
254254
.package_config("typescript", PKG_CONFIG_TYPESCRIPT)
255255
.binary_config("tsc", &bin_config("tsc", "typescript"))
256256
.binary_config("tsserver", &bin_config("tsserver", "typescript"))
257257
.shim("tsc")
258258
.shim("tsserver")
259-
.package_image("typescript", "1.4.0")
259+
.package_image("typescript", "1.4.0", None)
260260
.env("VOLTA_LOGLEVEL", "info")
261261
.build();
262262

@@ -280,14 +280,14 @@ fn yarn_remove_supports_multiples() {
280280
assert!(!Sandbox::bin_config_exists("cowthink"));
281281
assert!(!Sandbox::shim_exists("cowsay"));
282282
assert!(!Sandbox::shim_exists("cowthink"));
283-
assert!(!Sandbox::package_image_exists("cowsay", "1.4.0"));
283+
assert!(!Sandbox::package_image_exists("cowsay"));
284284

285285
assert!(!Sandbox::package_config_exists("typescript"));
286286
assert!(!Sandbox::bin_config_exists("tsc"));
287287
assert!(!Sandbox::bin_config_exists("tsserver"));
288288
assert!(!Sandbox::shim_exists("tsc"));
289289
assert!(!Sandbox::shim_exists("tsserver"));
290-
assert!(!Sandbox::package_image_exists("typescript", "1.4.0"));
290+
assert!(!Sandbox::package_image_exists("typescript"));
291291
}
292292

293293
#[test]

0 commit comments

Comments
 (0)