Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deps: Audit 08/29 #6

Merged
merged 6 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,057 changes: 581 additions & 476 deletions Cargo.lock

Large diffs are not rendered by default.

23 changes: 12 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@ resolver = "2"
members = ["crates/*"]

[workspace.dependencies]
extism-pdk = "1.2.0"
moon_common = "0.0.6"
moon_config = "0.0.8"
moon_pdk = "0.0.7"
moon_pdk_test_utils = "0.0.8"
moon_target = "0.0.5"
rustc-hash = "1.1.0"
serde = { version = "1.0.203", features = ["derive"] }
serde_json = "1.0.117"
extism-pdk = "1.2.1"
moon_common = "0.0.8"
moon_config = "0.0.10"
moon_pdk = "0.0.9"
moon_pdk_test_utils = "0.0.10"
moon_target = "0.0.7"
rustc-hash = "2.0.0"
serde = { version = "1.0.209", features = ["derive"] }
serde_json = "1.0.127"
serde_yaml = "0.9.34"
starbase_utils = { version = "0.7.4", default-features = false }
starbase_sandbox = "0.6.2"
starbase_utils = { version = "0.8.7", default-features = false }
starbase_sandbox = "0.7.2"
tokio = { version = "1.39.2", features = ["full"] }

# moon_common = { path = "../moon/nextgen/common" }
# moon_config = { path = "../moon/nextgen/config" }
Expand Down
4 changes: 2 additions & 2 deletions crates/common/src/download.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::format_virtual_path;
use extism_pdk::debug;
use moon_pdk::{fetch_url_bytes, AnyResult, VirtualPath};
use moon_pdk::{fetch_bytes, AnyResult, VirtualPath};
use std::fs;

pub fn download_from_url<U: AsRef<str>, P: AsRef<VirtualPath>>(
Expand All @@ -17,7 +17,7 @@ pub fn download_from_url<U: AsRef<str>, P: AsRef<VirtualPath>>(
let file_name = file_name.unwrap_or_else(|| &url[url.rfind('/').unwrap() + 1..]);

// Fetch the bytes of the URL
let bytes = fetch_url_bytes(url)?;
let bytes = fetch_bytes(url)?;

// Write the to the provided file
let file = dir.join(file_name);
Expand Down
8 changes: 8 additions & 0 deletions crates/download/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# Changelog

## Unreleased

#### 🚀 Updates

- Updated dependencies.

## 0.0.5

#### ⚙️ Internal
Expand Down
1 change: 1 addition & 0 deletions crates/download/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ moon_pdk = { workspace = true }
[dev-dependencies]
moon_pdk_test_utils = { workspace = true }
starbase_sandbox = { workspace = true }
tokio = { workspace = true }

[features]
default = ["wasm"]
Expand Down
130 changes: 71 additions & 59 deletions crates/download/tests/download_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,104 +5,116 @@ use std::fs;
mod download {
use super::*;

#[test]
#[tokio::test(flavor = "multi_thread")]
#[should_panic(expected = "the following required arguments were not provided")]
fn errors_if_no_args() {
async fn errors_if_no_args() {
let sandbox = create_empty_sandbox();
let plugin = create_extension("test", sandbox.path());

plugin.execute_extension(ExecuteExtensionInput {
args: vec![],
context: plugin.create_context(sandbox.path()),
});
plugin
.execute_extension(ExecuteExtensionInput {
args: vec![],
context: plugin.create_context(sandbox.path()),
})
.await;
}

#[test]
#[tokio::test(flavor = "multi_thread")]
#[should_panic(expected = "A valid URL is required for downloading.")]
fn errors_if_not_a_url() {
async fn errors_if_not_a_url() {
let sandbox = create_empty_sandbox();
let plugin = create_extension("test", sandbox.path());

plugin.execute_extension(ExecuteExtensionInput {
args: vec!["--url".into(), "invalid".into()],
context: plugin.create_context(sandbox.path()),
});
plugin
.execute_extension(ExecuteExtensionInput {
args: vec!["--url".into(), "invalid".into()],
context: plugin.create_context(sandbox.path()),
})
.await;
}

#[test]
#[tokio::test(flavor = "multi_thread")]
#[should_panic(expected = "must be a directory, found a file")]
fn errors_if_dest_is_a_file() {
async fn errors_if_dest_is_a_file() {
let sandbox = create_empty_sandbox();
let plugin = create_extension("test", sandbox.path());

sandbox.create_file("dest", "file");

plugin.execute_extension(ExecuteExtensionInput {
args: vec![
"--url".into(),
"https://raw.githubusercontent.com/moonrepo/moon/master/README.md".into(),
"--dest".into(),
"./dest".into(),
],
context: plugin.create_context(sandbox.path()),
});
plugin
.execute_extension(ExecuteExtensionInput {
args: vec![
"--url".into(),
"https://raw.githubusercontent.com/moonrepo/moon/master/README.md".into(),
"--dest".into(),
"./dest".into(),
],
context: plugin.create_context(sandbox.path()),
})
.await;
}

#[test]
fn downloads_file() {
#[tokio::test(flavor = "multi_thread")]
async fn downloads_file() {
let sandbox = create_empty_sandbox();
let plugin = create_extension("test", sandbox.path());

plugin.execute_extension(ExecuteExtensionInput {
args: vec![
"--url".into(),
"https://raw.githubusercontent.com/moonrepo/moon/master/README.md".into(),
"--dest".into(),
".".into(),
],
context: plugin.create_context(sandbox.path()),
});
plugin
.execute_extension(ExecuteExtensionInput {
args: vec![
"--url".into(),
"https://raw.githubusercontent.com/moonrepo/moon/master/README.md".into(),
"--dest".into(),
".".into(),
],
context: plugin.create_context(sandbox.path()),
})
.await;

let file = sandbox.path().join("README.md");

assert!(file.exists());
assert_eq!(fs::metadata(file).unwrap().len(), 3891);
assert_eq!(fs::metadata(file).unwrap().len(), 4107);
}

#[test]
fn downloads_file_to_subdir() {
#[tokio::test(flavor = "multi_thread")]
async fn downloads_file_to_subdir() {
let sandbox = create_empty_sandbox();
let plugin = create_extension("test", sandbox.path());

plugin.execute_extension(ExecuteExtensionInput {
args: vec![
"--url".into(),
"https://raw.githubusercontent.com/moonrepo/moon/master/README.md".into(),
"--dest".into(),
"./sub/dir".into(),
],
context: plugin.create_context(sandbox.path()),
});
plugin
.execute_extension(ExecuteExtensionInput {
args: vec![
"--url".into(),
"https://raw.githubusercontent.com/moonrepo/moon/master/README.md".into(),
"--dest".into(),
"./sub/dir".into(),
],
context: plugin.create_context(sandbox.path()),
})
.await;

assert!(sandbox.path().join("sub/dir/README.md").exists());
}

#[test]
fn downloads_file_with_custom_name() {
#[tokio::test(flavor = "multi_thread")]
async fn downloads_file_with_custom_name() {
let sandbox = create_empty_sandbox();
let plugin = create_extension("test", sandbox.path());

plugin.execute_extension(ExecuteExtensionInput {
args: vec![
"--url".into(),
"https://raw.githubusercontent.com/moonrepo/moon/master/README.md".into(),
"--dest".into(),
"./sub/dir".into(),
"--name".into(),
"moon.md".into(),
],
context: plugin.create_context(sandbox.path()),
});
plugin
.execute_extension(ExecuteExtensionInput {
args: vec![
"--url".into(),
"https://raw.githubusercontent.com/moonrepo/moon/master/README.md".into(),
"--dest".into(),
"./sub/dir".into(),
"--name".into(),
"moon.md".into(),
],
context: plugin.create_context(sandbox.path()),
})
.await;

assert!(sandbox.path().join("sub/dir/moon.md").exists());
}
Expand Down
10 changes: 10 additions & 0 deletions crates/migrate-nx/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# Changelog

## Unreleased

#### 🚀 Updates

- Added support for `defaultBase` from `nx.json`.
- Added support for `metadata` from `project.json`.
- Updated dependencies.

## 0.0.5

#### ⚙️ Internal
Expand Down
2 changes: 2 additions & 0 deletions crates/migrate-nx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ moon_pdk = { workspace = true }
moon_target = { workspace = true }
rustc-hash = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
starbase_utils = { workspace = true, features = ["glob", "json", "yaml"] }

[dev-dependencies]
moon_pdk_test_utils = { workspace = true }
starbase_sandbox = { workspace = true }
tokio = { workspace = true }

[features]
default = ["wasm"]
Expand Down
3 changes: 3 additions & 0 deletions crates/migrate-nx/src/nx_json.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// https://nx.dev/reference/nx-json
// https://github.com/nrwl/nx/blob/master/packages/nx/schemas/nx-schema.json

#![allow(dead_code)]

use rustc_hash::FxHashMap;
use serde::Deserialize;
use starbase_utils::json::JsonValue;
Expand Down Expand Up @@ -89,6 +91,7 @@ pub struct NxWorkspaceLayout {
#[serde(rename_all = "camelCase")]
pub struct NxJson {
pub affected: Option<NxAffected>,
pub default_base: Option<String>,
pub named_inputs: Option<NxNamedInputs>,
pub target_defaults: Option<FxHashMap<String, NxTargetOptions>>,
pub workspace_layout: Option<NxWorkspaceLayout>,
Expand Down
36 changes: 22 additions & 14 deletions crates/migrate-nx/src/nx_migrator.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
use crate::nx_json::*;
use crate::nx_project_json::*;
use moon_common::Id;
use moon_config::FilePath;
use moon_config::PortablePath;
use moon_config::TaskOptionEnvFile;
use moon_config::{
InputPath, OutputPath, PartialProjectDependsOn, PartialTaskArgs, PartialTaskConfig,
PartialTaskDependency, PartialTaskOptionsConfig, PartialVcsConfig, PartialWorkspaceProjects,
PlatformType, ProjectType,
FilePath, InputPath, OutputPath, PartialProjectDependsOn, PartialProjectMetadataConfig,
PartialTaskArgs, PartialTaskConfig, PartialTaskDependency, PartialTaskOptionsConfig,
PartialVcsConfig, PartialWorkspaceProjects, PlatformType, PortablePath, ProjectType,
TaskOptionEnvFile,
};
use moon_extension_common::migrator::*;
use moon_pdk::{map_miette_error, AnyResult, MoonContext};
Expand Down Expand Up @@ -71,14 +69,15 @@ impl NxMigrator {
}

pub fn migrate_root_config(&mut self, nx_json: NxJson) -> AnyResult<()> {
if let Some(affected) = nx_json.affected {
if let Some(default_branch) = affected.default_base {
self.inner
.load_workspace_config()?
.vcs
.get_or_insert(PartialVcsConfig::default())
.default_branch = Some(default_branch);
}
if let Some(default_branch) = nx_json
.default_base
.or_else(|| nx_json.affected.and_then(|aff| aff.default_base))
{
self.inner
.load_workspace_config()?
.vcs
.get_or_insert(PartialVcsConfig::default())
.default_branch = Some(default_branch);
}

if let Some(named_inputs) = nx_json.named_inputs {
Expand Down Expand Up @@ -223,6 +222,15 @@ impl NxMigrator {
}
}

if let Some(metadata) = project_json.metadata {
config
.project
.get_or_insert(PartialProjectMetadataConfig::default())
.metadata
.get_or_insert(Default::default())
.extend(metadata);
}

Ok(())
}

Expand Down
2 changes: 2 additions & 0 deletions crates/migrate-nx/src/nx_project_json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
use crate::nx_json::{NxNamedInputs, NxTargetOptions};
use rustc_hash::FxHashMap;
use serde::Deserialize;
use std::collections::HashMap;

#[derive(Default, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct NxProjectJson {
pub implicit_dependencies: Option<Vec<String>>,
pub metadata: Option<HashMap<String, serde_json::Value>>,
pub name: Option<String>,
pub named_inputs: Option<NxNamedInputs>,
pub project_type: Option<String>,
Expand Down
Loading