Skip to content

Commit

Permalink
Fixing up dependencies and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
NicholasLYang committed Jun 20, 2024
1 parent fc35ec2 commit 6145879
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 157 deletions.
208 changes: 85 additions & 123 deletions Cargo.lock

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -215,12 +215,12 @@ async-trait = "0.1.64"
atty = "0.2.14"
axum = "0.6.2"
axum-server = "0.4.4"
biome_console = { path = "../biome/crates/biome_console" }
biome_deserialize = { path = "../biome/crates/biome_deserialize", features = ["serde"] }
biome_deserialize_macros = { path = "../biome/crates/biome_deserialize_macros" }
biome_diagnostics = { path = "../biome/crates/biome_diagnostics" }
biome_json_parser = { path = "../biome/crates/biome_json_parser" }
biome_json_syntax = { path = "../biome/crates/biome_json_syntax" }
biome_console = { version = "0.5.7" }
biome_deserialize = { version = "0.6.0", features = ["serde"] }
biome_deserialize_macros = { version = "0.6.0" }
biome_diagnostics = { version = "0.5.7" }
biome_json_parser = { version = "0.5.7" }
biome_json_syntax = { version = "0.5.7" }
bytes = "1.1.0"
camino = { version = "1.1.4", features = ["serde1"] }
chrono = "0.4.23"
Expand Down
1 change: 0 additions & 1 deletion crates/turborepo-lsp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use std::{
borrow::Cow,
collections::{HashMap, HashSet},
iter,
str::FromStr,
sync::{Arc, Mutex},
};

Expand Down
6 changes: 2 additions & 4 deletions crates/turborepo-repository/src/package_graph/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ struct Dependencies {
}

