feat: updatePackage, sortPackage and normalizePackage utils#240
Conversation
|
@43081j @pi0 What would you think about convenience methods like But I would understand if you con't want to add that, as that could lead to a lot of PRs/requests to add others as well |
|
we could possibly change the updatePackageJSON('.', (pkg) => ({
scripts: {
...pkg.scripts,
build: "foo"
}
})); |
|
@43081j That could definitely be helpful, but in the example given that would still result into updatePackageJSON('.', ({ scripts: { "": _scriptToRemove, ...scripts } }) => ({
scripts,
}));And I actually wanted to avoid doing the destructing myself with a convenience method like |
|
i think in those cases we should just support updatePackageJSON('.', {
scripts: {
scriptToRemove: undefined
}
});this is already supported for top level keys, but not sub keys |
|
@43081j Sounds a good alternative if you ask me! |
|
Hey thanks for PR! I just had a chance to read through.
Supporting the second argument of We could have a followup to add some utils like |
|
Also landed support for |
@pi0 I agree though that we should be careful not to add utilities for all |
updatePackageJSON and normalizePackageJSON utils
updatePackageJSON and normalizePackageJSON utilsupdatePackageJSON, sortPackageJSON and normalizePackageJSON
updatePackageJSON, sortPackageJSON and normalizePackageJSONupdatePackage, sortPackage and normalizePackage utils
updatePackage, sortPackage and normalizePackage utilsupdatePackage, sortPackage and normalizePackage utils
This is a WIP of the package utils described in #238
Draft until we're happy with the shape, etc.
API design
addPackageJSONDependency(pkg, name, version[, type])Adds a dependency to the specified dependency list (by the
typeparameter).For example:
Automatically sorts the dependency list you mutated, and handles optional peer dependencies (when
typeis"optionalPeer").removePackageJSONDependency(pkg, name[, type])Removes a dependency from the specified dependency list (by the
typeparameter`).For example:
Also removes it from optional peer dependencies when
typeis"optionalPeer".updatePackageJSON(id, update[, resolveOptions])Applies a partial update to the
package.jsonfound atid(any resolvable string, e.g. a path).For example: