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

module-linker

v1.1.0

Published

Library that links local modules by name

Downloads

5

Readme

#Purpose

The module linker is a tool to recursively link and resolve local dependencies such that local modules can be required by name instead of their relative path.

#Behavior

It uses 'npm link' the linking and 'act-on-modules' project to find modules (recursively traversing directories and stopping whenever it finds a package.json file).

#Usage

##linker

###Description

This method will recursively traverse a series of directories it is given and globally link (to make available to the resolver) any module it finds.

Additionally, you can specify the tool (as a string) that will perform the link as a string (only 'npm' and 'yarn' are supported). If omitted, npm is assumed.

###Signature

const moduleLinker = require('module-linker');
moduleLinker.linker([<Strings of paths containing modules that will be required>], <tool>) //Returns a promise

###Example

//Linking with the default choice of npm
const moduleLinker = require('module-linker');
moduleLinker.linker(['/home/eric/nodeJsModules']).then(() => {
    console.log('all done');
});
//Linking with yarn
const moduleLinker = require('module-linker');
moduleLinker.linker(['/home/eric/nodeJsModules'], 'yarn').then(() => {
    console.log('all done');
});

##resolver

###Description

This method will recursively traverse a series of directories it is given and resolve any local dependencies it finds. Dependencies need to be indicated in the localDependencies entry of package.json files.

Additionally, you can specify the tool (as a string) that will perform the resolution as a string (only 'npm' and 'yarn' are supported). If omitted, npm is assumed.

###Signature

const moduleLinker = require('module-linker');
moduleLinker.resolver([<Strings of paths containing code that has local dependencies that need to be resolved>], <tool>) //Returns a promise

###Example

//Resolving with the default choice of npm
const moduleLinker = require('module-linker');
moduleLinker.resolver(['/home/eric/app', '/home/eric/nodeJsModules']).then(() => {
    console.log('all done');
});
//Resolving with yarn
const moduleLinker = require('module-linker');
moduleLinker.resolver(['/home/eric/app', '/home/eric/nodeJsModules'], 'yarn').then(() => {
    console.log('all done');
});

##call

###Description

A direct call to the library will call both the linker and resolver (sequentially as the resolver is dependent on the linker being finished).

Additionally, you can specify the tool (as a string) that will perform the resolution as a string (only 'npm' and 'yarn' are supported). If omitted, npm is assumed.

###Signature

const moduleLinker = require('module-linker');
moduleLinker([<Strings of paths containing code that has local dependencies that need to be resolved>], [<Strings of paths containing modules that will be required>], <tool>) //Returns a promise

###Example

//Using default choice of npm
const moduleLinker = require('module-linker');
moduleLinker(['/home/eric/app', '/home/eric/nodeJsModules'], ['/home/eric/nodeJsModules']).then(() => {
    console.log('all done');
});
//Using yarn
const moduleLinker = require('module-linker');
moduleLinker(['/home/eric/app', '/home/eric/nodeJsModules'], ['/home/eric/nodeJsModules'], 'yarn').then(() => {
    console.log('all done');
});

##Package.json pre-requisites

There are two pre-requisites in package.json files for the library to work as intended.

  • All modules that are to be required, need to have a legal unique (within the project) module name. This is the 'name' entry in the package.json file
  • All modules that have local dependencies, need to have a "localDependencies" in their package.json file listing their local dependencies as an array of strings. This is a custom entry that is used solely by the library.

Ex:

{
  "name": "sample-app",
  "version": "1.0.0",
  "main": "index.js",
  "licenses": [
    {
      "type": "MIT License",
      "url": "http://mit-license.org/"
    }
  ],
  "dependencies": {
  },
  "devDependencies": {
  },
  "localDependencies": ["user-store"],
  "license": "MIT",
  "directories": {
  },
  "scripts": {
      "start": "node index.js"
  }
}

##Running Tests

Run npm test run npm to test this module with npm

Run npm test run yarn to test this module with yarn

Because I didn't want the tests to pollute anyone's global space with throwaway test modules, I dockerized them so you'll need docker and docker-composed installed (as well as a user with enough privilege to execute docker without sudo) to run the tests.

##Installation

Run npm install module-linker