@netlify/plugin-nextjs
Advanced tools
Comparing version 5.3.3-canary-no-cache-fix.0 to 5.3.3
@@ -18,2 +18,5 @@ | ||
import { | ||
require_semver | ||
} from "../../esm-chunks/chunk-EFGWM7RS.js"; | ||
import { | ||
__toESM | ||
@@ -136,2 +139,3 @@ } from "../../esm-chunks/chunk-OEQOKJGE.js"; | ||
// src/build/content/prerendered.ts | ||
var import_semver = __toESM(require_semver(), 1); | ||
import { encodeBlobKey } from "../../shared/blobkey.js"; | ||
@@ -152,8 +156,18 @@ var tracer = wrapTracer(trace.getTracer("Next runtime")); | ||
pageData: JSON.parse(await readFile(`${path}.json`, "utf-8")), | ||
postponed: void 0, | ||
headers: void 0, | ||
status: void 0 | ||
}); | ||
var buildAppCacheValue = async (path) => { | ||
var buildAppCacheValue = async (path, shouldUseAppPageKind) => { | ||
const meta = JSON.parse(await readFile(`${path}.meta`, "utf-8")); | ||
const html = await readFile(`${path}.html`, "utf-8"); | ||
if (shouldUseAppPageKind) { | ||
return { | ||
kind: "APP_PAGE", | ||
html, | ||
rscData: await readFile(`${path}.rsc`, "base64").catch( | ||
() => readFile(`${path}.prefetch.rsc`, "base64") | ||
), | ||
...meta | ||
}; | ||
} | ||
const rsc = await readFile(`${path}.rsc`, "utf-8").catch( | ||
@@ -167,3 +181,3 @@ () => readFile(`${path}.prefetch.rsc`, "utf-8") | ||
kind: "PAGE", | ||
html: await readFile(`${path}.html`, "utf-8"), | ||
html, | ||
pageData: rsc, | ||
@@ -189,2 +203,5 @@ ...meta | ||
const limitConcurrentPrerenderContentHandling = pLimit(10); | ||
const shouldUseAppPageKind = ctx.nextVersion ? (0, import_semver.satisfies)(ctx.nextVersion, ">=15.0.0-canary.13 <15.0.0-d || >15.0.0-rc.0", { | ||
includePrerelease: true | ||
}) : false; | ||
await Promise.all( | ||
@@ -206,3 +223,6 @@ Object.entries(manifest.routes).map( | ||
case meta.dataRoute?.endsWith(".rsc"): | ||
value = await buildAppCacheValue(join(ctx.publishDir, "server/app", key)); | ||
value = await buildAppCacheValue( | ||
join(ctx.publishDir, "server/app", key), | ||
shouldUseAppPageKind | ||
); | ||
break; | ||
@@ -225,3 +245,6 @@ case meta.dataRoute === null: | ||
const key = "/404"; | ||
const value = await buildAppCacheValue(join(ctx.publishDir, "server/app/_not-found")); | ||
const value = await buildAppCacheValue( | ||
join(ctx.publishDir, "server/app/_not-found"), | ||
shouldUseAppPageKind | ||
); | ||
await writeCacheEntry(key, value, lastModified, ctx); | ||
@@ -228,0 +251,0 @@ } |
@@ -43,3 +43,2 @@ | ||
import { RUN_CONFIG } from "../../run/constants.js"; | ||
import { verifyNextVersion } from "../verification.js"; | ||
var tracer = wrapTracer(trace.getTracer("Next runtime")); | ||
@@ -195,14 +194,5 @@ var toPosixPath = (path) => path.split(sep).join(posixSep); | ||
const serverHandlerRequire = createRequire(posixJoin(ctx.serverHandlerDir, ":internal:")); | ||
let nextVersion; | ||
try { | ||
const { version } = serverHandlerRequire("next/package.json"); | ||
if (version) { | ||
nextVersion = version; | ||
} | ||
} catch { | ||
if (ctx.nextVersion) { | ||
await patchNextModules(ctx, ctx.nextVersion, serverHandlerRequire.resolve); | ||
} | ||
if (nextVersion) { | ||
verifyNextVersion(ctx, nextVersion); | ||
await patchNextModules(ctx, nextVersion, serverHandlerRequire.resolve); | ||
} | ||
try { | ||
@@ -209,0 +199,0 @@ const nextEntryAbsolutePath = serverHandlerRequire.resolve("next"); |
@@ -18,3 +18,5 @@ | ||
import { readFile } from "node:fs/promises"; | ||
import { createRequire } from "node:module"; | ||
import { join, relative, resolve } from "node:path"; | ||
import { join as posixJoin } from "node:path/posix"; | ||
import { fileURLToPath } from "node:url"; | ||
@@ -252,2 +254,18 @@ var MODULE_DIR = fileURLToPath(new URL(".", import.meta.url)); | ||
} | ||
#nextVersion = void 0; | ||
/** | ||
* Get Next.js version that was used to build the site | ||
*/ | ||
get nextVersion() { | ||
if (this.#nextVersion === void 0) { | ||
try { | ||
const serverHandlerRequire = createRequire(posixJoin(this.standaloneRootDir, ":internal:")); | ||
const { version } = serverHandlerRequire("next/package.json"); | ||
this.#nextVersion = version; | ||
} catch { | ||
this.#nextVersion = null; | ||
} | ||
} | ||
return this.#nextVersion; | ||
} | ||
/** Fails a build with a message and an optional error */ | ||
@@ -254,0 +272,0 @@ failBuild(message, error) { |
@@ -49,2 +49,7 @@ | ||
} | ||
if (ctx.nextVersion && !(0, import_semver.satisfies)(ctx.nextVersion, SUPPORTED_NEXT_VERSIONS, { includePrerelease: true })) { | ||
ctx.failBuild( | ||
`@netlify/plugin-next@5 requires Next.js version ${SUPPORTED_NEXT_VERSIONS}, but found ${ctx.nextVersion}. Please upgrade your project's Next.js version.` | ||
); | ||
} | ||
} | ||
@@ -62,9 +67,2 @@ if (ctx.buildConfig.output === "export") { | ||
} | ||
function verifyNextVersion(ctx, nextVersion) { | ||
if (!(0, import_semver.satisfies)(nextVersion, SUPPORTED_NEXT_VERSIONS, { includePrerelease: true })) { | ||
ctx.failBuild( | ||
`@netlify/plugin-next@5 requires Next.js version ${SUPPORTED_NEXT_VERSIONS}, but found ${nextVersion}. Please upgrade your project's Next.js version.` | ||
); | ||
} | ||
} | ||
async function verifyNoAdvancedAPIRoutes(ctx) { | ||
@@ -85,5 +83,4 @@ const apiRoutesConfigs = await getAPIRoutesConfigs(ctx); | ||
export { | ||
verifyNextVersion, | ||
verifyNoAdvancedAPIRoutes, | ||
verifyPublishDir | ||
}; |
@@ -24,2 +24,4 @@ | ||
...config.experimental, | ||
// @ts-expect-error incrementalCacheHandlerPath was removed from config type | ||
// but we still need to set it for older Next.js versions | ||
incrementalCacheHandlerPath: cacheHandler | ||
@@ -26,0 +28,0 @@ }; |
import type { Context } from '@netlify/edge-functions' | ||
import { addBasePath, normalizeDataUrl, normalizeLocalePath, removeBasePath } from './util.ts' | ||
import { | ||
addBasePath, | ||
addTrailingSlash, | ||
normalizeDataUrl, | ||
normalizeLocalePath, | ||
removeBasePath, | ||
} from './util.ts' | ||
@@ -44,18 +50,7 @@ interface I18NConfig { | ||
url.pathname = removeBasePath(url.pathname, nextConfig?.basePath) | ||
const didRemoveBasePath = url.toString() !== originalURL | ||
let pathname = removeBasePath(url.pathname, nextConfig?.basePath) | ||
let detectedLocale: string | undefined | ||
// If it exists, remove the locale from the URL and store it | ||
const { detectedLocale } = normalizeLocalePath(pathname, nextConfig?.i18n?.locales) | ||
if (nextConfig?.i18n) { | ||
const { pathname, detectedLocale: detected } = normalizeLocalePath( | ||
url.pathname, | ||
nextConfig?.i18n?.locales, | ||
) | ||
if (!nextConfig?.skipMiddlewareUrlNormalize) { | ||
url.pathname = pathname || '/' | ||
} | ||
detectedLocale = detected | ||
} | ||
if (!nextConfig?.skipMiddlewareUrlNormalize) { | ||
@@ -65,20 +60,13 @@ // We want to run middleware for data requests and expose the URL of the | ||
// the handler. | ||
url.pathname = normalizeDataUrl(url.pathname) | ||
pathname = normalizeDataUrl(pathname) | ||
// Normalizing the trailing slash based on the `trailingSlash` configuration | ||
// property from the Next.js config. | ||
if (nextConfig?.trailingSlash && url.pathname !== '/' && !url.pathname.endsWith('/')) { | ||
url.pathname = `${url.pathname}/` | ||
if (nextConfig?.trailingSlash) { | ||
pathname = addTrailingSlash(pathname) | ||
} | ||
} | ||
if (didRemoveBasePath) { | ||
url.pathname = addBasePath(url.pathname, nextConfig?.basePath) | ||
} | ||
url.pathname = addBasePath(pathname, nextConfig?.basePath) | ||
// keep the locale in the url for request.nextUrl object | ||
if (detectedLocale) { | ||
url.pathname = `/${detectedLocale}${url.pathname}` | ||
} | ||
return { | ||
@@ -85,0 +73,0 @@ url: url.toString(), |
{ | ||
"name": "@netlify/plugin-nextjs", | ||
"version": "5.3.3-canary-no-cache-fix.0", | ||
"version": "5.3.3", | ||
"description": "Run Next.js seamlessly on Netlify", | ||
@@ -17,3 +17,3 @@ "main": "./dist/index.js", | ||
"type": "git", | ||
"url": "git+https://github.com/netlify/next-runtime-minimal.git" | ||
"url": "git+https://github.com/netlify/next-runtime.git" | ||
}, | ||
@@ -28,5 +28,5 @@ "keywords": [ | ||
"bugs": { | ||
"url": "https://github.com/netlify/next-runtime-minimal/issues" | ||
"url": "https://github.com/netlify/next-runtime/issues" | ||
}, | ||
"homepage": "https://github.com/netlify/next-runtime-minimal#readme" | ||
"homepage": "https://github.com/netlify/next-runtime#readme" | ||
} |
@@ -1,4 +0,4 @@ | ||
![Next.js Runtime](https://github.com/netlify/next-runtime/raw/main/next-js-runtime.png) | ||
![Next.js Runtime](next-js-runtime.png) | ||
# `@netlify/plugin-nextjs` | ||
# Next.js Runtime | ||
@@ -19,1 +19,61 @@ <p align="center"> | ||
more details. | ||
Next.js is supported natively on Netlify, and in most cases you will not need to install or | ||
configure anything. This repo includes the packages used to support Next.js on Netlify. | ||
## Prerequisites | ||
- Next.js 13.5 or later | ||
- Node.js 18 or later | ||
- The latest version of the [Netlify CLI](https://docs.netlify.com/cli/get-started/) | ||
## Deploying | ||
If you build on Netlify, the Next.js Runtime will work with no additional configuration. | ||
## Manually installing the Next.js Runtime | ||
The Next.js Runtime installs automatically for new Next.js sites on Netlify. You can also install it | ||
manually in the following ways: | ||
### From the UI (Recommended) | ||
You can go to the [UI](https://app.netlify.com/plugins/@netlify/plugin-nextjs/install) and choose | ||
the site to install the Next.js Runtime on. This method is recommended because you will benefit from | ||
auto-upgrades to important fixes and feature updates. | ||
### From `npm` | ||
```shell | ||
npm install -D @netlify/plugin-nextjs | ||
``` | ||
...then add the following to your `netlify.toml` file: | ||
```toml | ||
[[plugins]] | ||
package = "@netlify/plugin-nextjs" | ||
``` | ||
This method is recommended if you wish to pin the Next.js Runtime to a specific version. | ||
## v4 | ||
If you are using Next.js 10-13.4 or Node.js < 18, you must use v4 of the Next.js Runtime. | ||
If you are still using v4, you can find | ||
[its README here](https://github.com/netlify/next-runtime/blob/v4/README.md) and the | ||
[v4 Runtime docs here](https://docs.netlify.com/frameworks/next-js/runtime-v4/overview/). | ||
### Upgrading from v4 to v5 | ||
To upgrade from v4 to v5, please visit | ||
[the v5 documentation](https://docs.netlify.com/frameworks/next-js/overview/). | ||
## Feedback | ||
If you think you have found a bug in Next.js on Netlify, | ||
[please open an issue](https://github.com/netlify/next-runtime/issues). If you have comments or | ||
feature requests, [see the discussion board](https://github.com/netlify/next-runtime/discussions) | ||
Please note that v4 will only receive security fixes and critical bug fixes. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
5244227
137095
1
0
79