Skip to content

Commit

Permalink
feat: custom registry support
Browse files Browse the repository at this point in the history
  • Loading branch information
mshanemc committed Mar 25, 2024
1 parent 164cca6 commit b0f2f35
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 30 deletions.
26 changes: 9 additions & 17 deletions src/shared/conflicts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,24 +65,16 @@ export const getDedupedConflictsFromChanges = ({
remoteChanges.flatMap((change) => (change.filenames ?? []).map((filename) => [filename, change]))
);

const conflicts = new Set<ChangeResult>();

populateTypesAndNames({ excludeUnresolvable: true, projectPath, forceIgnore, registry })(localChanges)
return populateTypesAndNames({ excludeUnresolvable: true, projectPath, forceIgnore, registry })(localChanges)
.filter(isChangeResultWithNameAndType)
.map((change) => {
.flatMap((change) => {
const metadataKey = getMetadataKey(change.name, change.type);
// option 1: name and type match
if (metadataKeyIndex.has(metadataKey)) {
conflicts.add({ ...(metadataKeyIndex.get(metadataKey) as ChangeResult) });
} else {
// option 2: some of the filenames match
change.filenames?.map((filename) => {
if (fileNameIndex.has(filename)) {
conflicts.add({ ...(fileNameIndex.get(filename) as ChangeResult) });
}
});
}
return metadataKeyIndex.has(metadataKey)
? // option 1: name and type match
[metadataKeyIndex.get(metadataKey)!]
: // option 2: some of the filenames match
(change.filenames ?? [])
.filter((filename) => fileNameIndex.has(filename))
.map((filename) => fileNameIndex.get(filename)!);
});
// deeply de-dupe
return Array.from(conflicts);
};
2 changes: 2 additions & 0 deletions src/shared/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ export const sourceComponentHasFullNameAndType = (input: SourceComponent): boole
typeof input.fullName === 'string' && typeof input.type.name === 'string';

export const getAllFiles = (sc: SourceComponent): string[] => [sc.xml, ...sc.walkContent()].filter(isString);

export const remoteChangeToMetadataMember = (cr: ChangeResult): MetadataMember => {
const checked = ensureNameAndType(cr);

Expand All @@ -142,6 +143,7 @@ export const remoteChangeToMetadataMember = (cr: ChangeResult): MetadataMember =
type: checked.type,
};
};

export const changeResultToMetadataComponent =
(registry: RegistryAccess = new RegistryAccess()) =>
(cr: ChangeResultWithNameAndType): MetadataComponent => ({
Expand Down
4 changes: 2 additions & 2 deletions src/shared/guards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@ export const FileResponseHasPath = (
): fileResponse is FileResponseSuccess & Required<Pick<FileResponseSuccess, 'filePath'>> =>
fileResponse.filePath !== undefined;

export const isChangeResultWithNameAndType = (cr: ChangeResult): cr is ChangeResultWithNameAndType =>
typeof cr.name === 'string' && typeof cr.type === 'string';
export const isChangeResultWithNameAndType = (cr?: ChangeResult): cr is ChangeResultWithNameAndType =>
typeof cr === 'object' && typeof cr.name === 'string' && typeof cr.type === 'string';
4 changes: 2 additions & 2 deletions src/shared/localShadowRepo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export class ShadowRepo {
// iso-git uses relative, posix paths
// but packageDirs has already resolved / normalized them
// so we need to make them project-relative again and convert if windows
const filepaths = this.packageDirs.map(packageDirToRelativePath(this.isWindows)(this.projectPath));
const filepaths = this.packageDirs.map(packageDirToRelativePosixPath(this.isWindows)(this.projectPath));

try {
// status hasn't been initialized yet
Expand Down Expand Up @@ -330,7 +330,7 @@ export class ShadowRepo {
}
}

const packageDirToRelativePath =
const packageDirToRelativePosixPath =
(isWindows: boolean) =>
(projectPath: string) =>
(packageDir: NamedPackageDir): string =>
Expand Down
2 changes: 1 addition & 1 deletion src/shared/metadataKeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const registry = new RegistryAccess();
// only compute once
const aliasTypes: Array<[string, string]> = registry
.getAliasTypes()
// allow assertion because
// allow assertion because aliasTypes are defined as having that property
.map((aliasType) => [aliasType.name, registry.getTypeByName(aliasType.aliasFor!).name]);

const reverseAliasTypes = new Map(aliasTypes.map(([alias, type]) => [type, alias]));
Expand Down
1 change: 1 addition & 0 deletions src/shared/populateFilePaths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export const populateFilePaths = ({
const matchingLocalSourceComponentsSet = ComponentSet.fromSource({
fsPaths: packageDirPaths,
include: remoteChangesAsComponentSet,
registry,
});
logger.debug(
` local source-backed component set has ${matchingLocalSourceComponentsSet.size.toString()} items from remote`
Expand Down
11 changes: 5 additions & 6 deletions src/shared/remoteSourceTrackingService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ export type Contents = {
serverMaxRevisionCounter: number;
sourceMembers: Record<string, MemberRevision>;
};
type MemberRevisionMapEntry = [string, MemberRevision];

const FILENAME = 'maxRevision.json';

/*
Expand Down Expand Up @@ -215,7 +217,7 @@ export class RemoteSourceTrackingService {
// does not match the serverRevisionCounter.
const returnElements = Array.from(this.sourceMembers.entries())
.filter(revisionDoesNotMatch)
.map(convertRevisionToChange);
.map(revisionToRemoteChangeElement);

this.logger.debug(
returnElements.length
Expand Down Expand Up @@ -523,10 +525,7 @@ export const remoteChangeElementToChangeResult = (rce: RemoteChangeElement): Cha
origin: 'remote', // we know they're remote
});

const convertRevisionToChange = ([memberKey, memberRevision]: [
memberKey: string,
memberRevision: MemberRevision
]): RemoteChangeElement => ({
const revisionToRemoteChangeElement = ([memberKey, memberRevision]: MemberRevisionMapEntry): RemoteChangeElement => ({
type: memberRevision.memberType,
name: memberKey.replace(`${memberRevision.memberType}__`, ''),
deleted: memberRevision.isNameObsolete,
Expand Down Expand Up @@ -622,7 +621,7 @@ const formatSourceMemberWarnings = (outstandingSourceMembers: Map<string, Remote
.join(EOL);
};

const revisionDoesNotMatch = ([, member]: [_: unknown, member: MemberRevision]): boolean => doesNotMatchServer(member);
const revisionDoesNotMatch = ([, member]: MemberRevisionMapEntry): boolean => doesNotMatchServer(member);

const doesNotMatchServer = (member: MemberRevision): boolean =>
member.serverRevisionCounter !== member.lastRetrievedFromServer;
8 changes: 6 additions & 2 deletions src/sourceTracking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,11 @@ type RemoteChangesResults = {
*
*/
export class SourceTracking extends AsyncCreatable {
public readonly registry: RegistryAccess;
public readonly projectPath: string;

private org: Org;
private project: SfProject;
private projectPath: string;
private packagesDirs: NamedPackageDir[];
private logger: Logger;
// remote and local tracking may not exist if not initialized
Expand All @@ -110,7 +112,6 @@ export class SourceTracking extends AsyncCreatable {
private subscribeSDREvents: boolean;
private ignoreLocalCache: boolean;
private orgId: string;
private registry: RegistryAccess;

public constructor(options: SourceTrackingOptions) {
super(options);
Expand Down Expand Up @@ -337,6 +338,7 @@ export class SourceTracking extends AsyncCreatable {
const matchingLocalSourceComponentsSet = ComponentSet.fromSource({
fsPaths: this.packagesDirs.map((dir) => resolve(dir.fullPath)),
include: remoteChangesAsComponentSet,
registry: this.registry,
});
if (options.format === 'string') {
return matchingLocalSourceComponentsSet.getSourceComponents().toArray().flatMap(getAllFiles);
Expand Down Expand Up @@ -431,6 +433,7 @@ export class SourceTracking extends AsyncCreatable {
marker?.addDetails({ nonDeletes: options.files?.length ?? 0, deletes: options.deletedFiles?.length ?? 0 });
await this.ensureLocalTracking();

this.logger.trace('files', options.files);
// relative paths make smaller trees AND isogit wants them relative
const relativeOptions = {
files: (options.files ?? []).map(ensureRelative(this.projectPath)),
Expand All @@ -442,6 +445,7 @@ export class SourceTracking extends AsyncCreatable {
// resolve from highest possible level. TODO: can we use [.]
fsPaths: relativeOptions.files.length ? [relativeOptions.files[0].split(sep)[0]] : [],
tree: VirtualTreeContainer.fromFilePaths(relativeOptions.files),
registry: this.registry,
});
// these are top-level bundle paths like lwc/foo
const bundlesWithDeletedFiles = (
Expand Down

0 comments on commit b0f2f35

Please sign in to comment.