Skip to content

Commit

Permalink
Merge branch 'canary' into yj/try-ci-test
Browse files Browse the repository at this point in the history
# Conflicts:
#	pnpm-lock.yaml
  • Loading branch information
ijjk committed Jan 22, 2025
2 parents 0d5b7c8 + 338eb99 commit e4168ee
Show file tree
Hide file tree
Showing 181 changed files with 9,846 additions and 3,385 deletions.
8 changes: 0 additions & 8 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,3 @@ packages/next/compiled/** -text linguist-vendored

# Make next/src/build folder indexable for github search
build/** linguist-generated=false

crates/next-custom-transforms/tests/fixture/**/output* linguist-generated=true

turbopack/crates/turbo-tasks-macros-tests/tests/**/*.stderr linguist-generated=true
turbopack/crates/turbopack-ecmascript/tests/tree-shaker/analyzer/**/output.md linguist-generated=true
turbopack/crates/turbopack-tests/tests/snapshot/**/output/** linguist-generated=true

**/__snapshots__/** linguist-generated=true
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/1.bug_report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ body:
options:
- 'Not sure'
- 'create-next-app'
- 'Developer Experience'
- 'CSS'
- 'dynamicIO'
- 'Lazy Loading'
- 'Font (next/font)'
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.

1 change: 1 addition & 0 deletions crates/napi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ tracing-chrome = "0.5.0"
url = { workspace = true }
urlencoding = { workspace = true }
once_cell = { workspace = true }
dashmap = "6.1.0"

swc_core = { workspace = true, features = [
"base_concurrent",
Expand Down
16 changes: 14 additions & 2 deletions crates/napi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,18 @@ DEALINGS IN THE SOFTWARE.
extern crate napi_derive;

use std::{
env,
panic::set_hook,
sync::{Arc, Once},
};

use backtrace::Backtrace;
use dashmap::DashMap;
use fxhash::FxHashSet;
use napi::bindgen_prelude::*;
use swc_core::{
base::{Compiler, TransformOutput},
common::{FilePathMapping, SourceMap},
};

#[cfg(not(target_arch = "wasm32"))]
pub mod css;
pub mod mdx;
Expand Down Expand Up @@ -97,6 +96,7 @@ pub fn complete_output(
env: &Env,
output: TransformOutput,
eliminated_packages: FxHashSet<String>,
use_cache_telemetry_tracker: DashMap<String, usize>,
) -> napi::Result<Object> {
let mut js_output = env.create_object()?;
js_output.set_named_property("code", env.create_string_from_std(output.code)?)?;
Expand All @@ -109,6 +109,18 @@ pub fn complete_output(
env.create_string_from_std(serde_json::to_string(&eliminated_packages)?)?,
)?;
}
if !use_cache_telemetry_tracker.is_empty() {
js_output.set_named_property(
"useCacheTelemetryTracker",
env.create_string_from_std(serde_json::to_string(
&use_cache_telemetry_tracker
.iter()
.map(|entry| (entry.key().clone(), *entry.value()))
.collect::<Vec<_>>(),
)?)?,
)?;
}

Ok(js_output)
}

Expand Down
12 changes: 6 additions & 6 deletions crates/napi/src/next_api/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use next_api::{
paths::ServerPath,
route::{
endpoint_server_changed_operation, endpoint_write_to_disk_operation, Endpoint,
WrittenEndpoint,
EndpointOutputPaths,
},
};
use tracing::Instrument;
Expand Down Expand Up @@ -52,10 +52,10 @@ pub struct NapiWrittenEndpoint {
pub config: NapiEndpointConfig,
}

impl From<Option<WrittenEndpoint>> for NapiWrittenEndpoint {
fn from(written_endpoint: Option<WrittenEndpoint>) -> Self {
impl From<Option<EndpointOutputPaths>> for NapiWrittenEndpoint {
fn from(written_endpoint: Option<EndpointOutputPaths>) -> Self {
match written_endpoint {
Some(WrittenEndpoint::NodeJs {
Some(EndpointOutputPaths::NodeJs {
server_entry_path,
server_paths,
client_paths,
Expand All @@ -66,7 +66,7 @@ impl From<Option<WrittenEndpoint>> for NapiWrittenEndpoint {
server_paths: server_paths.into_iter().map(From::from).collect(),
..Default::default()
},
Some(WrittenEndpoint::Edge {
Some(EndpointOutputPaths::Edge {
server_paths,
client_paths,
}) => Self {
Expand Down Expand Up @@ -125,7 +125,7 @@ async fn strongly_consistent_catch_collectables<R: VcValueType + Send>(

#[turbo_tasks::value(serialization = "none")]
struct WrittenEndpointWithIssues {
written: Option<ReadRef<WrittenEndpoint>>,
written: Option<ReadRef<EndpointOutputPaths>>,
issues: Arc<Vec<ReadRef<PlainIssue>>>,
diagnostics: Arc<Vec<ReadRef<PlainDiagnostic>>>,
effects: Arc<Effects>,
Expand Down
23 changes: 19 additions & 4 deletions crates/napi/src/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ use std::{
};

use anyhow::{anyhow, bail, Context as _};
use dashmap::DashMap;
use fxhash::FxHashSet;
use napi::bindgen_prelude::*;
use next_custom_transforms::chain_transforms::{custom_before_pass, TransformOptions};
Expand Down Expand Up @@ -81,12 +82,14 @@ fn skip_filename() -> bool {
}

impl Task for TransformTask {
type Output = (TransformOutput, FxHashSet<String>);
type Output = (TransformOutput, FxHashSet<String>, DashMap<String, usize>);
type JsValue = Object;

fn compute(&mut self) -> napi::Result<Self::Output> {
GLOBALS.set(&Default::default(), || {
let eliminated_packages: Rc<RefCell<fxhash::FxHashSet<String>>> = Default::default();
let use_cache_telemetry_tracker: Rc<DashMap<String, usize>> = Default::default();

let res = catch_unwind(AssertUnwindSafe(|| {
try_with_handler(
self.c.cm.clone(),
Expand Down Expand Up @@ -143,6 +146,7 @@ impl Task for TransformTask {
comments.clone(),
eliminated_packages.clone(),
unresolved_mark,
use_cache_telemetry_tracker.clone(),
)
},
|_| noop_pass(),
Expand All @@ -161,7 +165,13 @@ impl Task for TransformTask {

match res {
Ok(res) => res
.map(|o| (o, eliminated_packages.replace(Default::default())))
.map(|o| {
(
o,
eliminated_packages.replace(Default::default()),
(*use_cache_telemetry_tracker).clone(),
)
})
.convert_err(),
Err(err) => Err(napi::Error::new(
Status::GenericFailure,
Expand All @@ -174,9 +184,14 @@ impl Task for TransformTask {
fn resolve(
&mut self,
env: Env,
(output, eliminated_packages): Self::Output,
(output, eliminated_packages, use_cache_telemetry_tracker): Self::Output,
) -> napi::Result<Self::JsValue> {
complete_output(&env, output, eliminated_packages)
complete_output(
&env,
output,
eliminated_packages,
use_cache_telemetry_tracker,
)
}
}

Expand Down
Loading

0 comments on commit e4168ee

Please sign in to comment.