Skip to content

Commit 43b9c9a

Browse files
committed
add support for virtual-store-dir argument
1 parent e29da61 commit 43b9c9a

File tree

4 files changed

+15
-9
lines changed

4 files changed

+15
-9
lines changed

crates/cli/src/commands.rs

+4
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,8 @@ pub enum Subcommands {
2323
pub struct AddArgs {
2424
/// Name of the package
2525
pub package: String,
26+
/// The directory with links to the store (default is node_modules/.pacquet).
27+
/// All direct and indirect dependencies of the project are linked into this directory
28+
#[arg(long = "virtual-store-dir", default_value = "node_modules/.pacquet")]
29+
pub virtual_store_dir: String,
2630
}

crates/cli/src/lib.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ pub async fn run_commands() -> Result<()> {
1818
PackageJson::create()?;
1919
}
2020
Subcommands::Add(args) => {
21-
let mut registry_manager = RegistryManager::new(current_directory.join("node_modules"));
21+
let mut registry_manager = RegistryManager::new(
22+
current_directory.join("node_modules"),
23+
current_directory.join(&args.virtual_store_dir),
24+
);
2225
registry_manager.prepare()?;
2326
registry_manager.add_dependency(&args.package).await?;
2427
}

crates/registry/src/lib.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,11 @@ pub struct RegistryManager {
2323
}
2424

2525
impl RegistryManager {
26-
pub fn new<P: Into<PathBuf>>(path: P) -> RegistryManager {
27-
let path_into = path.into();
26+
pub fn new<P: Into<PathBuf>>(node_modules_path: P, store_path: P) -> RegistryManager {
2827
RegistryManager {
2928
client: Client::new(),
30-
node_modules_path: path_into.clone(),
31-
store_path: path_into.join(".pacquet"),
29+
node_modules_path: node_modules_path.into(),
30+
store_path: store_path.into(),
3231
}
3332
}
3433

@@ -49,6 +48,7 @@ impl RegistryManager {
4948
&latest_version.version,
5049
latest_version.get_tarball_url(),
5150
&self.node_modules_path,
51+
&self.store_path,
5252
&id,
5353
)
5454
.await?;
@@ -90,7 +90,7 @@ impl RegistryManager {
9090
&package.name,
9191
&package_version.version,
9292
package_version.get_tarball_url(),
93-
&self.node_modules_path,
93+
&self.store_path,
9494
&symlink_path.join(&package.name),
9595
)
9696
.await?;

crates/tarball/src/lib.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@ pub async fn download_direct_dependency(
5050
version: &str,
5151
url: &str,
5252
node_modules_path: &Path,
53+
store_path: &Path,
5354
// For example: fastify@1.1.0
5455
// For dependencies of fastify: fastify@1.1.0/node_modules/fastify
5556
package_identifier: &str,
5657
) -> Result<(), TarballError> {
5758
let store_folder_name = format!("{0}@{version}", normalize(name));
5859

59-
let store_path = node_modules_path.join(".pacquet");
6060
let tarball_path = store_path.join(format!("{store_folder_name}.tar.gz"));
6161
let package_path =
6262
store_path.join(normalize(package_identifier)).join("node_modules").join(name);
@@ -90,12 +90,11 @@ pub async fn download_indirect_dependency(
9090
name: &str,
9191
version: &str,
9292
url: &str,
93-
node_modules_path: &Path,
93+
store_path: &Path,
9494
symlink_to: &Path,
9595
) -> Result<(), TarballError> {
9696
let store_folder_name = format!("{0}@{version}", normalize(name));
9797

98-
let store_path = node_modules_path.join(".pacquet");
9998
let tarball_path = store_path.join(format!("{store_folder_name}.tar.gz"));
10099
let package_path = store_path.join(&store_folder_name).join("node_modules").join(name);
101100

0 commit comments

Comments
 (0)