Skip to content

Commit

Permalink
chore: remove execa dependency (#722)
Browse files Browse the repository at this point in the history
  • Loading branch information
aduh95 authored Sep 4, 2023
1 parent 4b2b6fa commit ff79809
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 29 deletions.
12 changes: 7 additions & 5 deletions components/git/v8.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import path from 'node:path';

import { execa } from 'execa';
import logSymbols from 'log-symbols';

import { minor, major, backport } from '../../lib/update-v8/index.js';
import { defaultBaseDir } from '../../lib/update-v8/constants.js';
import { checkCwd } from '../../lib/update-v8/common.js';
import { runAsync } from '../../lib/run.js';

export const command = 'v8 [major|minor|backport]';
export const describe = 'Update or patch the V8 engine';
Expand Down Expand Up @@ -80,14 +80,16 @@ export function handler(argv) {

options.execGitNode = function execGitNode(cmd, args, input) {
args.unshift(cmd);
return execa('git', args, {
cwd: options.nodeDir,
...input && { input }
return runAsync('git', args, {
spawnArgs: {
cwd: options.nodeDir,
...input && { input }
}
});
};

options.execGitV8 = function execGitV8(...args) {
return execa('git', args, { cwd: options.v8Dir });
return runAsync('git', args, { captureStdout: true, spawnArgs: { cwd: options.v8Dir } });
};

Promise.resolve()
Expand Down
6 changes: 3 additions & 3 deletions lib/update-v8/backport.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ function generatePatches() {
try {
const fullShas = await Promise.all(
shas.map(async(sha) => {
const { stdout } = await ctx.execGitV8('rev-parse', sha);
const stdout = await ctx.execGitV8('rev-parse', sha);
return stdout;
})
);
Expand All @@ -146,8 +146,8 @@ function generatePatches() {
]);
return {
sha,
data: patch.stdout,
message: message.stdout
data: patch,
message
};
}));
} catch (e) {
Expand Down
14 changes: 7 additions & 7 deletions lib/update-v8/majorUpdate.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import path from 'node:path';
import { promises as fs } from 'node:fs';

import Enquirer from 'enquirer';
import { execa } from 'execa';
import { Listr } from 'listr2';

import { getCurrentV8Version } from './common.js';
Expand All @@ -16,6 +15,7 @@ import {
} from './util.js';
import applyNodeChanges from './applyNodeChanges.js';
import { chromiumGit, v8Deps } from './constants.js';
import { runAsync } from '../run.js';

export default function majorUpdate() {
return {
Expand Down Expand Up @@ -54,7 +54,7 @@ function checkoutBranch() {
'--sort',
'version:refname'
);
const tags = res.stdout.split('\n').filter(isVersionString);
const tags = res.split('\n').filter(isVersionString);
const lastTag = tags[tags.length - 1];
if (lastTag) version = lastTag;
if (version.split('.').length === 3) {
Expand Down Expand Up @@ -88,8 +88,8 @@ function cloneLocalV8() {
return {
title: 'Clone branch to deps/v8',
task: (ctx) =>
execa('git', ['clone', '-b', ctx.branch, ctx.v8Dir, 'deps/v8'], {
cwd: ctx.nodeDir
runAsync('git', ['clone', '-b', ctx.branch, ctx.v8Dir, 'deps/v8'], {
spawnArgs: { cwd: ctx.nodeDir }
})
};
}
Expand All @@ -106,8 +106,8 @@ function addDepsV8() {
title: 'Track all files in deps/v8',
// Add all V8 files with --force before updating DEPS. We have to do this
// because some files are checked in by V8 despite .gitignore rules.
task: (ctx) => execa('git', ['add', '--force', 'deps/v8'], {
cwd: ctx.nodeDir
task: (ctx) => runAsync('git', ['add', '--force', 'deps/v8'], {
spawnArgs: { cwd: ctx.nodeDir }
})
};
}
Expand Down Expand Up @@ -166,6 +166,6 @@ async function fetchFromGit(cwd, repo, commit) {
await removeDirectory(path.join(cwd, '.git'));

function exec(...options) {
return execa('git', options, { cwd });
return runAsync('git', options, { spawnArgs: { cwd } });
}
}
25 changes: 15 additions & 10 deletions lib/update-v8/minorUpdate.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import path from 'node:path';
import { promises as fs } from 'node:fs';

import Enquirer from 'enquirer';
import { execa } from 'execa';
import { Listr } from 'listr2';

import { getCurrentV8Version } from './common.js';
import { isVersionString } from './util.js';
import { runAsync } from '../run.js';

export default function minorUpdate() {
return {
Expand All @@ -31,11 +31,14 @@ function getLatestV8Version() {
task: async(ctx) => {
const version = ctx.currentVersion;
const currentV8Tag = `${version.major}.${version.minor}.${version.build}`;
const result = await execa('git', ['tag', '-l', `${currentV8Tag}.*`], {
cwd: ctx.v8Dir,
encoding: 'utf8'
const result = await runAsync('git', ['tag', '-l', `${currentV8Tag}.*`], {
captureStdout: true,
spawnArgs: {
cwd: ctx.v8Dir,
encoding: 'utf8'
}
});
const tags = filterAndSortTags(result.stdout);
const tags = filterAndSortTags(result);
ctx.latestVersion = tags[0];
}
};
Expand Down Expand Up @@ -63,15 +66,17 @@ function doMinorUpdate() {
}

async function applyPatch(ctx, latestStr) {
const { stdout: diff } = await execa(
const diff = await runAsync(
'git',
['format-patch', '--stdout', `${ctx.currentVersion}...${latestStr}`],
{ cwd: ctx.v8Dir, encoding: 'utf8' }
{ captureStdout: true, spawnArgs: { cwd: ctx.v8Dir, encoding: 'utf8' } }
);
try {
await execa('git', ['apply', '--directory', 'deps/v8'], {
cwd: ctx.nodeDir,
input: diff
await runAsync('git', ['apply', '--directory', 'deps/v8'], {
spawnArgs: {
cwd: ctx.nodeDir,
input: diff
}
});
} catch (e) {
const file = path.join(ctx.nodeDir, `${latestStr}.diff`);
Expand Down
6 changes: 3 additions & 3 deletions lib/update-v8/updateV8Clone.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { promises as fs } from 'node:fs';

import Enquirer from 'enquirer';
import { execa } from 'execa';
import { Listr } from 'listr2';

import { v8Git } from './constants.js';
import { runAsync } from '../run.js';

export default function updateV8Clone() {
return {
Expand All @@ -24,7 +24,7 @@ function fetchOrigin() {
title: 'Fetch V8',
task: async(ctx, task) => {
try {
await execa('git', ['fetch', 'origin'], { cwd: ctx.v8Dir });
await runAsync('git', ['fetch', 'origin'], { spawnArgs: { cwd: ctx.v8Dir } });
} catch (e) {
if (e.code === 'ENOENT') {
ctx.shouldClone = true;
Expand All @@ -42,7 +42,7 @@ function createClone() {
title: 'Clone V8',
task: async(ctx) => {
await fs.mkdir(ctx.baseDir, { recursive: true });
await execa('git', ['clone', v8Git], { cwd: ctx.baseDir });
await runAsync('git', ['clone', v8Git], { spawnArgs: { cwd: ctx.baseDir } });
},
enabled: (ctx) => ctx.shouldClone
};
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
"clipboardy": "^3.0.0",
"core-validate-commit": "^4.0.0",
"enquirer": "^2.4.1",
"execa": "^8.0.1",
"figures": "^5.0.0",
"ghauth": "^5.0.1",
"inquirer": "^9.2.10",
Expand Down

0 comments on commit ff79809

Please sign in to comment.