2

I've recently been working on a on-demand build server. The build server is a NodeJS/Express REST API, which essentially wraps the Angular CLI and associated build tooling for completing a custom on-demand Angular application.

Everything is working as expected end to end, but I'd like to be able to get more granular with the status reporting, as Angular builds can be quite time consuming when factoring in 2 very large parts of the process

The two longest running parts of the process:

  1. the npm install (generally automatically kicked off via the ng-new schematic from the default @angular/schematics collection)
  2. the actual ng build command.

2 is easy to address, as I am spawning that process (ng build --prod) via child_process.spawn() directly.

1 has proven a bit more complicated, as the long running npm install process is actually kicked off internally to the default Angular ng-new schematic/command. So, if my thinking is correct, this is essentially a explicitly spawned child process (my spawned ng new) which is internally spawning npm install.

One work around that I've come up with is to pass in the --skip-install arg to ng new, which will prevent the internal npm install process from being kicked off by the Schematic. By doing this, I can then manually kick off npm install via child_process.spawn() and directly observe the stdout and stderr streams.

I'm curious if anyone knows of a way to spy on the stderr and stdout streams from the 'npm install' that's kicked off inside of my explicitly spawned ng new command?

Thanks!

mihai
  • 37,072
  • 9
  • 60
  • 86
mattezell
  • 607
  • 1
  • 6
  • 13

1 Answers1

0

If you're running on Linux you can use strace to spy on the ouput of another process.

strace -p7835 -e trace= -e write=3

See this answer for more details.

You can invoke strace from node of course, using spawn. To find the pid of the npm process (which is actually a node process btw), you would need to get the process tree using the ps command. There is already a node module that does this: ps-tree, which also appears to be cross platform.

For alternatives of strace on Windows, check this discussion. I would go for Process Monitor from Sysinternals.

mihai
  • 37,072
  • 9
  • 60
  • 86