Skip to content

Gets the main files for a NPM module

Notifications You must be signed in to change notification settings

cosminlupu/npmfiles

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

npmfiles

Build Status Coverage Status

Inspiration

Functionality ( and README ) heavily inspired by ck86's main-bower-files

Usage

var mainNPMFiles = require('npmfiles');
var files = mainNPMFiles([options]);

This will read your package.json, iterate through your dependencies and returns an array of files defined in the main property of the packages package.json.

You can override the behavior if you add an overrides property to your own package.json.

Usage with gulp

var gulp = require('gulp');
var mainNPMFiles = require('npmfiles');

gulp.task('TASKNAME', function() {
    return gulp.src(mainNPMFiles())
        .pipe(/* what you want to do with the files */)
});

Options

Overrides Options

These options can be set directly in your package.json file, e.g.:

{
    "name": "your-package-name",
    "dependencies": {
        "NPM-PACKAGE": "*"
    },
    "overrides": {
        "NPM-PACKAGE": {
            "main": [
                // Here you can override the main files or ignoring this package, for more info see options
            ]
        }
    }
}

main

Type: String or Array

You can specify which files should be selected. e.g.:

You can also use glob pattern to select files, e.g.:

{
    "overrides": {
        "NPM-PACKAGE": {
            "main": "**/*.js"
        }
    }
}

ignore

Type: Boolean Default: false

Set to true if you want to ignore this package.

Common Options

These options can be passed to this plugin, e.g: mainNPMFiles(/* options*/)

nodeModulesPath

Type: String

You can specify the node_modules folder path where the modules are located.

For example:

mainNPMFiles({
    nodeModulesPath: 'path/for/node_modules'
})
.pipe(gulp.dest('client/src/lib'));

nodePackageJsonPath

Type: String

You can specify the package.json file path.

For example:

mainNPMFiles({
    packageJsonPath: 'path/for/package.json'
})
.pipe(gulp.dest('client/src/lib'));

includeDev

Type: Boolean Default: false

Set this option to true to add the devDependencies to your dependencies

showWarnings

Type: Boolean Default: false

Set this option to true to show warnings for packages that don't have any files in the main entry or overrides

LICENSE

(MIT License)

Copyright (c) 2017 Cosmin Lupu

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.