Skip to content
This repository was archived by the owner on Feb 1, 2025. It is now read-only.

Commit 40076a2

Browse files
committed
🐛 fix(support next ^13.3): improved handling of next config lookup (fix #88)
Next 13.3/13.4 changed internal code how nextConfig is written. New regex added for finding this configuration in new syntax. Fixes #88 fix #88
1 parent 1b278ae commit 40076a2

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

lib/cli/pack.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { mkdirSync, rmSync, writeFileSync } from 'fs'
22
import { tmpdir } from 'os'
33
import path from 'path'
44

5-
import { nextServerConfigRegex } from '../consts'
6-
import { findInFile, findPathToNestedFile, validateFolderExists, validatePublicFolderStructure, zipMultipleFoldersOrFiles } from '../utils'
5+
import { nextServerConfigRegex, nextServerConfigRegex13_3 } from '../consts'
6+
import { findObjectInFile, findPathToNestedFile, validateFolderExists, validatePublicFolderStructure, zipMultipleFoldersOrFiles } from '../utils'
77

88
interface Props {
99
standaloneFolder: string
@@ -90,7 +90,7 @@ export const packHandler = async ({ handlerPath, outputFolder, publicFolder, sta
9090

9191
const tmpFolder = tmpdir()
9292

93-
const nextConfig = findInFile(generatedNextServerPath, nextServerConfigRegex)
93+
const nextConfig = findObjectInFile(generatedNextServerPath, [nextServerConfigRegex13_3, nextServerConfigRegex])
9494
const configPath = path.resolve(tmpFolder, `./config.json_${Math.random()}`)
9595
writeFileSync(configPath, nextConfig, 'utf-8')
9696

lib/consts.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export const nextServerConfigRegex = /(?<=conf: )(.*)(?=,)/
2+
export const nextServerConfigRegex13_3 = /(?<=nextConfig = )(.*)/
23

34
export const DEFAULT_REGION = 'eu-central-1'

lib/utils.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,29 @@ import { exec } from 'child_process'
33
import { createWriteStream, existsSync, readdirSync, readFileSync } from 'fs'
44
import glob, { IOptions as GlobOptions } from 'glob'
55

6-
export const findInFile = (filePath: string, regex: RegExp): string => {
6+
export const findObjectInFile = (filePath: string, regexes: RegExp[]): string => {
77
const content = readFileSync(filePath, 'utf-8')
8-
const data = content.match(regex)
98

10-
if (!data?.[0]) {
11-
throw new Error('Unable to match Next server configuration.')
9+
const data = regexes.reduce<string | null>((acc, regex) => {
10+
if (acc) {
11+
return acc
12+
}
13+
14+
return content.match(regex)?.[0] ?? null
15+
}, null)
16+
17+
if (!data) {
18+
throw new Error('Unable to match Next server configuration. Report this issue in Github.')
19+
}
20+
21+
try {
22+
JSON.parse(data)
23+
} catch (err) {
24+
console.warn(err)
25+
throw new Error('Unable to parse Next server configuration. Report this issue in Github.')
1226
}
1327

14-
return data[0]
28+
return data
1529
}
1630

1731
interface ZipFolderProps {

0 commit comments

Comments
 (0)