-
Notifications
You must be signed in to change notification settings - Fork 16
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
fix: deletes singular CL when from CLs when specified #381
Conversation
…sponses for multiple CL
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.
that's a nice test
src/sourceTracking.ts
Outdated
* @param filename - a path to a custom labels file | ||
* @param customLabels - an array of SourceComponents representing the custom labels to delete | ||
*/ | ||
public static async deleteCustomLabels(filename: string, customLabels: SourceComponent[]): Promise<void> { |
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.
if it's not using anything from the class, it could be a standalone function, top-level exported if needed by the plugins.
src/sourceTracking.ts
Outdated
} else { | ||
// in theory, we should only have custom labels passed in, but filter just to make sure | ||
const customLabelsToDelete = customLabels | ||
.filter((label) => label.type.id === 'customlabel') |
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.
I'd put this up at the top of the function. You could filter/warn/throw even before parsing the file if you got something unexpected
src/sourceTracking.ts
Outdated
ignoreAttributes: false, | ||
attributeNamePrefix: '@_', | ||
}); | ||
const cls = parser.parse(fs.readFileSync(filename, 'utf8')) as { |
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.
alternatively, there's kit/ensureArray
so you can have fewer conditionals. If you filtered the array and it ends up empty, you've got a check below for that to delete the file.
test/unit/sourceTracking.test.ts
Outdated
import * as sinon from 'sinon'; | ||
import { SourceComponent } from '@salesforce/source-deploy-retrieve'; | ||
import { expect } from 'chai'; | ||
import { SourceTracking } from '../../src'; |
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.
can you import it from the file instead of the parent folder?
src/shared/functions.ts
Outdated
* @param filename - a path to a custom labels file | ||
* @param customLabels - an array of SourceComponents representing the custom labels to delete | ||
*/ | ||
export const deleteCustomLabels = (filename: string, customLabels: SourceComponent[]): Promise<void> => { |
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.
Can it return some sort of results structure?
Like maybe it returns a Promise of either the file contents as JSON or undefined (if it was deleted), inside an object for potential future expansion? like, {fileContents?: cls }
you'd still need the writeStub in your test, but you could assert from the function response?
…-tracking into wr/deleteCustomLabels
* refactor: return file as object for consumers and tests * chore: dedupe pjson
What does this PR do?
this will parse the CLs file and delete an individual CL when a delete is encountered with source tracking commands
identical to what's here for
source delete
salesforcecli/plugin-deploy-retrieve#613What issues does this PR fix or reference?
@W-13167950@
tests: salesforcecli/plugin-source#839