Skip to content
Open
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ third_party
.disable-auto-updates
/*.yml
generated.env.sh
dist
build-tools-spec*
9 changes: 9 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"cSpell.words": [
"gerrit",
"osid",
"REAPI",
"SDKROOT",
"SISO"
]
}
31 changes: 21 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,19 @@
"engines": {
"node": ">= 18.0.0"
},
"type": "module",
"main": "null",
"private": true,
"scripts": {
"lint:markdown": "electron-markdownlint \"**/*.md\"",
"lint:js": "prettier --check \"src/**/*.js\" \"tests/*.js\" \"src/e\"",
"lint:js": "prettier --check \"src/**/*.{js,ts}\" \"tests/*.{js,ts}\"",
"lint": "npm run lint:js && npm run lint:markdown",
"prettier:write": "prettier --write \"src/**/*.js\" \"tests/*.js\" \"src/e\"",
"prettier:write": "prettier --write \"src/**/*.{js,ts}\" \"tests/*.{js,ts}\"",
"prepare": "husky",
"pretest": "tsc",
"test": "nyc --reporter=lcov --reporter=text-summary vitest run --reporter=verbose --exclude tests/bootstrap.spec.mjs",
"test:all": "nyc --reporter=lcov --reporter=text-summary vitest run --reporter=verbose"
"test:all": "nyc --reporter=lcov --reporter=text-summary vitest run --reporter=verbose",
"postinstall": "tsc"
},
"repository": "https://github.com/electron/build-tools",
"author": "Electron Authors",
Expand All @@ -22,35 +25,43 @@
"@marshallofsound/chrome-cookies-secure": "^2.1.1",
"@octokit/auth-oauth-device": "^3.1.1",
"@octokit/rest": "^18.5.2",
"ajv": "^8.11.0",
"ajv-formats": "^2.1.1",
"chalk": "^2.4.1",
"@types/node": "^22.7.1",
"@types/progress": "^2.0.7",
"@types/semver": "^7.7.0",
"@types/tar": "^6.1.13",
"ajv": "^8.17.1",
"ajv-formats": "^3.0.1",
"chalk": "^5.4.1",
"command-exists": "^1.2.8",
"commander": "^9.0.0",
"commander": "^9.5.0",
"debug": "^4.3.1",
"extract-zip": "^2.0.1",
"inquirer": "^8.2.4",
"node-gyp": "^10.0.1",
"open": "^6.4.0",
"path-key": "^3.1.0",
"progress": "^2.0.3",
"readline-sync": "^1.4.10",
"semver": "^7.6.0",
"tar": "^6.2.1",
"typescript": "^5.8.3",
"vscode-uri": "^3.0.7",
"which": "^2.0.2",
"yaml": "^2.4.5"
},
"devDependencies": {
"@electron/lint-roller": "^1.13.0",
"@tsconfig/node22": "^22.0.2",
"@types/command-exists": "^1.2.3",
"@types/inquirer": "^8.0.0",
"@types/readline-sync": "^1.4.8",
"husky": "^9.1.6",
"json-schema-to-typescript": "^15.0.4",
"lint-staged": "^15.2.10",
"nyc": "^17.1.0",
"prettier": "^3.3.3",
"vitest": "^3.0.6"
},
"lint-staged": {
"*.js": [
"*.{js,ts}": [
"prettier --write"
],
"e": [
Expand Down
28 changes: 0 additions & 28 deletions src/download.js

This file was deleted.

32 changes: 32 additions & 0 deletions src/download.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import fs from 'node:fs';
import stream from 'node:stream';
import { pipeline } from 'node:stream/promises';

import { fatal } from './utils/logging.js';
import { progressStream } from './utils/download.js';

const write = fs.createWriteStream(process.argv[3]);

async function tryDownload(attemptsLeft = 3) {
const response = await fetch(process.argv[2]);
const total = parseInt(response.headers.get('content-length') || '1', 10);

let promise: Promise<void>;
if (process.env.CI) {
promise = pipeline(stream.Readable.fromWeb(response.body!), write);
} else {
const progress = progressStream(total, '[:bar] :mbRateMB/s :percent :etas');
promise = pipeline(stream.Readable.fromWeb(response.body!), progress, write);
}

await promise.catch((err) => {
if (attemptsLeft === 0) {
return fatal(err);
}

console.log('Download failed, trying', attemptsLeft, 'more times');
tryDownload(attemptsLeft - 1);
});
}

tryDownload();
28 changes: 14 additions & 14 deletions src/e-auto-update.js → src/e-auto-update.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
#!/usr/bin/env node

const chalk = require('chalk');
const cp = require('child_process');
const fs = require('fs');
const path = require('path');
const program = require('commander');
const semver = require('semver');
import chalk from 'chalk';
import cp from 'node:child_process';
import fs from 'node:fs';
import path from 'node:path';
import { program } from 'commander';
import semver from 'semver';

const { color, fatal } = require('./utils/logging');
import { color, fatal } from './utils/logging.js';

const BUILD_TOOLS_INSTALLER_MIN_VERSION = '1.1.0';

const markerFilePath = path.join(__dirname, '..', '.disable-auto-updates');
const markerFilePath = path.join(import.meta.dirname, '..', '.disable-auto-updates');

program
.description('Check for build-tools updates or enable/disable automatic updates')
Expand All @@ -27,7 +27,7 @@ program
}
console.log('Automatic updates enabled');
} catch (e) {
fatal(e);
fatal(e as Error);
}
});

