-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: make project optional #771
Changes from 6 commits
4d7980f
ad7d8a7
5629581
19a8750
3b17032
7837ada
5faf172
726e04b
d834e2f
caafdc6
7a47bed
35d77b4
81af695
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ import { Flags, loglevel, orgApiVersionFlagWithDeprecations, SfCommand } from '@ | |
import { Messages } from '@salesforce/core/messages'; | ||
import { Package, PackageSaveResult } from '@salesforce/packaging'; | ||
import { requiredHubFlag } from '../../utils/hubFlag.js'; | ||
import { maybeGetProject } from '../../utils/getProject.js'; | ||
|
||
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url); | ||
const messages = Messages.loadMessages('@salesforce/plugin-packaging', 'package_update'); | ||
|
@@ -20,7 +21,6 @@ export class PackageUpdateCommand extends SfCommand<PackageSaveResult> { | |
public static readonly examples = messages.getMessages('examples'); | ||
public static readonly deprecateAliases = true; | ||
public static readonly aliases = ['force:package:update']; | ||
public static readonly requiresProject = true; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same (I'd expect it to update the packageDirectories description/etc with my changes) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mshanemc - I tested something similar with I updated the |
||
public static readonly flags = { | ||
loglevel, | ||
'target-dev-hub': requiredHubFlag, | ||
|
@@ -54,10 +54,11 @@ export class PackageUpdateCommand extends SfCommand<PackageSaveResult> { | |
|
||
public async run(): Promise<PackageSaveResult> { | ||
const { flags } = await this.parse(PackageUpdateCommand); | ||
|
||
const pkg = new Package({ | ||
packageAliasOrId: flags.package, | ||
connection: flags['target-dev-hub'].getConnection(flags['api-version']), | ||
project: this.project!, | ||
project: await maybeGetProject(), | ||
}); | ||
|
||
const result = await pkg.update({ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ import { Flags, loglevel, orgApiVersionFlagWithDeprecations, SfCommand } from '@ | |
import { Messages } from '@salesforce/core/messages'; | ||
import { PackageSaveResult, PackageVersion } from '@salesforce/packaging'; | ||
import { requiredHubFlag } from '../../../utils/hubFlag.js'; | ||
import { maybeGetProject } from '../../../utils/getProject.js'; | ||
|
||
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url); | ||
const messages = Messages.loadMessages('@salesforce/plugin-packaging', 'package_version_delete'); | ||
|
@@ -19,7 +20,6 @@ export class PackageVersionDeleteCommand extends SfCommand<PackageSaveResult> { | |
public static readonly examples = messages.getMessages('examples'); | ||
public static readonly deprecateAliases = true; | ||
public static readonly aliases = ['force:package:version:delete']; | ||
public static readonly requiresProject = true; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmm...[unrelated to this PR] I would have expected the delete command to remove the packageVersion from my project. I guess it never has (and this was that whole "delete doesn't really delete, just deprecates" so maybe that's correct?) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so maybe that should happen if there's a project, but it's not required? |
||
public static readonly flags = { | ||
loglevel, | ||
'target-dev-hub': requiredHubFlag, | ||
|
@@ -45,7 +45,7 @@ export class PackageVersionDeleteCommand extends SfCommand<PackageSaveResult> { | |
const { flags } = await this.parse(PackageVersionDeleteCommand); | ||
const packageVersion = new PackageVersion({ | ||
connection: flags['target-dev-hub'].getConnection(flags['api-version']), | ||
project: this.project!, | ||
project: await maybeGetProject(), | ||
idOrAlias: flags.package, | ||
}); | ||
await this.confirmDelete(flags['no-prompt'], flags.undelete); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
*/ | ||
|
||
import { Flags, loglevel, orgApiVersionFlagWithDeprecations, SfCommand, Ux } from '@salesforce/sf-plugins-core'; | ||
import { Messages, SfProject } from '@salesforce/core'; | ||
import { Messages } from '@salesforce/core'; | ||
import { | ||
getContainerOptions, | ||
getPackageVersionStrings, | ||
|
@@ -15,6 +15,7 @@ import { | |
PackageVersionListResult, | ||
} from '@salesforce/packaging'; | ||
import { requiredHubFlag } from '../../../utils/hubFlag.js'; | ||
import { maybeGetProject } from '../../../utils/getProject.js'; | ||
|
||
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url); | ||
const messages = Messages.loadMessages('@salesforce/plugin-packaging', 'package_version_list'); | ||
|
@@ -105,7 +106,7 @@ export class PackageVersionListCommand extends SfCommand<PackageVersionListComma | |
public async run(): Promise<PackageVersionListCommandResult> { | ||
const { flags } = await this.parse(PackageVersionListCommand); | ||
const connection = flags['target-dev-hub'].getConnection(flags['api-version']); | ||
const project = SfProject.getInstance(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this command didn't have |
||
const project = await maybeGetProject(); | ||
|
||
const records = await Package.listVersions(connection, project, { | ||
createdLastDays: flags['created-last-days'], | ||
|
@@ -135,7 +136,7 @@ export class PackageVersionListCommand extends SfCommand<PackageVersionListComma | |
|
||
records.forEach((record) => { | ||
const ids = [record.Id, record.SubscriberPackageVersionId]; | ||
const aliases = ids.map((id) => project.getAliasesFromPackageId(id)).flat(); | ||
const aliases = ids.map((id) => (project ? project.getAliasesFromPackageId(id) : id)).flat(); | ||
cristiand391 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const AliasStr = aliases.length > 0 ? aliases.join() : ''; | ||
|
||
// set Ancestor display values | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* Copyright (c) 2022, salesforce.com, inc. | ||
* All rights reserved. | ||
* Licensed under the BSD 3-Clause license. | ||
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
|
||
import { SfProject } from '@salesforce/core'; | ||
|
||
/* | ||
* Get the sfdx project from the current dir. | ||
* It will return `undefined` if there's no project. | ||
* */ | ||
export async function maybeGetProject(): Promise<SfProject | undefined> { | ||
try { | ||
return await SfProject.resolve(); | ||
} catch (err) { | ||
if (err instanceof Error && err.name === 'InvalidProjectWorkspaceError') { | ||
return undefined; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. any swallow all other errors? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
none, I think I was just following the error msg from |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,36 +15,46 @@ import { env } from '@salesforce/kit'; | |
import { PackageVersionCreateCommand } from '../../../src/commands/package/version/create.js'; | ||
import Package2VersionStatus = PackagingSObjects.Package2VersionStatus; | ||
|
||
const pkgVersionCreateErrorResult: Partial<PackageVersionCreateRequestResult> = { | ||
const pkgVersionCreateErrorResult: PackageVersionCreateRequestResult = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this type changed here: |
||
Id: '08c3i000000fylXXXX', | ||
Status: Package2VersionStatus.error, | ||
Package2Id: '0Ho3i000000TNHXXXX', | ||
Package2VersionId: undefined, | ||
SubscriberPackageVersionId: undefined, | ||
Tag: undefined, | ||
Branch: undefined, | ||
Package2VersionId: '', | ||
SubscriberPackageVersionId: '', | ||
Tag: '', | ||
Branch: '', | ||
Error: [ | ||
'PropertyController: Invalid type: Schema.Property__c', | ||
'SampleDataController: Invalid type: Schema.Property__c', | ||
'SampleDataController: Invalid type: Schema.Broker__c', | ||
], | ||
CreatedDate: '2022-11-03 09:21', | ||
HasMetadataRemoved: undefined, | ||
HasMetadataRemoved: null, | ||
CreatedBy: '0053i000001ZIyXXXX', | ||
Package2Name: null, | ||
HasPassedCodeCoverageCheck: null, | ||
CodeCoverage: null, | ||
VersionNumber: null, | ||
ConvertedFromVersionId: null, | ||
}; | ||
|
||
const pkgVersionCreateSuccessResult: Partial<PackageVersionCreateRequestResult> = { | ||
const pkgVersionCreateSuccessResult: PackageVersionCreateRequestResult = { | ||
Id: '08c3i000000fylgAAA', | ||
Status: Package2VersionStatus.success, | ||
Package2Id: '0Ho3i000000TNHYCA4', | ||
Package2VersionId: '05i3i000000fxw1AAA', | ||
SubscriberPackageVersionId: '04t3i000002eya2AAA', | ||
Tag: undefined, | ||
Branch: undefined, | ||
Tag: '', | ||
Branch: '', | ||
Error: [], | ||
CreatedDate: '2022-11-03 09:46', | ||
HasMetadataRemoved: false, | ||
CreatedBy: '0053i000001ZIyGAAW', | ||
Package2Name: null, | ||
HasPassedCodeCoverageCheck: null, | ||
CodeCoverage: null, | ||
VersionNumber: null, | ||
ConvertedFromVersionId: null, | ||
}; | ||
|
||
describe('package:version:create - tests', () => { | ||
|
@@ -84,7 +94,7 @@ describe('package:version:create - tests', () => { | |
const res = await cmd.run(); | ||
expect(envSpy.calledOnce).to.equal(true); | ||
expect(res).to.deep.equal({ | ||
Branch: undefined, | ||
Branch: '', | ||
CreatedBy: '0053i000001ZIyGAAW', | ||
CreatedDate: '2022-11-03 09:46', | ||
Error: [], | ||
|
@@ -94,7 +104,12 @@ describe('package:version:create - tests', () => { | |
Package2VersionId: '05i3i000000fxw1AAA', | ||
Status: 'Success', | ||
SubscriberPackageVersionId: '04t3i000002eya2AAA', | ||
Tag: undefined, | ||
Tag: '', | ||
Package2Name: null, | ||
HasPassedCodeCoverageCheck: null, | ||
CodeCoverage: null, | ||
VersionNumber: null, | ||
ConvertedFromVersionId: null, | ||
}); | ||
expect(logStub.callCount).to.equal(1); | ||
expect(logStub.args[0]).to.deep.equal([ | ||
|
@@ -115,7 +130,7 @@ describe('package:version:create - tests', () => { | |
const res = await cmd.run(); | ||
expect(envSpy.calledOnce).to.equal(true); | ||
expect(res).to.deep.equal({ | ||
Branch: undefined, | ||
Branch: '', | ||
CreatedBy: '0053i000001ZIyGAAW', | ||
CreatedDate: '2022-11-03 09:46', | ||
Error: [], | ||
|
@@ -125,7 +140,12 @@ describe('package:version:create - tests', () => { | |
Package2VersionId: '05i3i000000fxw1AAA', | ||
Status: 'Success', | ||
SubscriberPackageVersionId: '04t3i000002eya2AAA', | ||
Tag: undefined, | ||
Tag: '', | ||
Package2Name: null, | ||
HasPassedCodeCoverageCheck: null, | ||
CodeCoverage: null, | ||
VersionNumber: null, | ||
ConvertedFromVersionId: null, | ||
}); | ||
expect(logStub.callCount).to.equal(1); | ||
expect(logStub.args[0]).to.deep.equal([ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also would have expected this to modify sfdx-project after deleting the pkg