Skip to content

Commit 4688e57

Browse files
authored
Merge branch 'main' into mk/wasm-support
2 parents 6cb97a8 + d1e0e65 commit 4688e57

File tree

5 files changed

+36
-7
lines changed

5 files changed

+36
-7
lines changed

.github/pull_request_template.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
<!--Please tag yourself as the Assignee and netlify/frameworks as the Reviewer -->
2-
31
### Summary
42

53
<!-- Provide a brief summary of the change. -->

.release-please-manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"packages/runtime": "4.27.0",
2+
"packages/runtime": "4.27.1",
33
"packages/next": "1.3.1"
44
}

packages/runtime/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Changelog
22

3+
## [4.27.1](https://github.com/netlify/next-runtime/compare/plugin-nextjs-v4.27.0...plugin-nextjs-v4.27.1) (2022-10-18)
4+
5+
6+
### Bug Fixes
7+
8+
* gracefully handle missing static analysis tools ([#1691](https://github.com/netlify/next-runtime/issues/1691)) ([34a039e](https://github.com/netlify/next-runtime/commit/34a039ec80a7c7f050fb5f2dab6f4b8ffddda38a))
9+
310
## [4.27.0](https://github.com/netlify/next-runtime/compare/plugin-nextjs-v4.26.0...plugin-nextjs-v4.27.0) (2022-10-17)
411

512

packages/runtime/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@netlify/plugin-nextjs",
3-
"version": "4.27.0",
3+
"version": "4.27.1",
44
"description": "Run Next.js seamlessly on Netlify",
55
"main": "index.js",
66
"files": [

packages/runtime/src/helpers/analysis.ts

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import fs, { existsSync } from 'fs'
22

3-
import { extractExportedConstValue, UnsupportedValueError } from 'next/dist/build/analysis/extract-const-value'
4-
import { parseModule } from 'next/dist/build/analysis/parse-module'
53
import { relative } from 'pathe'
64

75
// I have no idea what eslint is up to here but it gives an error
@@ -81,13 +79,39 @@ export const validateConfigValue = (config: ApiConfig, apiFilePath: string): con
8179
return false
8280
}
8381

82+
let extractConstValue
83+
let parseModule
84+
let hasWarnedAboutNextVersion = false
8485
/**
8586
* Uses Next's swc static analysis to extract the config values from a file.
8687
*/
8788
export const extractConfigFromFile = async (apiFilePath: string): Promise<ApiConfig> => {
8889
if (!apiFilePath || !existsSync(apiFilePath)) {
8990
return {}
9091
}
92+
93+
try {
94+
if (!extractConstValue) {
95+
extractConstValue = require('next/dist/build/analysis/extract-const-value')
96+
}
97+
if (!parseModule) {
98+
// eslint-disable-next-line prefer-destructuring, @typescript-eslint/no-var-requires
99+
parseModule = require('next/dist/build/analysis/parse-module').parseModule
100+
}
101+
} catch (error) {
102+
if (error.code === 'MODULE_NOT_FOUND') {
103+
if (!hasWarnedAboutNextVersion) {
104+
console.log("This version of Next.js doesn't support advanced API routes. Skipping...")
105+
hasWarnedAboutNextVersion = true
106+
}
107+
// Old Next.js version
108+
return {}
109+
}
110+
throw error
111+
}
112+
113+
const { extractExportedConstValue, UnsupportedValueError } = extractConstValue
114+
91115
const fileContent = await fs.promises.readFile(apiFilePath, 'utf8')
92116
// No need to parse if there's no "config"
93117
if (!fileContent.includes('config')) {
@@ -99,7 +123,7 @@ export const extractConfigFromFile = async (apiFilePath: string): Promise<ApiCon
99123
try {
100124
config = extractExportedConstValue(ast, 'config')
101125
} catch (error) {
102-
if (error instanceof UnsupportedValueError) {
126+
if (UnsupportedValueError && error instanceof UnsupportedValueError) {
103127
console.warn(`Unsupported config value in ${relative(process.cwd(), apiFilePath)}`)
104128
}
105129
return {}

0 commit comments

Comments
 (0)