[cli] Remove a bunch of isCanary checks (#9806)

We no longer publish versions that include `-canary` in the package.json `version` field, so these are dead code. Just doing a little bit of cleanup.
This commit is contained in:
Nathan Rajlich
2023-04-14 13:35:56 -07:00
committed by GitHub
parent ed119d6a33
commit 3e7bcb2073
13 changed files with 13 additions and 58 deletions

View File

@@ -39,7 +39,6 @@
"version": "pnpm install && git add pnpm-lock.yaml",
"bootstrap": "lerna bootstrap",
"publish-stable": "echo 'Run `pnpm changelog` for instructions'",
"publish-canary": "git checkout main && git pull && lerna version prerelease --preid canary --message \"Publish Canary\" --exact",
"publish-from-github": "./utils/publish.sh",
"changelog": "node utils/changelog.js",
"build": "node utils/gen.js && turbo --no-update-notifier run build",

View File

@@ -54,8 +54,6 @@ import type { AuthConfig, GlobalConfig } from '@vercel-internals/types';
import { VercelConfig } from '@vercel/client';
import box from './util/output/box';
const isCanary = pkg.version.includes('canary');
const VERCEL_DIR = getGlobalPathConfig();
const VERCEL_CONFIG_PATH = configFiles.getConfigFilePath();
const VERCEL_AUTH_CONFIG_PATH = configFiles.getAuthConfigFilePath();
@@ -70,7 +68,7 @@ sourceMap.install();
Sentry.init({
dsn: SENTRY_DSN,
release: `vercel-cli@${pkg.version}`,
environment: isCanary ? 'canary' : 'stable',
environment: 'stable',
});
let client: Client;
@@ -165,13 +163,7 @@ const main = async () => {
)}`
);
} else {
output.print(
`${chalk.grey(
`${getTitleName()} CLI ${pkg.version}${
isCanary ? ' — https://vercel.com/feedback' : ''
}`
)}\n`
);
output.print(`${chalk.grey(`${getTitleName()} CLI ${pkg.version}`)}\n`);
}
// Handle `--version` directly
@@ -707,7 +699,6 @@ main()
// Check if an update is available. If so, `latest` will contain a string
// of the latest version, otherwise `undefined`.
const latest = getLatestVersion({
distTag: isCanary ? 'canary' : 'latest',
output,
pkg,
});

View File

@@ -51,10 +51,8 @@ import link from '../output/link';
import sleep from '../sleep';
import { Output } from '../output';
import { relative } from '../path-helpers';
import { getDistTag } from '../get-dist-tag';
import getVercelConfigPath from '../config/local-path';
import { MissingDotenvVarsError } from '../errors-ts';
import cliPkg from '../pkg';
import { getVercelDirectory } from '../projects/link';
import { staticFiles as getFiles } from '../get-files';
import { validateConfig } from '../validate-config';
@@ -593,7 +591,7 @@ export default class DevServer {
rewriteRoutes,
errorRoutes,
} = await detectBuilders(files, pkg, {
tag: getDistTag(cliPkg.version) === 'canary' ? 'canary' : 'latest',
tag: 'latest',
functions: vercelConfig.functions,
projectSettings: projectSettings || this.projectSettings,
featHandleMiss,

View File

@@ -1,9 +0,0 @@
import semver from 'semver';
export function getDistTag(version: string): string {
const parsed = semver.parse(version);
if (parsed && typeof parsed.prerelease[0] === 'string') {
return parsed.prerelease[0] as string;
}
return 'latest';
}

View File

@@ -1,7 +1,6 @@
import { Stats } from 'fs';
import { sep, dirname, join, resolve } from 'path';
import { lstat, readlink, readFile, realpath } from 'fs-extra';
import { isCanary } from './is-canary';
import { getPkgName } from './pkg-name';
async function isYarn(): Promise<boolean> {
@@ -99,8 +98,7 @@ async function isGlobal() {
}
export default async function getUpdateCommand(): Promise<string> {
const tag = isCanary() ? 'canary' : 'latest';
const pkgAndVersion = `${getPkgName()}@${tag}`;
const pkgAndVersion = `${getPkgName()}@latest`;
if (await isGlobal()) {
return (await isYarn())

View File

@@ -1,5 +0,0 @@
import pkg from '../../package.json';
export function isCanary() {
return pkg.version.includes('canary');
}

View File

@@ -1,7 +1,7 @@
{
"version": 2,
"builds": [
{ "src": "entrypoint**", "use": "@vercel/node@canary" },
{ "src": "type-module-package-json/**/*.js", "use": "@vercel/node@canary" }
{ "src": "entrypoint**", "use": "@vercel/node" },
{ "src": "type-module-package-json/**/*.js", "use": "@vercel/node" }
]
}

View File

@@ -1 +1 @@
{"builds":[{"src":"index.js","use":"@vercel/node@canary"}]}
{"builds":[{"src":"index.js","use":"@vercel/node"}]}

View File

@@ -3,7 +3,7 @@
"builds": [
{
"src": "package.json",
"use": "@vercel/static-build@canary",
"use": "@vercel/static-build",
"config": {
"distDir": "public"
}

View File

@@ -4,7 +4,6 @@ const {
fetch,
sleep,
fixture,
isCanary,
shouldSkip,
testFixture,
fetchWithRetry,
@@ -46,11 +45,7 @@ test('[vercel dev] 02-angular-node', async () => {
await sleep(5000);
if (isCanary()) {
stderr.includes('@now/build-utils@canary');
} else {
stderr.includes('@now/build-utils@latest');
}
stderr.includes('@now/build-utils@latest');
});
test(

View File

@@ -5,8 +5,6 @@ const fetch = require('node-fetch');
const retry = require('async-retry');
const { satisfies } = require('semver');
const stripAnsi = require('strip-ansi');
const { getDistTag } = require('../../src/util/get-dist-tag');
const { version: cliVersion } = require('../../package.json');
const {
fetchCachedToken,
} = require('../../../../test/lib/deployment/now-deploy');
@@ -16,7 +14,6 @@ jest.setTimeout(10 * 60 * 1000);
const isCI = !!process.env.CI;
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
const isCanary = () => getDistTag(cliVersion) === 'canary';
let port = 3000;
@@ -607,7 +604,6 @@ afterEach(async () => {
module.exports = {
sleep,
isCanary,
testPath,
testFixture,
testFixtureStdio,

View File

@@ -32,7 +32,6 @@ const binaryPath = path.resolve(__dirname, `../scripts/start.js`);
const deployHelpMessage = `${logo} vercel [options] <command | path>`;
let session = 'temp-session';
let secretName: string | undefined;
const isCanary = pkg.version.includes('canary');
const createFile = (dest: fs.PathLike) => fs.closeSync(fs.openSync(dest, 'w'));
@@ -1219,8 +1218,6 @@ test('create zero-config deployment', async () => {
'--yes',
]);
console.log('isCanary', isCanary);
expect(output.exitCode, formatOutput(output)).toBe(0);
const { host } = new URL(output.stdout);
@@ -1233,13 +1230,11 @@ test('create zero-config deployment', async () => {
expect(data.error).toBe(undefined);
const validBuilders = data.builds.every(build =>
isCanary ? build.use.endsWith('@canary') : !build.use.endsWith('@canary')
const validBuilders = data.builds.every(
build => !build.use.endsWith('@canary')
);
const buildList = JSON.stringify(data.builds.map(b => b.use));
const message = `builders match canary (${isCanary}): ${buildList}`;
expect(validBuilders, message).toBe(true);
expect(validBuilders).toBe(true);
});
test('next unsupported functions config shows warning link', async () => {

View File

@@ -1,11 +1,8 @@
import { isCanary } from '../../../src/util/is-canary';
import getUpdateCommand from '../../../src/util/get-update-command';
describe('getUpdateCommand', () => {
it('should detect update command', async () => {
const updateCommand = await getUpdateCommand();
expect(updateCommand).toEqual(
`npm i vercel@${isCanary() ? 'canary' : 'latest'}`
);
expect(updateCommand).toEqual(`npm i vercel@latest`);
});
});