@salesforce/core 8.2.8 → 8.2.9

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.
@@ -175,6 +175,7 @@ class ConfigFile extends configStore_1.BaseConfigStore {
175
175
  // internally and updated persistently via write().
176
176
  if (!this.hasRead || force) {
177
177
  this.logger.debug(`Reading config file: ${this.getPath()} because ${!this.hasRead ? 'hasRead is false' : 'force parameter is true'}`);
178
+ await (0, fileLocking_1.pollUntilUnlock)(this.getPath());
178
179
  const obj = (0, kit_1.parseJsonMap)(await fs.promises.readFile(this.getPath(), 'utf8'), this.getPath());
179
180
  this.setContentsFromFileContents(obj, (await fs.promises.stat(this.getPath(), { bigint: true })).mtimeNs);
180
181
  }
@@ -210,6 +211,7 @@ class ConfigFile extends configStore_1.BaseConfigStore {
210
211
  // Only need to read config files once. They are kept up to date
211
212
  // internally and updated persistently via write().
212
213
  if (!this.hasRead || force) {
214
+ (0, fileLocking_1.pollUntilUnlockSync)(this.getPath());
213
215
  this.logger.debug(`Reading config file: ${this.getPath()}`);
214
216
  const obj = (0, kit_1.parseJsonMap)(fs.readFileSync(this.getPath(), 'utf8'));
215
217
  this.setContentsFromFileContents(obj, fs.statSync(this.getPath(), { bigint: true }).mtimeNs);
@@ -21,4 +21,11 @@ export declare const lockInit: (filePath: string) => Promise<LockInitResponse>;
21
21
  * See its documentation for details.
22
22
  */
23
23
  export declare const lockInitSync: (filePath: string) => LockInitSyncResponse;
24
+ /**
25
+ * Poll until the file is unlocked.
26
+ *
27
+ * @param filePath file path to check
28
+ */
29
+ export declare const pollUntilUnlock: (filePath: string) => Promise<void>;
30
+ export declare const pollUntilUnlockSync: (filePath: string) => void;
24
31
  export {};
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.lockInitSync = exports.lockInit = void 0;
26
+ exports.pollUntilUnlockSync = exports.pollUntilUnlock = exports.lockInitSync = exports.lockInit = void 0;
27
27
  /*
28
28
  * Copyright (c) 2023, salesforce.com, inc.
29
29
  * All rights reserved.
@@ -33,6 +33,8 @@ exports.lockInitSync = exports.lockInit = void 0;
33
33
  const fs = __importStar(require("node:fs"));
34
34
  const node_path_1 = require("node:path");
35
35
  const proper_lockfile_1 = require("proper-lockfile");
36
+ const kit_1 = require("@salesforce/kit");
37
+ const ts_retry_promise_1 = require("ts-retry-promise");
36
38
  const sfError_1 = require("../sfError");
37
39
  const logger_1 = require("../logger/logger");
38
40
  const lockRetryOptions_1 = require("./lockRetryOptions");
@@ -111,4 +113,40 @@ const lockInitSync = (filePath) => {
111
113
  };
112
114
  };
113
115
  exports.lockInitSync = lockInitSync;
116
+ /**
117
+ * Poll until the file is unlocked.
118
+ *
119
+ * @param filePath file path to check
120
+ */
121
+ const pollUntilUnlock = async (filePath) => {
122
+ try {
123
+ await (0, ts_retry_promise_1.retryDecorator)(proper_lockfile_1.check, {
124
+ timeout: kit_1.Duration.minutes(1).milliseconds,
125
+ delay: 10,
126
+ until: (locked) => locked === false,
127
+ // don't retry errors (typically enoent or access on the lockfile, therefore not locked)
128
+ retryIf: () => false,
129
+ })(filePath, lockRetryOptions_1.lockRetryOptions);
130
+ }
131
+ catch (e) {
132
+ // intentionally swallow the error, same reason as above
133
+ }
134
+ };
135
+ exports.pollUntilUnlock = pollUntilUnlock;
136
+ const pollUntilUnlockSync = (filePath) => {
137
+ // Set a counter to ensure that the while loop does not run indefinitely
138
+ let counter = 0;
139
+ let locked = true;
140
+ while (locked && counter < 100) {
141
+ try {
142
+ locked = (0, proper_lockfile_1.checkSync)(filePath, lockRetryOptions_1.lockOptions);
143
+ counter++;
144
+ }
145
+ catch {
146
+ // Likely a file not found error, which means the file is not locked
147
+ locked = false;
148
+ }
149
+ }
150
+ };
151
+ exports.pollUntilUnlockSync = pollUntilUnlockSync;
114
152
  //# sourceMappingURL=fileLocking.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/core",
3
- "version": "8.2.8",
3
+ "version": "8.2.9",
4
4
  "description": "Core libraries to interact with SFDX projects, orgs, and APIs.",
5
5
  "main": "lib/index",
6
6
  "types": "lib/index.d.ts",
@@ -35,6 +35,7 @@
35
35
  "prepack": "sf-prepack",
36
36
  "prepare": "sf-install",
37
37
  "test": "wireit",
38
+ "test:nuts": "mocha \"test/**/*.nut.ts\" --timeout 500000",
38
39
  "test:only": "wireit",
39
40
  "test:perf": "ts-node test/perf/logger/main.test.ts"
40
41
  },
@@ -146,7 +147,7 @@
146
147
  "output": []
147
148
  },
148
149
  "test:only": {
149
- "command": "nyc mocha \"test/**/*Test.ts\"",
150
+ "command": "nyc mocha \"test/unit/**/*.test.ts\"",
150
151
  "env": {
151
152
  "FORCE_COLOR": "2"
152
153
  },