@salesforce/source-tracking 0.5.1 → 0.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -0
- package/LICENSE.txt +1 -1
- package/lib/shared/functions.d.ts +5 -0
- package/lib/shared/functions.js +18 -1
- package/lib/shared/localShadowRepo.d.ts +3 -1
- package/lib/shared/localShadowRepo.js +39 -16
- package/lib/sourceTracking.js +3 -3
- package/package.json +8 -7
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
### [0.5.2](https://github.com/forcedotcom/source-tracking/compare/v0.5.1...v0.5.2) (2022-01-05)
|
|
6
|
+
|
|
7
|
+
### Features
|
|
8
|
+
|
|
9
|
+
- path-scoped singleton ([de46db4](https://github.com/forcedotcom/source-tracking/commit/de46db4b08a3fe087a2931936655c75b3b7cc32c))
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
- distributed .gitignore and loose pkgDir matching ([a148a36](https://github.com/forcedotcom/source-tracking/commit/a148a366739b6941f3f479b375147897103316bb))
|
|
14
|
+
- remove singleton behavior for localShadowRepo ([887bb68](https://github.com/forcedotcom/source-tracking/commit/887bb684528df8df07fe9b4edf1bd2f4165fe3e2))
|
|
15
|
+
|
|
5
16
|
### [0.5.1](https://github.com/forcedotcom/source-tracking/compare/v0.5.0...v0.5.1) (2021-12-03)
|
|
6
17
|
|
|
7
18
|
### Bug Fixes
|
package/LICENSE.txt
CHANGED
|
@@ -3,3 +3,8 @@ import { RemoteChangeElement, ChangeResult } from './types';
|
|
|
3
3
|
export declare const getMetadataKey: (metadataType: string, metadataName: string) => string;
|
|
4
4
|
export declare const getKeyFromObject: (element: RemoteChangeElement | ChangeResult) => string;
|
|
5
5
|
export declare const isBundle: (cmp: SourceComponent) => boolean;
|
|
6
|
+
/**
|
|
7
|
+
* Verify that a filepath starts exactly with a complete parent path
|
|
8
|
+
* ex: '/foo/bar-extra/baz'.startsWith('foo/bar') would be true, but this function understands that they are not in the same folder
|
|
9
|
+
*/
|
|
10
|
+
export declare const pathIsInFolder: (filePath: string, folder: string) => boolean;
|
package/lib/shared/functions.js
CHANGED
|
@@ -6,7 +6,9 @@
|
|
|
6
6
|
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.isBundle = exports.getKeyFromObject = exports.getMetadataKey = void 0;
|
|
9
|
+
exports.pathIsInFolder = exports.isBundle = exports.getKeyFromObject = exports.getMetadataKey = void 0;
|
|
10
|
+
const path_1 = require("path");
|
|
11
|
+
const ts_types_1 = require("@salesforce/ts-types");
|
|
10
12
|
const getMetadataKey = (metadataType, metadataName) => {
|
|
11
13
|
return `${metadataType}__${metadataName}`;
|
|
12
14
|
};
|
|
@@ -20,4 +22,19 @@ const getKeyFromObject = (element) => {
|
|
|
20
22
|
exports.getKeyFromObject = getKeyFromObject;
|
|
21
23
|
const isBundle = (cmp) => { var _a; return ((_a = cmp.type.strategies) === null || _a === void 0 ? void 0 : _a.adapter) === 'bundle'; };
|
|
22
24
|
exports.isBundle = isBundle;
|
|
25
|
+
/**
|
|
26
|
+
* Verify that a filepath starts exactly with a complete parent path
|
|
27
|
+
* ex: '/foo/bar-extra/baz'.startsWith('foo/bar') would be true, but this function understands that they are not in the same folder
|
|
28
|
+
*/
|
|
29
|
+
const pathIsInFolder = (filePath, folder) => {
|
|
30
|
+
const biggerStringParts = (0, path_1.normalize)(filePath).split(path_1.sep).filter(nonEmptyStringFilter);
|
|
31
|
+
return (0, path_1.normalize)(folder)
|
|
32
|
+
.split(path_1.sep)
|
|
33
|
+
.filter(nonEmptyStringFilter)
|
|
34
|
+
.every((part, index) => part === biggerStringParts[index]);
|
|
35
|
+
};
|
|
36
|
+
exports.pathIsInFolder = pathIsInFolder;
|
|
37
|
+
const nonEmptyStringFilter = (value) => {
|
|
38
|
+
return (0, ts_types_1.isString)(value) && value.length > 0;
|
|
39
|
+
};
|
|
23
40
|
//# sourceMappingURL=functions.js.map
|
|
@@ -11,12 +11,13 @@ interface CommitRequest {
|
|
|
11
11
|
message?: string;
|
|
12
12
|
}
|
|
13
13
|
export declare class ShadowRepo {
|
|
14
|
-
private static
|
|
14
|
+
private static instanceMap;
|
|
15
15
|
gitDir: string;
|
|
16
16
|
projectPath: string;
|
|
17
17
|
private packageDirs;
|
|
18
18
|
private status;
|
|
19
19
|
private logger;
|
|
20
|
+
private gitIgnoreLocations;
|
|
20
21
|
private constructor();
|
|
21
22
|
static getInstance(options: ShadowRepoOptions): Promise<ShadowRepo>;
|
|
22
23
|
init(): Promise<void>;
|
|
@@ -74,6 +75,7 @@ export declare class ShadowRepo {
|
|
|
74
75
|
* @returns sha (string)
|
|
75
76
|
*/
|
|
76
77
|
commitChanges({ deployedFiles, deletedFiles, message, }?: CommitRequest): Promise<string>;
|
|
78
|
+
private locateIgnoreFiles;
|
|
77
79
|
private stashIgnoreFile;
|
|
78
80
|
private unStashIgnoreFile;
|
|
79
81
|
}
|
|
@@ -12,6 +12,7 @@ const path = require("path");
|
|
|
12
12
|
const os = require("os");
|
|
13
13
|
const core_1 = require("@salesforce/core");
|
|
14
14
|
const git = require("isomorphic-git");
|
|
15
|
+
const functions_1 = require("./functions");
|
|
15
16
|
const gitIgnoreFileName = '.gitignore';
|
|
16
17
|
const stashedGitIgnoreFileName = '.BAK.gitignore';
|
|
17
18
|
/**
|
|
@@ -28,16 +29,19 @@ const HEAD = 1;
|
|
|
28
29
|
const WORKDIR = 2;
|
|
29
30
|
class ShadowRepo {
|
|
30
31
|
constructor(options) {
|
|
32
|
+
this.gitIgnoreLocations = [];
|
|
31
33
|
this.gitDir = getGitDir(options.orgId, options.projectPath);
|
|
32
34
|
this.projectPath = options.projectPath;
|
|
33
35
|
this.packageDirs = options.packageDirs;
|
|
34
36
|
}
|
|
37
|
+
// think of singleton behavior but unique to the projectPath
|
|
35
38
|
static async getInstance(options) {
|
|
36
|
-
if (!ShadowRepo.
|
|
37
|
-
|
|
38
|
-
await
|
|
39
|
+
if (!ShadowRepo.instanceMap.has(options.projectPath)) {
|
|
40
|
+
const newInstance = new ShadowRepo(options);
|
|
41
|
+
await newInstance.init();
|
|
42
|
+
ShadowRepo.instanceMap.set(options.projectPath, newInstance);
|
|
39
43
|
}
|
|
40
|
-
return ShadowRepo.
|
|
44
|
+
return ShadowRepo.instanceMap.get(options.projectPath);
|
|
41
45
|
}
|
|
42
46
|
async init() {
|
|
43
47
|
this.logger = await core_1.Logger.child('ShadowRepo');
|
|
@@ -54,6 +58,7 @@ class ShadowRepo {
|
|
|
54
58
|
async gitInit() {
|
|
55
59
|
await core_1.fs.promises.mkdir(this.gitDir, { recursive: true });
|
|
56
60
|
await git.init({ fs: core_1.fs, dir: this.projectPath, gitdir: this.gitDir, defaultBranch: 'main' });
|
|
61
|
+
await this.locateIgnoreFiles();
|
|
57
62
|
}
|
|
58
63
|
/**
|
|
59
64
|
* Delete the local tracking files
|
|
@@ -94,8 +99,15 @@ class ShadowRepo {
|
|
|
94
99
|
dir: this.projectPath,
|
|
95
100
|
gitdir: this.gitDir,
|
|
96
101
|
filepaths,
|
|
97
|
-
|
|
98
|
-
|
|
102
|
+
filter: (f) =>
|
|
103
|
+
// no hidden files
|
|
104
|
+
!f.includes(`${path.sep}.`) &&
|
|
105
|
+
// no lwc tests
|
|
106
|
+
!f.includes('__tests__') &&
|
|
107
|
+
// no gitignore files
|
|
108
|
+
![gitIgnoreFileName, stashedGitIgnoreFileName].includes(path.basename(f)) &&
|
|
109
|
+
// isogit uses `startsWith` for filepaths so it's possible to get a false positive
|
|
110
|
+
filepaths.some((pkgDir) => (0, functions_1.pathIsInFolder)(f, pkgDir)),
|
|
99
111
|
});
|
|
100
112
|
// isomorphic-git stores things in unix-style tree. Convert to windows-style if necessary
|
|
101
113
|
if (isWindows) {
|
|
@@ -196,20 +208,31 @@ class ShadowRepo {
|
|
|
196
208
|
await this.unStashIgnoreFile();
|
|
197
209
|
}
|
|
198
210
|
}
|
|
211
|
+
async locateIgnoreFiles() {
|
|
212
|
+
// set the gitIgnoreLocations so we only have to do it once
|
|
213
|
+
this.gitIgnoreLocations = (await git.walk({
|
|
214
|
+
fs: core_1.fs,
|
|
215
|
+
dir: this.projectPath,
|
|
216
|
+
gitdir: this.gitDir,
|
|
217
|
+
trees: [git.WORKDIR()],
|
|
218
|
+
// TODO: this can be marginally faster if we limit it to pkgDirs and toplevel project files
|
|
219
|
+
// eslint-disable-next-line @typescript-eslint/require-await
|
|
220
|
+
map: async (filepath) => filepath,
|
|
221
|
+
}))
|
|
222
|
+
.filter((filepath) => filepath.includes(gitIgnoreFileName) &&
|
|
223
|
+
// can be top-level like '.' (no sep) OR must be in one of the package dirs
|
|
224
|
+
(!filepath.includes(path.sep) || this.packageDirs.some((dir) => (0, functions_1.pathIsInFolder)(filepath, dir.name))))
|
|
225
|
+
.map((ignoreFile) => path.join(this.projectPath, ignoreFile));
|
|
226
|
+
}
|
|
199
227
|
async stashIgnoreFile() {
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
if (core_1.fs.existsSync(originalLocation)) {
|
|
203
|
-
await core_1.fs.promises.rename(originalLocation, path.join(this.projectPath, stashedGitIgnoreFileName));
|
|
204
|
-
}
|
|
228
|
+
// allSettled allows them to fail (example, the file wasn't where it was expected).
|
|
229
|
+
await Promise.allSettled(this.gitIgnoreLocations.map((originalLocation) => core_1.fs.promises.rename(originalLocation, originalLocation.replace(gitIgnoreFileName, stashedGitIgnoreFileName))));
|
|
205
230
|
}
|
|
206
231
|
async unStashIgnoreFile() {
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
if (core_1.fs.existsSync(stashedLocation)) {
|
|
210
|
-
await core_1.fs.promises.rename(stashedLocation, path.join(this.projectPath, gitIgnoreFileName));
|
|
211
|
-
}
|
|
232
|
+
// allSettled allows them to fail (example, the file wasn't where it was expected).
|
|
233
|
+
await Promise.allSettled(this.gitIgnoreLocations.map((originalLocation) => core_1.fs.promises.rename(originalLocation.replace(gitIgnoreFileName, stashedGitIgnoreFileName), originalLocation)));
|
|
212
234
|
}
|
|
213
235
|
}
|
|
214
236
|
exports.ShadowRepo = ShadowRepo;
|
|
237
|
+
ShadowRepo.instanceMap = new Map();
|
|
215
238
|
//# sourceMappingURL=localShadowRepo.js.map
|
package/lib/sourceTracking.js
CHANGED
|
@@ -59,8 +59,8 @@ class SourceTracking extends kit_1.AsyncCreatable {
|
|
|
59
59
|
const groupings = (byPackageDir
|
|
60
60
|
? this.packagesDirs.map((pkgDir) => ({
|
|
61
61
|
path: pkgDir.name,
|
|
62
|
-
nonDeletes: allNonDeletes.filter((f) =>
|
|
63
|
-
deletes: allDeletes.filter((f) =>
|
|
62
|
+
nonDeletes: allNonDeletes.filter((f) => (0, functions_1.pathIsInFolder)(f, pkgDir.name)),
|
|
63
|
+
deletes: allDeletes.filter((f) => (0, functions_1.pathIsInFolder)(f, pkgDir.name)),
|
|
64
64
|
}))
|
|
65
65
|
: [
|
|
66
66
|
{
|
|
@@ -282,7 +282,7 @@ class SourceTracking extends kit_1.AsyncCreatable {
|
|
|
282
282
|
.filter(ts_types_1.isString);
|
|
283
283
|
await this.localRepo.commitChanges({
|
|
284
284
|
deployedFiles: relativeOptions.files,
|
|
285
|
-
deletedFiles: relativeOptions.deletedFiles.concat((await this.localRepo.getDeleteFilenames()).filter((deployedFile) => bundlesWithDeletedFiles.some((bundlePath) =>
|
|
285
|
+
deletedFiles: relativeOptions.deletedFiles.concat((await this.localRepo.getDeleteFilenames()).filter((deployedFile) => bundlesWithDeletedFiles.some((bundlePath) => (0, functions_1.pathIsInFolder)(deployedFile, bundlePath)) &&
|
|
286
286
|
!relativeOptions.files.includes(deployedFile))),
|
|
287
287
|
});
|
|
288
288
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@salesforce/source-tracking",
|
|
3
3
|
"description": "API for tracking local and remote Salesforce metadata changes",
|
|
4
|
-
"version": "0.5.
|
|
4
|
+
"version": "0.5.2",
|
|
5
5
|
"author": "Salesforce",
|
|
6
6
|
"license": "BSD-3-Clause",
|
|
7
7
|
"main": "lib/index.js",
|
|
@@ -24,7 +24,8 @@
|
|
|
24
24
|
"pretest": "sf-compile-test",
|
|
25
25
|
"prune:dead": "ts-prune | grep -v 'source-deploy-retrieve' | grep -v 'index.ts'",
|
|
26
26
|
"test": "sf-test",
|
|
27
|
-
"test:nuts": "nyc mocha \"**/*.nut.ts\" --slow 4500 --timeout 600000 --parallel"
|
|
27
|
+
"test:nuts": "nyc mocha \"**/*.nut.ts\" --slow 4500 --timeout 600000 --parallel",
|
|
28
|
+
"test:nuts:local": "mocha \"**/local*.nut.ts\" --slow 4500 --timeout 600000 --parallel"
|
|
28
29
|
},
|
|
29
30
|
"keywords": [
|
|
30
31
|
"force",
|
|
@@ -42,16 +43,16 @@
|
|
|
42
43
|
"/oclif.manifest.json"
|
|
43
44
|
],
|
|
44
45
|
"dependencies": {
|
|
45
|
-
"@salesforce/core": "^2.
|
|
46
|
+
"@salesforce/core": "^2.33.1",
|
|
46
47
|
"@salesforce/kit": "^1.5.17",
|
|
47
|
-
"@salesforce/source-deploy-retrieve": "^5.8.
|
|
48
|
+
"@salesforce/source-deploy-retrieve": "^5.8.2",
|
|
48
49
|
"isomorphic-git": "^1.9.2",
|
|
49
50
|
"ts-retry-promise": "^0.6.0"
|
|
50
51
|
},
|
|
51
52
|
"devDependencies": {
|
|
52
53
|
"@salesforce/cli-plugins-testkit": "^1.3.7",
|
|
53
|
-
"@salesforce/dev-config": "^
|
|
54
|
-
"@salesforce/dev-scripts": "^
|
|
54
|
+
"@salesforce/dev-config": "^3.0.0",
|
|
55
|
+
"@salesforce/dev-scripts": "^2.0.0",
|
|
55
56
|
"@salesforce/prettier-config": "^0.0.2",
|
|
56
57
|
"@salesforce/ts-sinon": "^1.3.21",
|
|
57
58
|
"@types/shelljs": "^0.8.9",
|
|
@@ -69,7 +70,7 @@
|
|
|
69
70
|
"eslint-plugin-jsdoc": "^37.0.1",
|
|
70
71
|
"eslint-plugin-prettier": "^3.4.0",
|
|
71
72
|
"husky": "^7.0.4",
|
|
72
|
-
"mocha": "^9.
|
|
73
|
+
"mocha": "^9.1.3",
|
|
73
74
|
"nyc": "^15.1.0",
|
|
74
75
|
"prettier": "^2.3.2",
|
|
75
76
|
"pretty-quick": "^3.1.1",
|