Skip to content

Commit 4c6e168

Browse files
committed
fix: tf fix
1 parent 9437504 commit 4c6e168

2 files changed

Lines changed: 13 additions & 21 deletions

File tree

src/commands/package/install.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {
2121
requiredOrgFlagWithDeprecations,
2222
SfCommand,
2323
} from '@salesforce/sf-plugins-core';
24-
import { Connection, Lifecycle, Messages, SfError } from '@salesforce/core';
24+
import { Connection, Lifecycle, Messages, SfError, SfProject } from '@salesforce/core';
2525
import { Duration } from '@salesforce/kit';
2626
import {
2727
PackageEvents,
@@ -135,9 +135,17 @@ export class Install extends SfCommand<PackageInstallRequest> {
135135
throw messages.createError('apiVersionTooLow');
136136
}
137137

138+
let packageId = flags.package;
139+
try {
140+
const project = SfProject.getInstance();
141+
packageId = project.getPackageIdFromAlias(flags.package) ?? flags.package;
142+
} catch {
143+
// not in a project directory; use the value as-is
144+
}
145+
138146
this.subscriberPackageVersion = new SubscriberPackageVersion({
139147
connection: this.connection,
140-
aliasOrId: flags.package,
148+
aliasOrId: packageId,
141149
password: flags['installation-key'],
142150
});
143151

test/commands/package/install.test.ts

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616
import { EOL } from 'node:os';
17-
import { Connection, Lifecycle, SfProject, SfError, SfProjectJson } from '@salesforce/core';
17+
import { Connection, Lifecycle, SfProject, SfError } from '@salesforce/core';
1818
import { MockTestOrgData, TestContext } from '@salesforce/core/testSetup';
1919
import { Config } from '@oclif/core';
2020
import { expect } from 'chai';
@@ -283,27 +283,11 @@ describe('package:install', () => {
283283
}
284284
});
285285

286-
// TODO: It seems that while linking @salesforce/packaging into the plugin
287-
// we cannot stub the library calls of `SfProject.getInstance` e.g. "SfProject, 'getInstance'"
288-
// once the library has been published, the stubs resume to work and this test will pass
289286
it('should print SUCCESS status correctly for package alias', async () => {
290-
// Stubs SfProject.getInstance, SfProject.getSfProjectJson, and SfProjectJson.getContents
291-
// in a way that makes TS happy... all to test package aliases.
292-
const getContentsStub = $$.SANDBOX.stub(SfProjectJson.prototype, 'getContents').returns({
293-
packageAliases: { ['my_package_alias']: myPackageVersion04t },
294-
packageDirectories: [],
295-
});
296-
// @ts-expect-error stubbing only 1 method
297-
const getSfProjectJsonStub = $$.SANDBOX.stub(SfProject.prototype, 'getSfProjectJson').callsFake(() => ({
298-
getContents: getContentsStub,
299-
}));
300-
const getPackageIdFromAliasStub = $$.SANDBOX.stub(SfProject.prototype, 'getPackageIdFromAlias').returns(
301-
myPackageVersion04t
302-
);
287+
$$.SANDBOX.stub(SfProject.prototype, 'getPackageIdFromAlias').returns(myPackageVersion04t);
303288
// @ts-expect-error stubbing only a subset of methods
304289
$$.SANDBOX.stub(SfProject, 'getInstance').callsFake(() => ({
305-
getSfProjectJson: getSfProjectJsonStub,
306-
getPackageIdFromAlias: getPackageIdFromAliasStub,
290+
getPackageIdFromAlias: $$.SANDBOX.stub().returns(myPackageVersion04t),
307291
}));
308292

309293
const request = Object.assign({}, pkgInstallRequest, { Status: 'SUCCESS' });

0 commit comments

Comments
 (0)