[Pkg-javascript-commits] [node-use] 01/05: New upstream version 3.1.0

Praveen Arimbrathodiyil praveen at moszumanska.debian.org
Thu Jan 11 16:28:36 UTC 2018


This is an automated email from the git hooks/post-receive script.

praveen pushed a commit to branch master
in repository node-use.

commit 4612e20713cde0face7e65efa4a30551825d8037
Author: Pirate Praveen <praveen at debian.org>
Date:   Thu Jan 11 21:38:28 2018 +0530

    New upstream version 3.1.0
---
 .editorconfig  |  18 ++---
 .eslintrc.json | 228 +++++++++------------------------------------------------
 .gitignore     |  30 ++++++--
 .travis.yml    |  13 ++--
 LICENSE        |   2 +-
 README.md      |  72 +++++++++++-------
 index.js       |  92 +++++++++++++++--------
 package.json   |  40 +++++-----
 test.js        |  69 +++++++++++++----
 utils.js       |  24 ------
 10 files changed, 255 insertions(+), 333 deletions(-)

diff --git a/.editorconfig b/.editorconfig
index 991900b..449f0da 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -1,22 +1,14 @@
-# http://editorconfig.org
+# http://editorconfig.org/
 root = true
 
 [*]
-indent_style = space
-end_of_line = lf
 charset = utf-8
+end_of_line = lf
 indent_size = 2
-trim_trailing_whitespace = true
+indent_style = space
 insert_final_newline = true
+trim_trailing_whitespace = true
 
-[*.md]
-trim_trailing_whitespace = false
-insert_final_newline = false
-
-[test/**]
-trim_trailing_whitespace = false
-insert_final_newline = false
-
-[templates/**]
+[{**/{actual,fixtures,expected,templates}/**,*.md}]
 trim_trailing_whitespace = false
 insert_final_newline = false
diff --git a/.eslintrc.json b/.eslintrc.json
index 5b78706..61e8895 100644
--- a/.eslintrc.json
+++ b/.eslintrc.json
@@ -1,107 +1,36 @@
 {
-  "ecmaFeatures": {
-    "modules": true,
-    "experimentalObjectRestSpread": true
-  },
   "env": {
     "browser": false,
     "es6": true,
     "node": true,
     "mocha": true
   },
+
   "globals": {
     "document": false,
     "navigator": false,
     "window": false
   },
+
   "rules": {
     "accessor-pairs": 2,
-    "arrow-spacing": [
-      2,
-      {
-        "before": true,
-        "after": true
-      }
-    ],
-    "block-spacing": [
-      2,
-      "always"
-    ],
-    "brace-style": [
-      2,
-      "1tbs",
-      {
-        "allowSingleLine": true
-      }
-    ],
-    "comma-dangle": [
-      2,
-      "never"
-    ],
-    "comma-spacing": [
-      2,
-      {
-        "before": false,
-        "after": true
-      }
-    ],
-    "comma-style": [
-      2,
-      "last"
-    ],
+    "arrow-spacing": [2, { "before": true, "after": true }],
+    "block-spacing": [2, "always"],
+    "brace-style": [2, "1tbs", { "allowSingleLine": true }],
+    "comma-dangle": [2, "never"],
+    "comma-spacing": [2, { "before": false, "after": true }],
+    "comma-style": [2, "last"],
     "constructor-super": 2,
-    "curly": [
-      2,
-      "multi-line"
-    ],
-    "dot-location": [
-      2,
-      "property"
-    ],
+    "curly": [2, "multi-line"],
+    "dot-location": [2, "property"],
     "eol-last": 2,
-    "eqeqeq": [
-      2,
-      "allow-null"
-    ],
-    "generator-star-spacing": [
-      2,
-      {
-        "before": true,
-        "after": true
-      }
-    ],
-    "handle-callback-err": [
-      2,
-      "^(err|error)$"
-    ],
-    "indent": [
-      2,
-      2,
-      {
-        "SwitchCase": 1
-      }
-    ],
-    "key-spacing": [
-      2,
-      {
-        "beforeColon": false,
-        "afterColon": true
-      }
-    ],
-    "keyword-spacing": [
-      2,
-      {
-        "before": true,
-        "after": true
-      }
-    ],
-    "new-cap": [
-      2,
-      {
-        "newIsCap": true,
-        "capIsNew": false
-      }
-    ],
+    "eqeqeq": [2, "allow-null"],
+    "generator-star-spacing": [2, { "before": true, "after": true }],
+    "handle-callback-err": [2, "^(err|error)$" ],
+    "indent": [2, 2, { "SwitchCase": 1 }],
+    "key-spacing": [2, { "beforeColon": false, "afterColon": true }],
+    "keyword-spacing": [2, { "before": true, "after": true }],
+    "new-cap": [2, { "newIsCap": true, "capIsNew": false }],
     "new-parens": 2,
     "no-array-constructor": 2,
     "no-caller": 2,
@@ -121,18 +50,12 @@
     "no-extend-native": 2,
     "no-extra-bind": 2,
     "no-extra-boolean-cast": 2,
-    "no-extra-parens": [
-      2,
-      "functions"
-    ],
+    "no-extra-parens": [2, "functions"],
     "no-fallthrough": 2,
     "no-floating-decimal": 2,
     "no-func-assign": 2,
     "no-implied-eval": 2,
-    "no-inner-declarations": [
-      2,
-      "functions"
-    ],
+    "no-inner-declarations": [2, "functions"],
     "no-invalid-regexp": 2,
     "no-irregular-whitespace": 2,
     "no-iterator": 2,
@@ -142,12 +65,7 @@
     "no-mixed-spaces-and-tabs": 2,
     "no-multi-spaces": 2,
     "no-multi-str": 2,
-    "no-multiple-empty-lines": [
-      2,
-      {
-        "max": 1
-      }
-    ],
+    "no-multiple-empty-lines": [2, { "max": 1 }],
     "no-native-reassign": 0,
     "no-negated-in-lhs": 2,
     "no-new": 2,
@@ -173,103 +91,27 @@
     "no-undef": 2,
     "no-undef-init": 2,
     "no-unexpected-multiline": 2,
-    "no-unneeded-ternary": [
-      2,
-      {
-        "defaultAssignment": false
-      }
-    ],
+    "no-unneeded-ternary": [2, { "defaultAssignment": false }],
     "no-unreachable": 2,
-    "no-unused-vars": [
-      2,
-      {
-        "vars": "all",
-        "args": "none"
-      }
-    ],
+    "no-unused-vars": [2, { "vars": "all", "args": "none" }],
     "no-useless-call": 0,
     "no-with": 2,
-    "one-var": [
-      0,
-      {
-        "initialized": "never"
-      }
-    ],
-    "operator-linebreak": [
-      0,
-      "after",
-      {
-        "overrides": {
-          "?": "before",
-          ":": "before"
-        }
-      }
-    ],
-    "padded-blocks": [
-      0,
-      "never"
-    ],
-    "quotes": [
-      2,
-      "single",
-      "avoid-escape"
-    ],
+    "one-var": [0, { "initialized": "never" }],
+    "operator-linebreak": [0, "after", { "overrides": { "?": "before", ":": "before" } }],
+    "padded-blocks": [0, "never"],
+    "quotes": [2, "single", "avoid-escape"],
     "radix": 2,
-    "semi": [
-      2,
-      "always"
-    ],
-    "semi-spacing": [
-      2,
-      {
-        "before": false,
-        "after": true
-      }
-    ],
-    "space-before-blocks": [
-      2,
-      "always"
-    ],
-    "space-before-function-paren": [
-      2,
-      "never"
-    ],
-    "space-in-parens": [
-      2,
-      "never"
-    ],
+    "semi": [2, "always"],
+    "semi-spacing": [2, { "before": false, "after": true }],
+    "space-before-blocks": [2, "always"],
+    "space-before-function-paren": [2, "never"],
+    "space-in-parens": [2, "never"],
     "space-infix-ops": 2,
-    "space-unary-ops": [
-      2,
-      {
-        "words": true,
-        "nonwords": false
-      }
-    ],
-    "spaced-comment": [
-      0,
-      "always",
-      {
-        "markers": [
-          "global",
-          "globals",
-          "eslint",
-          "eslint-disable",
-          "*package",
-          "!",
-          ","
-        ]
-      }
-    ],
+    "space-unary-ops": [2, { "words": true, "nonwords": false }],
+    "spaced-comment": [0, "always", { "markers": ["global", "globals", "eslint", "eslint-disable", "*package", "!", ","] }],
     "use-isnan": 2,
     "valid-typeof": 2,
-    "wrap-iife": [
-      2,
-      "any"
-    ],
-    "yoda": [
-      2,
-      "never"
-    ]
+    "wrap-iife": [2, "any"],
+    "yoda": [2, "never"]
   }
 }
diff --git a/.gitignore b/.gitignore
index 80a228c..4bf0a60 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,15 +1,29 @@
+# always ignore files
 *.DS_Store
+.idea
 *.sublime-*
-_gh_pages
-bower_components
+
+# test related, or directories generated by tests
+test/actual
+actual
+coverage
+.nyc*
+
+# npm
 node_modules
 npm-debug.log
-actual
-test/actual
+
+# yarn
+yarn.lock
+yarn-error.log
+
+# misc
+_gh_pages
+_draft
+_drafts
+bower_components
+vendor
 temp
 tmp
 TODO.md
-vendor
-.idea
-benchmark
-coverage
+package-lock.json
\ No newline at end of file
diff --git a/.travis.yml b/.travis.yml
index cb1d261..1686664 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,12 +1,15 @@
 sudo: false
+os:
+  - linux
+  - osx
 language: node_js
 node_js:
+  - node
+  - '9'
+  - '8'
+  - '7'
+  - '6'
   - '5'
   - '4'
   - '0.12'
   - '0.10'
-matrix:
-  fast_finish: true
-  allow_failures:
-    - node_js: '0.10'
-    - node_js: '0.12'
diff --git a/LICENSE b/LICENSE
index 1e49edf..e33d14b 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,6 +1,6 @@
 The MIT License (MIT)
 
-Copyright (c) 2015-2016, Jon Schlinkert.
+Copyright (c) 2015-2017, Jon Schlinkert.
 
 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
diff --git a/README.md b/README.md
index 13ddb9d..bd4e325 100644
--- a/README.md
+++ b/README.md
@@ -1,13 +1,15 @@
-# use [![NPM version](https://img.shields.io/npm/v/use.svg?style=flat)](https://www.npmjs.com/package/use) [![NPM downloads](https://img.shields.io/npm/dm/use.svg?style=flat)](https://npmjs.org/package/use) [![Build Status](https://img.shields.io/travis/jonschlinkert/use.svg?style=flat)](https://travis-ci.org/jonschlinkert/use)
+# use [![NPM version](https://img.shields.io/npm/v/use.svg?style=flat)](https://www.npmjs.com/package/use) [![NPM monthly downloads](https://img.shields.io/npm/dm/use.svg?style=flat)](https://npmjs.org/package/use) [![NPM total downloads](https://img.shields.io/npm/dt/use.svg?style=flat)](https://npmjs.org/package/use) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/use.svg?style=flat&label=Travis)](https://travis-ci.org/jonschlinkert/use)
 
-Easily add plugin support to your node.js application.
+> Easily add plugin support to your node.js application.
+
+Please consider following this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support.
 
 ## Install
 
 Install with [npm](https://www.npmjs.com/):
 
 ```sh
-$ npm install use --save
+$ npm install --save use
 ```
 
 A different take on plugin handling! This is not a middleware system, if you need something that handles async middleware, [ware](https://github.com/segmentio/ware) is great for that.
@@ -20,51 +22,69 @@ var use = require('use');
 
 See the [examples folder](./examples) for usage examples.
 
-## Related projects
-
-You might also be interested in these projects:
+## About
 
-* [base-methods](https://www.npmjs.com/package/base-methods): base-methods is the foundation for creating modular, unit testable and highly pluggable node.js applications, starting… [more](https://www.npmjs.com/package/base-methods) | [homepage](https://github.com/jonschlinkert/base-methods)
-* [ware](https://www.npmjs.com/package/ware): Easily create your own middleware layer. | [homepage](https://github.com/segmentio/ware)
+<details>
+<summary><strong>Contributing</strong></summary>
 
-## Contributing
+Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).
 
-Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/jonschlinkert/use/issues/new).
+</details>
 
-## Building docs
+<details>
+<summary><strong>Running Tests</strong></summary>
 
-Generate readme and API documentation with [verb](https://github.com/verbose/verb):
+Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
 
 ```sh
-$ npm install verb && npm run docs
+$ npm install && npm test
 ```
 
-Or, if [verb](https://github.com/verbose/verb) is installed globally:
+</details>
 
-```sh
-$ verb
-```
+<details>
+<summary><strong>Building docs</strong></summary>
 
-## Running tests
+_(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_
 
-Install dev dependencies:
+To generate the readme, run the following command:
 
 ```sh
-$ npm install -d && npm test
+$ npm install -g verbose/verb#dev verb-generate-readme && verb
 ```
 
-## Author
+</details>
+
+### Related projects
+
+You might also be interested in these projects:
+
+* [base-plugins](https://www.npmjs.com/package/base-plugins): Adds 'smart plugin' support to your base application. | [homepage](https://github.com/node-base/base-plugins "Adds 'smart plugin' support to your base application.")
+* [base](https://www.npmjs.com/package/base): Framework for rapidly creating high quality, server-side node.js applications, using plugins like building blocks | [homepage](https://github.com/node-base/base "Framework for rapidly creating high quality, server-side node.js applications, using plugins like building blocks")
+* [ware](https://www.npmjs.com/package/ware): Easily create your own middleware layer. | [homepage](https://github.com/segmentio/ware "Easily create your own middleware layer.")
+
+### Contributors
+
+| **Commits** | **Contributor** | 
+| --- | --- |
+| 33 | [jonschlinkert](https://github.com/jonschlinkert) |
+| 7 | [charlike-old](https://github.com/charlike-old) |
+| 2 | [doowb](https://github.com/doowb) |
+| 2 | [wtgtybhertgeghgtwtg](https://github.com/wtgtybhertgeghgtwtg) |
+
+### Author
 
 **Jon Schlinkert**
 
+* [linkedin/in/jonschlinkert](https://linkedin.com/in/jonschlinkert)
 * [github/jonschlinkert](https://github.com/jonschlinkert)
-* [twitter/jonschlinkert](http://twitter.com/jonschlinkert)
+* [twitter/jonschlinkert](https://twitter.com/jonschlinkert)
 
-## License
+### License
 
-Copyright © 2016, [Jon Schlinkert](https://github.com/jonschlinkert).
-Released under the [MIT license](https://github.com/jonschlinkert/use/blob/master/LICENSE).
+Copyright © 2017, [Jon Schlinkert](https://github.com/jonschlinkert).
+Released under the [MIT License](LICENSE).
 
 ***
 
-_This file was generated by [verb](https://github.com/verbose/verb), v0.9.0, on May 11, 2016._
\ No newline at end of file
+_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on December 03, 2017._
\ No newline at end of file
diff --git a/index.js b/index.js
index f707906..11edc71 100644
--- a/index.js
+++ b/index.js
@@ -1,26 +1,23 @@
 /*!
  * use <https://github.com/jonschlinkert/use>
  *
- * Copyright (c) 2015, Jon Schlinkert.
- * Licensed under the MIT License.
+ * Copyright (c) 2015, 2017, Jon Schlinkert.
+ * Released under the MIT License.
  */
 
 'use strict';
 
-var utils = require('./utils');
+var typeOf = require('kind-of');
 
-module.exports = function base(app, opts) {
-  if (!utils.isObject(app) && typeof app !== 'function') {
-    throw new TypeError('use: expect `app` be an object or function');
+module.exports = function base(app, options) {
+  if (typeOf(app) !== 'object' && typeof app !== 'function') {
+    throw new TypeError('expected an object or function');
   }
 
-  if (!utils.isObject(opts)) {
-    opts = {};
-  }
-
-  var prop = utils.isString(opts.prop) ? opts.prop : 'fns';
-  if (!utils.isArray(app[prop])) {
-    utils.define(app, prop, []);
+  var opts = typeOf(options) === 'object' ? options : {};
+  var prop = typeof opts.prop === 'string' ? opts.prop : 'fns';
+  if (!Array.isArray(app[prop])) {
+    define(app, prop, []);
   }
 
   /**
@@ -53,7 +50,7 @@ module.exports = function base(app, opts) {
    * @api public
    */
 
-  utils.define(app, 'use', use);
+  define(app, 'use', use);
 
   /**
    * Run all plugins on `fns`. Any plugin that returns a function
@@ -69,9 +66,17 @@ module.exports = function base(app, opts) {
    * @api public
    */
 
-  utils.define(app, 'run', function(val) {
-    if (!utils.isObject(val)) return;
-    decorate(val);
+  define(app, 'run', function(val) {
+    if (typeOf(val) !== 'object') return;
+
+    if (!val.use || !val.run) {
+      define(val, prop, val[prop] || []);
+      define(val, 'use', use);
+    }
+
+    if (!val[prop] || val[prop].indexOf(base) === -1) {
+      val.use(base);
+    }
 
     var self = this || app;
     var fns = self[prop];
@@ -89,33 +94,60 @@ module.exports = function base(app, opts) {
    * `fns` array to be called by the `run` method.
    */
 
-  function use(fn, options) {
+  function use(type, fn, options) {
+    var offset = 1;
+
+    if (typeof type === 'string' || Array.isArray(type)) {
+      fn = wrap(type, fn);
+      offset++;
+    } else {
+      options = fn;
+      fn = type;
+    }
+
     if (typeof fn !== 'function') {
-      throw new TypeError('.use expects `fn` be a function');
+      throw new TypeError('expected a function');
     }
 
     var self = this || app;
-    if (typeof opts.fn === 'function') {
-      opts.fn.call(self, self, options);
+    var fns = self[prop];
+
+    var args = [].slice.call(arguments, offset);
+    args.unshift(self);
+
+    if (typeof opts.hook === 'function') {
+      opts.hook.apply(self, args);
     }
 
-    var plugin = fn.call(self, self);
-    if (typeof plugin === 'function') {
-      var fns = self[prop];
-      fns.push(plugin);
+    var val = fn.apply(self, args);
+    if (typeof val === 'function' && fns.indexOf(val) === -1) {
+      fns.push(val);
     }
     return self;
   }
 
   /**
-   * Ensure the `.use` method exists on `val`
+   * Wrap a named plugin function so that it's only called on objects of the
+   * given `type`
+   *
+   * @param {String} `type`
+   * @param {Function} `fn` Plugin function
+   * @return {Function}
    */
 
-  function decorate(val) {
-    if (!val.use || !val.run) {
-      base(val);
-    }
+  function wrap(type, fn) {
+    return function plugin() {
+      return this.type === type ? fn.apply(this, arguments) : plugin;
+    };
   }
 
   return app;
 };
+
+function define(obj, key, val) {
+  Object.defineProperty(obj, key, {
+    configurable: true,
+    writable: true,
+    value: val
+  });
+}
diff --git a/package.json b/package.json
index a2c68c3..21582fc 100644
--- a/package.json
+++ b/package.json
@@ -1,17 +1,22 @@
 {
   "name": "use",
   "description": "Easily add plugin support to your node.js application.",
-  "version": "2.0.0",
+  "version": "3.1.0",
   "homepage": "https://github.com/jonschlinkert/use",
   "author": "Jon Schlinkert (https://github.com/jonschlinkert)",
+  "contributors": [
+    "Brian Woodward (https://twitter.com/doowb)",
+    "Jon Schlinkert (http://twitter.com/jonschlinkert)",
+    "Olsten Larck (https://i.am.charlike.online)",
+    "(https://github.com/wtgtybhertgeghgtwtg)"
+  ],
   "repository": "jonschlinkert/use",
   "bugs": {
     "url": "https://github.com/jonschlinkert/use/issues"
   },
   "license": "MIT",
   "files": [
-    "index.js",
-    "utils.js"
+    "index.js"
   ],
   "main": "index.js",
   "engines": {
@@ -21,20 +26,18 @@
     "test": "mocha"
   },
   "dependencies": {
-    "define-property": "^0.2.5",
-    "isarray": "^1.0.0",
-    "isobject": "^2.1.0",
-    "lazy-cache": "^2.0.1"
+    "kind-of": "^6.0.2"
   },
   "devDependencies": {
-    "base-plugins": "^0.4.1",
-    "extend-shallow": "^2.0.1",
-    "gulp": "^3.9.0",
-    "gulp-eslint": "^1.1.0",
-    "gulp-format-md": "^0.1.9",
-    "gulp-istanbul": "^0.10.2",
-    "gulp-mocha": "^2.1.3",
-    "mocha": "^2.4.5"
+    "base-plugins": "^1.0.0",
+    "define-property": "^2.0.0",
+    "extend-shallow": "^3.0.1",
+    "gulp": "^3.9.1",
+    "gulp-eslint": "^4.0.0",
+    "gulp-format-md": "^1.0.0",
+    "gulp-istanbul": "^1.1.2",
+    "gulp-mocha": "^3.0.1",
+    "mocha": "^4.0.1"
   },
   "keywords": [
     "use"
@@ -42,13 +45,14 @@
   "verb": {
     "related": {
       "list": [
-        "base-methods",
+        "base",
+        "base-plugins",
         "ware"
       ]
     },
     "reflinks": [
-      "ware",
-      "verb"
+      "verb",
+      "ware"
     ],
     "toc": false,
     "layout": "default",
diff --git a/test.js b/test.js
index 4249402..40666e8 100644
--- a/test.js
+++ b/test.js
@@ -16,7 +16,7 @@ describe('use', function() {
       use(123);
     }
     assert.throws(fixture, TypeError);
-    assert.throws(fixture, /expect `app` be an object or function/);
+    assert.throws(fixture, /expected an object or function/);
   });
 
   it('should throw TypeError if not a function passed to `.use` method', function() {
@@ -24,22 +24,22 @@ describe('use', function() {
       use({}).use(123);
     }
     assert.throws(fixture, TypeError);
-    assert.throws(fixture, /use expects `fn` be a function/);
+    assert.throws(fixture, /expected a function/);
   });
 
-  it('should allow passing `opts.fn` to merge options from each plugin to app options', function() {
-    var limon = {options: {
-      foo: 'bar'
-    }};
-    use(limon, {
-      fn: function(app, options) {
+  it('should allow passing `opts.hook` to merge options from each plugin to app options', function() {
+    var obj = {options: {foo: 'bar'}};
+    var count = 0;
+    use(obj, {
+      hook: function(app, options) {
         assert.strictEqual(this.options.foo, 'bar');
         this.options = extend(this.options, options);
         this.options.qux = 123;
+        count++;
       }
     });
 
-    limon
+    obj
       .use(function() {
         assert.strictEqual(this.options.foo, 'bar');
         assert.strictEqual(this.options.xxx, 'yyy');
@@ -51,15 +51,17 @@ describe('use', function() {
         assert.strictEqual(this.options.qux, 123);
         assert.strictEqual(this.options.ccc, 'ddd');
       }, { ccc: 'ddd' });
+
+     assert.equal(count, 2);
   });
 
   it('should not extend options if `opts.fn` not given (#3)', function() {
-    var limon = {options: {
+    var obj = {options: {
       foo: 'bar'
     }};
-    use(limon);
+    use(obj);
 
-    limon
+    obj
       .use(function() {
         assert.strictEqual(this.options.foo, 'bar');
         assert.strictEqual(this.options.xxx, undefined);
@@ -105,8 +107,7 @@ describe('use', function() {
     use(app, { prop: 'plugins' });
     assert.strictEqual(Array.isArray(app.fns), false);
     assert.strictEqual(Array.isArray(app.plugins), true);
-    assert(app.plugins.length === 0);
-
+    assert.equal(app.plugins.length, 0);
   });
 
   it('should immediately invoke a plugin function', function() {
@@ -277,6 +278,44 @@ describe('run', function() {
     assert.deepEqual(foo,  { a: 'b', c: 'd', e: 'f' });
     assert.equal(typeof foo.use, 'function');
     assert.equal(typeof foo.run, 'function');
-    assert.equal(typeof foo.fns, 'undefined');
+    assert(Array.isArray(foo.fns));
+  });
+
+  describe('named plugins', function() {
+    it('should register named plugins', function() {
+      var app = {type: 'app'};
+      use(app);
+
+      var names = [];
+
+      app.use('foo', function() {
+        names.push(this.type);
+      });
+
+      app.use('bar', function() {
+        names.push(this.type);
+      });
+
+      app.use('baz', function() {
+        names.push(this.type);
+      });
+
+      var foo = {};
+      foo.type = 'foo';
+      foo.parent = app;
+      app.run(foo);
+
+      var bar = {};
+      bar.type = 'bar';
+      bar.parent = foo;
+      foo.run(bar);
+
+      var baz = {};
+      baz.type = 'baz';
+      baz.parent = bar;
+      bar.run(baz);
+
+      assert.deepEqual(names, ['foo', 'bar', 'baz']);
+    });
   });
 });
diff --git a/utils.js b/utils.js
deleted file mode 100644
index 18cd0ce..0000000
--- a/utils.js
+++ /dev/null
@@ -1,24 +0,0 @@
-'use strict';
-
-var utils = require('lazy-cache')(require);
-var fn = require;
-require = utils; // eslint-disable-line
-
-/**
- * Lazily required module dependencies
- */
-
-require('define-property', 'define');
-require('isarray', 'isArray');
-require('isobject', 'isObject');
-require = fn; // eslint-disable-line
-
-utils.isString = function(val) {
-  return val && typeof val === 'string';
-};
-
-/**
- * Expose `utils` modules
- */
-
-module.exports = utils;

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-use.git



More information about the Pkg-javascript-commits mailing list