Skip to content
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: changes for customLabelsBeta v2 #651

Merged
merged 9 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,21 @@
},
"dependencies": {
"@oclif/core": "^4.0.17",
"@salesforce/core": "^8.2.7",
"@salesforce/kit": "^3.2.0",
"@salesforce/source-deploy-retrieve": "^12.1.11",
"@salesforce/core": "^8.4.0",
"@salesforce/kit": "^3.2.1",
"@salesforce/source-deploy-retrieve": "^12.4.0",
"@salesforce/ts-types": "^2.0.12",
"fast-xml-parser": "^4.4.1",
"graceful-fs": "^4.2.11",
"isomorphic-git": "^1.27.1",
"ts-retry-promise": "^0.8.1"
},
"devDependencies": {
"@salesforce/cli-plugins-testkit": "^5.3.20",
"@salesforce/cli-plugins-testkit": "^5.3.23",
"@salesforce/dev-scripts": "^10.2.9",
"@salesforce/schemas": "^1.9.0",
"@types/graceful-fs": "^4.1.9",
"eslint-plugin-sf-plugin": "^1.20.1",
"eslint-plugin-sf-plugin": "^1.20.3",
"ts-node": "^10.9.2",
"ts-patch": "^3.2.1",
"typescript": "^5.5.4"
Expand Down
68 changes: 35 additions & 33 deletions src/shared/metadataKeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/
import { basename, dirname, join, normalize, sep } from 'node:path';
import { ComponentSet, RegistryAccess } from '@salesforce/source-deploy-retrieve';
import { Lifecycle } from '@salesforce/core';
import { Lifecycle } from '@salesforce/core/lifecycle';
import { RemoteSyncInput } from './types';
import { getMetadataKey } from './functions';

Expand All @@ -20,13 +20,13 @@ const pathAfterFullName = (fileResponse: RemoteSyncInput): string =>
).replace(/\\/gi, '/')
: '';

const registry = new RegistryAccess();
const registryAccess = new RegistryAccess();

// only compute once
const aliasTypes: Array<[string, string]> = registry
const aliasTypes: Array<[string, string]> = registryAccess
.getAliasTypes()
// allow assertion because aliasTypes are defined as having that property
.map((aliasType) => [aliasType.name, registry.getTypeByName(aliasType.aliasFor!).name]);
.map((aliasType) => [aliasType.name, registryAccess.getTypeByName(aliasType.aliasFor!).name]);

const reverseAliasTypes = new Map(aliasTypes.map(([alias, type]) => [type, alias]));

Expand Down Expand Up @@ -79,32 +79,34 @@ export const mappingsForSourceMemberTypesToMetadataType = new Map<string, string
['LightningComponentResource', 'LightningComponentBundle'],
]);

