@netlify/plugin-nextjs 4.27.0 → 4.27.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/helpers/analysis.js +27 -5
- package/package.json +1 -1
package/lib/helpers/analysis.js
CHANGED
|
@@ -25,8 +25,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.extractConfigFromFile = exports.validateConfigValue = void 0;
|
|
27
27
|
const fs_1 = __importStar(require("fs"));
|
|
28
|
-
const extract_const_value_1 = require("next/dist/build/analysis/extract-const-value");
|
|
29
|
-
const parse_module_1 = require("next/dist/build/analysis/parse-module");
|
|
30
28
|
const pathe_1 = require("pathe");
|
|
31
29
|
const validateConfigValue = (config, apiFilePath) => {
|
|
32
30
|
if (config.type === "experimental-scheduled" /* ApiRouteType.SCHEDULED */) {
|
|
@@ -55,6 +53,9 @@ const validateConfigValue = (config, apiFilePath) => {
|
|
|
55
53
|
return false;
|
|
56
54
|
};
|
|
57
55
|
exports.validateConfigValue = validateConfigValue;
|
|
56
|
+
let extractConstValue;
|
|
57
|
+
let parseModule;
|
|
58
|
+
let hasWarnedAboutNextVersion = false;
|
|
58
59
|
/**
|
|
59
60
|
* Uses Next's swc static analysis to extract the config values from a file.
|
|
60
61
|
*/
|
|
@@ -62,18 +63,39 @@ const extractConfigFromFile = async (apiFilePath) => {
|
|
|
62
63
|
if (!apiFilePath || !(0, fs_1.existsSync)(apiFilePath)) {
|
|
63
64
|
return {};
|
|
64
65
|
}
|
|
66
|
+
try {
|
|
67
|
+
if (!extractConstValue) {
|
|
68
|
+
extractConstValue = require('next/dist/build/analysis/extract-const-value');
|
|
69
|
+
}
|
|
70
|
+
if (!parseModule) {
|
|
71
|
+
// eslint-disable-next-line prefer-destructuring, @typescript-eslint/no-var-requires
|
|
72
|
+
parseModule = require('next/dist/build/analysis/parse-module').parseModule;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
if (error.code === 'MODULE_NOT_FOUND') {
|
|
77
|
+
if (!hasWarnedAboutNextVersion) {
|
|
78
|
+
console.log("This version of Next.js doesn't support advanced API routes. Skipping...");
|
|
79
|
+
hasWarnedAboutNextVersion = true;
|
|
80
|
+
}
|
|
81
|
+
// Old Next.js version
|
|
82
|
+
return {};
|
|
83
|
+
}
|
|
84
|
+
throw error;
|
|
85
|
+
}
|
|
86
|
+
const { extractExportedConstValue, UnsupportedValueError } = extractConstValue;
|
|
65
87
|
const fileContent = await fs_1.default.promises.readFile(apiFilePath, 'utf8');
|
|
66
88
|
// No need to parse if there's no "config"
|
|
67
89
|
if (!fileContent.includes('config')) {
|
|
68
90
|
return {};
|
|
69
91
|
}
|
|
70
|
-
const ast = await
|
|
92
|
+
const ast = await parseModule(apiFilePath, fileContent);
|
|
71
93
|
let config;
|
|
72
94
|
try {
|
|
73
|
-
config =
|
|
95
|
+
config = extractExportedConstValue(ast, 'config');
|
|
74
96
|
}
|
|
75
97
|
catch (error) {
|
|
76
|
-
if (error instanceof
|
|
98
|
+
if (UnsupportedValueError && error instanceof UnsupportedValueError) {
|
|
77
99
|
console.warn(`Unsupported config value in ${(0, pathe_1.relative)(process.cwd(), apiFilePath)}`);
|
|
78
100
|
}
|
|
79
101
|
return {};
|