Skip to content

Commit 3a40a78

Browse files
authored
fix: addDirectory do not support absolute command dir (#2465)
1 parent 90e9eca commit 3a40a78

2 files changed

Lines changed: 24 additions & 2 deletions

File tree

‎lib/command.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export class CommandInstance {
6161
): void {
6262
opts = opts || {};
6363
this.requireCache.add(callerFile);
64-
const fullDirPath = this.shim.path.join(
64+
const fullDirPath = this.shim.path.resolve(
6565
this.shim.path.dirname(callerFile),
6666
dir
6767
);

‎test/command.mjs‎

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import * as assert from 'assert';
55
import yargs from '../index.mjs';
66
import {expect, should} from 'chai';
77
import {checkOutput} from './helpers/utils.mjs';
8-
import {join} from 'node:path';
8+
import {join, resolve} from 'node:path';
99

1010
should();
1111

@@ -2185,6 +2185,28 @@ describe('Command', () => {
21852185
});
21862186

21872187
describe('commandDir', () => {
2188+
it('supports absolute dirs', () => {
2189+
const absoluteDir = resolve('test/fixtures/cmddir');
2190+
const r = checkOutput(() => {
2191+
yargs('--help').wrap(null).commandDir(absoluteDir).parse();
2192+
});
2193+
r.exit.should.equal(true);
2194+
r.exitCode.should.equal(0);
2195+
r.errors.length.should.equal(0);
2196+
r.should.have.property('logs');
2197+
r.logs
2198+
.join('\n')
2199+
.split(/\n+/)
2200+
.should.deep.equal([
2201+
'usage [command]',
2202+
'Commands:',
2203+
' usage dream [command] [opts] Go to sleep and dream',
2204+
'Options:',
2205+
' --help Show help [boolean]',
2206+
' --version Show version number [boolean]',
2207+
]);
2208+
});
2209+
21882210
it('supports relative dirs', () => {
21892211
const r = checkOutput(() =>
21902212
yargs('--help').wrap(null).commandDir('fixtures/cmddir').parse()

0 commit comments

Comments
 (0)