export const registrySupportsType = (type: string): boolean => {
if (mappingsForSourceMemberTypesToMetadataType.has(type)) {
return true;
}
if (type === 'PicklistValue') {
/* "PicklistValue" appears occasionally in sourceMembers, but it's not a real, addressable type in the registry
* It only appears when a picklist value is reactivated, so I'd call this a SourceMember bug
* We also can't make it a child type in the SDR registry because it it can be a parent of either CustomField/Picklist OR GlobalValueSet
* in both parent cases (GVS and CustomField), the the parent is marked as changed in SourceMembers, to the behavior is ok igoring the PicklistValue
* This suppresses the warning, and could be removed if the SourceMember bug is fixed
*/
return false;
}
if (type === 'ExperienceResource') {
/* ExperienceResource is a child of ExperienceBundle but fine-grained source tracking isn't supported for
* ExperienceBundle since it's not defined that way in the SDR registry. Since ExperienceBundle is
* essentially deprecated in favor of DigitalExperienceBundle this is not something we're going to support.
*/
return false;
}
try {
// this must use getTypeByName because findType doesn't support addressable child types (ex: customField!)
registry.getTypeByName(type);
return true;
} catch (e) {
void Lifecycle.getInstance().emitWarning(`Unable to find type ${type} in registry`);
return false;
}
};
export const registrySupportsType =
(registry: RegistryAccess = new RegistryAccess()) =>
(type: string): boolean => {
if (mappingsForSourceMemberTypesToMetadataType.has(type)) {
return true;
}
if (type === 'PicklistValue') {
/* "PicklistValue" appears occasionally in sourceMembers, but it's not a real, addressable type in the registry
* It only appears when a picklist value is reactivated, so I'd call this a SourceMember bug
* We also can't make it a child type in the SDR registry because it it can be a parent of either CustomField/Picklist OR GlobalValueSet
* in both parent cases (GVS and CustomField), the the parent is marked as changed in SourceMembers, to the behavior is ok igoring the PicklistValue
* This suppresses the warning, and could be removed if the SourceMember bug is fixed
*/
return false;
}
if (type === 'ExperienceResource') {
/* ExperienceResource is a child of ExperienceBundle but fine-grained source tracking isn't supported for
* ExperienceBundle since it's not defined that way in the SDR registry. Since ExperienceBundle is
* essentially deprecated in favor of DigitalExperienceBundle this is not something we're going to support.
*/
return false;
}
try {
// this must use getTypeByName because findType doesn't support addressable child types (ex: customField!)
registry.getTypeByName(type);
return true;
} catch (e) {
void Lifecycle.getInstance().emitWarning(`Unable to find type ${type} in registry`);
return false;
}
};
2 changes: 1 addition & 1 deletion src/shared/populateFilePaths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import { EOL } from 'node:os';
import { Logger } from '@salesforce/core';
import { Logger } from '@salesforce/core/logger';
import { ComponentSet, RegistryAccess } from '@salesforce/source-deploy-retrieve';
import { ChangeResult } from './types';
import { isChangeResultWithNameAndType } from './guards';
Expand Down
2 changes: 1 addition & 1 deletion src/shared/populateTypesAndNames.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* 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 { Logger } from '@salesforce/core';
import { Logger } from '@salesforce/core/logger';
import { isString } from '@salesforce/ts-types';
import {
MetadataResolver,
Expand Down
2 changes: 1 addition & 1 deletion src/shared/remoteChangeIgnoring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import { ForceIgnore, MetadataComponent, MetadataMember, RegistryAccess } from '@salesforce/source-deploy-retrieve';
import { SfError } from '@salesforce/core';
import { SfError } from '@salesforce/core/sfError';
import { filePathsFromMetadataComponent } from '@salesforce/source-deploy-retrieve/lib/src/utils/filePathGenerator';
import { ChangeResult } from './types';
import { isChangeResultWithNameAndType } from './guards';
Expand Down
4 changes: 2 additions & 2 deletions src/shared/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { FileResponse, SourceComponent } from '@salesforce/source-deploy-retrieve';
import { SfError } from '@salesforce/core';
import { SfError } from '@salesforce/core/sfError';

export type ChangeOptions = {
origin: 'local' | 'remote';
Expand Down Expand Up @@ -69,7 +69,7 @@ export type ConflictResponse = {
// there will be a data property of type ConflictResponse[]
export type SourceConflictErrorType = {
name: 'SourceConflictError';
} & SfError<ConflictResponse[]>
} & SfError<ConflictResponse[]>;

export class SourceConflictError extends SfError<ConflictResponse[]> implements SourceConflictErrorType {
public readonly name: SourceConflictErrorType['name'];
Expand Down
7 changes: 5 additions & 2 deletions src/sourceTracking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ export class SourceTracking extends AsyncCreatable {
const filteredChanges = remoteChanges
.filter(remoteFilterByState[options.state])
// skip any remote types not in the registry. Will emit warnings
.filter((rce) => registrySupportsType(rce.type));
.filter((rce) => registrySupportsType(this.registry)(rce.type));
if (options.format === 'ChangeResult') {
return filteredChanges.map(remoteChangeElementToChangeResult);
}
Expand Down Expand Up @@ -401,11 +401,14 @@ export class SourceTracking extends AsyncCreatable {
)
);

// original CustomLabels behavior
const nonDecomposedLabels = this.registry.getTypeByName('customlabel').strategies?.transformer === 'nonDecomposed';

const filenames = Array.from(sourceComponentByFileName.keys());
// delete the files
await Promise.all(
filenames.map((filename) =>
sourceComponentByFileName.get(filename)?.type.id === 'customlabel'
sourceComponentByFileName.get(filename)?.type.id === 'customlabel' && nonDecomposedLabels
? deleteCustomLabels(filename, changesToDelete.filter(sourceComponentIsCustomLabel))
: fs.promises.unlink(filename)
)
Expand Down
10 changes: 5 additions & 5 deletions test/unit/metadataKeys.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,12 @@ describe('metadataKeys', () => {

describe('registrySupportsType', () => {
it('custom mapped types', () => {
expect(registrySupportsType('AuraDefinition')).to.equal(true);
expect(registrySupportsType('LightningComponentResource')).to.equal(true);
expect(registrySupportsType()('AuraDefinition')).to.equal(true);
expect(registrySupportsType()('LightningComponentResource')).to.equal(true);
});
it('other real types types', () => {
expect(registrySupportsType('CustomObject')).to.equal(true);
expect(registrySupportsType('ApexClass')).to.equal(true);
expect(registrySupportsType()('CustomObject')).to.equal(true);
expect(registrySupportsType()('ApexClass')).to.equal(true);
});
it('bad type returns false and emits warning', async () => {
const warningEmitted: string[] = [];
Expand All @@ -124,7 +124,7 @@ describe('registrySupportsType', () => {
warningEmitted.push(w);
return Promise.resolve();
});
expect(registrySupportsType(badType)).to.equal(false);
expect(registrySupportsType()(badType)).to.equal(false);
expect(
warningEmitted.some((w) => w.includes(badType)),
'warning not emitted'
Expand Down
Loading
Loading