Repository: vercel/next.js
File: packages/next/src/lib/inline-static-env.ts (TypeScript)

Code before:
import fs from 'fs'
import path from 'path'
import crypto from 'crypto'
import { promisify } from 'util'
import globOriginal from 'next/dist/compiled/glob'
import { Sema } from 'next/dist/compiled/async-sema'
import type { NextConfigComplete } from '../server/config-shared'
import { getNextConfigEnv, getStaticEnv } from './static-env'
import { evaluateDeploymentId } from '../server/evaluate-deployment-id'

const glob = promisify(globOriginal)

export async function inlineStaticEnv({
  distDir,
  config,
}: {
  distDir: string
  config: NextConfigComplete
}) {
  const nextConfigEnv = getNextConfigEnv(config)
  // User-configured deploymentId takes precedence over NEXT_DEPLOYMENT_ID
  const deploymentId = evaluateDeploymentId(
    config.deploymentId || process.env.NEXT_DEPLOYMENT_ID
  )
  const staticEnv = getStaticEnv(config, deploymentId)

  const serverDir = path.join(distDir, 'server')
  const serverChunks = await glob('**/*.{js,json,js.map}', {
    cwd: serverDir,
  })
  const clientDir = path.join(distDir, 'static')
  const clientChunks = await glob('**/*.{js,json,js.map}', {
    cwd: clientDir,
  })
  const manifestChunks = await glob('*.{js,json,js.map}', {
    cwd: distDir,
  })

  const inlineSema = new Sema(8)
  const nextConfigEnvKeys = Object.keys(nextConfigEnv).map((item) =>
    item.split('process.env.').pop()
  )

  const builtRegEx = new RegExp(
    `[\\w]{1,}(\\.env)?\\.(?:NEXT_PUBLIC_[\\w]{1,}${nextConfigEnvKeys.length ? '|' + nextConfigEnvKeys.join('|') : ''})`,
    'g'
  )
  const changedClientFiles: Array<{ file: string; content: string }> = []

Review comment (suggestion):
there should be a single place where you do the 
```js
typeof config.deploymentId === "function" ?
	config.deploymentId() :
	(config.deploymentId  || process.env.NEXT_DEPLOYMENT_ID)
```
normalization and then that is passed through the rest of the codebase as a singular value

Code after:
import fs from 'fs'
import path from 'path'
import crypto from 'crypto'
import { promisify } from 'util'
import globOriginal from 'next/dist/compiled/glob'
import { Sema } from 'next/dist/compiled/async-sema'
import type { NextConfigComplete } from '../server/config-shared'
import { getNextConfigEnv, getStaticEnv } from './static-env'

const glob = promisify(globOriginal)

export async function inlineStaticEnv({
  distDir,
  config,
}: {
  distDir: string
  config: NextConfigComplete
}) {
  const nextConfigEnv = getNextConfigEnv(config)
  const staticEnv = getStaticEnv(config, config.deploymentId)

  const serverDir = path.join(distDir, 'server')
  const serverChunks = await glob('**/*.{js,json,js.map}', {
    cwd: serverDir,
  })
  const clientDir = path.join(distDir, 'static')
  const clientChunks = await glob('**/*.{js,json,js.map}', {
    cwd: clientDir,
  })
  const manifestChunks = await glob('*.{js,json,js.map}', {
    cwd: distDir,
  })

  const inlineSema = new Sema(8)
  const nextConfigEnvKeys = Object.keys(nextConfigEnv).map((item) =>
    item.split('process.env.').pop()
  )

  const builtRegEx = new RegExp(
    `[\\w]{1,}(\\.env)?\\.(?:NEXT_PUBLIC_[\\w]{1,}${nextConfigEnvKeys.length ? '|' + nextConfigEnvKeys.join('|') : ''})`,
    'g'
  )
  const changedClientFiles: Array<{ file: string; content: string }> = []
  const filesToCheck = new Set<string>(
    manifestChunks.map((f) => path.join(distDir, f))
  )

  for (const [parentDir, files] of [