Unverified Commit 1d685d4b authored by Tim Neutkens's avatar Tim Neutkens Committed by GitHub

Turbopack build: Replace process.env.TURBOPACK usage (#77783)

Follow-up of #77762 as that was having too many conflicts as a similar
change landed last night.

<!-- Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation

- Run `pnpm prettier-fix` to fix formatting issues before opening the
PR.
- Read the Docs Contribution Guide to ensure your contribution follows
the docs guidelines:
https://nextjs.org/docs/community/contribution-guide

### Adding or Updating Examples

- The "examples guidelines" are followed from our contributing doc
https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See
https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature
request has been accepted for implementation before opening a PR. (A
discussion must be opened, see
https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added
(https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs)
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md


## For Maintainers

- Minimal description (aim for explaining to someone not on the team to
understand the PR)
- When linking to a Slack thread, you might want to share details of the
conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic
behind a change

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->
parent 6f56b5f9
......@@ -229,6 +229,7 @@ module.exports = ({ dev, turbo, bundleType, experimental, ...rest }) => {
experimental ? true : false
),
'process.env.NEXT_RUNTIME': JSON.stringify('nodejs'),
'process.turbopack': JSON.stringify(turbo),
'process.env.TURBOPACK': JSON.stringify(turbo),
}),
!!process.env.ANALYZE &&
......
......@@ -2275,7 +2275,6 @@ export default async function build(
// @ts-expect-error internal field TODO: fix this, should use a separate mechanism to pass the info.
isExperimentalCompile: isCompileMode,
isTurbopackBuild: isTurbopack,
},
},
appDir: dir,
......
......@@ -33,16 +33,6 @@ const nextStart = async (options: NextStartOptions, directory?: string) => {
printAndExit(getReservedPortExplanation(port), 1)
}
const isTurbopack = Boolean(
options.turbo ||
options.turbopack ||
// TODO: Used for Testing in Next.js CI. Rename to something better like `NEXT_TEST_TURBOPACK`.
process.env.TURBOPACK
)
if (isTurbopack) {
process.env.TURBOPACK = '1'
}
await startServer({
dir,
isDev: false,
......
......@@ -192,20 +192,6 @@ export default class NextNodeServer extends BaseServer<
this.isDev = isDev
this.sriEnabled = Boolean(options.conf.experimental?.sri?.algorithm)
// @ts-expect-error internal field not publicly exposed
const isTurbopackBuild = this.nextConfig.experimental?.isTurbopackBuild
if (!isDev && typeof isTurbopackBuild !== 'undefined') {
if (process.env.TURBOPACK && !isTurbopackBuild) {
throw new Error(
`Invariant: --turbopack is set but the build used Webpack`
)
} else if (!process.env.TURBOPACK && isTurbopackBuild) {
throw new Error(
`Invariant: --turbopack is not set but the build used Turbopack. Add --turbopack to "next start".`
)
}
}
/**
* This sets environment variable to be used at the time of SSR by head.tsx.
* Using this from process.env allows targeting SSR by calling
......
......@@ -240,9 +240,6 @@ export class NextServer implements NextWrapperServer {
// @ts-expect-error internal field
config.experimental.isExperimentalCompile =
serializedConfig.experimental.isExperimentalCompile
// @ts-expect-error internal field
config.experimental.isTurbopackBuild =
serializedConfig.experimental.isTurbopackBuild
} catch (_) {
// if distDir is customized we don't know until we
// load the config so fallback to loading the config
......
import { ReactNode } from 'react'
export default function Root({ children }: { children: ReactNode }) {
return (
<html>
<body>{children}</body>
</html>
)
}
export default function Page() {
return <p>hello world</p>
}
/**
* @type {import('next').NextConfig}
*/
const nextConfig = {}
module.exports = nextConfig
import { nextTestSetup } from 'e2e-utils'
describe('turbopack-build-marker', () => {
const { next } = nextTestSetup({
files: __dirname,
})
it('should have Turbopack build marker', async () => {
const requiredServerFilesManifest = await next.readJSON(
'.next/required-server-files.json'
)
expect(
requiredServerFilesManifest.config.experimental.isTurbopackBuild
).toBe(!!process.env.TURBOPACK)
})
})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment