Skip to content

Commit a571938

Browse files
authored
chore: update many dependencies (#590)
- do major updates that do not affect us - replace fs-extra with fs.promises - replace node-fetch with undici
1 parent 9029c9c commit a571938

File tree

11 files changed

+109
-61
lines changed

11 files changed

+109
-61
lines changed

lib/request.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
'use strict';
22

3-
const fetch = require('node-fetch');
43
const fs = require('fs');
54
const path = require('path');
5+
const { fetch } = require('undici');
66
const { CI_DOMAIN } = require('./ci/ci_type_parser');
77
const proxy = require('./proxy');
88
const {

lib/update-v8/applyNodeChanges.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
const path = require('path');
44

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

87
const {
98
getNodeV8Version,
109
filterForVersion,
11-
replaceGitignore
10+
replaceGitignore,
11+
removeDirectory
1212
} = require('./util');
1313

1414
const nodeChanges = [
@@ -21,8 +21,8 @@ const nodeChanges = [
2121
function applyNodeChanges() {
2222
return {
2323
title: 'Apply Node-specific changes',
24-
task: (ctx) => {
25-
const v8Version = getNodeV8Version(ctx.nodeDir);
24+
task: async(ctx) => {
25+
const v8Version = await getNodeV8Version(ctx.nodeDir);
2626
const list = filterForVersion(nodeChanges, v8Version);
2727
return new Listr(list.map((change) => change.task()));
2828
}
@@ -38,7 +38,9 @@ function removeEuStrip() {
3838
match: '!/third_party/eu-strip\n',
3939
replace: ''
4040
});
41-
await fs.remove(path.join(ctx.nodeDir, 'deps/v8/third_party/eu-strip'));
41+
await removeDirectory(
42+
path.join(ctx.nodeDir, 'deps/v8/third_party/eu-strip')
43+
);
4244
}
4345
};
4446
}

lib/update-v8/backport.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22

33
const path = require('path');
44

5-
const fs = require('fs-extra');
5+
const {
6+
promises: {
7+
readFile,
8+
writeFile
9+
}
10+
} = require('fs');
611
const inquirer = require('inquirer');
712
const { Listr } = require('listr2');
813

@@ -219,12 +224,12 @@ function incrementV8Version() {
219224
task: async(ctx) => {
220225
const incremented = ++ctx.currentVersion.patch;
221226
const versionHPath = `${ctx.nodeDir}/deps/v8/include/v8-version.h`;
222-
let versionH = await fs.readFile(versionHPath, 'utf8');
227+
let versionH = await readFile(versionHPath, 'utf8');
223228
versionH = versionH.replace(
224229
/V8_PATCH_LEVEL (\d+)/,
225230
`V8_PATCH_LEVEL ${incremented}`
226231
);
227-
await fs.writeFile(versionHPath, versionH);
232+
await writeFile(versionHPath, versionH);
228233
}
229234
};
230235
}
@@ -235,11 +240,11 @@ function incrementEmbedderVersion() {
235240
title: 'Increment embedder version number',
236241
task: async(ctx) => {
237242
const commonGypiPath = path.join(ctx.nodeDir, 'common.gypi');
238-
const commonGypi = await fs.readFile(commonGypiPath, 'utf8');
243+
const commonGypi = await readFile(commonGypiPath, 'utf8');
239244
const embedderValue = parseInt(embedderRegex.exec(commonGypi)[1], 10);
240245
const embedderString = `'v8_embedder_string': '-node.${embedderValue +
241246
1}'`;
242-
await fs.writeFile(
247+
await writeFile(
243248
commonGypiPath,
244249
commonGypi.replace(embedderRegex, embedderString)
245250
);

lib/update-v8/commitUpdate.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module.exports = function() {
66
return {
77
title: 'Commit V8 update',
88
task: async(ctx) => {
9-
const newV8Version = util.getNodeV8Version(ctx.nodeDir);
9+
const newV8Version = await util.getNodeV8Version(ctx.nodeDir);
1010
await ctx.execGitNode('add', ['deps/v8']);
1111
const moreArgs = [];
1212
let message;

lib/update-v8/common.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,27 @@
22

33
const path = require('path');
44

5-
const fs = require('fs-extra');
5+
const {
6+
promises: {
7+
readFile
8+
}
9+
} = require('fs');
610

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

913
exports.getCurrentV8Version = function getCurrentV8Version() {
1014
return {
1115
title: 'Get current V8 version',
12-
task: (ctx) => {
13-
ctx.currentVersion = util.getNodeV8Version(ctx.nodeDir);
16+
task: async(ctx) => {
17+
ctx.currentVersion = await util.getNodeV8Version(ctx.nodeDir);
1418
}
1519
};
1620
};
1721

1822
exports.checkCwd = async function checkCwd(ctx) {
1923
let isNode = false;
2024
try {
21-
const nodeVersion = await fs.readFile(
25+
const nodeVersion = await readFile(
2226
path.join(ctx.nodeDir, 'src/node_version.h')
2327
);
2428
const match = /#define NODE_MAJOR_VERSION (\d+)/.exec(nodeVersion);

lib/update-v8/majorUpdate.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,21 @@
33
const path = require('path');
44

55
const execa = require('execa');
6-
const fs = require('fs-extra');
6+
const {
7+
promises: {
8+
readFile,
9+
mkdir
10+
}
11+
} = require('fs');
712
const { Listr } = require('listr2');
813

914
const common = require('./common');
1015
const {
1116
getNodeV8Version,
1217
filterForVersion,
1318
addToGitignore,
14-
replaceGitignore
19+
replaceGitignore,
20+
removeDirectory
1521
} = require('./util');
1622
const applyNodeChanges = require('./applyNodeChanges');
1723
const { chromiumGit, v8Deps } = require('./constants');
@@ -76,7 +82,7 @@ function checkoutBranch() {
7682
function removeDepsV8() {
7783
return {
7884
title: 'Remove deps/v8',
79-
task: (ctx) => fs.remove(path.join(ctx.nodeDir, 'deps/v8'))
85+
task: (ctx) => removeDirectory(path.join(ctx.nodeDir, 'deps/v8'))
8086
};
8187
}
8288

@@ -93,7 +99,7 @@ function cloneLocalV8() {
9399
function removeDepsV8Git() {
94100
return {
95101
title: 'Remove deps/v8/.git',
96-
task: (ctx) => fs.remove(path.join(ctx.nodeDir, 'deps/v8/.git'))
102+
task: (ctx) => removeDirectory(path.join(ctx.nodeDir, 'deps/v8/.git'))
97103
};
98104
}
99105

@@ -112,7 +118,7 @@ function updateV8Deps() {
112118
return {
113119
title: 'Update V8 DEPS',
114120
task: async(ctx) => {
115-
const newV8Version = getNodeV8Version(ctx.nodeDir);
121+
const newV8Version = await getNodeV8Version(ctx.nodeDir);
116122
const repoPrefix = newV8Version.majorMinor >= 86 ? '' : 'v8/';
117123
const deps = filterForVersion(v8Deps.map((v8Dep) => ({
118124
...v8Dep,
@@ -139,7 +145,7 @@ function updateV8Deps() {
139145
}
140146

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

156162
async function fetchFromGit(cwd, repo, commit) {
157-
await fs.ensureDir(cwd);
163+
await mkdir(cwd, { recursive: true });
158164
await exec('init');
159165
await exec('remote', 'add', 'origin', repo);
160166
await exec('fetch', 'origin', commit);
161167
await exec('reset', '--hard', 'FETCH_HEAD');
162-
await fs.remove(path.join(cwd, '.git'));
168+
await removeDirectory(path.join(cwd, '.git'));
163169

164170
function exec(...options) {
165171
return execa('git', options, { cwd });

lib/update-v8/minorUpdate.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
const path = require('path');
44

55
const execa = require('execa');
6-
const fs = require('fs-extra');
6+
const {
7+
promises: {
8+
writeFile
9+
}
10+
} = require('fs');
711
const { Listr } = require('listr2');
812

913
const common = require('./common');
@@ -71,7 +75,7 @@ async function doMinorUpdate(ctx, latestStr) {
7175
});
7276
} catch (e) {
7377
const file = path.join(ctx.nodeDir, `${latestStr}.diff`);
74-
await fs.writeFile(file, diff);
78+
await writeFile(file, diff);
7579
throw new Error(`Could not apply patch.\n${e}\nDiff was stored in ${file}`);
7680
}
7781
}

lib/update-v8/updateV8Clone.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22

33
const execa = require('execa');
44
const { Listr } = require('listr2');
5-
const fs = require('fs-extra');
5+
const {
6+
promises: {
7+
mkdir
8+
}
9+
} = require('fs');
610

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

@@ -37,7 +41,7 @@ function createClone() {
3741
return {
3842
title: 'Clone V8',
3943
task: async(ctx) => {
40-
await fs.ensureDir(ctx.baseDir);
44+
await mkdir(ctx.baseDir, { recursive: true });
4145
await execa('git', ['clone', v8Git], { cwd: ctx.baseDir });
4246
},
4347
enabled: (ctx) => ctx.shouldClone

lib/update-v8/updateVersionNumbers.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
'use strict';
22

33
const path = require('path');
4+
const {
5+
promises: {
6+
readFile,
7+
writeFile
8+
}
9+
} = require('fs');
410

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

813
const util = require('./util');
@@ -20,7 +25,7 @@ function bumpNodeModule() {
2025
return {
2126
title: 'Bump NODE_MODULE_VERSION',
2227
task: async(ctx) => {
23-
const v8Version = util.getNodeV8Version(ctx.nodeDir);
28+
const v8Version = await util.getNodeV8Version(ctx.nodeDir);
2429
const newModuleVersion = await updateModuleVersionRegistry(
2530
ctx.nodeDir,
2631
v8Version,
@@ -51,7 +56,7 @@ async function updateModuleVersionRegistry(
5156
nodeMajorVersion
5257
) {
5358
const registryFile = `${nodeDir}/doc/abi_version_registry.json`;
54-
const registryStr = await fs.readFile(registryFile, 'utf8');
59+
const registryStr = await readFile(registryFile, 'utf8');
5560
const registry = JSON.parse(registryStr);
5661
const newVersion = registry.NODE_MODULE_VERSION[0].modules + 1;
5762
const newLine =
@@ -63,18 +68,18 @@ async function updateModuleVersionRegistry(
6368
registryStr.substring(0, firstLineIndex) +
6469
newLine +
6570
registryStr.substring(firstLineIndex);
66-
await fs.writeFile(registryFile, newRegistry);
71+
await writeFile(registryFile, newRegistry);
6772
return newVersion;
6873
}
6974

7075
async function updateModuleVersion(nodeDir, newVersion) {
7176
const path = `${nodeDir}/src/node_version.h`;
72-
let nodeVersionH = fs.readFileSync(path, 'utf8');
77+
let nodeVersionH = await readFile(path, 'utf8');
7378
nodeVersionH = nodeVersionH.replace(
7479
/NODE_MODULE_VERSION \d+/,
7580
`NODE_MODULE_VERSION ${newVersion}`
7681
);
77-
fs.writeFileSync(path, nodeVersionH);
82+
await writeFile(path, nodeVersionH);
7883
}
7984

8085
function getCommitTitle(moduleVersion) {
@@ -97,10 +102,10 @@ function resetEmbedderString() {
97102
title: 'Reset V8 embedder version string',
98103
task: async(ctx, task) => {
99104
const commonGypiPath = path.join(ctx.nodeDir, 'common.gypi');
100-
const commonGypi = await fs.readFile(commonGypiPath, 'utf8');
105+
const commonGypi = await readFile(commonGypiPath, 'utf8');
101106
const embedderValue = embedderRegex.exec(commonGypi)[1];
102107
if (embedderValue !== '0') {
103-
await fs.writeFile(
108+
await writeFile(
104109
commonGypiPath,
105110
commonGypi.replace(embedderRegex, embedderString)
106111
);

lib/update-v8/util.js

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
'use strict';
22

3-
const fs = require('fs-extra');
3+
const {
4+
promises: {
5+
appendFile,
6+
readFile,
7+
writeFile,
8+
rm,
9+
rmdir
10+
}
11+
} = require('fs');
412
const path = require('path');
513

6-
function getNodeV8Version(cwd) {
14+
async function getNodeV8Version(cwd) {
715
try {
8-
const v8VersionH = fs.readFileSync(
16+
const v8VersionH = await readFile(
917
`${cwd}/deps/v8/include/v8-version.h`,
1018
'utf8'
1119
);
@@ -39,19 +47,30 @@ function filterForVersion(list, version) {
3947

4048
async function addToGitignore(nodeDir, value) {
4149
const gitignorePath = path.join(nodeDir, 'deps/v8/.gitignore');
42-
await fs.appendFile(gitignorePath, `${value}\n`);
50+
await appendFile(gitignorePath, `${value}\n`);
4351
}
4452

4553
async function replaceGitignore(nodeDir, options) {
4654
const gitignorePath = path.join(nodeDir, 'deps/v8/.gitignore');
47-
let gitignore = await fs.readFile(gitignorePath, 'utf8');
55+
let gitignore = await readFile(gitignorePath, 'utf8');
4856
gitignore = gitignore.replace(options.match, options.replace);
49-
await fs.writeFile(gitignorePath, gitignore);
57+
await writeFile(gitignorePath, gitignore);
58+
}
59+
60+
function removeDirectory(path) {
61+
if (typeof rm !== 'undefined') {
62+
return rm(path, { recursive: true, force: true });
63+
} else {
64+
// Node.js 12 doesn't have `rm`, and `rmdir` emits a deprecation warning in
65+
// Node.js 16+.
66+
return rmdir(path, { recursive: true });
67+
}
5068
}
5169

5270
module.exports = {
5371
getNodeV8Version,
5472
filterForVersion,
5573
addToGitignore,
56-
replaceGitignore
74+
replaceGitignore,
75+
removeDirectory
5776
};

0 commit comments

Comments
 (0)