@salesforce/core 8.10.2 → 8.11.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.
Files changed (2) hide show
  1. package/lib/messages.js +10 -3
  2. package/package.json +2 -2
package/lib/messages.js CHANGED
@@ -521,6 +521,7 @@ class Messages {
521
521
  throw new sfError_1.SfError(`Missing message ${this.bundleName}:${key} for locale ${Messages.getLocale()}.`, 'MissingMessageError');
522
522
  }
523
523
  const messages = (0, kit_1.ensureArray)(msg);
524
+ let tokenCur = 0; // Keep track of which tokens we've used
524
525
  return messages.map((message) => {
525
526
  const msgStr = (0, ts_types_1.ensureString)(message);
526
527
  // If the message does not contain a specifier, util.format still appends the token to the end.
@@ -530,12 +531,18 @@ class Messages {
530
531
  // https://nodejs.org/api/util.html#utilformatformat-args
531
532
  // https://regex101.com/r/8Hf8Z6/1
532
533
  const specifierRegex = new RegExp('%[sdifjoO]{1}', 'gm');
533
- const specifierFound = specifierRegex.test(msgStr);
534
- if (!specifierFound && tokens.length > 0) {
534
+ const specifierFound = msgStr.match(specifierRegex) ?? [];
535
+ const tokenCount = specifierFound.length;
536
+ if (tokenCount > 0) {
537
+ const relevantTokens = tokens.slice(tokenCur, tokenCur + tokenCount);
538
+ tokenCur += tokenCount;
539
+ return util.format(msgStr, ...relevantTokens);
540
+ }
541
+ else {
535
542
  const logger = logger_1.Logger.childFromRoot('core:messages');
536
543
  logger.warn(`Unable to render tokens in message. Ensure a specifier (e.g. %s) exists in the message:\n${msgStr}`);
537
544
  }
538
- return specifierFound ? util.format(msgStr, ...tokens) : msgStr;
545
+ return msgStr;
539
546
  });
540
547
  }
541
548
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/core",
3
- "version": "8.10.2",
3
+ "version": "8.11.0",
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",
@@ -74,7 +74,7 @@
74
74
  },
75
75
  "devDependencies": {
76
76
  "@salesforce/dev-scripts": "^10.1.1",
77
- "@salesforce/ts-sinon": "^1.4.27",
77
+ "@salesforce/ts-sinon": "^1.4.30",
78
78
  "@types/benchmark": "^2.1.5",
79
79
  "@types/fast-levenshtein": "^0.0.4",
80
80
  "@types/jsonwebtoken": "9.0.7",