From bf32ea48a3851a3028020dd776fd5a941ab140b6 Mon Sep 17 00:00:00 2001 From: outslept <135520429+outslept@users.noreply.github.com> Date: Mon, 28 Jul 2025 00:39:05 +0300 Subject: [PATCH] Replace minimist with mri --- cmd.cjs | 23 +++++++++++---- package-lock.json | 71 +++++++++++++++++++++++++++++++++-------------- package.json | 2 +- 3 files changed, 68 insertions(+), 28 deletions(-) diff --git a/cmd.cjs b/cmd.cjs index 738e5462f..545863c6c 100755 --- a/cmd.cjs +++ b/cmd.cjs @@ -16,7 +16,7 @@ require("please-upgrade-node")(pkg, { }, }); -const minimist = require("minimist"); +const mri = require("mri"); const debug = require("debug")("Eleventy:cmd"); class SimpleError extends Error { @@ -31,7 +31,7 @@ async function exec() { const { EleventyErrorHandler } = await import("./src/Errors/EleventyErrorHandler.js"); try { - const argv = minimist(process.argv.slice(2), { + const argv = mri(process.argv.slice(2), { string: ["input", "output", "formats", "config", "pathprefix", "port", "to", "incremental", "loader"], boolean: [ "quiet", @@ -47,12 +47,23 @@ async function exec() { "ignore-initial": false, "to": "fs", }, - unknown: function (unknownArgument) { + }); + + // mri doesn't provide the same unknown flag detection as minimist, + // so we implement it manually for better UX + const knownFlags = [ + "input", "output", "formats", "config", "pathprefix", "port", "to", + "incremental", "loader", "quiet", "version", "watch", "dryrun", + "help", "serve", "ignore-initial" + ]; + + for (const key of Object.keys(argv)) { + if (key !== '_' && !knownFlags.includes(key)) { throw new Error( - `We don’t know what '${unknownArgument}' is. Use --help to see the list of supported commands.`, + `We don't know what '${key}' is. Use --help to see the list of supported commands.`, ); - }, - }); + } + } debug("command: eleventy %o", argv); const { Eleventy } = await import("./src/Eleventy.js"); diff --git a/package-lock.json b/package-lock.json index a034025d3..4fae67f7c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -33,8 +33,8 @@ "kleur": "^4.1.5", "liquidjs": "^10.21.1", "markdown-it": "^14.1.0", - "minimist": "^1.2.8", "moo": "^0.5.2", + "mri": "^1.2.0", "node-retrieve-globals": "^6.0.1", "nunjucks": "^3.2.4", "picomatch": "^4.0.3", @@ -2275,7 +2275,8 @@ "optional": true, "os": [ "android" - ] + ], + "peer": true }, "node_modules/@rollup/rollup-android-arm64": { "version": "4.45.1", @@ -2289,7 +2290,8 @@ "optional": true, "os": [ "android" - ] + ], + "peer": true }, "node_modules/@rollup/rollup-darwin-arm64": { "version": "4.45.1", @@ -2303,7 +2305,8 @@ "optional": true, "os": [ "darwin" - ] + ], + "peer": true }, "node_modules/@rollup/rollup-darwin-x64": { "version": "4.45.1", @@ -2317,7 +2320,8 @@ "optional": true, "os": [ "darwin" - ] + ], + "peer": true }, "node_modules/@rollup/rollup-freebsd-arm64": { "version": "4.45.1", @@ -2331,7 +2335,8 @@ "optional": true, "os": [ "freebsd" - ] + ], + "peer": true }, "node_modules/@rollup/rollup-freebsd-x64": { "version": "4.45.1", @@ -2345,7 +2350,8 @@ "optional": true, "os": [ "freebsd" - ] + ], + "peer": true }, "node_modules/@rollup/rollup-linux-arm-gnueabihf": { "version": "4.45.1", @@ -2359,7 +2365,8 @@ "optional": true, "os": [ "linux" - ] + ], + "peer": true }, "node_modules/@rollup/rollup-linux-arm-musleabihf": { "version": "4.45.1", @@ -2373,7 +2380,8 @@ "optional": true, "os": [ "linux" - ] + ], + "peer": true }, "node_modules/@rollup/rollup-linux-arm64-gnu": { "version": "4.45.1", @@ -2387,7 +2395,8 @@ "optional": true, "os": [ "linux" - ] + ], + "peer": true }, "node_modules/@rollup/rollup-linux-arm64-musl": { "version": "4.45.1", @@ -2401,7 +2410,8 @@ "optional": true, "os": [ "linux" - ] + ], + "peer": true }, "node_modules/@rollup/rollup-linux-loongarch64-gnu": { "version": "4.45.1", @@ -2415,7 +2425,8 @@ "optional": true, "os": [ "linux" - ] + ], + "peer": true }, "node_modules/@rollup/rollup-linux-powerpc64le-gnu": { "version": "4.45.1", @@ -2429,7 +2440,8 @@ "optional": true, "os": [ "linux" - ] + ], + "peer": true }, "node_modules/@rollup/rollup-linux-riscv64-gnu": { "version": "4.45.1", @@ -2443,7 +2455,8 @@ "optional": true, "os": [ "linux" - ] + ], + "peer": true }, "node_modules/@rollup/rollup-linux-riscv64-musl": { "version": "4.45.1", @@ -2457,7 +2470,8 @@ "optional": true, "os": [ "linux" - ] + ], + "peer": true }, "node_modules/@rollup/rollup-linux-s390x-gnu": { "version": "4.45.1", @@ -2471,7 +2485,8 @@ "optional": true, "os": [ "linux" - ] + ], + "peer": true }, "node_modules/@rollup/rollup-linux-x64-gnu": { "version": "4.45.1", @@ -2485,7 +2500,8 @@ "optional": true, "os": [ "linux" - ] + ], + "peer": true }, "node_modules/@rollup/rollup-linux-x64-musl": { "version": "4.45.1", @@ -2499,7 +2515,8 @@ "optional": true, "os": [ "linux" - ] + ], + "peer": true }, "node_modules/@rollup/rollup-win32-arm64-msvc": { "version": "4.45.1", @@ -2513,7 +2530,8 @@ "optional": true, "os": [ "win32" - ] + ], + "peer": true }, "node_modules/@rollup/rollup-win32-ia32-msvc": { "version": "4.45.1", @@ -2527,7 +2545,8 @@ "optional": true, "os": [ "win32" - ] + ], + "peer": true }, "node_modules/@rollup/rollup-win32-x64-msvc": { "version": "4.45.1", @@ -2541,7 +2560,8 @@ "optional": true, "os": [ "win32" - ] + ], + "peer": true }, "node_modules/@sindresorhus/merge-streams": { "version": "2.3.0", @@ -7868,6 +7888,15 @@ "integrity": "sha512-z6bfWFMra7kBqDjQGHud1LSXtq5JJC060viEkQFMBX6baIecpkNr2Ywrn2OQfWP3rXiNFQRPoFjD8/TvJcWcDg==", "license": "MIT" }, + "node_modules/mri": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/mri/-/mri-1.2.0.tgz", + "integrity": "sha512-tzzskb3bG8LvYGFF/mDTpq3jpI6Q9wc3LEmBaghu+DdCssd1FakN7Bc0hVNmEyGq1bq3RgfkCb3cmQLpNPOroA==", + "license": "MIT", + "engines": { + "node": ">=4" + } + }, "node_modules/mrmime": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/mrmime/-/mrmime-2.0.1.tgz", diff --git a/package.json b/package.json index d4800c281..adae66593 100644 --- a/package.json +++ b/package.json @@ -153,8 +153,8 @@ "kleur": "^4.1.5", "liquidjs": "^10.21.1", "markdown-it": "^14.1.0", - "minimist": "^1.2.8", "moo": "^0.5.2", + "mri": "^1.2.0", "node-retrieve-globals": "^6.0.1", "nunjucks": "^3.2.4", "picomatch": "^4.0.3",