Skip to content

chore: Remove replace-in-file and inquirer #12687

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions dev-packages/bundle-analyzer-scenarios/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@
"license": "MIT",
"private": true,
"dependencies": {
"html-webpack-plugin": "^5.5.0",
"inquirer": "^8.2.0",
"webpack": "^5.76.0",
"webpack-bundle-analyzer": "^4.5.0"
"html-webpack-plugin": "^5.6.0",
"webpack": "^5.92.1",
"webpack-bundle-analyzer": "^4.10.2"
},
"scripts": {
"analyze": "node webpack.cjs"
Expand Down
35 changes: 20 additions & 15 deletions dev-packages/bundle-analyzer-scenarios/webpack.cjs
Original file line number Diff line number Diff line change
@@ -1,28 +1,33 @@
const path = require('path');
const { promises } = require('fs');
const path = require('node:path');
const { promises } = require('node:fs');
const { parseArgs } = require('node:util');

const inquirer = require('inquirer');
const webpack = require('webpack');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const HtmlWebpackPlugin = require('html-webpack-plugin');

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

const answers = await inquirer.prompt([
{
type: 'rawlist',
name: 'scenario',
message: 'Which scenario you want to run?',
choices: scenarios,
pageSize: scenarios.length,
loop: false,
},
]);
const { values } = parseArgs({
args: process.argv.slice(2),
options: { scenario: { type: 'string', short: 's' }, list: { type: 'boolean', short: 'l' } },
});

if (values.list) {
console.log('Available scenarios:', scenarios);
process.exit(0);
}

if (!scenarios.some(scenario => scenario === values.scenario)) {
console.error('Invalid scenario:', values.scenario);
console.error('Available scenarios:', scenarios);
process.exit(1);
}

console.log(`Bundling scenario: ${answers.scenario}`);
console.log(`Bundling scenario: ${values.scenario}`);

await runWebpack(answers.scenario);
await runWebpack(values.scenario);
}

async function runWebpack(scenario) {
Expand Down
10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@
"nodemon": "^2.0.16",
"npm-run-all": "^4.1.5",
"prettier": "^3.1.1",
"replace-in-file": "^4.0.0",
"rimraf": "^3.0.2",
"rollup": "^4.13.0",
"rollup-plugin-cleanup": "^3.2.1",
Expand All @@ -134,8 +133,15 @@
"vitest": "^1.6.0",
"yalc": "^1.0.0-pre.53"
},
"//_resolutions_comment": [
"Because new versions of strip-ansi, string-width, and wrap-ansi are ESM only packages,",
"we need to resolve them to the CommonJS versions.",
"This is a temporary solution until we can upgrade to a version of lerna that supports ESM packages"
],
"resolutions": {
"gauge/strip-ansi": "6.0.1"
"gauge/strip-ansi": "6.0.1",
"wide-align/string-width": "4.2.3",
"cliui/wrap-ansi": "7.0.0"
},
"version": "0.0.0",
"name": "sentry-javascript",
Expand Down
44 changes: 27 additions & 17 deletions scripts/versionbump.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@
const replace = require('replace-in-file');
const { readFile, writeFile } = require('node:fs').promises;
const pjson = require(`${process.cwd()}/package.json`);

const files = process.argv.slice(2);
if (files.length === 0) {
console.error('Please provide files to bump');
process.exit(1);
}
const REPLACE_REGEX = /\d+\.\d+.\d+(?:-\w+(?:\.\w+)?)?/g;

async function run() {
const files = process.argv.slice(2);
if (files.length === 0) {
// eslint-disable-next-line no-console
console.error('[versionbump] Please provide files to bump');
process.exit(1);
}

replace({
files: files,
from: /\d+\.\d+.\d+(?:-\w+(?:\.\w+)?)?/g,
to: pjson.version,
})
.then(changedFiles => {
console.log('Modified files:', changedFiles.join(', '));
})
.catch(error => {
console.error('Error occurred:', error);
try {
await Promise.all(
files.map(async file => {
const data = String(await readFile(file, 'utf8'));
await writeFile(file, data.replace(REPLACE_REGEX, pjson.version));
}),
);

// eslint-disable-next-line no-console
console.log(`[versionbump] Bumped version for ${files.join(', ')}`);
} catch (error) {
// eslint-disable-next-line no-console
console.error('[versionbump] Error occurred:', error);
process.exit(1);
});
}
}

run();
Loading
Loading