Skip to content

Commit

Permalink
fix: rightfully manipulate package json topics
Browse files Browse the repository at this point in the history
the existing Object spread merge does not play right here.
Replaced by using lodash.defaultsDeep.
defaultsDeep instead of merge to not replace existing keys/comments etc
  • Loading branch information
KevinGossentCap committed Jun 5, 2023
1 parent e0dd5bc commit d3b35d0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"graphology": "^0.25.1",
"graphology-types": "^0.24.7",
"js-yaml": "^4.1.0",
"lodash.defaultsdeep": "^4.6.1",
"replace-in-file": "^6.3.2",
"shelljs": "^0.8.5",
"tslib": "^2",
Expand All @@ -35,6 +36,7 @@
"@salesforce/ts-sinon": "1.4.7",
"@swc/core": "1.3.20",
"@types/js-yaml": "^4.0.5",
"@types/lodash.defaultsdeep": "^4.6.7",
"@types/shelljs": "^0.8.10",
"@types/yeoman-generator": "^5.2.10",
"@types/yeoman-test": "^4.0.3",
Expand Down Expand Up @@ -245,4 +247,4 @@
"output": []
}
}
}
}
5 changes: 3 additions & 2 deletions src/generators/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { pascalCase } from 'change-case';
import { set } from '@salesforce/kit';
import { get } from '@salesforce/ts-types';
import { exec } from 'shelljs';
import defaultsDeep = require('lodash.defaultsdeep');
import { PackageJson, Topic } from '../types';

// eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-unsafe-assignment
Expand Down Expand Up @@ -89,11 +90,11 @@ export default class Command extends Generator {
const commands = commandsJson.map((command) => command.id.replace(/:/g, '.').replace(/ /g, '.'));

const newTopics = addTopics(this.options.name, this.pjson.oclif.topics, commands);
this.pjson.oclif.topics = { ...this.pjson.oclif.topics, ...newTopics };
defaultsDeep(this.pjson.oclif.topics, newTopics)
this.internalPlugin = true;
} else {
const newTopics = addTopics(this.options.name, this.pjson.oclif.topics);
this.pjson.oclif.topics = { ...this.pjson.oclif.topics, ...newTopics };
defaultsDeep(this.pjson.oclif.topics, newTopics)
}

this.fs.writeJSON('package.json', this.pjson);
Expand Down
12 changes: 12 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1408,6 +1408,13 @@
dependencies:
"@types/node" "*"

"@types/lodash.defaultsdeep@^4.6.7":
version "4.6.7"
resolved "https://registry.yarnpkg.com/@types/lodash.defaultsdeep/-/lodash.defaultsdeep-4.6.7.tgz#1a4f96d6d95815bbb16ac6f639fe0617bb71cd7c"
integrity sha512-D+AUxs64qehDMkbfFoskG0XsIOh2CHBGqYfcQcubLbZSFCGKJKS885su3a97huqBNHj+p9of9UZ/uUIP46wUGQ==
dependencies:
"@types/lodash" "*"

"@types/lodash@*":
version "4.14.194"
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.194.tgz#b71eb6f7a0ff11bff59fc987134a093029258a76"
Expand Down Expand Up @@ -4891,6 +4898,11 @@ lodash.defaults@^4.2.0:
resolved "https://registry.yarnpkg.com/lodash.defaults/-/lodash.defaults-4.2.0.tgz#d09178716ffea4dde9e5fb7b37f6f0802274580c"
integrity sha512-qjxPLHd3r5DnsdGacqOMU6pb/avJzdh9tFX2ymgoZE27BmjXrNy/y4LoaiTeAb+O3gL8AfpJGtqfX/ae2leYYQ==

lodash.defaultsdeep@^4.6.1:
version "4.6.1"
resolved "https://registry.yarnpkg.com/lodash.defaultsdeep/-/lodash.defaultsdeep-4.6.1.tgz#512e9bd721d272d94e3d3a63653fa17516741ca6"
integrity sha512-3j8wdDzYuWO3lM3Reg03MuQR957t287Rpcxp1njpEa8oDrikb+FwGdW3n+FELh/A6qib6yPit0j/pv9G/yeAqA==

lodash.difference@^4.5.0:
version "4.5.0"
resolved "https://registry.yarnpkg.com/lodash.difference/-/lodash.difference-4.5.0.tgz#9ccb4e505d486b91651345772885a2df27fd017c"
Expand Down

0 comments on commit d3b35d0

Please sign in to comment.