@netlify/plugin-nextjs 4.27.2 → 4.27.3
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/edge.js +11 -2
- package/lib/helpers/matchers.js +34 -0
- package/package.json +3 -2
package/lib/helpers/edge.js
CHANGED
|
@@ -12,6 +12,7 @@ const destr_1 = __importDefault(require("destr"));
|
|
|
12
12
|
const fs_extra_1 = require("fs-extra");
|
|
13
13
|
const outdent_1 = require("outdent");
|
|
14
14
|
const config_1 = require("./config");
|
|
15
|
+
const matchers_1 = require("./matchers");
|
|
15
16
|
const loadMiddlewareManifest = (netlifyConfig) => {
|
|
16
17
|
const middlewarePath = (0, path_1.resolve)(netlifyConfig.build.publish, 'server', 'middleware-manifest.json');
|
|
17
18
|
if (!(0, fs_1.existsSync)(middlewarePath)) {
|
|
@@ -61,7 +62,7 @@ const getMiddlewareBundle = async ({ edgeFunctionDefinition, netlifyConfig, }) =
|
|
|
61
62
|
};
|
|
62
63
|
const getEdgeTemplatePath = (file) => (0, path_1.join)(__dirname, '..', '..', 'src', 'templates', 'edge', file);
|
|
63
64
|
const copyEdgeSourceFile = ({ file, target, edgeFunctionDir, }) => fs_1.promises.copyFile(getEdgeTemplatePath(file), (0, path_1.join)(edgeFunctionDir, target !== null && target !== void 0 ? target : file));
|
|
64
|
-
const writeEdgeFunction = async ({ edgeFunctionDefinition, edgeFunctionRoot, netlifyConfig, }) => {
|
|
65
|
+
const writeEdgeFunction = async ({ edgeFunctionDefinition, edgeFunctionRoot, netlifyConfig, nextConfig, }) => {
|
|
65
66
|
const name = sanitizeName(edgeFunctionDefinition.name);
|
|
66
67
|
const edgeFunctionDir = (0, path_1.join)(edgeFunctionRoot, name);
|
|
67
68
|
const bundle = await getMiddlewareBundle({
|
|
@@ -80,13 +81,19 @@ const writeEdgeFunction = async ({ edgeFunctionDefinition, edgeFunctionRoot, net
|
|
|
80
81
|
if ('regexp' in edgeFunctionDefinition) {
|
|
81
82
|
matchers.push({ regexp: edgeFunctionDefinition.regexp });
|
|
82
83
|
}
|
|
84
|
+
else if (nextConfig.i18n) {
|
|
85
|
+
matchers.push(...edgeFunctionDefinition.matchers.map((matcher) => ({
|
|
86
|
+
...matcher,
|
|
87
|
+
regexp: (0, matchers_1.makeLocaleOptional)(matcher.regexp),
|
|
88
|
+
})));
|
|
89
|
+
}
|
|
83
90
|
else {
|
|
84
91
|
matchers.push(...edgeFunctionDefinition.matchers);
|
|
85
92
|
}
|
|
86
93
|
await (0, fs_extra_1.writeJson)((0, path_1.join)(edgeFunctionDir, 'matchers.json'), matchers);
|
|
87
94
|
// We add a defintion for each matching path
|
|
88
95
|
return matchers.map((matcher) => {
|
|
89
|
-
const pattern = matcher.regexp;
|
|
96
|
+
const pattern = (0, matchers_1.stripLookahead)(matcher.regexp);
|
|
90
97
|
return { function: name, pattern, name: edgeFunctionDefinition.name };
|
|
91
98
|
});
|
|
92
99
|
};
|
|
@@ -155,6 +162,7 @@ const writeEdgeFunctions = async (netlifyConfig) => {
|
|
|
155
162
|
edgeFunctionDefinition,
|
|
156
163
|
edgeFunctionRoot,
|
|
157
164
|
netlifyConfig,
|
|
165
|
+
nextConfig,
|
|
158
166
|
});
|
|
159
167
|
manifest.functions.push(...functionDefinitions);
|
|
160
168
|
}
|
|
@@ -167,6 +175,7 @@ const writeEdgeFunctions = async (netlifyConfig) => {
|
|
|
167
175
|
edgeFunctionDefinition,
|
|
168
176
|
edgeFunctionRoot,
|
|
169
177
|
netlifyConfig,
|
|
178
|
+
nextConfig,
|
|
170
179
|
});
|
|
171
180
|
manifest.functions.push(...functionDefinitions);
|
|
172
181
|
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.makeLocaleOptional = exports.stripLookahead = void 0;
|
|
4
|
+
const regexp_tree_1 = require("regexp-tree");
|
|
5
|
+
// The Go regexp lib doesn't support lookaheads, so we need to remove them
|
|
6
|
+
const stripLookahead = (regex) => {
|
|
7
|
+
// Early return if there's no lookahead
|
|
8
|
+
if (!(regex === null || regex === void 0 ? void 0 : regex.includes('(?!'))) {
|
|
9
|
+
return regex;
|
|
10
|
+
}
|
|
11
|
+
try {
|
|
12
|
+
// Parse the regexp into an AST
|
|
13
|
+
const re = (0, regexp_tree_1.transform)(`/${regex}/`, {
|
|
14
|
+
Assertion(path) {
|
|
15
|
+
// Remove the lookahead
|
|
16
|
+
if (path.node.kind === 'Lookahead') {
|
|
17
|
+
path.remove();
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
});
|
|
21
|
+
// Strip the leading and trailing slashes
|
|
22
|
+
return re.toString().slice(1, -1);
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
// Failed to parse regex, so return unchanged
|
|
26
|
+
return regex;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
exports.stripLookahead = stripLookahead;
|
|
30
|
+
const LOCALIZED_REGEX_PREFIX = '(?:\\/(_next\\/data\\/[^/]{1,}))?(?:\\/([^/.]{1,}))';
|
|
31
|
+
const OPTIONAL_REGEX_PREFIX = '(?:\\/(_next\\/data\\/[^/]{1,}))?(?:\\/([^/.]{1,}))?';
|
|
32
|
+
// Make the locale section of the matcher regex optional
|
|
33
|
+
const makeLocaleOptional = (regex) => regex.replace(LOCALIZED_REGEX_PREFIX, OPTIONAL_REGEX_PREFIX);
|
|
34
|
+
exports.makeLocaleOptional = makeLocaleOptional;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@netlify/plugin-nextjs",
|
|
3
|
-
"version": "4.27.
|
|
3
|
+
"version": "4.27.3",
|
|
4
4
|
"description": "Run Next.js seamlessly on Netlify",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"files": [
|
|
@@ -28,13 +28,14 @@
|
|
|
28
28
|
"p-limit": "^3.1.0",
|
|
29
29
|
"pathe": "^0.2.0",
|
|
30
30
|
"pretty-bytes": "^5.6.0",
|
|
31
|
+
"regexp-tree": "^0.1.24",
|
|
31
32
|
"semver": "^7.3.5",
|
|
32
33
|
"slash": "^3.0.0",
|
|
33
34
|
"tiny-glob": "^0.2.9"
|
|
34
35
|
},
|
|
35
36
|
"devDependencies": {
|
|
36
37
|
"@delucis/if-env": "^1.1.2",
|
|
37
|
-
"@netlify/build": "^28.1.
|
|
38
|
+
"@netlify/build": "^28.1.1",
|
|
38
39
|
"@types/fs-extra": "^9.0.13",
|
|
39
40
|
"@types/jest": "^27.4.1",
|
|
40
41
|
"@types/merge-stream": "^1.1.2",
|