From 01cf2a5a4740fd501a15313bb99483abd2495d37 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Tue, 11 Oct 2022 10:45:58 +0700 Subject: [PATCH] Require Node.js 14 --- index.d.ts | 14 +++++++------- index.js | 6 +++--- index.test-d.ts | 4 ++-- package.json | 23 +++++++++++++---------- test/test.js | 4 ++-- 5 files changed, 27 insertions(+), 24 deletions(-) diff --git a/index.d.ts b/index.d.ts index 31e906a..5c06aaa 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,4 +1,4 @@ -import { +import type { CamelCasedProperties, PackageJson, } from 'type-fest'; @@ -15,13 +15,13 @@ Callback function to determine if a flag is required during runtime. */ export type IsRequiredPredicate = (flags: Readonly, input: readonly string[]) => boolean; -export interface Flag { +export type Flag = { readonly type?: Type; readonly alias?: string; readonly default?: Default; readonly isRequired?: boolean | IsRequiredPredicate; readonly isMultiple?: IsMultiple; -} +}; type StringFlag = Flag<'string', string> | Flag<'string', string[], true>; type BooleanFlag = Flag<'boolean', boolean> | Flag<'boolean', boolean[], true>; @@ -29,7 +29,7 @@ type NumberFlag = Flag<'number', number> | Flag<'number', number[], true>; type AnyFlag = StringFlag | BooleanFlag | NumberFlag; type AnyFlags = Record; -export interface Options { +export type Options = { /** Pass in [`import.meta`](https://nodejs.org/dist/latest/docs/api/esm.html#esm_import_meta). This is used to find the correct package.json file. */ @@ -216,7 +216,7 @@ export interface Options { @default true */ readonly allowUnknownFlags?: boolean; -} +}; type TypedFlag = Flag extends {type: 'number'} @@ -240,7 +240,7 @@ export type TypedFlags = { : PossiblyOptionalFlag> }; -export interface Result { +export type Result = { /** Non-flag arguments. */ @@ -277,7 +277,7 @@ export interface Result { Show the version text and exit. */ showVersion: () => void; -} +}; /** @param helpMessage - Shortcut for the `help` option. diff --git a/index.js b/index.js index 2ab52d0..b17499c 100644 --- a/index.js +++ b/index.js @@ -82,7 +82,7 @@ const buildParserFlags = ({flags, booleanDefault}) => { if (flag.isMultiple) { flag.type = flag.type ? `${flag.type}-array` : 'array'; - flag.default = flag.default || []; + flag.default = flag.default ?? []; delete flag.isMultiple; } @@ -107,7 +107,7 @@ const meow = (helpText, options = {}) => { helpText = ''; } - if (!(options.importMeta && options.importMeta.url)) { + if (!options.importMeta?.url) { throw new TypeError('The `importMeta` option is required. Its value must be `import.meta`.'); } @@ -176,7 +176,7 @@ const meow = (helpText, options = {}) => { const {pkg: package_} = options; const argv = parseArguments(options.argv, parserOptions); - let help = redent(trimNewlines((options.help || '').replace(/\t+\n*$/, '')), 2); + let help = redent(trimNewlines((options.help ?? '').replace(/\t+\n*$/, '')), 2); normalizePackageData(package_); diff --git a/index.test-d.ts b/index.test-d.ts index 1677e6b..add5eb3 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -1,6 +1,6 @@ import {expectAssignable, expectError, expectType} from 'tsd'; -import {PackageJson} from 'type-fest'; -import meow, {Result, AnyFlag} from './index.js'; +import type {PackageJson} from 'type-fest'; +import meow, {type Result, type AnyFlag} from './index.js'; const importMeta = import.meta; diff --git a/package.json b/package.json index f7890b8..f0851e2 100644 --- a/package.json +++ b/package.json @@ -11,9 +11,12 @@ "url": "https://sindresorhus.com" }, "type": "module", - "exports": "./index.js", + "exports": { + "types": "./index.d.ts", + "default": "./index.js" + }, "engines": { - "node": "^12.20.0 || ^14.13.1 || >=16.0.0" + "node": ">=14.16" }, "scripts": { "test": "xo && ava && tsd" @@ -43,25 +46,25 @@ ], "dependencies": { "@types/minimist": "^1.2.2", - "camelcase-keys": "^7.0.0", - "decamelize": "^5.0.0", + "camelcase-keys": "^8.0.2", + "decamelize": "^6.0.0", "decamelize-keys": "^1.1.0", "hard-rejection": "^2.1.0", "minimist-options": "4.1.0", - "normalize-package-data": "^3.0.2", - "read-pkg-up": "^8.0.0", + "normalize-package-data": "^4.0.1", + "read-pkg-up": "^9.1.0", "redent": "^4.0.0", "trim-newlines": "^4.0.2", "type-fest": "^3.1.0", - "yargs-parser": "^20.2.9" + "yargs-parser": "^21.1.1" }, "devDependencies": { - "ava": "^3.15.0", + "ava": "^4.3.3", "execa": "^6.1.0", "indent-string": "^5.0.0", "read-pkg": "^7.1.0", - "tsd": "^0.20.0", - "xo": "^0.48.0" + "tsd": "^0.24.1", + "xo": "^0.52.4" }, "xo": { "rules": { diff --git a/test/test.js b/test/test.js index b9e7fa7..d9b8033 100644 --- a/test/test.js +++ b/test/test.js @@ -101,13 +101,13 @@ test('spawn cli and test input flag', async t => { t.is(stdout, 'bar'); }); -test.serial('pkg.bin as a string should work', t => { +test.serial.failing('pkg.bin as a string should work', t => { meow({ importMeta, pkg: { importMeta, name: 'browser-sync', - bin: 'bin/browser-sync.js', + bin: './bin/browser-sync.js', }, });