Package mutation utilities
Open
@43081j is already working on this.
Since Aug 4, 2025.
enhancement
- Dominant language
- TypeScript
- Stars
- 300
- Forks
- 30
- Avg merge
- 20h 45m
- Merged PRs (30d)
- 3
Description
Describe the feature
To provide a lighter alternative to the npmcli libraries, we could provide the common mutation utilities and leave out the rest:
Features
- Add/remove dependencies from prod, dev, peer, optional peer
- Partial updates
- Basic normalisation
- Automatically sort dependency lists
Implementation
We can probably also follow a class based approach like npm did:
type DependencyType = 'peer' | 'optionalPeer' | 'dev' | 'prod';
declare class PackageJson {
addDependency(
name: string,
version: string,
type?: DependencyType
): void;
removeDependency(
name: string,
type?: DependencyType
): void;
update(
partial: Partial<PackageJson>
): void;
save(): Promise<void>;
}
declare function loadPackageJson(path: string): Promise<PackageJson>;
internally, save can do basic normalisation:
- sort the dependency lists
- set
nameto be''if it isn't set - set
versionto be''if it isn't set
Given we already have PackageJson (type), we could name this PackageJsonManager or some such thing, and have a convenience constructor/util to new one up from a PackageJson (as that's also what we'd store internally).
Additional information
- Would you be willing to help implement this feature?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.