Skip to content

Commit 2f212e3

Browse files
authoredAug 22, 2023
fix: add middleware to default nextjs config plugin (#212)
1 parent af83f22 commit 2f212e3

File tree

8 files changed

+54
-1
lines changed

8 files changed

+54
-1
lines changed
 

‎fixtures/nextjs/next.config.js

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/** @type {import('next').NextConfig} */
2+
const nextConfig = {}
3+
4+
module.exports = nextConfig

‎fixtures/nextjs/package.json

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"name": "@fixtures/nextjs",
3+
"dependencies": {
4+
"next": "*"
5+
}
6+
}

‎fixtures/nextjs/src/app/page.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default function Page() {
2+
return <div>Page</div>;
3+
};

‎fixtures/nextjs/src/middleware.ts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export function middleware() {
2+
console.log('log from middleware')
3+
}

‎fixtures/nextjs/tsconfig.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"compilerOptions": {
3+
"jsx": "react-jsx"
4+
}
5+
}

‎src/plugins/next/README.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,13 @@ or `devDependencies`:
1212
```json
1313
{
1414
"next": {
15-
"entry": ["next.config.{js,ts,cjs,mjs}", "{app,pages}/**/*.{js,jsx,ts,tsx}", "src/{app,pages}/**/*.{js,jsx,ts,tsx}"]
15+
"entry": [
16+
"next.config.{js,ts,cjs,mjs}",
17+
"{app,pages}/**/*.{js,jsx,ts,tsx}",
18+
"src/{app,pages}/**/*.{js,jsx,ts,tsx}",
19+
"middleware.{js,ts}",
20+
"src/middleware.{js,ts}"
21+
]
1622
}
1723
}
1824
```

‎src/plugins/next/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,6 @@ export const ENTRY_FILE_PATTERNS = ['next.config.{js,ts,cjs,mjs}'];
1515
export const PRODUCTION_ENTRY_FILE_PATTERNS = [
1616
'{app,pages}/**/*.{js,jsx,ts,tsx}',
1717
'src/{app,pages}/**/*.{js,jsx,ts,tsx}',
18+
'middleware.{js,ts}',
19+
'src/middleware.{js,ts}',
1820
];

‎tests/nextjs.test.ts

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import assert from 'node:assert/strict';
2+
import test from 'node:test';
3+
import { main } from '../src/index.js';
4+
import { resolve } from '../src/util/path.js';
5+
import baseArguments from './helpers/baseArguments.js';
6+
import baseCounters from './helpers/baseCounters.js';
7+
8+
test('Support NextJS files', async () => {
9+
const cwd = resolve('fixtures/nextjs');
10+
11+
const { counters } = await main({
12+
...baseArguments,
13+
cwd,
14+
});
15+
16+
console.log({ counters });
17+
18+
assert.deepEqual(counters, {
19+
...baseCounters,
20+
dependencies: 0,
21+
processed: 3,
22+
total: 3,
23+
});
24+
});

0 commit comments

Comments
 (0)
Please sign in to comment.