Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Package mutation utilities #238

@43081j

Description

@43081j

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 name to be '' if it isn't set
  • set version to 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?

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions