dependencies: Remove three JS argument parsing libraries.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg
2024-11-10 15:10:00 -08:00
committed by Anders Kaseorg
parent da749d1c94
commit ff70ab441d
7 changed files with 65 additions and 84 deletions

View File

@@ -122,7 +122,6 @@
"callsites": "^3.1.0", "callsites": "^3.1.0",
"cldr-annotations-derived-modern": "^45.0.0", "cldr-annotations-derived-modern": "^45.0.0",
"cldr-annotations-modern": "^45.0.0", "cldr-annotations-modern": "^45.0.0",
"commander": "^12.0.0",
"confusing-browser-globals": "^1.0.11", "confusing-browser-globals": "^1.0.11",
"css.escape": "^1.5.1", "css.escape": "^1.5.1",
"diff": "^7.0.0", "diff": "^7.0.0",
@@ -137,7 +136,6 @@
"eslint-plugin-no-jquery": "^3.0.2", "eslint-plugin-no-jquery": "^3.0.2",
"eslint-plugin-unicorn": "^56.0.0", "eslint-plugin-unicorn": "^56.0.0",
"jsdom": "^25.0.0", "jsdom": "^25.0.0",
"minimist": "^1.2.6",
"mockdate": "^3.0.2", "mockdate": "^3.0.2",
"nyc": "^17.0.0", "nyc": "^17.0.0",
"openapi-examples-validator": "^5.0.0", "openapi-examples-validator": "^5.0.0",
@@ -154,7 +152,6 @@
"webpack-dev-server": "^5.0.2", "webpack-dev-server": "^5.0.2",
"xvfb": "^0.4.0", "xvfb": "^0.4.0",
"yaml": "^2.0.0-8", "yaml": "^2.0.0-8",
"yargs": "^17.1.1",
"zulip-js": "^2.0.8" "zulip-js": "^2.0.8"
}, },
"pnpm": { "pnpm": {

15
pnpm-lock.yaml generated
View File

@@ -377,9 +377,6 @@ importers:
cldr-annotations-modern: cldr-annotations-modern:
specifier: ^45.0.0 specifier: ^45.0.0
version: 45.0.0 version: 45.0.0
commander:
specifier: ^12.0.0
version: 12.1.0
confusing-browser-globals: confusing-browser-globals:
specifier: ^1.0.11 specifier: ^1.0.11
version: 1.0.11 version: 1.0.11
@@ -422,9 +419,6 @@ importers:
jsdom: jsdom:
specifier: ^25.0.0 specifier: ^25.0.0
version: 25.0.1 version: 25.0.1
minimist:
specifier: ^1.2.6
version: 1.2.8
mockdate: mockdate:
specifier: ^3.0.2 specifier: ^3.0.2
version: 3.0.5 version: 3.0.5
@@ -473,9 +467,6 @@ importers:
yaml: yaml:
specifier: ^2.0.0-8 specifier: ^2.0.0-8
version: 2.6.0 version: 2.6.0
yargs:
specifier: ^17.1.1
version: 17.7.2
zulip-js: zulip-js:
specifier: ^2.0.8 specifier: ^2.0.8
version: 2.1.0(encoding@0.1.13) version: 2.1.0(encoding@0.1.13)
@@ -3464,10 +3455,6 @@ packages:
resolution: {integrity: sha512-MwVNWlYjDTtOjX5PiD7o5pK0UrFU/OYgcJfjjK4RaHZETNtjJqrZa9Y9ds88+A+f+d5lv+561eZ+yCKoS3gbAA==} resolution: {integrity: sha512-MwVNWlYjDTtOjX5PiD7o5pK0UrFU/OYgcJfjjK4RaHZETNtjJqrZa9Y9ds88+A+f+d5lv+561eZ+yCKoS3gbAA==}
engines: {node: '>=18'} engines: {node: '>=18'}
commander@12.1.0:
resolution: {integrity: sha512-Vw8qHK3bZM9y/P10u3Vib8o/DdkvA2OtPtZvD871QKjy74Wj1WSKFILMPRPSdUSx5RFK1arlJzEtA4PkFgnbuA==}
engines: {node: '>=18'}
commander@2.20.3: commander@2.20.3:
resolution: {integrity: sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==} resolution: {integrity: sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==}
@@ -12604,8 +12591,6 @@ snapshots:
commander@12.0.0: {} commander@12.0.0: {}
commander@12.1.0: {}
commander@2.20.3: {} commander@2.20.3: {}
commander@6.2.1: {} commander@6.2.1: {}

View File

@@ -3,21 +3,24 @@
"use strict"; "use strict";
const fs = require("node:fs"); const fs = require("node:fs");
const {parseArgs} = require("node:util");
const Diff = require("diff"); const Diff = require("diff");
const ExampleValidator = require("openapi-examples-validator"); const ExampleValidator = require("openapi-examples-validator");
const Prettier = require("prettier"); const Prettier = require("prettier");
const SwaggerParser = require("swagger-parser"); const SwaggerParser = require("swagger-parser");
const {Composer, CST, LineCounter, Parser, Scalar, YAMLMap, YAMLSeq, visit} = require("yaml"); 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)) const usage = "Usage: check-openapi [--fix] <file>...";
.option("fix", { const {
type: "boolean", values: {fix, help},
description: "Automatically fix some problems", positionals: files,
}) } = parseArgs({options: {fix: {type: "boolean"}, help: {type: "boolean"}}, allowPositionals: true});
.parse();
if (help) {
console.log(usage);
process.exit(0);
}
async function checkFile(file) { async function checkFile(file) {
const yaml = await fs.promises.readFile(file, "utf8"); const yaml = await fs.promises.readFile(file, "utf8");
@@ -85,7 +88,7 @@ async function checkFile(file) {
formatted = formatted.replace(/\n$/, ""); formatted = formatted.replace(/\n$/, "");
} }
if (formatted !== node.value.value) { if (formatted !== node.value.value) {
if (argv.fix) { if (fix) {
reformats.set(node.value.range[0], { reformats.set(node.value.range[0], {
value: formatted, value: formatted,
context: {afterKey: true}, context: {afterKey: true},
@@ -158,7 +161,7 @@ async function checkFile(file) {
} }
(async () => { (async () => {
for (const file of argv._) { for (const file of files) {
await checkFile(file); await checkFile(file);
} }
})().catch((error) => { })().catch((error) => {

View File

@@ -4,28 +4,28 @@
const fs = require("node:fs"); const fs = require("node:fs");
const path = require("node:path"); const path = require("node:path");
const {parseArgs} = require("node:util");
const {program} = require("commander");
require("css.escape"); require("css.escape");
const puppeteer = require("puppeteer"); 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 if (help) {
.arguments("<message_id> <image_path> <realm_url>") console.log(usage);
.action((messageId, imagePath, realmUrl) => { process.exit(0);
options.messageId = messageId; }
options.imagePath = imagePath; if (realmUrl === undefined) {
options.realmUrl = realmUrl; console.error(usage);
console.log(`Capturing screenshot for message ${messageId} to ${imagePath}`);
})
.parse(process.argv);
if (options.messageId === undefined) {
console.error("no messageId specified!");
process.exit(1); process.exit(1);
} }
console.log(`Capturing screenshot for message ${messageId} to ${imagePath}`);
// TODO: Refactor to share code with web/e2e-tests/realm-creation.test.ts // TODO: Refactor to share code with web/e2e-tests/realm-creation.test.ts
async function run() { async function run() {
const browser = await puppeteer.launch({ const browser = await puppeteer.launch({
@@ -43,7 +43,7 @@ async function run() {
const page = await browser.newPage(); const page = await browser.newPage();
// deviceScaleFactor:2 gives better quality screenshots (higher pixel density) // deviceScaleFactor:2 gives better quality screenshots (higher pixel density)
await page.setViewport({width: 1280, height: 1024, deviceScaleFactor: 2}); 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. // wait for Iago devlogin button and click on it.
await page.waitForSelector('[value="iago@zulip.com"]'); await page.waitForSelector('[value="iago@zulip.com"]');
@@ -54,17 +54,15 @@ async function run() {
]); ]);
// Navigate to message and capture screenshot // Navigate to message and capture screenshot
await page.goto(`${options.realmUrl}/#narrow/id/${options.messageId}`, { await page.goto(`${realmUrl}/#narrow/id/${messageId}`, {
waitUntil: "networkidle2", waitUntil: "networkidle2",
}); });
// eslint-disable-next-line no-undef // eslint-disable-next-line no-undef
const message_list_id = await page.evaluate(() => zulip_test.current_msg_list.id); const 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); await page.waitForSelector(messageSelector);
// remove unread marker and don't select message // remove unread marker and don't select message
const marker = `#message-row-${message_list_id}-${CSS.escape( const marker = `#message-row-${message_list_id}-${CSS.escape(messageId)} .unread_marker`;
options.messageId,
)} .unread_marker`;
await page.evaluate((sel) => $(sel).remove(), marker); await page.evaluate((sel) => $(sel).remove(), marker);
const messageBox = await page.$(messageSelector); const messageBox = await page.$(messageSelector);
await page.evaluate((msg) => $(msg).removeClass("selected_message"), messageSelector); await page.evaluate((msg) => $(msg).removeClass("selected_message"), messageSelector);
@@ -74,7 +72,6 @@ async function run() {
clip.x -= 5; clip.x -= 5;
clip.width += 10; clip.width += 10;
clip.y += 5; clip.y += 5;
const imagePath = options.imagePath;
const imageDir = path.dirname(imagePath); const imageDir = path.dirname(imagePath);
await fs.promises.mkdir(imageDir, {recursive: true}); await fs.promises.mkdir(imageDir, {recursive: true});
await page.screenshot({path: imagePath, clip}); await page.screenshot({path: imagePath, clip});

View File

@@ -4,30 +4,29 @@
const fs = require("node:fs"); const fs = require("node:fs");
const path = require("node:path"); const path = require("node:path");
const {parseArgs} = require("node:util");
const {program} = require("commander");
require("css.escape"); require("css.escape");
const puppeteer = require("puppeteer"); 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 if (help) {
.arguments("<narrow_uri> <narrow> <unread_msg_id> <image_path> <realm_url>") console.log(usage);
.action((narrow_uri, narrow, unread_msg_id, imagePath, realmUrl) => { process.exit(0);
options.narrowUri = narrow_uri; }
options.narrow = narrow; if (realmUrl === undefined) {
options.messageId = unread_msg_id; console.error(usage);
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!");
process.exit(1); process.exit(1);
} }
console.log(`Capturing screenshot for ${narrow} to ${imagePath}`);
// TODO: Refactor to share code with web/e2e-tests/realm-creation.test.ts // TODO: Refactor to share code with web/e2e-tests/realm-creation.test.ts
async function run() { async function run() {
const browser = await puppeteer.launch({ const browser = await puppeteer.launch({
@@ -45,7 +44,7 @@ async function run() {
const page = await browser.newPage(); const page = await browser.newPage();
// deviceScaleFactor:2 gives better quality screenshots (higher pixel density) // deviceScaleFactor:2 gives better quality screenshots (higher pixel density)
await page.setViewport({width: 530, height: 1024, deviceScaleFactor: 2}); 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. // wait for Iago devlogin button and click on it.
await page.waitForSelector('[value="iago@zulip.com"]'); await page.waitForSelector('[value="iago@zulip.com"]');
@@ -56,7 +55,7 @@ async function run() {
]); ]);
// Navigate to message and capture screenshot // Navigate to message and capture screenshot
await page.goto(`${options.narrowUri}`, { await page.goto(`${narrowUri}`, {
waitUntil: "networkidle2", waitUntil: "networkidle2",
}); });
// eslint-disable-next-line no-undef // eslint-disable-next-line no-undef
@@ -72,7 +71,7 @@ async function run() {
$(sel).remove(); $(sel).remove();
}, marker); }, 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); await page.waitForSelector(messageSelector);
const messageListBox = await page.$(messageListSelector); const messageListBox = await page.$(messageListSelector);
@@ -91,7 +90,6 @@ async function run() {
clip.width -= 64; clip.width -= 64;
clip.y += 10; clip.y += 10;
clip.height -= 8; clip.height -= 8;
const imagePath = options.imagePath;
const imageDir = path.dirname(imagePath); const imageDir = path.dirname(imagePath);
await fs.promises.mkdir(imageDir, {recursive: true}); await fs.promises.mkdir(imageDir, {recursive: true});
await page.screenshot({path: imagePath, clip}); await page.screenshot({path: imagePath, clip});

View File

@@ -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 # historical commits sharing the same major version, in which case a
# minor version bump suffices. # 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, yargs

View File

@@ -127,23 +127,24 @@ module.exports = {diff_strings};
// Simple CLI for this module // Simple CLI for this module
// Only run this code if called as a command-line utility // Only run this code if called as a command-line utility
if (require.main === module) { if (require.main === module) {
// First two args are just "node" and "mdiff.js" const {parseArgs} = require("node:util");
const argv = require("minimist")(process.argv.slice(2));
if (Object.hasOwn(argv, "help")) { const usage =
console.log( "Usage: mdiff <string_0> <string_1>\nWhere <string_0> and <string_1> are the strings to be diffed";
process.argv[0] + const {
" " + values: {help},
process.argv[1] + positionals: [string_0, string_1],
" [ --help ]" + } = parseArgs({options: {help: {type: "boolean"}}, allowPositionals: true});
" string_0" +
" string_1" + if (help) {
"\n" + console.log(usage);
"Where string_0 and string_1 are the strings to be diffed",
);
process.exit(0); 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); console.log(output);
} }