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

fix: use oxc-resolver hot fix for symlinks #9302

Merged
merged 11 commits into from
Oct 22, 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
42 changes: 28 additions & 14 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/turbo-trace/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ license = "MIT"
camino.workspace = true
clap = { version = "4.5.17", features = ["derive"] }
miette = { workspace = true, features = ["fancy"] }
oxc_resolver = "1.11.0"
oxc_resolver = { version = "2.0.0" }
swc_common = { workspace = true }
swc_ecma_ast = { workspace = true }
swc_ecma_parser = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion crates/turbo-trace/src/tracer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ impl Tracer {
errors.push(TraceError::PathEncoding(err));
}
},
Err(ResolveError::Builtin(_)) => {}
Err(ResolveError::Builtin { .. }) => {}
Err(_) => {
let (start, end) = self.source_map.span_to_char_offset(&source_file, *span);

Expand Down
3 changes: 2 additions & 1 deletion crates/turborepo-lib/src/process/child.rs
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,8 @@ mod test {
while !root.join_component(".git").exists() {
root = root.parent().unwrap().to_owned();
}
root.join_components(&["crates", "turborepo-lib", "test", "scripts"])
println!("root: {root:?}");
root.join_components(&["crates", "turborepo-lib", "test-data", "scripts"])
}

#[test_case(false)]
Expand Down
2 changes: 1 addition & 1 deletion crates/turborepo-lib/src/process/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ mod test {

fn get_script_command(script_name: &str) -> Command {
let mut cmd = Command::new("node");
cmd.args([format!("./test/scripts/{script_name}")]);
cmd.args([format!("./test-data/scripts/{script_name}")]);
cmd
}

Expand Down
49 changes: 33 additions & 16 deletions crates/turborepo-lib/src/query/file.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::sync::Arc;

use async_graphql::{Object, SimpleObject};
use camino::Utf8PathBuf;
use itertools::Itertools;
use swc_ecma_ast::EsVersion;
use swc_ecma_parser::{EsSyntax, Syntax, TsSyntax};
Expand Down Expand Up @@ -68,10 +69,11 @@ impl File {
}
}

#[derive(SimpleObject, Debug)]
#[derive(SimpleObject, Debug, Default)]
pub struct TraceError {
message: String,
path: Option<String>,
import: Option<String>,
start: Option<usize>,
end: Option<usize>,
}
Expand All @@ -83,27 +85,32 @@ impl From<turbo_trace::TraceError> for TraceError {
turbo_trace::TraceError::FileNotFound(file) => TraceError {
message,
path: Some(file.to_string()),
start: None,
end: None,
..Default::default()
},
turbo_trace::TraceError::PathEncoding(_) => TraceError {
message,
path: None,
start: None,
end: None,
..Default::default()
},
turbo_trace::TraceError::RootFile(path) => TraceError {
message,
path: Some(path.to_string()),
start: None,
end: None,
},
turbo_trace::TraceError::Resolve { span, text } => TraceError {
message,
path: Some(text.name().to_string()),
start: Some(span.offset()),
end: Some(span.offset() + span.len()),
..Default::default()
},
turbo_trace::TraceError::Resolve { span, text } => {
let import = text
.inner()
.read_span(&span, 1, 1)
.ok()
.map(|s| String::from_utf8_lossy(s.data()).to_string());

TraceError {
message,
import,
path: Some(text.name().to_string()),
start: Some(span.offset()),
end: Some(span.offset() + span.len()),
}
}
}
}
}
Expand Down Expand Up @@ -147,11 +154,21 @@ impl File {
Ok(self.path.to_string())
}

