rushstack icon indicating copy to clipboard operation
rushstack copied to clipboard

rush: build fails to use local npm scripts binaries

Open Schibum opened this issue 9 years ago • 8 comments

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 )

Schibum avatar Apr 13 '17 08:04 Schibum

Does it work for you if you install it globally?

qz2017 avatar Apr 13 '17 17:04 qz2017

I think we can expand it to any locally installed packages.

qz2017 avatar Apr 13 '17 17:04 qz2017

@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.)

octogonz avatar Apr 14 '17 06:04 octogonz

@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)

Schibum avatar Apr 14 '17 14:04 Schibum

Can you try installing rimraf globally (i.e. - npm install rimraf -g) and see if rush rebuild works?

iclanton avatar Apr 14 '17 20:04 iclanton

When I try:

"scripts": {
    "clean": "'rimraf lib'"
},

It works; but it breaks the normal npm run command.

voodooattack avatar Jun 12 '17 17:06 voodooattack

@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'].)

octogonz avatar Jun 12 '17 19:06 octogonz

This was probably fixed a long time. It is definitely working as of PR https://github.com/Microsoft/web-build-tools/pull/601

octogonz avatar Apr 17 '18 01:04 octogonz