From 4c0cd89f7893953875fed35fb4d932bfd0543a70 Mon Sep 17 00:00:00 2001 From: James Garbutt <43081j@users.noreply.github.com> Date: Wed, 17 Jun 2026 22:58:24 +0100 Subject: [PATCH] feat: switch CLI to parseArgs We can now use the built-in `parseArgs` feature instead of needing minimist. --- package-lock.json | 11 +---------- package.json | 3 +-- src/cli.js | 34 ++++++++++++++++++++++++++-------- 3 files changed, 28 insertions(+), 20 deletions(-) diff --git a/package-lock.json b/package-lock.json index be7a41bb..a6e0f208 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,8 +12,7 @@ "asn1.js": "^5.3.0", "http_ece": "1.2.1", "https-proxy-agent": "^9.1.0", - "jws": "^4.0.1", - "minimist": "^1.2.5" + "jws": "^4.0.1" }, "bin": { "web-push": "src/cli.js" @@ -1529,14 +1528,6 @@ "resolved": "https://registry.npmjs.org/minimalistic-assert/-/minimalistic-assert-1.0.1.tgz", "integrity": "sha512-UtJcAD4yEaGtjPezWuO9wC4nwUnVH/8/Im3yEHQP4b67cXlD/Qr9hdITCU1xDbSEXg2XKNaP8jsReV7vQd00/A==" }, - "node_modules/minimist": { - "version": "1.2.8", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz", - "integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==", - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, "node_modules/minipass": { "version": "7.1.3", "resolved": "https://registry.npmjs.org/minipass/-/minipass-7.1.3.tgz", diff --git a/package.json b/package.json index 8867b7ad..7def25ff 100644 --- a/package.json +++ b/package.json @@ -33,8 +33,7 @@ "asn1.js": "^5.3.0", "http_ece": "1.2.1", "https-proxy-agent": "^9.1.0", - "jws": "^4.0.1", - "minimist": "^1.2.5" + "jws": "^4.0.1" }, "devDependencies": { "@eslint/js": "^10.0.1", diff --git a/src/cli.js b/src/cli.js index b645865f..71849b94 100755 --- a/src/cli.js +++ b/src/cli.js @@ -1,6 +1,6 @@ #! /usr/bin/env node -import minimist from 'minimist'; +import { parseArgs } from 'node:util'; import * as webPush from '../src/index.js'; @@ -76,10 +76,10 @@ const sendNotification = args => { const options = {}; if (args.ttl) { - options.TTL = args.ttl; + options.TTL = Number(args.ttl); } - if (argv['vapid-subject'] || argv['vapid-pubkey'] || argv['vapid-pvtkey']) { + if (args['vapid-subject'] || args['vapid-pubkey'] || args['vapid-pvtkey']) { options.vapidDetails = { subject: args['vapid-subject'] || null, publicKey: args['vapid-pubkey'] || null, @@ -111,19 +111,37 @@ const sendNotification = args => { }); }; -const action = process.argv[2]; -const argv = minimist(process.argv.slice(3)); +const { values: args, positionals } = parseArgs({ + args: process.argv.slice(2), + allowPositionals: true, + options: { + endpoint: { type: 'string' }, + key: { type: 'string' }, + auth: { type: 'string' }, + payload: { type: 'string' }, + ttl: { type: 'string' }, + encoding: { type: 'string' }, + 'vapid-subject': { type: 'string' }, + 'vapid-pubkey': { type: 'string' }, + 'vapid-pvtkey': { type: 'string' }, + proxy: { type: 'string' }, + 'gcm-api-key': { type: 'string' }, + json: { type: 'boolean' } + } +}); + +const action = positionals[0]; switch (action) { case 'send-notification': - if (!argv.endpoint) { + if (!args.endpoint) { printUsageDetails(); break; } - sendNotification(argv); + sendNotification(args); break; case 'generate-vapid-keys': - generateVapidKeys(argv.json || false); + generateVapidKeys(args.json || false); break; default: printUsageDetails();