Skip to content
This repository was archived by the owner on May 25, 2025. It is now read-only.

Commit 6e58e57

Browse files
feat: _yargs esm helper
1 parent ae8451c commit 6e58e57

File tree

4 files changed

+19
-1
lines changed

4 files changed

+19
-1
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"@naturalcycles/js-lib": "^14",
2424
"@types/js-yaml": "^4",
2525
"@types/jsonwebtoken": "^9",
26+
"@types/yargs": "^16",
2627
"ajv": "^8",
2728
"ajv-formats": "^3",
2829
"ajv-keywords": "^5",
@@ -41,7 +42,6 @@
4142
"@naturalcycles/dev-lib": "^16",
4243
"@types/node": "^22",
4344
"@types/through2-concurrent": "^2",
44-
"@types/yargs": "^16",
4545
"@vitest/coverage-v8": "^3",
4646
"tsx": "^4",
4747
"vitest": "^3"

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ export * from './validation/joi/joi.shared.schemas'
8282
export * from './validation/joi/joi.validation.error'
8383
export * from './validation/joi/joi.validation.util'
8484
export type { StringSchema } from './validation/joi/string.extensions'
85+
export * from './yargs.util'
8586

8687
export type {
8788
AlternativesSchema,

src/yargs.util.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { expect, test } from 'vitest'
2+
import { _yargs } from './yargs.util'
3+
4+
test('_yargs', () => {
5+
expect(typeof _yargs().options).toBe('function')
6+
})

src/yargs.util.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import yargs from 'yargs'
2+
import { hideBin } from 'yargs/helpers'
3+
4+
/**
5+
* Quick yargs helper to make it work in esm.
6+
* It also allows to not have yargs and `@types/yargs` to be declared as dependencies.
7+
*/
8+
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type, @typescript-eslint/explicit-module-boundary-types
9+
export function _yargs() {
10+
return yargs(hideBin(process.argv))
11+
}

0 commit comments

Comments
 (0)