@netlify/plugin-nextjs 5.15.6 → 5.15.8
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.
|
@@ -405,7 +405,7 @@ var require_dist = __commonJS({
|
|
|
405
405
|
// src/build/functions/edge.ts
|
|
406
406
|
var import_fast_glob = __toESM(require_out(), 1);
|
|
407
407
|
var import_path_to_regexp = __toESM(require_dist(), 1);
|
|
408
|
-
import { cp, mkdir, readdir, readFile,
|
|
408
|
+
import { cp, lstat, mkdir, readdir, readFile, readlink, rm, writeFile } from "node:fs/promises";
|
|
409
409
|
import { dirname, join, relative } from "node:path/posix";
|
|
410
410
|
import { EDGE_HANDLER_NAME } from "../plugin-context.js";
|
|
411
411
|
function nodeMiddlewareDefinitionHasMatcher(definition) {
|
|
@@ -562,15 +562,20 @@ Check https://docs.netlify.com/build/frameworks/framework-setup-guides/nextjs/ov
|
|
|
562
562
|
);
|
|
563
563
|
}
|
|
564
564
|
const commonPrefix = relative(join(srcDir, maxParentDirectoriesPath), srcDir);
|
|
565
|
-
parts.push(`const virtualModules = new Map();`);
|
|
565
|
+
parts.push(`const virtualModules = new Map();`, `const virtualSymlinks = new Map();`);
|
|
566
566
|
const handleFileOrDirectory = async (fileOrDir) => {
|
|
567
567
|
const srcPath = join(srcDir, fileOrDir);
|
|
568
|
-
const stats = await
|
|
568
|
+
const stats = await lstat(srcPath);
|
|
569
569
|
if (stats.isDirectory()) {
|
|
570
570
|
const filesInDir = await readdir(srcPath);
|
|
571
571
|
for (const fileInDir of filesInDir) {
|
|
572
572
|
await handleFileOrDirectory(join(fileOrDir, fileInDir));
|
|
573
573
|
}
|
|
574
|
+
} else if (stats.isSymbolicLink()) {
|
|
575
|
+
const symlinkTarget = await readlink(srcPath);
|
|
576
|
+
parts.push(
|
|
577
|
+
`virtualSymlinks.set(${JSON.stringify(join(commonPrefix, fileOrDir))}, ${JSON.stringify(symlinkTarget)});`
|
|
578
|
+
);
|
|
574
579
|
} else {
|
|
575
580
|
const content = await readFile(srcPath, "utf8");
|
|
576
581
|
parts.push(
|
|
@@ -581,7 +586,7 @@ Check https://docs.netlify.com/build/frameworks/framework-setup-guides/nextjs/ov
|
|
|
581
586
|
for (const file of files) {
|
|
582
587
|
await handleFileOrDirectory(file);
|
|
583
588
|
}
|
|
584
|
-
parts.push(`registerCJSModules(import.meta.url, virtualModules);
|
|
589
|
+
parts.push(`registerCJSModules(import.meta.url, virtualModules, virtualSymlinks);
|
|
585
590
|
|
|
586
591
|
const require = createRequire(import.meta.url);
|
|
587
592
|
const handlerMod = require("./${join(commonPrefix, entry)}");
|
|
@@ -114,7 +114,7 @@ var NetlifyCacheHandler = class {
|
|
|
114
114
|
}
|
|
115
115
|
if (cacheValue.kind === "PAGE" || cacheValue.kind === "PAGES" || cacheValue.kind === "APP_PAGE" || cacheValue.kind === "ROUTE" || cacheValue.kind === "APP_ROUTE") {
|
|
116
116
|
if (cacheValue.headers?.[import_constants.NEXT_CACHE_TAGS_HEADER]) {
|
|
117
|
-
const cacheTags = cacheValue.headers[import_constants.NEXT_CACHE_TAGS_HEADER].split(/,|%2c/gi);
|
|
117
|
+
const cacheTags = cacheValue.headers[import_constants.NEXT_CACHE_TAGS_HEADER].split(/,|%2c/gi).map(encodeURI);
|
|
118
118
|
requestContext.responseCacheTags = cacheTags;
|
|
119
119
|
} else if ((cacheValue.kind === "PAGE" || cacheValue.kind === "PAGES") && typeof cacheValue.pageData === "object") {
|
|
120
120
|
const cacheTags = [`_N_T_${key === "/index" ? "/" : encodeURI(key)}`];
|
|
@@ -86,7 +86,7 @@ var pipeline = (0, import_util.promisify)(import_stream.pipeline);
|
|
|
86
86
|
|
|
87
87
|
// package.json
|
|
88
88
|
var name = "@netlify/plugin-nextjs";
|
|
89
|
-
var version = "5.15.
|
|
89
|
+
var version = "5.15.8";
|
|
90
90
|
|
|
91
91
|
// src/run/handlers/tags-handler.cts
|
|
92
92
|
var import_storage = require("../storage/storage.cjs");
|
package/edge-runtime/lib/cjs.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Module, createRequire } from 'node:module'
|
|
2
2
|
import vm from 'node:vm'
|
|
3
3
|
import { sep } from 'node:path'
|
|
4
|
-
import { join, dirname, sep as posixSep } from 'node:path/posix'
|
|
4
|
+
import { join, dirname, sep as posixSep, resolve as pathResolve } from 'node:path/posix'
|
|
5
5
|
import { fileURLToPath, pathToFileURL } from 'node:url'
|
|
6
6
|
|
|
7
7
|
const toPosixPath = (path: string) => path.split(sep).join(posixSep)
|
|
@@ -13,8 +13,30 @@ type RegisteredModule = {
|
|
|
13
13
|
// lazily parsed json string
|
|
14
14
|
parsedJson?: any
|
|
15
15
|
}
|
|
16
|
-
type ModuleResolutions = (subpath: string) => string
|
|
17
|
-
|
|
16
|
+
type ModuleResolutions = (subpath: string, handleExportMap?: boolean) => string
|
|
17
|
+
|
|
18
|
+
const registeredSymlinks = new Map<string, string>()
|
|
19
|
+
|
|
20
|
+
class SymlinkAwareRegisteredModulesMap extends Map<string, RegisteredModule> {
|
|
21
|
+
private resolveSymlink(path: string) {
|
|
22
|
+
for (const [symlinkPath, targetPath] of registeredSymlinks) {
|
|
23
|
+
if (path === symlinkPath) {
|
|
24
|
+
return targetPath
|
|
25
|
+
}
|
|
26
|
+
if (path.startsWith(symlinkPath + '/')) {
|
|
27
|
+
return targetPath + path.slice(symlinkPath.length)
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return path
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
override get(key: string): RegisteredModule | undefined {
|
|
35
|
+
return super.get(this.resolveSymlink(key))
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const registeredModules = new SymlinkAwareRegisteredModulesMap()
|
|
18
40
|
const memoizedPackageResolvers = new WeakMap<RegisteredModule, ModuleResolutions>()
|
|
19
41
|
|
|
20
42
|
const require = createRequire(import.meta.url)
|
|
@@ -141,8 +163,8 @@ function getPackageResolver(packageJsonMatchedModule: RegisteredModule) {
|
|
|
141
163
|
: pkgJson.exports
|
|
142
164
|
}
|
|
143
165
|
|
|
144
|
-
const resolveInPackage: ModuleResolutions = (subpath: string) => {
|
|
145
|
-
if (exports) {
|
|
166
|
+
const resolveInPackage: ModuleResolutions = (subpath: string, handleExportMap = true) => {
|
|
167
|
+
if (handleExportMap && exports) {
|
|
146
168
|
const normalizedSubpath = subpath.length === 0 ? '.' : './' + subpath
|
|
147
169
|
|
|
148
170
|
// https://github.com/nodejs/node/blob/6fd67ec6e3ccbdfcfa0300b9b742040a0607a4bc/lib/internal/modules/esm/resolve.js#L594
|
|
@@ -186,8 +208,8 @@ function getPackageResolver(packageJsonMatchedModule: RegisteredModule) {
|
|
|
186
208
|
throw new Error(`Cannot find module '${normalizedSubpath}'`)
|
|
187
209
|
}
|
|
188
210
|
|
|
189
|
-
if (subpath.length === 0 && pkgJson.main) {
|
|
190
|
-
return pkgJson.main
|
|
211
|
+
if (subpath.length === 0 && pkgJson.main && typeof pkgJson.main === 'string') {
|
|
212
|
+
return pkgJson.main as string
|
|
191
213
|
}
|
|
192
214
|
|
|
193
215
|
return subpath
|
|
@@ -264,7 +286,11 @@ function tryMatchingWithIndex(target: string) {
|
|
|
264
286
|
return matchedModule
|
|
265
287
|
}
|
|
266
288
|
|
|
267
|
-
export function registerCJSModules(
|
|
289
|
+
export function registerCJSModules(
|
|
290
|
+
baseUrl: URL,
|
|
291
|
+
modules: Map<string, string>,
|
|
292
|
+
symlinks: Map<string, string> = new Map(),
|
|
293
|
+
) {
|
|
268
294
|
const basePath = dirname(toPosixPath(fileURLToPath(baseUrl, { windows: false })))
|
|
269
295
|
|
|
270
296
|
for (const [filename, source] of modules.entries()) {
|
|
@@ -272,6 +298,12 @@ export function registerCJSModules(baseUrl: URL, modules: Map<string, string>) {
|
|
|
272
298
|
registeredModules.set(target, { source, loaded: false, filepath: target })
|
|
273
299
|
}
|
|
274
300
|
|
|
301
|
+
for (const [symlinkPath, targetPath] of symlinks) {
|
|
302
|
+
const source = join(basePath, symlinkPath)
|
|
303
|
+
const target = pathResolve(dirname(source), targetPath)
|
|
304
|
+
registeredSymlinks.set(source, target)
|
|
305
|
+
}
|
|
306
|
+
|
|
275
307
|
if (!hookedIn) {
|
|
276
308
|
// @ts-expect-error - private untyped API
|
|
277
309
|
const original_resolveFilename = Module._resolveFilename.bind(Module)
|
|
@@ -309,7 +341,19 @@ export function registerCJSModules(baseUrl: URL, modules: Map<string, string>) {
|
|
|
309
341
|
relativeTarget = packageResolver(moduleInPackagePath)
|
|
310
342
|
}
|
|
311
343
|
|
|
312
|
-
|
|
344
|
+
let potentialPath = join(nodeModulePaths, packageName, relativeTarget)
|
|
345
|
+
|
|
346
|
+
// we need to also check if there is package.json at the potentialPath location
|
|
347
|
+
// as it might have "main" field that redirects further
|
|
348
|
+
const potentialNestedPackageJson = join(potentialPath, 'package.json')
|
|
349
|
+
const maybeNestedPackageJson = registeredModules.get(potentialNestedPackageJson)
|
|
350
|
+
if (maybeNestedPackageJson) {
|
|
351
|
+
const packageResolver = getPackageResolver(maybeNestedPackageJson)
|
|
352
|
+
const maybeMain = packageResolver('', false)
|
|
353
|
+
if (maybeMain) {
|
|
354
|
+
potentialPath = join(potentialPath, maybeMain)
|
|
355
|
+
}
|
|
356
|
+
}
|
|
313
357
|
|
|
314
358
|
matchedModule = tryMatchingWithIndex(potentialPath)
|
|
315
359
|
if (matchedModule) {
|