Skip to content

Commit

Permalink
Merge branch 'main' into shew-86f07
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonyshew authored Nov 5, 2024
2 parents 8fbfe16 + 9c02365 commit 6f15250
Show file tree
Hide file tree
Showing 76 changed files with 1,098 additions and 1,155 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/lsp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ jobs:
fail-fast: false
matrix:
settings:
- host: macos-12
- host: macos-13
target: "x86_64-apple-darwin"
container-options: "--rm"
- host: macos-12
- host: macos-13
target: "aarch64-apple-darwin"
container-options: "--rm"
- host: ubuntu-latest
Expand Down
12 changes: 2 additions & 10 deletions .github/workflows/test-js-packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,14 @@ jobs:
PATTERNS: |
packages/**
- name: Docs related changes
id: docs
uses: technote-space/get-diff-action@v6
with:
PATTERNS: |
docs/**
outputs:
ci: ${{ steps.ci.outputs.diff != ''}}
packages: ${{ steps.packages.outputs.diff != '' }}
docs: ${{ steps.docs.outputs.diff != '' }}

js_packages:
name: "JS Package Tests (${{matrix.os.name}}, Node ${{matrix.node-version}})"
timeout-minutes: 30
if: needs.determine_jobs.outputs.ci == 'true' || needs.determine_jobs.outputs.packages == 'true' || needs.determine_jobs.outputs.docs == 'true'
if: needs.determine_jobs.outputs.ci == 'true' || needs.determine_jobs.outputs.packages == 'true'
needs: [determine_jobs]
runs-on: ${{ matrix.os.runner }}
strategy:
Expand All @@ -68,7 +60,7 @@ jobs:
- "x64"
- "metal"
- name: macos
runner: macos-12
runner: macos-13
node-version:
- 18
- 20
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/turborepo-native-lib-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ name: Turborepo Native Library Tests
on:
push:
branches: [main]
paths-ignore:
- "docs/**"
pull_request:

permissions:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/turborepo-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ jobs:
matrix:
os:
- runner: ubuntu-latest
- runner: macos-12
- runner: macos-13
- runner: windows-latest
steps:
# On Windows, set autocrlf to input so that when the repo is cloned down
Expand Down Expand Up @@ -276,7 +276,7 @@ jobs:
- "metal"
nextest: linux
- name: macos
runner: macos-12
runner: macos-13
nextest: mac
- name: windows
runner: windows-latest
Expand Down
2 changes: 2 additions & 0 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions crates/turbo-trace/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ futures = { workspace = true }
globwalk = { version = "0.1.0", path = "../turborepo-globwalk" }
miette = { workspace = true, features = ["fancy"] }
oxc_resolver = { version = "2.0.0" }
swc_common = { workspace = true, features = ["concurrent"] }
swc_common = { workspace = true, features = ["concurrent", "tty-emitter"] }
swc_ecma_ast = { workspace = true }
swc_ecma_parser = { workspace = true }
swc_ecma_visit = { workspace = true }
thiserror = { workspace = true }
tokio = { workspace = true }
tokio = { workspace = true, features = ["full"] }
tracing = { workspace = true }
tracing-subscriber = { workspace = true }
turbopath = { workspace = true }
Expand Down
72 changes: 58 additions & 14 deletions crates/turbo-trace/src/tracer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,33 @@ use std::{collections::HashMap, sync::Arc};

use camino::Utf8PathBuf;
use globwalk::WalkType;
use miette::{Diagnostic, NamedSource, SourceSpan};
use miette::{Diagnostic, Report, SourceSpan};
use oxc_resolver::{
EnforceExtension, ResolveError, ResolveOptions, Resolver, TsconfigOptions, TsconfigReferences,
};
use swc_common::{comments::SingleThreadedComments, input::StringInput, FileName, SourceMap};
use swc_common::{
comments::SingleThreadedComments,
errors::{ColorConfig, Handler},
input::StringInput,
FileName, SourceMap,
};
use swc_ecma_ast::EsVersion;
use swc_ecma_parser::{lexer::Lexer, Capturing, EsSyntax, Parser, Syntax, TsSyntax};
use swc_ecma_visit::VisitWith;
use thiserror::Error;
use tokio::task::JoinSet;
use tracing::debug;
use tracing::{debug, error};
use turbopath::{AbsoluteSystemPath, AbsoluteSystemPathBuf, PathError};

use crate::import_finder::ImportFinder;

#[derive(Debug, Default)]
pub struct SeenFile {
// We have to add these because of a Rust bug where dead code analysis
// doesn't work properly in multi-target crates
// (i.e. crates with both a binary and library)
// https://github.com/rust-lang/rust/issues/95513
#[allow(dead_code)]
pub ast: Option<swc_ecma_ast::Module>,
}

Expand All @@ -31,35 +41,61 @@ pub struct Tracer {
import_type: ImportType,
}

#[derive(Debug, Error, Diagnostic)]
#[derive(Clone, Debug, Error, Diagnostic)]
pub enum TraceError {
#[error("failed to parse file {}: {:?}", .0, .1)]
ParseError(AbsoluteSystemPathBuf, swc_ecma_parser::error::Error),
#[error("failed to read file: {0}")]
FileNotFound(AbsoluteSystemPathBuf),
#[error(transparent)]
PathEncoding(PathError),
PathEncoding(Arc<PathError>),
#[error("tracing a root file `{0}`, no parent found")]
RootFile(AbsoluteSystemPathBuf),
#[error("failed to resolve import to `{path}`")]
#[error("failed to resolve import to `{import}` in `{file_path}`")]
Resolve {
path: String,
import: String,
file_path: String,
#[label("import here")]
span: SourceSpan,
#[source_code]
text: NamedSource,
text: String,
},
#[error("failed to walk files")]
GlobError(#[from] globwalk::WalkError),
GlobError(Arc<globwalk::WalkError>),
}

impl TraceResult {
#[allow(dead_code)]
pub fn emit_errors(&self) {
let handler = Handler::with_tty_emitter(
ColorConfig::Auto,
true,
false,
Some(self.source_map.clone()),
);
for error in &self.errors {
match error {
TraceError::ParseError(_, e) => {
e.clone().into_diagnostic(&handler).emit();
}
e => {
eprintln!("{:?}", Report::new(e.clone()));
}
}
}
}
}

pub struct TraceResult {
#[allow(dead_code)]
source_map: Arc<SourceMap>,
pub errors: Vec<TraceError>,
pub files: HashMap<AbsoluteSystemPathBuf, SeenFile>,
}

/// The type of imports to trace.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[allow(dead_code)]
pub enum ImportType {
/// Trace all imports.
All,
Expand Down Expand Up @@ -90,6 +126,7 @@ impl Tracer {
}
}

#[allow(dead_code)]
pub fn set_import_type(&mut self, import_type: ImportType) {
self.import_type = import_type;
}
Expand Down Expand Up @@ -162,7 +199,7 @@ impl Tracer {
match resolver.resolve(file_dir, import) {
Ok(resolved) => {
debug!("resolved {:?}", resolved);
match resolved.into_path_buf().try_into() {
match resolved.into_path_buf().try_into().map_err(Arc::new) {
Ok(path) => files.push(path),
Err(err) => {
errors.push(TraceError::PathEncoding(err));
Expand All @@ -176,11 +213,14 @@ impl Tracer {
Err(err) => {
debug!("failed to resolve: {:?}", err);
let (start, end) = source_map.span_to_char_offset(&source_file, *span);
let start = start as usize;
let end = end as usize;

errors.push(TraceError::Resolve {
path: import.to_string(),
span: (start as usize, end as usize).into(),
text: NamedSource::new(file_path.to_string(), file_content.clone()),
import: import.to_string(),
file_path: file_path.to_string(),
span: SourceSpan::new(start.into(), (end - start).into()),
text: file_content.clone(),
});
continue;
}
Expand Down Expand Up @@ -299,6 +339,7 @@ impl Tracer {
}

TraceResult {
source_map: self.source_map.clone(),
files: seen,
errors: self.errors,
}
Expand All @@ -322,15 +363,17 @@ impl Tracer {
Ok(files) => files,
Err(e) => {
return TraceResult {
source_map: self.source_map.clone(),
files: HashMap::new(),
errors: vec![e.into()],
errors: vec![TraceError::GlobError(Arc::new(e))],
}
}
};

let mut futures = JoinSet::new();

let resolver = Arc::new(self.create_resolver());
let source_map = self.source_map.clone();
let shared_self = Arc::new(self);

for file in files {
Expand Down Expand Up @@ -380,6 +423,7 @@ impl Tracer {
}

TraceResult {
source_map,
files: usages,
errors,
}
Expand Down
1 change: 1 addition & 0 deletions crates/turborepo-cache/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ bytes.workspace = true
camino = { workspace = true }
futures = { workspace = true }
hmac = "0.12.1"
miette = { workspace = true }
os_str_bytes = "6.5.0"
path-clean = { workspace = true }
petgraph = "0.6.3"
Expand Down
42 changes: 32 additions & 10 deletions crates/turborepo-cache/src/async_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,8 @@ mod tests {

use crate::{
test_cases::{get_test_cases, TestCase},
AsyncCache, CacheHitMetadata, CacheOpts, CacheSource, RemoteCacheOpts,
AsyncCache, CacheActions, CacheConfig, CacheHitMetadata, CacheOpts, CacheSource,
RemoteCacheOpts,
};

#[tokio::test]
Expand Down Expand Up @@ -255,9 +256,16 @@ mod tests {

let opts = CacheOpts {
cache_dir: Utf8PathBuf::from(".turbo/cache"),
remote_cache_read_only: false,
skip_remote: false,
skip_filesystem: true,
cache: CacheConfig {
local: CacheActions {
read: false,
write: false,
},
remote: CacheActions {
read: true,
write: true,
},
},
workers: 10,
remote_cache_opts: Some(RemoteCacheOpts {
unused_team_id: Some("my-team".to_string()),
Expand Down Expand Up @@ -337,9 +345,16 @@ mod tests {

let opts = CacheOpts {
cache_dir: Utf8PathBuf::from(".turbo/cache"),
remote_cache_read_only: false,
skip_remote: true,
skip_filesystem: false,
cache: CacheConfig {
local: CacheActions {
read: true,
write: true,
},
remote: CacheActions {
read: false,
write: false,
},
},
workers: 10,
remote_cache_opts: Some(RemoteCacheOpts {
unused_team_id: Some("my-team".to_string()),
Expand Down Expand Up @@ -429,9 +444,16 @@ mod tests {

let opts = CacheOpts {
cache_dir: Utf8PathBuf::from(".turbo/cache"),
remote_cache_read_only: false,
skip_remote: false,
skip_filesystem: false,
cache: CacheConfig {
local: CacheActions {
read: true,
write: true,
},
remote: CacheActions {
read: true,
write: true,
},
},
workers: 10,
remote_cache_opts: Some(RemoteCacheOpts {
unused_team_id: Some("my-team".to_string()),
Expand Down
Loading

0 comments on commit 6f15250

Please sign in to comment.