pax_global_header00006660000000000000000000000064130450525300014507gustar00rootroot0000000000000052 comment=55cf056777085fa2c647e1d0c650ace7382b3fa2 gulp-load-plugins-1.5.0/000077500000000000000000000000001304505253000150555ustar00rootroot00000000000000gulp-load-plugins-1.5.0/.editorconfig000066400000000000000000000001421304505253000175270ustar00rootroot00000000000000root = true [*] end_of_line = lf insert_final_newline = true indent_style = space indent_size = 2gulp-load-plugins-1.5.0/.eslintrc000066400000000000000000000003341304505253000167010ustar00rootroot00000000000000{ "extends": "standard", "env": { "node": true }, "globals": { "describe": true, "it": true, "before": true }, "rules": { "semi": [2, "always"], "space-before-function-paren": 0 } } gulp-load-plugins-1.5.0/.gitattributes000066400000000000000000000000141304505253000177430ustar00rootroot00000000000000* text=auto gulp-load-plugins-1.5.0/.gitignore000066400000000000000000000000351304505253000170430ustar00rootroot00000000000000/node_modules npm-debug.log gulp-load-plugins-1.5.0/.travis.yml000066400000000000000000000000741304505253000171670ustar00rootroot00000000000000sudo: false language: node_js node_js: - "4.1" - "0.12" gulp-load-plugins-1.5.0/CONTRIBUTING.md000066400000000000000000000031261304505253000173100ustar00rootroot00000000000000# Contributing to gulp-load-plugins Firstly, contributions are hugely welcomed and much appreciated! __If you've never contributed to an open source project before, please don't let that put you off!__ I am more than happy to help with PRs, etc, please ping me on GitHub or email jack at jackfranklin dot net. ### Working on an issue Before you start working on an idea, make sure: - If you're working to fix an [outstanding issue](https://github.com/jackfranklin/gulp-load-plugins/issues), please leave a comment that you're working on it so that we don't end up with duplicated effort. - If you have an idea for a new feature, please raise it as an [issue](https://github.com/jackfranklin/gulp-load-plugins/issues) so we can make sure the feature is right for the plugin, and you don't end up wasting effort. - If you're working on a bug fix, make sure you're running the latest version of gulp-load-plugins, in case the bug has since been fixed in a newer version. ### Writing the code - Follow the code standards of the existing project. We use ESLint to keep our code formatted, and running `npm test` will first run `eslint` before the tests so you can ensure you've followed the style. - Be sure to add yourself as a contributor to the [package.json](https://github.com/jackfranklin/gulp-load-plugins/blob/master/package.json) file. - If possible, write a test that covers the bug fix / feature addition that you're making. If you're unsure how to write the test, open your PR first and someone will help you. - If you have any questions at all, please don't hesitate to get in touch. We're here to help :) gulp-load-plugins-1.5.0/LICENSE000066400000000000000000000020701304505253000160610ustar00rootroot00000000000000The MIT License (MIT) Copyright (c) 2016 Jack Franklin 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. gulp-load-plugins-1.5.0/README.md000066400000000000000000000247261304505253000163470ustar00rootroot00000000000000# gulp-load-plugins [![npm](https://nodei.co/npm/gulp-load-plugins.svg?downloads=true)](https://nodei.co/npm/gulp-load-plugins/) > Loads gulp plugins from package dependencies and attaches them to an object of your choice. [![Build Status](https://travis-ci.org/jackfranklin/gulp-load-plugins.svg?branch=master)](https://travis-ci.org/jackfranklin/gulp-load-plugins) ## Install ```sh $ npm install --save-dev gulp-load-plugins ``` ## Usage Given a `package.json` file that has some dependencies within: ```json { "dependencies": { "gulp-jshint": "*", "gulp-concat": "*" } } ``` Adding this into your `Gulpfile.js`: ```js var gulp = require('gulp'); var gulpLoadPlugins = require('gulp-load-plugins'); var plugins = gulpLoadPlugins(); ``` Or, even shorter: ```js var plugins = require('gulp-load-plugins')(); ``` Will result in the following happening (roughly, plugins are lazy loaded but in practice you won't notice any difference): ```js plugins.jshint = require('gulp-jshint'); plugins.concat = require('gulp-concat'); ``` You can then use the plugins just like you would if you'd manually required them, but referring to them as `plugins.name()`, rather than just `name()`. This frees you up from having to manually require each gulp plugin. ## Options You can pass in an object of options that are shown below: (the values for the keys are the defaults): ```js gulpLoadPlugins({ DEBUG: false, // when set to true, the plugin will log info to console. Useful for bug reporting and issue debugging pattern: ['gulp-*', 'gulp.*', '@*/gulp{-,.}*'], // the glob(s) to search for overridePattern: true, // When true, overrides the built-in patterns. Otherwise, extends built-in patterns matcher list. config: 'package.json', // where to find the plugins, by default searched up from process.cwd() scope: ['dependencies', 'devDependencies', 'peerDependencies'], // which keys in the config to look within replaceString: /^gulp(-|\.)/, // what to remove from the name of the module when adding it to the context camelize: true, // if true, transforms hyphenated plugins names to camel case lazy: true, // whether the plugins should be lazy loaded on demand rename: {}, // a mapping of plugins to rename renameFn: function (name) { ... }, // a function to handle the renaming of plugins (the default works) postRequireTransforms: {}, // see documentation below maintainScope: true // toggles loading all npm scopes like non-scoped packages }); ``` ## Multiple `config` locations While it's possile to grab plugins from another location, often times you may want to extend from another package that enables you to keep your own `package.json` free from duplicates, but still add in your own plugins that are needed for your project. Since the `config` option accepts an object, you can merge together multiple locations using the [lodash.merge](https://www.npmjs.com/package/lodash.merge) package: ```js var merge = require('lodash.merge'); var packages = merge( require('dep/package.json'), require('./package.json') ); // Utilities var $ = gulpLoadPlugins({ config: packages }); ``` ## `postRequireTransforms` (1.3+ only) This enables you to transform the plugin after it has been required by gulp-load-plugins. For example, one particular plugin (let's say, `gulp-foo`), might need you to call a function to configure it before it is used. So you would end up with: ```js var $ = require('gulp-load-plugins')(); $.foo = $.foo.configure(...); ``` This is a bit messy. Instead you can pass a `postRequireTransforms` object which will enable you to do this: ```js var $ = require('gulp-load-plugins')({ postRequireTransforms: { foo: function(foo) { return foo.configure(...); } } }); $.foo // is already configured ``` Everytime a plugin is loaded, we check to see if a transform is defined, and if so, we call that function, passing in the loaded plugin. Whatever this function returns is then used as the value that's returned by gulp-load-plugins. For 99% of gulp-plugins you will not need this behaviour, but for the odd plugin it's a nice way of keeping your code cleaner. ## Renaming From 0.8.0, you can pass in an object of mappings for renaming plugins. For example, imagine you want to load the `gulp-ruby-sass` plugin, but want to refer to it as just `sass`: ```js gulpLoadPlugins({ rename: { 'gulp-ruby-sass': 'sass' } }); ``` Note that if you specify the `renameFn` options with your own custom rename function, while the `rename` option will still work, the `replaceString` and `camelize` options will be ignored. ## npm Scopes `gulp-load-plugins` comes with [npm scope](https://docs.npmjs.com/misc/scope) support. By default, the scoped plugins are accessible through an object on `plugins` that represents the scope. When `maintainScope = false`, the plugins are available in the top level just like any other non-scoped plugins. __Note:__ `maintainScope` is only available in Version 1.4.0 and up. For example, if the plugin is `@myco/gulp-test-plugin` then you can access the plugin as shown in the following example: ```js var scoped = require('gulp-load-plugins')({ // true is the default value maintainScope: true, }); scoped.myco.testPlugin(); var nonScoped = require('gulp-load-plugins')({ maintainScope: false, }); nonScoped.testPlugin(); ``` ## Lazy Loading In 0.4.0 and prior, lazy loading used to only work with plugins that return a function. In newer versions though, lazy loading should work for any plugin. If you have a problem related to this please try disabling lazy loading and see if that fixes it. Feel free to open an issue on this repo too. ## Override Pattern In 1.4.0 and prior, configuring the `pattern` option would override the built-in `['gulp-*', 'gulp.*', '@*/gulp{-,.}*']`. If `overridePattern: false`, the configured `pattern` will now extends the built-in matching. For example, both are equivilant statements. ```js var overridePlugins = require('gulp-load-plugins')({ // true is the default value overridePattern: true, pattern: ['gulp-*', 'gulp.*', '@*/gulp{-,.}*', 'foo-bar'] }); var extendedPlugins = require('gulp-load-plugins')({ overridePattern: false, pattern: ['foo-bar'] }); ``` ## Credit Credit largely goes to @sindresorhus for his [load-grunt-plugins](https://github.com/sindresorhus/load-grunt-tasks) plugin. This plugin is almost identical, just tweaked slightly to work with Gulp and to expose the required plugins. ## Changelog ##### 1.5.0 - added `overridePattern` - thanks @bretkikehara - [PR](https://github.com/jackfranklin/gulp-load-plugins/pull/127) ##### 1.4.0 - added `maintainScope` - thanks @bretkikehara - [PR](https://github.com/jackfranklin/gulp-load-plugins/pull/126) ##### 1.3.0 - added `postRequireTransforms` - thanks @vinitm - [PR](https://github.com/jackfranklin/gulp-load-plugins/pull/119) ##### 1.2.4 - Fix bug in 1.2.3 release that stopped logging output in Gulp 3 - thanks @doowb ##### 1.2.3 - Update dependencies in line with Gulp 4 - [PR](https://github.com/jackfranklin/gulp-load-plugins/pull/108) - thanks @doowb ##### 1.2.2 - revert the previous PR in 1.2.1 which broke configuration loading for some users ##### 1.2.1 - fix using the wrong `require` function - [PR](https://github.com/jackfranklin/gulp-load-plugins/pull/104) - thanks @mwessner ##### 1.2 - throw an error if two packages are loaded that end up having the same name after the `replaceString` has been removed - thanks @carloshpds ##### 1.1 - added `DEBUG` option to turn on logging and help us debug issues - thanks @dcamilleri ##### 1.0.0 - added `renameFn` function to give users complete control over the name a plugin should be given when loaded - thanks @callumacrae ##### 1.0.0-rc.1 - This is the first release candidate for what will become version 1 of gulp-load-plugins. Once a fix for [#70](https://github.com/jackfranklin/gulp-load-plugins/issues/70) is landed, I plan to release V1. - **Breaking Change** support for `NODE_PATH` is no longer supported. It was causing complexities and in [the PR that droppped support](https://github.com/jackfranklin/gulp-load-plugins/pull/75) no one shouted that they required `NODE_PATH` support. ##### 0.10.0 - throw a more informative error if a plugin is loaded that gulp-load-plugins can't find. [PR](https://github.com/jackfranklin/gulp-load-plugins/pull/68) - thanks @connor4312 - allow `require` to look on the `NODE_PATH` if it can't find the module in the working directory. [PR](https://github.com/jackfranklin/gulp-load-plugins/pull/69) - thanks @chmanie ##### 0.9.0 - add support for npm-scoped plugins. [PR](https://github.com/jackfranklin/gulp-load-plugins/pull/63) - thanks @hbetts ##### 0.8.1 - fixed a bug where gulp-load-plugins would use the right `package.json` file but the wrong `node_modules` directory - thanks @callumacrae ##### 0.8.0 - add the ability to rename plugins that gulp-load-plugins loads in. ##### 0.7.1 - add `files` property to package.json so only required files are downloaded when installed - thanks @shinnn ##### 0.7.0 - support loading plugins with a dot in the name, such as `gulp.spritesmith` - thanks to @MRuy - upgrade multimatch to 1.0.0 ##### 0.6.0 - Fix issues around plugin picking wrong package.json file - thanks @iliakan (see [issue](https://github.com/jackfranklin/gulp-load-plugins/issues/35)). ##### 0.5.3 - Show a nicer error if the plugin is unable to load any configuration and hence can't find any dependencies to load ##### 0.5.2 - Swap out globule for multimatch, thanks @sindresorhus. ##### 0.5.1 - Updated some internal dependencies which should see some small improvements - thanks @shinnn for this contribution. ##### 0.5.0 - improved lazy loading so it should work with plugins that don't just return a function. Thanks to @nfroidure for help with this. ##### 0.4.0 - plugins are lazy loaded for performance benefit. Thanks @julien-f for this. ##### 0.3.0 - turn the `camelize` option on by default ##### 0.2.0 - added `camelize` option, thanks @kombucha. - renamed to `gulp-load-plugins`. ##### 0.1.1 - add link to this repository into `package.json` (thanks @ben-eb). ##### 0.1.0 - move to `gulpLoadplugins` returning an object with the tasks define. ##### 0.0.5 - added `replaceString` option to configure exactly what gets replace when the plugin adds the module to the context ##### 0.0.4 - fixed keyword typo so plugin appears in search for gulp plugins ##### 0.0.3 - removed accidental console.log I'd left in ##### 0.0.2 - fixed accidentally missing a dependency out of package.json ##### 0.0.1 - initial release gulp-load-plugins-1.5.0/index.js000066400000000000000000000134351304505253000165300ustar00rootroot00000000000000'use strict'; var hasGulplog = require('has-gulplog'); var micromatch = require('micromatch'); var unique = require('array-unique'); var findup = require('findup-sync'); var resolve = require('resolve'); var path = require('path'); function arrayify(el) { return Array.isArray(el) ? el : [el]; } function camelize(str) { return str.replace(/-(\w)/g, function(m, p1) { return p1.toUpperCase(); }); } // code from https://github.com/gulpjs/gulp-util/blob/master/lib/log.js // to use the same functionality as gulp-util for backwards compatibility // with gulp 3x cli function logger() { if (hasGulplog()) { // specifically deferring loading here to keep from registering it globally var gulplog = require('gulplog'); gulplog.info.apply(gulplog, arguments); } else { // specifically defering loading because it might not be used var fancylog = require('fancy-log'); fancylog.apply(null, arguments); } } function getPattern(options) { var defaultPatterns = ['gulp-*', 'gulp.*', '@*/gulp{-,.}*']; var overridePattern = 'overridePattern' in options ? !!options.overridePattern : true; if (overridePattern) { return arrayify(options.pattern || defaultPatterns); } return defaultPatterns.concat(arrayify(options.pattern)); } module.exports = function(options) { var finalObject = {}; var configObject; var requireFn; options = options || {}; var DEBUG = options.DEBUG || false; var pattern = getPattern(options); var config = options.config || findup('package.json', { cwd: parentDir }); var scope = arrayify(options.scope || ['dependencies', 'devDependencies', 'peerDependencies']); var replaceString = options.replaceString || /^gulp(-|\.)/; var camelizePluginName = options.camelize !== false; var lazy = 'lazy' in options ? !!options.lazy : true; var renameObj = options.rename || {}; var maintainScope = 'maintainScope' in options ? !!options.maintainScope : true; logDebug('Debug enabled with options: ' + JSON.stringify(options)); var renameFn = options.renameFn || function(name) { name = name.replace(replaceString, ''); return camelizePluginName ? camelize(name) : name; }; var postRequireTransforms = options.postRequireTransforms || {}; if (typeof options.requireFn === 'function') { requireFn = options.requireFn; } else if (typeof config === 'string') { requireFn = function(name) { // This searches up from the specified package.json file, making sure // the config option behaves as expected. See issue #56. var src = resolve.sync(name, { basedir: path.dirname(config) }); return require(src); }; } else { requireFn = require; } configObject = (typeof config === 'string') ? require(config) : config; if (!configObject) { throw new Error('Could not find dependencies. Do you have a package.json file in your project?'); } var names = scope.reduce(function(result, prop) { return result.concat(Object.keys(configObject[prop] || {})); }, []); logDebug(names.length + ' plugin(s) found: ' + names.join(' ')); pattern.push('!gulp-load-plugins'); function logDebug(message) { if (DEBUG) { logger('gulp-load-plugins: ' + message); } } function defineProperty(object, transform, requireName, name, maintainScope) { var err; if (object[requireName]) { logDebug('error: defineProperty ' + name); err = maintainScope ? 'Could not define the property "' + requireName + '", you may have repeated dependencies in your package.json like' + ' "gulp-' + requireName + '" and ' + '"' + requireName + '"' : 'Could not define the property "' + requireName + '", you may have repeated a dependency in another scope like' + ' "gulp-' + requireName + '" and ' + '"@foo/gulp-' + requireName + '"'; throw new Error(err); } if (lazy) { logDebug('lazyload: adding property ' + requireName); Object.defineProperty(object, requireName, { enumerable: true, get: function() { logDebug('lazyload: requiring ' + name + '...'); return transform(requireName, requireFn(name)); } }); } else { logDebug('requiring ' + name + '...'); object[requireName] = transform(requireName, requireFn(name)); } } function getRequireName(name) { var requireName; if (renameObj[name]) { requireName = options.rename[name]; } else { requireName = renameFn(name); } logDebug('renaming ' + name + ' to ' + requireName); return requireName; } function applyTransform(requireName, plugin) { var transform = postRequireTransforms[requireName]; if (transform && typeof transform === 'function') { // if postRequireTransform function is passed, pass it the plugin and return it logDebug('transforming ' + requireName); return transform(plugin); } else { return plugin; // if no postRequireTransform function passed, return the plugin as is } } var scopeTest = new RegExp('^@'); var scopeDecomposition = new RegExp('^@(.+)/(.+)'); unique(micromatch(names, pattern)).forEach(function(name) { var decomposition; var fObject = finalObject; if (scopeTest.test(name)) { decomposition = scopeDecomposition.exec(name); if (maintainScope) { if (!fObject.hasOwnProperty(decomposition[1])) { finalObject[decomposition[1]] = {}; } fObject = finalObject[decomposition[1]]; } defineProperty(fObject, applyTransform, getRequireName(decomposition[2]), name, maintainScope); } else { defineProperty(fObject, applyTransform, getRequireName(name), name, maintainScope); } }); return finalObject; }; var parentDir = path.dirname(module.parent.filename); // Necessary to get the current `module.parent` and resolve paths correctly. delete require.cache[__filename]; gulp-load-plugins-1.5.0/package.json000066400000000000000000000026301304505253000173440ustar00rootroot00000000000000{ "name": "gulp-load-plugins", "version": "1.5.0", "description": "Automatically load any gulp plugins in your package.json", "scripts": { "test": "npm run lint && NODE_PATH=test/global_modules mocha", "lint": "eslint **/*.js" }, "license": "MIT", "files": [ "index.js" ], "repository": "jackfranklin/gulp-load-plugins", "keywords": [ "gulpfriendly", "gulp", "require", "load", "plugins" ], "author": "Jack Franklin", "contributors": [ "Pascal Hartig", "Ben Briggs", "kombucha", "Nicolas Froidure", "Sindre Sorhus", "Julien Fontanet ", "Callum Macrae", "Hutson Betts", "Christian Maniewski", "Connor Peet", "Dorian Camilleri", "Carlos Henrique", "iamfrontender ", "Brian Woodward", "Zach Schnackel ", "Bret K. Ikehara " ], "dependencies": { "array-unique": "^0.2.1", "fancy-log": "^1.2.0", "findup-sync": "^0.4.0", "gulplog": "^1.0.0", "has-gulplog": "^0.1.0", "micromatch": "^2.3.8", "resolve": "^1.1.7" }, "devDependencies": { "capture-stream": "^0.1.2", "eslint": "2.13.1", "eslint-config-standard": "5.3.1", "eslint-plugin-promise": "1.3.2", "eslint-plugin-standard": "1.3.2", "mocha": "^2.1.0", "proxyquire": "^1.0.1", "sinon": "^1.9.1" } } gulp-load-plugins-1.5.0/test/000077500000000000000000000000001304505253000160345ustar00rootroot00000000000000gulp-load-plugins-1.5.0/test/global_modules/000077500000000000000000000000001304505253000210245ustar00rootroot00000000000000gulp-load-plugins-1.5.0/test/global_modules/gulp-test-global/000077500000000000000000000000001304505253000242065ustar00rootroot00000000000000gulp-load-plugins-1.5.0/test/global_modules/gulp-test-global/index.js000066400000000000000000000000411304505253000256460ustar00rootroot00000000000000module.exports = function () {}; gulp-load-plugins-1.5.0/test/index.js000066400000000000000000000166631304505253000175150ustar00rootroot00000000000000'use strict'; var assert = require('assert'); var sinon = require('sinon'); var capture = require('capture-stream'); var path = require('path'); var gulpLoadPlugins = (function() { var wrapInFunc = function(value) { return function() { return value; }; }; var proxyquire = require('proxyquire').noCallThru(); return proxyquire('../', { 'gulp-foo': wrapInFunc({ name: 'foo' }), 'gulp-bar': wrapInFunc({ name: 'bar' }), 'bar': wrapInFunc({ name: 'bar' }), 'gulp-foo-bar': wrapInFunc({ name: 'foo-bar' }), 'jack-foo': wrapInFunc({ name: 'jack-foo' }), 'gulp-insert': { 'append': wrapInFunc({ name: 'insert.append' }), 'wrap': wrapInFunc({ name: 'insert.wrap' }) }, 'gulp.baz': wrapInFunc({ name: 'baz' }), 'findup-sync': function() { return null; }, '@myco/gulp-test-plugin': wrapInFunc({ name: 'test' }) }); })(); describe('configuration', function() { it('throws a nice error if no configuration is found', function() { assert.throws(function() { gulpLoadPlugins({ config: null }); }, /Could not find dependencies. Do you have a package.json file in your project?/); }); it("throws a nice error if there're repeated dependencies pattern in package.json ", function() { assert.throws(function() { gulpLoadPlugins({ pattern: [ '*', '!gulp' ], config: { dependencies: { 'bar': '*', 'gulp-bar': '~0.0.12' } } }); }, /Could not define the property "bar", you may have repeated dependencies in your package.json like "gulp-bar" and "bar"/); }); it("throws a nice error if there're repeated package names pattern in package.json ", function() { assert.throws(function() { gulpLoadPlugins({ config: { dependencies: { '@foo/gulp-bar': '*', 'gulp-bar': '~0.0.12' } }, maintainScope: false }); }, /Could not define the property "bar", you may have repeated a dependency in another scope like "gulp-bar" and "@foo\/gulp-bar"/); }); }); // Contains common tests with and without lazy mode. var commonTests = function(lazy) { it('loads things in', function() { var x = gulpLoadPlugins({ lazy: lazy, config: { dependencies: { 'gulp-foo': '1.0.0', 'gulp-bar': '*', 'gulp-insert': '*', 'gulp.baz': '*' } } }); assert.deepEqual(x.foo(), { name: 'foo' }); assert.deepEqual(x.bar(), { name: 'bar' }); assert.deepEqual(x.baz(), { name: 'baz' }); assert.deepEqual(x.insert.wrap(), { name: 'insert.wrap' }); assert.deepEqual(x.insert.append(), { name: 'insert.append' }); }); it('can take a pattern override', function() { var x = gulpLoadPlugins({ lazy: lazy, pattern: 'jack-*', replaceString: 'jack-', config: { dependencies: { 'jack-foo': '1.0.0', 'gulp-bar': '*' } } }); assert.deepEqual(x.foo(), { name: 'jack-foo' }); assert(!x.bar); }); it('can extend the patterns', function() { var x = gulpLoadPlugins({ lazy: lazy, config: { dependencies: { 'jack-foo': '1.0.0', 'gulp-bar': '*' } }, overridePattern: false, pattern: 'jack-*' }); assert.deepEqual(x.jackFoo(), { name: 'jack-foo' }); assert(x.bar); }); it('allows camelizing to be turned off', function() { var x = gulpLoadPlugins({ lazy: lazy, camelize: false, config: { dependencies: { 'gulp-foo-bar': '*' } } }); assert.deepEqual(x['foo-bar'](), { name: 'foo-bar' }); }); it('camelizes plugins name by default', function() { var x = gulpLoadPlugins({ lazy: lazy, config: { dependencies: { 'gulp-foo-bar': '*' } } }); assert.deepEqual(x.fooBar(), { name: 'foo-bar' }); }); it('lets something be completely renamed', function() { var x = gulpLoadPlugins({ lazy: lazy, config: { dependencies: { 'gulp-foo': '1.0.0' } }, rename: { 'gulp-foo': 'bar' } }); assert.deepEqual(x.bar(), { name: 'foo' }); }); it('outputs debug statements', function() { var restore = capture(process.stdout); try { var x = gulpLoadPlugins({ lazy: lazy, DEBUG: true, config: { dependencies: { 'gulp-foo': '*' } } }); assert.deepEqual(x.foo(), { name: 'foo' }); } catch (err) { restore(); throw err; } var output = restore('true'); assert(output.indexOf('gulp-load-plugins') !== -1, 'Expected output to be logged to stdout'); }); it('supports loading scopped package as a nested reference', function() { var x = gulpLoadPlugins({ lazy: lazy, config: { dependencies: { '@myco/gulp-test-plugin': '1.0.0' } } }); assert.deepEqual(x.myco.testPlugin(), { name: 'test' }); }); it('supports loading scopped package as a top-level reference', function() { var x = gulpLoadPlugins({ lazy: lazy, maintainScope: false, config: { dependencies: { '@myco/gulp-test-plugin': '1.0.0' } } }); assert.deepEqual(x.testPlugin(), { name: 'test' }); }); it('supports custom rename functions', function () { var x = gulpLoadPlugins({ renameFn: function () { return 'baz'; }, config: { dependencies: { 'gulp-foo-bar': '*' } } }); assert.throws(function () { x.fooBar(); }); assert.deepEqual(x.baz(), { name: 'foo-bar' }); }); it('supports transforming', function() { var x = gulpLoadPlugins({ lazy: lazy, config: { dependencies: { 'gulp-foo': '1.0.0' } }, postRequireTransforms: { foo: function(foo) { foo.bar = 'test string'; return foo; } } }); assert.strictEqual(x.foo.bar, 'test string'); }); }; describe('no lazy loading', function() { commonTests(false); var spy; before(function() { spy = sinon.spy(); gulpLoadPlugins({ lazy: false, config: { dependencies: { 'gulp-insert': '*' } }, requireFn: function() { spy(); return function() {}; } }); }); it('does require at first', function() { assert(spy.called); }); }); describe('with lazy loading', function() { commonTests(true); var x, spy; before(function() { spy = sinon.spy(); x = gulpLoadPlugins({ lazy: true, config: { dependencies: { 'gulp-insert': '*' } }, requireFn: function() { spy(); return function() {}; } }); }); it('does not require at first', function() { assert(!spy.called); }); it('does when the property is accessed', function() { x.insert(); assert(spy.called); }); }); describe('common functionality', function () { it('throws a sensible error when not found', function () { var x = gulpLoadPlugins({ config: path.join(__dirname, '/package.json') }); assert.throws(function () { x.oops(); }, /Cannot find module 'gulp-oops'/); }); it('allows you to use in a lower directory', function() { var plugins = require('../')(); assert.ok(typeof plugins.test === 'function'); }); }); gulp-load-plugins-1.5.0/test/node_modules/000077500000000000000000000000001304505253000205115ustar00rootroot00000000000000gulp-load-plugins-1.5.0/test/node_modules/gulp-test/000077500000000000000000000000001304505253000224355ustar00rootroot00000000000000gulp-load-plugins-1.5.0/test/node_modules/gulp-test/index.js000066400000000000000000000000411304505253000240750ustar00rootroot00000000000000module.exports = function () {}; gulp-load-plugins-1.5.0/test/package.json000066400000000000000000000001441304505253000203210ustar00rootroot00000000000000{ "dependencies": { "gulp-test": "*", "gulp-test-global": "*", "gulp-oops": "*" } }