From cb01c98c44e30f55c2dc9434caef524ae433d9a4 Mon Sep 17 00:00:00 2001 From: "Benjamin E. Coe" Date: Mon, 9 Nov 2020 10:08:20 -0500 Subject: [PATCH] fix(deno): get yargs working on deno@1.5.x (#1799) --- README.md | 4 ++-- deno.ts | 3 +-- lib/platform-shims/deno.ts | 4 ++-- lib/yargs-factory.ts | 10 ++++++---- test/deno/yargs.test.ts | 4 ++-- types.ts | 16 ++++++++++------ 6 files changed, 23 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 9407ba5ee..977096721 100644 --- a/README.md +++ b/README.md @@ -124,10 +124,10 @@ As of `v16`, `yargs` supports [Deno](https://github.com/denoland/deno): ```typescript import yargs from 'https://deno.land/x/yargs/deno.ts' -import { Arguments, YargsType } from 'https://deno.land/x/yargs/types.ts' +import { Arguments } from 'https://deno.land/x/yargs/types.ts' yargs(Deno.args) - .command('download ', 'download a list of files', (yargs: YargsType) => { + .command('download ', 'download a list of files', (yargs: any) => { return yargs.positional('files', { describe: 'a list of files to do something with' }) diff --git a/deno.ts b/deno.ts index f67dbc764..62613e5c9 100644 --- a/deno.ts +++ b/deno.ts @@ -1,11 +1,10 @@ // Bootstrap yargs for Deno platform: import denoPlatformShim from './lib/platform-shims/deno.ts'; import {YargsWithShim} from './build/lib/yargs-factory.js'; -import type {YargsInstance as YargsType} from './build/lib/yargs-factory.d.ts'; const WrappedYargs = YargsWithShim(denoPlatformShim); -function Yargs(args?: string[]): YargsType { +function Yargs(args?: string[]) { return WrappedYargs(args); } diff --git a/lib/platform-shims/deno.ts b/lib/platform-shims/deno.ts index 741d202d9..9b55ea180 100644 --- a/lib/platform-shims/deno.ts +++ b/lib/platform-shims/deno.ts @@ -11,9 +11,9 @@ import { posix, } from 'https://deno.land/std/path/mod.ts'; -import cliui from 'https://deno.land/x/cliui@v7.0.0-deno/deno.ts'; +import cliui from 'https://deno.land/x/cliui@v7.0.4-deno/deno.ts'; import escalade from 'https://deno.land/x/escalade@v3.0.3/sync.ts'; -import Parser from 'https://deno.land/x/yargs_parser@v20.2.0-deno/deno.ts'; +import Parser from 'https://deno.land/x/yargs_parser@v20.2.4-deno/deno.ts'; import y18n from 'https://deno.land/x/y18n@v5.0.0-deno/deno.ts'; import {YError} from '../../build/lib/yerror.js'; diff --git a/lib/yargs-factory.ts b/lib/yargs-factory.ts index 91bab1bc0..76f7f4e38 100644 --- a/lib/yargs-factory.ts +++ b/lib/yargs-factory.ts @@ -14,18 +14,20 @@ import { command as Command, CommandHandlerDefinition, } from './command.js'; -import { +import type { Dictionary, - assertNotStrictEqual, KeyOf, DictionaryKeyof, ValueOf, - objectKeys, - assertSingleKey, RequireDirectoryOptions, PlatformShim, RequireType, } from './typings/common-types.js'; +import { + assertNotStrictEqual, + assertSingleKey, + objectKeys, +} from './typings/common-types.js'; import { ArgsOutput, DetailedArguments as ParserDetailedArguments, diff --git a/test/deno/yargs.test.ts b/test/deno/yargs.test.ts index dbd5169b8..1cfda8605 100644 --- a/test/deno/yargs.test.ts +++ b/test/deno/yargs.test.ts @@ -5,7 +5,7 @@ import { assertMatch } from 'https://deno.land/std/testing/asserts.ts' import yargs from '../../deno.ts' -import { Arguments, YargsType } from '../../types.ts' +import { Arguments } from '../../types.ts' Deno.test('demandCommand(1) throw error if no command provided', () => { let err: Error|null = null @@ -31,7 +31,7 @@ Deno.test('guesses version # based on package.json', () => { // https://github.com/yargs/yargs/issues/1758 Deno.test('does not drop .0 if positional is configured as string', async () => { const argv = await yargs(['cmd', '33.0']) - .command('cmd [str]', 'a command', (yargs: YargsType) => { + .command('cmd [str]', 'a command', (yargs: any) => { return yargs.positional('str', { type: 'string' }) diff --git a/types.ts b/types.ts index 64be032a8..afcbc5908 100644 --- a/types.ts +++ b/types.ts @@ -1,7 +1,11 @@ -// expose types for the benefit of Deno. -import type { - YargsInstance as YargsType, - Arguments, -} from './build/lib/yargs-factory.d.ts'; +declare type ArgsOutput = (string | number)[]; -export type {Arguments, YargsType}; +// TODO(bcoe): attempt to get the types for YargsInstance working again. +export interface Arguments { + /** Non-option arguments */ + _: ArgsOutput; + /** Arguments after the end-of-options flag `--` */ + '--'?: ArgsOutput; + /** All remaining options */ + [argName: string]: any; +}