18 lines
609 B
JavaScript
18 lines
609 B
JavaScript
|
|
import { copyFile, readdir } from 'node:fs/promises'
|
||
|
|
import path from 'node:path'
|
||
|
|
|
||
|
|
const chunksDir = path.resolve(process.cwd(), '.next/static/chunks')
|
||
|
|
const entries = await readdir(chunksDir)
|
||
|
|
const hashedMainApp = entries.find((entry) => /^main-app-[^.]+\.(js)$/.test(entry))
|
||
|
|
|
||
|
|
if (!hashedMainApp) {
|
||
|
|
console.warn('[fix-next-main-app] No hashed main-app chunk found, skipping.')
|
||
|
|
process.exit(0)
|
||
|
|
}
|
||
|
|
|
||
|
|
const source = path.join(chunksDir, hashedMainApp)
|
||
|
|
const target = path.join(chunksDir, 'main-app.js')
|
||
|
|
|
||
|
|
await copyFile(source, target)
|
||
|
|
console.log(`[fix-next-main-app] Copied ${hashedMainApp} -> main-app.js`)
|