Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
dependencies: Remove three JS argument parsing libraries.
Anders Kaseorgff70ab441d09
diff --git a/package.json b/package.jsonindex 712dcfd90f0..dd7c418d58e 100644--- a/package.json+++ b/package.json@@ -122,7 +122,6 @@"callsites": "^3.1.0","cldr-annotations-derived-modern": "^45.0.0","cldr-annotations-modern": "^45.0.0",- "commander": "^12.0.0","confusing-browser-globals": "^1.0.11","css.escape": "^1.5.1","diff": "^7.0.0",@@ -137,7 +136,6 @@"eslint-plugin-no-jquery": "^3.0.2","eslint-plugin-unicorn": "^56.0.0","jsdom": "^25.0.0",- "minimist": "^1.2.6","mockdate": "^3.0.2","nyc": "^17.0.0","openapi-examples-validator": "^5.0.0",@@ -154,7 +152,6 @@"webpack-dev-server": "^5.0.2","xvfb": "^0.4.0","yaml": "^2.0.0-8",- "yargs": "^17.1.1","zulip-js": "^2.0.8"},"pnpm": {diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 405e902be8a..76c064478c5 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -377,9 +377,6 @@ importers:cldr-annotations-modern:specifier: ^45.0.0version: 45.0.0- commander:- specifier: ^12.0.0- version: 12.1.0confusing-browser-globals:specifier: ^1.0.11version: 1.0.11@@ -422,9 +419,6 @@ importers:jsdom:specifier: ^25.0.0version: 25.0.1- minimist:- specifier: ^1.2.6- version: 1.2.8mockdate:specifier: ^3.0.2version: 3.0.5@@ -473,9 +467,6 @@ importers:yaml:specifier: ^2.0.0-8version: 2.6.0- yargs:- specifier: ^17.1.1- version: 17.7.2zulip-js:specifier: ^2.0.8version: 2.1.0([email protected])@@ -3464,10 +3455,6 @@ packages:resolution: {integrity: sha512-MwVNWlYjDTtOjX5PiD7o5pK0UrFU/OYgcJfjjK4RaHZETNtjJqrZa9Y9ds88+A+f+d5lv+561eZ+yCKoS3gbAA==}engines: {node: '>=18'}- resolution: {integrity: sha512-Vw8qHK3bZM9y/P10u3Vib8o/DdkvA2OtPtZvD871QKjy74Wj1WSKFILMPRPSdUSx5RFK1arlJzEtA4PkFgnbuA==}- engines: {node: '>=18'}-resolution: {integrity: sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==}@@ -12604,8 +12591,6 @@ snapshots:- [email protected]: {}-diff --git a/tools/check-openapi b/tools/check-openapiindex bdbc6d2f87c..0810a273e3d 100755--- a/tools/check-openapi+++ b/tools/check-openapi@@ -3,21 +3,24 @@"use strict";const fs = require("node:fs");+const {parseArgs} = require("node:util");const Diff = require("diff");const ExampleValidator = require("openapi-examples-validator");const Prettier = require("prettier");const SwaggerParser = require("swagger-parser");const {Composer, CST, LineCounter, Parser, Scalar, YAMLMap, YAMLSeq, visit} = require("yaml");-const {hideBin} = require("yargs/helpers");-const yargs = require("yargs/yargs");-const argv = yargs(hideBin(process.argv))- .option("fix", {- type: "boolean",- description: "Automatically fix some problems",- })- .parse();+const usage = "Usage: check-openapi [--fix] <file>...";+const {+ values: {fix, help},+ positionals: files,+} = parseArgs({options: {fix: {type: "boolean"}, help: {type: "boolean"}}, allowPositionals: true});++if (help) {+ console.log(usage);+ process.exit(0);+}async function checkFile(file) {const yaml = await fs.promises.readFile(file, "utf8");@@ -85,7 +88,7 @@ async function checkFile(file) {formatted = formatted.replace(/\n$/, "");}if (formatted !== node.value.value) {- if (argv.fix) {+ if (fix) {reformats.set(node.value.range[0], {value: formatted,context: {afterKey: true},@@ -158,7 +161,7 @@ async function checkFile(file) {}(async () => {- for (const file of argv._) {+ for (const file of files) {await checkFile(file);}})().catch((error) => {diff --git a/tools/screenshots/message-screenshot.js b/tools/screenshots/message-screenshot.jsindex db964b234d0..0d176fd8134 100644--- a/tools/screenshots/message-screenshot.js+++ b/tools/screenshots/message-screenshot.js@@ -4,28 +4,28 @@const fs = require("node:fs");const path = require("node:path");+const {parseArgs} = require("node:util");-const {program} = require("commander");require("css.escape");const puppeteer = require("puppeteer");-const options = {};+const usage = "Usage: message-screenshot.js <message_id> <image_path> <realm_url>";+const {+ values: {help},+ positionals: [messageId, imagePath, realmUrl],+} = parseArgs({options: {help: {type: "boolean"}}, allowPositionals: true});-program- .arguments("<message_id> <image_path> <realm_url>")- .action((messageId, imagePath, realmUrl) => {- options.messageId = messageId;- options.imagePath = imagePath;- options.realmUrl = realmUrl;- console.log(`Capturing screenshot for message ${messageId} to ${imagePath}`);- })- .parse(process.argv);--if (options.messageId === undefined) {- console.error("no messageId specified!");+if (help) {+ console.log(usage);+ process.exit(0);+}+if (realmUrl === undefined) {+ console.error(usage);process.exit(1);}+console.log(`Capturing screenshot for message ${messageId} to ${imagePath}`);+// TODO: Refactor to share code with web/e2e-tests/realm-creation.test.tsasync function run() {const browser = await puppeteer.launch({@@ -43,7 +43,7 @@ async function run() {const page = await browser.newPage();// deviceScaleFactor:2 gives better quality screenshots (higher pixel density)await page.setViewport({width: 1280, height: 1024, deviceScaleFactor: 2});- await page.goto(`${options.realmUrl}/devlogin`);+ await page.goto(`${realmUrl}/devlogin`);// wait for Iago devlogin button and click on it.await page.waitForSelector('[value="[email protected]"]');@@ -54,17 +54,15 @@ async function run() {]);// Navigate to message and capture screenshot- await page.goto(`${options.realmUrl}/#narrow/id/${options.messageId}`, {+ await page.goto(`${realmUrl}/#narrow/id/${messageId}`, {waitUntil: "networkidle2",});// eslint-disable-next-line no-undefconst message_list_id = await page.evaluate(() => zulip_test.current_msg_list.id);- const messageSelector = `#message-row-${message_list_id}-${CSS.escape(options.messageId)}`;+ const messageSelector = `#message-row-${message_list_id}-${CSS.escape(messageId)}`;await page.waitForSelector(messageSelector);// remove unread marker and don't select message- const marker = `#message-row-${message_list_id}-${CSS.escape(- options.messageId,- )} .unread_marker`;+ const marker = `#message-row-${message_list_id}-${CSS.escape(messageId)} .unread_marker`;await page.evaluate((sel) => $(sel).remove(), marker);const messageBox = await page.$(messageSelector);await page.evaluate((msg) => $(msg).removeClass("selected_message"), messageSelector);@@ -74,7 +72,6 @@ async function run() {clip.x -= 5;clip.width += 10;clip.y += 5;- const imagePath = options.imagePath;const imageDir = path.dirname(imagePath);await fs.promises.mkdir(imageDir, {recursive: true});await page.screenshot({path: imagePath, clip});diff --git a/tools/screenshots/thread-screenshot.js b/tools/screenshots/thread-screenshot.jsindex b7bc9f8a4d6..611e54209bb 100644--- a/tools/screenshots/thread-screenshot.js+++ b/tools/screenshots/thread-screenshot.js@@ -4,30 +4,29 @@const fs = require("node:fs");const path = require("node:path");+const {parseArgs} = require("node:util");-const {program} = require("commander");require("css.escape");const puppeteer = require("puppeteer");-const options = {};+const usage =+ "Usage: thread-screenshot.js <narrow_uri> <narrow> <message_id> <image_path> <realm_url>";+const {+ values: {help},+ positionals: [narrowUri, narrow, messageId, imagePath, realmUrl],+} = parseArgs({options: {help: {type: "boolean"}}, allowPositionals: true});-program- .arguments("<narrow_uri> <narrow> <unread_msg_id> <image_path> <realm_url>")- .action((narrow_uri, narrow, unread_msg_id, imagePath, realmUrl) => {- options.narrowUri = narrow_uri;- options.narrow = narrow;- options.messageId = unread_msg_id;- options.imagePath = imagePath;- options.realmUrl = realmUrl;- console.log(`Capturing screenshot for ${narrow} to ${imagePath}`);- })- .parse(process.argv);--if (options.imagePath === undefined) {- console.error("no image path specified!");+if (help) {+ console.log(usage);+ process.exit(0);+}+if (realmUrl === undefined) {+ console.error(usage);process.exit(1);}+console.log(`Capturing screenshot for ${narrow} to ${imagePath}`);+// TODO: Refactor to share code with web/e2e-tests/realm-creation.test.tsasync function run() {const browser = await puppeteer.launch({@@ -45,7 +44,7 @@ async function run() {const page = await browser.newPage();// deviceScaleFactor:2 gives better quality screenshots (higher pixel density)await page.setViewport({width: 530, height: 1024, deviceScaleFactor: 2});- await page.goto(`${options.realmUrl}/devlogin`);+ await page.goto(`${realmUrl}/devlogin`);// wait for Iago devlogin button and click on it.await page.waitForSelector('[value="[email protected]"]');@@ -56,7 +55,7 @@ async function run() {]);// Navigate to message and capture screenshot- await page.goto(`${options.narrowUri}`, {+ await page.goto(`${narrowUri}`, {waitUntil: "networkidle2",});// eslint-disable-next-line no-undef@@ -72,7 +71,7 @@ async function run() {$(sel).remove();}, marker);- const messageSelector = `#message-row-${message_list_id}-${CSS.escape(options.messageId)}`;+ const messageSelector = `#message-row-${message_list_id}-${CSS.escape(messageId)}`;await page.waitForSelector(messageSelector);const messageListBox = await page.$(messageListSelector);@@ -91,7 +90,6 @@ async function run() {clip.width -= 64;clip.y += 10;clip.height -= 8;- const imagePath = options.imagePath;const imageDir = path.dirname(imagePath);await fs.promises.mkdir(imageDir, {recursive: true});await page.screenshot({path: imagePath, clip});diff --git a/version.py b/version.pyindex c063fc8fd84..9b46db1973c 100644--- a/version.py+++ b/version.py@@ -49,4 +49,4 @@ API_FEATURE_LEVEL = 319 # Last bumped for message-link class# historical commits sharing the same major version, in which case a# minor version bump suffices.-PROVISION_VERSION = (300, 0) # bumped 2024-11-10 to remove mkdirp+PROVISION_VERSION = (301, 0) # bumped 2024-11-10 to remove commander, minimist, yargsdiff --git a/web/tests/lib/mdiff.js b/web/tests/lib/mdiff.jsindex 4159c24fa39..7f8df585e6b 100644--- a/web/tests/lib/mdiff.js+++ b/web/tests/lib/mdiff.js@@ -127,23 +127,24 @@ module.exports = {diff_strings};// Simple CLI for this module// Only run this code if called as a command-line utilityif (require.main === module) {- // First two args are just "node" and "mdiff.js"- const argv = require("minimist")(process.argv.slice(2));-- if (Object.hasOwn(argv, "help")) {- console.log(- process.argv[0] +- " " +- process.argv[1] +- " [ --help ]" +- " string_0" +- " string_1" +- "\n" +- "Where string_0 and string_1 are the strings to be diffed",- );+ const {parseArgs} = require("node:util");++ const usage =+ "Usage: mdiff <string_0> <string_1>\nWhere <string_0> and <string_1> are the strings to be diffed";+ const {+ values: {help},+ positionals: [string_0, string_1],+ } = parseArgs({options: {help: {type: "boolean"}}, allowPositionals: true});++ if (help) {+ console.log(usage);process.exit(0);}+ if (string_1 === undefined) {+ console.error(usage);+ process.exit(1);+ }- const output = diff_strings(argv._[0], argv._[1]);+ const output = diff_strings(string_0, string_1);console.log(output);}