From 9241156920a689849e3e0ae38688325189545fab Mon Sep 17 00:00:00 2001 From: Erick Zhao Date: Tue, 17 Dec 2024 22:16:55 -0800 Subject: [PATCH] chore: remove unused `utils` --- tools/fix-deps.ts | 39 --------- tools/position-docs.ts | 41 ---------- tools/update-dependencies.js | 151 ----------------------------------- tools/update-node-version.ts | 16 ---- 4 files changed, 247 deletions(-) delete mode 100644 tools/fix-deps.ts delete mode 100644 tools/position-docs.ts delete mode 100755 tools/update-dependencies.js delete mode 100644 tools/update-node-version.ts diff --git a/tools/fix-deps.ts b/tools/fix-deps.ts deleted file mode 100644 index 6e2e9040df..0000000000 --- a/tools/fix-deps.ts +++ /dev/null @@ -1,39 +0,0 @@ -import * as path from 'node:path'; - -import * as fs from 'fs-extra'; - -import { getPackageInfo } from './utils'; - -(async () => { - const packages = await getPackageInfo(); - - const baseJson = await fs.readJson(path.resolve(__dirname, '..', 'package.json')); - - const allDeps = { - ...baseJson.dependencies, - ...baseJson.devDependencies, - ...baseJson.optionalDependencies, - }; - - for (const p of packages) { - const json = await fs.readJson(path.resolve(p.path, 'package.json')); - - for (const key of ['dependencies', 'devDependencies', 'optionalDependencies']) { - const deps = json[key]; - if (!deps) continue; - - for (const depKey in deps) { - if (depKey.startsWith('@electron-forge/')) continue; - - if (deps[depKey] !== allDeps[depKey]) { - console.error(p.name, depKey, deps[depKey], '-->', allDeps[depKey]); - deps[depKey] = allDeps[depKey]; - } - } - } - - await fs.writeJson(path.resolve(p.path, 'package.json'), json, { - spaces: 2, - }); - } -})().catch(console.error); diff --git a/tools/position-docs.ts b/tools/position-docs.ts deleted file mode 100644 index 1ad1dfc497..0000000000 --- a/tools/position-docs.ts +++ /dev/null @@ -1,41 +0,0 @@ -import * as path from 'node:path'; - -import glob from 'fast-glob'; -import * as fs from 'fs-extra'; - -import { getPackageInfo } from './utils'; - -const DOCS_PATH = path.resolve(__dirname, '..', 'docs'); - -async function normalizeLinks(htmlFile: string, subPath: string): Promise { - const content: string = await fs.readFile(htmlFile, 'utf8'); - const relative: string = path.relative(path.resolve(DOCS_PATH, subPath), path.dirname(htmlFile)); - return content - .replace(/="[^"]*assets\//gi, '="/assets/') - .replace(/( `${m1}/${path.posix.join(subPath, relative, m2)}"`); -} - -(async () => { - const packages = await getPackageInfo(); - - let copiedAssets = false; - await fs.remove(path.resolve(DOCS_PATH, 'assets')); - await fs.remove(path.resolve(DOCS_PATH)); - for (const p of packages) { - const dir = p.path; - const subPath = path.posix.join(path.basename(path.dirname(dir)), path.basename(dir)); - const docPath = path.resolve(DOCS_PATH, subPath); - if (!copiedAssets) { - await fs.copy(path.resolve(dir, 'doc', 'assets'), path.resolve(DOCS_PATH, 'assets')); - copiedAssets = true; - } - await fs.copy(path.resolve(dir, 'doc'), docPath); - await fs.remove(path.resolve(docPath, 'assets')); - - // Rewrite assets path to allow better cross-dep caching - // otherwise each module will have it's own unique JS file :( - for (const htmlFile of await glob(path.resolve(docPath, '**', '*.html'))) { - await fs.writeFile(htmlFile, await normalizeLinks(htmlFile, subPath)); - } - } -})(); diff --git a/tools/update-dependencies.js b/tools/update-dependencies.js deleted file mode 100755 index 3d74e40e94..0000000000 --- a/tools/update-dependencies.js +++ /dev/null @@ -1,151 +0,0 @@ -#!/usr/bin/env node - -const { spawn } = require('@malept/cross-spawn-promise'); -const glob = require('fast-glob'); -const { satisfies } = require('semver'); - -const DO_NOT_UPGRADE = [ - '@types/node-fetch', // No longer needed when node-fetch is upgraded to >= 3.0.0 - '@typescript-eslint/eslint-plugin', // special case - 'chalk', // Requires ESM - 'commander', // TODO: convert to yargs - 'eslint-plugin-mocha', // Requires Node 14 - 'find-up', // Requires ESM - 'log-symbols', // Requires ESM - 'node-fetch', // Requires ESM - 'ora', // Requires ESM - 'username', // Requires ESM -]; - -/** - * Spawn, but pass through stdio by default. - */ -async function spawnPassthrough(cmd, args, options) { - await spawn(cmd, args, { stdio: 'inherit', ...options }); -} - -async function git(...args) { - await spawnPassthrough('git', args); -} - -async function yarn(...args) { - await spawnPassthrough('yarn', args); -} - -const packageJSON = require(__dirname + '/../package.json'); - -class Package { - constructor(name, currentVersion, wantedVersion, latestVersion, type) { - this.name = name; - this.currentVersion = currentVersion; - this.wantedVersion = wantedVersion; - this.latestVersion = latestVersion; - this.type = type; - } - - get commitType() { - switch (this.type) { - case 'dependencies': - case 'optionalDependencies': - return 'deps'; - case 'devDependencies': - return 'deps-dev'; - default: - return 'deps-unknown'; - } - } - - get commitVersion() { - if (this.isMajorVersionBump()) { - return `^${this.latestVersion}`; - } else if (this.isMinorVersionBump()) { - return `~${this.latestVersion}`; - } else { - return this.latestVersion; - } - } - - get minorVersionLocked() { - return packageJSON[this.type][this.name].startsWith('~'); - } - - isMajorVersionBump() { - return !satisfies(this.latestVersion, `^${this.wantedVersion}`); - } - - isMinorVersionBump() { - return this.minorVersionLocked && !satisfies(this.latestVersion, `~${this.wantedVersion}`); - } - - async smoketestAndCommit(packageName = null) { - const packageJSONs = await glob('packages/*/*/package.json'); - await yarn('lint'); - await yarn('build'); - await git('add', 'package.json', 'yarn.lock', ...packageJSONs); - await git('commit', '-m', `build(${this.commitType}): upgrade ${packageName || this.name} to ${this.commitVersion}`); - } - - async upgrade() { - if (this.isMajorVersionBump() || this.isMinorVersionBump()) { - await this.yarn_upgrade_and_update_packageJSON(); - } else { - await this.yarn_upgrade_in_yarn_lock(); - } - } - - async yarn_upgrade_and_update_packageJSON() { - console.log(`Upgrading ${this.name} from ${this.wantedVersion} to ^${this.latestVersion} (and updating package.json)...`); - await yarn('upgrade', `${this.name}@^${this.latestVersion}`); - } - - async yarn_upgrade_in_yarn_lock() { - console.log(`Upgrading ${this.name} from ${this.currentVersion} to ${this.latestVersion} in yarn.lock...`); - await yarn('upgrade', this.name); - } -} - -async function main() { - const onlyModules = []; - if (process.argv.length > 2) { - onlyModules.push(...process.argv.slice(2)); - } - try { - await spawn('yarn', ['outdated', '--json']); - console.log('No packages to update.'); - } catch (error) { - const table = JSON.parse(error.stdout.split('\n')[1]); - for (const [packageName, currentVersion, wantedVersion, latestVersion, packageType /*, _url */] of table.data.body) { - if (DO_NOT_UPGRADE.includes(packageName)) { - console.log(`Skipping "${packageName} from update as it is in the denylist`); - continue; - } - if (onlyModules.length > 0 && !onlyModules.includes(packageName)) { - console.log(`Skipping "${packageName}" from update as it was not specified on the command line`); - continue; - } - let commitPackageName = null; - const nodePackage = new Package(packageName, currentVersion, wantedVersion, latestVersion, packageType); - await nodePackage.upgrade(); - - if (packageName === '@typescript-eslint/parser') { - const eslintPlugin = new Package('@typescript-eslint/eslint-plugin', currentVersion, wantedVersion, latestVersion, packageType); - await eslintPlugin.upgrade(); - commitPackageName = '@typescript-eslint/{parser,eslint-plugin}'; - } - - await nodePackage.smoketestAndCommit(commitPackageName); - } - } - - if (onlyModules.length == 0) { - console.log(`Upgrading transitive dependencies in yarn.lock...`); - await yarn('upgrade'); - await git('add', 'yarn.lock'); - await git('commit', '-m', `build(deps): upgrade transitive dependencies`); - } -} - -main().catch((err) => { - console.error(err); - process.exit(1); -}); diff --git a/tools/update-node-version.ts b/tools/update-node-version.ts deleted file mode 100644 index cb5dfd16fc..0000000000 --- a/tools/update-node-version.ts +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/env ts-node - -import path from 'node:path'; - -import { readJsonSync, writeJsonSync } from 'fs-extra'; - -import { getPackageInfoSync } from './utils'; - -const nodeVersion = process.argv[2]; - -for (const { path: packagePath } of getPackageInfoSync()) { - const filename = path.join(packagePath, 'package.json'); - const packageJSON = readJsonSync(filename); - packageJSON.engines.node = `>= ${nodeVersion}`; - writeJsonSync(filename, packageJSON, { spaces: 2 }); -}