Skip to content

Commit 17fce00

Browse files
committed
feat: fail fast logic for convert commands not run in project dir
1 parent a9c21eb commit 17fce00

2 files changed

Lines changed: 7 additions & 8 deletions

File tree

src/commands/package/convert.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export class PackageConvert extends SfCommand<PackageVersionCreateRequestResult>
3737
public static readonly examples = messages.getMessages('examples');
3838
public static readonly deprecateAliases = true;
3939
public static readonly aliases = ['force:package:convert'];
40+
public static readonly requiresProject = true;
4041
public static readonly flags = {
4142
loglevel,
4243
'target-dev-hub': requiredHubFlag,
@@ -128,13 +129,7 @@ export class PackageConvert extends SfCommand<PackageVersionCreateRequestResult>
128129
} else {
129130
this.spinner.start('Converting Package', 'Initializing');
130131
}
131-
// initialize the project instance if in a project
132-
let project: SfProject | undefined;
133-
try {
134-
project = await SfProject.resolve();
135-
} catch (err) {
136-
// ignore project is optional
137-
}
132+
138133
const result = await Package.convert(
139134
flags.package,
140135
flags['target-dev-hub'].getConnection(flags['api-version']),
@@ -148,7 +143,7 @@ export class PackageConvert extends SfCommand<PackageVersionCreateRequestResult>
148143
patchversion: flags['patch-version'] as string,
149144
codecoverage: flags['code-coverage'] as boolean,
150145
},
151-
project
146+
this.project as SfProject
152147
);
153148

154149
switch (result.Status) {

test/commands/package/packageConvert.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ describe('package:convert', () => {
5252
$$.restore();
5353
});
5454

55+
it('should require an sfdx project', () => {
56+
expect(PackageConvert.requiresProject).to.be.true;
57+
});
58+
5559
it('returns error for missing installationkey or installationkeybypass flag', async () => {
5660
const expectedErrorMsg =
5761
'Exactly one of the following must be provided: --installation-key, --installation-key-bypass';

0 commit comments

Comments
 (0)