npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@springernature/util-package-extender

v0.0.4

Published

Extends a component package by merging with the package it extends

Downloads

6

Readme

Package Extender

NPM version Node version MIT License

This helper allows you to extend one Component Package (remote) with another (local). The helper merges files from the remote package with files from the local, ignoring any files in the remote that already exist at the local level.

Remote Package - package being extended, published to NPM
Local Package - package that extends the remote

example package extension

This should be run from within the repository of the local package, and requires the local package to have a package.json file with the fields name, version, extendsPackage. The last of these should define the name and version of the remote package in the format package-name@version. For example:

{
  "name": "brand-package",
  "version": "1.0.0",
  "extendsPackage": "[email protected]"
}

Install

$ npm install @springernature/util-package-extender

Usage

The helper exports two functions:

getPackageExtensionDetails(packageJsonObject, packageScope)

Returns a Promise with package extension details contained in an Object. The package.json file for the local package needs to contain the keys name, version, and extendsPackage.

packageJsonObject

Type: Object

A Javascript Object representing the package.json file of the local package.

packageScope

Type: String
Default: 'springernature'

The scope under which to search for the remote package (only works with scoped packages at the moment).

Example

const extender = require('@springernature/util-package-extender');
const obj = require('./package.json');

// With default scope
// ------------------

try {
    const details = await extender.getPackageExtensionDetails(obj);
    // {
    //   extendPackage: true,
    //   remotePackage: '@springernature/[email protected]',
    //   localPackage: '[email protected]'
    // }
} catch(err) {
    throw err;
}

// With custom scope
// -----------------

try {
    const details = await extender.getPackageExtensionDetails(obj, 'my-scope');
    // {
    //   extendPackage: true,
    //   remotePackage: '@my-scope/[email protected]',
    //   localPackage: '[email protected]'
    // }
} catch(err) {
    throw err;
}

// No package extension defined
// ----------------------------

try {
    const details = await extender.getPackageExtensionDetails(obj);
    // {
    //   extendPackage: false,
    //   remotePackage: null,
    //   localPackage: null
    // }
} catch(err) {
    throw err;
}

extendPackage(packageJsonPath, remotePackage, localPackage, outputDirectory)

Returns a Promise after merging the two packages on the local filesystem. Files from the remote package are either merged in place with the local files, or merged into an output directory with a copy of the local files.

packageJsonPath

Type: String

Location of the package.json file for the local package.

remotePackage

Type: String

Name and version of the remote package in the format package-name@version.

localPackage

Type: String

Name and version of the local package in the format package-name@version.

outputDirectory

Type: String
Default: null

Directory in which to store the merged files. Defaults to merging in place with the local files.

Example

const extender = require('@springernature/util-package-extender');
const obj = require('./package.json');

// Merge in place
// --------------

try {
    const details = await extender.getPackageExtensionDetails(obj);
    await extender.extendPackage(
        '/path/to/package.json',
        details.remotePackage,
        details.localPackage
    )
} catch(err) {
    throw err;
}

// Merge into output directory (./demo)
// ------------------------------------

try {
    const details = await extender.getPackageExtensionDetails(obj);
    await extender.extendPackage(
        '/path/to/package.json',
        details.remotePackage,
		details.localPackage,
        './demo'
    )
} catch(err) {
    throw err;
}

License

MIT License © 2019, Springer Nature