Skip to content

Commit ffadbd7

Browse files
committed
chore: update code comments
1 parent fa3f12f commit ffadbd7

File tree

5 files changed

+19
-12
lines changed

5 files changed

+19
-12
lines changed

src/handlers/cache.cts

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/**
2+
* Netlify Cache Handler
3+
* (CJS format because Next.js doesn't support ESM yet)
4+
*/
5+
16
export default class CacheHandler {
27
options: any
38
cache: Map<string, any>

src/helpers/config.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,17 @@ import { readFile } from 'node:fs/promises'
33
import { TASK_DIR } from './constants.js'
44

55
/**
6-
* Enable Next.js standalone mode
6+
* Enable standalone mode at build-time
77
*/
88
export const setBuildConfig = () => {
99
process.env.NEXT_PRIVATE_STANDALONE = 'true'
1010
}
1111

12+
/**
13+
* Configure the request-time custom cache handler
14+
*/
1215
export const setRequestConfig = async () => {
16+
// get config from the build output
1317
const runtimeConfig = JSON.parse(await readFile(`${TASK_DIR}/.next/required-server-files.json`, 'utf-8'))
1418

1519
// set the path to the cache handler
@@ -18,6 +22,6 @@ export const setRequestConfig = async () => {
1822
incrementalCacheHandlerPath: `${TASK_DIR}/dist/handlers/cache.cjs`,
1923
}
2024

21-
// set config from the build output
25+
// set config
2226
process.env.__NEXT_PRIVATE_STANDALONE_CONFIG = JSON.stringify(runtimeConfig.config)
2327
}

src/helpers/files.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@ import { copySync, moveSync } from 'fs-extra/esm'
66
import { BUILD_DIR } from './constants.js'
77

88
/**
9-
* Move the Next.js build output to a temporary directory
9+
* Move the Next.js build output from the publish dir to a temp dir
1010
*/
11-
export const moveBuildOutput = ({ PUBLISH_DIR }: NetlifyPluginConstants) => {
11+
export const stashBuildOutput = ({ PUBLISH_DIR }: NetlifyPluginConstants) => {
1212
moveSync(PUBLISH_DIR, BUILD_DIR, { overwrite: true })
1313
}
1414

1515
/**
16-
* Move static assets so they are uploaded to the Netlify CDN
16+
* Move static assets to the publish dir so they upload to the CDN
1717
*/
18-
export const moveStaticAssets = ({ PUBLISH_DIR }: NetlifyPluginConstants) => {
18+
export const publishStaticAssets = ({ PUBLISH_DIR }: NetlifyPluginConstants) => {
1919
if (existsSync('public')) {
2020
copySync('public', PUBLISH_DIR)
2121
}

src/helpers/functions.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ const pkg = readJsonSync(`${PLUGIN_DIR}/package.json`)
99

1010
/**
1111
* Create a Netlify function to run the Next.js server
12-
* @param publishDir The publish directory
13-
* @param config Netlify config
1412
*/
1513
export const createServerHandler = async () => {
1614
// clear the handler directory
@@ -43,7 +41,7 @@ export const createServerHandler = async () => {
4341
version: 1,
4442
})
4543

46-
// config ESM
44+
// configure ESM
4745
writeFileSync(`${SERVER_HANDLER_DIR}/package.json`, JSON.stringify({ type: 'module' }))
4846

4947
// write the root handler file

src/index.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { NetlifyPluginOptions } from '@netlify/build'
22

33
import { setBuildConfig } from './helpers/config.js'
4-
import { moveStaticAssets, moveBuildOutput } from './helpers/files.js'
4+
import { publishStaticAssets, stashBuildOutput } from './helpers/files.js'
55
import { createServerHandler } from './helpers/functions.js'
66

77
type NetlifyPluginOptionsWithFlags = NetlifyPluginOptions & { featureFlags?: Record<string, unknown> }
@@ -11,7 +11,7 @@ export const onPreBuild = () => {
1111
}
1212

1313
export const onBuild = async ({ constants }: NetlifyPluginOptionsWithFlags) => {
14-
moveBuildOutput(constants)
15-
moveStaticAssets(constants)
14+
stashBuildOutput(constants)
15+
publishStaticAssets(constants)
1616
await createServerHandler()
1717
}

0 commit comments

Comments
 (0)