rush: build fails to use local npm scripts binaries
So a package.json with local scripts like this:
"scripts": {
"clean": "rimraf lib"
},
"dependencies": {
"rimraf": "^2.0.0",
...
Fails to build with rush rebuild
It only seems to look for a local "gulp" binary right now ( https://github.com/Microsoft/web-build-tools/blob/master/rush/rush/src/taskRunner/ProjectBuildTask.ts#L239 )
Does it work for you if you install it globally?
I think we can expand it to any locally installed packages.
@Schibum is your project open source? If you could share a branch, I'd be willing to help you get it building with Rush. That might be more efficient than reporting/fixing a series of bugs. (We generally assume that projects build using gulp, so your scenario is not very well tested -- although certainly intended to work.)
@pgonzal it's not open source, I just tried rush on some internal projects, that use locally installed npm binaries (like Babel-cli or typescript) to build in a simple npm run build script.
Would be nice to be able to run arbitrary commands in each package (like lerna run in https://lernajs.io)
Can you try installing rimraf globally (i.e. - npm install rimraf -g) and see if rush rebuild works?
When I try:
"scripts": {
"clean": "'rimraf lib'"
},
It works; but it breaks the normal npm run command.
@nickpape-msft @qz2017 I was able to repro this issue using a script like this:
{
"name": "project1",
"version": "1.0.0",
"scripts": {
"clean": "rimraf lib",
"test": "gulp"
},
"dependencies": {
"rimraf": "^2.6.1"
}
}
(Note that rimraf needs to appear in the package.json file, so that Rush will find it in "./common/temp/node_modules/.bin".)
Surprisingly, the "lib" folder is deleted correctly, however Rush still fails with this error message:
rimraf lib returned error code: 1
That is coming from this code in ProjectBuildTask.ts:
buildTask.on('close', (code: number) => {
// Detect & display errors
const errors: TaskError[] = this._errorDetector.execute(
writer.getStdOutput() + os.EOL + writer.getStdError());
for (let i: number = 0; i < errors.length; i++) {
writer.writeError(errors[i].toString(this._errorDisplayMode) + os.EOL);
}
// Display a summary of why the task failed or succeeded
if (errors.length) {
writer.writeError(`${errors.length} Error${errors.length > 1 ? 's' : ''}!` + os.EOL);
} else if (code) {
writer.writeError(`${cleanCommand} returned error code: ${code}${os.EOL}`);
}
When I manually run "rimraf lib" or "cmd /d /s /c ..\common\temp\node_modules\.bin\rimraf lib" from the command line, the exit code is 0 (not 1).
Seems like either the above code is reading the exit code incorrectly, or else something weird is happening when we pack the parameters into strings. (It is a little odd that the array of arguments ends up like ['/d /s /c', 'rimraf lib'] -- I would have expected something more like ['/d', '/s', '/c', 'rimraf', 'lib'].)
This was probably fixed a long time. It is definitely working as of PR https://github.com/Microsoft/web-build-tools/pull/601