Skip to content

Commit 315920c

Browse files
Merge pull request #766 from forcedotcom/t/packaging-distribution/W-19170618/Bug-Fixes
feat: version ovveride
2 parents 4d9b11f + 00a6662 commit 315920c

4 files changed

Lines changed: 71 additions & 4 deletions

File tree

scripts/Icon

Whitespace-only changes.

src/package/packageBundleVersion.ts

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,15 +184,14 @@ export class PackageBundleVersion {
184184
id: string
185185
): Promise<PackagingSObjects.SubscriberPackageVersion[]> {
186186
const query =
187-
'SELECT Component.Id, Component.Name, Component.Description, Component.PublisherName, Component.MajorVersion, Component.MinorVersion, Component.PatchVersion, Component.BuildNumber, Component.ReleaseState, Component.IsManaged, Component.IsDeprecated, Component.IsPasswordProtected, Component.IsBeta, Component.Package2ContainerOptions, Component.IsSecurityReviewed, Component.IsOrgDependent, Component.AppExchangePackageName, Component.AppExchangeDescription, Component.AppExchangePublisherName, Component.AppExchangeLogoUrl, Component.ReleaseNotesUrl, Component.PostInstallUrl, Component.RemoteSiteSettings, Component.CspTrustedSites, Component.Profiles, Component.Dependencies, Component.InstallValidationStatus, Component.SubscriberPackageId ' +
187+
'SELECT Component.Id, Component.Description, Component.PublisherName, Component.MajorVersion, Component.MinorVersion, Component.PatchVersion, Component.BuildNumber, Component.ReleaseState, Component.IsManaged, Component.IsDeprecated, Component.IsPasswordProtected, Component.IsBeta, Component.Package2ContainerOptions, Component.IsSecurityReviewed, Component.IsOrgDependent, Component.AppExchangePackageName, Component.AppExchangeDescription, Component.AppExchangePublisherName, Component.AppExchangeLogoUrl, Component.ReleaseNotesUrl, Component.PostInstallUrl, Component.RemoteSiteSettings, Component.CspTrustedSites, Component.Profiles, Component.Dependencies, Component.InstallValidationStatus, Component.SubscriberPackageId ' +
188188
"FROM PkgBundleVersionComponent WHERE PackageBundleVersion.Id = '" +
189189
id +
190190
"' ORDER BY CreatedDate";
191191
const queryResult = await connection.autoFetchQuery<
192192
Schema & {
193193
Component?: {
194194
Id: string;
195-
Name: string;
196195
Description: string;
197196
PublisherName: string;
198197
MajorVersion: number;
@@ -222,15 +221,58 @@ export class PackageBundleVersion {
222221
};
223222
}
224223
>(query, { tooling: true });
224+
225+
// Get unique SubscriberPackageIds to query for Names
226+
const subscriberPackageIds = [
227+
...new Set(
228+
queryResult.records
229+
.map((record) => record.Component?.SubscriberPackageId)
230+
.filter((packageId): packageId is string => !!packageId)
231+
),
232+
];
233+
234+
// Query SubscriberPackage to get Names (one by one due to implementation restriction)
235+
const subscriberPackageNames = new Map<string, string>();
236+
const packageQueries = subscriberPackageIds.map(async (packageId) => {
237+
try {
238+
const packageQuery = `SELECT Id, Name FROM SubscriberPackage WHERE Id='${packageId}'`;
239+
const packageQueryResult = await connection.autoFetchQuery<
240+
Schema & {
241+
Id: string;
242+
Name: string;
243+
}
244+
>(packageQuery, { tooling: true });
245+
246+
return {
247+
packageId,
248+
name: packageQueryResult.records.length > 0 ? packageQueryResult.records[0].Name : '',
249+
};
250+
} catch (error) {
251+
// If individual query fails, return empty name for this package
252+
return {
253+
packageId,
254+
name: '',
255+
};
256+
}
257+
});
258+
259+
const packageResults = await Promise.allSettled(packageQueries);
260+
packageResults.forEach((result) => {
261+
if (result.status === 'fulfilled') {
262+
subscriberPackageNames.set(result.value.packageId, result.value.name);
263+
}
264+
});
265+
225266
return queryResult.records.map((record) => {
226267
const component = record.Component;
227268
if (!component) {
228269
throw new Error(bundleVersionMessages.getMessage('componentRecordMissing'));
229270
}
271+
const packageName = subscriberPackageNames.get(component.SubscriberPackageId) ?? '';
230272
return {
231273
Id: component.Id,
232274
SubscriberPackageId: component.SubscriberPackageId,
233-
Name: component.Name,
275+
Name: packageName,
234276
Description: component.Description,
235277
PublisherName: component.PublisherName,
236278
MajorVersion: component.MajorVersion,

src/package/packageBundleVersionCreate.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,12 @@ export class PackageBundleVersionCreate {
7575
project
7676
);
7777
const packageBundleId = PackageBundleVersionCreate.parsePackageBundleId(options.PackageBundle, project);
78-
const version = await PackageBundleVersionCreate.getPackageVersion(options, project, connection);
78+
79+
// Use provided MajorVersion and MinorVersion if they are not empty strings, otherwise get from bundle configuration
80+
const version =
81+
options.MajorVersion && options.MinorVersion
82+
? { MajorVersion: options.MajorVersion, MinorVersion: options.MinorVersion }
83+
: await PackageBundleVersionCreate.getPackageVersion(options, project, connection);
7984

8085
const request: BundleSObjects.PkgBundleVersionCreateReq = {
8186
PackageBundleId: packageBundleId,

test/package/bundleVersionReport.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,26 @@ describe('PackageBundleVersion', () => {
355355
totalSize: 2,
356356
records: mockComponentPackages,
357357
});
358+
} else if (
359+
request &&
360+
ensureString(requestMap.url).includes('SubscriberPackage') &&
361+
ensureString(requestMap.url).includes('0330000000000001')
362+
) {
363+
return Promise.resolve({
364+
done: true,
365+
totalSize: 1,
366+
records: [{ Id: '0330000000000001', Name: 'Test Package 1' }],
367+
});
368+
} else if (
369+
request &&
370+
ensureString(requestMap.url).includes('SubscriberPackage') &&
371+
ensureString(requestMap.url).includes('0330000000000002')
372+
) {
373+
return Promise.resolve({
374+
done: true,
375+
totalSize: 1,
376+
records: [{ Id: '0330000000000002', Name: 'Test Package 2' }],
377+
});
358378
} else {
359379
return Promise.reject(new SfError(`Unexpected request: ${String(requestMap.url)}`));
360380
}

0 commit comments

Comments
 (0)