@salesforce/source-tracking 0.3.0 → 0.4.3

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 ADDED
@@ -0,0 +1,91 @@
1
+ # Changelog
2
+
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
+
5
+ ### [0.4.3](https://github.com/forcedotcom/source-tracking/compare/v0.4.2...v0.4.3) (2021-11-11)
6
+
7
+
8
+ ### Features
9
+
10
+ * emit warnings for types not pulled ([fdeabbf](https://github.com/forcedotcom/source-tracking/commit/fdeabbfb11bb4ba1fd17931adedc49f9cb5ae658))
11
+
12
+
13
+ ### Bug Fixes
14
+
15
+ * don't pull remote changes where type isn't in SDR registry ([46250ee](https://github.com/forcedotcom/source-tracking/commit/46250eef09e29dfa0d06af984bbfcc3e88765968))
16
+ * don't pull things not in the registry ([38136bb](https://github.com/forcedotcom/source-tracking/commit/38136bbbf1e44c8e58bc06621957819913273b4e))
17
+
18
+ ### [0.4.2](https://github.com/forcedotcom/source-tracking/compare/v0.4.1...v0.4.2) (2021-10-28)
19
+
20
+ ### [0.4.1](https://github.com/forcedotcom/source-tracking/compare/v0.4.0...v0.4.1) (2021-10-28)
21
+
22
+
23
+ ### Bug Fixes
24
+
25
+ * better conflict handling (can match filenames or type/name) ([4441a0a](https://github.com/forcedotcom/source-tracking/commit/4441a0abd70c7f8f315e1c638b4cef7fcf3e2e68))
26
+ * gitignore stashing location ([5145545](https://github.com/forcedotcom/source-tracking/commit/5145545eeee6c800986014327479d20e943143e5))
27
+ * polling exclusion logic for aura meta.xml was wrong ([2d40b2e](https://github.com/forcedotcom/source-tracking/commit/2d40b2ef65ef9a3145d0c75cd4943e4325d5745c))
28
+
29
+ ## 0.4.0 (2021-10-22)
30
+
31
+
32
+ ### ⚠ BREAKING CHANGES
33
+
34
+ * remove retrieve simplifier
35
+
36
+ ### Features
37
+
38
+ * add commitlint and sample circleci config ([43e7fa4](https://github.com/forcedotcom/source-tracking/commit/43e7fa4a44dbcb9da37d21618678687f4edda644))
39
+ * add new tests and upadte readme ([6a7ad54](https://github.com/forcedotcom/source-tracking/commit/6a7ad542f42ce75275ebacc78d50ee4dc0ab6f32))
40
+ * add option to get remoteChanges with filePaths, use for Conflicts ([350a0d6](https://github.com/forcedotcom/source-tracking/commit/350a0d60599cfce2c432c223f4523c25a4f53c81))
41
+ * basic using isogit ([f39e6c5](https://github.com/forcedotcom/source-tracking/commit/f39e6c5e305fcb2fdb6a27b343d9dc20800202c9))
42
+ * conflict detection ([3e22774](https://github.com/forcedotcom/source-tracking/commit/3e22774d8949a1aa4302e62d8580b69c4b35aab5))
43
+ * consolidate conflict handling, return data in error ([45178c7](https://github.com/forcedotcom/source-tracking/commit/45178c7b13ed61e657f9a07ea5b40f49f73f651a))
44
+ * delete handling public for pull ([eb87eb7](https://github.com/forcedotcom/source-tracking/commit/eb87eb7dfa81ba5256735af7f2b8bc29dfb1e16b))
45
+ * finish status, add clear/reset ([c71e66f](https://github.com/forcedotcom/source-tracking/commit/c71e66f7f7a3dc20d2c965349b5e01e15edabf36))
46
+ * handle status ignore marking from STL ([2ec6fad](https://github.com/forcedotcom/source-tracking/commit/2ec6fad4b4f4f2e124da7e4f53cf8e534354d342))
47
+ * ignorewarnings flag for push ([b13fd05](https://github.com/forcedotcom/source-tracking/commit/b13fd0534930fb063075c39e6f75ea46ab9d3be8))
48
+ * migrate messages/descriptions ([8fea6e5](https://github.com/forcedotcom/source-tracking/commit/8fea6e5242c50865dd635412d7592164ab57fec4))
49
+ * most of sourceStatus logic, code cleanup ([f100cb8](https://github.com/forcedotcom/source-tracking/commit/f100cb83f220b3724284ae69301712a08b14376d))
50
+ * non-delete push works ([487a20e](https://github.com/forcedotcom/source-tracking/commit/487a20e48c428a02ef315b58db24b714d2de0416))
51
+ * push supporting bundle types ([639d459](https://github.com/forcedotcom/source-tracking/commit/639d459101cd4990fa217f657b99d64517611383))
52
+ * remote and conflicts ([f98ecf1](https://github.com/forcedotcom/source-tracking/commit/f98ecf17fc6cbe386d8edae6994500388b7e0ed6))
53
+ * remote tracknig with UT ([cb805e5](https://github.com/forcedotcom/source-tracking/commit/cb805e5745020be9a266a261f584979713e4b351))
54
+ * source tracking from toolbelt ([6c2ebb4](https://github.com/forcedotcom/source-tracking/commit/6c2ebb444ce5518eaa81402b685fe00f1090e437))
55
+ * sourcemember polling like toolbelt ([abdd7b3](https://github.com/forcedotcom/source-tracking/commit/abdd7b3ad275ea4739673a6e1b1a99853f1de2da))
56
+ * spinners while waiting on pull ([dfe5aea](https://github.com/forcedotcom/source-tracking/commit/dfe5aeae0a5f9a30eddfe96852e0dab025972e1e))
57
+ * status result sorting ([b7b109c](https://github.com/forcedotcom/source-tracking/commit/b7b109cf3e7bcad60507618099873c717ff31f61))
58
+ * sync customObj when their fields sync ([3ded96d](https://github.com/forcedotcom/source-tracking/commit/3ded96dbd7a7ea45cb8f97719b98bae294905c05))
59
+ * throws if "old" source files are present ([4b868d8](https://github.com/forcedotcom/source-tracking/commit/4b868d8232769eec5e227052bf823a35baedd288))
60
+ * typed push ([6e76812](https://github.com/forcedotcom/source-tracking/commit/6e7681263b81d3b692d002a3ce5deb8ef00bbd13))
61
+ * virtualTree for deletes ([b425d77](https://github.com/forcedotcom/source-tracking/commit/b425d77b4fca5c6fbab2faab7490e3516bf3f547))
62
+
63
+
64
+ ### Bug Fixes
65
+
66
+ * again with the promises ([ad9dec5](https://github.com/forcedotcom/source-tracking/commit/ad9dec50336c61996456d48ee489426393c62329))
67
+ * another attempt at node12 support ([c8736d0](https://github.com/forcedotcom/source-tracking/commit/c8736d0bbe53756d1b5572e00402e55af94003c1))
68
+ * case of empty orgId dir ([1cb6333](https://github.com/forcedotcom/source-tracking/commit/1cb6333d14cfcee02b27711b6db273d5db31fc8e))
69
+ * case on formatter filename ([02adf22](https://github.com/forcedotcom/source-tracking/commit/02adf22419d2bf81fb070d7d7d90f7d996bd1ada))
70
+ * casing on imports ([d4425d9](https://github.com/forcedotcom/source-tracking/commit/d4425d9ee2ad77c4e28d32333025e59a3c7e3af9))
71
+ * correct statusCommand description ([b834a2f](https://github.com/forcedotcom/source-tracking/commit/b834a2fa0213fbc72dbc6dc3a563cd92f413d222))
72
+ * don't commit empty changelists ([67b9772](https://github.com/forcedotcom/source-tracking/commit/67b9772eccd6d2d4850322eb80f5a6113aac18e6))
73
+ * export compatibility ([c6e5f7c](https://github.com/forcedotcom/source-tracking/commit/c6e5f7cba68ed6a7739b237adb027fda2442e8c4))
74
+ * fix vscode image in readme ([441c15f](https://github.com/forcedotcom/source-tracking/commit/441c15f79dbaf4a97c84d9d6ddc923eae59bca34))
75
+ * handle org:create's single tracking file ([008793d](https://github.com/forcedotcom/source-tracking/commit/008793d0fa15210ffb263cc5d179a0be8dcb05ff))
76
+ * handle stash failures ([09dacc9](https://github.com/forcedotcom/source-tracking/commit/09dacc9484e48f3cba4813f3d733c66d2a30cd6b))
77
+ * leif .yml merge [skip-validate-pr] ([ff10f84](https://github.com/forcedotcom/source-tracking/commit/ff10f84ec15757df55657ba73cc6976c5892595c))
78
+ * local ST uses graceful via core2 ([3ba883f](https://github.com/forcedotcom/source-tracking/commit/3ba883ff2b02e27b0eb01a709f6c1e03ef91bb73))
79
+ * match server subfiles with forward slash ([c2489a6](https://github.com/forcedotcom/source-tracking/commit/c2489a62c244a64fe0938e0eecdc087f4529b5ad))
80
+ * normalize windows paths on commit, too ([4339e46](https://github.com/forcedotcom/source-tracking/commit/4339e46a1cb9cbeb4cc652572e340b60e3b5bc68))
81
+ * one more fs/promises fixed for node12 ([71bafcf](https://github.com/forcedotcom/source-tracking/commit/71bafcf7738e60d8b86150199ef8d0687167a010))
82
+ * path normalizing for metadata keys ([6190590](https://github.com/forcedotcom/source-tracking/commit/6190590df2c2e7cc9a25eab0fa8891e3b8df9057))
83
+ * path normalizing from iso-git ([b8cddaf](https://github.com/forcedotcom/source-tracking/commit/b8cddaf40930bedd18f3edec578a030220454627))
84
+ * status output on windows uses backslash ([78ac398](https://github.com/forcedotcom/source-tracking/commit/78ac3988d3d04e956f17f35c67de4d1144062fcb))
85
+ * support windows path on commits with \\ ([5712af4](https://github.com/forcedotcom/source-tracking/commit/5712af4447ee03e30d7a5a769fc5ba58f6913552))
86
+ * there could be nested LWC templates ([d833981](https://github.com/forcedotcom/source-tracking/commit/d8339810bf76c0ab75824faee7aef59ff9a2d89e))
87
+ * turns bundle parts of SourceMembers into real MDtypes ([5646042](https://github.com/forcedotcom/source-tracking/commit/564604269be7d56499963699b51920b81227297f))
88
+ * use correct var name ([0708312](https://github.com/forcedotcom/source-tracking/commit/0708312c5b4f11cb94539416d0a10b5432850310))
89
+
90
+
91
+ * remove retrieve simplifier ([bd71eef](https://github.com/forcedotcom/source-tracking/commit/bd71eef784bc7c7efd1999ba11193e632aef3d47))
package/README.md CHANGED
@@ -20,7 +20,7 @@ const tracking = await SourceTracking.create({
20
20
 
21
21
  Any calls to methods on your instance of `tracking` will check to make sure that the appropriate remote/local files are up to date and loaded.
22
22
 
23
- If you know you need to access remote or local, you can `ensure` them so that the FS and API operations don't happen multiple time (useful before calling operations in that run parallel)
23
+ If you know you need to access remote or local, you can `ensure` them so that the FS and API operations don't happen multiple time (useful before calling operations that run in parallel)
24
24
 
25
25
  ```ts
26
26
  await tracking.ensureRemoteTracking(); // pass `true` if you know you need to force a re-query.
@@ -29,17 +29,17 @@ await tracking.ensureRemoteTracking(); // pass `true` if you know you need to fo
29
29
  await tracking.ensureLocalTracking();
30
30
  ```
31
31
 
32
- ### Use cases:
32
+ ## Use cases
33
33
 
34
34
  1. push,pull,status: `getConflicts()`, `getChanges()`
35
35
  1. deploy/retrieve: `updateLocalTracking()`,`updateRemoteTracking`
36
36
 
37
- ## Deploy:
37
+ ### Deploy
38
38
 
39
39
  1. Once your SDR-based deploy finishes, you need to update the client's tracking files for both local (because local files went to the server) AND remote (because your deployment will result in new SourceMembers that need to be synced to the client).
40
40
 
41
41
  ```ts
42
- // send it an two arrays of Files (nonDeletes and Deletes)
42
+ // send in two arrays of Files (nonDeletes and Deletes)
43
43
  await tracking.updateLocalTracking({
44
44
  deployedFiles: ['force-app/main/default/classes/MyClass.cls', 'force-app/main/default/classes/MyClass.cls-meta.xml'],
45
45
  deletedFiles: [],
@@ -63,7 +63,7 @@ await tracking.updateRemoteTracking([
63
63
  ]);
64
64
  ```
65
65
 
66
- ## Retrieve:
66
+ ### Retrieve
67
67
 
68
68
  Once your retrieve finishes, use the same updateLocalTracking as you did for deploy to commit the file changes to local and remote changes.
69
69
 
@@ -93,7 +93,7 @@ await tracking.updateRemoteTracking(
93
93
  NUT for tracking file compatibility check logic
94
94
  pollSourceMembers should better handle aggregated types. ex:
95
95
 
96
- ```
96
+ ```txt
97
97
  DEBUG Could not find 2 SourceMembers (using ebikes): AuraDefinition__pageTemplate_2_7_3/pageTemplate_2_7_3.cmp-meta.xml,[object Object],CustomObject__Account,[object Object]
98
98
  ```
99
99
 
@@ -3,11 +3,14 @@ declare type TrackingFileVersion = 'plugin-source' | 'toolbelt' | 'none';
3
3
  /**
4
4
  * A project can have "old" (toolbelt), "new" (plugin-source) or "none" tracking files
5
5
  *
6
+ * @deprecated use only during transition to new source-tracking commands
6
7
  */
7
8
  export declare const getTrackingFileVersion: (org: Org, projectPath: string) => TrackingFileVersion;
8
9
  /**
9
10
  * Convenient wrapper for throwing errors with helpful messages so commands don't have to
10
11
  *
12
+ * @deprecated use only during transition to new source-tracking commands
13
+ *
11
14
  * @param org: an Org, typically from a command's this.org
12
15
  * @param project: the project path, typically from this.project.
13
16
  * @param toValidate: whether your command lives in 'toolbelt' or 'plugin-source'
@@ -20,11 +23,10 @@ export declare const throwIfInvalid: ({ org, projectPath, toValidate, command, }
20
23
  command: string;
21
24
  }) => void;
22
25
  /**
23
- *
26
+ * @deprecated use only during transition to new source-tracking commands
24
27
  * @param input the string that might contain things that would be replaced
25
28
  * @param reverse use the mappings backward
26
29
  * @returns string
27
30
  */
28
31
  export declare const replaceRenamedCommands: (input: string, reverse?: boolean) => string;
29
- export declare const renames: Map<string, string>;
30
32
  export {};
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.renames = exports.replaceRenamedCommands = exports.throwIfInvalid = exports.getTrackingFileVersion = void 0;
3
+ exports.replaceRenamedCommands = exports.throwIfInvalid = exports.getTrackingFileVersion = void 0;
4
4
  /*
5
5
  * Copyright (c) 2020, salesforce.com, inc.
6
6
  * All rights reserved.
@@ -15,6 +15,7 @@ const messages = core_1.Messages.loadMessages('@salesforce/source-tracking', 'co
15
15
  /**
16
16
  * A project can have "old" (toolbelt), "new" (plugin-source) or "none" tracking files
17
17
  *
18
+ * @deprecated use only during transition to new source-tracking commands
18
19
  */
19
20
  const getTrackingFileVersion = (org, projectPath) => {
20
21
  const orgsDir = path.join(projectPath, '.sfdx', 'orgs');
@@ -38,6 +39,8 @@ exports.getTrackingFileVersion = getTrackingFileVersion;
38
39
  /**
39
40
  * Convenient wrapper for throwing errors with helpful messages so commands don't have to
40
41
  *
42
+ * @deprecated use only during transition to new source-tracking commands
43
+ *
41
44
  * @param org: an Org, typically from a command's this.org
42
45
  * @param project: the project path, typically from this.project.
43
46
  * @param toValidate: whether your command lives in 'toolbelt' or 'plugin-source'
@@ -65,19 +68,19 @@ const throwIfInvalid = ({ org, projectPath, toValidate, command, }) => {
65
68
  };
66
69
  exports.throwIfInvalid = throwIfInvalid;
67
70
  /**
68
- *
71
+ * @deprecated use only during transition to new source-tracking commands
69
72
  * @param input the string that might contain things that would be replaced
70
73
  * @param reverse use the mappings backward
71
74
  * @returns string
72
75
  */
73
76
  const replaceRenamedCommands = (input, reverse = false) => {
74
- exports.renames.forEach((value, key) => {
77
+ renames.forEach((value, key) => {
75
78
  input = reverse ? input.replace(value, key) : input.replace(key, value);
76
79
  });
77
80
  return input;
78
81
  };
79
82
  exports.replaceRenamedCommands = replaceRenamedCommands;
80
- exports.renames = new Map([
83
+ const renames = new Map([
81
84
  ['force:source:status', 'force:source:beta:status'],
82
85
  ['force:source:push', 'force:source:beta:push'],
83
86
  ['force:source:pull', 'force:source:beta:pull'],
package/lib/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './sourceTracking';
2
2
  export * from './compatibility';
3
- export { RemoteSyncInput } from './shared/types';
3
+ export { RemoteSyncInput, ChangeOptionType, ChangeOptions, LocalUpdateOptions, ChangeResult, ConflictError, StatusOutputRow, } from './shared/types';
4
+ export { getKeyFromObject } from './shared/functions';
package/lib/index.js CHANGED
@@ -16,6 +16,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
17
17
  };
18
18
  Object.defineProperty(exports, "__esModule", { value: true });
19
+ exports.getKeyFromObject = void 0;
19
20
  __exportStar(require("./sourceTracking"), exports);
20
21
  __exportStar(require("./compatibility"), exports);
22
+ var functions_1 = require("./shared/functions");
23
+ Object.defineProperty(exports, "getKeyFromObject", { enumerable: true, get: function () { return functions_1.getKeyFromObject; } });
21
24
  //# sourceMappingURL=index.js.map
@@ -1,5 +1,6 @@
1
1
  import { VirtualTreeContainer } from '@salesforce/source-deploy-retrieve';
2
2
  /**
3
+ * @deprecated this is moving to SDR
3
4
  * Designed for recreating virtual files from deleted files where the only information we have is the file's former location
4
5
  * Any use of MetadataResolver was trying to access the non-existent files and throwing
5
6
  *
@@ -10,6 +10,7 @@ exports.filenamesToVirtualTree = void 0;
10
10
  const path = require("path");
11
11
  const source_deploy_retrieve_1 = require("@salesforce/source-deploy-retrieve");
12
12
  /**
13
+ * @deprecated this is moving to SDR
13
14
  * Designed for recreating virtual files from deleted files where the only information we have is the file's former location
14
15
  * Any use of MetadataResolver was trying to access the non-existent files and throwing
15
16
  *
@@ -0,0 +1,3 @@
1
+ import { RemoteChangeElement, ChangeResult } from './types';
2
+ export declare const getMetadataKey: (metadataType: string, metadataName: string) => string;
3
+ export declare const getKeyFromObject: (element: RemoteChangeElement | ChangeResult) => string;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2020, salesforce.com, inc.
4
+ * All rights reserved.
5
+ * Licensed under the BSD 3-Clause license.
6
+ * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.getKeyFromObject = exports.getMetadataKey = void 0;
10
+ const getMetadataKey = (metadataType, metadataName) => {
11
+ return `${metadataType}__${metadataName}`;
12
+ };
13
+ exports.getMetadataKey = getMetadataKey;
14
+ const getKeyFromObject = (element) => {
15
+ if (element.type && element.name) {
16
+ return (0, exports.getMetadataKey)(element.type, element.name);
17
+ }
18
+ throw new Error(`unable to complete key from ${JSON.stringify(element)}`);
19
+ };
20
+ exports.getKeyFromObject = getKeyFromObject;
21
+ //# sourceMappingURL=functions.js.map
@@ -0,0 +1,4 @@
1
+ import { SourceComponent, MetadataMember } from '@salesforce/source-deploy-retrieve';
2
+ export declare const stringGuard: (input: string | undefined) => input is string;
3
+ export declare const sourceComponentGuard: (input: SourceComponent | undefined) => input is SourceComponent;
4
+ export declare const metadataMemberGuard: (input: MetadataMember | undefined) => input is MetadataMember;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.metadataMemberGuard = exports.sourceComponentGuard = exports.stringGuard = void 0;
4
+ /*
5
+ * Copyright (c) 2020, salesforce.com, inc.
6
+ * All rights reserved.
7
+ * Licensed under the BSD 3-Clause license.
8
+ * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
9
+ */
10
+ const source_deploy_retrieve_1 = require("@salesforce/source-deploy-retrieve");
11
+ const stringGuard = (input) => {
12
+ return typeof input === 'string';
13
+ };
14
+ exports.stringGuard = stringGuard;
15
+ const sourceComponentGuard = (input) => {
16
+ return input instanceof source_deploy_retrieve_1.SourceComponent;
17
+ };
18
+ exports.sourceComponentGuard = sourceComponentGuard;
19
+ const metadataMemberGuard = (input) => {
20
+ return input !== undefined && typeof input.fullName === 'string' && typeof input.type === 'string';
21
+ };
22
+ exports.metadataMemberGuard = metadataMemberGuard;
23
+ //# sourceMappingURL=guards.js.map
@@ -1,4 +1,3 @@
1
- import { AsyncCreatable } from '@salesforce/kit';
2
1
  import { NamedPackageDir } from '@salesforce/core';
3
2
  interface ShadowRepoOptions {
4
3
  orgId: string;
@@ -11,14 +10,15 @@ interface CommitRequest {
11
10
  deletedFiles?: string[];
12
11
  message?: string;
13
12
  }
14
- export declare class ShadowRepo extends AsyncCreatable<ShadowRepoOptions> {
13
+ export declare class ShadowRepo {
14
+ private static instance;
15
15
  gitDir: string;
16
16
  projectPath: string;
17
17
  private packageDirs;
18
18
  private status;
19
19
  private logger;
20
- private options;
21
- constructor(options: ShadowRepoOptions);
20
+ private constructor();
21
+ static getInstance(options: ShadowRepoOptions): Promise<ShadowRepo>;
22
22
  init(): Promise<void>;
23
23
  /**
24
24
  * Initialize a new source tracking shadow repo. Think of git init
@@ -10,9 +10,10 @@ 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 kit_1 = require("@salesforce/kit");
14
13
  const core_1 = require("@salesforce/core");
15
14
  const git = require("isomorphic-git");
15
+ const gitIgnoreFileName = '.gitignore';
16
+ const stashedGitIgnoreFileName = '.BAK.gitignore';
16
17
  /**
17
18
  * returns the full path to where we store the shadow repo
18
19
  */
@@ -25,17 +26,21 @@ const toFilenames = (rows) => rows.map((row) => row[FILE]);
25
26
  const FILE = 0;
26
27
  const HEAD = 1;
27
28
  const WORKDIR = 2;
28
- class ShadowRepo extends kit_1.AsyncCreatable {
29
+ class ShadowRepo {
29
30
  constructor(options) {
30
- super(options);
31
- this.options = options;
32
31
  this.gitDir = getGitDir(options.orgId, options.projectPath);
33
32
  this.projectPath = options.projectPath;
34
33
  this.packageDirs = options.packageDirs;
35
34
  }
35
+ static async getInstance(options) {
36
+ if (!ShadowRepo.instance) {
37
+ ShadowRepo.instance = new ShadowRepo(options);
38
+ await ShadowRepo.instance.init();
39
+ }
40
+ return ShadowRepo.instance;
41
+ }
36
42
  async init() {
37
43
  this.logger = await core_1.Logger.child('ShadowRepo');
38
- this.logger.debug('options for constructor are', this.options);
39
44
  // initialize the shadow repo if it doesn't exist
40
45
  if (!core_1.fs.existsSync(this.gitDir)) {
41
46
  this.logger.debug('initializing git repo');
@@ -75,21 +80,25 @@ class ShadowRepo extends kit_1.AsyncCreatable {
75
80
  */
76
81
  async getStatus(noCache = false) {
77
82
  if (!this.status || noCache) {
78
- await this.stashIgnoreFile();
79
- // status hasn't been initalized yet
80
- this.status = await git.statusMatrix({
81
- fs: core_1.fs,
82
- dir: this.projectPath,
83
- gitdir: this.gitDir,
84
- filepaths: this.packageDirs.map((dir) => dir.path),
85
- // filter out hidden files and __tests__ patterns, regardless of gitignore
86
- filter: (f) => !f.includes(`${path.sep}.`) && !f.includes('__tests__'),
87
- });
88
- // isomorphic-git stores things in unix-style tree. Convert to windows-style if necessary
89
- if (os.type() === 'Windows_NT') {
90
- this.status = this.status.map((row) => [path.normalize(row[FILE]), row[HEAD], row[WORKDIR], row[3]]);
83
+ try {
84
+ await this.stashIgnoreFile();
85
+ // status hasn't been initalized yet
86
+ this.status = await git.statusMatrix({
87
+ fs: core_1.fs,
88
+ dir: this.projectPath,
89
+ gitdir: this.gitDir,
90
+ filepaths: this.packageDirs.map((dir) => dir.path),
91
+ // filter out hidden files and __tests__ patterns, regardless of gitignore
92
+ filter: (f) => !f.includes(`${path.sep}.`) && !f.includes('__tests__'),
93
+ });
94
+ // isomorphic-git stores things in unix-style tree. Convert to windows-style if necessary
95
+ if (os.type() === 'Windows_NT') {
96
+ this.status = this.status.map((row) => [path.normalize(row[FILE]), row[HEAD], row[WORKDIR], row[3]]);
97
+ }
98
+ }
99
+ finally {
100
+ await this.unStashIgnoreFile();
91
101
  }
92
- await this.unStashIgnoreFile();
93
102
  }
94
103
  return this.status;
95
104
  }
@@ -149,8 +158,8 @@ class ShadowRepo extends kit_1.AsyncCreatable {
149
158
  async commitChanges({ deployedFiles = [], deletedFiles = [], message = 'sfdx source tracking', } = {}) {
150
159
  // if no files are specified, commit all changes
151
160
  if (deployedFiles.length === 0 && deletedFiles.length === 0) {
152
- deployedFiles = await this.getNonDeleteFilenames();
153
- deletedFiles = await this.getDeleteFilenames();
161
+ // this is valid, might not be an error
162
+ return 'no files to commit';
154
163
  }
155
164
  this.logger.debug('changes are', deployedFiles);
156
165
  this.logger.debug('deletes are', deletedFiles);
@@ -173,6 +182,8 @@ class ShadowRepo extends kit_1.AsyncCreatable {
173
182
  message,
174
183
  author: { name: 'sfdx source tracking' },
175
184
  });
185
+ // status changed as a result of the commit. This prevents users from having to run getStatus(true) to avoid cache
186
+ await this.getStatus(true);
176
187
  return sha;
177
188
  }
178
189
  finally {
@@ -180,17 +191,17 @@ class ShadowRepo extends kit_1.AsyncCreatable {
180
191
  }
181
192
  }
182
193
  async stashIgnoreFile() {
183
- const originalLocation = path.join(this.projectPath, '.gitignore');
194
+ const originalLocation = path.join(this.projectPath, gitIgnoreFileName);
184
195
  // another process may have already stashed the file
185
196
  if (core_1.fs.existsSync(originalLocation)) {
186
- await core_1.fs.promises.rename(originalLocation, path.join(this.projectPath, '.BAK.gitignore'));
197
+ await core_1.fs.promises.rename(originalLocation, path.join(this.projectPath, stashedGitIgnoreFileName));
187
198
  }
188
199
  }
189
200
  async unStashIgnoreFile() {
190
- const stashedLocation = path.join(this.projectPath, '.gitignore');
201
+ const stashedLocation = path.join(this.projectPath, stashedGitIgnoreFileName);
191
202
  // another process may have already un-stashed the file
192
203
  if (core_1.fs.existsSync(stashedLocation)) {
193
- await core_1.fs.promises.rename(stashedLocation, path.join(this.projectPath, '.gitignore'));
204
+ await core_1.fs.promises.rename(stashedLocation, path.join(this.projectPath, gitIgnoreFileName));
194
205
  }
195
206
  }
196
207
  }
@@ -8,7 +8,7 @@ exports.getMetadataKeyFromFileResponse = void 0;
8
8
  * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
9
9
  */
10
10
  const path = require("path");
11
- const remoteSourceTrackingService_1 = require("./remoteSourceTrackingService");
11
+ const functions_1 = require("./functions");
12
12
  // LWC can have child folders (ex: dynamic templates like /templates/noDataIllustration.html
13
13
  const pathAfterFullName = (fileResponse) => fileResponse && fileResponse.filePath
14
14
  ? fileResponse.filePath.substr(fileResponse.filePath.indexOf(fileResponse.fullName)).replace(/\\/gi, '/')
@@ -21,25 +21,25 @@ const getMetadataKeyFromFileResponse = (fileResponse) => {
21
21
  const splits = path.normalize(fileResponse.filePath).split(path.sep);
22
22
  const objectFolderIndex = splits.indexOf('objects');
23
23
  return [
24
- (0, remoteSourceTrackingService_1.getMetadataKey)('CustomObject', splits[objectFolderIndex + 1]),
25
- (0, remoteSourceTrackingService_1.getMetadataKey)(fileResponse.type, fileResponse.fullName),
24
+ (0, functions_1.getMetadataKey)('CustomObject', splits[objectFolderIndex + 1]),
25
+ (0, functions_1.getMetadataKey)(fileResponse.type, fileResponse.fullName),
26
26
  ];
27
27
  }
28
28
  // Aura/LWC need to have both the bundle level and file level keys
29
29
  if (fileResponse.type === 'LightningComponentBundle' && fileResponse.filePath) {
30
30
  return [
31
31
  `LightningComponentResource__${pathAfterFullName(fileResponse)}`,
32
- (0, remoteSourceTrackingService_1.getMetadataKey)(fileResponse.type, fileResponse.fullName),
32
+ (0, functions_1.getMetadataKey)(fileResponse.type, fileResponse.fullName),
33
33
  ];
34
34
  }
35
35
  if (fileResponse.type === 'AuraDefinitionBundle' && fileResponse.filePath) {
36
36
  return [
37
37
  `AuraDefinition__${pathAfterFullName(fileResponse)}`,
38
- (0, remoteSourceTrackingService_1.getMetadataKey)(fileResponse.type, fileResponse.fullName),
38
+ (0, functions_1.getMetadataKey)(fileResponse.type, fileResponse.fullName),
39
39
  ];
40
40
  }
41
41
  // standard key
42
- return [(0, remoteSourceTrackingService_1.getMetadataKey)(fileResponse.type, fileResponse.fullName)];
42
+ return [(0, functions_1.getMetadataKey)(fileResponse.type, fileResponse.fullName)];
43
43
  };
44
44
  exports.getMetadataKeyFromFileResponse = getMetadataKeyFromFileResponse;
45
45
  //# sourceMappingURL=metadataKeys.js.map
@@ -1,23 +1,5 @@
1
1
  import { ConfigFile, Logger } from '@salesforce/core';
2
- import { RemoteSyncInput } from '../shared/types';
3
- export declare type MemberRevision = {
4
- serverRevisionCounter: number;
5
- lastRetrievedFromServer: number | null;
6
- memberType: string;
7
- isNameObsolete: boolean;
8
- };
9
- export declare type SourceMember = {
10
- MemberType: string;
11
- MemberName: string;
12
- IsNameObsolete: boolean;
13
- RevisionCounter: number;
14
- };
15
- export declare type RemoteChangeElement = {
16
- name: string;
17
- type: string;
18
- deleted?: boolean;
19
- modified?: boolean;
20
- };
2
+ import { ChangeResult, RemoteChangeElement, SourceMember, RemoteSyncInput } from './types';
21
3
  export declare namespace RemoteSourceTrackingService {
22
4
  interface Options extends ConfigFile.Options {
23
5
  orgId: string;
@@ -25,7 +7,6 @@ export declare namespace RemoteSourceTrackingService {
25
7
  username: string;
26
8
  }
27
9
  }
28
- export declare const getMetadataKey: (metadataType: string, metadataName: string) => string;
29
10
  /**
30
11
  * This service handles source tracking of metadata between a local project and an org.
31
12
  * Source tracking state is persisted to .sfdx/orgs/<orgId>/maxRevision.json.
@@ -143,3 +124,8 @@ export declare class RemoteSourceTrackingService extends ConfigFile<RemoteSource
143
124
  private querySourceMembersTo;
144
125
  private query;
145
126
  }
127
+ /**
128
+ * pass in an RCE, and this will return a pullable ChangeResult.
129
+ * Useful for correcing bundle types where the files show change results with types but aren't resolvable
130
+ */
131
+ export declare const remoteChangeElementToChangeResult: (rce: RemoteChangeElement) => ChangeResult;
@@ -8,18 +8,14 @@
8
8
  /* eslint-disable no-underscore-dangle */
9
9
  /* eslint-disable @typescript-eslint/member-ordering */
10
10
  Object.defineProperty(exports, "__esModule", { value: true });
11
- exports.RemoteSourceTrackingService = exports.getMetadataKey = void 0;
11
+ exports.remoteChangeElementToChangeResult = exports.RemoteSourceTrackingService = void 0;
12
12
  const path = require("path");
13
- const fs = require("fs");
14
13
  const ts_retry_promise_1 = require("ts-retry-promise");
15
14
  const core_1 = require("@salesforce/core");
16
15
  const source_deploy_retrieve_1 = require("@salesforce/source-deploy-retrieve");
17
16
  const kit_1 = require("@salesforce/kit");
18
17
  const metadataKeys_1 = require("./metadataKeys");
19
- const getMetadataKey = (metadataType, metadataName) => {
20
- return `${metadataType}__${metadataName}`;
21
- };
22
- exports.getMetadataKey = getMetadataKey;
18
+ const functions_1 = require("./functions");
23
19
  /**
24
20
  * This service handles source tracking of metadata between a local project and an org.
25
21
  * Source tracking state is persisted to .sfdx/orgs/<orgId>/maxRevision.json.
@@ -89,8 +85,8 @@ class RemoteSourceTrackingService extends core_1.ConfigFile {
89
85
  static async delete(orgId) {
90
86
  const fileToDelete = RemoteSourceTrackingService.getFilePath(orgId);
91
87
  // the file might not exist, in which case we don't need to delete it
92
- if (fs.existsSync(fileToDelete)) {
93
- await fs.promises.unlink(fileToDelete);
88
+ if (core_1.fs.existsSync(fileToDelete)) {
89
+ await core_1.fs.promises.unlink(fileToDelete);
94
90
  }
95
91
  return path.isAbsolute(fileToDelete) ? fileToDelete : path.join(process.cwd(), fileToDelete);
96
92
  }
@@ -211,7 +207,7 @@ class RemoteSourceTrackingService extends core_1.ConfigFile {
211
207
  members = await this.querySourceMembersFrom({ fromRevision: 0 });
212
208
  }
213
209
  await this.trackSourceMembers(members, true);
214
- return members.map((member) => (0, exports.getMetadataKey)(member.MemberType, member.MemberName));
210
+ return members.map((member) => (0, functions_1.getMetadataKey)(member.MemberType, member.MemberName));
215
211
  }
216
212
  //
217
213
  // * * * * * P R I V A T E M E T H O D S * * * * *
@@ -259,7 +255,7 @@ class RemoteSourceTrackingService extends core_1.ConfigFile {
259
255
  sourceMembers.forEach((change) => {
260
256
  // try accessing the sourceMembers object at the index of the change's name
261
257
  // if it exists, we'll update the fields - if it doesn't, we'll create and insert it
262
- const key = (0, exports.getMetadataKey)(change.MemberType, change.MemberName);
258
+ const key = (0, functions_1.getMetadataKey)(change.MemberType, change.MemberName);
263
259
  let sourceMember = this.getSourceMember(key);
264
260
  if (sourceMember) {
265
261
  // We are already tracking this element so we'll update it
@@ -360,13 +356,13 @@ class RemoteSourceTrackingService extends core_1.ConfigFile {
360
356
  // filter known Source tracking issues
361
357
  expectedMembers
362
358
  .filter((fileResponse) => {
363
- var _a, _b;
359
+ var _a;
364
360
  // unchanged files will never be in the sourceMembers. Not really sure why SDR returns them.
365
361
  return fileResponse.state !== source_deploy_retrieve_1.ComponentStatus.Unchanged &&
366
362
  // if a listView is the only change inside an object, the object won't have a sourceMember change. We won't wait for those to be found
367
363
  fileResponse.type !== 'CustomObject' &&
368
364
  // aura meta.xml aren't tracked as SourceMembers
369
- !(((_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')));
365
+ !((_a = fileResponse.filePath) === null || _a === void 0 ? void 0 : _a.endsWith('.cmp-meta.xml'));
370
366
  })
371
367
  .map((member) => {
372
368
  (0, metadataKeys_1.getMetadataKeyFromFileResponse)(member).map((key) => outstandingSourceMembers.set(key, member));
@@ -386,7 +382,7 @@ class RemoteSourceTrackingService extends core_1.ConfigFile {
386
382
  });
387
383
  // remove anything returned from the query list
388
384
  queriedMembers.map((member) => {
389
- outstandingSourceMembers.delete((0, exports.getMetadataKey)(member.MemberType, member.MemberName));
385
+ outstandingSourceMembers.delete((0, functions_1.getMetadataKey)(member.MemberType, member.MemberName));
390
386
  });
391
387
  this.logger.debug(`[${pollAttempts}] Found ${originalSize - outstandingSourceMembers.size} of ${originalSize} SourceMembers`);
392
388
  // update but don't sync
@@ -474,4 +470,25 @@ class RemoteSourceTrackingService extends core_1.ConfigFile {
474
470
  }
475
471
  exports.RemoteSourceTrackingService = RemoteSourceTrackingService;
476
472
  RemoteSourceTrackingService.remoteSourceTrackingServiceDictionary = {};
473
+ /**
474
+ * pass in an RCE, and this will return a pullable ChangeResult.
475
+ * Useful for correcing bundle types where the files show change results with types but aren't resolvable
476
+ */
477
+ const remoteChangeElementToChangeResult = (rce) => {
478
+ return {
479
+ ...rce,
480
+ ...(mappingsForSourceMemberTypesToMetadataType.has(rce.type)
481
+ ? {
482
+ name: rce.name.split('/')[0],
483
+ type: mappingsForSourceMemberTypesToMetadataType.get(rce.type),
484
+ }
485
+ : {}),
486
+ origin: 'remote', // we know they're remote
487
+ };
488
+ };
489
+ exports.remoteChangeElementToChangeResult = remoteChangeElementToChangeResult;
490
+ const mappingsForSourceMemberTypesToMetadataType = new Map([
491
+ ['AuraDefinition', 'AuraDefinitionBundle'],
492
+ ['LightningComponentResource', 'LightningComponentBundle'],
493
+ ]);
477
494
  //# sourceMappingURL=remoteSourceTrackingService.js.map