Skip to content

Commit 10ff24e

Browse files
committed
Merge branch 'mk/self-global' of github.com:netlify/next-runtime into mk/self-global
2 parents 181f553 + 29c85a9 commit 10ff24e

File tree

5 files changed

+28
-12
lines changed

5 files changed

+28
-12
lines changed

README.md

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ by targeting the `/_next/image/*` route:
4444

4545
## Disabling included image loader
4646

47-
If you wish to disable the use of the image loader which is bundled into the runtime by default, set the `DISABLE_IPX` environment variable to `true`.
47+
If you wish to disable the use of the image loader which is bundled into the runtime by default, set the `DISABLE_IPX` environment variable to `true`.
4848

4949
This should only be done if the site is not using `next/image` or is using a different loader (such as Cloudinary or Imgix).
5050

@@ -60,7 +60,7 @@ For more details on Next.js Middleware with Netlify, see the [middleware docs](h
6060

6161
### Limitations
6262

63-
Due to how the site configuration is handled when it's run using Netlify Edge Functions, data such as `locale` and `defaultLocale` will be missing on the `req.nextUrl` object when running `netlify dev`.
63+
Due to how the site configuration is handled when it's run using Netlify Edge Functions, data such as `locale` and `defaultLocale` will be missing on the `req.nextUrl` object when running `netlify dev`.
6464

6565
However, this data is available on `req.nextUrl` in a production environment.
6666

@@ -107,7 +107,15 @@ Edge runtime or middleware is enabled it will also generate edge functions for m
107107

108108
## Manually installing the Next.js Runtime
109109

110-
The Next.js Runtime installs automatically for new Next.js sites on Netlify. You can also install it manually like this:
110+
The Next.js Runtime installs automatically for new Next.js sites on Netlify. You can also install it manually in the
111+
following ways:
112+
113+
### From the UI (Recommended):
114+
115+
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
116+
is recommended because you will benefit from auto-upgrades to important fixes and feature updates.
117+
118+
### From `npm`:
111119

112120
```shell
113121
npm install -D @netlify/plugin-nextjs
@@ -117,9 +125,11 @@ npm install -D @netlify/plugin-nextjs
117125

118126
```toml
119127
[[plugins]]
120-
package = "@netlify/plugin-nextjs"
128+
package = "@netlify/plugin-nextjs"
121129
```
122130

131+
This method is recommended if you wish to pin the Next.js Runtime to a specific version.
132+
123133
## Manually upgrading from an older version of the Next.js Runtime
124134

125135
If you previously set these values, they're no longer needed and should be removed:
@@ -139,7 +149,7 @@ information on changes to how they are handled in this version. In particular, n
139149
files must be placed in `public`, not in the root of the site.
140150

141151
## Using with pnpm
142-
If your site uses pnpm to manage dependencies, currently you must [enable public hoisting](https://pnpm.io/npmrc#public-hoist-pattern).
152+
If your site uses pnpm to manage dependencies, currently you must [enable public hoisting](https://pnpm.io/npmrc#public-hoist-pattern).
143153
The simplest way to do this is to create a `.npmrc` file in the root of your project with the content:
144154

145155
```ini

packages/runtime/src/helpers/edge.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ const fetch = async (url, init) => {
117117
}
118118
119119
// Next edge runtime uses "self" as a function-scoped global-like object, but some of the older polyfills expect it to equal globalThis
120+
// See https://nextjs.org/docs/basic-features/supported-browsers-features#polyfills
120121
const self = { ...globalThis, fetch }
121122
122123
`

packages/runtime/src/helpers/files.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -337,11 +337,13 @@ const getServerFile = (root: string, includeBase = true) => {
337337
/**
338338
* Find the source file for a given page route
339339
*/
340-
export const getSourceFileForPage = (page: string, root: string) => {
341-
for (const extension of SOURCE_FILE_EXTENSIONS) {
342-
const file = join(root, `${page}.${extension}`)
343-
if (existsSync(file)) {
344-
return file
340+
export const getSourceFileForPage = (page: string, roots: string[]) => {
341+
for (const root of roots) {
342+
for (const extension of SOURCE_FILE_EXTENSIONS) {
343+
const file = join(root, `${page}.${extension}`)
344+
if (existsSync(file)) {
345+
return file
346+
}
345347
}
346348
}
347349
console.log('Could not find source file for page', page)

packages/runtime/src/helpers/functions.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,11 +169,14 @@ export const setupImageFunction = async ({
169169
export const getApiRouteConfigs = async (publish: string, baseDir: string): Promise<Array<ApiRouteConfig>> => {
170170
const pages = await readJSON(join(publish, 'server', 'pages-manifest.json'))
171171
const apiRoutes = Object.keys(pages).filter((page) => page.startsWith('/api/'))
172+
// two possible places
173+
// Ref: https://nextjs.org/docs/advanced-features/src-directory
172174
const pagesDir = join(baseDir, 'pages')
175+
const srcPagesDir = join(baseDir, 'src', 'pages')
173176

174177
return await Promise.all(
175178
apiRoutes.map(async (apiRoute) => {
176-
const filePath = getSourceFileForPage(apiRoute, pagesDir)
179+
const filePath = getSourceFileForPage(apiRoute, [pagesDir, srcPagesDir])
177180
return { route: apiRoute, config: await extractConfigFromFile(filePath), compiled: pages[apiRoute] }
178181
}),
179182
)

test/e2e/jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const config = {
1414
'\\.[jt]sx?$': 'babel-jest',
1515
},
1616
verbose: true,
17-
testTimeout: 60000,
17+
testTimeout: 300000,
1818
moduleFileExtensions: ['js', 'jsx', 'ts', 'tsx'],
1919
moduleNameMapper: {
2020
'e2e-utils': '<rootDir>/next-test-lib/e2e-utils.ts',

0 commit comments

Comments
 (0)