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

dry-dry-revised

v0.5.4

Published

Use npm across multiple projects without repeating yourself

Downloads

26

Readme

DRY - Use npm across multiple projects without repeating yourself

Code Shelter Build Status code style: prettier

Get it

npm i -g dry-dry

Use it

dry init

Key concepts

The copy/paste madness

Because companies and other groups have bunch of package.json attributes that are the same across all npm projects. Those attributes must be maintained using copy/paste across all projects. This is wrong !

We believe that those attributes should be easily distributed and updated across projects.

The version management madness

Because most of multi module project use multiple version of the same dependencies. Bundling an application with those modules may be challenging.

Dry provide a mecanism to centralize dependencies version management.

Do not repeat yourself

dry is a stupid npm wrapper allowing any package.json to extend a parent file. The parent file can be located on the system or simply inside a published npm module.

How does it work

On each dry command, dry:

  • creates a merged package.json based on the provided package-dry.json
  • runs the npm command
  • applies the possible package.json modifications made by npm to package-dry.json
  • removes package.json

package.json is always removed to make sure that nobody will execute a pure npm command in a dry project.

Inheritance in action

Parent project

package-dry.json

{
    "name": "parent",
    "version": "1.0.0",
    "description": "",
    "main": "index.js",
    "scripts": {
        "test": "echo \"Error: no test specified\" && exit 1",
        "foo": "npm help"
    },
    "keywords": [],
    "author": "",
    "license": "ISC",
    "dependencyManagement": {
        "dependency-one": "1.0.0",
        "dependency-two": "2.0.0",
        "dev-dependency-one": "1.1.0",
        "dev-dependency-two": "2.2.0"
    }
}

Child project

package-dry.json

{
    "name": "child",
    "version": "1.0.0",
    "description": "",
    "main": "index.js",
    "scripts": {
        "test": "echo \"Error: no test specified\" && exit 1"
    },
    "keywords": [],
    "author": "",
    "license": "ISC",
    "dry": {
        "extends": "parent/package-dry.json",
        "dependencies": {
            "parent": "1.0.0"
        }
    },
    "dependencies": {
        "dependency-one": "managed",
        "dependency-three": "1.2.3"
    },
    "devDependencies": {
        "dev-dependency-two": "managed",
        "dev-dependency-three": "1.2.3"
    }
}

After run dry i in children project...

Merged package.json

{
  "name": "child",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "foo": "npm help"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
     "dependency-one": "1.0.0",
     "dependency-three": "1.2.3"
  },
  "devDependencies": {
     "dev-dependency-two": "1.1.0",
     "dev-dependency-three": "1.2.3"
  }
}

package-dry.json

To do that, dry introduces a file named package-dry.json. package-dry.json replaces package.json in your dry projects. Of course, it can contain all the attributes of package.json with the addition of an attribute called dry.

package-dry.json dry attribute has 2 optional attributes:

  • extends - The parent of the current dry package
  • dependencies - The dependencies needed to resolve the file pointed by extends. Those dependencies will not be saved to your project.

dry commands

dry proxies all received arguments to yarn. Just take your usual yarn commands and replace the word yarn with dry.

| yarn | dry | | ------------ | ----------- | | yarn init | dry init | | yarn add | dry add | | yarn publish | dry publish | | yarn x y z | dry x y z |

dry commands : additional parameters

The dry command accepts some additional parameters

  • --dry-packager packager_cli_name : specify the nodejs packager cli to proxy (default : yarn, possible values: npm|pnpm|yarn)
  • --dry-keep-package-json' : when provided the generated package.json file is not deleted
  • --dry-save-package-json-to' target_file_path : when provided a copy of the generated package.json file is done to target_file_path location

Other handled parameters:

  • --loglevel trace|debug|info|warn|error: log set to a specific level
  • -s, --silent: --loglevel error
  • -q, --quiet: --loglevel warn
  • -d: --loglevel info
  • -dd, --verbose: --loglevel debug
  • -ddd: --loglevel trace

dry : using a custom package manager

Dry use by default yarn and it also allows using another package manager like npm and pnpm trough the parameter --dry-packager.

If you're not using one of the configured packagers or if you need to extend an existing packager then you can provide to the --dry-packager parameter a path to a 'Package Manager Descriptor' json file.

All package manager available in Dry are defined using a 'Package Manager Descriptor'. It provides to Dry which command it needs to execute and how to handle and map dry supported arguments


{
    "extends": "",
    "packageManager": "", 
    "installParentCommandTemplate": "", 
    "preventPackageJsonChangeFromParentInstall": true|false,
    "mappedArguments" : [
        { 
            "arguments": [""],
            "expectSubArgument": true|false,
            "allowArgInInstallParentCommand": true|false,
            "mappedArgumentValues": {
                "": [""],
                "": [""],
                "": [""]
            }
        },
        { 
            "arguments": [""],
            "allowArgInInstallParentCommand": true|false,
            "mappedTo" : [""]
        }
   ]
}        

DryPackagerDescriptor

| property | description | | ----------------------------------------- | ----------------------------------------------------------------------------------------------------- | | extends | string : If the package manager you plan to use is just a wrapper around another existing one. You can provide his key (npm|yarn|pnpm). A relative/absolute file path is also accepted (Ex: pnpm.json | | packageManager | string : The package manager cli name to invoke. Must be available in PATH | | installParentCommandTemplate | string : the command template to use to install the parent of the current dry package in the node_modules folder. Preferably, this command should not modify the "package.json" file. The command must contains '{0}' which will be replaced by the dependency to install.'{0}' will be replaced by '[email protected]' or a packed file path 'file://path/to/package.tgz' | | preventPackageJsonChangeFromParentInstall | boolean : If the command provided in "installParentCommandTemplate" do modify the "package.json" file then turning on this boolean will restore the "package.json" file | | mappedArguments | ArgumentMapping[]: list of mapped arguments |

ArgumentMapping

| property | description | | ----------------------------------------- | ----------------------------------------------------------------------------------------------------- | | arguments | string[]: Contains the list of handled arguments | | expectSubArgument | boolean : Indicate if the provided arguments expect an associated value. If 'false' then 'mappedTo' must be provided. If 'true' then 'mappedArgumentValues' must be provided | | allowArgInInstallParentCommand | boolean : Indicate if the mapping result can also be added to the "installParentCommandTemplate" | | mappedTo | string[]: The argument provided as input will be replaced by this list of argument as output | | mappedArgumentValues | Map<string, string[]> : The argument value provided as input will be used as key for this map to get the map value and return the value as the list of argument to output |

You can check current descriptors with the links below: