Skip to content

Commit

Permalink
chore: update many dependencies (#590)
Browse files Browse the repository at this point in the history
- do major updates that do not affect us
- replace fs-extra with fs.promises
- replace node-fetch with undici
  • Loading branch information
targos committed Nov 14, 2021
1 parent 9029c9c commit a571938
Show file tree
Hide file tree
Showing 11 changed files with 109 additions and 61 deletions.
2 changes: 1 addition & 1 deletion lib/request.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict';

const fetch = require('node-fetch');
const fs = require('fs');
const path = require('path');
const { fetch } = require('undici');
const { CI_DOMAIN } = require('./ci/ci_type_parser');
const proxy = require('./proxy');
const {
Expand Down
12 changes: 7 additions & 5 deletions lib/update-v8/applyNodeChanges.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

const path = require('path');

const fs = require('fs-extra');
const { Listr } = require('listr2');

const {
getNodeV8Version,
filterForVersion,
replaceGitignore
replaceGitignore,
removeDirectory
} = require('./util');

const nodeChanges = [
Expand All @@ -21,8 +21,8 @@ const nodeChanges = [
function applyNodeChanges() {
return {
title: 'Apply Node-specific changes',
task: (ctx) => {
const v8Version = getNodeV8Version(ctx.nodeDir);
task: async(ctx) => {
const v8Version = await getNodeV8Version(ctx.nodeDir);
const list = filterForVersion(nodeChanges, v8Version);
return new Listr(list.map((change) => change.task()));
}
Expand All @@ -38,7 +38,9 @@ function removeEuStrip() {
match: '!/third_party/eu-strip\n',
replace: ''
});
await fs.remove(path.join(ctx.nodeDir, 'deps/v8/third_party/eu-strip'));
await removeDirectory(
path.join(ctx.nodeDir, 'deps/v8/third_party/eu-strip')
);
}
};
}
Expand Down
15 changes: 10 additions & 5 deletions lib/update-v8/backport.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@

const path = require('path');

const fs = require('fs-extra');
const {
promises: {
readFile,
writeFile
}
} = require('fs');
const inquirer = require('inquirer');
const { Listr } = require('listr2');

Expand Down Expand Up @@ -219,12 +224,12 @@ function incrementV8Version() {
task: async(ctx) => {
const incremented = ++ctx.currentVersion.patch;
const versionHPath = `${ctx.nodeDir}/deps/v8/include/v8-version.h`;
let versionH = await fs.readFile(versionHPath, 'utf8');
let versionH = await readFile(versionHPath, 'utf8');
versionH = versionH.replace(
/V8_PATCH_LEVEL (\d+)/,
`V8_PATCH_LEVEL ${incremented}`
);
await fs.writeFile(versionHPath, versionH);
await writeFile(versionHPath, versionH);
}
};
}
Expand All @@ -235,11 +240,11 @@ function incrementEmbedderVersion() {
title: 'Increment embedder version number',
task: async(ctx) => {
const commonGypiPath = path.join(ctx.nodeDir, 'common.gypi');
const commonGypi = await fs.readFile(commonGypiPath, 'utf8');
const commonGypi = await readFile(commonGypiPath, 'utf8');
const embedderValue = parseInt(embedderRegex.exec(commonGypi)[1], 10);
const embedderString = `'v8_embedder_string': '-node.${embedderValue +
1}'`;
await fs.writeFile(
await writeFile(
commonGypiPath,
commonGypi.replace(embedderRegex, embedderString)
);
Expand Down
2 changes: 1 addition & 1 deletion lib/update-v8/commitUpdate.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = function() {
return {
title: 'Commit V8 update',
task: async(ctx) => {
const newV8Version = util.getNodeV8Version(ctx.nodeDir);
const newV8Version = await util.getNodeV8Version(ctx.nodeDir);
await ctx.execGitNode('add', ['deps/v8']);
const moreArgs = [];
let message;
Expand Down
12 changes: 8 additions & 4 deletions lib/update-v8/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,27 @@

const path = require('path');

const fs = require('fs-extra');
const {
promises: {
readFile
}
} = require('fs');

const util = require('./util');

exports.getCurrentV8Version = function getCurrentV8Version() {
return {
title: 'Get current V8 version',
task: (ctx) => {
ctx.currentVersion = util.getNodeV8Version(ctx.nodeDir);
task: async(ctx) => {
ctx.currentVersion = await util.getNodeV8Version(ctx.nodeDir);
}
};
};

exports.checkCwd = async function checkCwd(ctx) {
let isNode = false;
try {
const nodeVersion = await fs.readFile(
const nodeVersion = await readFile(
path.join(ctx.nodeDir, 'src/node_version.h')
);
const match = /#define NODE_MAJOR_VERSION (\d+)/.exec(nodeVersion);
Expand Down
22 changes: 14 additions & 8 deletions lib/update-v8/majorUpdate.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,21 @@
const path = require('path');

const execa = require('execa');
const fs = require('fs-extra');
const {
promises: {
readFile,
mkdir
}
} = require('fs');
const { Listr } = require('listr2');

const common = require('./common');
const {
getNodeV8Version,
filterForVersion,
addToGitignore,
replaceGitignore
replaceGitignore,
removeDirectory
} = require('./util');
const applyNodeChanges = require('./applyNodeChanges');
const { chromiumGit, v8Deps } = require('./constants');
Expand Down Expand Up @@ -76,7 +82,7 @@ function checkoutBranch() {
function removeDepsV8() {
return {
title: 'Remove deps/v8',
task: (ctx) => fs.remove(path.join(ctx.nodeDir, 'deps/v8'))
task: (ctx) => removeDirectory(path.join(ctx.nodeDir, 'deps/v8'))
};
}

Expand All @@ -93,7 +99,7 @@ function cloneLocalV8() {
function removeDepsV8Git() {
return {
title: 'Remove deps/v8/.git',
task: (ctx) => fs.remove(path.join(ctx.nodeDir, 'deps/v8/.git'))
task: (ctx) => removeDirectory(path.join(ctx.nodeDir, 'deps/v8/.git'))
};
}

Expand All @@ -112,7 +118,7 @@ function updateV8Deps() {
return {
title: 'Update V8 DEPS',
task: async(ctx) => {
const newV8Version = getNodeV8Version(ctx.nodeDir);
const newV8Version = await getNodeV8Version(ctx.nodeDir);
const repoPrefix = newV8Version.majorMinor >= 86 ? '' : 'v8/';
const deps = filterForVersion(v8Deps.map((v8Dep) => ({
...v8Dep,
Expand All @@ -139,7 +145,7 @@ function updateV8Deps() {
}

async function readDeps(nodeDir, depName) {
const depsStr = await fs.readFile(path.join(nodeDir, 'deps/v8/DEPS'), 'utf8');
const depsStr = await readFile(path.join(nodeDir, 'deps/v8/DEPS'), 'utf8');
const start = depsStr.indexOf('deps = {');
const end = depsStr.indexOf('\n}', start) + 2;
const depsDeclaration = depsStr.substring(start, end).replace(/^ *#.*/gm, '');
Expand All @@ -154,12 +160,12 @@ async function readDeps(nodeDir, depName) {
}

async function fetchFromGit(cwd, repo, commit) {
await fs.ensureDir(cwd);
await mkdir(cwd, { recursive: true });
await exec('init');
await exec('remote', 'add', 'origin', repo);
await exec('fetch', 'origin', commit);
await exec('reset', '--hard', 'FETCH_HEAD');
await fs.remove(path.join(cwd, '.git'));
await removeDirectory(path.join(cwd, '.git'));

function exec(...options) {
return execa('git', options, { cwd });
Expand Down
8 changes: 6 additions & 2 deletions lib/update-v8/minorUpdate.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
const path = require('path');

const execa = require('execa');
const fs = require('fs-extra');
const {
promises: {
writeFile
}
} = require('fs');
const { Listr } = require('listr2');

const common = require('./common');
Expand Down Expand Up @@ -71,7 +75,7 @@ async function doMinorUpdate(ctx, latestStr) {
});
} catch (e) {
const file = path.join(ctx.nodeDir, `${latestStr}.diff`);
await fs.writeFile(file, diff);
await writeFile(file, diff);
throw new Error(`Could not apply patch.\n${e}\nDiff was stored in ${file}`);
}
}
Expand Down
8 changes: 6 additions & 2 deletions lib/update-v8/updateV8Clone.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

const execa = require('execa');
const { Listr } = require('listr2');
const fs = require('fs-extra');
const {
promises: {
mkdir
}
} = require('fs');

const { v8Git } = require('./constants');

Expand Down Expand Up @@ -37,7 +41,7 @@ function createClone() {
return {
title: 'Clone V8',
task: async(ctx) => {
await fs.ensureDir(ctx.baseDir);
await mkdir(ctx.baseDir, { recursive: true });
await execa('git', ['clone', v8Git], { cwd: ctx.baseDir });
},
enabled: (ctx) => ctx.shouldClone
Expand Down
21 changes: 13 additions & 8 deletions lib/update-v8/updateVersionNumbers.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
'use strict';

const path = require('path');
const {
promises: {
readFile,
writeFile
}
} = require('fs');

const fs = require('fs-extra');
const { Listr } = require('listr2');

const util = require('./util');
Expand All @@ -20,7 +25,7 @@ function bumpNodeModule() {
return {
title: 'Bump NODE_MODULE_VERSION',
task: async(ctx) => {
const v8Version = util.getNodeV8Version(ctx.nodeDir);
const v8Version = await util.getNodeV8Version(ctx.nodeDir);
const newModuleVersion = await updateModuleVersionRegistry(
ctx.nodeDir,
v8Version,
Expand Down Expand Up @@ -51,7 +56,7 @@ async function updateModuleVersionRegistry(
nodeMajorVersion
) {
const registryFile = `${nodeDir}/doc/abi_version_registry.json`;
const registryStr = await fs.readFile(registryFile, 'utf8');
const registryStr = await readFile(registryFile, 'utf8');
const registry = JSON.parse(registryStr);
const newVersion = registry.NODE_MODULE_VERSION[0].modules + 1;
const newLine =
Expand All @@ -63,18 +68,18 @@ async function updateModuleVersionRegistry(
registryStr.substring(0, firstLineIndex) +
newLine +
registryStr.substring(firstLineIndex);
await fs.writeFile(registryFile, newRegistry);
await writeFile(registryFile, newRegistry);
return newVersion;
}

async function updateModuleVersion(nodeDir, newVersion) {
const path = `${nodeDir}/src/node_version.h`;
let nodeVersionH = fs.readFileSync(path, 'utf8');
let nodeVersionH = await readFile(path, 'utf8');
nodeVersionH = nodeVersionH.replace(
/NODE_MODULE_VERSION \d+/,
`NODE_MODULE_VERSION ${newVersion}`
);
fs.writeFileSync(path, nodeVersionH);
await writeFile(path, nodeVersionH);
}

function getCommitTitle(moduleVersion) {
Expand All @@ -97,10 +102,10 @@ function resetEmbedderString() {
title: 'Reset V8 embedder version string',
task: async(ctx, task) => {
const commonGypiPath = path.join(ctx.nodeDir, 'common.gypi');
const commonGypi = await fs.readFile(commonGypiPath, 'utf8');
const commonGypi = await readFile(commonGypiPath, 'utf8');
const embedderValue = embedderRegex.exec(commonGypi)[1];
if (embedderValue !== '0') {
await fs.writeFile(
await writeFile(
commonGypiPath,
commonGypi.replace(embedderRegex, embedderString)
);
Expand Down
33 changes: 26 additions & 7 deletions lib/update-v8/util.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
'use strict';

const fs = require('fs-extra');
const {
promises: {
appendFile,
readFile,
writeFile,
rm,
rmdir
}
} = require('fs');
const path = require('path');

function getNodeV8Version(cwd) {
async function getNodeV8Version(cwd) {
try {
const v8VersionH = fs.readFileSync(
const v8VersionH = await readFile(
`${cwd}/deps/v8/include/v8-version.h`,
'utf8'
);
Expand Down Expand Up @@ -39,19 +47,30 @@ function filterForVersion(list, version) {

async function addToGitignore(nodeDir, value) {
const gitignorePath = path.join(nodeDir, 'deps/v8/.gitignore');
await fs.appendFile(gitignorePath, `${value}\n`);
await appendFile(gitignorePath, `${value}\n`);
}

async function replaceGitignore(nodeDir, options) {
const gitignorePath = path.join(nodeDir, 'deps/v8/.gitignore');
let gitignore = await fs.readFile(gitignorePath, 'utf8');
let gitignore = await readFile(gitignorePath, 'utf8');
gitignore = gitignore.replace(options.match, options.replace);
await fs.writeFile(gitignorePath, gitignore);
await writeFile(gitignorePath, gitignore);
}

function removeDirectory(path) {
if (typeof rm !== 'undefined') {
return rm(path, { recursive: true, force: true });
} else {
// Node.js 12 doesn't have `rm`, and `rmdir` emits a deprecation warning in
// Node.js 16+.
return rmdir(path, { recursive: true });
}
}

module.exports = {
getNodeV8Version,
filterForVersion,
addToGitignore,
replaceGitignore
replaceGitignore,
removeDirectory
};

0 comments on commit a571938

Please sign in to comment.