Skip to content

Commit 80ec407

Browse files
targosjoyeecheung
authored andcommitted
git-node v8: remove eu-strip during major upgrades (#243)
* git-node v8: remove eu-strip during major upgrades Ref: nodejs/node#20304
1 parent d6ce6dc commit 80ec407

File tree

3 files changed

+81
-22
lines changed

3 files changed

+81
-22
lines changed

lib/update-v8/applyNodeChanges.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
'use strict';
2+
3+
const path = require('path');
4+
5+
const fs = require('fs-extra');
6+
const Listr = require('listr');
7+
8+
const {
9+
getNodeV8Version,
10+
filterForVersion,
11+
replaceGitignore
12+
} = require('./util');
13+
14+
const nodeChanges = [
15+
{
16+
since: 66,
17+
task: removeEuStrip
18+
}
19+
];
20+
21+
function applyNodeChanges() {
22+
return {
23+
title: 'Apply Node-specific changes',
24+
task: (ctx) => {
25+
const v8Version = getNodeV8Version(ctx.nodeDir);
26+
const list = filterForVersion(nodeChanges, v8Version);
27+
return new Listr(list.map((change) => change.task()));
28+
}
29+
};
30+
}
31+
32+
// Ref: https://github.com/nodejs/node/pull/20304
33+
function removeEuStrip() {
34+
return {
35+
title: 'Remove eu-strip binary',
36+
task: async(ctx) => {
37+
await replaceGitignore(ctx.nodeDir, {
38+
match: '!/third_party/eu-strip\n',
39+
replace: ''
40+
});
41+
await fs.remove(path.join(ctx.nodeDir, 'deps/v8/third_party/eu-strip'));
42+
}
43+
};
44+
}
45+
46+
module.exports = applyNodeChanges;

lib/update-v8/majorUpdate.js

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,19 @@ const Listr = require('listr');
88
const mkdirp = require('mkdirp');
99

1010
const common = require('./common');
11-
const util = require('./util');
11+
const {
12+
getNodeV8Version,
13+
filterForVersion,
14+
addToGitignore,
15+
replaceGitignore
16+
} = require('./util');
1217
const {
1318
moveGypfilesOut,
1419
moveGypfilesIn,
1520
updateGypfiles
1621
} = require('./gypfiles');
17-
const { chromiumGit } = require('./constants');
22+
const applyNodeChanges = require('./applyNodeChanges');
23+
const { chromiumGit, v8Deps } = require('./constants');
1824

1925
module.exports = function() {
2026
return {
@@ -28,6 +34,7 @@ module.exports = function() {
2834
cloneLocalV8(),
2935
removeDepsV8Git(),
3036
updateV8Deps(),
37+
applyNodeChanges(),
3138
moveGypfilesIn(),
3239
updateGypfiles()
3340
]);
@@ -102,8 +109,8 @@ function updateV8Deps() {
102109
return {
103110
title: 'Update V8 DEPS',
104111
task: async(ctx) => {
105-
const newV8Version = util.getNodeV8Version(ctx.nodeDir);
106-
const deps = util.getV8Deps(newV8Version);
112+
const newV8Version = getNodeV8Version(ctx.nodeDir);
113+
const deps = filterForVersion(v8Deps, newV8Version);
107114
if (deps.length === 0) return;
108115
/* eslint-disable no-await-in-loop */
109116
for (const dep of deps) {
@@ -123,18 +130,6 @@ function updateV8Deps() {
123130
};
124131
}
125132

126-
async function addToGitignore(nodeDir, value) {
127-
const gitignorePath = path.join(nodeDir, 'deps/v8/.gitignore');
128-
await fs.appendFile(gitignorePath, `${value}\n`);
129-
}
130-
131-
async function replaceGitignore(nodeDir, options) {
132-
const gitignorePath = path.join(nodeDir, 'deps/v8/.gitignore');
133-
let gitignore = await fs.readFile(gitignorePath, 'utf8');
134-
gitignore = gitignore.replace(options.match, options.replace);
135-
await fs.writeFile(gitignorePath, gitignore);
136-
}
137-
138133
async function readDeps(nodeDir, depName) {
139134
const depsStr = await fs.readFile(path.join(nodeDir, 'deps/v8/DEPS'), 'utf8');
140135
const start = depsStr.indexOf('deps = {');

lib/update-v8/util.js

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
'use strict';
22

3-
const fs = require('fs');
3+
const fs = require('fs-extra');
4+
const path = require('path');
45

5-
const constants = require('./constants');
6-
7-
exports.getNodeV8Version = function getNodeV8Version(cwd) {
6+
function getNodeV8Version(cwd) {
87
try {
98
const v8VersionH = fs.readFileSync(
109
`${cwd}/deps/v8/include/v8-version.h`,
@@ -21,11 +20,30 @@ exports.getNodeV8Version = function getNodeV8Version(cwd) {
2120
}
2221
};
2322

24-
exports.getV8Deps = function getV8Deps(version) {
23+
function filterForVersion(list, version) {
2524
const major = version[0];
2625
const minor = version[1];
2726
const number = major * 10 + minor;
28-
return constants.v8Deps.filter(
27+
return list.filter(
2928
(dep) => dep.since <= number && (dep.until || Infinity) >= number
3029
);
30+
}
31+
32+
async function addToGitignore(nodeDir, value) {
33+
const gitignorePath = path.join(nodeDir, 'deps/v8/.gitignore');
34+
await fs.appendFile(gitignorePath, `${value}\n`);
35+
}
36+
37+
async function replaceGitignore(nodeDir, options) {
38+
const gitignorePath = path.join(nodeDir, 'deps/v8/.gitignore');
39+
let gitignore = await fs.readFile(gitignorePath, 'utf8');
40+
gitignore = gitignore.replace(options.match, options.replace);
41+
await fs.writeFile(gitignorePath, gitignore);
42+
}
43+
44+
module.exports = {
45+
getNodeV8Version,
46+
filterForVersion,
47+
addToGitignore,
48+
replaceGitignore
3149
};

0 commit comments

Comments
 (0)