Skip to content

Commit e40a212

Browse files
committed
refactor: check deps during landing
1 parent 3a8e38c commit e40a212

File tree

3 files changed

+95
-47
lines changed

3 files changed

+95
-47
lines changed

lib/deprecations.js

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
'use strict';
2+
3+
const { promises: fs } = require('fs');
4+
const path = require('path');
5+
const replace = require('replace-in-file');
6+
7+
const newDeprecationPattern =
8+
/<\s*a id="DEP0([X]+[0-9]*)+"[^>]*><\s*\/\s*a>/g;
9+
10+
async function getUnmarkedDeprecations() {
11+
const deprecationFilePath = path.resolve('doc', 'api', 'deprecations.md');
12+
const deprecationFile = await fs.readFile(deprecationFilePath, 'utf8');
13+
14+
const unmarkedDeprecations = [
15+
...deprecationFile.matchAll(newDeprecationPattern)
16+
].map(m => m[1]);
17+
18+
return unmarkedDeprecations;
19+
}
20+
21+
async function updateDeprecations() {
22+
const deprecationPattern =
23+
/<\s*a id="DEP0([0-9]{3})+"[^>]*><\s*\/\s*a>/g;
24+
25+
const deprecationFilePath = path.resolve('doc', 'api', 'deprecations.md');
26+
const deprecationFile = await fs.readFile(deprecationFilePath, 'utf8');
27+
28+
const unmarkedDeprecations = await getUnmarkedDeprecations();
29+
const deprecationNumbers = [
30+
...deprecationFile.matchAll(deprecationPattern)
31+
].map(m => m[1]).reverse();
32+
33+
// Pull highest deprecation number off the list and increment from there.
34+
let depNumber = parseInt(deprecationNumbers[0]) + 1;
35+
36+
// Loop through each new unmarked deprecation number and replace instances.
37+
for (const unmarked of unmarkedDeprecations) {
38+
await replace({
39+
files: [
40+
'doc/api/*.md',
41+
'lib/**/*.js',
42+
'src/**/*.{h,cc}',
43+
'test/**/*.js'
44+
],
45+
ignore: 'test/common/README.md',
46+
from: new RegExp(`DEP0${unmarked}`, 'g'),
47+
to: `DEP0${depNumber}`
48+
});
49+
50+
depNumber++;
51+
}
52+
}
53+
54+
module.exports = {
55+
updateDeprecations,
56+
getUnmarkedDeprecations
57+
};

lib/landing_session.js

+17-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
'use strict';
22

33
const path = require('path');
4+
const {
5+
getUnmarkedDeprecations,
6+
updateDeprecations
7+
} = require('./deprecations');
48

59
const {
610
runAsync, runSync, forceRunAsync
711
} = require('./run');
812
const Session = require('./session');
9-
const {
10-
shortSha
11-
} = require('./utils');
13+
const { shortSha } = require('./utils');
1214

1315
const isWindows = process.platform === 'win32';
1416

@@ -84,6 +86,18 @@ class LandingSession extends Session {
8486
process.exit(1);
8587
}
8688
}
89+
90+
// Update any new deprecations in the codebase.
91+
const unmarkedDepCount = await getUnmarkedDeprecations();
92+
if (unmarkedDepCount > 0) {
93+
cli.startSpinner('Assigning deprecation numbers to DEPOXXX items');
94+
const updatedDepCount = await updateDeprecations();
95+
96+
// Amend the last commit with the updated deprecation items.
97+
await runAsync('git', ['commit', '--amend', '--no-edit']);
98+
cli.stopSpinner(`Updated ${updatedDepCount} DEPOXXX items in codebase`);
99+
}
100+
87101
cli.ok('Patches applied');
88102
return patch;
89103
}

lib/prepare_release.js

+21-44
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
'use strict';
22

33
const path = require('path');
4-
const fs = require('fs').promises;
4+
const { promises: fs } = require('fs');
55
const semver = require('semver');
66
const replace = require('replace-in-file');
77

88
const { getMergedConfig } = require('./config');
99
const { runAsync, runSync } = require('./run');
1010
const { writeJson, readJson } = require('./file');
11+
const {
12+
getUnmarkedDeprecations,
13+
updateDeprecations
14+
} = require('./deprecations');
1115

1216
const isWindows = process.platform === 'win32';
1317

@@ -113,10 +117,22 @@ class ReleasePreparation {
113117
await this.updateREPLACEMEs();
114118
cli.stopSpinner('Updated REPLACEME items in docs');
115119

116-
// Update any new deprecations in the codebase.
117-
cli.startSpinner('Updating DEPOXXX items in codebase');
118-
const depCount = await this.updateDeprecations();
119-
cli.stopSpinner(`Updated ${depCount} DEPOXXX items in codebase`);
120+
// Check for any unmarked deprecations in the codebase.
121+
const unmarkedDepCount = await getUnmarkedDeprecations();
122+
if (unmarkedDepCount > 0) {
123+
const mark = await cli.prompt(
124+
`Automatically mark ${unmarkedDepCount} deprecations?`);
125+
if (mark) {
126+
cli.startSpinner(
127+
`Marking ${unmarkedDepCount} unmarked DEPOXXX items in codebase`);
128+
const depCount = await updateDeprecations();
129+
cli.stopSpinner(`Updated ${depCount} DEPOXXX items in codebase`);
130+
} else {
131+
await cli.prompt('Finished updating unmarked DEPOXXX item?',
132+
{ defaultAnswer: false });
133+
cli.stopSpinner('Finished updating DEPOXXX items in codebase');
134+
}
135+
}
120136

121137
// Fetch date to use in release commit & changelogs.
122138
const todayDate = new Date().toISOString().split('T')[0];
@@ -230,45 +246,6 @@ class ReleasePreparation {
230246
]).trim();
231247
}
232248

233-
async updateDeprecations() {
234-
const deprecationPattern =
235-
/<\s*a id="DEP0([0-9]{3})+"[^>]*><\s*\/\s*a>/g;
236-
const newDeprecationPattern =
237-
/<\s*a id="DEP0([X]+[0-9]*)+"[^>]*><\s*\/\s*a>/g;
238-
239-
const deprecationFilePath = path.resolve('doc', 'api', 'deprecations.md');
240-
const deprecationFile = await fs.readFile(deprecationFilePath, 'utf8');
241-
242-
const deprecationNumbers = [
243-
...deprecationFile.matchAll(deprecationPattern)
244-
].map(m => m[1]).reverse();
245-
const newDeprecationNumbers = [
246-
...deprecationFile.matchAll(newDeprecationPattern)
247-
].map(m => m[1]);
248-
249-
// Pull highest deprecation number off the list and increment from there.
250-
let depNumber = parseInt(deprecationNumbers[0]) + 1;
251-
252-
// Loop through each new unmarked deprecation number and replace instances.
253-
for (const newDep of newDeprecationNumbers) {
254-
await replace({
255-
files: [
256-
'doc/api/*.md',
257-
'lib/**/*.js',
258-
'src/**/*.{h,cc}',
259-
'test/**/*.js'
260-
],
261-
ignore: 'test/common/README.md',
262-
from: new RegExp(`DEP0${newDep}`, 'g'),
263-
to: `DEP0${depNumber}`
264-
});
265-
266-
depNumber++;
267-
}
268-
269-
return newDeprecationNumbers.length;
270-
}
271-
272249
async updateREPLACEMEs() {
273250
const { newVersion } = this;
274251

0 commit comments

Comments
 (0)