@salesforce/source-tracking
Version:
API for tracking local and remote Salesforce metadata changes
75 lines • 3.51 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.getDedupedConflictsFromChanges = exports.findConflictsInComponentSet = exports.throwIfConflicts = void 0;
/*
* Copyright 2025, Salesforce, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
const node_path_1 = require("node:path");
const types_1 = require("./types");
const functions_1 = require("./functions");
const populateTypesAndNames_1 = require("./populateTypesAndNames");
const guards_1 = require("./guards");
const throwIfConflicts = (conflicts) => {
if (conflicts.length > 0) {
throw new types_1.SourceConflictError(`${conflicts.length} conflicts detected`, conflicts);
}
};
exports.throwIfConflicts = throwIfConflicts;
/**
*
* @param cs ComponentSet to compare
* @param conflicts ChangeResult[] representing conflicts from SourceTracking.getConflicts
* @returns ConflictResponse[] de-duped and formatted for json or table display
*/
const findConflictsInComponentSet = (cs, conflicts) => {
// map do dedupe by name-type-filename
const conflictMap = new Map();
conflicts
.filter(guards_1.isChangeResultWithNameAndType)
.filter((cr) => cs.has({ fullName: cr.name, type: cr.type }))
.forEach((cr) => {
cr.filenames?.forEach((f) => {
conflictMap.set(`${cr.name}#${cr.type}#${f}`, {
state: 'Conflict',
fullName: cr.name,
type: cr.type,
filePath: (0, node_path_1.resolve)(f),
});
});
});
const reformattedConflicts = Array.from(conflictMap.values());
return reformattedConflicts;
};
exports.findConflictsInComponentSet = findConflictsInComponentSet;
const getDedupedConflictsFromChanges = ({ localChanges = [], remoteChanges = [], projectPath, forceIgnore, registry, }) => {
const metadataKeyIndex = new Map(remoteChanges
.filter(guards_1.isChangeResultWithNameAndType)
.map((change) => [(0, functions_1.getMetadataKey)(change.name, change.type), change]));
const fileNameIndex = new Map(remoteChanges.flatMap((change) => (change.filenames ?? []).map((filename) => [filename, change])));
return (0, populateTypesAndNames_1.populateTypesAndNames)({ excludeUnresolvable: true, projectPath, forceIgnore, registry })(localChanges)
.filter(guards_1.isChangeResultWithNameAndType)
.flatMap((change) => {
const metadataKey = (0, functions_1.getMetadataKey)(change.name, change.type);
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));
});
};
exports.getDedupedConflictsFromChanges = getDedupedConflictsFromChanges;
//# sourceMappingURL=conflicts.js.map
;