impl Dependencies {
pub fn new<'a, S: AsRef<str> + 'a, I: IntoIterator<Item = (S, S)>>(
pub fn new<'a, I: IntoIterator<Item = (&'a String, &'a String)>>(
repo_root: &AbsoluteSystemPath,
workspace_json_path: &AnchoredSystemPathBuf,
workspaces: &HashMap<PackageName, PackageInfo>,
Expand All @@ -575,12 +575,10 @@ impl Dependencies {
let splitter =
DependencySplitter::new(repo_root, workspace_dir, workspaces, package_manager, npmrc);
for (name, version) in dependencies.into_iter() {
let name = name.as_ref();
let version = version.as_ref();
if let Some(workspace) = splitter.is_internal(name, version) {
internal.insert(workspace);
} else {
external.insert(name.to_owned(), version.to_owned());
external.insert(name.clone(), version.clone());
}
}
Self { internal, external }
Expand Down
2 changes: 1 addition & 1 deletion crates/turborepo-repository/src/package_graph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pub struct PackageInfo {

impl PackageInfo {
pub fn package_name(&self) -> Option<String> {
self.package_json.name.clone().into()
self.package_json.name.clone()
}

pub fn package_json_path(&self) -> &AnchoredSystemPath {
Expand Down
23 changes: 11 additions & 12 deletions crates/turborepo-repository/src/package_json.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use std::{
collections::{BTreeMap, HashMap},
str::FromStr,
};
use std::collections::{BTreeMap, HashMap};

use anyhow::Result;
use biome_deserialize::{json::deserialize_from_json_str, Text};
Expand Down Expand Up @@ -38,14 +35,17 @@ pub struct PackageJson {
#[serde(skip_serializing_if = "Option::is_none")]
pub pnpm: Option<PnpmConfig>,
// Unstructured fields kept for round trip capabilities
#[serde(flatten)]
pub other: BTreeMap<String, serde_json::Value>,
}

#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct PnpmConfig {
#[serde(skip_serializing_if = "Option::is_none")]
pub patched_dependencies: Option<BTreeMap<String, RelativeUnixPathBuf>>,
// Unstructured config options kept for round trip capabilities
#[serde(flatten)]
pub other: BTreeMap<String, serde_json::Value>,
}

Expand All @@ -58,6 +58,7 @@ pub struct RawPackageJson {
pub dev_dependencies: Option<BTreeMap<String, UnescapedString>>,
pub optional_dependencies: Option<BTreeMap<String, UnescapedString>>,
pub peer_dependencies: Option<BTreeMap<String, UnescapedString>>,
#[deserializable(rename = "turbo")]
pub legacy_turbo_config: Option<serde_json::Value>,
pub scripts: BTreeMap<String, UnescapedString>,
pub resolutions: Option<BTreeMap<String, UnescapedString>>,
Expand Down Expand Up @@ -94,25 +95,24 @@ impl From<RawPackageJson> for PackageJson {
package_manager: raw.package_manager.map(|s| s.into()),
dependencies: raw
.dependencies
.map(|m| m.into_iter().map(|(k, v)| (k.into(), v.into())).collect()),
.map(|m| m.into_iter().map(|(k, v)| (k, v.into())).collect()),
dev_dependencies: raw
.dev_dependencies
.map(|m| m.into_iter().map(|(k, v)| (k.into(), v.into())).collect()),
.map(|m| m.into_iter().map(|(k, v)| (k, v.into())).collect()),
optional_dependencies: raw
.optional_dependencies
.map(|m| m.into_iter().map(|(k, v)| (k.into(), v.into())).collect()),
.map(|m| m.into_iter().map(|(k, v)| (k, v.into())).collect()),
peer_dependencies: raw
.peer_dependencies
.map(|m| m.into_iter().map(|(k, v)| (k.into(), v.into())).collect()),
legacy_turbo_config: raw.legacy_turbo_config.map(|v| v.to_string()),
.map(|m| m.into_iter().map(|(k, v)| (k, v.into())).collect()),
scripts: raw
.scripts
.into_iter()
.map(|(k, v)| (k, v.into()))
.collect(),
resolutions: raw
.resolutions
.map(|m| m.into_iter().map(|(k, v)| (k.into(), v.into())).collect()),
.map(|m| m.into_iter().map(|(k, v)| (k, v.into())).collect()),
pnpm: raw.pnpm.map(|p| p.into()),
other: raw
.other
Expand Down Expand Up @@ -169,13 +169,12 @@ impl PackageJson {
Ok(package_json)
}

pub fn all_dependencies(&self) -> impl Iterator<Item = (&str, &str)> + '_ {
pub fn all_dependencies(&self) -> impl Iterator<Item = (&String, &String)> + '_ {
self.dev_dependencies
.iter()
.flatten()
.chain(self.optional_dependencies.iter().flatten())
.chain(self.dependencies.iter().flatten())
.map(|(s1, s2)| (s1.as_ref(), s2.as_ref()))
}

/// Returns the command for script_name if it is non-empty
Expand Down
2 changes: 1 addition & 1 deletion crates/turborepo-repository/src/package_manager/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ impl PackageManager {
.resolutions
.iter()
.flatten()
.map(|(k, v)| (k.clone().into(), v.clone().into())),
.map(|(k, v)| (k.clone(), v.clone())),
)),
)?),
})
Expand Down
12 changes: 3 additions & 9 deletions turborepo-tests/integration/tests/bad-turbo-json.t
Original file line number Diff line number Diff line change
Expand Up @@ -76,27 +76,21 @@ Run build with syntax errors in turbo.json

x failed to parse turbo json

Error: turbo_json_parse_error

x Expected a property but instead found ','.
Error: x Expected a property but instead found ','.
,-[1:1]
1 | {
2 | "$schema": "https://turbo.build/schema.json",,
: ^
3 | "globalDependencies": ["foo.txt"],
`----
Error: turbo_json_parse_error

x expected `,` but instead found `42`
Error: x expected `,` but instead found `42`
,-[11:1]
11 | "my-app#build": {
12 | "outputs": ["banana.txt", "apple.json"]42,
: ^^
13 | "inputs": [".env.local"
`----
Error: turbo_json_parse_error

x expected `,` but instead found `}`
Error: x expected `,` but instead found `}`
,-[13:1]
13 | "inputs": [".env.local"
14 | },
Expand Down

0 comments on commit 6145879

Please sign in to comment.