@salesforce/source-tracking
Advanced tools
Comparing version 0.4.0 to 0.4.1
@@ -5,2 +5,11 @@ # Changelog | ||
### [0.4.1](https://github.com/forcedotcom/source-tracking/compare/v0.4.0...v0.4.1) (2021-10-28) | ||
### Bug Fixes | ||
* better conflict handling (can match filenames or type/name) ([4441a0a](https://github.com/forcedotcom/source-tracking/commit/4441a0abd70c7f8f315e1c638b4cef7fcf3e2e68)) | ||
* gitignore stashing location ([5145545](https://github.com/forcedotcom/source-tracking/commit/5145545eeee6c800986014327479d20e943143e5)) | ||
* polling exclusion logic for aura meta.xml was wrong ([2d40b2e](https://github.com/forcedotcom/source-tracking/commit/2d40b2ef65ef9a3145d0c75cd4943e4325d5745c)) | ||
## 0.4.0 (2021-10-22) | ||
@@ -7,0 +16,0 @@ |
@@ -15,2 +15,4 @@ "use strict"; | ||
const git = require("isomorphic-git"); | ||
const gitIgnoreFileName = '.gitignore'; | ||
const stashedGitIgnoreFileName = '.BAK.gitignore'; | ||
/** | ||
@@ -193,13 +195,13 @@ * returns the full path to where we store the shadow repo | ||
async stashIgnoreFile() { | ||
const originalLocation = path.join(this.projectPath, '.gitignore'); | ||
const originalLocation = path.join(this.projectPath, gitIgnoreFileName); | ||
// another process may have already stashed the file | ||
if (core_1.fs.existsSync(originalLocation)) { | ||
await core_1.fs.promises.rename(originalLocation, path.join(this.projectPath, '.BAK.gitignore')); | ||
await core_1.fs.promises.rename(originalLocation, path.join(this.projectPath, stashedGitIgnoreFileName)); | ||
} | ||
} | ||
async unStashIgnoreFile() { | ||
const stashedLocation = path.join(this.projectPath, '.gitignore'); | ||
const stashedLocation = path.join(this.projectPath, stashedGitIgnoreFileName); | ||
// another process may have already un-stashed the file | ||
if (core_1.fs.existsSync(stashedLocation)) { | ||
await core_1.fs.promises.rename(stashedLocation, path.join(this.projectPath, '.gitignore')); | ||
await core_1.fs.promises.rename(stashedLocation, path.join(this.projectPath, gitIgnoreFileName)); | ||
} | ||
@@ -206,0 +208,0 @@ } |
@@ -359,3 +359,3 @@ "use strict"; | ||
.filter((fileResponse) => { | ||
var _a, _b; | ||
var _a; | ||
// unchanged files will never be in the sourceMembers. Not really sure why SDR returns them. | ||
@@ -366,3 +366,3 @@ return fileResponse.state !== source_deploy_retrieve_1.ComponentStatus.Unchanged && | ||
// aura meta.xml aren't tracked as SourceMembers | ||
!(((_a = fileResponse.filePath) === null || _a === void 0 ? void 0 : _a.includes('AuraDefinition')) && ((_b = fileResponse.filePath) === null || _b === void 0 ? void 0 : _b.endsWith('.cmp-meta.xml'))); | ||
!((_a = fileResponse.filePath) === null || _a === void 0 ? void 0 : _a.endsWith('.cmp-meta.xml')); | ||
}) | ||
@@ -369,0 +369,0 @@ .map((member) => { |
@@ -27,4 +27,2 @@ import { Org, SfdxProject } from '@salesforce/core'; | ||
private forceIgnore; | ||
private registry; | ||
private transformerFactory; | ||
constructor(options: SourceTrackingOptions); | ||
@@ -121,3 +119,2 @@ init(): Promise<void>; | ||
private remoteChangesToOutputRows; | ||
private filesPathFromNonLocalSourceComponent; | ||
} |
@@ -12,2 +12,3 @@ "use strict"; | ||
const path = require("path"); | ||
const os_1 = require("os"); | ||
const core_1 = require("@salesforce/core"); | ||
@@ -17,4 +18,2 @@ const kit_1 = require("@salesforce/kit"); | ||
const source_deploy_retrieve_1 = require("@salesforce/source-deploy-retrieve"); | ||
const metadataTransformerFactory_1 = require("@salesforce/source-deploy-retrieve/lib/src/convert/transformers/metadataTransformerFactory"); | ||
const convertContext_1 = require("@salesforce/source-deploy-retrieve/lib/src/convert/convertContext"); | ||
const remoteSourceTrackingService_1 = require("./shared/remoteSourceTrackingService"); | ||
@@ -343,6 +342,10 @@ const localShadowRepo_1 = require("./shared/localShadowRepo"); | ||
} | ||
// index them by filename | ||
// index the remoteChanges by filename | ||
const fileNameIndex = new Map(); | ||
const metadataKeyIndex = new Map(); | ||
remoteChanges.map((change) => { | ||
var _a; | ||
if (change.name && change.type) { | ||
metadataKeyIndex.set((0, functions_1.getMetadataKey)(change.name, change.type), change); | ||
} | ||
(_a = change.filenames) === null || _a === void 0 ? void 0 : _a.map((filename) => { | ||
@@ -353,9 +356,17 @@ fileNameIndex.set(filename, change); | ||
const conflicts = new Set(); | ||
localChanges.map((change) => { | ||
this.populateTypesAndNames({ elements: localChanges, excludeUnresolvable: true }).map((change) => { | ||
var _a; | ||
(_a = change.filenames) === null || _a === void 0 ? void 0 : _a.map((filename) => { | ||
if (fileNameIndex.has(filename)) { | ||
conflicts.add({ ...fileNameIndex.get(filename) }); | ||
} | ||
}); | ||
const metadataKey = (0, functions_1.getMetadataKey)(change.name, change.type); | ||
// option 1: name and type match | ||
if (metadataKeyIndex.has(metadataKey)) { | ||
conflicts.add({ ...metadataKeyIndex.get(metadataKey) }); | ||
} | ||
else { | ||
// option 2: some of the filenames match | ||
(_a = change.filenames) === null || _a === void 0 ? void 0 : _a.map((filename) => { | ||
if (fileNameIndex.has(filename)) { | ||
conflicts.add({ ...fileNameIndex.get(filename) }); | ||
} | ||
}); | ||
} | ||
}); | ||
@@ -407,5 +418,6 @@ // deeply de-dupe | ||
// Set the ignored status at the component level so it can apply to all its files, some of which may not match the ignoreFile (ex: ApexClass) | ||
this.forceIgnore = (_a = this.forceIgnore) !== null && _a !== void 0 ? _a : source_deploy_retrieve_1.ForceIgnore.findAndCreate(this.projectPath); | ||
this.forceIgnore = (_a = this.forceIgnore) !== null && _a !== void 0 ? _a : source_deploy_retrieve_1.ForceIgnore.findAndCreate(this.project.getDefaultPackage().path); | ||
const ignored = filenamesFromMatchingComponent | ||
.filter(guards_1.stringGuard) | ||
.filter((filename) => !filename.includes('__tests__')) | ||
.some((filename) => this.forceIgnore.denies(filename)); | ||
@@ -468,5 +480,7 @@ filenamesFromMatchingComponent.map((filename) => { | ||
if (remoteChangesAsComponentSet.size < elements.length) { | ||
// iterate the elements to see which ones didn't make it into the component set | ||
throw new Error(`unable to generate complete component set for ${elements | ||
.map((element) => `${element.name}(${element.type})`) | ||
.join(',')}`); | ||
.filter((element) => !remoteChangesAsComponentSet.has({ type: element === null || element === void 0 ? void 0 : element.type, fullName: element === null || element === void 0 ? void 0 : element.name })) | ||
.map((element) => `${element.name} (${element.type})`) | ||
.join(os_1.EOL)}`); | ||
} | ||
@@ -536,6 +550,8 @@ const matchingLocalSourceComponentsSet = source_deploy_retrieve_1.ComponentSet.fromSource({ | ||
} | ||
// this will eventually have async call to figure out the target file locations for remote changes | ||
// eslint-disable-next-line @typescript-eslint/require-await | ||
async remoteChangesToOutputRows(input) { | ||
var _a, _b, _c, _d; | ||
this.logger.debug('converting ChangeResult to a row', input); | ||
this.forceIgnore = (_a = this.forceIgnore) !== null && _a !== void 0 ? _a : source_deploy_retrieve_1.ForceIgnore.findAndCreate(this.projectPath); | ||
this.forceIgnore = (_a = this.forceIgnore) !== null && _a !== void 0 ? _a : source_deploy_retrieve_1.ForceIgnore.findAndCreate(this.project.getDefaultPackage().path); | ||
const baseObject = { | ||
@@ -555,23 +571,6 @@ type: (_b = input.type) !== null && _b !== void 0 ? _b : '', | ||
} | ||
// when the file doesn't exist locally, there are no filePaths. | ||
// we can determine where the filePath *would* go using SDR's transformers stuff | ||
const fakeFilePaths = await this.filesPathFromNonLocalSourceComponent({ | ||
fullName: baseObject.fullName, | ||
typeName: baseObject.type, | ||
}); | ||
return [{ ...baseObject, ignored: fakeFilePaths.some((filePath) => this.forceIgnore.denies(filePath)) }]; | ||
// when the file doesn't exist locally, there are no filePaths | ||
// So we can't say whether it's ignored or not | ||
return [baseObject]; | ||
} | ||
// TODO: This goes in SDR on SourceComponent | ||
// we don't have a local copy of the component | ||
// this uses SDR's approach to determine what the filePath would be if the component were written locally | ||
async filesPathFromNonLocalSourceComponent({ fullName, typeName, }) { | ||
var _a, _b; | ||
this.registry = (_a = this.registry) !== null && _a !== void 0 ? _a : new source_deploy_retrieve_1.RegistryAccess(); | ||
const component = new source_deploy_retrieve_1.SourceComponent({ name: fullName, type: this.registry.getTypeByName(typeName) }); | ||
this.transformerFactory = | ||
(_b = this.transformerFactory) !== null && _b !== void 0 ? _b : new metadataTransformerFactory_1.MetadataTransformerFactory(this.registry, new convertContext_1.ConvertContext()); | ||
const transformer = this.transformerFactory.getTransformer(component); | ||
const writePaths = await transformer.toSourceFormat(component); | ||
return writePaths.map((writePath) => writePath.output); | ||
} | ||
} | ||
@@ -578,0 +577,0 @@ exports.SourceTracking = SourceTracking; |
{ | ||
"name": "@salesforce/source-tracking", | ||
"description": "API for tracking local and remote Salesforce metadata changes", | ||
"version": "0.4.0", | ||
"version": "0.4.1", | ||
"author": "Salesforce", | ||
@@ -10,3 +10,3 @@ "license": "BSD-3-Clause", | ||
"homepage": "https://github.com/forcedotcom/source-tracking#readme", | ||
"repository": "forcedotcom/source-tracking.git", | ||
"repository": "forcedotcom/source-tracking", | ||
"scripts": { | ||
@@ -13,0 +13,0 @@ "build": "sf-build", |
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
106832
1964