diff --git a/examples/with-apollo/package.json b/examples/with-apollo/package.json index 5a8e0fb9e0014..48019f9baacf0 100644 --- a/examples/with-apollo/package.json +++ b/examples/with-apollo/package.json @@ -8,7 +8,7 @@ "dependencies": { "@apollo/client": "3.1.1", "deepmerge": "^4.2.2", - "lodash": "4.17.20", + "lodash": "4.17.21", "graphql": "^15.3.0", "next": "latest", "prop-types": "^15.6.2", diff --git a/examples/with-clerk/package.json b/examples/with-clerk/package.json index 26e40d55c4dae..91ab67c8fb2fe 100644 --- a/examples/with-clerk/package.json +++ b/examples/with-clerk/package.json @@ -10,7 +10,7 @@ "@types/node": "20.5.7", "@types/react": "18.2.8", "@types/react-dom": "18.2.7", - "next": "13.4.2", + "next": "13.5.1", "react": "18.2.0", "react-dom": "18.2.0", "typescript": "5.2.2" diff --git a/examples/with-segment-analytics-pages-router/package.json b/examples/with-segment-analytics-pages-router/package.json index 19b1f6fdfff26..1c31963cc0c72 100644 --- a/examples/with-segment-analytics-pages-router/package.json +++ b/examples/with-segment-analytics-pages-router/package.json @@ -6,7 +6,7 @@ "start": "next start" }, "dependencies": { - "@segment/analytics-next": "1.53.0", + "@segment/analytics-next": "1.69.0", "next": "latest", "react": "^18.2.0", "react-dom": "^18.2.0" diff --git a/package.json b/package.json index fc72d0abf5912..eb2da1ece688c 100644 --- a/package.json +++ b/package.json @@ -171,11 +171,11 @@ "ky-universal": "0.6.0", "lerna": "4.0.0", "lint-staged": "10.1.7", - "lodash": "4.17.20", + "lodash": "4.17.21", "lost": "8.3.1", "minimatch": "3.0.4", "moment": "^2.24.0", - "nanoid": "3.1.30", + "nanoid": "3.1.31", "next": "workspace:*", "node-fetch": "2.6.7", "node-plop": "0.31.1", diff --git a/packages/next-swc/crates/napi/src/next_api/project.rs b/packages/next-swc/crates/napi/src/next_api/project.rs index f596bbc8a7ab9..cc0dfdfc76e18 100644 --- a/packages/next-swc/crates/napi/src/next_api/project.rs +++ b/packages/next-swc/crates/napi/src/next_api/project.rs @@ -298,7 +298,7 @@ pub async fn project_update( #[napi(object)] #[derive(Default)] -struct NapiRoute { +pub struct NapiRoute { /// The relative path from project_path to the route file pub pathname: String, @@ -367,7 +367,7 @@ impl NapiRoute { } #[napi(object)] -struct NapiMiddleware { +pub struct NapiMiddleware { pub endpoint: External, } @@ -386,7 +386,7 @@ impl NapiMiddleware { } #[napi(object)] -struct NapiInstrumentation { +pub struct NapiInstrumentation { pub node_js: External, pub edge: External, } @@ -410,7 +410,7 @@ impl NapiInstrumentation { } #[napi(object)] -struct NapiEntrypoints { +pub struct NapiEntrypoints { pub routes: Vec, pub middleware: Option, pub instrumentation: Option, @@ -442,6 +442,99 @@ async fn get_entrypoints_with_issues( .cell()) } +#[napi] +pub async fn project_entrypoints( + #[napi(ts_arg_type = "{ __napiType: \"Project\" }")] project: External, +) -> napi::Result> { + let turbo_tasks = project.turbo_tasks.clone(); + let container = project.container; + + let EntrypointsWithIssues { + entrypoints, + issues, + diagnostics, + } = &*get_entrypoints_with_issues(container) + .strongly_consistent() + .await?; + + let issues_result = issues + .iter() + .map(|issue| NapiIssue::from(&**issue)) + .collect(); + let diagnostics_result = diagnostics + .iter() + .map(|d| NapiDiagnostic::from(d)) + .collect(); + + let ( + routes, + middleware, + instrumentation, + pages_document_endpoint, + pages_app_endpoint, + pages_error_endpoint, + ) = turbo_tasks + .run_once(async move { + let routes = entrypoints + .routes + .iter() + .map(|(pathname, &route)| { + NapiRoute::from_route(pathname.clone(), route, &turbo_tasks) + }) + .collect::>(); + let middleware = entrypoints + .middleware + .as_ref() + .map(|m| NapiMiddleware::from_middleware(m, &turbo_tasks)) + .transpose()?; + let instrumentation = entrypoints + .instrumentation + .as_ref() + .map(|m| NapiInstrumentation::from_instrumentation(m, &turbo_tasks)) + .transpose()?; + + let pages_document_endpoint = External::new(ExternalEndpoint(VcArc::new( + turbo_tasks.clone(), + entrypoints.pages_document_endpoint, + ))); + + let pages_app_endpoint = External::new(ExternalEndpoint(VcArc::new( + turbo_tasks.clone(), + entrypoints.pages_app_endpoint, + ))); + + let pages_error_endpoint = External::new(ExternalEndpoint(VcArc::new( + turbo_tasks.clone(), + entrypoints.pages_error_endpoint, + ))); + + Ok(( + routes, + middleware, + instrumentation, + pages_document_endpoint, + pages_app_endpoint, + pages_error_endpoint, + )) + }) + .await + .map_err(|e| napi::Error::from_reason(PrettyPrintError(&e).to_string()))?; + + let turbopack_result = TurbopackResult { + result: NapiEntrypoints { + routes, + middleware, + instrumentation, + pages_document_endpoint, + pages_app_endpoint, + pages_error_endpoint, + }, + issues: issues_result, + diagnostics: diagnostics_result, + }; + Ok(turbopack_result) +} + #[napi(ts_return_type = "{ __napiType: \"RootTask\" }")] pub fn project_entrypoints_subscribe( #[napi(ts_arg_type = "{ __napiType: \"Project\" }")] project: External, diff --git a/packages/next/package.json b/packages/next/package.json index 22be5f4a53b8f..c35990b27bec3 100644 --- a/packages/next/package.json +++ b/packages/next/package.json @@ -251,7 +251,7 @@ "lru-cache": "5.1.1", "mini-css-extract-plugin": "2.4.3", "msw": "1.3.0", - "nanoid": "3.1.32", + "nanoid": "3.1.31", "native-url": "0.3.4", "neo-async": "2.6.1", "node-html-parser": "5.3.3", diff --git a/packages/next/src/build/index.ts b/packages/next/src/build/index.ts index 964b9d489631c..6d15930d83239 100644 --- a/packages/next/src/build/index.ts +++ b/packages/next/src/build/index.ts @@ -1317,7 +1317,7 @@ export default async function build( const project = await bindings.turbo.createProject({ projectPath: dir, rootPath: config.experimental.outputFileTracingRoot || dir, - nextConfig: config.nextConfig, + nextConfig: config, jsConfig: await getTurbopackJsConfig(dir, config), watch: false, env: process.env as Record, @@ -1335,8 +1335,8 @@ export default async function build( }), }) - // eslint-disable-next-line @typescript-eslint/no-unused-vars - const entrypointsSubscription = project.entrypointsSubscribe() + const entrypoints = await project.entrypoints() + console.log({ entrypoints }) // for await (const entrypoints of entrypointsSubscription) { // } throw new Error("next build doesn't support turbopack yet") diff --git a/packages/next/src/build/swc/index.ts b/packages/next/src/build/swc/index.ts index dbd483236ad8d..cff1367a8d176 100644 --- a/packages/next/src/build/swc/index.ts +++ b/packages/next/src/build/swc/index.ts @@ -611,6 +611,7 @@ export interface UpdateInfo { export interface Project { update(options: Partial): Promise + entrypoints(): Promise> entrypointsSubscribe(): AsyncIterableIterator> hmrEvents(identifier: string): AsyncIterableIterator> hmrIdentifiersSubscribe(): AsyncIterableIterator< @@ -841,6 +842,10 @@ function bindingToApi(binding: any, _wasm: boolean) { ) } + entrypoints() { + return binding.projectEntrypoints(this._nativeProject) + } + entrypointsSubscribe() { type NapiEndpoint = { __napiType: 'Endpoint' } diff --git a/packages/next/src/server/dev/hot-reloader-turbopack.ts b/packages/next/src/server/dev/hot-reloader-turbopack.ts index feb1e7de2dde8..db1724336b92d 100644 --- a/packages/next/src/server/dev/hot-reloader-turbopack.ts +++ b/packages/next/src/server/dev/hot-reloader-turbopack.ts @@ -131,11 +131,7 @@ export async function createHotReloaderTurbopack( }), }) const entrypointsSubscription = project.entrypointsSubscribe() - const currentEntrypoints: CurrentEntrypoints = new Map() - const changeSubscriptions: Map< - string, - Promise> - > = new Map() + let prevMiddleware: boolean | undefined = undefined const globalEntrypoints: GlobalEntrypoints = { @@ -295,6 +291,10 @@ export async function createHotReloaderTurbopack( > = new Map() const clients = new Set() + const changeSubscriptions: Map< + string, + Promise> + > = new Map() const changeSubscription: ChangeSubscription = async ( page, @@ -374,6 +374,8 @@ export async function createHotReloaderTurbopack( subscription?.return!() } + const currentEntrypoints: CurrentEntrypoints = new Map() + try { async function handleEntrypointsSubscription() { for await (const entrypoints of entrypointsSubscription) { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 62a942c5eb856..a93be1b440da1 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -360,8 +360,8 @@ importers: specifier: 10.1.7 version: 10.1.7 lodash: - specifier: 4.17.20 - version: 4.17.20 + specifier: 4.17.21 + version: 4.17.21 lost: specifier: 8.3.1 version: 8.3.1 @@ -372,8 +372,8 @@ importers: specifier: ^2.24.0 version: 2.24.0 nanoid: - specifier: 3.1.30 - version: 3.1.30 + specifier: 3.1.31 + version: 3.1.31 next: specifier: workspace:* version: link:packages/next @@ -1251,8 +1251,8 @@ importers: specifier: 1.3.0 version: 1.3.0(typescript@5.2.2) nanoid: - specifier: 3.1.32 - version: 3.1.32 + specifier: 3.1.31 + version: 3.1.31 native-url: specifier: 0.3.4 version: 0.3.4 @@ -8594,7 +8594,7 @@ packages: resolution: {integrity: sha512-0dv5RNRUlUKxGYIIErl01lpvi8b7W2R04Qcl1mCj70ahwZcgiklfXnFlh4FGnRh6aayCfSZKdhiMryVzcq5Dmg==} engines: {node: '>= 8.x.x'} dependencies: - lodash: 4.17.21 + lodash: 4.17.20 traverse: 0.6.6 dev: true @@ -14345,7 +14345,7 @@ packages: cli-width: 3.0.0 external-editor: 3.1.0 figures: 3.1.0 - lodash: 4.17.21 + lodash: 4.17.20 mute-stream: 0.0.8 run-async: 2.4.1 rxjs: 6.6.2 @@ -16806,6 +16806,7 @@ packages: /lodash@4.17.21: resolution: {integrity: sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==} + dev: true /log-driver@1.2.7: resolution: {integrity: sha512-U7KCmLdqsGHBLeWqYlFA0V0Sl6P08EE1ZrmA9cxjUE0WVqT9qnyVDPz1kzpFEP0jdJuFnasWIfSd7fsaNXkpbg==} @@ -18075,14 +18076,8 @@ packages: /mute-stream@0.0.8: resolution: {integrity: sha512-nnbWWOkoWyUsTjKrhgD0dcz22mdkSnpYqbEjIm2nhwhuxlSkpywJmBo8h0ZqJdkp73mb90SssHkN4rsRaBAfAA==} - /nanoid@3.1.30: - resolution: {integrity: sha512-zJpuPDwOv8D2zq2WRoMe1HsfZthVewpel9CAvTfc/2mBD1uUT/agc5f7GHGWXlYkFvi1mVxe4IjvP2HNrop7nQ==} - engines: {node: ^10 || ^12 || ^13.7 || ^14 || >=15.0.1} - hasBin: true - dev: true - - /nanoid@3.1.32: - resolution: {integrity: sha512-F8mf7R3iT9bvThBoW4tGXhXFHCctyCiUUPrWF8WaTqa3h96d9QybkSeba43XVOOE3oiLfkVDe4bT8MeGmkrTxw==} + /nanoid@3.1.31: + resolution: {integrity: sha512-ZivnJm0o9bb13p2Ot5CpgC2rQdzB9Uxm/mFZweqm5eMViqOJe3PV6LU2E30SiLgheesmcPrjquqraoolONSA0A==} engines: {node: ^10 || ^12 || ^13.7 || ^14 || >=15.0.1} hasBin: true dev: true @@ -20605,7 +20600,7 @@ packages: engines: {node: ^10 || ^12 || >=14} dependencies: colorette: 1.4.0 - nanoid: 3.1.32 + nanoid: 3.1.31 source-map: 0.6.1 dev: true @@ -21830,7 +21825,7 @@ packages: peerDependencies: request: ^2.34 dependencies: - lodash: 4.17.21 + lodash: 4.17.20 request: 2.88.2 dev: true @@ -22164,7 +22159,7 @@ packages: peerDependencies: rollup: ^2.0.0 dependencies: - nanoid: 3.1.32 + nanoid: 3.3.6 open: 8.4.0 rollup: 2.35.1 source-map: 0.7.4 @@ -25094,7 +25089,7 @@ packages: chalk: 4.1.2 commander: 7.2.0 gzip-size: 6.0.0 - lodash: 4.17.21 + lodash: 4.17.20 opener: 1.5.2 sirv: 1.0.10 ws: 7.5.3