Skip to content

Commit bf266d8

Browse files
committed
fix: Relative --source-dir paths are handled correctly now
1 parent 6d01415 commit bf266d8

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

src/program.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,13 @@ export class Program {
7878
(resolve) => {
7979
this.yargs.exitProcess(this.shouldExitProgram);
8080
argv = this.yargs.argv;
81+
82+
// Fix up sourceDir. This can hopefully move to option configuration
83+
// soon. See https://github.com/yargs/yargs/issues/535
84+
if (argv.sourceDir) {
85+
argv.sourceDir = path.resolve(argv.sourceDir);
86+
}
87+
8188
cmd = argv._[0];
8289
if (cmd === undefined) {
8390
throw new WebExtError('No sub-command was specified in the args');
@@ -147,13 +154,15 @@ Example: $0 --help run.
147154
alias: 's',
148155
describe: 'Web extension source directory.',
149156
default: process.cwd(),
157+
normalize: true,
150158
requiresArg: true,
151159
type: 'string',
152160
},
153161
'artifacts-dir': {
154162
alias: 'a',
155163
describe: 'Directory where artifacts will be saved.',
156164
default: path.join(process.cwd(), 'web-ext-artifacts'),
165+
normalize: true,
157166
requiresArg: true,
158167
type: 'string',
159168
},

tests/test.program.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,34 @@ describe('program.main', () => {
269269
});
270270
});
271271

272+
it('turns sourceDir into an absolute path', () => {
273+
const fakeCommands = fake(commands, {
274+
build: () => Promise.resolve(),
275+
});
276+
return run(
277+
['build', '--source-dir', '..'], {commands: fakeCommands})
278+
.then(() => {
279+
assert.equal(fakeCommands.build.called, true);
280+
assert.equal(fakeCommands.build.firstCall.args[0].sourceDir,
281+
path.resolve(path.join(process.cwd(), '..')));
282+
});
283+
});
284+
285+
it('normalizes the artifactsDir path', () => {
286+
const fakeCommands = fake(commands, {
287+
build: () => Promise.resolve(),
288+
});
289+
return run(
290+
// Add a double slash to the path, which will be fixed by normalization.
291+
['build', '--artifacts-dir', process.cwd() + path.sep + path.sep],
292+
{commands: fakeCommands})
293+
.then(() => {
294+
assert.equal(fakeCommands.build.called, true);
295+
assert.equal(fakeCommands.build.firstCall.args[0].artifactsDir,
296+
process.cwd() + path.sep);
297+
});
298+
});
299+
272300
});
273301

274302

0 commit comments

Comments
 (0)