Skip to content

Commit

Permalink
Merge pull request #989 from forcedotcom/sm/packaging-project-methods
Browse files Browse the repository at this point in the history
fix: write safety and valid typing for sfProject
  • Loading branch information
mshanemc authored Nov 15, 2023
2 parents 2e48032 + ff8b066 commit 28483e5
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 24 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
29 changes: 14 additions & 15 deletions src/sfProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ConfigFile.Options, ProjectJson> {
public static BLOCKLIST = ['packageAliases'];

public static getFileName(): string {
Expand All @@ -102,32 +102,28 @@ export class SfProjectJson extends ConfigFile {
return options;
}

public async read(): Promise<ConfigContents> {
public async read(): Promise<ProjectJson> {
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<ConfigContents> {
public async write(): Promise<ProjectJson> {
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 ?? {}) };
Expand Down Expand Up @@ -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
Expand Down
21 changes: 13 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 28483e5

Please sign in to comment.