Skip to content

Commit 8b34135

Browse files
committed
chore: more cleanup related to going back to commonjs
1 parent 7db5872 commit 8b34135

File tree

6 files changed

+60
-58
lines changed

6 files changed

+60
-58
lines changed

packages/runtime/src/constants.ts

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import destr from 'destr'
2+
13
export const HANDLER_FUNCTION_NAME = '___netlify-handler'
24
export const ODB_FUNCTION_NAME = '___netlify-odb-handler'
35
export const API_FUNCTION_NAME = '___netlify-api-handler'
@@ -9,31 +11,30 @@ export const ODB_FUNCTION_TITLE = 'Next.js ISR handler'
911
export const API_FUNCTION_TITLE = 'Next.js API handler'
1012
export const IMAGE_FUNCTION_TITLE = 'next/image handler'
1113

12-
const hiddenPaths = async () => {
13-
const destr = await import('destr')
14-
const paths = destr.destr(process.env.NEXT_KEEP_METADATA_FILES)
14+
const hiddenPaths = () => {
15+
const paths = destr(process.env.NEXT_KEEP_METADATA_FILES)
1516
? []
1617
: [
17-
'/cache',
18-
'/server',
19-
'/serverless',
20-
'/trace',
21-
'/traces',
22-
'/routes-manifest.json',
23-
'/build-manifest.json',
24-
'/prerender-manifest.json',
25-
'/react-loadable-manifest.json',
26-
'/BUILD_ID',
27-
'/app-build-manifest.json',
28-
'/app-path-routes-manifest.json',
29-
'/export-marker.json',
30-
'/images-manifest.json',
31-
'/next-server.js.nft.json',
32-
'/package.json',
33-
'/prerender-manifest.js',
34-
'/required-server-files.json',
35-
'/static-manifest.json',
36-
]
18+
'/cache',
19+
'/server',
20+
'/serverless',
21+
'/trace',
22+
'/traces',
23+
'/routes-manifest.json',
24+
'/build-manifest.json',
25+
'/prerender-manifest.json',
26+
'/react-loadable-manifest.json',
27+
'/BUILD_ID',
28+
'/app-build-manifest.json',
29+
'/app-path-routes-manifest.json',
30+
'/export-marker.json',
31+
'/images-manifest.json',
32+
'/next-server.js.nft.json',
33+
'/package.json',
34+
'/prerender-manifest.js',
35+
'/required-server-files.json',
36+
'/static-manifest.json',
37+
]
3738
return paths
3839
}
3940

packages/runtime/src/helpers/config.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { NetlifyConfig } from '@netlify/build'
2+
import destr from 'destr'
23
import { readJSON, writeJSON } from 'fs-extra'
34
import type { Header } from 'next/dist/lib/load-custom-routes'
45
import type { NextConfigComplete } from 'next/dist/server/config-shared'
@@ -114,13 +115,13 @@ export const configureHandlerFunctions = async ({
114115
ignore: Array<string>
115116
apiLambdas: APILambda[]
116117
ssrLambdas: SSRLambda[]
117-
splitApiRoutes: boolean
118+
splitApiRoutes: unknown
118119
}) => {
119120
const config = await getRequiredServerFiles(publish)
120121
const files = config.files || []
121122
const cssFilesToInclude = files.filter((f) => f.startsWith(`${publish}/static/css/`))
122-
const destr = await import('destr')
123-
if (!destr.destr(process.env.DISABLE_IPX)) {
123+
124+
if (!destr(process.env.DISABLE_IPX)) {
124125
netlifyConfig.functions[IMAGE_FUNCTION_NAME] ||= {}
125126
netlifyConfig.functions[IMAGE_FUNCTION_NAME].node_bundler = 'nft'
126127
}

packages/runtime/src/helpers/edge.ts

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

44
import type { NetlifyConfig, NetlifyPluginConstants } from '@netlify/build'
55
import { greenBright } from 'chalk'
6+
import destr from 'destr'
67
import { copy, copyFile, emptyDir, ensureDir, readJSON, writeJSON, writeJson } from 'fs-extra'
78
import type { PrerenderManifest } from 'next/dist/build'
89
import type { MiddlewareManifest } from 'next/dist/build/webpack/plugins/middleware-plugin'
@@ -52,19 +53,19 @@ export interface FunctionManifest {
5253
version: 1
5354
functions: Array<
5455
| {
55-
function: string
56-
name?: string
57-
path: string
58-
cache?: 'manual'
59-
generator: string
60-
}
56+
function: string
57+
name?: string
58+
path: string
59+
cache?: 'manual'
60+
generator: string
61+
}
6162
| {
62-
function: string
63-
name?: string
64-
pattern: string
65-
cache?: 'manual'
66-
generator: string
67-
}
63+
function: string
64+
name?: string
65+
pattern: string
66+
cache?: 'manual'
67+
generator: string
68+
}
6869
>
6970
layers?: Array<{ name: `https://${string}/mod.ts`; flag: string }>
7071
import_map?: string
@@ -380,9 +381,9 @@ export const writeEdgeFunctions = async ({
380381
await copy(getEdgeTemplatePath('../edge-shared'), join(edgeFunctionRoot, 'edge-shared'))
381382
await writeJSON(join(edgeFunctionRoot, 'edge-shared', 'nextConfig.json'), nextConfig)
382383
await copy(join(publish, 'prerender-manifest.json'), join(edgeFunctionRoot, 'edge-shared', 'prerender-manifest.json'))
383-
const destr = await import('destr')
384+
384385
// early return if edge is disabled
385-
if (destr.destr(process.env.NEXT_DISABLE_NETLIFY_EDGE)) {
386+
if (destr(process.env.NEXT_DISABLE_NETLIFY_EDGE)) {
386387
console.log('Environment variable NEXT_DISABLE_NETLIFY_EDGE has been set, skipping Netlify Edge Function creation.')
387388
return
388389
}
@@ -479,9 +480,9 @@ export const writeEdgeFunctions = async ({
479480
}
480481

481482
if (
482-
destr.destr(process.env.NEXT_FORCE_EDGE_IMAGES) &&
483-
!destr.destr(process.env.NEXT_DISABLE_EDGE_IMAGES) &&
484-
!destr.destr(process.env.DISABLE_IPX)
483+
destr(process.env.NEXT_FORCE_EDGE_IMAGES) &&
484+
!destr(process.env.NEXT_DISABLE_EDGE_IMAGES) &&
485+
!destr(process.env.DISABLE_IPX)
485486
) {
486487
usesEdge = true
487488
console.log(

packages/runtime/src/helpers/flags.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import destr from 'destr'
12
import { existsSync } from 'fs-extra'
23
import { join } from 'pathe'
34

@@ -16,9 +17,8 @@ import { join } from 'pathe'
1617
*
1718
* Disabled by default. Can be overriden using the NEXT_SPLIT_API_ROUTES env var.
1819
*/
19-
export const splitApiRoutes = async (featureFlags: Record<string, unknown>, publish: string) => {
20-
const destr = await import('destr')
21-
const isEnabled = destr.destr(process.env.NEXT_SPLIT_API_ROUTES) ?? featureFlags.next_split_api_routes ?? false
20+
export const splitApiRoutes = (featureFlags: Record<string, unknown>, publish: string) => {
21+
const isEnabled = destr(process.env.NEXT_SPLIT_API_ROUTES) ?? featureFlags.next_split_api_routes ?? false
2222

2323
if (isEnabled && !existsSync(join(publish, 'next-server.js.nft.json'))) {
2424
console.warn(
@@ -30,10 +30,9 @@ export const splitApiRoutes = async (featureFlags: Record<string, unknown>, publ
3030
return isEnabled
3131
}
3232

33-
export const bundleBasedOnNftFiles = async (featureFlags: Record<string, unknown>) => {
34-
const destr = await import('destr')
33+
export const bundleBasedOnNftFiles = (featureFlags: Record<string, unknown>) => {
3534
const isEnabled =
36-
destr.destr(process.env.NEXT_BUNDLE_BASED_ON_NFT_FILES) ?? featureFlags.next_bundle_based_on_nft_files ?? false
35+
destr(process.env.NEXT_BUNDLE_BASED_ON_NFT_FILES) ?? featureFlags.next_bundle_based_on_nft_files ?? false
3736

3837
return isEnabled
3938
}

packages/runtime/src/helpers/functions.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { NetlifyConfig, NetlifyPluginConstants } from '@netlify/build'
22
import bridgeFile from '@vercel/node-bridge'
33
import chalk from 'chalk'
4+
import destr from 'destr'
45
import { copyFile, ensureDir, existsSync, readJSON, writeFile, writeJSON, stat } from 'fs-extra'
56
import { PrerenderManifest } from 'next/dist/build'
67
import type { ImageConfigComplete, RemotePattern } from 'next/dist/shared/lib/image-config'
@@ -209,8 +210,8 @@ export const setupImageFunction = async ({
209210
responseHeaders?: Record<string, string>
210211
}): Promise<void> => {
211212
const imagePath = imageconfig.path || '/_next/image'
212-
const destr = await import('destr')
213-
if (destr.destr(process.env.DISABLE_IPX)) {
213+
214+
if (destr(process.env.DISABLE_IPX)) {
214215
// If no image loader is specified, need to redirect to a 404 page since there's no
215216
// backing loader to serve local site images once deployed to Netlify
216217
if (!IS_LOCAL && imageconfig.loader === 'default') {

packages/runtime/src/helpers/redirects.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { NetlifyConfig } from '@netlify/build'
22
import { yellowBright } from 'chalk'
3+
import destr from 'destr'
34
import { readJSON } from 'fs-extra'
45
import type { NextConfig } from 'next'
56
import type { PrerenderManifest, SsgRoute } from 'next/dist/build'
@@ -211,8 +212,7 @@ export const generateDynamicRewrites = ({
211212
const dynamicRewrites: NetlifyConfig['redirects'] = []
212213
const dynamicRoutesThatMatchMiddleware: Array<string> = []
213214

214-
const dynamicR = async () => {
215-
const destr = await import('destr')
215+
const dynamicR = () => {
216216
dynamicRoutes.forEach((route) => {
217217
if (isApiRoute(route.page) || is404Route(route.page, i18n)) {
218218
return
@@ -235,7 +235,7 @@ export const generateDynamicRewrites = ({
235235
} else if (
236236
prerenderedDynamicRoutes[route.page].fallback === false &&
237237
!is404Isr &&
238-
!destr.destr(process.env.LEGACY_FALLBACK_FALSE)
238+
!destr(process.env.LEGACY_FALLBACK_FALSE)
239239
) {
240240
dynamicRewrites.push(...redirectsForNext404Route({ route: route.page, buildId, basePath, i18n }))
241241
} else {
@@ -350,10 +350,9 @@ export const generateRedirects = async ({
350350
if (middlewareMatches > 0) {
351351
console.log(
352352
yellowBright(outdent`
353-
There ${
354-
middlewareMatches === 1
355-
? `is one statically-generated or ISR route that matches`
356-
: `are ${middlewareMatches} statically-generated or ISR routes that match`
353+
There ${middlewareMatches === 1
354+
? `is one statically-generated or ISR route that matches`
355+
: `are ${middlewareMatches} statically-generated or ISR routes that match`
357356
} a middleware function. Matched routes will always be served from the SSR function and will not use ISR or be served from the CDN.
358357
If this was not intended, ensure that your middleware only matches routes that you intend to use SSR.
359358
`),

0 commit comments

Comments
 (0)