JustBlackBird / gulp-phpcs

Gulp plugin for running PHP Code Sniffer
MIT License
47 stars 12 forks source link

Bin Folder Path Issue #3

Closed pokoot closed 8 years ago

pokoot commented 9 years ago

Im trying to install phpcs using composer. So i call phpcs by ./vendor/bin/phpcs on my root folder and works perfectly fine.

When using gulp-phpcs I get an error Error: Command failed: The system cannot find the path specified.

pipe(phpcs({
            bin: 'vendor/bin/phpcs',
            standard: 'PSR2',
            warningSeverity: 0
        }))

The reason I call via composer because phpcs is installed on different environments like windows and unix servers and etc.

Anything i can do to make this work? Or how should I call the right path? or am i just missing something.

JustBlackBird commented 9 years ago

Where do the gulp file lives? Could you provide a draft of directories structure of your project?

As for composer, I've used it with gulp-phpcs in one of my projects and it works fine. Here is the gulp file: https://github.com/Mibew/mibew/blob/master/src/gulpfile.js#L59

pokoot commented 9 years ago

phpcs lives in my project relative path which is ./vendor/bin/phpcs. Take note of the ./

JustBlackBird commented 9 years ago

if you have the following directories structure:

project_root\
    gulpfile.js
    ...
    vendor\
        bin\
        phpcs\

and you run gulp from the project_root it should works fine. Check the gulp file I've provide you in the last comment.

May be you do something with cwd in the gulp file or run the gulp from another place?

JustBlackBird commented 9 years ago

@pokoot Do you still have the problems with you gulp file?

JustBlackBird commented 9 years ago

The problem is not reproducible and seems to be invalid.

PhantomWatson commented 8 years ago

I also have this problem.

Directory structure:

gulpfile.js
...
\vendor
    \bin
        phpcs

Gulp code:

gulp.task('php_cs', function() {
    return gulp.src(['src/**/*.php'])
        // Validate files using PHP Code Sniffer
        .pipe(phpcs({
            bin: 'vendor/bin/phpcs',
            standard: 'PSR2',
            warningSeverity: 0
        }))
        // Log all problems that was found
        .pipe(phpcs.reporter('log'));
});

Results:

[13:37:16] Using gulpfile C:\xampp\htdocs\website\gulpfile.js
[13:37:16] Starting 'php_cs'...

events.js:141
      throw er; // Unhandled 'error' event
      ^
Error: Cannot find "vendor/bin/phpcs"
    at ChildProcess.<anonymous> (C:\xampp\htdocs\website\node_modules\gulp-phpcs\index.js:81:32)
    at emitOne (events.js:77:13)
    at ChildProcess.emit (events.js:169:7)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:198:12)
    at onErrorNT (internal/child_process.js:344:16)
    at doNTCallback2 (node.js:429:9)
    at process._tickDomainCallback (node.js:384:17)

Using gulp-phpcs 1.0.0

JustBlackBird commented 8 years ago

Did you try to use ./vendor/bin/phpcs as phpcs bin? Also, as I see you use windows. So, did not you try to use .\\vendor\\bin\\phpcs as bin option?

PhantomWatson commented 8 years ago

Code:

bin: './vendor/bin/phpcs',

Result:

Error: Cannot find "./vendor/bin/phpcs"

Code:

bin: '.\\vendor\\bin\\phpcs',

Result:

Error: Cannot find ".\vendor\bin\phpcs"

It worked fine before updating from version 0.7 to 1.0.

JustBlackBird commented 8 years ago

Yep, I finally found it!

The problem is in files extensions. As I see, composer creates vendor\bin\phpcs.bat on windows instead of just vendor\bin\phpcs. Normally windows cmd resolves command.bat to command. At the same time, node.js child_process.spawn does not use shell to spawn PHPCS process, so no resolving is done.

As a temporary workaround you can specify .\\vendor\\bin\\phpcs.bat as bin option. Does it work for you, @PhantomWatson?

JustBlackBird commented 8 years ago

Moved to #21 because it's not related with the original @pokoot issue.

PhantomWatson commented 8 years ago

Aha! .\\vendor\\bin\\phpcs.bat works for me!

Thanks for getting back to me, and thanks for your work on this project!

JustBlackBird commented 8 years ago

You're welcome, I glad that the workaround works for you.

Actually, I need some time to figure out how to fix real problem without any workarounds. You can watch the progress in #21 (I've moved your problem there).