From 049f962598772132f05dc40d84ce30fbb8f56c63 Mon Sep 17 00:00:00 2001 From: tommy-mitchell Date: Wed, 28 Feb 2024 19:34:54 -0600 Subject: [PATCH 1/3] remove `false` from `version` type * this has had no effect since #68 --- readme.md | 2 +- source/index.d.ts | 4 +--- test/options/version.js | 2 +- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/readme.md b/readme.md index 7f51362..61d585b 100644 --- a/readme.md +++ b/readme.md @@ -161,7 +161,7 @@ The description will be shown above your help text automatically. ##### version -Type: `string | boolean`\ +Type: `string`\ Default: The package.json `"version"` property Set a custom version output. diff --git a/source/index.d.ts b/source/index.d.ts index 5fa3b34..7da71ae 100644 --- a/source/index.d.ts +++ b/source/index.d.ts @@ -180,10 +180,8 @@ export type Options = { /** Set a custom version output. Default: The package.json `"version"` property. - - Set it to `false` to disable it altogether. */ - readonly version?: string | false; + readonly version?: string; /** Automatically show the help text when the `--help` flag is present. Useful to set this value to `false` when a CLI manages child CLIs with their own help text. diff --git a/test/options/version.js b/test/options/version.js index 29b5f28..273e190 100644 --- a/test/options/version.js +++ b/test/options/version.js @@ -38,7 +38,7 @@ test('custom version', verifyVersion, { test('version = false has no effect', verifyVersion, { args: '--version', execaOptions: {env: {VERSION: 'false'}}, - expected: '1.0.0', + expected: 'false', }); test('manual showVersion', verifyVersion, { From d29639bbdc618c7bac6a3337866871b9f721815c Mon Sep 17 00:00:00 2001 From: tommy-mitchell Date: Wed, 28 Feb 2024 19:36:01 -0600 Subject: [PATCH 2/3] add version fallback message --- source/index.js | 2 +- source/options.js | 1 + test/options/version.js | 6 ++++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/source/index.js b/source/index.js index 7881e24..da32775 100644 --- a/source/index.js +++ b/source/index.js @@ -36,7 +36,7 @@ const buildResult = (options, parserOptions) => { }; const showVersion = () => { - console.log(typeof options.version === 'string' ? options.version : package_.version); + console.log(options.version); process.exit(0); }; diff --git a/source/options.js b/source/options.js index d46d317..69d3edf 100644 --- a/source/options.js +++ b/source/options.js @@ -75,6 +75,7 @@ export const buildOptions = (helpText, options) => { inferType: false, input: 'string', help: helpText, + version: foundPackage?.packageJson.version || 'No version found', autoHelp: true, autoVersion: true, booleanDefault: false, diff --git a/test/options/version.js b/test/options/version.js index 273e190..576a6a6 100644 --- a/test/options/version.js +++ b/test/options/version.js @@ -45,3 +45,9 @@ test('manual showVersion', verifyVersion, { args: '--show-version', expected: '1.0.0', }); + +test('no version fallback message', verifyVersion, { + fixture: 'with-package-json/default/fixture.js', + args: '--version', + expected: 'No version found', +}); From 7d9b25a39701b65b6a2acfc58be89ec856feebb9 Mon Sep 17 00:00:00 2001 From: tommy-mitchell Date: Wed, 28 Feb 2024 19:41:12 -0600 Subject: [PATCH 3/3] fix type tests --- test-d/build.test-d.ts | 1 - test-d/index.test-d.ts | 1 - 2 files changed, 2 deletions(-) diff --git a/test-d/build.test-d.ts b/test-d/build.test-d.ts index 29ec7de..f05ae20 100644 --- a/test-d/build.test-d.ts +++ b/test-d/build.test-d.ts @@ -40,7 +40,6 @@ expectType>(meow({importMeta, description: false})); expectType>(meow({importMeta, help: 'foo'})); expectType>(meow({importMeta, help: false})); expectType>(meow({importMeta, version: 'foo'})); -expectType>(meow({importMeta, version: false})); expectType>(meow({importMeta, autoHelp: false})); expectType>(meow({importMeta, autoVersion: false})); expectType>(meow({importMeta, pkg: {foo: 'bar'}})); diff --git a/test-d/index.test-d.ts b/test-d/index.test-d.ts index aa5bf91..a1d0f65 100644 --- a/test-d/index.test-d.ts +++ b/test-d/index.test-d.ts @@ -40,7 +40,6 @@ expectType>(meow({importMeta, description: false})); expectType>(meow({importMeta, help: 'foo'})); expectType>(meow({importMeta, help: false})); expectType>(meow({importMeta, version: 'foo'})); -expectType>(meow({importMeta, version: false})); expectType>(meow({importMeta, autoHelp: false})); expectType>(meow({importMeta, autoVersion: false})); expectType>(meow({importMeta, pkg: {foo: 'bar'}}));