Files
vercel/utils/update-legacy-name.js
Steven 3b021993b5 [tests] Fix deprecation message (#5157)
This PR is a follow up to #5119 which had the names backwards.

I fixed the variable names to avoid the confusion since "new" and "old" were ambiguous.

I also removed the incorrect deprecation message from packages published during commit c9597dc199.
2020-09-05 13:49:20 -04:00

55 lines
1.6 KiB
JavaScript
Vendored

#!/usr/bin/env node
/**
* Updates the `package.json` file to contain the legacy "now" `name` field.
* The provided argument should be a tag containing the new name.
*/
const fs = require('fs');
const { join } = require('path');
const npa = require('npm-package-arg');
const parsed = npa(process.argv[2]);
// Find the correct directory for this package
const packagesDir = join(__dirname, '..', 'packages');
const packageDir = fs.readdirSync(packagesDir).find(p => {
if (p.startsWith('.')) return false;
try {
const pkg = JSON.parse(
fs.readFileSync(join(packagesDir, p, 'package.json'), 'utf8')
);
return pkg.name === parsed.name;
} catch (err) {
console.error(err);
}
});
if (!packageDir) {
throw new Error(`Could not find the package directory for "${parsed.name}"`);
}
const pkgJsonPath = join(packagesDir, packageDir, 'package.json');
const pkg = JSON.parse(fs.readFileSync(pkgJsonPath, 'utf8'));
const vcName = pkg.name;
const version = pkg.version;
if (pkg.name === '@vercel/client') {
// The legacy name for `@vercel/client` is `now-client` (global scope)
pkg.name = 'now-client';
} else {
pkg.name = pkg.name.replace('vercel', 'now');
if (pkg.bin && pkg.bin.vercel) {
// The legacy "bin" for Now CLI is "now"
pkg.bin = { now: pkg.bin.vercel };
}
}
const nowName = pkg.name;
console.error(`Updated package name: "${vcName}" -> "${nowName}"`);
fs.writeFileSync(pkgJsonPath, `${JSON.stringify(pkg, null, 2)}\n`);
// Log the directory name to stdout for the `publish-legacy.sh`
// script to consume for the `npm publish` that happens next.
const IFS = '|';
console.log([packageDir, vcName, nowName, version].join(IFS));