mirror of
https://github.com/LukeHagar/vercel.git
synced 2025-12-07 21:07:46 +00:00
[cli] Update NowConfig references to VercelConfig (#6256)
The `NowConfig` interface is deprecated.
This commit is contained in:
@@ -19,7 +19,7 @@ import link from '../../util/output/link';
|
||||
import { User } from '../../types';
|
||||
import { getCommandName } from '../../util/pkg-name';
|
||||
import toHost from '../../util/to-host';
|
||||
import { NowConfig } from '../../util/dev/types';
|
||||
import { VercelConfig } from '../../util/dev/types';
|
||||
|
||||
type Options = {
|
||||
'--debug': boolean;
|
||||
@@ -421,7 +421,7 @@ function handleCreateAliasError<T>(
|
||||
return error;
|
||||
}
|
||||
|
||||
function getTargetsForAlias(args: string[], { alias }: NowConfig) {
|
||||
function getTargetsForAlias(args: string[], { alias }: VercelConfig) {
|
||||
if (args.length) {
|
||||
return [args[args.length - 1]]
|
||||
.map(target => (target.indexOf('.') !== -1 ? toHost(target) : target))
|
||||
|
||||
@@ -3,7 +3,7 @@ import chalk from 'chalk';
|
||||
import Client from '../client';
|
||||
import { Output } from '../output';
|
||||
import { User } from '../../types';
|
||||
import { NowConfig } from '../dev/types';
|
||||
import { VercelConfig } from '../dev/types';
|
||||
import getDeploymentsByAppName from '../deploy/get-deployments-by-appname';
|
||||
import getDeploymentByIdOrHost from '../deploy/get-deployment-by-id-or-host';
|
||||
|
||||
@@ -35,7 +35,7 @@ export async function getDeploymentForAlias(
|
||||
localConfigPath: string | undefined,
|
||||
user: User,
|
||||
contextName: string,
|
||||
localConfig: NowConfig
|
||||
localConfig: VercelConfig
|
||||
) {
|
||||
output.spinner(`Fetching deployment to alias in ${chalk.bold(contextName)}`);
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ import responseError from './response-error';
|
||||
import ua from './ua';
|
||||
import printIndications from './print-indications';
|
||||
import { AuthConfig, GlobalConfig } from '../types';
|
||||
import { NowConfig } from './dev/types';
|
||||
import { VercelConfig } from './dev/types';
|
||||
import doSsoLogin from './login/sso';
|
||||
import { writeToAuthConfigFile } from './config/files';
|
||||
|
||||
@@ -28,7 +28,7 @@ export interface ClientOptions {
|
||||
authConfig: AuthConfig;
|
||||
output: Output;
|
||||
config: GlobalConfig;
|
||||
localConfig: NowConfig;
|
||||
localConfig: VercelConfig;
|
||||
}
|
||||
|
||||
export default class Client extends EventEmitter {
|
||||
@@ -37,7 +37,7 @@ export default class Client extends EventEmitter {
|
||||
authConfig: AuthConfig;
|
||||
output: Output;
|
||||
config: GlobalConfig;
|
||||
localConfig: NowConfig;
|
||||
localConfig: VercelConfig;
|
||||
|
||||
constructor(opts: ClientOptions) {
|
||||
super();
|
||||
|
||||
@@ -8,7 +8,7 @@ import getLocalPathConfig from './local-path';
|
||||
import { NowError } from '../now-error';
|
||||
import error from '../output/error';
|
||||
import highlight from '../output/highlight';
|
||||
import { NowConfig } from '../dev/types';
|
||||
import { VercelConfig } from '../dev/types';
|
||||
import { AuthConfig, GlobalConfig } from '../../types';
|
||||
|
||||
const VERCEL_DIR = getGlobalPathConfig();
|
||||
@@ -100,8 +100,8 @@ export function getAuthConfigFilePath() {
|
||||
|
||||
export function readLocalConfig(
|
||||
prefix: string = process.cwd()
|
||||
): NowConfig | null {
|
||||
let config: NowConfig | null = null;
|
||||
): VercelConfig | null {
|
||||
let config: VercelConfig | null = null;
|
||||
let target = '';
|
||||
|
||||
try {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { join } from 'path';
|
||||
import { CantParseJSONFile } from '../errors-ts';
|
||||
import readJSONFile from '../read-json-file';
|
||||
import { NowConfig } from '../dev/types';
|
||||
import { VercelConfig } from '../dev/types';
|
||||
import getLocalConfigPath from './local-path';
|
||||
|
||||
export default async function readConfig(dir: string) {
|
||||
@@ -13,7 +13,7 @@ export default async function readConfig(dir: string) {
|
||||
}
|
||||
|
||||
if (result) {
|
||||
return result as NowConfig;
|
||||
return result as VercelConfig;
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
@@ -9,7 +9,7 @@ import {
|
||||
import { Output } from '../output';
|
||||
// @ts-ignore
|
||||
import Now from '../../util';
|
||||
import { NowConfig } from '../dev/types';
|
||||
import { VercelConfig } from '../dev/types';
|
||||
import { Org } from '../../types';
|
||||
import ua from '../ua';
|
||||
import { linkFolderToProject } from '../projects/link';
|
||||
@@ -43,7 +43,7 @@ export default async function processDeployment({
|
||||
uploadStamp: () => string;
|
||||
deployStamp: () => string;
|
||||
quiet: boolean;
|
||||
nowConfig?: NowConfig;
|
||||
nowConfig?: VercelConfig;
|
||||
force?: boolean;
|
||||
withCache?: boolean;
|
||||
org: Org;
|
||||
|
||||
@@ -27,7 +27,7 @@ import { LambdaSizeExceededError } from '../errors-ts';
|
||||
import DevServer from './server';
|
||||
import { getBuilder } from './builder-cache';
|
||||
import {
|
||||
NowConfig,
|
||||
VercelConfig,
|
||||
BuildMatch,
|
||||
BuildResult,
|
||||
BuilderInputs,
|
||||
@@ -96,7 +96,7 @@ async function createBuildProcess(
|
||||
}
|
||||
|
||||
export async function executeBuild(
|
||||
nowConfig: NowConfig,
|
||||
nowConfig: VercelConfig,
|
||||
devServer: DevServer,
|
||||
files: BuilderInputs,
|
||||
match: BuildMatch,
|
||||
@@ -383,7 +383,7 @@ export async function executeBuild(
|
||||
}
|
||||
|
||||
export async function getBuildMatches(
|
||||
nowConfig: NowConfig,
|
||||
nowConfig: VercelConfig,
|
||||
cwd: string,
|
||||
output: Output,
|
||||
devServer: DevServer,
|
||||
|
||||
@@ -4,7 +4,7 @@ import PCRE from 'pcre-to-regexp';
|
||||
import isURL from './is-url';
|
||||
import DevServer from './server';
|
||||
|
||||
import { NowConfig, HttpHeadersConfig, RouteResult } from './types';
|
||||
import { VercelConfig, HttpHeadersConfig, RouteResult } from './types';
|
||||
import { isHandler, Route, HandleValue } from '@vercel/routing-utils';
|
||||
|
||||
export function resolveRouteParameters(
|
||||
@@ -50,7 +50,7 @@ export async function devRouter(
|
||||
reqMethod?: string,
|
||||
routes?: Route[],
|
||||
devServer?: DevServer,
|
||||
nowConfig?: NowConfig,
|
||||
nowConfig?: VercelConfig,
|
||||
previousHeaders?: HttpHeadersConfig,
|
||||
missRoutes?: Route[],
|
||||
phase?: HandleValue | null
|
||||
|
||||
@@ -49,7 +49,7 @@ import sleep from '../sleep';
|
||||
import { Output } from '../output';
|
||||
import { relative } from '../path-helpers';
|
||||
import { getDistTag } from '../get-dist-tag';
|
||||
import getNowConfigPath from '../config/local-path';
|
||||
import getVercelConfigPath from '../config/local-path';
|
||||
import { MissingDotenvVarsError } from '../errors-ts';
|
||||
import cliPkg from '../pkg';
|
||||
import { getVercelDirectory } from '../projects/link';
|
||||
@@ -73,7 +73,7 @@ import errorTemplate502 from './templates/error_502';
|
||||
import redirectTemplate from './templates/redirect';
|
||||
|
||||
import {
|
||||
NowConfig,
|
||||
VercelConfig,
|
||||
DevServerOptions,
|
||||
BuildMatch,
|
||||
BuildResult,
|
||||
@@ -145,7 +145,7 @@ export default class DevServer {
|
||||
private devServerPids: Set<number>;
|
||||
private projectSettings?: ProjectSettings;
|
||||
|
||||
private getNowConfigPromise: Promise<NowConfig> | null;
|
||||
private getVercelConfigPromise: Promise<VercelConfig> | null;
|
||||
private blockingBuildsPromise: Promise<void> | null;
|
||||
private updateBuildersPromise: Promise<void> | null;
|
||||
private updateBuildersTimeout: NodeJS.Timeout | undefined;
|
||||
@@ -181,7 +181,7 @@ export default class DevServer {
|
||||
this.inProgressBuilds = new Map();
|
||||
this.devCacheDir = join(getVercelDirectory(cwd), 'cache');
|
||||
|
||||
this.getNowConfigPromise = null;
|
||||
this.getVercelConfigPromise = null;
|
||||
this.blockingBuildsPromise = null;
|
||||
this.updateBuildersPromise = null;
|
||||
this.startPromise = null;
|
||||
@@ -244,7 +244,7 @@ export default class DevServer {
|
||||
}
|
||||
}
|
||||
|
||||
const nowConfig = await this.getNowConfig();
|
||||
const nowConfig = await this.getVercelConfig();
|
||||
|
||||
// Update the build matches in case an entrypoint was created or deleted
|
||||
await this.updateBuildMatches(nowConfig);
|
||||
@@ -375,7 +375,7 @@ export default class DevServer {
|
||||
}
|
||||
|
||||
async updateBuildMatches(
|
||||
nowConfig: NowConfig,
|
||||
nowConfig: VercelConfig,
|
||||
isInitial = false
|
||||
): Promise<void> {
|
||||
const fileList = this.resolveBuildFiles(this.files);
|
||||
@@ -460,7 +460,7 @@ export default class DevServer {
|
||||
}
|
||||
|
||||
async invalidateBuildMatches(
|
||||
nowConfig: NowConfig,
|
||||
nowConfig: VercelConfig,
|
||||
updatedBuilders: string[]
|
||||
): Promise<void> {
|
||||
if (updatedBuilders.length === 0) {
|
||||
@@ -516,25 +516,25 @@ export default class DevServer {
|
||||
return {};
|
||||
}
|
||||
|
||||
clearNowConfigPromise = () => {
|
||||
this.getNowConfigPromise = null;
|
||||
clearVercelConfigPromise = () => {
|
||||
this.getVercelConfigPromise = null;
|
||||
};
|
||||
|
||||
getNowConfig(): Promise<NowConfig> {
|
||||
if (this.getNowConfigPromise) {
|
||||
return this.getNowConfigPromise;
|
||||
getVercelConfig(): Promise<VercelConfig> {
|
||||
if (this.getVercelConfigPromise) {
|
||||
return this.getVercelConfigPromise;
|
||||
}
|
||||
this.getNowConfigPromise = this._getNowConfig();
|
||||
this.getVercelConfigPromise = this._getVercelConfig();
|
||||
|
||||
// Clean up the promise once it has resolved
|
||||
const clear = this.clearNowConfigPromise;
|
||||
this.getNowConfigPromise.finally(clear);
|
||||
const clear = this.clearVercelConfigPromise;
|
||||
this.getVercelConfigPromise.finally(clear);
|
||||
|
||||
return this.getNowConfigPromise;
|
||||
return this.getVercelConfigPromise;
|
||||
}
|
||||
|
||||
async _getNowConfig(): Promise<NowConfig> {
|
||||
const configPath = getNowConfigPath(this.cwd);
|
||||
async _getVercelConfig(): Promise<VercelConfig> {
|
||||
const configPath = getVercelConfigPath(this.cwd);
|
||||
|
||||
const [
|
||||
pkg = null,
|
||||
@@ -543,10 +543,10 @@ export default class DevServer {
|
||||
config = { version: 2, [fileNameSymbol]: 'vercel.json' },
|
||||
] = await Promise.all([
|
||||
this.readJsonFile<PackageJson>('package.json'),
|
||||
this.readJsonFile<NowConfig>(configPath),
|
||||
this.readJsonFile<VercelConfig>(configPath),
|
||||
]);
|
||||
|
||||
await this.validateNowConfig(config);
|
||||
await this.validateVercelConfig(config);
|
||||
const { error: routeError, routes: maybeRoutes } = getTransformedRoutes({
|
||||
nowConfig: config,
|
||||
});
|
||||
@@ -634,7 +634,7 @@ export default class DevServer {
|
||||
config.builds.sort(sortBuilders);
|
||||
}
|
||||
|
||||
await this.validateNowConfig(config);
|
||||
await this.validateVercelConfig(config);
|
||||
|
||||
this.caseSensitive = hasNewRoutingProperties(config);
|
||||
this.apiDir = detectApiDirectory(config.builds || []);
|
||||
@@ -710,8 +710,8 @@ export default class DevServer {
|
||||
}
|
||||
|
||||
async tryValidateOrExit(
|
||||
config: NowConfig,
|
||||
validate: (c: NowConfig) => string | null
|
||||
config: VercelConfig,
|
||||
validate: (c: VercelConfig) => string | null
|
||||
): Promise<void> {
|
||||
const message = validate(config);
|
||||
|
||||
@@ -721,7 +721,7 @@ export default class DevServer {
|
||||
}
|
||||
}
|
||||
|
||||
async validateNowConfig(config: NowConfig): Promise<void> {
|
||||
async validateVercelConfig(config: VercelConfig): Promise<void> {
|
||||
if (config.version === 1) {
|
||||
this.output.error('Cannot run `version: 1` projects.');
|
||||
await this.exit(1);
|
||||
@@ -855,7 +855,7 @@ export default class DevServer {
|
||||
.replace('[::]', 'localhost')
|
||||
.replace('127.0.0.1', 'localhost');
|
||||
|
||||
const nowConfig = await this.getNowConfig();
|
||||
const nowConfig = await this.getVercelConfig();
|
||||
const devCommandPromise = this.runDevCommand();
|
||||
|
||||
const files = await getFiles(this.cwd, { output: this.output });
|
||||
@@ -982,7 +982,7 @@ export default class DevServer {
|
||||
|
||||
if (devProcess) {
|
||||
ops.push(
|
||||
new Promise((resolve, reject) => {
|
||||
new Promise<void>((resolve, reject) => {
|
||||
devProcess.once('exit', () => resolve());
|
||||
try {
|
||||
process.kill(devProcess.pid);
|
||||
@@ -1201,7 +1201,7 @@ export default class DevServer {
|
||||
match: BuildMatch,
|
||||
requestPath: string | null,
|
||||
req: http.IncomingMessage | null,
|
||||
nowConfig: NowConfig,
|
||||
nowConfig: VercelConfig,
|
||||
previousBuildResult?: BuildResult,
|
||||
filesChanged?: string[],
|
||||
filesRemoved?: string[]
|
||||
@@ -1290,7 +1290,7 @@ export default class DevServer {
|
||||
this.output.debug(`${chalk.bold(method)} ${req.url}`);
|
||||
|
||||
try {
|
||||
const nowConfig = await this.getNowConfig();
|
||||
const nowConfig = await this.getVercelConfig();
|
||||
await this.serveProjectAsNowV2(req, res, nowRequestId, nowConfig);
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
@@ -1339,7 +1339,7 @@ export default class DevServer {
|
||||
req: http.IncomingMessage,
|
||||
res: http.ServerResponse,
|
||||
nowRequestId: string,
|
||||
nowConfig: NowConfig,
|
||||
nowConfig: VercelConfig,
|
||||
routes: Route[] | undefined = nowConfig.routes,
|
||||
callLevel: number = 0
|
||||
) => {
|
||||
@@ -1992,7 +1992,7 @@ export default class DevServer {
|
||||
return true;
|
||||
}
|
||||
|
||||
async hasFilesystem(dest: string, nowConfig: NowConfig): Promise<boolean> {
|
||||
async hasFilesystem(dest: string, nowConfig: VercelConfig): Promise<boolean> {
|
||||
if (
|
||||
await findBuildMatch(
|
||||
this.buildMatches,
|
||||
@@ -2181,7 +2181,7 @@ async function findBuildMatch(
|
||||
files: BuilderInputs,
|
||||
requestPath: string,
|
||||
devServer: DevServer,
|
||||
nowConfig: NowConfig,
|
||||
nowConfig: VercelConfig,
|
||||
isFilesystem = false
|
||||
): Promise<BuildMatch | null> {
|
||||
requestPath = requestPath.replace(/^\//, '');
|
||||
@@ -2219,7 +2219,7 @@ async function shouldServe(
|
||||
files: BuilderInputs,
|
||||
requestPath: string,
|
||||
devServer: DevServer,
|
||||
nowConfig: NowConfig,
|
||||
nowConfig: VercelConfig,
|
||||
isFilesystem = false
|
||||
): Promise<boolean> {
|
||||
const {
|
||||
@@ -2284,7 +2284,7 @@ async function findMatchingRoute(
|
||||
match: BuildMatch,
|
||||
requestPath: string,
|
||||
devServer: DevServer,
|
||||
nowConfig: NowConfig
|
||||
nowConfig: VercelConfig
|
||||
): Promise<RouteResult | void> {
|
||||
const reqUrl = `/${requestPath}`;
|
||||
for (const buildResult of match.buildResults.values()) {
|
||||
@@ -2305,7 +2305,7 @@ async function findMatchingRoute(
|
||||
function findAsset(
|
||||
match: BuildMatch,
|
||||
requestPath: string,
|
||||
nowConfig: NowConfig
|
||||
nowConfig: VercelConfig
|
||||
): { asset: BuilderOutput; assetKey: string } | void {
|
||||
if (!match.buildOutput) {
|
||||
return;
|
||||
@@ -2397,7 +2397,7 @@ function filterFrontendBuilds(build: Builder) {
|
||||
return !frontendRuntimeSet.has(name || '');
|
||||
}
|
||||
|
||||
function hasNewRoutingProperties(nowConfig: NowConfig) {
|
||||
function hasNewRoutingProperties(nowConfig: VercelConfig) {
|
||||
return (
|
||||
typeof nowConfig.cleanUrls !== undefined ||
|
||||
typeof nowConfig.headers !== undefined ||
|
||||
|
||||
@@ -14,12 +14,12 @@ import {
|
||||
Lambda,
|
||||
PackageJson,
|
||||
} from '@vercel/build-utils';
|
||||
import { NowConfig } from '@vercel/client';
|
||||
import { VercelConfig } from '@vercel/client';
|
||||
import { HandleValue, Route } from '@vercel/routing-utils';
|
||||
import { Output } from '../output';
|
||||
import { ProjectEnvVariable, ProjectSettings } from '../../types';
|
||||
|
||||
export { NowConfig };
|
||||
export { VercelConfig };
|
||||
|
||||
export interface DevServerOptions {
|
||||
output: Output;
|
||||
|
||||
@@ -7,7 +7,7 @@ import {
|
||||
rewritesSchema,
|
||||
trailingSlashSchema,
|
||||
} from '@vercel/routing-utils';
|
||||
import { NowConfig } from './types';
|
||||
import { VercelConfig } from './types';
|
||||
import {
|
||||
functionsSchema,
|
||||
buildsSchema,
|
||||
@@ -36,7 +36,7 @@ const vercelConfigSchema = {
|
||||
const ajv = new Ajv();
|
||||
const validate = ajv.compile(vercelConfigSchema);
|
||||
|
||||
export function validateConfig(config: NowConfig): NowBuildError | null {
|
||||
export function validateConfig(config: VercelConfig): NowBuildError | null {
|
||||
if (!validate(config)) {
|
||||
if (validate.errors && validate.errors[0]) {
|
||||
const error = validate.errors[0];
|
||||
|
||||
@@ -9,15 +9,15 @@ import {
|
||||
import humanizePath from './humanize-path';
|
||||
import readJSONFile from './read-json-file';
|
||||
import readPackage from './read-package';
|
||||
import { NowConfig } from './dev/types';
|
||||
import { VercelConfig } from './dev/types';
|
||||
import { Output } from './output';
|
||||
|
||||
let config: NowConfig;
|
||||
let config: VercelConfig;
|
||||
|
||||
export default async function getConfig(
|
||||
output: Output,
|
||||
configFile?: string
|
||||
): Promise<NowConfig | Error> {
|
||||
): Promise<VercelConfig | Error> {
|
||||
// If config was already read, just return it
|
||||
if (config) {
|
||||
return config;
|
||||
@@ -44,7 +44,7 @@ export default async function getConfig(
|
||||
return localConfig;
|
||||
}
|
||||
if (localConfig !== null) {
|
||||
config = localConfig as NowConfig;
|
||||
config = localConfig as VercelConfig;
|
||||
config[fileNameSymbol] = configFile;
|
||||
return config;
|
||||
}
|
||||
@@ -68,13 +68,13 @@ export default async function getConfig(
|
||||
}
|
||||
if (vercelConfig !== null) {
|
||||
output.debug(`Found config in file "${vercelFilePath}"`);
|
||||
config = vercelConfig as NowConfig;
|
||||
config = vercelConfig as VercelConfig;
|
||||
config[fileNameSymbol] = 'vercel.json';
|
||||
return config;
|
||||
}
|
||||
if (nowConfig !== null) {
|
||||
output.debug(`Found config in file "${nowFilePath}"`);
|
||||
config = nowConfig as NowConfig;
|
||||
config = nowConfig as VercelConfig;
|
||||
config[fileNameSymbol] = 'now.json';
|
||||
return config;
|
||||
}
|
||||
@@ -87,7 +87,7 @@ export default async function getConfig(
|
||||
}
|
||||
if (pkgConfig) {
|
||||
output.debug(`Found config in package ${pkgFilePath}`);
|
||||
config = pkgConfig as NowConfig;
|
||||
config = pkgConfig as VercelConfig;
|
||||
config[fileNameSymbol] = 'package.json';
|
||||
return config;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import { join, basename } from 'path';
|
||||
import chalk from 'chalk';
|
||||
import { remove } from 'fs-extra';
|
||||
import { ProjectLinkResult, ProjectSettings } from '../../types';
|
||||
import { NowConfig } from '../dev/types';
|
||||
import { VercelConfig } from '../dev/types';
|
||||
import {
|
||||
getLinkedProject,
|
||||
linkFolderToProject,
|
||||
@@ -134,7 +134,7 @@ export default async function setupAndLink(
|
||||
return { status: 'error', exitCode: 1 };
|
||||
}
|
||||
|
||||
let localConfig: NowConfig = {};
|
||||
let localConfig: VercelConfig = {};
|
||||
if (client.localConfig && !(client.localConfig instanceof Error)) {
|
||||
localConfig = client.localConfig;
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import path from 'path';
|
||||
import { CantParseJSONFile } from './errors-ts';
|
||||
import readJSONFile from './read-json-file';
|
||||
import { NowConfig } from './dev/types';
|
||||
import { VercelConfig } from './dev/types';
|
||||
import { PackageJson } from '@vercel/build-utils';
|
||||
|
||||
interface CustomPackage extends PackageJson {
|
||||
now?: NowConfig;
|
||||
now?: VercelConfig;
|
||||
}
|
||||
|
||||
export default async function readPackage(file?: string) {
|
||||
|
||||
Reference in New Issue
Block a user