Expand All @@ -39,7 +39,7 @@ program
fs.closeSync(fs.openSync(markerFilePath, 'w'));
console.log('Automatic updates disabled');
} catch (e) {
fatal(e);
fatal(e as Error);
}
});

Expand Down Expand Up @@ -72,7 +72,7 @@ function checkForUpdates() {
);

try {
packageJson = JSON.parse(fs.readFileSync(buildToolsInstallerPackage));
packageJson = JSON.parse(fs.readFileSync(buildToolsInstallerPackage, 'utf-8'));
} catch {
continue;
}
Expand All @@ -87,8 +87,8 @@ function checkForUpdates() {
break;
}

const execOpts = { cwd: path.resolve(__dirname, '..') };
const git = (args) => cp.execSync(`git ${args}`, execOpts).toString('utf8').trim();
const execOpts = { cwd: path.resolve(import.meta.dirname, '..') };
const git = (args: string) => cp.execSync(`git ${args}`, execOpts).toString('utf8').trim();

const headCmd = 'rev-parse --verify HEAD';
const headBefore = git(headCmd);
Expand Down Expand Up @@ -127,7 +127,7 @@ function checkForUpdates() {
console.log('build-tools updated to latest version!');
}
} catch (e) {
fatal(e);
fatal(e as Error);
}
}

Expand Down
56 changes: 35 additions & 21 deletions src/e-backport.js → src/e-backport.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#!/usr/bin/env node

const { Octokit } = require('@octokit/rest');
const chalk = require('chalk').default;
const program = require('commander');
const inquirer = require('inquirer');
const path = require('path');
import { Octokit } from '@octokit/rest';
import chalk from 'chalk';
import { program } from 'commander';
import inquirer from 'inquirer';
import path from 'node:path';

const evmConfig = require('./evm-config');
const { spawnSync } = require('./utils/depot-tools');
const { getGitHubAuthToken } = require('./utils/github-auth');
const { fatal } = require('./utils/logging');
import * as evmConfig from './evm-config.js';
import { depotSpawnSync } from './utils/depot-tools.js';
import { getGitHubAuthToken } from './utils/github-auth.js';
import { fatal } from './utils/logging.js';

program
.arguments('[pr]')
Expand All @@ -36,8 +36,8 @@ program
}

const targetBranches = pr.labels
.filter((label) => label.name.startsWith('needs-manual-bp/'))
.map((label) => label.name.substring(16));
.filter((label) => label.name?.startsWith('needs-manual-bp/'))
.map((label) => label.name!.substring(16));
if (targetBranches.length === 0) {
fatal('The given pull request is not needing any manual backports yet');
return;
Expand All @@ -56,24 +56,30 @@ program
const gitOpts = {
cwd: path.resolve(config.root, 'src', 'electron'),
stdio: 'pipe',
};
const result = spawnSync(config, 'git', ['status', '--porcelain'], gitOpts);
} as const;
const result = depotSpawnSync(config, 'git', ['status', '--porcelain'], gitOpts);
if (result.status !== 0 || result.stdout.toString().trim().length !== 0) {
fatal(
"Your current git working directory is not clean, we won't erase your local changes. Clean it up and try again",
);
return;
}

spawnSync(config, 'git', ['checkout', targetBranch], gitOpts, 'Failed to checkout base branch');
spawnSync(
depotSpawnSync(
config,
'git',
['checkout', targetBranch],
gitOpts,
'Failed to checkout base branch',
);
depotSpawnSync(
config,
'git',
['pull', 'origin', targetBranch],
gitOpts,
'Failed to update base branch',
);
spawnSync(
depotSpawnSync(
config,
'git',
['fetch', 'origin', pr.base.ref],
Expand All @@ -82,22 +88,30 @@ program
);

const manualBpBranch = `manual-bp/${user.login}/pr/${prNumber}/branch/${targetBranch}`;
spawnSync(config, 'git', ['branch', '-D', manualBpBranch], gitOpts);
spawnSync(
depotSpawnSync(config, 'git', ['branch', '-D', manualBpBranch], gitOpts);
depotSpawnSync(
config,
'git',
['checkout', '-b', manualBpBranch],
gitOpts,
`Failed to checkout new branch "${manualBpBranch}"`,
);

spawnSync(config, 'yarn', ['install'], gitOpts, `Failed to do "yarn install" on new branch`);
depotSpawnSync(
config,
'yarn',
['install'],
gitOpts,
`Failed to do "yarn install" on new branch`,
);

const cherryPickResult = spawnSync(config, 'git', ['cherry-pick', pr.merge_commit_sha], {
const cherryPickResult = depotSpawnSync(config, 'git', ['cherry-pick', pr.merge_commit_sha], {
cwd: gitOpts.cwd,
});

const pushCommand = chalk.yellow(!!config.remotes.electron.fork ? 'git push fork' : 'git push');
const pushCommand = chalk.yellow(
!!config.remotes?.electron.fork ? 'git push fork' : 'git push',
);
const cherryPickCommand = chalk.yellow('git cherry-pick --continue');
const prCommand = chalk.yellow(`e pr --backport ${prNumber}`);

Expand Down
Loading