Skip to content

Commit 244aeb3

Browse files
authored
fix: Resolve input sourceDir to absolute path (#3024)
Fixes #2993
1 parent f4ac2d9 commit 244aeb3

File tree

4 files changed

+19
-14
lines changed

4 files changed

+19
-14
lines changed

src/cmd/run.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import path from 'path';
2+
13
import { fs } from 'mz';
24

35
import defaultBuildExtension from './build.js';
@@ -60,6 +62,7 @@ export default async function run(
6062
getValidatedManifest = defaultGetValidatedManifest,
6163
} = {},
6264
) {
65+
sourceDir = path.resolve(sourceDir);
6366
log.info(`Running web extension from ${sourceDir}`);
6467
if (preInstall) {
6568
log.info(

src/program.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ Example: $0 --help run.
417417
default: process.cwd(),
418418
requiresArg: true,
419419
type: 'string',
420-
coerce: (arg) => (arg != null ? path.resolve(arg) : undefined),
420+
coerce: (arg) => arg ?? undefined,
421421
},
422422
'artifacts-dir': {
423423
alias: 'a',

tests/unit/test-cmd/test.run.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,21 @@ describe('run', () => {
128128
});
129129
});
130130

131+
it('turns sourceDir into an absolute path', async () => {
132+
const getFakeManifest = sinon.spy();
133+
const cmd = await prepareRun();
134+
135+
await cmd.run(
136+
{ sourceDir: '.' },
137+
{ getValidatedManifest: getFakeManifest },
138+
);
139+
140+
sinon.assert.calledOnce(desktopRunnerStub);
141+
const runnerParams = desktopRunnerStub.firstCall.args[0];
142+
const [{ sourceDir: expectedSourceDir }] = runnerParams.extensions;
143+
assert.equal(expectedSourceDir, process.cwd());
144+
});
145+
131146
it('passes the expected parameters to the extension runner', async () => {
132147
const cmd = await prepareRun();
133148
const runOptions = {

tests/unit/test.program.js

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -481,19 +481,6 @@ describe('program.main', () => {
481481
sinon.assert.calledWith(fakeVersionGetter, projectRoot);
482482
});
483483

484-
it('turns sourceDir into an absolute path', () => {
485-
const fakeCommands = fake(commands, {
486-
build: () => Promise.resolve(),
487-
});
488-
return execProgram(['build', '--source-dir', '..'], {
489-
commands: fakeCommands,
490-
}).then(() => {
491-
sinon.assert.calledWithMatch(fakeCommands.build, {
492-
sourceDir: path.resolve(path.join(process.cwd(), '..')),
493-
});
494-
});
495-
});
496-
497484
it('normalizes the artifactsDir path', () => {
498485
const fakeCommands = fake(commands, {
499486
build: () => Promise.resolve(),

0 commit comments

Comments
 (0)