Files
vercel/utils/update-legacy-name.js
Nathan Rajlich 8a68211cad [all] Rename packages to vercel and add logic to publish legacy package names to npm (#4233)
https://vercel.com/blog/zeit-is-now-vercel

* Updates all org packages from `@now` to `@vercel`
* Updates Now CLI package name from `now` to `vercel`
  * Packages contains `"bin"` entries for _both_ `vercel` and `now` in the package.json
* Updates `now-client` package name to `@vercel/client` (org scoped, for authenticity)

There is also a new `publish-legacy.sh` script which ensures that all the legacy package names (i.e. `now`, `now-client`, `@now/node`, etc.) will still be published as well.

We will remove this legacy publishing logic on Jan 1, 2021.
2020-05-05 23:43:57 +00:00

48 lines
1.4 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 originalName = pkg.name;
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');
}
console.error(`Updated package name: "${originalName}" -> "${pkg.name}"`);
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.
console.log(packageDir);