Skip to content

Commit 24dfc66

Browse files
authored
chore: Remove replace-in-file and inquirer (#12687)
ref: #12644 We can remove `replace-in-file` with some built-in functions and clean up our lockfile even more. Extracted from the previous PR because 1 big change was breaking CI and I couldn't figure out the root cause.
1 parent c548c3c commit 24dfc66

File tree

5 files changed

+108
-155
lines changed

5 files changed

+108
-155
lines changed

dev-packages/bundle-analyzer-scenarios/package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@
88
"license": "MIT",
99
"private": true,
1010
"dependencies": {
11-
"html-webpack-plugin": "^5.5.0",
12-
"inquirer": "^8.2.0",
13-
"webpack": "^5.76.0",
14-
"webpack-bundle-analyzer": "^4.5.0"
11+
"html-webpack-plugin": "^5.6.0",
12+
"webpack": "^5.92.1",
13+
"webpack-bundle-analyzer": "^4.10.2"
1514
},
1615
"scripts": {
1716
"analyze": "node webpack.cjs"

dev-packages/bundle-analyzer-scenarios/webpack.cjs

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,33 @@
1-
const path = require('path');
2-
const { promises } = require('fs');
1+
const path = require('node:path');
2+
const { promises } = require('node:fs');
3+
const { parseArgs } = require('node:util');
34

4-
const inquirer = require('inquirer');
55
const webpack = require('webpack');
66
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
77
const HtmlWebpackPlugin = require('html-webpack-plugin');
88

99
async function init() {
1010
const scenarios = await getScenariosFromDirectories();
1111

12-
const answers = await inquirer.prompt([
13-
{
14-
type: 'rawlist',
15-
name: 'scenario',
16-
message: 'Which scenario you want to run?',
17-
choices: scenarios,
18-
pageSize: scenarios.length,
19-
loop: false,
20-
},
21-
]);
12+
const { values } = parseArgs({
13+
args: process.argv.slice(2),
14+
options: { scenario: { type: 'string', short: 's' }, list: { type: 'boolean', short: 'l' } },
15+
});
16+
17+
if (values.list) {
18+
console.log('Available scenarios:', scenarios);
19+
process.exit(0);
20+
}
21+
22+
if (!scenarios.some(scenario => scenario === values.scenario)) {
23+
console.error('Invalid scenario:', values.scenario);
24+
console.error('Available scenarios:', scenarios);
25+
process.exit(1);
26+
}
2227

23-
console.log(`Bundling scenario: ${answers.scenario}`);
28+
console.log(`Bundling scenario: ${values.scenario}`);
2429

25-
await runWebpack(answers.scenario);
30+
await runWebpack(values.scenario);
2631
}
2732

2833
async function runWebpack(scenario) {

package.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@
120120
"nodemon": "^2.0.16",
121121
"npm-run-all": "^4.1.5",
122122
"prettier": "^3.1.1",
123-
"replace-in-file": "^4.0.0",
124123
"rimraf": "^3.0.2",
125124
"rollup": "^4.13.0",
126125
"rollup-plugin-cleanup": "^3.2.1",
@@ -134,8 +133,15 @@
134133
"vitest": "^1.6.0",
135134
"yalc": "^1.0.0-pre.53"
136135
},
136+
"//_resolutions_comment": [
137+
"Because new versions of strip-ansi, string-width, and wrap-ansi are ESM only packages,",
138+
"we need to resolve them to the CommonJS versions.",
139+
"This is a temporary solution until we can upgrade to a version of lerna that supports ESM packages"
140+
],
137141
"resolutions": {
138-
"gauge/strip-ansi": "6.0.1"
142+
"gauge/strip-ansi": "6.0.1",
143+
"wide-align/string-width": "4.2.3",
144+
"cliui/wrap-ansi": "7.0.0"
139145
},
140146
"version": "0.0.0",
141147
"name": "sentry-javascript",

scripts/versionbump.js

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,31 @@
1-
const replace = require('replace-in-file');
1+
const { readFile, writeFile } = require('node:fs').promises;
22
const pjson = require(`${process.cwd()}/package.json`);
33

4-
const files = process.argv.slice(2);
5-
if (files.length === 0) {
6-
console.error('Please provide files to bump');
7-
process.exit(1);
8-
}
4+
const REPLACE_REGEX = /\d+\.\d+.\d+(?:-\w+(?:\.\w+)?)?/g;
5+
6+
async function run() {
7+
const files = process.argv.slice(2);
8+
if (files.length === 0) {
9+
// eslint-disable-next-line no-console
10+
console.error('[versionbump] Please provide files to bump');
11+
process.exit(1);
12+
}
913

10-
replace({
11-
files: files,
12-
from: /\d+\.\d+.\d+(?:-\w+(?:\.\w+)?)?/g,
13-
to: pjson.version,
14-
})
15-
.then(changedFiles => {
16-
console.log('Modified files:', changedFiles.join(', '));
17-
})
18-
.catch(error => {
19-
console.error('Error occurred:', error);
14+
try {
15+
await Promise.all(
16+
files.map(async file => {
17+
const data = String(await readFile(file, 'utf8'));
18+
await writeFile(file, data.replace(REPLACE_REGEX, pjson.version));
19+
}),
20+
);
21+
22+
// eslint-disable-next-line no-console
23+
console.log(`[versionbump] Bumped version for ${files.join(', ')}`);
24+
} catch (error) {
25+
// eslint-disable-next-line no-console
26+
console.error('[versionbump] Error occurred:', error);
2027
process.exit(1);
21-
});
28+
}
29+
}
30+
31+
run();

0 commit comments

Comments
 (0)