Skip to content

Commit

Permalink
feat(apply): rename restore to apply
Browse files Browse the repository at this point in the history
Fixes: #227
  • Loading branch information
zkat committed Apr 10, 2023
1 parent 9da2e1e commit 82f7b62
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 30 deletions.
12 changes: 6 additions & 6 deletions CONTRIBUTING.md
Expand Up @@ -80,20 +80,20 @@ To build `node-maintainer`:

## Working on the installer

Orogene's "install" command is called `restore`. During development, you can
Orogene's "install" command is called `apply`. During development, you can
call it like this:

```sh
$ cargo run [--release] -- restore [--root ../path/to/test/react-app] [--oro-cache ./path/to/cache] [--loglevel info]
$ cargo run [--release] -- apply [--root ../path/to/test/react-app] [--oro-cache ./path/to/cache] [--loglevel info]
```

It might be worth it to run with `--release` every time if you plan on seeing
restores to completion, because debug builds of orogene are pretty slow.
applies to completion, because debug builds of orogene are pretty slow.

The restore command itself is defined in `src/commands/restore.rs`, and is
The apply command itself is defined in `src/commands/apply.rs`, and is
pretty much a UI wrapper around `crates/node-maintainer`'s APIs.

If you're only interested in the dependency resolution aspect of `restore`,
If you're only interested in the dependency resolution aspect of `apply`,
you can run with `--lockfile-only`, which will skip the much more expensive
extraction process.

