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

Revert "Implement Turbopack trace server bindings" #65419

Merged
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,289 changes: 289 additions & 1,000 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ swc_core = { version = "0.90.33", features = [
testing = { version = "0.35.22" }

# Turbo crates
turbopack-binding = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-240506.2" }
turbopack-binding = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-240503.1" }
# [TODO]: need to refactor embed_directory! macro usages, as well as resolving turbo_tasks::function, macros..
turbo-tasks = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-240506.2" }
turbo-tasks = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-240503.1" }
# [TODO]: need to refactor embed_directory! macro usage in next-core
turbo-tasks-fs = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-240506.2" }
turbo-tasks-fs = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-240503.1" }

# General Deps

Expand Down
2 changes: 0 additions & 2 deletions packages/next-swc/crates/napi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ pub mod next_api;
pub mod parse;
pub mod transform;
#[cfg(not(target_arch = "wasm32"))]
pub mod turbo_trace_server;
#[cfg(not(target_arch = "wasm32"))]
pub mod turbopack;
#[cfg(not(target_arch = "wasm32"))]
pub mod turbotrace;
Expand Down
14 changes: 2 additions & 12 deletions packages/next-swc/crates/napi/src/next_api/project.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{path::PathBuf, sync::Arc, thread, time::Duration};
use std::{path::PathBuf, sync::Arc, time::Duration};

use anyhow::{anyhow, bail, Context, Result};
use napi::{
Expand Down Expand Up @@ -249,22 +249,12 @@
.context("Unable to create .next directory")
.unwrap();
let trace_file = internal_dir.join("trace.log");
let trace_writer = std::fs::File::create(trace_file.clone()).unwrap();
let trace_writer = std::fs::File::create(trace_file).unwrap();
let (trace_writer, guard) = TraceWriter::new(trace_writer);
let subscriber = subscriber.with(RawTraceLayer::new(trace_writer));

let guard = ExitGuard::new(guard).unwrap();

let trace_server = std::env::var("NEXT_TURBOPACK_TRACE_SERVER").ok();
if trace_server.is_some() {
thread::spawn(move || {
turbopack_binding::turbopack::trace_server::start_turbopack_trace_server(
trace_file,
);
});
println!("Turbopack trace server started. View trace at https://turbo-trace-viewer.vercel.app/");
}

subscriber.init();

Some(guard)
Expand Down Expand Up @@ -771,7 +761,7 @@
}
}

/// Subscribes to lifecycle events of the compilation.

Check warning on line 764 in packages/next-swc/crates/napi/src/next_api/project.rs

View workflow job for this annotation

GitHub Actions / rustdoc check / build

public documentation for `project_update_info_subscribe` links to private item `UpdateMessage::Start`

Check warning on line 764 in packages/next-swc/crates/napi/src/next_api/project.rs

View workflow job for this annotation

GitHub Actions / rustdoc check / build

public documentation for `project_update_info_subscribe` links to private item `UpdateMessage::End`

Check warning on line 764 in packages/next-swc/crates/napi/src/next_api/project.rs

View workflow job for this annotation

GitHub Actions / rustdoc check / build

public documentation for `project_update_info_subscribe` links to private item `UpdateMessage::End`

Check warning on line 764 in packages/next-swc/crates/napi/src/next_api/project.rs

View workflow job for this annotation

GitHub Actions / rustdoc check / build

public documentation for `project_update_info_subscribe` links to private item `UpdateMessage::Start`
/// Emits an [UpdateMessage::Start] event when any computation starts.
/// Emits an [UpdateMessage::End] event when there was no computation for the
/// specified time (`aggregation_ms`). The [UpdateMessage::End] event contains
Expand Down
7 changes: 0 additions & 7 deletions packages/next-swc/crates/napi/src/turbo_trace_server.rs

This file was deleted.

1 change: 0 additions & 1 deletion packages/next-swc/crates/next-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ turbopack-binding = { workspace = true, features = [
"__turbopack_image",
"__turbopack_node",
"__turbopack_trace_utils",
"__turbopack_trace_server",
] }

turbo-tasks = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion packages/next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@
"@types/ws": "8.2.0",
"@vercel/ncc": "0.34.0",
"@vercel/nft": "0.26.4",
"@vercel/turbopack-ecmascript-runtime": "https://gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-240506.2",
"@vercel/turbopack-ecmascript-runtime": "https://gitpkg-fork.vercel.sh/vercel/turbo/crates/turbopack-ecmascript-runtime/js?turbopack-240503.1",
"acorn": "8.5.0",
"amphtml-validator": "1.0.35",
"anser": "1.4.9",
Expand Down
15 changes: 0 additions & 15 deletions packages/next/src/bin/next.ts
Original file line number Diff line number Diff line change
Expand Up @@ -383,19 +383,4 @@ program
})
.usage('[directory] [options]')

