From da27c0208a6776f4d64ff83f26eeb5b212f2cd7b Mon Sep 17 00:00:00 2001 From: mshanemc Date: Wed, 15 Nov 2023 07:45:18 -0600 Subject: [PATCH 1/2] chore: bump dev-scripts --- package.json | 2 +- yarn.lock | 21 +++++++++++++-------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index 0e595f55ad..03cdb0ee17 100644 --- a/package.json +++ b/package.json @@ -59,7 +59,7 @@ "ts-retry-promise": "^0.7.1" }, "devDependencies": { - "@salesforce/dev-scripts": "^6.0.3", + "@salesforce/dev-scripts": "^6.0.4", "@salesforce/ts-sinon": "^1.4.19", "@types/benchmark": "^2.1.3", "@types/chai-string": "^1.4.5", diff --git a/yarn.lock b/yarn.lock index e71b60a4b8..9efab36069 100644 --- a/yarn.lock +++ b/yarn.lock @@ -516,21 +516,21 @@ "@nodelib/fs.scandir" "2.1.5" fastq "^1.6.0" -"@salesforce/dev-config@^4.0.1": +"@salesforce/dev-config@^4.1.0": version "4.1.0" resolved "https://registry.yarnpkg.com/@salesforce/dev-config/-/dev-config-4.1.0.tgz#e529576466d074e7a5f1441236510fef123da01e" integrity sha512-2iDDepiIwjXHS5IVY7pwv8jMo4xWosJ7p/UTj+lllpB/gnJiYLhjJPE4Z3FCGFKyvfg5jGaimCd8Ca6bLGsCQA== -"@salesforce/dev-scripts@^6.0.3": - version "6.0.3" - resolved "https://registry.yarnpkg.com/@salesforce/dev-scripts/-/dev-scripts-6.0.3.tgz#6cf4504fd0ec8b4685e729b26685eed60f9c8b26" - integrity sha512-WLl1N07oNeRywdypwUrebX/kCkSm3IzmAQpUt4q4Sk8r4vTWv5b6F0pHLv0pGS8/QWNJT7xWGZDF1lgJBHOsmA== +"@salesforce/dev-scripts@^6.0.4": + version "6.0.4" + resolved "https://registry.yarnpkg.com/@salesforce/dev-scripts/-/dev-scripts-6.0.4.tgz#0043b8ef4b970f8c2f945cc74eada3b1db52fa9a" + integrity sha512-/kdl99bHaNeCoVwfeQhIaKzorcmgpe/nZhlT7ru+If+18NRvBgW5OGmh++Q/NsraaYbsQ/0cDcGNz1dnQ11weA== dependencies: "@commitlint/cli" "^17.1.2" "@commitlint/config-conventional" "^17.1.0" - "@salesforce/dev-config" "^4.0.1" + "@salesforce/dev-config" "^4.1.0" "@salesforce/prettier-config" "^0.0.3" - "@types/chai" "^4.2.11" + "@types/chai" "^4.3.9" "@types/mocha" "^10.0.3" "@types/node" "^18" "@types/sinon" "^10.0.20" @@ -670,11 +670,16 @@ dependencies: "@types/chai" "*" -"@types/chai@*", "@types/chai@^4.2.11": +"@types/chai@*": version "4.3.1" resolved "https://registry.yarnpkg.com/@types/chai/-/chai-4.3.1.tgz#e2c6e73e0bdeb2521d00756d099218e9f5d90a04" integrity sha512-/zPMqDkzSZ8t3VtxOa4KPq7uzzW978M9Tvh+j7GHKuo6k6GTLxPJ4J5gE5cjfJ26pnXst0N5Hax8Sr0T2Mi9zQ== +"@types/chai@^4.3.9": + version "4.3.10" + resolved "https://registry.yarnpkg.com/@types/chai/-/chai-4.3.10.tgz#2ad2959d1767edee5b0e4efb1a0cd2b500747317" + integrity sha512-of+ICnbqjmFCiixUnqRulbylyXQrPqIGf/B3Jax1wIF3DvSheysQxAWvqHhZiW3IQrycvokcLcFQlveGp+vyNg== + "@types/json-schema@^7.0.12": version "7.0.15" resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.15.tgz#596a1747233694d50f6ad8a7869fcb6f56cf5841" From ff8b06696f7ef88ac74a35f60e281b90eb74471b Mon Sep 17 00:00:00 2001 From: mshanemc Date: Wed, 15 Nov 2023 07:46:50 -0600 Subject: [PATCH 2/2] fix: write safety and valid typing for sfProject --- src/sfProject.ts | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/src/sfProject.ts b/src/sfProject.ts index 1161641c5a..9f2cd9a9a6 100644 --- a/src/sfProject.ts +++ b/src/sfProject.ts @@ -89,7 +89,7 @@ export type ProjectJson = ConfigContents & { * * **See** [force:project:create](https://developer.salesforce.com/docs/atlas.en-us.sfdx_dev.meta/sfdx_dev/sfdx_dev_ws_create_new.htm) */ -export class SfProjectJson extends ConfigFile { +export class SfProjectJson extends ConfigFile { public static BLOCKLIST = ['packageAliases']; public static getFileName(): string { @@ -102,32 +102,28 @@ export class SfProjectJson extends ConfigFile { return options; } - public async read(): Promise { + public async read(): Promise { const contents = await super.read(); this.validateKeys(); return contents; } - public readSync(): ConfigContents { + public readSync(): ProjectJson { const contents = super.readSync(); this.validateKeys(); return contents; } - public async write(): Promise { + public async write(): Promise { this.validateKeys(); return super.write(); } - public writeSync(): ConfigContents { + public writeSync(): ProjectJson { this.validateKeys(); return super.writeSync(); } - public getContents(): ProjectJson { - return super.getContents() as ProjectJson; - } - // eslint-disable-next-line class-methods-use-this public getDefaultOptions(options?: ConfigFile.Options): ConfigFile.Options { return { ...{ isState: false }, ...(options ?? {}) }; @@ -354,12 +350,15 @@ export class SfProjectJson extends ConfigFile { dirIndex > -1 ? this.getContents().packageDirectories[dirIndex] : packageDir, packageDir ); - // update package dir entries - if (dirIndex > -1) { - this.getContents().packageDirectories[dirIndex] = packageDirEntry; - } else { - this.getContents().packageDirectories.push(packageDirEntry); - } + + const modifiedPackagesDirs = + dirIndex > -1 + ? // replace the matching entry with the new entry + this.getContents().packageDirectories.map((pd, i) => (i === dirIndex ? packageDir : pd)) + : // add the new entry to the end of the list + [...(this.getContents()?.packageDirectories ?? []), packageDirEntry]; + + this.set('packageDirectories', modifiedPackagesDirs); } // eslint-disable-next-line class-methods-use-this