Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes: #238
- Loading branch information
Showing
9 changed files
with
259 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{{#include ../../../tests/snapshots/help__remove.snap:8:}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
use async_trait::async_trait; | ||
use clap::Args; | ||
use miette::{IntoDiagnostic, Result}; | ||
use oro_pretty_json::Formatted; | ||
|
||
use crate::apply_args::ApplyArgs; | ||
use crate::commands::OroCommand; | ||
|
||
/// Removes one or more dependencies to the target package. | ||
#[derive(Debug, Args)] | ||
#[clap(visible_aliases(["rm"]))] | ||
pub struct RemoveCmd { | ||
/// Package names of dependencies to remove. These will be removed from | ||
/// all dependency types. | ||
#[arg(required = true)] | ||
names: Vec<String>, | ||
|
||
#[command(flatten)] | ||
apply: ApplyArgs, | ||
} | ||
|
||
#[async_trait] | ||
impl OroCommand for RemoveCmd { | ||
async fn execute(self) -> Result<()> { | ||
let mut manifest = oro_pretty_json::from_str( | ||
&async_std::fs::read_to_string(self.apply.root.join("package.json")) | ||
.await | ||
.into_diagnostic()?, | ||
) | ||
.into_diagnostic()?; | ||
let mut count = 0; | ||
for name in &self.names { | ||
count += self.remove_from_manifest(&mut manifest, name); | ||
} | ||
|
||
async_std::fs::write( | ||
self.apply.root.join("package.json"), | ||
oro_pretty_json::to_string_pretty(&manifest).into_diagnostic()?, | ||
) | ||
.await | ||
.into_diagnostic()?; | ||
|
||
tracing::info!( | ||
"{}Removed {count} dependencies from package.json.", | ||
if self.apply.emoji { "📝 " } else { "" }, | ||
); | ||
|
||
// TODO: Force locked = false here, once --locked is supported. | ||
// Using `oro remove` with `--locked` doesn't make sense. | ||
// self.apply.locked = false; | ||
|
||
// Then, we apply the change. | ||
self.apply.execute().await | ||
} | ||
} | ||
|
||
impl RemoveCmd { | ||
fn remove_from_manifest(&self, mani: &mut Formatted, name: &str) -> usize { | ||
let mut count = 0; | ||
for ty in [ | ||
"dependencies", | ||
"devDependencies", | ||
"optionalDependencies", | ||
"peerDependencies", | ||
] { | ||
if mani.value[ty].is_object() { | ||
if let Some(obj) = mani.value[ty].as_object_mut() { | ||
if obj.contains_key(name) { | ||
tracing::debug!( | ||
"Removing {name}@{} from {ty}.", | ||
obj[name].as_str().unwrap_or("") | ||
); | ||
obj.remove(name); | ||
count += 1; | ||
} | ||
} | ||
} | ||
} | ||
count | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
--- | ||
source: tests/help.rs | ||
expression: "sub_md(\"remove\")" | ||
--- | ||
stderr: | ||
|
||
stdout: | ||
# oro remove | ||
|
||
Removes one or more dependencies to the target package | ||
|
||
### Usage: | ||
|
||
``` | ||
oro remove [OPTIONS] <NAMES>... | ||
``` | ||
[alias: rm] | ||
### Arguments | ||
#### `<NAMES>...` | ||
Package names of dependencies to remove. These will be removed from all dependency types | ||
### Options | ||
#### `-h, --help` | ||
Print help (see a summary with '-h') | ||
#### `-V, --version` | ||
Print version | ||
### Apply Options | ||
#### `--no-apply` | ||
Prevent all apply operations from executing | ||
#### `--prefer-copy` | ||
When extracting packages, prefer to copy files files instead of linking them. | ||
This option has no effect if hard linking fails (for example, if the cache is on a different drive), or if the project is on a filesystem that supports Copy-on-Write (zfs, btrfs, APFS (macOS), etc). | ||
#### `--validate` | ||
Validate the integrity of installed files. | ||
When this is true, orogene will verify all files extracted from the cache, as well as verify that any files in the existing `node_modules` are unmodified. If verification fails, the packages will be reinstalled. | ||
#### `--lockfile-only` | ||
Whether to skip restoring packages into `node_modules` and just resolve the tree and write the lockfile | ||
#### `--no-scripts` | ||
Skip running install scripts | ||
#### `--default-tag <DEFAULT_TAG>` | ||
Default dist-tag to use when resolving package versions | ||
\[default: latest] | ||
#### `--concurrency <CONCURRENCY>` | ||
Controls number of concurrent operations during various apply steps (resolution fetches, extractions, etc). | ||
Tuning this might help reduce memory usage (if lowered), or improve performance (if increased). | ||
\[default: 50] | ||
#### `--script-concurrency <SCRIPT_CONCURRENCY>` | ||
Controls number of concurrent script executions while running `run_script`. | ||
This option is separate from `concurrency` because executing concurrent scripts is a much heavier operation. | ||
\[default: 6] | ||
#### `--no-lockfile` | ||
Disable writing the lockfile after operations complete. | ||
Note that lockfiles are only written after all operations complete successfully. | ||
#### `--hoisted` | ||
Use the hoisted installation mode, where all dependencies and their transitive dependencies are installed as high up in the `node_modules` tree as possible. | ||
This can potentially mean that packages have access to dependencies they did not specify in their package.json, but it might be useful for compatibility. | ||
By default, dependencies are installed in "isolated" mode, using a symlink/junction structure to simulate a dependency tree. | ||
### Global Options | ||
#### `--root <ROOT>` | ||
Path to the project to operate on. | ||
By default, Orogene will look up from the current working directory until it finds a directory with a `package.json` file or a `node_modules/` directory. | ||
\[default: .] | ||
#### `--registry <REGISTRY>` | ||
Registry used for unscoped packages | ||
\[default: https://registry.npmjs.org] | ||
#### `--scoped-registry <SCOPED_REGISTRIES>` | ||
Registry to use for a specific `@scope`, using `--scoped-registry @scope=https://foo.com` format. | ||
Can be provided multiple times to specify multiple scoped registries. | ||
#### `--cache <CACHE>` | ||
Location of disk cache. | ||
Default location varies by platform. | ||
#### `--config <CONFIG>` | ||
File to read configuration values from. | ||
When specified, global configuration loading is disabled and configuration values will only be read from this location. | ||
#### `--loglevel <LOGLEVEL>` | ||
Log output level/directive. | ||
Supports plain loglevels (off, error, warn, info, debug, trace) as well as more advanced directives in the format `target[span{field=value}]=level`. | ||
\[default: info] | ||
#### `-q, --quiet` | ||
Disable all output | ||
#### `--json` | ||
Format output as JSON | ||
#### `--no-progress` | ||
Disable the progress bars | ||
#### `--no-emoji` | ||
Disable printing emoji. | ||
By default, this will show emoji when outputting to a TTY that supports unicode. | ||