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

build: refactor tools scripts to remove third-party deps #1622

Merged
merged 1 commit into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@
"@types/fs-extra": "^9.0.7",
"@types/getos": "^3.0.1",
"@types/jest": "^29.5.3",
"@types/log-symbols": "^3.0.0",
"@types/node": "^20.10.0",
"@types/react": "^16.14.0",
"@types/react-dom": "^16.9.11",
Expand Down Expand Up @@ -131,7 +130,7 @@
"less": "^4.1.1",
"less-loader": "^11.0.0",
"lint-staged": "^15.2.7",
"log-symbols": "^4.0.0",
"log-symbols": "^6.0.0",
"mini-css-extract-plugin": "^2.6.1",
"monaco-editor-webpack-plugin": "2.1.0",
"npm-run-all": "^4.1.5",
Expand Down
21 changes: 15 additions & 6 deletions tools/contributors.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import * as fs from 'node:fs';
import * as path from 'node:path';
import * as util from 'node:util';

import fetch from 'cross-fetch';
import fs from 'fs-extra';
import logSymbols from 'log-symbols';

const { GITHUB_TOKEN, GH_TOKEN } = process.env;
const CONTRIBUTORS_FILE_PATH = path.join(
__dirname,
Expand Down Expand Up @@ -38,7 +35,12 @@ interface ContributorInfo {
location: string;
}

// Helper function to work around import issues with ESM module
const dynamicImport = new Function('specifier', 'return import(specifier)');

export async function maybeFetchContributors(silent?: boolean): Promise<void> {
const { default: logSymbols } = await dynamicImport('log-symbols');

try {
const stats = fs.statSync(CONTRIBUTORS_FILE_PATH);
const mtime = new Date(util.inspect(stats.mtime));
Expand All @@ -54,7 +56,9 @@ export async function maybeFetchContributors(silent?: boolean): Promise<void> {
}
await fetchAndWriteContributorsFile();
} else {
const contributors = await fs.readJson(CONTRIBUTORS_FILE_PATH);
const contributors = JSON.parse(
await fs.promises.readFile(CONTRIBUTORS_FILE_PATH, 'utf-8'),
);
if (contributors.length === 0) {
// File exists, but is empty
await fetchAndWriteContributorsFile();
Expand Down Expand Up @@ -157,6 +161,8 @@ function fetchContributors() {
* Fetch the contributors and write the result to disk
*/
async function fetchAndWriteContributorsFile() {
const { default: logSymbols } = await dynamicImport('log-symbols');

await new Promise<void>((resolve) => {
fs.access(
CONTRIBUTORS_FILE_PATH,
Expand Down Expand Up @@ -186,7 +192,10 @@ async function fetchAndWriteContributorsFile() {
data = [];
}

await fs.outputFile(CONTRIBUTORS_FILE_PATH, JSON.stringify(data));
await fs.promises.writeFile(
CONTRIBUTORS_FILE_PATH,
JSON.stringify(data),
);

console.log(logSymbols.success, `${data.length} Contributors fetched`);
resolve();
Expand Down
4 changes: 2 additions & 2 deletions tools/fetch-releases.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as fs from 'node:fs';
import * as path from 'node:path';

import { ElectronVersions } from '@electron/fiddle-core';
import fs from 'fs-extra';

const file = path.join(__dirname, '..', 'static', 'releases.json');

Expand All @@ -16,7 +16,7 @@ export async function populateReleases() {
`Updating local releases.json with ${releases.length} versions.`,
);

await fs.outputJSON(file, releases);
await fs.promises.writeFile(file, JSON.stringify(releases));
} else if (process.env.CI) {
throw new Error('Failed to fetch latest releases.json');
} else {
Expand Down
33 changes: 13 additions & 20 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2551,13 +2551,6 @@
dependencies:
"@types/node" "*"

"@types/log-symbols@^3.0.0":
version "3.0.0"
resolved "https://registry.npmjs.org/@types/log-symbols/-/log-symbols-3.0.0.tgz"
integrity sha512-uW/AGf/41aZ1c1dhZ3s063Ii2OqT8EQooZu3t4VCRyR3dqyA2Bg46BcKyZpnWTY7wzm6cayq4jzylnruu4KqSA==
dependencies:
log-symbols "*"

"@types/mdast@^3.0.0":
version "3.0.15"
resolved "https://registry.yarnpkg.com/@types/mdast/-/mdast-3.0.15.tgz#49c524a263f30ffa28b71ae282f813ed000ab9f5"
Expand Down Expand Up @@ -3847,7 +3840,7 @@ chalk@^4.0.0, chalk@^4.1.0, chalk@^4.1.1, chalk@^4.1.2:
ansi-styles "^4.1.0"
supports-color "^7.1.0"

chalk@~5.3.0:
chalk@^5.3.0, chalk@~5.3.0:
version "5.3.0"
resolved "https://registry.yarnpkg.com/chalk/-/chalk-5.3.0.tgz#67c20a7ebef70e7f3970a01f90fa210cb6860385"
integrity sha512-dLitG79d+GV1Nb/VYcCDFivJeK1hiukt9QjRNVOsUtTy1rR1YJsmpGGTZ3qJos+uw7WmWF4wUwBd9jxjocFC2w==
Expand Down Expand Up @@ -7263,10 +7256,10 @@ is-unicode-supported@^0.1.0:
resolved "https://registry.npmjs.org/is-unicode-supported/-/is-unicode-supported-0.1.0.tgz"
integrity sha512-knxG2q4UC3u8stRGyAVJCOdxFmv5DZiRcdlIaAQXAbSfJya+OhopNotLQrstBhququ4ZpuKbDc/8S6mgXgPFPw==

is-unicode-supported@^1.0.0:
version "1.0.0"
resolved "https://registry.npmjs.org/is-unicode-supported/-/is-unicode-supported-1.0.0.tgz"
integrity sha512-TfeaLetCvWAJ/QjG8zBbr0H2LXE0m/Oatp25w0kgU2T/N+Xd2VMV3ENm/h3H4/ajBG9euaK2gsqipL4aCz8lTQ==
is-unicode-supported@^1.3.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/is-unicode-supported/-/is-unicode-supported-1.3.0.tgz#d824984b616c292a2e198207d4a609983842f714"
integrity sha512-43r2mRvz+8JRIKnWJ+3j8JtjRKZ6GmjzfaE/qiBJnikNnYv/6bagRJ1kUhNk8R5EX/GkobD+r+sfxCPJsiKBLQ==

is-url@^1.1.0, is-url@^1.2.4:
version "1.2.4"
Expand Down Expand Up @@ -8278,14 +8271,6 @@ lodash@^4.17.11, lodash@^4.17.15, lodash@^4.17.20, lodash@^4.17.21, lodash@^4.17
resolved "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz"
integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==

log-symbols@*:
version "5.0.0"
resolved "https://registry.npmjs.org/log-symbols/-/log-symbols-5.0.0.tgz"
integrity sha512-zBsSKauX7sM0kcqrf8VpMRPqcWzU6a/Wi7iEl0QlVSCiIZ4CctaLdfVdiZUn6q2/nenyt392qJqpw9FhNAwqxQ==
dependencies:
chalk "^4.1.0"
is-unicode-supported "^1.0.0"

log-symbols@^4.0.0, log-symbols@^4.1.0:
version "4.1.0"
resolved "https://registry.npmjs.org/log-symbols/-/log-symbols-4.1.0.tgz"
Expand All @@ -8294,6 +8279,14 @@ log-symbols@^4.0.0, log-symbols@^4.1.0:
chalk "^4.1.0"
is-unicode-supported "^0.1.0"

log-symbols@^6.0.0:
version "6.0.0"
resolved "https://registry.yarnpkg.com/log-symbols/-/log-symbols-6.0.0.tgz#bb95e5f05322651cac30c0feb6404f9f2a8a9439"
integrity sha512-i24m8rpwhmPIS4zscNzK6MSEhk0DUWa/8iYQWxhffV8jkI4Phvs3F+quL5xvS0gdQR0FyTCMMH33Y78dDTzzIw==
dependencies:
chalk "^5.3.0"
is-unicode-supported "^1.3.0"

log-update@^4.0.0:
version "4.0.0"
resolved "https://registry.npmjs.org/log-update/-/log-update-4.0.0.tgz"
Expand Down