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

load-grunt-parent-tasks

v0.1.2

Published

Loads de-duped grunt tasks from parent or sibling modules.

Downloads

441

Readme

load-grunt-parent-tasks

Loads de-duped grunt tasks from parent or sibling modules.

TL;DR

load-grunt-parent-tasks is a Grunt library that allows you to load all of your Grunt tasks even if they are in a parent folder. This library was heavily inspired by this StackOverflow post: "Centralise Node Modules In Project With Subproject", and and utilizes the gruntcollection feature of grunt.loadNpmTasks.

Description

If Grunt task is loaded as a submodule then create a grunt-collection module in your local node_modules folder to trick grunt into loading dependencies from a parent folder. This might be necessary if project A contains a Gruntfile.js with dependencies X, Y, and Z, and is loaded as a npm dependency of project B which contains dependencies A, X and Y. In that scenario Npm will de-dupe project A's Npm dependencies when executing npm install in project B and will look like this:

B
├── node_modules
│   ├── A
│   │   ├── Gruntfile.js
│   │   ├── node_modules
│   │   │   └── Z
│   │   └── package.json (has depencencies X,Y,Z)
│   ├── X
│   └── Y
└── package.json (has dependencies A,X,Y)

If project A's package.json contains an install or postinstall script that executes it's Gruntfile.js the Grunt task will throw 2 errors:

Local Npm module "X" not found. Is it installed?
Local Npm module "Y" not found. Is it installed?

Project A's Grunt task will not be able to load the de-duped dependencies because they reside in the parents node_modules folder. This can be fixed by dropping in a new module which contains project A's package.json with the addition of a keywords property that contains "gruntcollection" in it's array.

B
├── node_modules
│   ├── A
│   │   ├── Gruntfile.js
│   │   ├── node_modules
│   │   │   ├── grunt-collection
│   │   │   │   └── package.json (has dependencies X,Y,Z and 'keywords: ["gruntcollection"]')
│   │   │   └── Z
│   │   └── package.json (has depencencies X,Y,Z)
│   ├── X
│   └── Y
└── package.json (has dependencies A,X,Y)

Then at the beginning of your Gruntfile.js you call grunt.loadNpmTasks('grunt-collection'). Now Grunt will search up for the current directory to find the modules to load.

Features

  • Checks if the main Grunt task is a submodule of another project.
  • Creates a grunt-collection module in your local node_modules folder.
  • Creates a grunt-collection/package.json that is a mirror of your projects package.json file defined by options.config.
  • Filters out npm modules to load using globbing patterns defined in options.pattern.
  • Filters out which dependencies key to load from defined by options.scope.

##Installation

npm install --save load-grunt-parent-tasks

##Example

Basic Gruntfile.js

module.exports = function(grunt) {

  require('load-grunt-parent-tasks')(grunt);

};

Creates the following:

A
├── Gruntfile.js
├── node_modules
│   └── grunt-collection
│       └── package.json
└── package.json

Gruntfile.js with options

module.exports = function(grunt) {

  require('load-grunt-parent-tasks')(grunt, {
    config: 'package.json',
    pattern: 'grunt-*',
    scope: 'dependencies',
    module: 'abc-def'
  });

};

// Can also be written as:
module.exports = function(grunt) {

  require('load-grunt-parent-tasks')(grunt, {
    config: require('package.json'),
    pattern: ['grunt-*'],
    scope: ['dependencies'],
    module: 'abc-def'
  });

};

Creates the following:

A
├── Gruntfile.js
├── node_modules
│   └── abc-def
│       └── package.json
└── package.json

Options

config

Type: String, Object
Default: Path to nearest package.json

pattern

Type: String, Array
Default: 'grunt-*' (globbing pattern)

scope

Type: String, Array
Default: ['dependencies', 'optionalDependencies']

module

Type: String
Default: 'grunt-collection'

The module option can be changed in case grunt-collection ever conflicts with any other package name.

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.

License

MIT © Larry Gordon