Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename -proposal-s that became standard to -transform- #15614

Merged
merged 11 commits into from May 22, 2023
36 changes: 36 additions & 0 deletions .github/workflows/reminders.yml
@@ -0,0 +1,36 @@
name: Open issue to remind doing something
on:
schedule:
- cron: 0 0 15 07 *

permissions:
issues: write

jobs:
npm_deprecate:
name: Create issue for deprecating npm packages
runs-on: ubuntu-latest
steps:
- name: Issue Bot Action
uses: imjohnbo/issue-bot@v3.4.3
with:
assignees: nicolo-ribaudo
title: "Deprecate renamed npm packages"
body: |-
Please run these commands:
```
npm deprecate @babel/plugin-proposal-class-static-block "This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-class-static-block instead."
npm deprecate @babel/plugin-proposal-private-property-in-object "This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-private-property-in-object instead."
npm deprecate @babel/plugin-proposal-class-properties "This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-class-properties instead."
npm deprecate @babel/plugin-proposal-private-methods "This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-private-methods instead."
npm deprecate @babel/plugin-proposal-numeric-separator "This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-numeric-separator instead."
npm deprecate @babel/plugin-proposal-logical-assignment-operators "This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-logical-assignment-operators instead."
npm deprecate @babel/plugin-proposal-nullish-coalescing-operator "This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-nullish-coalescing-operator instead."
npm deprecate @babel/plugin-proposal-optional-chaining "This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-optional-chaining instead."
npm deprecate @babel/plugin-proposal-json-strings "This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-json-strings instead."
npm deprecate @babel/plugin-proposal-optional-catch-binding "This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-optional-catch-binding instead."
npm deprecate @babel/plugin-proposal-async-generator-functions "This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-async-generator-functions instead."
npm deprecate @babel/plugin-proposal-object-rest-spread "This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-object-rest-spread instead."
npm deprecate @babel/plugin-proposal-unicode-property-regex "This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-unicode-property-regex instead."
npm deprecate @babel/plugin-proposal-export-namespace-from "This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-export-namespace-from instead."
```
112 changes: 112 additions & 0 deletions scripts/rename-proposal-to-transform.js
@@ -0,0 +1,112 @@
#!/usr/bin/env node

import path from "node:path";
import fs from "node:fs";
import { Glob } from "glob";
import { execSync } from "node:child_process";

const oldName = process.argv[2].match(/proposal-[\w-]+/)[0];
const newName = process.argv[3] || oldName.replace("proposal-", "transform-");

const oldPackageFolder = path.resolve(process.cwd(), process.argv[2]);
const oldPackageJSONPath = path.join(oldPackageFolder, "package.json");

console.info("Updating package.json...");
{
const pkgJSON = JSON.parse(fs.readFileSync(oldPackageJSONPath, "utf8"));
pkgJSON.name = pkgJSON.name.replace(oldName, newName);
pkgJSON.description = pkgJSON.description.replace(
/the ([a-z-]+?)s? proposal/gi,
"$1s"
);
pkgJSON.repository.directory = pkgJSON.repository.directory.replace(
oldName,
newName
);
pkgJSON.homepage = pkgJSON.homepage.replace(oldName, newName);
fs.writeFileSync(oldPackageJSONPath, JSON.stringify(pkgJSON, null, 2) + "\n");
}

console.info("Updating the plugin name...");
pluginName: {
const indexPath = path.join(oldPackageFolder, "src", "index.ts");

let indexContents;
try {
indexContents = fs.readFileSync(indexPath, "utf8");
} catch (error) {
console.warn("Could not find src/index.ts, skipping...");
break pluginName;
}

const newContents = indexContents.replace(
new RegExp(`(?<=name:\\s*")${oldName}`),
newName
);
if (newContents === indexContents) {
console.warn("Could not find name in src/index.ts, skipping...");
break pluginName;
}

fs.writeFileSync(indexPath, newContents);
}

console.info("Updating the README...");
readme: {
const readmePath = path.join(oldPackageFolder, "README.md");

let indexContents;
try {
indexContents = fs.readFileSync(readmePath, "utf8");
} catch (error) {
console.warn("Could not find README.md, skipping...");
break readme;
}

const newContents = indexContents.replaceAll(oldName, newName);
if (newContents === indexContents) {
console.warn("Could not find name in README.md, skipping...");
break readme;
}

fs.writeFileSync(readmePath, newContents);
}

console.info("Renaming the folder...");
{
const newPackageFolder = oldPackageFolder.replace(oldName, newName);
if (fs.existsSync(newPackageFolder)) {
fs.rmSync(newPackageFolder, { recursive: true });
}
fs.renameSync(oldPackageFolder, newPackageFolder);
}

console.info("Renaming all usages in tests...");
await globRename(
"./{packages,eslint,codemods}/*/test/fixtures/**/options.json"
);

console.info("Renaming all usages in package.json files...");
await globRename("./{packages,eslint,codemods}/*/package.json");

console.info("Renaming other well-known usages...");
await globRename([
"packages/babel-core/src/parser/util/missing-plugin-helper.ts",
"packages/babel-preset-env/src/available-plugins.ts",
"packages/babel-standalone/scripts/pluginConfig.json",
]);

async function globRename(pattern) {
for await (const filename of new Glob(pattern, {})) {
const oldContents = fs.readFileSync(filename, "utf8");
const newContents = oldContents.replaceAll(oldName, newName);
if (oldContents !== newContents) {
fs.writeFileSync(filename, newContents);
}
}
}

if (!process.env.SKIP_BOOTSTRAP) {
console.info("Running `make bootstrap`...");
execSync("make bootstrap", { stdio: "inherit" });
}