Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix(deno): get yargs working on deno@1.5.x (#1799)
  • Loading branch information
bcoe committed Nov 9, 2020
1 parent 75f98fb commit cb01c98
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 18 deletions.
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -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 <files...>', 'download a list of files', (yargs: YargsType) => {
.command('download <files...>', 'download a list of files', (yargs: any) => {
return yargs.positional('files', {
describe: 'a list of files to do something with'
})
Expand Down
3 changes: 1 addition & 2 deletions 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);
}

Expand Down
4 changes: 2 additions & 2 deletions lib/platform-shims/deno.ts
Expand Up @@ -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';

Expand Down
10 changes: 6 additions & 4 deletions lib/yargs-factory.ts
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions test/deno/yargs.test.ts
Expand Up @@ -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
Expand All @@ -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'
})
Expand Down
16 changes: 10 additions & 6 deletions 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;
}

0 comments on commit cb01c98

Please sign in to comment.