diff --git a/.eslintrc.js b/.eslintrc.js index da419dec4..53f86d181 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -134,7 +134,7 @@ module.exports = { }, }, { - files: ["**/*.mjs"], + files: ["**/*.mjs", "scripts/release/**/*.js"], parserOptions: { sourceType: "module", }, diff --git a/scripts/release/package.json b/scripts/release/package.json index afe9f8e64..c0662eab8 100644 --- a/scripts/release/package.json +++ b/scripts/release/package.json @@ -1,5 +1,6 @@ { "private": true, + "type": "module", "dependencies": { "chalk": "4.1.1", "execa": "5.1.1", @@ -7,6 +8,6 @@ "node-fetch": "2.6.1", "outdent": "0.8.0", "semver": "7.3.5", - "string-width": "4.2.0" + "string-width": "5.0.0" } } diff --git a/scripts/release/release.js b/scripts/release/release.js index 8a737a6b9..5782d5093 100644 --- a/scripts/release/release.js +++ b/scripts/release/release.js @@ -1,15 +1,17 @@ #!/usr/bin/env node -"use strict"; - -const { exec } = require("child_process"); +import { exec } from "node:child_process"; +import { fileURLToPath } from "node:url"; +import path from "node:path"; async function run() { - const chalk = require("chalk"); - const minimist = require("minimist"); - const semver = require("semver"); - const { string: outdentString } = require("outdent"); - const { runGit, readJson } = require("./utils.js"); + const importDefault = async (module) => (await import(module)).default; + + const chalk = await importDefault("chalk"); + const minimist = await importDefault("minimist"); + const semver = await importDefault("semver"); + const { string: outdentString } = await importDefault("outdent"); + const { runGit, readJson } = await import("./utils.js"); const params = minimist(process.argv.slice(2), { string: ["version"], @@ -32,20 +34,22 @@ async function run() { ).version; } - const steps = [ - require("./steps/validate-new-version.js"), - require("./steps/check-git-status.js"), - require("./steps/install-dependencies.js"), - require("./steps/run-tests.js"), - require("./steps/update-version.js"), - require("./steps/generate-bundles.js"), - require("./steps/update-changelog.js"), - require("./steps/push-to-git.js"), - require("./steps/publish-to-npm.js"), - require("./steps/bump-prettier.js"), - require("./steps/update-dependents-count.js"), - require("./steps/post-publish-steps.js"), - ]; + const steps = await Promise.all( + [ + "./steps/validate-new-version.js", + "./steps/check-git-status.js", + "./steps/install-dependencies.js", + "./steps/run-tests.js", + "./steps/update-version.js", + "./steps/generate-bundles.js", + "./steps/update-changelog.js", + "./steps/push-to-git.js", + "./steps/publish-to-npm.js", + "./steps/bump-prettier.js", + "./steps/update-dependents-count.js", + "./steps/post-publish-steps.js", + ].map((step) => importDefault(step)) + ); try { for (const step of steps) { @@ -64,7 +68,7 @@ exec( "git fetch --tags", // Fetch git tags to get the previous version number (i.e. the latest tag) "yarn install", // Install script's dependencies before any require ].join(" && "), - { cwd: __dirname }, + { cwd: path.dirname(fileURLToPath(import.meta.url)) }, (error) => { if (error) { console.error(error); diff --git a/scripts/release/steps/bump-prettier.js b/scripts/release/steps/bump-prettier.js index 1a64b1911..0084a1eb2 100644 --- a/scripts/release/steps/bump-prettier.js +++ b/scripts/release/steps/bump-prettier.js @@ -1,14 +1,6 @@ -"use strict"; - -const fs = require("fs"); -const semver = require("semver"); -const { - runYarn, - runGit, - logPromise, - readJson, - writeJson, -} = require("../utils.js"); +import fs from "node:fs"; +import semver from "semver"; +import { runYarn, runGit, logPromise, readJson, writeJson } from "../utils.js"; async function format() { await runYarn(["lint:eslint", "--fix"]); @@ -44,7 +36,7 @@ async function bump({ await writeJson("package.json", pkg, { spaces: 2 }); } -module.exports = async function (params) { +export default async function (params) { const { dry, version } = params; if (dry) { @@ -59,4 +51,4 @@ module.exports = async function (params) { await logPromise("Updating files", format()); await logPromise("Bump default branch version", bump(params)); await logPromise("Committing changed files", commit(version)); -}; +} diff --git a/scripts/release/steps/check-git-status.js b/scripts/release/steps/check-git-status.js index 139098a9a..7860b3ec3 100644 --- a/scripts/release/steps/check-git-status.js +++ b/scripts/release/steps/check-git-status.js @@ -1,8 +1,6 @@ -"use strict"; +import { runGit } from "../utils.js"; -const { runGit } = require("../utils.js"); - -module.exports = async function () { +export default async function () { const { stdout: status } = await runGit(["status", "--porcelain"]); if (status) { @@ -11,4 +9,4 @@ module.exports = async function () { "Please revert or commit all local changes before making a release." ); } -}; +} diff --git a/scripts/release/steps/generate-bundles.js b/scripts/release/steps/generate-bundles.js index f52b77827..f5b799aba 100644 --- a/scripts/release/steps/generate-bundles.js +++ b/scripts/release/steps/generate-bundles.js @@ -1,9 +1,7 @@ -"use strict"; +import chalk from "chalk"; +import { runYarn, logPromise, readJson } from "../utils.js"; -const chalk = require("chalk"); -const { runYarn, logPromise, readJson } = require("../utils.js"); - -module.exports = async function ({ version }) { +export default async function ({ version }) { await logPromise("Generating bundles", runYarn(["build", "--purge-cache"])); const builtPkg = await readJson("dist/package.json"); @@ -16,4 +14,4 @@ module.exports = async function ({ version }) { await logPromise("Running tests on generated bundles", runYarn("test:dist")); console.log(chalk.green.bold("Build successful!\n")); -}; +} diff --git a/scripts/release/steps/install-dependencies.js b/scripts/release/steps/install-dependencies.js index 62d156df3..8d5928143 100644 --- a/scripts/release/steps/install-dependencies.js +++ b/scripts/release/steps/install-dependencies.js @@ -1,7 +1,5 @@ -"use strict"; - -const execa = require("execa"); -const { runYarn, runGit, logPromise } = require("../utils.js"); +import execa from "execa"; +import { runYarn, runGit, logPromise } from "../utils.js"; async function install() { await execa("rm", ["-rf", "node_modules"]); @@ -15,6 +13,6 @@ async function install() { } } -module.exports = function () { +export default function () { return logPromise("Installing NPM dependencies", install()); -}; +} diff --git a/scripts/release/steps/post-publish-steps.js b/scripts/release/steps/post-publish-steps.js index 997cdccd2..3d4346149 100644 --- a/scripts/release/steps/post-publish-steps.js +++ b/scripts/release/steps/post-publish-steps.js @@ -1,9 +1,9 @@ -"use strict"; +import chalk from "chalk"; +import outdent from "outdent"; +import execa from "execa"; +import { fetchText, logPromise } from "../utils.js"; -const chalk = require("chalk"); -const { string: outdentString } = require("outdent"); -const execa = require("execa"); -const { fetchText, logPromise } = require("../utils.js"); +const outdentString = outdent.string; const SCHEMA_REPO = "SchemaStore/schemastore"; const SCHEMA_PATH = "src/schemas/json/prettierrc.json"; @@ -43,7 +43,7 @@ function twitterAnnouncement() { `); } -module.exports = async function () { +export default async function () { const steps = [await checkSchema(), twitterAnnouncement()].filter(Boolean); console.log(chalk.bold.green("The script has finished!\n")); @@ -61,4 +61,4 @@ module.exports = async function () { ${steps.join("\n\n")} `) ); -}; +} diff --git a/scripts/release/steps/publish-to-npm.js b/scripts/release/steps/publish-to-npm.js index 9e884b177..f4fede901 100644 --- a/scripts/release/steps/publish-to-npm.js +++ b/scripts/release/steps/publish-to-npm.js @@ -1,9 +1,9 @@ -"use strict"; +import chalk from "chalk"; +import outdent from "outdent"; +import execa from "execa"; +import { logPromise, waitForEnter } from "../utils.js"; -const chalk = require("chalk"); -const { string: outdentString } = require("outdent"); -const execa = require("execa"); -const { logPromise, waitForEnter } = require("../utils.js"); +const outdentString = outdent.string; /** * Retry "npm publish" when to enter OTP is failed. @@ -27,7 +27,7 @@ async function retryNpmPublish() { } } -module.exports = async function ({ dry, version }) { +export default async function ({ dry, version }) { if (dry) { return; } @@ -54,4 +54,4 @@ module.exports = async function ({ dry, version }) { `) ); await waitForEnter(); -}; +} diff --git a/scripts/release/steps/push-to-git.js b/scripts/release/steps/push-to-git.js index 646fec422..914b53713 100644 --- a/scripts/release/steps/push-to-git.js +++ b/scripts/release/steps/push-to-git.js @@ -1,6 +1,4 @@ -"use strict"; - -const { runGit, logPromise } = require("../utils.js"); +import { runGit, logPromise } from "../utils.js"; async function pushGit({ version }) { await runGit(["commit", "-am", `Release ${version}`]); @@ -9,10 +7,10 @@ async function pushGit({ version }) { await runGit(["push", "--tags"]); } -module.exports = function (params) { +export default function (params) { if (params.dry) { return; } return logPromise("Committing and pushing to remote", pushGit(params)); -}; +} diff --git a/scripts/release/steps/run-tests.js b/scripts/release/steps/run-tests.js index 84189ae78..cf1f4880b 100644 --- a/scripts/release/steps/run-tests.js +++ b/scripts/release/steps/run-tests.js @@ -1,9 +1,7 @@ -"use strict"; +import { runYarn, logPromise } from "../utils.js"; -const { runYarn, logPromise } = require("../utils.js"); - -module.exports = async function () { +export default async function () { await logPromise("Running linter", runYarn("lint:eslint")); await logPromise("Running Prettier on docs", runYarn("lint:prettier")); await logPromise("Running tests", runYarn("test")); -}; +} diff --git a/scripts/release/steps/update-changelog.js b/scripts/release/steps/update-changelog.js index afc6c997f..1f3d0abcb 100644 --- a/scripts/release/steps/update-changelog.js +++ b/scripts/release/steps/update-changelog.js @@ -1,11 +1,11 @@ -"use strict"; +import fs from "node:fs"; +import execa from "execa"; +import chalk from "chalk"; +import outdent from "outdent"; +import semver from "semver"; +import { waitForEnter, runYarn, logPromise } from "../utils.js"; -const fs = require("fs"); -const execa = require("execa"); -const chalk = require("chalk"); -const { outdent, string: outdentString } = require("outdent"); -const semver = require("semver"); -const { waitForEnter, runYarn, logPromise } = require("../utils.js"); +const outdentString = outdent.string; function getBlogPostInfo(version) { const date = new Date(); @@ -42,7 +42,7 @@ async function getChangelogForPatch({ version, previousVersion }) { return changelog; } -module.exports = async function ({ version, previousVersion }) { +export default async function ({ version, previousVersion }) { const semverDiff = semver.diff(version, previousVersion); if (semverDiff !== "patch") { @@ -81,4 +81,4 @@ module.exports = async function ({ version, previousVersion }) { "Re-running Prettier on docs", runYarn(["lint:prettier", "--write"]) ); -}; +} diff --git a/scripts/release/steps/update-dependents-count.js b/scripts/release/steps/update-dependents-count.js index 43dd01a60..ce46a0e50 100644 --- a/scripts/release/steps/update-dependents-count.js +++ b/scripts/release/steps/update-dependents-count.js @@ -1,7 +1,5 @@ -"use strict"; - -const chalk = require("chalk"); -const { runGit, fetchText, logPromise, processFile } = require("../utils.js"); +import chalk from "chalk"; +import { runGit, fetchText, logPromise, processFile } from "../utils.js"; async function update() { const npmPage = await logPromise( @@ -73,10 +71,10 @@ function formatNumber(value) { return Math.floor(value / 1e5) / 10 + " million"; } -module.exports = async function () { +export default async function () { try { await update(); } catch (error) { console.log(chalk.red.bold(error.message)); } -}; +} diff --git a/scripts/release/steps/update-version.js b/scripts/release/steps/update-version.js index 7e1b29ad9..dce557463 100644 --- a/scripts/release/steps/update-version.js +++ b/scripts/release/steps/update-version.js @@ -1,12 +1,10 @@ -"use strict"; - -const { +import { runYarn, logPromise, readJson, writeJson, processFile, -} = require("../utils.js"); +} from "../utils.js"; async function bump({ version }) { const pkg = await readJson("package.json"); @@ -34,6 +32,6 @@ async function bump({ version }) { }); } -module.exports = async function (params) { +export default async function (params) { await logPromise("Bumping version", bump(params)); -}; +} diff --git a/scripts/release/steps/validate-new-version.js b/scripts/release/steps/validate-new-version.js index fd3ab548f..b936f4625 100644 --- a/scripts/release/steps/validate-new-version.js +++ b/scripts/release/steps/validate-new-version.js @@ -1,9 +1,7 @@ -"use strict"; +import chalk from "chalk"; +import semver from "semver"; -const chalk = require("chalk"); -const semver = require("semver"); - -module.exports = function ({ version, previousVersion }) { +export default function ({ version, previousVersion }) { if (!semver.valid(version)) { throw new Error("Invalid version specified"); } @@ -13,4 +11,4 @@ module.exports = function ({ version, previousVersion }) { `Version ${chalk.yellow(version)} has already been published` ); } -}; +} diff --git a/scripts/release/utils.js b/scripts/release/utils.js index 7f52e4d0a..8ce3589c1 100644 --- a/scripts/release/utils.js +++ b/scripts/release/utils.js @@ -1,12 +1,11 @@ -"use strict"; +import fs from "node:fs"; +import readline from "node:readline"; +import chalk from "chalk"; +import execa from "execa"; +import stringWidth from "string-width"; +import fetch from "node-fetch"; -require("readline").emitKeypressEvents(process.stdin); - -const fs = require("fs"); -const chalk = require("chalk"); -const execa = require("execa"); -const stringWidth = require("string-width"); -const fetch = require("node-fetch"); +readline.emitKeypressEvents(process.stdin); const OK = chalk.bgGreen.black(" DONE "); const FAIL = chalk.bgRed.black(" FAIL "); @@ -91,7 +90,7 @@ async function fetchText(url) { return response.text(); } -module.exports = { +export { runYarn, runGit, fetchText, diff --git a/scripts/release/yarn.lock b/scripts/release/yarn.lock index bb3fbe9a2..7040c660d 100644 --- a/scripts/release/yarn.lock +++ b/scripts/release/yarn.lock @@ -2,10 +2,10 @@ # yarn lockfile v1 -ansi-regex@^5.0.0: - version "5.0.0" - resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-5.0.0.tgz#388539f55179bf39339c81af30a654d69f87cb75" - integrity sha512-bY6fj56OUQ0hU1KjFNDQuJFezqKdrAyFdIevADiqrWHwSlbmBNMHp5ak2f40Pm8JTFyM2mqxkG6ngkHO11f/lg== +ansi-regex@^6.0.0: + version "6.0.0" + resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-6.0.0.tgz#ecc7f5933cbe5ac7b33e209a5ff409ab1669c6b2" + integrity sha512-tAaOSrWCHF+1Ear1Z4wnJCXA9GGox4K6Ic85a5qalES2aeEwQGr7UC93mwef49536PkCYjzkp0zIxfFvexJ6zQ== ansi-styles@^4.1.0: version "4.3.0" @@ -43,10 +43,10 @@ cross-spawn@^7.0.3: shebang-command "^2.0.0" which "^2.0.1" -emoji-regex@^8.0.0: - version "8.0.0" - resolved "https://registry.yarnpkg.com/emoji-regex/-/emoji-regex-8.0.0.tgz#e818fd69ce5ccfcb404594f842963bf53164cc37" - integrity sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A== +emoji-regex@^9.2.2: + version "9.2.2" + resolved "https://registry.yarnpkg.com/emoji-regex/-/emoji-regex-9.2.2.tgz#840c8803b0d8047f4ff0cf963176b32d4ef3ed72" + integrity sha512-L18DaJsXSUk2+42pv8mLs5jJT2hqFkFE4j21wOmgbUqsZ2hL72NsUU785g9RXgo3s0ZNgVl42TiHp3ZtOv/Vyg== execa@5.1.1: version "5.1.1" @@ -78,10 +78,10 @@ human-signals@^2.1.0: resolved "https://registry.yarnpkg.com/human-signals/-/human-signals-2.1.0.tgz#dc91fcba42e4d06e4abaed33b3e7a3c02f514ea0" integrity sha512-B4FFZ6q/T2jhhksgkbEW3HBvWIfDW85snkQgawt07S7J5QXTk6BkNV+0yAeZrM5QpMAdYlocGoljn0sJ/WQkFw== -is-fullwidth-code-point@^3.0.0: - version "3.0.0" - resolved "https://registry.yarnpkg.com/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz#f116f8064fe90b3f7844a38997c0b75051269f1d" - integrity sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg== +is-fullwidth-code-point@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/is-fullwidth-code-point/-/is-fullwidth-code-point-4.0.0.tgz#fae3167c729e7463f8461ce512b080a49268aa88" + integrity sha512-O4L094N2/dZ7xqVdrXhh9r1KODPJpFms8B5sGdJLPy664AgvXsreZUyCQQNItZRDlYug4xStLjNp/sz3HvBowQ== is-stream@^2.0.0: version "2.0.0" @@ -167,21 +167,21 @@ signal-exit@^3.0.3: resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.3.tgz#a1410c2edd8f077b08b4e253c8eacfcaf057461c" integrity sha512-VUJ49FC8U1OxwZLxIbTTrDvLnf/6TDgxZcK8wxR8zs13xpx7xbG60ndBlhNrFi2EMuFRoeDoJO7wthSLq42EjA== -string-width@4.2.0: - version "4.2.0" - resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.0.tgz#952182c46cc7b2c313d1596e623992bd163b72b5" - integrity sha512-zUz5JD+tgqtuDjMhwIg5uFVV3dtqZ9yQJlZVfq4I01/K5Paj5UHj7VyrQOJvzawSVlKpObApbfD0Ed6yJc+1eg== +string-width@5.0.0: + version "5.0.0" + resolved "https://registry.yarnpkg.com/string-width/-/string-width-5.0.0.tgz#19191f152f937b96f4ec54ba0986a5656660c5a2" + integrity sha512-zwXcRmLUdiWhMPrHz6EXITuyTgcEnUqDzspTkCLhQovxywWz6NP9VHgqfVg20V/1mUg0B95AKbXxNT+ALRmqCw== dependencies: - emoji-regex "^8.0.0" - is-fullwidth-code-point "^3.0.0" - strip-ansi "^6.0.0" + emoji-regex "^9.2.2" + is-fullwidth-code-point "^4.0.0" + strip-ansi "^7.0.0" -strip-ansi@^6.0.0: - version "6.0.0" - resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.0.tgz#0b1571dd7669ccd4f3e06e14ef1eed26225ae532" - integrity sha512-AuvKTrTfQNYNIctbR1K/YGTR1756GycPsg7b9bdV9Duqur4gv6aKqHXah67Z8ImS7WEz5QVcOtlfW2rZEugt6w== +strip-ansi@^7.0.0: + version "7.0.0" + resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-7.0.0.tgz#1dc49b980c3a4100366617adac59327eefdefcb0" + integrity sha512-UhDTSnGF1dc0DRbUqr1aXwNoY3RgVkSWG8BrpnuFIxhP57IqbS7IRta2Gfiavds4yCxc5+fEAVVOgBZWnYkvzg== dependencies: - ansi-regex "^5.0.0" + ansi-regex "^6.0.0" strip-final-newline@^2.0.0: version "2.0.0"