-
Notifications
You must be signed in to change notification settings - Fork 995
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(helpers): rebase, Parser, applyExtends now blessed helpers (#1733)
- Loading branch information
Showing
10 changed files
with
91 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,14 @@ | ||
export { hideBin } from './build/lib/utils/process-argv.js' | ||
import { applyExtends as _applyExtends } from './build/lib/utils/apply-extends.js' | ||
import { hideBin } from './build/lib/utils/process-argv.js' | ||
import Parser from 'yargs-parser' | ||
import shim from './lib/platform-shims/esm.mjs' | ||
|
||
const applyExtends = (config, cwd, mergeExtends) => { | ||
return _applyExtends(config, cwd, mergeExtends, shim) | ||
} | ||
|
||
export { | ||
applyExtends, | ||
hideBin, | ||
Parser, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
'use strict' | ||
|
||
import * as assert from 'assert' | ||
import { | ||
applyExtends, | ||
hideBin, | ||
Parser, | ||
} from '../../helpers.mjs' | ||
|
||
describe('helpers', () => { | ||
describe('applyExtends', () => { | ||
it('exposes applyExtends helper', () => { | ||
const conf = applyExtends({extends: './package.json', apple: 'red'}, process.cwd(), true); | ||
assert.strictEqual(conf.name, 'yargs') // loads packge.json. | ||
assert.strictEqual(conf.apple, 'red') // keeps config with extends. | ||
}) | ||
}) | ||
describe('Parser', () => { | ||
it('exposes functional argument parser', () => { | ||
const argv = Parser('--foo --bar=99') | ||
assert.strictEqual(argv.bar, 99) | ||
}) | ||
}) | ||
describe('hideBin', () => { | ||
it('hides bin for standard node.js application', () => { | ||
const args = hideBin(['node', 'foo.js', '--apple', '--banana']) | ||
// assert.deepEqual(args, ['--apple', '--banana']) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
'use strict' | ||
|
||
const {describe, it} = require('mocha') | ||
const assert = require('assert') | ||
const yargs = require('../yargs.cjs'); | ||
const { applyExtends } = require('../yargs.cjs'); | ||
|
||
const HELPER_COUNT = 2; | ||
|
||
describe('helpers', () => { | ||
it('does not expose additional helpers beyond blessed list', () => { | ||
assert.strictEqual(Object.keys(yargs).length, HELPER_COUNT) | ||
}) | ||
describe('applyExtends', () => { | ||
it('exposes applyExtends helper', () => { | ||
const conf = applyExtends({extends: './package.json', apple: 'red'}, process.cwd(), true); | ||
assert.strictEqual(conf.name, 'yargs') // loads packge.json. | ||
assert.strictEqual(conf.apple, 'red') // keeps config with extends. | ||
}) | ||
}) | ||
describe('Parser', () => { | ||
it('exposes functional argument parser', () => { | ||
const argv = yargs.Parser('--foo --bar=99') | ||
assert.strictEqual(argv.bar, 99) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// TODO: consolidate on using a helpers file at some point in the future, which | ||
// is the approach currently used to export Parser and applyExtends for ESM: | ||
const {applyExtends, cjsPlatformShim, Parser, Yargs} = require('./build/index.cjs') | ||
Yargs.applyExtends = (config, cwd, mergeExtends) => { | ||
return applyExtends(config, cwd, mergeExtends, cjsPlatformShim) | ||
} | ||
Yargs.Parser = Parser | ||
module.exports = Yargs |