Skip to content

Commit

Permalink
update e2es to handle next.config.mjs files and update next-dev R…
Browse files Browse the repository at this point in the history
…EADME (#652)

* update e2es to handle next.config.mjs files

since 14.1.0 `create-next-app` generates a next.config.mjs file as the default config
one (instead of next.config.js), thus the e2es need to be updated so that they properly
handle such new default

* reference next.config.mjs instead of next.config.js in the md docs

* reference next.config.mjs in code comments and eslint-plugin messages

* pin node version in github actions to 20.10.0

* pin vitest version to 0.32.4
  • Loading branch information
dario-piotrowicz authored Feb 1, 2024
1 parent 52499eb commit f58ace8
Show file tree
Hide file tree
Showing 32 changed files with 68 additions and 87 deletions.
4 changes: 2 additions & 2 deletions .github/actions/node-setup/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ inputs:
runs:
using: composite
steps:
- name: Setup Node.js 20.x
- name: Setup Node.js 20.10.0
uses: actions/setup-node@v3
with:
node-version: 20.x
node-version: 20.10.0

- name: Get current node version
id: node-version
Expand Down
6 changes: 3 additions & 3 deletions docs/technical/routing.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ At the start of the routing process, there is typically a series of source route

During this phase, a number of events may happen. Some of the Next.js features that it handles are as follows.

- `next.config.js`
- `next.config.mjs`
- Applying [`headers`](https://nextjs.org/docs/pages/api-reference/next-config-js/headers).
- Applying [`redirects`](https://nextjs.org/docs/pages/api-reference/next-config-js/redirects).
- Applying `beforeFiles` [`rewrites`](https://nextjs.org/docs/pages/api-reference/next-config-js/rewrites).
Expand All @@ -43,7 +43,7 @@ When checking that routes exist in the build output, it only looks for static as

If a file is not found in the build output at the start of routing (after the `none` phase), the system enters the `filesystem` phase. Here, it will handle another Next.js feature.

- `next.config.js`
- `next.config.mjs`
- Applying `afterFiles` [`rewrites`](https://nextjs.org/docs/pages/api-reference/next-config-js/rewrites).

The only routes checked in the build output with this phase are those that result from `afterFiles` `rewrites`.
Expand All @@ -69,7 +69,7 @@ This could be considered the penultimate stage in the routing system, as it is t

The `resource` phase handles any remaining user-specified rewrites, and then checks the build output for any remaining routes. Further, it sets the status to 404 for any other routes that have not had a match yet.

- `next.config.js`
- `next.config.mjs`
- Applying `fallback` [`rewrites`](https://nextjs.org/docs/pages/api-reference/next-config-js/rewrites).

### `miss`
Expand Down
8 changes: 4 additions & 4 deletions internal-packages/docs-scraper/scripts/createOrUpdateIssue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ void (async function (): Promise<void> {
owner: context.repo.owner,
repo: context.repo.repo,
labels: [label],
title: '⚠️📄 The `next.config.js` supported doc is out of date 📄⚠️',
title: '⚠️📄 The `next.config.mjs` supported doc is out of date 📄⚠️',
body: issueBody,
});
} else {
Expand All @@ -74,18 +74,18 @@ function generateIssueBody(
documentedNonNextConfigs: string[],
): string {
let issueBody =
'### The next-on-pages documentation of the next.config.js options is out of date\n';
'### The next-on-pages documentation of the next.config.mjs options is out of date\n';

if (undocumentedNextConfigs.length > 0) {
issueBody += `\n\n${generateMdList(
'The following next.config.js configs are not documented in our supported doc',
'The following next.config.mjs configs are not documented in our supported doc',
undocumentedNextConfigs,
)}`;
}

if (documentedNonNextConfigs.length > 0) {
issueBody += `\n\n${generateMdList(
'The following configs present in our supported doc are not present in the next.config.js documentation pages',
'The following configs present in our supported doc are not present in the next.config.mjs documentation pages',
documentedNonNextConfigs,
)}`;
}
Expand Down
10 changes: 5 additions & 5 deletions internal-packages/next-dev/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@ IMPORTANT: As mentioned above the module allows you to run the standard Next.js

## How to use the module

The module is part of the `@cloudflare/next-on-pages` package so it does not need installation, it exports the `setupDevBindings` function which you need to import and call in your `next.config.js` file to declare what bindings your application is using and need to be made available in the development server.
The module is part of the `@cloudflare/next-on-pages` package so it does not need installation, it exports the `setupDevBindings` function which you need to import and call in your `next.config.mjs` file to declare what bindings your application is using and need to be made available in the development server.

After having added the `setupDevBindings` call to the `next.config.js` you can simply run `next dev` and inside your edge routes you will be able to access your bindings via `process.env` in the exact same way as you would in your production code.
After having added the `setupDevBindings` call to the `next.config.mjs` you can simply run `next dev` and inside your edge routes you will be able to access your bindings via `process.env` in the exact same way as you would in your production code.

### Example

Let's see an example of how to use the utility, in a Next.js application built in TypeScript using the App router.

Firstly we need to update the `next.config.js` file:
Firstly we need to update the `next.config.mjs` file:

```js
// file: next.config.js
// file: next.config.mjs

/** @type {import('next').NextConfig} */
const nextConfig = {};

module.exports = nextConfig;
export default nextConfig;

// we only need to use the utility during development so we can check NODE_ENV
// (note: this check is recommended but completely optional)
Expand Down
34 changes: 6 additions & 28 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit f58ace8

Please sign in to comment.