[cli] Remove "now" from variable names in vc dev (#6483)

This commit is contained in:
Nathan Rajlich
2021-07-19 10:32:21 -07:00
committed by GitHub
parent e37e558674
commit 8cc72a6872
9 changed files with 160 additions and 154 deletions

View File

@@ -246,20 +246,18 @@ export default class DevServer {
}
}
const nowConfig = await this.getVercelConfig();
const vercelConfig = await this.getVercelConfig();
// Update the build matches in case an entrypoint was created or deleted
await this.updateBuildMatches(nowConfig);
await this.updateBuildMatches(vercelConfig);
const filesChangedArray = [...filesChanged];
const filesRemovedArray = [...filesRemoved];
// Trigger rebuilds of any existing builds that are dependent
// on one of the files that has changed
const needsRebuild: Map<
BuildResult,
[string | null, BuildMatch]
> = new Map();
const needsRebuild: Map<BuildResult, [string | null, BuildMatch]> =
new Map();
for (const match of this.buildMatches.values()) {
for (const [requestPath, result] of match.buildResults) {
@@ -292,13 +290,19 @@ export default class DevServer {
for (const [result, [requestPath, match]] of needsRebuild) {
if (
requestPath === null ||
(await shouldServe(match, this.files, requestPath, this, nowConfig))
(await shouldServe(
match,
this.files,
requestPath,
this,
vercelConfig
))
) {
this.triggerBuild(
match,
requestPath,
null,
nowConfig,
vercelConfig,
result,
filesChangedArray,
filesRemovedArray
@@ -377,12 +381,12 @@ export default class DevServer {
}
async updateBuildMatches(
nowConfig: VercelConfig,
vercelConfig: VercelConfig,
isInitial = false
): Promise<void> {
const fileList = this.resolveBuildFiles(this.files);
const matches = await getBuildMatches(
nowConfig,
vercelConfig,
this.cwd,
this.output,
this,
@@ -419,7 +423,7 @@ export default class DevServer {
this.buildMatches.set(match.src, match);
if (!isInitial && needsBlockingBuild(match)) {
const buildPromise = executeBuild(
nowConfig,
vercelConfig,
this,
this.files,
match,
@@ -462,7 +466,7 @@ export default class DevServer {
}
async invalidateBuildMatches(
nowConfig: VercelConfig,
vercelConfig: VercelConfig,
updatedBuilders: string[]
): Promise<void> {
if (updatedBuilders.length === 0) {
@@ -485,7 +489,7 @@ export default class DevServer {
}
// Re-add the build matches that were just removed, but with the new builder
await this.updateBuildMatches(nowConfig);
await this.updateBuildMatches(vercelConfig);
}
async getLocalEnv(fileName: string, base?: Env): Promise<Env> {
@@ -542,26 +546,26 @@ export default class DevServer {
pkg = null,
// The default empty `vercel.json` is used to serve all
// files as static when no `vercel.json` is present
config = { version: 2, [fileNameSymbol]: 'vercel.json' },
vercelConfig = { version: 2, [fileNameSymbol]: 'vercel.json' },
] = await Promise.all([
this.readJsonFile<PackageJson>('package.json'),
this.readJsonFile<VercelConfig>(configPath),
]);
await this.validateVercelConfig(config);
await this.validateVercelConfig(vercelConfig);
const { error: routeError, routes: maybeRoutes } = getTransformedRoutes({
nowConfig: config,
nowConfig: vercelConfig,
});
if (routeError) {
this.output.prettyError(routeError);
await this.exit();
}
config.routes = maybeRoutes || [];
vercelConfig.routes = maybeRoutes || [];
// no builds -> zero config
if (!config.builds || config.builds.length === 0) {
if (!vercelConfig.builds || vercelConfig.builds.length === 0) {
const featHandleMiss = true; // enable for zero config
const { projectSettings, cleanUrls, trailingSlash } = config;
const { projectSettings, cleanUrls, trailingSlash } = vercelConfig;
const opts = { output: this.output };
const files = (await getFiles(this.cwd, opts)).map(f =>
@@ -578,7 +582,7 @@ export default class DevServer {
errorRoutes,
} = await detectBuilders(files, pkg, {
tag: getDistTag(cliPkg.version) === 'canary' ? 'canary' : 'latest',
functions: config.functions,
functions: vercelConfig.functions,
projectSettings: projectSettings || this.projectSettings,
featHandleMiss,
cleanUrls,
@@ -601,18 +605,17 @@ export default class DevServer {
builders = builders.filter(filterFrontendBuilds);
}
config.builds = config.builds || [];
config.builds.push(...builders);
vercelConfig.builds = vercelConfig.builds || [];
vercelConfig.builds.push(...builders);
delete config.functions;
delete vercelConfig.functions;
}
let routes: Route[] = [];
const { routes: nowConfigRoutes } = config;
routes.push(...(redirectRoutes || []));
routes.push(
...appendRoutesToPhase({
routes: nowConfigRoutes,
routes: vercelConfig.routes,
newRoutes: rewriteRoutes,
phase: 'filesystem',
})
@@ -623,28 +626,28 @@ export default class DevServer {
phase: 'error',
});
routes.push(...(defaultRoutes || []));
config.routes = routes;
vercelConfig.routes = routes;
}
if (Array.isArray(config.builds)) {
if (Array.isArray(vercelConfig.builds)) {
if (this.devCommand) {
config.builds = config.builds.filter(filterFrontendBuilds);
vercelConfig.builds = vercelConfig.builds.filter(filterFrontendBuilds);
}
// `@vercel/static-build` needs to be the last builder
// since it might catch all other requests
config.builds.sort(sortBuilders);
vercelConfig.builds.sort(sortBuilders);
}
await this.validateVercelConfig(config);
await this.validateVercelConfig(vercelConfig);
// TODO: temporarily strip and warn since `has` is not implemented yet
config.routes = (config.routes || []).filter(route => {
vercelConfig.routes = (vercelConfig.routes || []).filter(route => {
if ('has' in route) {
if (!this.vercelConfigWarning) {
this.vercelConfigWarning = true;
this.output.warn(
`The "has" property in ${config[fileNameSymbol]} will be ignored during development. Deployments will work as expected.`
`The "has" property in ${vercelConfig[fileNameSymbol]} will be ignored during development. Deployments will work as expected.`
);
}
return false;
@@ -652,14 +655,14 @@ export default class DevServer {
return true;
});
this.caseSensitive = hasNewRoutingProperties(config);
this.apiDir = detectApiDirectory(config.builds || []);
this.apiExtensions = detectApiExtensions(config.builds || []);
this.caseSensitive = hasNewRoutingProperties(vercelConfig);
this.apiDir = detectApiDirectory(vercelConfig.builds || []);
this.apiExtensions = detectApiExtensions(vercelConfig.builds || []);
// Update the env vars configuration
let [runEnv, buildEnv] = await Promise.all([
this.getLocalEnv('.env', config.env),
this.getLocalEnv('.env.build', config.build?.env),
this.getLocalEnv('.env', vercelConfig.env),
this.getLocalEnv('.env.build', vercelConfig.build?.env),
]);
let allEnv = { ...buildEnv, ...runEnv };
@@ -691,7 +694,7 @@ export default class DevServer {
}
this.envConfigs = { buildEnv, runEnv, allEnv };
return config;
return vercelConfig;
}
async readJsonFile<T>(
@@ -871,7 +874,7 @@ export default class DevServer {
.replace('[::]', 'localhost')
.replace('127.0.0.1', 'localhost');
const nowConfig = await this.getVercelConfig();
const vercelConfig = await this.getVercelConfig();
const devCommandPromise = this.runDevCommand();
const files = await getFiles(this.cwd, { output: this.output });
@@ -887,13 +890,13 @@ export default class DevServer {
}
const builders = new Set<string>(
(nowConfig.builds || [])
(vercelConfig.builds || [])
.filter((b: Builder) => b.use)
.map((b: Builder) => b.use)
);
await installBuilders(builders, this.output);
await this.updateBuildMatches(nowConfig, true);
await this.updateBuildMatches(vercelConfig, true);
// Updating builders happens lazily, and any builders that were updated
// get their "build matches" invalidated so that the new version is used.
@@ -901,7 +904,7 @@ export default class DevServer {
this.updateBuildersPromise = updateBuilders(builders, this.output)
.then(updatedBuilders => {
this.updateBuildersPromise = null;
this.invalidateBuildMatches(nowConfig, updatedBuilders);
this.invalidateBuildMatches(vercelConfig, updatedBuilders);
})
.catch(err => {
this.updateBuildersPromise = null;
@@ -922,7 +925,7 @@ export default class DevServer {
);
for (const match of blockingBuilds) {
await executeBuild(nowConfig, this, this.files, match, null, true);
await executeBuild(vercelConfig, this, this.files, match, null, true);
}
this.output.success('Build completed');
@@ -1062,21 +1065,21 @@ export default class DevServer {
async send404(
req: http.IncomingMessage,
res: http.ServerResponse,
nowRequestId: string
requestId: string
): Promise<void> {
return this.sendError(req, res, nowRequestId, 'NOT_FOUND', 404);
return this.sendError(req, res, requestId, 'NOT_FOUND', 404);
}
async sendError(
req: http.IncomingMessage,
res: http.ServerResponse,
nowRequestId: string,
requestId: string,
errorCode?: string,
statusCode: number = 500,
headers: HttpHeadersConfig = {}
): Promise<void> {
res.statusCode = statusCode;
this.setResponseHeaders(res, nowRequestId, headers);
this.setResponseHeaders(res, requestId, headers);
const http_status_description = generateHttpStatusDescription(statusCode);
const error_code = errorCode || http_status_description;
@@ -1103,7 +1106,7 @@ export default class DevServer {
http_status_code: statusCode,
http_status_description,
error_code,
now_id: nowRequestId,
request_id: requestId,
});
} else if (statusCode === 502) {
view = errorTemplate502({
@@ -1111,13 +1114,13 @@ export default class DevServer {
http_status_code: statusCode,
http_status_description,
error_code,
now_id: nowRequestId,
request_id: requestId,
});
} else {
view = errorTemplate({
http_status_code: statusCode,
http_status_description,
now_id: nowRequestId,
request_id: requestId,
});
}
body = errorTemplateBase({
@@ -1135,14 +1138,14 @@ export default class DevServer {
async sendRedirect(
req: http.IncomingMessage,
res: http.ServerResponse,
nowRequestId: string,
requestId: string,
location: string,
statusCode: number = 302
): Promise<void> {
this.output.debug(`Redirect ${statusCode}: ${location}`);
res.statusCode = statusCode;
this.setResponseHeaders(res, nowRequestId, { location });
this.setResponseHeaders(res, requestId, { location });
let body: string;
const { accept = 'text/plain' } = req.headers;
@@ -1173,14 +1176,14 @@ export default class DevServer {
*/
setResponseHeaders(
res: http.ServerResponse,
nowRequestId: string,
requestId: string,
headers: http.OutgoingHttpHeaders = {}
): void {
const allHeaders = {
'cache-control': 'public, max-age=0, must-revalidate',
...headers,
server: 'Vercel',
'x-vercel-id': nowRequestId,
'x-vercel-id': requestId,
'x-vercel-cache': 'MISS',
};
for (const [name, value] of Object.entries(allHeaders)) {
@@ -1191,9 +1194,9 @@ export default class DevServer {
/**
* Returns the request `headers` that will be sent to the Lambda.
*/
getNowProxyHeaders(
getProxyHeaders(
req: http.IncomingMessage,
nowRequestId: string,
requestId: string,
xfwd: boolean
): http.IncomingHttpHeaders {
const ip = this.getRequestIp(req);
@@ -1203,7 +1206,7 @@ export default class DevServer {
'x-real-ip': ip,
'x-vercel-deployment-url': host,
'x-vercel-forwarded-for': ip,
'x-vercel-id': nowRequestId,
'x-vercel-id': requestId,
};
if (xfwd) {
headers['x-forwarded-host'] = host;
@@ -1217,7 +1220,7 @@ export default class DevServer {
match: BuildMatch,
requestPath: string | null,
req: http.IncomingMessage | null,
nowConfig: VercelConfig,
vercelConfig: VercelConfig,
previousBuildResult?: BuildResult,
filesChanged?: string[],
filesRemoved?: string[]
@@ -1253,7 +1256,7 @@ export default class DevServer {
}
this.output.debug(msg);
buildPromise = executeBuild(
nowConfig,
vercelConfig,
this,
this.files,
match,
@@ -1294,11 +1297,11 @@ export default class DevServer {
) => {
await this.startPromise;
let nowRequestId = generateRequestId(this.podId);
let requestId = generateRequestId(this.podId);
if (this.stopping) {
res.setHeader('Connection', 'close');
await this.send404(req, res, nowRequestId);
await this.send404(req, res, requestId);
return;
}
@@ -1306,8 +1309,8 @@ export default class DevServer {
this.output.debug(`${chalk.bold(method)} ${req.url}`);
try {
const nowConfig = await this.getVercelConfig();
await this.serveProjectAsNowV2(req, res, nowRequestId, nowConfig);
const vercelConfig = await this.getVercelConfig();
await this.serveProjectAsNowV2(req, res, requestId, vercelConfig);
} catch (err) {
console.error(err);
this.output.debug(err.stack);
@@ -1328,20 +1331,20 @@ export default class DevServer {
phase: HandleValue | null,
req: http.IncomingMessage,
res: http.ServerResponse,
nowRequestId: string
requestId: string
): Promise<boolean> => {
const { status, headers, dest } = routeResult;
const location = headers['location'] || dest;
if (status && location && 300 <= status && status <= 399) {
this.output.debug(`Route found with redirect status code ${status}`);
await this.sendRedirect(req, res, nowRequestId, location, status);
await this.sendRedirect(req, res, requestId, location, status);
return true;
}
if (!match && status && phase !== 'miss') {
this.output.debug(`Route found with with status code ${status}`);
await this.sendError(req, res, nowRequestId, '', status, headers);
await this.sendError(req, res, requestId, '', status, headers);
return true;
}
@@ -1354,9 +1357,9 @@ export default class DevServer {
serveProjectAsNowV2 = async (
req: http.IncomingMessage,
res: http.ServerResponse,
nowRequestId: string,
nowConfig: VercelConfig,
routes: Route[] | undefined = nowConfig.routes,
requestId: string,
vercelConfig: VercelConfig,
routes: Route[] | undefined = vercelConfig.routes,
callLevel: number = 0
) => {
const { debug } = this.output;
@@ -1373,7 +1376,7 @@ export default class DevServer {
// Only `GET` requests are redirected.
// Other methods are normalized without redirecting.
if (req.method === 'GET') {
await this.sendRedirect(req, res, nowRequestId, location, 301);
await this.sendRedirect(req, res, requestId, location, 301);
return;
}
@@ -1382,7 +1385,7 @@ export default class DevServer {
}
if (callLevel === 0) {
await this.updateBuildMatches(nowConfig);
await this.updateBuildMatches(vercelConfig);
}
if (this.blockingBuildsPromise) {
@@ -1424,7 +1427,7 @@ export default class DevServer {
req.method,
phaseRoutes,
this,
nowConfig,
vercelConfig,
prevHeaders,
missRoutes,
phase
@@ -1444,8 +1447,8 @@ export default class DevServer {
const destUrl = url.format(destParsed);
debug(`ProxyPass: ${destUrl}`);
this.setResponseHeaders(res, nowRequestId);
return proxyPass(req, res, destUrl, this, nowRequestId);
this.setResponseHeaders(res, requestId);
return proxyPass(req, res, destUrl, this, requestId);
}
match = await findBuildMatch(
@@ -1453,7 +1456,7 @@ export default class DevServer {
this.files,
routeResult.dest,
this,
nowConfig
vercelConfig
);
if (
@@ -1463,7 +1466,7 @@ export default class DevServer {
phase,
req,
res,
nowRequestId
requestId
)
) {
return;
@@ -1476,7 +1479,7 @@ export default class DevServer {
req.method,
missRoutes,
this,
nowConfig,
vercelConfig,
routeResult.headers,
[],
'miss'
@@ -1487,7 +1490,7 @@ export default class DevServer {
this.files,
routeResult.dest,
this,
nowConfig
vercelConfig
);
if (
await this.exitWithStatus(
@@ -1496,7 +1499,7 @@ export default class DevServer {
phase,
req,
res,
nowRequestId
requestId
)
) {
return;
@@ -1510,7 +1513,7 @@ export default class DevServer {
req.method,
hitRoutes,
this,
nowConfig,
vercelConfig,
routeResult.headers,
[],
'hit'
@@ -1538,7 +1541,7 @@ export default class DevServer {
req.method,
errorRoutes,
this,
nowConfig,
vercelConfig,
routeResult.headers,
[],
'error'
@@ -1550,7 +1553,7 @@ export default class DevServer {
this.files,
routeResultForError.dest,
this,
nowConfig
vercelConfig
);
if (matchForError) {
@@ -1569,7 +1572,7 @@ export default class DevServer {
'error',
req,
res,
nowRequestId
requestId
)
) {
return;
@@ -1611,25 +1614,25 @@ export default class DevServer {
debug(`Proxying to frontend dev server: ${upstream}`);
// Add the Vercel platform proxy request headers
const headers = this.getNowProxyHeaders(req, nowRequestId, false);
const headers = this.getProxyHeaders(req, requestId, false);
for (const [name, value] of Object.entries(headers)) {
req.headers[name] = value;
}
this.setResponseHeaders(res, nowRequestId);
this.setResponseHeaders(res, requestId);
const origUrl = url.parse(req.url || '/', true);
delete origUrl.search;
origUrl.pathname = dest;
Object.assign(origUrl.query, uri_args);
req.url = url.format(origUrl);
return proxyPass(req, res, upstream, this, nowRequestId, false);
return proxyPass(req, res, upstream, this, requestId, false);
}
if (
(statusCode === 404 && routeResult.phase === 'miss') ||
!this.renderDirectoryListing(req, res, requestPath, nowRequestId)
!this.renderDirectoryListing(req, res, requestPath, requestId)
) {
await this.send404(req, res, nowRequestId);
await this.send404(req, res, requestId);
}
return;
}
@@ -1655,7 +1658,7 @@ export default class DevServer {
req.method,
buildResult.routes,
this,
nowConfig
vercelConfig
);
if (matchedRoute.found && callLevel === 0) {
debug(`Found matching route ${matchedRoute.dest} for ${newUrl}`);
@@ -1663,8 +1666,8 @@ export default class DevServer {
await this.serveProjectAsNowV2(
req,
res,
nowRequestId,
nowConfig,
requestId,
vercelConfig,
buildResult.routes,
callLevel + 1
);
@@ -1713,7 +1716,7 @@ export default class DevServer {
await this.sendError(
req,
res,
nowRequestId,
requestId,
'NO_RESPONSE_FROM_FUNCTION',
502
);
@@ -1723,7 +1726,7 @@ export default class DevServer {
if (devServerResult) {
// When invoking lambda functions, the region where the lambda was invoked
// is also included in the request ID. So use the same `dev1` fake region.
nowRequestId = generateRequestId(this.podId, true);
requestId = generateRequestId(this.podId, true);
const { port, pid } = devServerResult;
this.devServerPids.add(pid);
@@ -1745,31 +1748,31 @@ export default class DevServer {
});
// Add the Vercel platform proxy request headers
const headers = this.getNowProxyHeaders(req, nowRequestId, false);
const headers = this.getProxyHeaders(req, requestId, false);
for (const [name, value] of Object.entries(headers)) {
req.headers[name] = value;
}
this.setResponseHeaders(res, nowRequestId);
this.setResponseHeaders(res, requestId);
return proxyPass(
req,
res,
`http://localhost:${port}`,
this,
nowRequestId,
requestId,
false
);
} else {
debug(`Skipping \`startDevServer()\` for ${match.entrypoint}`);
}
}
let foundAsset = findAsset(match, requestPath, nowConfig);
let foundAsset = findAsset(match, requestPath, vercelConfig);
if (!foundAsset && callLevel === 0) {
await this.triggerBuild(match, buildRequestPath, req, nowConfig);
await this.triggerBuild(match, buildRequestPath, req, vercelConfig);
// Since the `asset` was just built, resolve again to get the new asset
foundAsset = findAsset(match, requestPath, nowConfig);
foundAsset = findAsset(match, requestPath, vercelConfig);
}
// Proxy to the dev server:
@@ -1782,24 +1785,24 @@ export default class DevServer {
debug('Proxying to frontend dev server');
// Add the Vercel platform proxy request headers
const headers = this.getNowProxyHeaders(req, nowRequestId, false);
const headers = this.getProxyHeaders(req, requestId, false);
for (const [name, value] of Object.entries(headers)) {
req.headers[name] = value;
}
this.setResponseHeaders(res, nowRequestId);
this.setResponseHeaders(res, requestId);
return proxyPass(
req,
res,
`http://localhost:${this.devProcessPort}`,
this,
nowRequestId,
requestId,
false
);
}
if (!foundAsset) {
await this.send404(req, res, nowRequestId);
await this.send404(req, res, requestId);
return;
}
@@ -1813,7 +1816,7 @@ export default class DevServer {
/* eslint-disable no-case-declarations */
switch (asset.type) {
case 'FileFsRef':
this.setResponseHeaders(res, nowRequestId);
this.setResponseHeaders(res, requestId);
req.url = `/${basename(asset.fsPath)}`;
return serveStaticFile(req, res, dirname(asset.fsPath), {
headers: [
@@ -1834,7 +1837,7 @@ export default class DevServer {
'Content-Length': asset.data.length,
'Content-Type': asset.contentType || getMimeType(assetKey),
};
this.setResponseHeaders(res, nowRequestId, headers);
this.setResponseHeaders(res, requestId, headers);
res.end(asset.data);
return;
@@ -1846,7 +1849,7 @@ export default class DevServer {
await this.sendError(
req,
res,
nowRequestId,
requestId,
'INTERNAL_LAMBDA_NOT_FOUND'
);
return;
@@ -1854,7 +1857,7 @@ export default class DevServer {
// When invoking lambda functions, the region where the lambda was invoked
// is also included in the request ID. So use the same `dev1` fake region.
nowRequestId = generateRequestId(this.podId, true);
requestId = generateRequestId(this.podId, true);
// Mix the `routes` result dest query params into the req path
const parsed = url.parse(req.url || '/', true);
@@ -1871,7 +1874,7 @@ export default class DevServer {
path,
headers: {
...req.headers,
...this.getNowProxyHeaders(req, nowRequestId, true),
...this.getProxyHeaders(req, requestId, true),
},
encoding: 'base64',
body: body.toString('base64'),
@@ -1890,7 +1893,7 @@ export default class DevServer {
await this.sendError(
req,
res,
nowRequestId,
requestId,
'NO_RESPONSE_FROM_FUNCTION',
502
);
@@ -1900,7 +1903,7 @@ export default class DevServer {
if (!statusCode) {
res.statusCode = result.statusCode;
}
this.setResponseHeaders(res, nowRequestId, result.headers);
this.setResponseHeaders(res, requestId, result.headers);
let resBody: Buffer | string | undefined;
if (result.encoding === 'base64' && typeof result.body === 'string') {
@@ -1912,15 +1915,15 @@ export default class DevServer {
default:
// This shouldn't really ever happen...
await this.sendError(req, res, nowRequestId, 'UNKNOWN_ASSET_TYPE');
await this.sendError(req, res, requestId, 'UNKNOWN_ASSET_TYPE');
}
};
renderDirectoryListing(
req: http.IncomingMessage,
_req: http.IncomingMessage,
res: http.ServerResponse,
requestPath: string,
nowRequestId: string
requestId: string
): boolean {
// If the "directory listing" feature is disabled in the
// Project's settings, then don't render the directory listing
@@ -1998,7 +2001,7 @@ export default class DevServer {
paths,
directory,
});
this.setResponseHeaders(res, nowRequestId);
this.setResponseHeaders(res, requestId);
res.setHeader('Content-Type', 'text/html; charset=utf-8');
res.setHeader(
'Content-Length',
@@ -2008,14 +2011,17 @@ export default class DevServer {
return true;
}
async hasFilesystem(dest: string, nowConfig: VercelConfig): Promise<boolean> {
async hasFilesystem(
dest: string,
vercelConfig: VercelConfig
): Promise<boolean> {
if (
await findBuildMatch(
this.buildMatches,
this.files,
dest,
this,
nowConfig,
vercelConfig,
true
)
) {
@@ -2121,7 +2127,7 @@ function proxyPass(
res: http.ServerResponse,
dest: string,
devServer: DevServer,
nowRequestId: string,
requestId: string,
ignorePath: boolean = true
): void {
return devServer.proxy.web(
@@ -2136,7 +2142,7 @@ function proxyPass(
devServer.sendError(
req,
res,
nowRequestId,
requestId,
'NO_RESPONSE_FROM_FUNCTION',
502
);
@@ -2197,7 +2203,7 @@ async function findBuildMatch(
files: BuilderInputs,
requestPath: string,
devServer: DevServer,
nowConfig: VercelConfig,
vercelConfig: VercelConfig,
isFilesystem = false
): Promise<BuildMatch | null> {
requestPath = requestPath.replace(/^\//, '');
@@ -2210,7 +2216,7 @@ async function findBuildMatch(
files,
requestPath,
devServer,
nowConfig,
vercelConfig,
isFilesystem
)
) {
@@ -2235,7 +2241,7 @@ async function shouldServe(
files: BuilderInputs,
requestPath: string,
devServer: DevServer,
nowConfig: VercelConfig,
vercelConfig: VercelConfig,
isFilesystem = false
): Promise<boolean> {
const {
@@ -2249,22 +2255,22 @@ async function shouldServe(
: requestPath;
if (
nowConfig.cleanUrls &&
nowConfig.trailingSlash &&
vercelConfig.cleanUrls &&
vercelConfig.trailingSlash &&
cleanSrc === trimmedPath
) {
// Mimic fmeta-util and convert cleanUrls and trailingSlash
return true;
} else if (
nowConfig.cleanUrls &&
!nowConfig.trailingSlash &&
vercelConfig.cleanUrls &&
!vercelConfig.trailingSlash &&
cleanSrc === requestPath
) {
// Mimic fmeta-util and convert cleanUrls
return true;
} else if (
!nowConfig.cleanUrls &&
nowConfig.trailingSlash &&
!vercelConfig.cleanUrls &&
vercelConfig.trailingSlash &&
src === trimmedPath
) {
// Mimic fmeta-util and convert trailingSlash
@@ -2280,13 +2286,13 @@ async function shouldServe(
if (shouldServe) {
return true;
}
} else if (findAsset(match, requestPath, nowConfig)) {
} else if (findAsset(match, requestPath, vercelConfig)) {
// If there's no `shouldServe()` function, then look up if there's
// a matching build asset on the `match` that has already been built.
return true;
} else if (
!isFilesystem &&
(await findMatchingRoute(match, requestPath, devServer, nowConfig))
(await findMatchingRoute(match, requestPath, devServer, vercelConfig))
) {
// If there's no `shouldServe()` function and no matched asset, then look
// up if there's a matching build route on the `match` that has already
@@ -2300,7 +2306,7 @@ async function findMatchingRoute(
match: BuildMatch,
requestPath: string,
devServer: DevServer,
nowConfig: VercelConfig
vercelConfig: VercelConfig
): Promise<RouteResult | void> {
const reqUrl = `/${requestPath}`;
for (const buildResult of match.buildResults.values()) {
@@ -2310,7 +2316,7 @@ async function findMatchingRoute(
undefined,
buildResult.routes,
devServer,
nowConfig
vercelConfig
);
if (route.found) {
return route;
@@ -2321,7 +2327,7 @@ async function findMatchingRoute(
function findAsset(
match: BuildMatch,
requestPath: string,
nowConfig: VercelConfig
vercelConfig: VercelConfig
): { asset: BuilderOutput; assetKey: string } | void {
if (!match.buildOutput) {
return;
@@ -2329,7 +2335,7 @@ function findAsset(
let assetKey: string = requestPath.replace(/\/$/, '');
let asset = match.buildOutput[requestPath];
if (nowConfig.trailingSlash && requestPath.endsWith('/')) {
if (vercelConfig.trailingSlash && requestPath.endsWith('/')) {
asset = match.buildOutput[requestPath.slice(0, -1)];
}
@@ -2413,13 +2419,13 @@ function filterFrontendBuilds(build: Builder) {
return !frontendRuntimeSet.has(name || '');
}
function hasNewRoutingProperties(nowConfig: VercelConfig) {
function hasNewRoutingProperties(vercelConfig: VercelConfig) {
return (
typeof nowConfig.cleanUrls !== undefined ||
typeof nowConfig.headers !== undefined ||
typeof nowConfig.redirects !== undefined ||
typeof nowConfig.rewrites !== undefined ||
typeof nowConfig.trailingSlash !== undefined
typeof vercelConfig.cleanUrls !== undefined ||
typeof vercelConfig.headers !== undefined ||
typeof vercelConfig.redirects !== undefined ||
typeof vercelConfig.rewrites !== undefined ||
typeof vercelConfig.trailingSlash !== undefined
);
}