const internal = program
.command('internal')
.description(
'Internal debugging commands. Use with caution. Not covered by semver.'
)

internal
.command('turbo-trace-server')
.argument('[file]', 'Trace file to serve.')
.action((file) => {
return import('../cli/internal/turbo-trace-server.js').then((mod) =>
mod.startTurboTraceServerCli(file)
)
})

program.parse(process.argv)
34 changes: 14 additions & 20 deletions packages/next/src/build/swc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ let lastNativeBindingsLoadErrorCode:
| 'unsupported_target'
| string
| undefined = undefined
let nativeBindings: Binding
let nativeBindings: any
let wasmBindings: any
let downloadWasmPromise: any
let pendingBindings: any
Expand All @@ -157,21 +157,21 @@ export interface Binding {
stream: any
get: any
}
mdx: {
compile: any
compileSync: any
}
createProject: (
options: ProjectOptions,
turboEngineOptions?: TurboEngineOptions
) => Promise<Project>
startTurbopackTraceServer: (path: string) => void
}
mdx: {
compile: any
compileSync: any
}
minify: any
minifySync: any
transform: any
transformSync: any
parse: any
parseSync: any

getTargetTriple(): string | undefined

Expand Down Expand Up @@ -752,10 +752,7 @@ function rustifyEnv(env: Record<string, string>): RustifiedEnv {
}

// TODO(sokra) Support wasm option.
function bindingToApi(
binding: any,
_wasm: boolean
): Binding['turbo']['createProject'] {
function bindingToApi(binding: any, _wasm: boolean) {
type NativeFunction<T> = (
callback: (err: Error, value: T) => void
) => Promise<{ __napiType: 'RootTask' }>
Expand Down Expand Up @@ -1197,10 +1194,10 @@ function bindingToApi(
}
}

const createProject: Binding['turbo']['createProject'] = async (
options,
turboEngineOptions
) => {
async function createProject(
options: ProjectOptions,
turboEngineOptions: TurboEngineOptions
) {
return new ProjectImpl(
await binding.projectNew(
await rustifyProjectOptions(options),
Expand Down Expand Up @@ -1258,6 +1255,9 @@ async function loadWasm(importPath = '') {
? bindings.parse(src.toString(), options)
: Promise.resolve(bindings.parseSync(src.toString(), options))
},
parseSync(src: string, options: any) {
return bindings.parseSync(src.toString(), options)
},
getTargetTriple() {
return undefined
},
Expand Down Expand Up @@ -1483,12 +1483,6 @@ function loadNative(importPath?: string) {
},
},
createProject: bindingToApi(customBindings ?? bindings, false),
startTurbopackTraceServer: (traceFilePath) => {
Log.warn(
'Turbopack trace server started. View trace at https://turbo-trace-viewer.vercel.app/'
)
;(customBindings ?? bindings).startTurbopackTraceServer(traceFilePath)
},
},
mdx: {
compile: (src: string, options: any) =>
Expand Down
6 changes: 0 additions & 6 deletions packages/next/src/cli/internal/turbo-trace-server.ts

This file was deleted.

8 changes: 4 additions & 4 deletions pnpm-lock.yaml

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

Loading