JustBlackBird / gulp-phpcs

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

Error Cannot find "vendor/bin/phpcs" on Windows #21

Closed JustBlackBird closed 8 years ago

JustBlackBird commented 8 years ago

Each of these bin option values

end with Error: Cannot find error on Windows.


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

It seems that 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.

tyler36 commented 8 years ago

This is the same issue I was having with 'PHPcs encoding issue #10'

For some reason, the error was outputting with incorrect coding, and therefore unreadable. I was assuming it was an encoding error with this plugin. Since PHPCS worked fine from CLI in windows and CLI / gulp via Homestead.

JustBlackBird commented 8 years ago

Well, the problem described in the issue is not only in slash styles. It's most about resolving command path without running subshell (subshell is spawned by node.js child_process.exec but not with child_process.spawn).

Frankly, i don't see a way to fix the problem right now.

cedon commented 8 years ago

I'm having this issue as well. My installation of phpcs is on my C: while my development stuff is on D:. My php directory is the path so setting bin: 'phpcs.bat' worked for me to fix it. It's something on Microsoft's end which will hopefully be fixed with Windows 10 getting BASH soon.

JustBlackBird commented 8 years ago

I'm not sure what your problem exactly is but setting full path as bin option should help.

cedon commented 8 years ago

It's the same issue of phpcs.bat not being resolved as phpcs when gulp. In a normal command prompt, it works fine with phpcs {filename}, but with gulp I get "Cannot find phpcs".

JustBlackBird commented 8 years ago

At the moment i'm waiting for https://github.com/npm/node-which/issues/29 and https://github.com/npm/node-which/issues/26 to be resolved to rewrite gulp-phpcs bin finder logic.

JustBlackBird commented 8 years ago

Fixed in v1.1.0