Skip to content

Commit

Permalink
Introduce NextMode (vercel#49852)
Browse files Browse the repository at this point in the history
This introduces a `NextMode` enum that controls which mode Next.js Turbo
is currently running in:
* `NextMode::Development`: `next dev`
* `NextMode::Build`: `next build`

Requires vercel/turbo#4972

This also update Turbopack to `turbopack-230517.2` with the following
changes:

* vercel/turbo#4972 <!-- Alex Kirszenberg -
Configure React development flag, inherit NODE_ENV from execution
context -->

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
2 people authored and hydRAnger committed Jun 12, 2023
1 parent 68fa26d commit 4a5f08b
Show file tree
Hide file tree
Showing 25 changed files with 296 additions and 151 deletions.
67 changes: 34 additions & 33 deletions Cargo.lock

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

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ swc_core = { version = "0.76.6" }
testing = { version = "0.33.10" }

# Turbo crates
turbopack-binding = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230516.1" }
turbopack-binding = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230517.2" }
# [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-230516.1" }
turbo-tasks = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230517.2" }
# [TODO]: need to refactor embed_directory! macro usage in next-core
turbo-tasks-fs = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230516.1" }
turbo-tasks-fs = { git = "https://github.com/vercel/turbo.git", tag = "turbopack-230517.2" }

# General Deps

Expand Down
4 changes: 2 additions & 2 deletions packages/next-swc/crates/next-core/js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"check": "tsc --noEmit"
},
"dependencies": {
"@vercel/turbopack-dev": "https://gitpkg.vercel.app/vercel/turbo/crates/turbopack-dev/js?turbopack-230516.1",
"@vercel/turbopack-node": "https://gitpkg.vercel.app/vercel/turbo/crates/turbopack-node/js?turbopack-230516.1",
"@vercel/turbopack-dev": "https://gitpkg.vercel.app/vercel/turbo/crates/turbopack-dev/js?turbopack-230517.2",
"@vercel/turbopack-node": "https://gitpkg.vercel.app/vercel/turbo/crates/turbopack-node/js?turbopack-230517.2",
"anser": "^2.1.1",
"css.escape": "^1.5.1",
"next": "*",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* This is the runtime entry point for Next.js client-side bundles.
*/

import './shims'
import 'next/dist/client/next'
11 changes: 11 additions & 0 deletions packages/next-swc/crates/next-core/js/src/build/client/shims.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import '../shims'

// Next uses __webpack_require__ extensively.
globalThis.__webpack_require__ = (name) => {
console.error(
`__webpack_require__ is not implemented (when requiring ${name})`
)
}

// initialize() needs `__webpack_public_path__` to be defined.
globalThis.__webpack_public_path__ = undefined
3 changes: 3 additions & 0 deletions packages/next-swc/crates/next-core/js/src/build/shims.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// This ensures Next.js uses React 18's APIs (hydrateRoot) instead of React 17's
// (hydrate).
process.env.__NEXT_REACT_ROOT = 'true'
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ async function loadPageChunk(assetPrefix: string, chunkData: ChunkData) {

window.next = {
version: version || '',
// @ts-expect-error
get router() {
return router
},
Expand Down
7 changes: 6 additions & 1 deletion packages/next-swc/crates/next-core/js/types/globals.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import type { Router } from 'next/dist/client/router'
import type { MittEmitter } from 'next/dist/shared/lib/mitt'

declare global {
type ChunkData =
| string
Expand All @@ -20,7 +23,9 @@ declare global {
)[]
var next: {
version: string
appDir: boolean
appDir?: boolean
router?: Router
emitter?: MittEmitter<string>
}

function __turbopack_load_page_chunks__(
Expand Down

0 comments on commit 4a5f08b

Please sign in to comment.