Skip to content

Commit 9787385

Browse files
committed
Clean up implementation based on PR comments
1 parent e05b542 commit 9787385

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,8 @@ impl<'a> LinkArgs<'a> {
348348
pub fn executor(self, platform: Platform, project_name: Option<String>) -> Fallible<Executor> {
349349
if self.tools.is_empty() {
350350
// If no tools are specified, then this is a bare link command, linking the current
351-
// project as a global package. We treat this exactly like a global install
351+
// project as a global package. We treat this like a global install except we look up
352+
// the name from the current directory first.
352353
match project_name {
353354
Some(name) => PackageInstallCommand::for_npm_link(self.common_args, platform, name),
354355
None => PackageInstallCommand::new(self.common_args, platform, PackageManager::Npm),

crates/volta-core/src/tool/package/mod.rs

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub struct Package {
3535

3636
impl Package {
3737
pub fn new(name: String, version: VersionSpec) -> Fallible<Self> {
38-
let staging = setup_staging_directory(PackageManager::Npm, false /* needs_scope */)?;
38+
let staging = setup_staging_directory(PackageManager::Npm, NeedsScope::No)?;
3939

4040
Ok(Package {
4141
name,
@@ -123,6 +123,9 @@ impl Display for Package {
123123
///
124124
/// Provides methods to simplify installing into a staging directory and then moving that install
125125
/// into the proper location after it is complete.
126+
///
127+
/// Note: We don't always know the name of the package up-front, as the install could be from a
128+
/// tarball or a git coordinate. If we do know ahead of time, then we can skip looking it up
126129
pub struct DirectInstall {
127130
staging: TempDir,
128131
manager: PackageManager,
@@ -131,7 +134,7 @@ pub struct DirectInstall {
131134

132135
impl DirectInstall {
133136
pub fn new(manager: PackageManager) -> Fallible<Self> {
134-
let staging = setup_staging_directory(manager, false /* needs_scope */)?;
137+
let staging = setup_staging_directory(manager, NeedsScope::No)?;
135138

136139
Ok(DirectInstall {
137140
staging,
@@ -141,7 +144,7 @@ impl DirectInstall {
141144
}
142145

143146
pub fn with_name(manager: PackageManager, name: String) -> Fallible<Self> {
144-
let staging = setup_staging_directory(manager, name.contains('/'))?;
147+
let staging = setup_staging_directory(manager, name.contains('/').into())?;
145148

146149
Ok(DirectInstall {
147150
staging,
@@ -228,9 +231,25 @@ impl InPlaceUpgrade {
228231
}
229232
}
230233

234+
#[derive(Clone, Copy, PartialEq)]
235+
enum NeedsScope {
236+
Yes,
237+
No,
238+
}
239+
240+
impl From<bool> for NeedsScope {
241+
fn from(value: bool) -> Self {
242+
if value {
243+
NeedsScope::Yes
244+
} else {
245+
NeedsScope::No
246+
}
247+
}
248+
}
249+
231250
/// Create the temporary staging directory we will use to install and ensure expected
232251
/// subdirectories exist within it
233-
fn setup_staging_directory(manager: PackageManager, needs_scope: bool) -> Fallible<TempDir> {
252+
fn setup_staging_directory(manager: PackageManager, needs_scope: NeedsScope) -> Fallible<TempDir> {
234253
// Workaround to ensure relative symlinks continue to work.
235254
// The final installed location of packages is:
236255
// $VOLTA_HOME/tools/image/packages/{name}/
@@ -243,7 +262,7 @@ fn setup_staging_directory(manager: PackageManager, needs_scope: bool) -> Fallib
243262
let mut staging_root = volta_home()?.tmp_dir().to_owned();
244263
staging_root.push("image");
245264
staging_root.push("packages");
246-
if needs_scope {
265+
if needs_scope == NeedsScope::Yes {
247266
staging_root.push("scope");
248267
}
249268
create_dir_all(&staging_root).with_context(|| ErrorKind::ContainingDirError {

0 commit comments

Comments
 (0)