Skip to content

feat: restore NETLIFY_NEXT_PLUGIN_SKIP #3017

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

Merged
merged 3 commits into from
Jul 31, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,17 @@ import {
verifyPublishDir,
} from './build/verification.js'

const skipPlugin =
process.env.NETLIFY_NEXT_PLUGIN_SKIP === 'true' || process.env.NETLIFY_NEXT_PLUGIN_SKIP === '1'
const skipText = 'Skipping Next.js plugin due to NETLIFY_NEXT_PLUGIN_SKIP environment variable.'
const tracer = wrapTracer(trace.getTracer('Next.js runtime'))

export const onPreDev = async (options: NetlifyPluginOptions) => {
if (skipPlugin) {
console.warn(skipText)
return
}

await tracer.withActiveSpan('onPreDev', async () => {
const context = new PluginContext(options)

Expand All @@ -36,6 +44,11 @@ export const onPreDev = async (options: NetlifyPluginOptions) => {
}

export const onPreBuild = async (options: NetlifyPluginOptions) => {
if (skipPlugin) {
console.warn(skipText)
return
}

await tracer.withActiveSpan('onPreBuild', async () => {
// Enable Next.js standalone mode at build time
process.env.NEXT_PRIVATE_STANDALONE = 'true'
Expand All @@ -53,6 +66,11 @@ export const onPreBuild = async (options: NetlifyPluginOptions) => {
}

export const onBuild = async (options: NetlifyPluginOptions) => {
if (skipPlugin) {
console.warn(skipText)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will repeat skipText quite a bit for each hook. For comparison v4 did omit logs/warnings in some of hooks like

if (shouldSkip()) {
return
}

I think it's fine as-is and we can maybe change this later if we think it's too spammy in practice, but more important is to restore ability to skip, so let's ship this

return
}

await tracer.withActiveSpan('onBuild', async (span) => {
const ctx = new PluginContext(options)

Expand Down Expand Up @@ -86,12 +104,22 @@ export const onBuild = async (options: NetlifyPluginOptions) => {
}

export const onPostBuild = async (options: NetlifyPluginOptions) => {
if (skipPlugin) {
console.warn(skipText)
return
}

await tracer.withActiveSpan('onPostBuild', async () => {
await publishStaticDir(new PluginContext(options))
})
}

export const onSuccess = async () => {
if (skipPlugin) {
console.warn(skipText)
return
}

await tracer.withActiveSpan('onSuccess', async () => {
const prewarm = [process.env.DEPLOY_URL, process.env.DEPLOY_PRIME_URL, process.env.URL].filter(
// If running locally then the deploy ID is a placeholder value. Filtering for `https://0--` removes it.
Expand All @@ -102,6 +130,11 @@ export const onSuccess = async () => {
}

export const onEnd = async (options: NetlifyPluginOptions) => {
if (skipPlugin) {
console.warn(skipText)
return
}

await tracer.withActiveSpan('onEnd', async () => {
await unpublishStaticDir(new PluginContext(options))
})
Expand Down
Loading