@salesforce/source-tracking 1.1.7 → 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,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
+ ## [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
+
5
16
  ### [1.1.7](https://github.com/forcedotcom/source-tracking/compare/v1.1.6...v1.1.7) (2022-03-16)
6
17
 
7
18
  ### Bug Fixes
@@ -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
@@ -18,7 +18,6 @@ export declare class ShadowRepo {
18
18
  private packageDirs;
19
19
  private status;
20
20
  private logger;
21
- private gitIgnoreLocations;
22
21
  private constructor();
23
22
  static getInstance(options: ShadowRepoOptions): Promise<ShadowRepo>;
24
23
  init(): Promise<void>;
@@ -76,8 +75,5 @@ export declare class ShadowRepo {
76
75
  * @returns sha (string)
77
76
  */
78
77
  commitChanges({ deployedFiles, deletedFiles, message, needsUpdatedStatus, }?: CommitRequest): Promise<string>;
79
- private locateIgnoreFiles;
80
- private stashIgnoreFile;
81
- private unStashIgnoreFile;
82
78
  }
83
79
  export {};
@@ -15,7 +15,6 @@ const core_1 = require("@salesforce/core");
15
15
  const git = require("isomorphic-git");
16
16
  const functions_1 = require("./functions");
17
17
  const gitIgnoreFileName = '.gitignore';
18
- const stashedGitIgnoreFileName = '.BAK.gitignore';
19
18
  /**
20
19
  * returns the full path to where we store the shadow repo
21
20
  */
@@ -30,7 +29,6 @@ const HEAD = 1;
30
29
  const WORKDIR = 2;
31
30
  class ShadowRepo {
32
31
  constructor(options) {
33
- this.gitIgnoreLocations = [];
34
32
  this.gitDir = getGitDir(options.orgId, options.projectPath);
35
33
  this.projectPath = options.projectPath;
36
34
  this.packageDirs = options.packageDirs;
@@ -51,7 +49,6 @@ class ShadowRepo {
51
49
  this.logger.debug('initializing git repo');
52
50
  await this.gitInit();
53
51
  }
54
- await this.locateIgnoreFiles();
55
52
  }
56
53
  /**
57
54
  * Initialize a new source tracking shadow repo. Think of git init
@@ -86,37 +83,34 @@ class ShadowRepo {
86
83
  */
87
84
  async getStatus(noCache = false) {
88
85
  if (!this.status || noCache) {
89
- try {
90
- // only ask about OS once but use twice
91
- const isWindows = os.type() === 'Windows_NT';
92
- await this.stashIgnoreFile();
93
- const filepaths = isWindows
94
- ? // iso-git uses posix paths, but packageDirs has already normalized them so we need to convert if windows
95
- this.packageDirs.map((dir) => dir.path.split(path.sep).join(path.posix.sep))
96
- : this.packageDirs.map((dir) => dir.path);
97
- // status hasn't been initalized yet
98
- this.status = await git.statusMatrix({
99
- fs,
100
- dir: this.projectPath,
101
- gitdir: this.gitDir,
102
- filepaths,
103
- filter: (f) =>
104
- // no hidden files
105
- !f.includes(`${path.sep}.`) &&
106
- // no lwc tests
107
- !f.includes('__tests__') &&
108
- // no gitignore files
109
- ![gitIgnoreFileName, stashedGitIgnoreFileName].includes(path.basename(f)) &&
110
- // isogit uses `startsWith` for filepaths so it's possible to get a false positive
111
- filepaths.some((pkgDir) => (0, functions_1.pathIsInFolder)(f, pkgDir)),
112
- });
113
- // isomorphic-git stores things in unix-style tree. Convert to windows-style if necessary
114
- if (isWindows) {
115
- this.status = this.status.map((row) => [path.normalize(row[FILE]), row[HEAD], row[WORKDIR], row[3]]);
116
- }
117
- }
118
- finally {
119
- 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]]);
120
114
  }
121
115
  }
122
116
  return this.status;
@@ -180,56 +174,35 @@ class ShadowRepo {
180
174
  // this is valid, might not be an error
181
175
  return 'no files to commit';
182
176
  }
183
- await this.stashIgnoreFile();
184
177
  // these are stored in posix/style/path format. We have to convert inbound stuff from windows
185
178
  if (os.type() === 'Windows_NT') {
186
179
  deployedFiles = deployedFiles.map((filepath) => path.normalize(filepath).split(path.sep).join(path.posix.sep));
187
180
  deletedFiles = deletedFiles.map((filepath) => path.normalize(filepath).split(path.sep).join(path.posix.sep));
188
181
  }
189
- try {
190
- if (deployedFiles.length) {
191
- await git.add({ fs, dir: this.projectPath, gitdir: this.gitDir, filepath: [...new Set(deployedFiles)] });
192
- }
193
- for (const filepath of [...new Set(deletedFiles)]) {
194
- await git.remove({ fs, dir: this.projectPath, gitdir: this.gitDir, filepath });
195
- }
196
- const sha = await git.commit({
182
+ if (deployedFiles.length) {
183
+ await git.add({
197
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
- if (needsUpdatedStatus) {
205
- await this.getStatus(true);
206
- }
207
- return sha;
208
190
  }
209
- finally {
210
- await this.unStashIgnoreFile();
191
+ for (const filepath of [...new Set(deletedFiles)]) {
192
+ await git.remove({ fs, dir: this.projectPath, gitdir: this.gitDir, filepath });
211
193
  }
212
- }
213
- async locateIgnoreFiles() {
214
- // set the gitIgnoreLocations so we only have to do it once
215
- this.gitIgnoreLocations = (await git.walk({
194
+ const sha = await git.commit({
216
195
  fs,
217
196
  dir: this.projectPath,
218
197
  gitdir: this.gitDir,
219
- trees: [git.WORKDIR()],
220
- // eslint-disable-next-line @typescript-eslint/require-await
221
- map: async (filepath) => filepath,
222
- }))
223
- .filter((filepath) => filepath.includes(gitIgnoreFileName))
224
- .map((ignoreFile) => path.join(this.projectPath, ignoreFile));
225
- }
226
- async stashIgnoreFile() {
227
- // allSettled allows them to fail (example, the file wasn't where it was expected).
228
- await Promise.allSettled(this.gitIgnoreLocations.map((originalLocation) => fs.promises.rename(originalLocation, originalLocation.replace(gitIgnoreFileName, stashedGitIgnoreFileName))));
229
- }
230
- async unStashIgnoreFile() {
231
- // allSettled allows them to fail (example, the file wasn't where it was expected).
232
- await Promise.allSettled(this.gitIgnoreLocations.map((originalLocation) => 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;
233
206
  }
234
207
  }
235
208
  exports.ShadowRepo = ShadowRepo;
@@ -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.7",
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.14.0",
49
+ "isomorphic-git": "1.16.0",
50
50
  "ts-retry-promise": "^0.6.0"
51
51
  },
52
52
  "devDependencies": {