async fn dependencies(&self, depth: Option<usize>) -> TraceResult {
async fn dependencies(&self, depth: Option<usize>, ts_config: Option<String>) -> TraceResult {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a behavior change where we now respect tsconfig? Maybe update PR description to include functionality this gains us? (I'm curious and want to know, but can't grok it from this PR)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah tsconfig is necessary for doing prefix resolution, i.e. @/components/ui. tsconfig loading is what's broken in oxc-resolver

let ts_config = match ts_config {
Some(ts_config) => Some(Utf8PathBuf::from(ts_config)),
None => self
.path
.ancestors()
.skip(1)
.find(|p| p.join_component("tsconfig.json").exists())
.map(|p| p.as_path().to_owned()),
};

let tracer = Tracer::new(
self.run.repo_root().to_owned(),
vec![self.path.clone()],
None,
ts_config,
);

let mut result = tracer.trace(depth);
Expand Down
5 changes: 5 additions & 0 deletions crates/turborepo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,13 @@ build-target = "0.4.0"

[dev-dependencies]
assert_cmd = { workspace = true }
camino = { workspace = true }
insta = { version = "1.40.0", features = ["json"] }
itertools = { workspace = true }
pretty_assertions = { workspace = true }
serde_json = { workspace = true }
tempfile = { workspace = true }


[lints]
workspace = true
Expand Down
60 changes: 60 additions & 0 deletions crates/turborepo/tests/query.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
use std::{path::Path, process::Command};

use camino::Utf8Path;

fn setup_fixture(

Check warning on line 5 in crates/turborepo/tests/query.rs

View workflow job for this annotation

GitHub Actions / Turborepo Rust testing on windows

function `setup_fixture` is never used
fixture: &str,
package_manager: Option<&str>,
test_dir: &Path,
) -> Result<(), anyhow::Error> {
let script_path = Utf8Path::new(env!("CARGO_MANIFEST_DIR"))
.join("../../turborepo-tests/helpers/setup_integration_test.sh");

Command::new("bash")
.arg("-c")
.arg(format!(
"{} {} {}",
script_path,
fixture,
package_manager.unwrap_or("npm@10.5.0")
))
.current_dir(test_dir)
.spawn()?
.wait()?;

Ok(())
}

fn check_query(fixture: &str, query: &str) -> Result<(), anyhow::Error> {

Check warning on line 28 in crates/turborepo/tests/query.rs

View workflow job for this annotation

GitHub Actions / Turborepo Rust testing on windows

function `check_query` is never used
let tempdir = tempfile::tempdir()?;
setup_fixture(fixture, None, tempdir.path())?;
let output = assert_cmd::Command::cargo_bin("turbo")?
.arg("query")
.arg(query)
.current_dir(tempdir.path())
.output()?;

let stdout = String::from_utf8(output.stdout)?;
let query_output: serde_json::Value = serde_json::from_str(&stdout)?;
insta::assert_json_snapshot!(query_output);

Ok(())
}

#[cfg(not(windows))]
#[test]
fn test_double_symlink() -> Result<(), anyhow::Error> {
check_query(
"oxc_repro",
"query {
file(path: \"./index.js\") {
path
dependencies {
files { items { path } }
errors { items { message import } }
}
}
}",
)?;
Ok(())
}
23 changes: 23 additions & 0 deletions crates/turborepo/tests/snapshots/query__check_query.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
source: crates/turborepo-lib/tests/query.rs
expression: query_output
---
{
"data": {
"file": {
"path": "index.js",
"dependencies": {
"files": {
"items": [
{
"path": "nm/index.js"
}
]
},
"errors": {
"items": []
}
}
}
}
}
2 changes: 0 additions & 2 deletions turborepo-tests/helpers/install_deps.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env bash

set -eo pipefail

# TODO: Should we default to pnpm here?
PACKAGE_MANAGER="npm"
# Check if "@" is present in the argument and remove it if so
Expand All @@ -11,7 +10,6 @@ elif [[ $1 != "" ]]; then
PACKAGE_MANAGER=$1
fi


if [ "$PACKAGE_MANAGER" == "npm" ]; then
npm install > /dev/null 2>&1
if [[ "$OSTYPE" == "msys" ]]; then
Expand Down
22 changes: 13 additions & 9 deletions turborepo-tests/helpers/setup_package_manager.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,25 @@ if [ "$pkgManager" != "" ]; then
fi
fi

# If we're in a prysk test, set the corepack install directory to the prysk temp directory.
# get just the packageManager name, without the version
# We pass the name to corepack enable so that it will work for npm also.
# `corepack enable` with no specified packageManager does not work for npm.
pkgManagerName="${pkgManager%%@*}"

# Set the corepack install directory to a temp directory (either prysk temp or provided dir).
# This will help isolate from the rest of the system, especially when running tests on a dev machine.
if [ "$PRYSK_TEMP" == "" ]; then
COREPACK_INSTALL_DIR_CMD=
COREPACK_INSTALL_DIR="$dir/corepack"
mkdir -p "${COREPACK_INSTALL_DIR}"
export PATH=${COREPACK_INSTALL_DIR}:$PATH
else
COREPACK_INSTALL_DIR="${PRYSK_TEMP}/corepack"
mkdir -p "${COREPACK_INSTALL_DIR}"
export PATH=${COREPACK_INSTALL_DIR}:$PATH
COREPACK_INSTALL_DIR_CMD="--install-directory=${COREPACK_INSTALL_DIR}"
fi

# get just the packageManager name, without the version
# We pass the name to corepack enable so that it will work for npm also.
# `corepack enable` with no specified packageManager does not work for npm.
pkgManagerName="${pkgManager%%@*}"

# Enable corepack so that the packageManager setting in package.json is respected.
corepack enable $pkgManagerName "${COREPACK_INSTALL_DIR_CMD}"
corepack enable $pkgManagerName "--install-directory=${COREPACK_INSTALL_DIR}"



3 changes: 3 additions & 0 deletions turborepo-tests/integration/fixtures/oxc_repro/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.idea
/node_modules
.turbo
Loading
Loading