Skip to content

Commit

Permalink
types: improve napi binding typing using generated types (#69680)
Browse files Browse the repository at this point in the history
### Why?

All the `any` and `unknown` types kept bothering me.

I've also removed some unused napi functions
  • Loading branch information
ForsakenHarmony committed Sep 24, 2024
1 parent 624449f commit 0539477
Show file tree
Hide file tree
Showing 21 changed files with 1,174 additions and 526 deletions.
6 changes: 3 additions & 3 deletions crates/napi/src/next_api/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ pub struct ProjectInstance {
exit_receiver: tokio::sync::Mutex<Option<ExitReceiver>>,
}

#[napi(ts_return_type = "{ __napiType: \"Project\" }")]
#[napi(ts_return_type = "Promise<{ __napiType: \"Project\" }>")]
pub async fn project_new(
options: NapiProjectOptions,
turbo_engine_options: NapiTurboEngineOptions,
Expand Down Expand Up @@ -421,7 +421,7 @@ async fn benchmark_file_io(directory: Vc<FileSystemPath>) -> Result<Vc<Completio
Ok(Completion::new())
}

#[napi(ts_return_type = "{ __napiType: \"Project\" }")]
#[napi]
pub async fn project_update(
#[napi(ts_arg_type = "{ __napiType: \"Project\" }")] project: External<ProjectInstance>,
options: NapiPartialProjectOptions,
Expand All @@ -439,7 +439,7 @@ pub async fn project_update(
Ok(())
}

#[napi(ts_return_type = "{ __napiType: \"Project\" }")]
#[napi]
pub async fn project_shutdown(
#[napi(ts_arg_type = "{ __napiType: \"Project\" }")] project: External<ProjectInstance>,
) {
Expand Down
5 changes: 0 additions & 5 deletions crates/napi/src/turbopack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,3 @@ impl From<NapiRouteHas> for RouteHas {
}
}
}

#[napi]
pub async fn experimental_turbo(_unused: Buffer) -> napi::Result<()> {
unimplemented!("__experimental_turbo is not yet implemented");
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@
"update-google-fonts": "node ./scripts/update-google-fonts.js",
"patch-next": "node scripts/patch-next.cjs",
"unpack-next": "node scripts/unpack-next.cjs",
"swc-build-native": "pnpm --filter=@next/swc build-native",
"swc-build-native": "node scripts/build-native.cjs",
"swc-build-wasm": "node scripts/build-wasm.cjs",
"sweep": "node scripts/sweep.cjs"
},
"devDependencies": {
Expand Down
3 changes: 2 additions & 1 deletion packages/next/src/build/collect-build-traces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { normalizeAppPath } from '../shared/lib/router/utils/app-paths'
import isError from '../lib/is-error'
import type { NodeFileTraceReasons } from '@vercel/nft'
import type { RoutesUsingEdgeRuntime } from './utils'
import type { ExternalObject, TurboTasks } from './swc/generated-native'

const debug = debugOriginal('next:build:build-traces')

Expand Down Expand Up @@ -107,7 +108,7 @@ export async function collectBuildTraces({
}) {
const startTime = Date.now()
debug('starting build traces')
let turboTasksForTrace: unknown
let turboTasksForTrace: ExternalObject<TurboTasks>
let bindings = await loadBindings()

const runTurbotrace = async function () {
Expand Down
Loading

0 comments on commit 0539477

Please sign in to comment.