jackfranklin/gulp-load-plugins

gulp-load-plugins only loads one plugin

Closed this issue · 15 comments

I initially posted this as a comment to #70 but considering that the proposed solution didn't work and more importantly the problem I'm having is not identical, I'm opening a new issue.

This plugin is only loading one of the many plugins I have.

Here's my simplified gulpfile.js:

var gulp = require('gulp');
var plugins = require('gulp-load-plugins')({
    lazy: false
});

In one of my default tasks, I'm logging JSON.stringify(plugins), which gives me:

{
  "util": {
      "colors": {
          "enabled": true,
          "styles": {
              "reset": {
                  "open": "\u001b[0m",
                  "close": "\u001b[0m",
                  "closeRe": {}
              },
...

util is the only thing there.

util seems to refer to gulp-util. The plugin seems to default to removing the gulp prefix even if I'm not using the parameter replaceString (is this a bug?). If I add the parameter with an incorrect value like so replaceString: '/^gulp(-|\.)/' util becomes gulpUtil. I find this a little strange since the plugin is named 'gulp-util' and I'm not camelizing it.

I examined an strace of the call, but can't catch the culprit. Here's a brief version of the salient bits.
The first plugin, gulp-uglify, does not load. The second, gulp-util, does.

stat("/a/path/app/node_modules/gulp-uglify", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0
stat("/a/path/app/node_modules/gulp-uglify.js", 0x7ffc64e32c90) = -1 ENOENT (No such file or directory)
stat("/a/path/app/node_modules/gulp-uglify/package.json", {st_mode=S_IFREG|0664, st_size=2114, ...}) = 0
open("/a/path/app/node_modules/gulp-uglify/package.json", O_RDONLY) = 9
ioctl(9, FIOCLEX)                       = 0
fstat(9, {st_mode=S_IFREG|0664, st_size=2114, ...}) = 0
read(9, "{\n  \"name\": \"gulp-uglify\",\n  \"de"..., 2114) = 2114
close(9)                                = 0
stat("/a/path/app/node_modules/gulp-uglify/index.js", {st_mode=S_IFREG|0664, st_size=158, ...}) = 0
stat("/a/path/app/node_modules/gulp-uglify/index.js", {st_mode=S_IFREG|0664, st_size=158, ...}) = 0
stat("/a/path/app/node_modules/gulp-util", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0
stat("/a/path/app/node_modules/gulp-util.js", 0x7ffc64e32c90) = -1 ENOENT (No such file or directory)
stat("/a/path/app/node_modules/gulp-util/package.json", {st_mode=S_IFREG|0664, st_size=2297, ...}) = 0
open("/a/path/app/node_modules/gulp-util/package.json", O_RDONLY) = 9
ioctl(9, FIOCLEX)                       = 0
fstat(9, {st_mode=S_IFREG|0664, st_size=2297, ...}) = 0
read(9, "{\n  \"name\": \"gulp-util\",\n  \"desc"..., 2297) = 2297
close(9)                                = 0
stat("/a/path/app/node_modules/gulp-util/index", 0x7ffc64e32c30) = -1 ENOENT (No such file or directory)
stat("/a/path/app/node_modules/gulp-util/index.js", {st_mode=S_IFREG|0664, st_size=553, ...}) = 0
stat("/a/path/app/node_modules/gulp-util/index.js", {st_mode=S_IFREG|0664, st_size=553, ...}) = 0
write(1, "{\n    \"util\": {\n        \"colors\""..., 4537{

So it does read from the appropriate plugins (read(9, "{\n \"name\": \"gulp-uglify\",\n \"de"..., 2114)), but only writes util.

Part of my package.json:

...
"devDependencies": {
    "gulp": "^3.9.0",
    "gulp-load-plugins": "^1.0.0-rc.1",
    "gulp-uglify": "^1.2.0",
    "gulp-util": "^3.0.6"
}
...

My guess is that this issue has something to do my environment.

If there is a need for it, I can attach the entire output of the strace call.

Would you be to set up a repo that we can replicate this in?

Here is the repo.

Replicated

So you replicated the problem? That's strange.
Considering that such a simple example was failing, I was expecting the issue to be associated with my environment.

Is gulp-util required for the plugin to work? I tried uninstalling it to see if I would get an empty object, but it says Cannot find module 'gulp-util'. It's not in my package.json nor am I referencing it anywhere in my gulpfile.

Edit:

After running an strace it looks like gulp-util is globally installed, so perhaps that's why it wants to use it. Though I'm not sure why just the fact that it's globally installed means it needs to reference it. Something strange is going on, and I don't understand it.

It looks like gulp-util is installed here: {prefix}/node_modules/gulp-util
However, my logs are trying to access this path: {prefix}/bin/node_modules/gulp-util

Where {prefix} is /usr/local/lib/node_modules/gulp/.

Is this maybe not an issue with your plugin then?

@callumacrae did you get anywhere with this? Let me know if I can be of use.

Replicated on Windows 8.1. Same issue.

Sorry, should have been clearer: not really capable of typing right now except with one hand (broke my collarbone), so won't be able to fix this right now.

@callumacrae ouch! No worries; @pushkin- I'll try to take a look if I get some spare time.

@pushkin- sorry I haven't got round to this issue, I'll try to take a look.

In the mean time, if you upgrade to gulp-load-plugins v1.1 and set DEBUG: true, does any of the output help us debug at all?

I had originally thought I reproduced this; but it appears I cannot read or type.

If anyone else is having this problem, make sure you correctly spell the name of the resulting plugins (ie; gulp-typescript becomes plugins.typescript)

@pushkin- I just downloaded your test repo, then made sure I was running the latest version:

npm install gulp-load-plugins@1.1.0 --save

I then turned DEBUG: true on and also updated the console log so it just logged the keys:

'use strict';

var gulp = require('gulp');
var path = require('path');

var $ = require('gulp-load-plugins')({
    //scope: ['devDependencies'],
    //config: path.join(__dirname, 'package.json'),
  DEBUG: true,
  lazy: false
});

gulp.task('test', function() {
    console.log(JSON.stringify(Object.keys($), null, 4));
});

gulp.task('default', ['test']);

Running gulp gives me:

[10:27:06] gulp-load-plugins: Debug enabled with options: {"DEBUG":true,"lazy":false}
[10:27:06] gulp-load-plugins: 8 plugin(s) found: gulp-load-plugins jquery path underscore gulp gulp-load-plugins gulp-rename gulp-util
[10:27:06] gulp-load-plugins: renaming gulp-rename to rename
[10:27:06] gulp-load-plugins: requiring gulp-rename...
[10:27:06] gulp-load-plugins: renaming gulp-util to util
[10:27:06] gulp-load-plugins: requiring gulp-util...
[10:27:06] Using gulpfile ~/git/gulp-load-plugin-issue/gulpfile.js
[10:27:06] Starting 'test'...
[
    "rename",
    "util"
]
[10:27:06] Finished 'test' after 362 μs
[10:27:06] Starting 'default'...
[10:27:06] Finished 'default' after 5.78 μs

As you can see, it finds the two plugins as I would expect. Could you try running it at your end and see if it now works?

util seems to refer to gulp-util. The plugin seems to default to removing the gulp prefix even if I'm not using the parameter replaceString (is this a bug?). If I add the parameter with an incorrect value like so replaceString: '/^gulp(-|.)/' util becomes gulpUtil. I find this a little strange since the plugin is named 'gulp-util' and I'm not camelizing it.

If this is still happening for you on the latest version, could you open a new issue so it's easier to track separately to this one? Thanks :)

@jackfranklin Huh. Using your gulpfile (printing Object.keys($) vs the whole object), I get the same output you got. And after successfully using the loaded plugin, I can verify that it does indeed work.

Printing the whole object, the only key I see is util for some reason (like in my original post). But printing just the keys gets me both util and rename.

If I remember correctly, I couldn't even use the plugins I loaded, but now it seems I can. Not sure what the issue was before.

(Note, I am using a different environment to test (Windows 10))

@pushkin- perfect, so it's all working! Weird regarding it printing or not :/ If both the plugins work as normal though that's good. I'm going to close but please comment / start a new issue if anything else goes awry. I haven't tested on Windows so there may well be more bugs.