mirror of
https://github.com/LukeHagar/vercel.git
synced 2025-12-10 12:57:47 +00:00
[fs-detectors] Exclude the middleware builder if it's a Next.js app (#8239)
This commit is contained in:
@@ -99,7 +99,7 @@ export async function detectBuilders(
|
|||||||
const errors: ErrorResponse[] = [];
|
const errors: ErrorResponse[] = [];
|
||||||
const warnings: ErrorResponse[] = [];
|
const warnings: ErrorResponse[] = [];
|
||||||
|
|
||||||
const apiBuilders: Builder[] = [];
|
let apiBuilders: Builder[] = [];
|
||||||
let frontendBuilder: Builder | null = null;
|
let frontendBuilder: Builder | null = null;
|
||||||
|
|
||||||
const functionError = validateFunctions(options);
|
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[] = [];
|
const builders: Builder[] = [];
|
||||||
|
|
||||||
if (apiBuilders.length) {
|
if (apiBuilders.length) {
|
||||||
|
|||||||
@@ -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 () => {
|
it('Test `detectRoutes`', async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user