Skip to content

Commit 8a5a9c6

Browse files
committed
chore: use destr for env var flags
1 parent 0483bb2 commit 8a5a9c6

File tree

4 files changed

+38
-51
lines changed

4 files changed

+38
-51
lines changed

package-lock.json

Lines changed: 29 additions & 40 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/runtime/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"@netlify/ipx": "^1.2.5",
1616
"@vercel/node-bridge": "^2.1.0",
1717
"chalk": "^4.1.2",
18+
"destr": "^1.1.1",
1819
"execa": "^5.1.1",
1920
"fs-extra": "^10.0.0",
2021
"globby": "^11.0.4",
@@ -63,4 +64,4 @@
6364
"engines": {
6465
"node": ">=12.0.0"
6566
}
66-
}
67+
}

packages/runtime/src/helpers/edge.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { resolve, join } from 'path'
44

55
import type { NetlifyConfig, NetlifyPluginConstants } from '@netlify/build'
66
import { greenBright } from 'chalk'
7+
import destr from 'destr'
78
import { copy, copyFile, emptyDir, ensureDir, readJSON, readJson, writeJSON, writeJson } from 'fs-extra'
89
import type { MiddlewareManifest } from 'next/dist/build/webpack/plugins/middleware-plugin'
910
import type { RouteHas } from 'next/dist/lib/load-custom-routes'
@@ -206,12 +207,7 @@ export const writeEdgeFunctions = async (netlifyConfig: NetlifyConfig) => {
206207
await copy(getEdgeTemplatePath('../edge-shared'), join(edgeFunctionRoot, 'edge-shared'))
207208
await writeJSON(join(edgeFunctionRoot, 'edge-shared', 'nextConfig.json'), nextConfig)
208209

209-
if (
210-
process.env.NEXT_DISABLE_EDGE_IMAGES !== '1' &&
211-
process.env.NEXT_DISABLE_EDGE_IMAGES !== 'true' &&
212-
process.env.NEXT_DISABLE_NETLIFY_EDGE !== 'true' &&
213-
process.env.NEXT_DISABLE_NETLIFY_EDGE !== '1'
214-
) {
210+
if (!destr(process.env.NEXT_DISABLE_EDGE_IMAGES) && !destr(process.env.NEXT_DISABLE_NETLIFY_EDGE)) {
215211
console.log(
216212
'Using Netlify Edge Functions for image format detection. Set env var "NEXT_DISABLE_EDGE_IMAGES=true" to disable.',
217213
)
@@ -227,7 +223,7 @@ export const writeEdgeFunctions = async (netlifyConfig: NetlifyConfig) => {
227223
path: '/_next/image*',
228224
})
229225
}
230-
if (process.env.NEXT_DISABLE_NETLIFY_EDGE !== 'true' && process.env.NEXT_DISABLE_NETLIFY_EDGE !== '1') {
226+
if (!destr(process.env.NEXT_DISABLE_NETLIFY_EDGE)) {
231227
const middlewareManifest = await loadMiddlewareManifest(netlifyConfig)
232228
if (!middlewareManifest) {
233229
console.error("Couldn't find the middleware manifest")

packages/runtime/src/index.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { join, relative } from 'path'
33

44
import type { NetlifyPlugin } from '@netlify/build'
55
import { bold, redBright } from 'chalk'
6+
import destr from 'destr'
67
import { existsSync, readFileSync } from 'fs-extra'
78
import { outdent } from 'outdent'
89

@@ -86,7 +87,7 @@ const plugin: NetlifyPlugin = {
8687
if (
8788
middlewareManifest?.functions &&
8889
Object.keys(middlewareManifest.functions).length !== 0 &&
89-
process.env.NEXT_DISABLE_NETLIFY_EDGE
90+
destr(process.env.NEXT_DISABLE_NETLIFY_EDGE)
9091
) {
9192
failBuild(outdent`
9293
You are using Next.js experimental edge runtime, but have set NEXT_DISABLE_NETLIFY_EDGE to true. This is not supported.
@@ -97,7 +98,7 @@ const plugin: NetlifyPlugin = {
9798
if (
9899
middlewareManifest?.middleware &&
99100
Object.keys(middlewareManifest.middleware).length !== 0 &&
100-
process.env.NEXT_DISABLE_NETLIFY_EDGE
101+
destr(process.env.NEXT_DISABLE_NETLIFY_EDGE)
101102
) {
102103
console.log(
103104
redBright(outdent`
@@ -149,7 +150,7 @@ const plugin: NetlifyPlugin = {
149150

150151
await patchNextFiles(basePath)
151152

152-
if (!process.env.SERVE_STATIC_FILES_FROM_ORIGIN) {
153+
if (!destr(process.env.SERVE_STATIC_FILES_FROM_ORIGIN)) {
153154
await moveStaticPages({ target, netlifyConfig, i18n, basePath })
154155
}
155156

0 commit comments

Comments
 (0)