diff --git a/.gitignore b/.gitignore index 3059a185..245f7bd3 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ package-lock.json ./test/fixtures/package.json coverage build +example.* diff --git a/lib/yargs-parser.ts b/lib/yargs-parser.ts index 90078178..0b29c9aa 100644 --- a/lib/yargs-parser.ts +++ b/lib/yargs-parser.ts @@ -660,7 +660,10 @@ export class YargsParser { setConfigObject(config) } catch (ex) { - if (argv[configKey]) error = Error(__('Invalid JSON config file: %s', configPath)) + // Deno will receive a PermissionDenied error if an attempt is + // made to load config without the --allow-read flag: + if (ex.name === 'PermissionDenied') error = ex + else if (argv[configKey]) error = Error(__('Invalid JSON config file: %s', configPath)) } } }) diff --git a/test/typescript/tokenize-arg-string.ts b/test/typescript/tokenize-arg-string.ts index 70d76ee3..ff8d486f 100644 --- a/test/typescript/tokenize-arg-string.ts +++ b/test/typescript/tokenize-arg-string.ts @@ -1,7 +1,6 @@ /* global describe, it */ import { strictEqual } from 'assert' import { tokenizeArgString } from '../../lib/tokenize-arg-string.js' -import { expect } from 'chai' describe('TokenizeArgString', function () { it('handles unquoted string', function () { @@ -24,109 +23,109 @@ describe('TokenizeArgString', function () { it('handles single quoted string with spaces', function () { const args = tokenizeArgString("--foo 'hello world' --bar='foo bar'") - args[0].should.equal('--foo') - args[1].should.equal("'hello world'") - args[2].should.equal("--bar='foo bar'") + strictEqual(args[0], '--foo') + strictEqual(args[1], "'hello world'") + strictEqual(args[2], "--bar='foo bar'") }) it('handles double quoted string with spaces', function () { const args = tokenizeArgString('--foo "hello world" --bar="foo bar"') - args[0].should.equal('--foo') - args[1].should.equal('"hello world"') - args[2].should.equal('--bar="foo bar"') + strictEqual(args[0], '--foo') + strictEqual(args[1], '"hello world"') + strictEqual(args[2], '--bar="foo bar"') }) it('handles single quoted empty string', function () { const args = tokenizeArgString('--foo \'\' --bar=\'\'') - args[0].should.equal('--foo') - args[1].should.equal("''") - args[2].should.equal("--bar=''") + strictEqual(args[0], '--foo') + strictEqual(args[1], "''") + strictEqual(args[2], "--bar=''") }) it('handles double quoted empty string', function () { const args = tokenizeArgString('--foo "" --bar=""') - args[0].should.equal('--foo') - args[1].should.equal('""') - args[2].should.equal('--bar=""') + strictEqual(args[0], '--foo') + strictEqual(args[1], '""') + strictEqual(args[2], '--bar=""') }) it('handles quoted string with embedded quotes', function () { var args = tokenizeArgString('--foo "hello \'world\'" --bar=\'foo "bar"\'') - args[0].should.equal('--foo') - args[1].should.equal('"hello \'world\'"') - args[2].should.equal('--bar=\'foo "bar"\'') + strictEqual(args[0], '--foo') + strictEqual(args[1], '"hello \'world\'"') + strictEqual(args[2], '--bar=\'foo "bar"\'') }) // https://github.com/yargs/yargs-parser/pull/100 // https://github.com/yargs/yargs-parser/pull/106 it('ignores unneeded spaces', function () { const args = tokenizeArgString(' foo bar "foo bar" ') - args[0].should.equal('foo') - expect(args[1]).equal('bar') - expect(args[2]).equal('"foo bar"') + strictEqual(args[0], 'foo') + strictEqual(args[1], 'bar') + strictEqual(args[2], '"foo bar"') }) it('handles boolean options', function () { const args = tokenizeArgString('--foo -bar') - expect(args[0]).to.equal(('--foo')) - expect(args[1]).to.equal(('-bar')) + strictEqual(args[0], '--foo') + strictEqual(args[1], '-bar') }) it('handles empty string', function () { const args = tokenizeArgString('') - expect(args.length).to.equal(0) + strictEqual(args.length, 0) }) it('handles array with unquoted string', function () { const args = tokenizeArgString(['--foo', '99']) - args[0].should.equal('--foo') - args[1].should.equal('99') + strictEqual(args[0], '--foo') + strictEqual(args[1], '99') }) it('handles array with quoted string with no spaces', function () { const args = tokenizeArgString(['--foo', "'hello'"]) - args[0].should.equal('--foo') - args[1].should.equal("'hello'") + strictEqual(args[0], '--foo') + strictEqual(args[1], "'hello'") }) it('handles array with single quoted string with spaces', function () { const args = tokenizeArgString(['--foo', "'hello world'", "--bar='foo bar'"]) - args[0].should.equal('--foo') - args[1].should.equal("'hello world'") - args[2].should.equal("--bar='foo bar'") + strictEqual(args[0], '--foo') + strictEqual(args[1], "'hello world'") + strictEqual(args[2], "--bar='foo bar'") }) it('handles array with double quoted string with spaces', function () { const args = tokenizeArgString(['--foo', '"hello world"', '--bar="foo bar"']) - args[0].should.equal('--foo') - args[1].should.equal('"hello world"') - args[2].should.equal('--bar="foo bar"') + strictEqual(args[0], '--foo') + strictEqual(args[1], '"hello world"') + strictEqual(args[2], '--bar="foo bar"') }) it('handles array with single quoted empty string', function () { const args = tokenizeArgString(['--foo', "''", "--bar=''"]) - args[0].should.equal('--foo') - args[1].should.equal("''") - args[2].should.equal("--bar=''") + strictEqual(args[0], '--foo') + strictEqual(args[1], "''") + strictEqual(args[2], "--bar=''") }) it('handles array with double quoted empty string', function () { const args = tokenizeArgString(['--foo', '""', '--bar=""']) - args[0].should.equal('--foo') - args[1].should.equal('""') - args[2].should.equal('--bar=""') + strictEqual(args[0], '--foo') + strictEqual(args[1], '""') + strictEqual(args[2], '--bar=""') }) it('handles array with quoted string with embedded quotes', function () { var args = tokenizeArgString(['--foo', '"hello \'world\'"', '--bar=\'foo "bar"\'']) - args[0].should.equal('--foo') - args[1].should.equal('"hello \'world\'"') - args[2].should.equal('--bar=\'foo "bar"\'') + strictEqual(args[0], '--foo') + strictEqual(args[1], '"hello \'world\'"') + strictEqual(args[2], '--bar=\'foo "bar"\'') }) it('handles array with boolean options', function () { const args = tokenizeArgString(['--foo', '-bar']) - expect(args[0]).to.equal('--foo') - expect(args[1]).to.equal('-bar') + strictEqual(args[0], '--foo') + strictEqual(args[1], '-bar') }) })