Skip to content

cravler/nmpm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

nmpm

Node modules package manager

Install

$ npm install nmpm

nmpm depends on Node.js and npm.

Usage

const Manager = require('nmpm');

const manager = new Manager('manager-name');

manager.list().then(result => {}, error => {});

manager.import('package-name').then(result => {}, error => {});

manager.package('package-name').then(result => {}, error => {});

manager.install('package-name', satisfies = async (pkg) => {}).then(result => {}, error => {});

manager.remove('package-name').then(result => {}, error => {});

Configure manager

const opts = {
    'fund': false,
    'audit': false,
    'loglevel': 'error',
    'global-style': true,
    'package-lock': false,
    'prefix': './plugins' // by default `process.cwd()`
};

const filter = async (pkg) => {
    if (!pkg.hasOwnProperty('manager-name')) {
        throw new Error('Package `' + pkg['name'] + '@' + pkg['version'] + '` is not supported');
    }
};

const throwPackageNotFound = (name) => {
    throw new Error('Unable to locate package `' + name + '`');
};

const manager = new Manager('manager-name', { opts, filter, throwPackageNotFound });

Dynamic import

const Module = require('module');
if (!Module.prototype.import) {
    Module.prototype.import = function(id) {
        return import(Module._resolveFilename(id, this, false)).catch(err => {
            if ('ERR_UNKNOWN_FILE_EXTENSION' == err.code) {
                return Promise.resolve({ default: this.require(id) });
            }
            throw err;
        });
    };
}

Package example

{
  "name": "package-name",
  "manager-name": true,
  ...
}

Install with satisfies check

const semver = require('semver');

const satisfies = async (pkg) => {
    if (pkg['engines']) {
        if (pkg['engines']['node']) {
            if (!semver.satisfies(semver.coerce(process.version), pkg['engines']['node'])) {
                throw new Error(
                    'Package `' + pkg['name'] + '@' + pkg['version'] + '` require `node@' + pkg['engines']['node'] + '`'
                );
            }
        }
    }
};

manager.install('package-name', satisfies).then(result => {}, error => {});

License

This software is under the MIT license. See the complete license in:

LICENSE

About

Node modules package manager

Resources

License

Stars

Watchers

Forks

Packages

No packages published