@salesforce/source-tracking 1.1.5 → 1.2.0

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 CHANGED
@@ -2,6 +2,25 @@
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
+ ## [1.2.0](https://github.com/forcedotcom/source-tracking/compare/v1.1.7...v1.2.0) (2022-03-23)
6
+
7
+ ### Features
8
+
9
+ - let isogit deal with ignore files ([#135](https://github.com/forcedotcom/source-tracking/issues/135)) ([1ddb2cd](https://github.com/forcedotcom/source-tracking/commit/1ddb2cdb8f23688f7bb4876a893097a85581f4c1))
10
+
11
+ ### Bug Fixes
12
+
13
+ - ga tracking commands compatibility ([3a31a0d](https://github.com/forcedotcom/source-tracking/commit/3a31a0de448993c643ea4661a7a37772e46e8f51))
14
+ - support pkgDir with ./foo ([3b46454](https://github.com/forcedotcom/source-tracking/commit/3b46454b3e57f653cbe80c66fbfee1cac121c2a8))
15
+
16
+ ### [1.1.7](https://github.com/forcedotcom/source-tracking/compare/v1.1.6...v1.1.7) (2022-03-16)
17
+
18
+ ### Bug Fixes
19
+
20
+ - use isogit multiple add ([0845df8](https://github.com/forcedotcom/source-tracking/commit/0845df81845f07bd2bece444118497b2ef72e7aa))
21
+
22
+ ### [1.1.6](https://github.com/forcedotcom/source-tracking/compare/v1.1.5...v1.1.6) (2022-03-14)
23
+
5
24
  ### [1.1.5](https://github.com/forcedotcom/source-tracking/compare/v1.1.4...v1.1.5) (2022-03-11)
6
25
 
7
26
  ### [1.1.4](https://github.com/forcedotcom/source-tracking/compare/v1.1.3...v1.1.4) (2022-03-07)
@@ -57,13 +57,18 @@ const throwIfInvalid = ({ org, projectPath, toValidate, command, }) => {
57
57
  throw new core_1.SfdxError(`${messages.getMessage('sourceTrackingFileVersionMismatch', ['new/beta'])}\n\nTry this:\n${messages.getMessage('useOtherVersion', ['new/beta', (0, exports.replaceRenamedCommands)(command.replace(':legacy', ''))])}.\n${messages.getMessage('clearSuggestion', [
58
58
  'new/beta',
59
59
  (0, exports.replaceRenamedCommands)('sfdx force:source:tracking:clear'),
60
+ (0, exports.replaceRenamedCommands)('sfdx force:source:tracking:reset', true),
60
61
  ])}.`, 'SourceTrackingFileVersionMismatch');
61
62
  }
62
63
  // We expected it to be the plugin-source version but it is using the old tracking files
63
64
  if (toValidate === 'plugin-source') {
64
65
  throw new core_1.SfdxError(messages.getMessage('sourceTrackingFileVersionMismatch', ['old/legacy']), 'SourceTrackingFileVersionMismatch', [
65
66
  messages.getMessage('useOtherVersion', ['old/legacy', (0, exports.replaceRenamedCommands)(command, true)]),
66
- messages.getMessage('clearSuggestion', ['old/legacy', 'sfdx force:source:tracking:clear']),
67
+ messages.getMessage('clearSuggestion', [
68
+ 'old/legacy',
69
+ 'sfdx force:source:legacy:tracking:clear',
70
+ 'sfdx force:source:tracking:reset',
71
+ ]),
67
72
  ]);
68
73
  }
69
74
  };
@@ -82,10 +87,10 @@ const replaceRenamedCommands = (input, reverse = false) => {
82
87
  };
83
88
  exports.replaceRenamedCommands = replaceRenamedCommands;
84
89
  const renames = new Map([
85
- ['force:source:status', 'force:source:beta:status'],
86
- ['force:source:push', 'force:source:beta:push'],
87
- ['force:source:pull', 'force:source:beta:pull'],
88
- ['force:source:tracking:reset', 'force:source:beta:tracking:reset'],
89
- ['force:source:tracking:clear', 'force:source:beta:tracking:clear'],
90
+ ['force:source:legacy:status', 'force:source:status'],
91
+ ['force:source:legacy:push', 'force:source:push'],
92
+ ['force:source:legacy:pull', 'force:source:pull'],
93
+ ['force:source:legacy:tracking:reset', 'force:source:tracking:reset'],
94
+ ['force:source:legacy:tracking:clear', 'force:source:tracking:clear'],
90
95
  ]);
91
96
  //# sourceMappingURL=compatibility.js.map
@@ -9,6 +9,7 @@ interface CommitRequest {
9
9
  deployedFiles?: string[];
10
10
  deletedFiles?: string[];
11
11
  message?: string;
12
+ needsUpdatedStatus?: boolean;
12
13
  }
13
14
  export declare class ShadowRepo {
14
15
  private static instanceMap;
@@ -17,7 +18,6 @@ export declare class ShadowRepo {
17
18
  private packageDirs;
18
19
  private status;
19
20
  private logger;
20
- private gitIgnoreLocations;
21
21
  private constructor();
22
22
  static getInstance(options: ShadowRepoOptions): Promise<ShadowRepo>;
23
23
  init(): Promise<void>;
@@ -74,9 +74,6 @@ export declare class ShadowRepo {
74
74
  *
75
75
  * @returns sha (string)
76
76
  */
77
- commitChanges({ deployedFiles, deletedFiles, message, }?: CommitRequest): Promise<string>;
78
- private locateIgnoreFiles;
79
- private stashIgnoreFile;
80
- private unStashIgnoreFile;
77
+ commitChanges({ deployedFiles, deletedFiles, message, needsUpdatedStatus, }?: CommitRequest): Promise<string>;
81
78
  }
82
79
  export {};
@@ -10,11 +10,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
10
10
  exports.ShadowRepo = void 0;
11
11
  const path = require("path");
12
12
  const os = require("os");
13
+ const fs = require("fs");
13
14
  const core_1 = require("@salesforce/core");
14
15
  const git = require("isomorphic-git");
15
16
  const functions_1 = require("./functions");
16
17
  const gitIgnoreFileName = '.gitignore';
17
- const stashedGitIgnoreFileName = '.BAK.gitignore';
18
18
  /**
19
19
  * returns the full path to where we store the shadow repo
20
20
  */
@@ -29,7 +29,6 @@ const HEAD = 1;
29
29
  const WORKDIR = 2;
30
30
  class ShadowRepo {
31
31
  constructor(options) {
32
- this.gitIgnoreLocations = [];
33
32
  this.gitDir = getGitDir(options.orgId, options.projectPath);
34
33
  this.projectPath = options.projectPath;
35
34
  this.packageDirs = options.packageDirs;
@@ -46,19 +45,18 @@ class ShadowRepo {
46
45
  async init() {
47
46
  this.logger = await core_1.Logger.child('ShadowRepo');
48
47
  // initialize the shadow repo if it doesn't exist
49
- if (!core_1.fs.existsSync(this.gitDir)) {
48
+ if (!fs.existsSync(this.gitDir)) {
50
49
  this.logger.debug('initializing git repo');
51
50
  await this.gitInit();
52
51
  }
53
- await this.locateIgnoreFiles();
54
52
  }
55
53
  /**
56
54
  * Initialize a new source tracking shadow repo. Think of git init
57
55
  *
58
56
  */
59
57
  async gitInit() {
60
- await core_1.fs.promises.mkdir(this.gitDir, { recursive: true });
61
- await git.init({ fs: core_1.fs, dir: this.projectPath, gitdir: this.gitDir, defaultBranch: 'main' });
58
+ await fs.promises.mkdir(this.gitDir, { recursive: true });
59
+ await git.init({ fs, dir: this.projectPath, gitdir: this.gitDir, defaultBranch: 'main' });
62
60
  }
63
61
  /**
64
62
  * Delete the local tracking files
@@ -66,12 +64,12 @@ class ShadowRepo {
66
64
  * @returns the deleted directory
67
65
  */
68
66
  async delete() {
69
- if (typeof core_1.fs.promises.rm === 'function') {
70
- await core_1.fs.promises.rm(this.gitDir, { recursive: true, force: true });
67
+ if (typeof fs.promises.rm === 'function') {
68
+ await fs.promises.rm(this.gitDir, { recursive: true, force: true });
71
69
  }
72
70
  else {
73
71
  // when node 12 support is over, switch to promise version
74
- core_1.fs.rmdirSync(this.gitDir, { recursive: true });
72
+ fs.rmdirSync(this.gitDir, { recursive: true });
75
73
  }
76
74
  return this.gitDir;
77
75
  }
@@ -85,37 +83,34 @@ class ShadowRepo {
85
83
  */
86
84
  async getStatus(noCache = false) {
87
85
  if (!this.status || noCache) {
88
- try {
89
- // only ask about OS once but use twice
90
- const isWindows = os.type() === 'Windows_NT';
91
- await this.stashIgnoreFile();
92
- const filepaths = isWindows
93
- ? // iso-git uses posix paths, but packageDirs has already normalized them so we need to convert if windows
94
- this.packageDirs.map((dir) => dir.path.split(path.sep).join(path.posix.sep))
95
- : this.packageDirs.map((dir) => dir.path);
96
- // status hasn't been initalized yet
97
- this.status = await git.statusMatrix({
98
- fs: core_1.fs,
99
- dir: this.projectPath,
100
- gitdir: this.gitDir,
101
- filepaths,
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)),
111
- });
112
- // isomorphic-git stores things in unix-style tree. Convert to windows-style if necessary
113
- if (isWindows) {
114
- this.status = this.status.map((row) => [path.normalize(row[FILE]), row[HEAD], row[WORKDIR], row[3]]);
115
- }
116
- }
117
- finally {
118
- await this.unStashIgnoreFile();
86
+ // only ask about OS once but use twice
87
+ const isWindows = os.type() === 'Windows_NT';
88
+ // iso-git uses relative, posix paths
89
+ // but packageDirs has already resolved / normalized them
90
+ // so we need to make them project-relative again and convert if windows
91
+ const filepaths = this.packageDirs
92
+ .map((dir) => path.relative(this.projectPath, dir.fullPath))
93
+ .map((p) => (isWindows ? p.split(path.sep).join(path.posix.sep) : p));
94
+ // status hasn't been initalized yet
95
+ this.status = await git.statusMatrix({
96
+ fs,
97
+ dir: this.projectPath,
98
+ gitdir: this.gitDir,
99
+ filepaths,
100
+ ignored: true,
101
+ filter: (f) =>
102
+ // no hidden files
103
+ !f.includes(`${path.sep}.`) &&
104
+ // no lwc tests
105
+ !f.includes('__tests__') &&
106
+ // no gitignore files
107
+ !f.endsWith(gitIgnoreFileName) &&
108
+ // isogit uses `startsWith` for filepaths so it's possible to get a false positive
109
+ filepaths.some((pkgDir) => (0, functions_1.pathIsInFolder)(f, pkgDir)),
110
+ });
111
+ // isomorphic-git stores things in unix-style tree. Convert to windows-style if necessary
112
+ if (isWindows) {
113
+ this.status = this.status.map((row) => [path.normalize(row[FILE]), row[HEAD], row[WORKDIR], row[3]]);
119
114
  }
120
115
  }
121
116
  return this.status;
@@ -173,61 +168,41 @@ class ShadowRepo {
173
168
  *
174
169
  * @returns sha (string)
175
170
  */
176
- async commitChanges({ deployedFiles = [], deletedFiles = [], message = 'sfdx source tracking', } = {}) {
171
+ async commitChanges({ deployedFiles = [], deletedFiles = [], message = 'sfdx source tracking', needsUpdatedStatus = true, } = {}) {
177
172
  // if no files are specified, commit all changes
178
173
  if (deployedFiles.length === 0 && deletedFiles.length === 0) {
179
174
  // this is valid, might not be an error
180
175
  return 'no files to commit';
181
176
  }
182
- this.logger.debug('changes are', deployedFiles);
183
- this.logger.debug('deletes are', deletedFiles);
184
- await this.stashIgnoreFile();
185
177
  // these are stored in posix/style/path format. We have to convert inbound stuff from windows
186
178
  if (os.type() === 'Windows_NT') {
187
179
  deployedFiles = deployedFiles.map((filepath) => path.normalize(filepath).split(path.sep).join(path.posix.sep));
188
180
  deletedFiles = deletedFiles.map((filepath) => path.normalize(filepath).split(path.sep).join(path.posix.sep));
189
181
  }
190
- try {
191
- // stage changes
192
- await Promise.all([
193
- ...deployedFiles.map((filepath) => git.add({ fs: core_1.fs, dir: this.projectPath, gitdir: this.gitDir, filepath })),
194
- ...deletedFiles.map((filepath) => git.remove({ fs: core_1.fs, dir: this.projectPath, gitdir: this.gitDir, filepath })),
195
- ]);
196
- const sha = await git.commit({
197
- fs: core_1.fs,
182
+ if (deployedFiles.length) {
183
+ await git.add({
184
+ fs,
198
185
  dir: this.projectPath,
199
186
  gitdir: this.gitDir,
200
- message,
201
- author: { name: 'sfdx source tracking' },
187
+ filepath: [...new Set(deployedFiles)],
188
+ force: true,
202
189
  });
203
- // status changed as a result of the commit. This prevents users from having to run getStatus(true) to avoid cache
204
- await this.getStatus(true);
205
- return sha;
206
190
  }
207
- finally {
208
- await this.unStashIgnoreFile();
191
+ for (const filepath of [...new Set(deletedFiles)]) {
192
+ await git.remove({ fs, dir: this.projectPath, gitdir: this.gitDir, filepath });
209
193
  }
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,
194
+ const sha = await git.commit({
195
+ fs,
215
196
  dir: this.projectPath,
216
197
  gitdir: this.gitDir,
217
- trees: [git.WORKDIR()],
218
- // eslint-disable-next-line @typescript-eslint/require-await
219
- map: async (filepath) => filepath,
220
- }))
221
- .filter((filepath) => filepath.includes(gitIgnoreFileName))
222
- .map((ignoreFile) => path.join(this.projectPath, ignoreFile));
223
- }
224
- async stashIgnoreFile() {
225
- // allSettled allows them to fail (example, the file wasn't where it was expected).
226
- await Promise.allSettled(this.gitIgnoreLocations.map((originalLocation) => core_1.fs.promises.rename(originalLocation, originalLocation.replace(gitIgnoreFileName, stashedGitIgnoreFileName))));
227
- }
228
- async unStashIgnoreFile() {
229
- // allSettled allows them to fail (example, the file wasn't where it was expected).
230
- await Promise.allSettled(this.gitIgnoreLocations.map((originalLocation) => core_1.fs.promises.rename(originalLocation.replace(gitIgnoreFileName, stashedGitIgnoreFileName), originalLocation)));
198
+ message,
199
+ author: { name: 'sfdx source tracking' },
200
+ });
201
+ // status changed as a result of the commit. This prevents users from having to run getStatus(true) to avoid cache
202
+ if (needsUpdatedStatus) {
203
+ await this.getStatus(true);
204
+ }
205
+ return sha;
231
206
  }
232
207
  }
233
208
  exports.ShadowRepo = ShadowRepo;
@@ -11,6 +11,7 @@ var _a;
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.remoteChangeElementToChangeResult = exports.RemoteSourceTrackingService = void 0;
13
13
  const path = require("path");
14
+ const fs = require("fs");
14
15
  const ts_retry_promise_1 = require("ts-retry-promise");
15
16
  const core_1 = require("@salesforce/core");
16
17
  const source_deploy_retrieve_1 = require("@salesforce/source-deploy-retrieve");
@@ -98,8 +99,8 @@ class RemoteSourceTrackingService extends core_1.ConfigFile {
98
99
  static async delete(orgId) {
99
100
  const fileToDelete = RemoteSourceTrackingService.getFilePath(orgId);
100
101
  // the file might not exist, in which case we don't need to delete it
101
- if (core_1.fs.existsSync(fileToDelete)) {
102
- await core_1.fs.promises.unlink(fileToDelete);
102
+ if (fs.existsSync(fileToDelete)) {
103
+ await fs.promises.unlink(fileToDelete);
103
104
  }
104
105
  return path.isAbsolute(fileToDelete) ? fileToDelete : path.join(process.cwd(), fileToDelete);
105
106
  }
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "sourceTrackingFileVersionMismatch": "This project uses the %s version of source tracking files.",
3
- "clearSuggestion": "Clear the %s version of the tracking files by running '%s'",
3
+ "clearSuggestion": "Push/Pull any local or remote changes. Then, clear the %s version of the tracking files by running '%s' followed by '%s'.",
4
4
  "useOtherVersion": "Use the %s version of the command, '%s' with your existing tracking files."
5
5
  }
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": "1.1.5",
4
+ "version": "1.2.0",
5
5
  "author": "Salesforce",
6
6
  "license": "BSD-3-Clause",
7
7
  "main": "lib/index.js",
@@ -46,7 +46,7 @@
46
46
  "@salesforce/core": "^2.33.1",
47
47
  "@salesforce/kit": "^1.5.17",
48
48
  "@salesforce/source-deploy-retrieve": "^5.9.4",
49
- "isomorphic-git": "^1.9.2",
49
+ "isomorphic-git": "1.16.0",
50
50
  "ts-retry-promise": "^0.6.0"
51
51
  },
52
52
  "devDependencies": {