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

ref(nextjs): Make isBuild rely on NEXT_PHASE environment variable #5829

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 8 additions & 17 deletions packages/nextjs/src/utils/isBuild.ts
Expand Up @@ -2,21 +2,12 @@
* Decide if the currently running process is part of the build phase or happening at runtime.
*/
export function isBuild(): boolean {
// During build, the main process is invoked by
// `node next build`
// and child processes are invoked as
// `node <path>/node_modules/.../jest-worker/processChild.js`.
// The former is (obviously) easy to recognize, but the latter could happen at runtime as well. Fortunately, the main
// process hits this file before any of the child processes do, so we're able to set an env variable which the child
// processes can then check. During runtime, the main process is invoked as
// `node next start`
// or
// `node /var/runtime/index.js`,
// so we never drop into the `if` in the first place.
if (process.argv.includes('build') || process.env.SENTRY_BUILD_PHASE) {
process.env.SENTRY_BUILD_PHASE = 'true';
return true;
}

return false;
// Next.js sets the `NEXT_PHASE` env var depending on what phase/environment we're in.
// These phases are constants within the Next.js codebase but sadly they're not exported in a way that we can easily
// import them with our rollup setup so we're simply vendoring the relevant constant ourselves.
// This constant hasn't changed in the Next.js codebase since next@10:
// Most recent: https://github.com/vercel/next.js/blob/406d69d4d9f7d14b9bf497a134f0151914b13964/packages/next/shared/lib/constants.ts#L20
// v10: https://github.com/vercel/next.js/blob/118ab7992bc8f7a7e5a7bb996510d9b56ffe4f68/packages/next/next-server/lib/constants.ts#L2
const PHASE_PRODUCTION_BUILD = 'phase-production-build';
return process.env.NEXT_PHASE === PHASE_PRODUCTION_BUILD;
}
51 changes: 0 additions & 51 deletions packages/nextjs/test/utils/isBuild.test.ts

This file was deleted.