@netlify/plugin-nextjs 4.2.3 → 4.2.4
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/files.js +27 -21
- package/lib/helpers/utils.js +19 -1
- package/package.json +1 -1
package/lib/helpers/files.js
CHANGED
|
@@ -14,6 +14,7 @@ const p_limit_1 = __importDefault(require("p-limit"));
|
|
|
14
14
|
const pathe_1 = require("pathe");
|
|
15
15
|
const slash_1 = __importDefault(require("slash"));
|
|
16
16
|
const constants_1 = require("../constants");
|
|
17
|
+
const utils_1 = require("./utils");
|
|
17
18
|
const TEST_ROUTE = /(|\/)\[[^/]+?](\/|\.html|$)/;
|
|
18
19
|
const isDynamicRoute = (route) => TEST_ROUTE.test(route);
|
|
19
20
|
exports.isDynamicRoute = isDynamicRoute;
|
|
@@ -220,47 +221,52 @@ const moveStaticPages = async ({ netlifyConfig, target, i18n, }) => {
|
|
|
220
221
|
}
|
|
221
222
|
};
|
|
222
223
|
exports.moveStaticPages = moveStaticPages;
|
|
224
|
+
/**
|
|
225
|
+
* Attempt to patch a source file, preserving a backup
|
|
226
|
+
*/
|
|
223
227
|
const patchFile = async ({ file, from, to }) => {
|
|
224
228
|
if (!(0, fs_extra_1.existsSync)(file)) {
|
|
225
|
-
|
|
229
|
+
console.warn('File was not found');
|
|
230
|
+
return false;
|
|
226
231
|
}
|
|
227
232
|
const content = await (0, fs_extra_1.readFile)(file, 'utf8');
|
|
228
233
|
if (content.includes(to)) {
|
|
229
|
-
|
|
234
|
+
console.log('File already patched');
|
|
235
|
+
return false;
|
|
230
236
|
}
|
|
231
237
|
const newContent = content.replace(from, to);
|
|
238
|
+
if (newContent === content) {
|
|
239
|
+
console.warn('File was not changed');
|
|
240
|
+
return false;
|
|
241
|
+
}
|
|
232
242
|
await (0, fs_extra_1.writeFile)(`${file}.orig`, content);
|
|
233
243
|
await (0, fs_extra_1.writeFile)(file, newContent);
|
|
244
|
+
console.log('Done');
|
|
245
|
+
return true;
|
|
234
246
|
};
|
|
247
|
+
/**
|
|
248
|
+
* The file we need has moved around a bit over the past few versions,
|
|
249
|
+
* so we iterate through the options until we find it
|
|
250
|
+
*/
|
|
235
251
|
const getServerFile = (root) => {
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
}
|
|
243
|
-
if (!serverFile) {
|
|
244
|
-
try {
|
|
245
|
-
// eslint-disable-next-line node/no-missing-require
|
|
246
|
-
serverFile = require.resolve('next/dist/next-server/server/next-server', { paths: [root] });
|
|
247
|
-
}
|
|
248
|
-
catch {
|
|
249
|
-
// Ignore
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
return serverFile;
|
|
252
|
+
const candidates = [
|
|
253
|
+
'next/dist/server/base-server',
|
|
254
|
+
'next/dist/server/next-server',
|
|
255
|
+
'next/dist/next-server/server/next-server',
|
|
256
|
+
];
|
|
257
|
+
return (0, utils_1.findModuleFromBase)({ candidates, paths: [root] });
|
|
253
258
|
};
|
|
254
|
-
const patchNextFiles =
|
|
259
|
+
const patchNextFiles = (root) => {
|
|
255
260
|
const serverFile = getServerFile(root);
|
|
256
261
|
console.log(`Patching ${serverFile}`);
|
|
257
262
|
if (serverFile) {
|
|
258
|
-
|
|
263
|
+
return patchFile({
|
|
259
264
|
file: serverFile,
|
|
260
265
|
from: `let ssgCacheKey = `,
|
|
261
266
|
to: `let ssgCacheKey = process.env._BYPASS_SSG || `,
|
|
262
267
|
});
|
|
263
268
|
}
|
|
269
|
+
return false;
|
|
264
270
|
};
|
|
265
271
|
exports.patchNextFiles = patchNextFiles;
|
|
266
272
|
const unpatchNextFiles = async (root) => {
|
package/lib/helpers/utils.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.shouldSkip = exports.getPreviewRewrites = exports.getApiRewrites = exports.redirectsForNextRouteWithData = exports.redirectsForNextRoute = exports.isApiRoute = exports.routeToDataRoute = exports.netlifyRoutesForNextRouteWithData = exports.toNetlifyRoute = void 0;
|
|
6
|
+
exports.findModuleFromBase = exports.shouldSkip = exports.getPreviewRewrites = exports.getApiRewrites = exports.redirectsForNextRouteWithData = exports.redirectsForNextRoute = exports.isApiRoute = exports.routeToDataRoute = exports.netlifyRoutesForNextRouteWithData = exports.toNetlifyRoute = void 0;
|
|
7
7
|
const globby_1 = __importDefault(require("globby"));
|
|
8
8
|
const pathe_1 = require("pathe");
|
|
9
9
|
const constants_1 = require("../constants");
|
|
@@ -116,3 +116,21 @@ const shouldSkip = () => process.env.NEXT_PLUGIN_FORCE_RUN === 'false' ||
|
|
|
116
116
|
process.env.NETLIFY_NEXT_PLUGIN_SKIP === 'true' ||
|
|
117
117
|
process.env.NETLIFY_NEXT_PLUGIN_SKIP === '1';
|
|
118
118
|
exports.shouldSkip = shouldSkip;
|
|
119
|
+
/**
|
|
120
|
+
* Given an array of base paths and candidate modules, return the first one that exists
|
|
121
|
+
*/
|
|
122
|
+
const findModuleFromBase = ({ paths, candidates }) => {
|
|
123
|
+
for (const candidate of candidates) {
|
|
124
|
+
try {
|
|
125
|
+
const modulePath = require.resolve(candidate, { paths });
|
|
126
|
+
if (modulePath) {
|
|
127
|
+
return modulePath;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
catch (error) {
|
|
131
|
+
console.error(error);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return null;
|
|
135
|
+
};
|
|
136
|
+
exports.findModuleFromBase = findModuleFromBase;
|