3

We've just upgraded to the NPM version of JSHint in Windows, and our CI won't fail on JSHint failures anymore. This feels like a silly problem, but I can't figure it out.

We're running NAnt and CCNet. When we try to run jshint.cmd from within NAnt, it fails saying that the path is wrong. I can't hard code the path in the script because each dev station (and CI server) has NPM and JSHint installed in a different location ("C:\Users\me\AppData\Roaming\npm").

So we've written a batch file which NAnt calls, which calls jshint.cmd. It now runs JSHint, but won't give error codes or fail properly. It looks like the end of our batch file is not run after the jshint.cmd fails, and it looks like there is no errorlevel set for NAnt to check against. I've tried checking resultproperty in NAnt as well with no luck.

Here's a few files:

JSHint.build

<target name="JSHint">
    <exec program="runjshint.cmd" basedir="${jshint.dir}" workingdir="${jshint.dir}">
        <arg value="${scripts.dir}" />
    </exec>
</target>

runjshint.cmd

    jshint --reporter=reporter.js %1
    REM Everything past here isn't run.

NAnt output

             [exec] C:\work\ThirdParty\jshint>jshint --reporter=reporter.js ..\..\src\Scripts
             [exec]
             [exec]
             [exec] jshint failed:
             [exec]
             [exec] ..\..\src\Scripts\app\ViewModels\FakeViewModel.js: line 62, col 31, 'FakeVariable' is not defined.
             [exec] ..\..\src\Scripts\app\ViewModels\FakeViewModel.js: line 78, col 33, 'FakeVariable' is not defined.
             [exec]
             [exec] 2 errors

        BUILD SUCCEEDED

Note that the build succeeded even though JSHint failed.

4

1 回答 1

1

我在另一篇关于 SO 的帖子中找到了答案:https ://stackoverflow.com/a/10359327/227349

<!--Next arg: forces node's stderror and stdout to a temporary file-->
<arg line=" &gt; _tempfile.out 2&lt;&amp;1"/>

<!--Next arg: If command exits with an error, then output the temporary file to stdout, -->
<!--delete the temporary file and finally exit with error level 1 so that    -->
<!--the apply task can catch the error if @failonerror="true"                -->
<arg line=" || (type _tempfile.out &amp; del _tempfile.out &amp; exit /b 1)"/>

<!--Next arg: Otherwise, just type the temporary file and delete it-->
<arg line=" &amp; type _tempfile.out &amp; del _tempfile.out &amp;"/>
于 2013-10-29T16:14:40.463 回答