[fs-detectors] Exclude the middleware builder if it's a Next.js app (#8239)

This commit is contained in:
Seiya Nuta
2022-08-01 21:18:29 +09:00
committed by GitHub
parent fc3fa61b59
commit 71b3ded398
2 changed files with 44 additions and 1 deletions

View File

@@ -99,7 +99,7 @@ export async function detectBuilders(
const errors: ErrorResponse[] = [];
const warnings: ErrorResponse[] = [];
const apiBuilders: Builder[] = [];
let apiBuilders: Builder[] = [];
let frontendBuilder: Builder | null = null;
const functionError = validateFunctions(options);
@@ -305,6 +305,24 @@ export async function detectBuilders(
};
}
// Exclude the middleware builder for Next.js apps since @vercel/next
// will build middlewares.
//
// While maybeGetApiBuilder() excludes the middleware builder, however,
// we need to check if it's a Next.js app here again for the case where
// `projectSettings.framework == null`.
if (
framework === null &&
frontendBuilder?.use === '@vercel/next' &&
apiBuilders.length > 0
) {
apiBuilders = apiBuilders.filter(builder => {
const isMiddlewareBuilder =
builder.use === '@vercel/node' && builder.config?.middleware;
return !isMiddlewareBuilder;
});
}
const builders: Builder[] = [];
if (apiBuilders.length) {

View File

@@ -2281,6 +2281,31 @@ describe('Test `detectBuilders` with `featHandleMiss=true`', () => {
},
]);
});
it('should not add middleware builder when building "nextjs"', async () => {
const files = ['package.json', 'pages/index.ts', 'middleware.ts'];
const pkg = {
scripts: { build: 'next build' },
dependencies: { next: '12.2.0' },
};
const projectSettings = {
framework: null, // "Other" framework
createdAt: Date.parse('2020-02-01'),
};
const { builders } = await detectBuilders(files, pkg, {
projectSettings,
featHandleMiss,
});
expect(builders).toEqual([
{
use: '@vercel/next',
src: 'package.json',
config: {
zeroConfig: true,
},
},
]);
});
});
it('Test `detectRoutes`', async () => {