Expand All @@ -104,7 +104,7 @@ orogene uses [tracing](https://docs.rs/tracing) and
logging capabilities, which can be configured through `--loglevel`. The syntax
for this option is documented
[here](https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html#directives).
For example, `cargo run -- restore --loglevel node_maintainer=trace,info` will
For example, `cargo run -- apply --loglevel node_maintainer=trace,info` will
default to INFO-level logging for everything, but also include TRACE-level
logging for anything logged by `node-maintainer` (node the underscore. It's
based on the module name, not the crate.)
Expand Down
2 changes: 1 addition & 1 deletion book/src/SUMMARY.md
Expand Up @@ -13,8 +13,8 @@

# Commands

- [apply](./commands/apply.md)
- [ping](./commands/ping.md)
- [restore](./commands/restore.md)
- [view](./commands/view.md)

---
Expand Down
1 change: 1 addition & 0 deletions book/src/commands/apply.md
@@ -0,0 +1 @@
{{#include ../../../tests/snapshots/help__apply.snap:8:}}
1 change: 0 additions & 1 deletion book/src/commands/restore.md

This file was deleted.

2 changes: 1 addition & 1 deletion crates/node-maintainer/src/maintainer.rs
Expand Up @@ -74,7 +74,7 @@ impl NodeMaintainerOptions {
self
}

/// Controls number of concurrent operations during various restore steps
/// Controls number of concurrent operations during various apply steps
/// (resolution fetches, extractions, etc). Tuning this might help reduce
/// memory usage.
pub fn concurrency(mut self, concurrency: usize) -> Self {
Expand Down
2 changes: 1 addition & 1 deletion examples/render-benchmarks.rs
Expand Up @@ -83,7 +83,7 @@ fn exec_benchmark(prepare: &str) -> Result<BenchmarkResults> {
&json_output,
"--warmup",
"1",
"../release/oro restore --cache pm-cache",
"../release/oro apply --ignore-scripts --cache pm-cache",
"bun install --ignore-scripts",
"npm install --ignore-scripts --cache pm-cache",
"npx -p pnpm pnpm install --ignore-scripts --store-dir pm-cache",
Expand Down
15 changes: 9 additions & 6 deletions src/commands/restore.rs → src/commands/apply.rs
Expand Up @@ -12,10 +12,13 @@ use url::Url;

use crate::commands::OroCommand;

/// Resolves and extracts a `node_modules/` tree.
/// Applies the current project's requested dependencies to `node_modules/`,
/// adding, removing, and updating dependencies as needed. This command is
/// intended to be an idempotent way to make sure your `node_modules` is in
/// the right state to execute, based on your declared dependencies.
#[derive(Debug, Args)]
#[clap(visible_aliases(["r", "res"]))]
pub struct RestoreCmd {
#[clap(visible_aliases(["a", "ap", "app"]))]
pub struct ApplyCmd {
/// When extracting packages, prefer to copy files files instead of
/// linking them.
///
Expand Down Expand Up @@ -47,7 +50,7 @@ pub struct RestoreCmd {
#[arg(long, default_value = "latest")]
default_tag: String,

/// Controls number of concurrent operations during various restore steps
/// Controls number of concurrent operations during various apply steps
/// (resolution fetches, extractions, etc).
///
/// Tuning this might help reduce memory usage (if lowered), or improve
Expand Down Expand Up @@ -104,7 +107,7 @@ pub struct RestoreCmd {
}

#[async_trait]
impl OroCommand for RestoreCmd {
impl OroCommand for ApplyCmd {
async fn execute(self) -> Result<()> {
let total_time = std::time::Instant::now();
let root = &self.root;
Expand Down Expand Up @@ -142,7 +145,7 @@ impl OroCommand for RestoreCmd {
}
}

impl RestoreCmd {
impl ApplyCmd {
fn configured_maintainer(&self) -> NodeMaintainerOptions {
let root = &self.root;
let mut nm = NodeMaintainerOptions::new();
Expand Down
2 changes: 1 addition & 1 deletion src/commands/mod.rs
@@ -1,8 +1,8 @@
use async_trait::async_trait;
use miette::Result;

pub mod apply;
pub mod ping;
pub mod restore;
pub mod view;

#[async_trait]
Expand Down
7 changes: 4 additions & 3 deletions src/lib.rs
Expand Up @@ -397,9 +397,9 @@ where

#[derive(Debug, Subcommand)]
pub enum OroCmd {
Ping(commands::ping::PingCmd),
Apply(commands::apply::ApplyCmd),

Restore(commands::restore::RestoreCmd),
Ping(commands::ping::PingCmd),

View(commands::view::ViewCmd),

Expand All @@ -413,13 +413,14 @@ impl OroCommand for Orogene {
log_command_line();
match self.subcommand {
OroCmd::Ping(cmd) => cmd.execute().await,
OroCmd::Restore(cmd) => cmd.execute().await,
OroCmd::Apply(cmd) => cmd.execute().await,
OroCmd::View(cmd) => cmd.execute().await,
OroCmd::HelpMarkdown(cmd) => cmd.execute().await,
}
}
}

/// Used for generating markdown documentation for Orogene commands.
#[derive(Debug, Args)]
pub struct HelpMarkdownCmd {
#[arg()]
Expand Down
8 changes: 4 additions & 4 deletions tests/help.rs
Expand Up @@ -3,13 +3,13 @@ use std::process::{Command, Output, Stdio};
static BIN: &str = env!("CARGO_BIN_EXE_oro");

#[test]
fn ping_markdown() {
insta::assert_snapshot!("ping", sub_md("ping"));
fn apply_markdown() {
insta::assert_snapshot!("apply", sub_md("apply"));
}

#[test]
fn restore_markdown() {
insta::assert_snapshot!("restore", sub_md("restore"));
fn ping_markdown() {
insta::assert_snapshot!("ping", sub_md("ping"));
}

#[test]
Expand Down
@@ -1,21 +1,21 @@
---
source: tests/help.rs
expression: "sub_md(\"restore\")"
expression: "sub_md(\"apply\")"
---
stderr:

stdout:
# oro restore
# oro apply

Resolves and extracts a `node_modules/` tree
Applies the current project's requested dependencies to `node_modules/`, adding, removing, and updating dependencies as needed. This command is intended to be an idempotent way to make sure your `node_modules` is in the right state to execute, based on your declared dependencies

### Usage:

```
oro restore [OPTIONS]
oro apply [OPTIONS]
```

[aliases: r, res]
[aliases: a, ap, app]

### Options

Expand Down Expand Up @@ -47,7 +47,7 @@ Default dist-tag to use when resolving package versions
#### `--concurrency <CONCURRENCY>`
Controls number of concurrent operations during various restore steps (resolution fetches, extractions, etc).
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).
Expand Down

0 comments on commit 82f7b62

Please sign in to comment.