0

I'm trying to run a script from node, and I'm seeing different behaviour compared to if I run it from the terminal and I don't understand why.

I'm trying to do something a little bit out there, in that to save people typing pnpm {scriptName} --filter {packageName} I created a little script that they could run instead. It basically takes scriptName and lists all the available packages they can select from, and then trigger spawns a new process calling that command. Something like:

spawn("pnpm", ["--filter " + packageName, scriptName], { stdio: "inherit" });

Example:

enter image description here

In my particular case, I'm trying to test a script that ends up generating a pnpm --filter @ig/main test:debug.

I'm struggling a little though, in that if I invoke that via a terminal it works fine (test:debug is defined both in .\package.json and .\apps\main\package.json). However if I invoke it via the spawn command in node, then for some reason it invoking the test:debug script in the root, rather than just in apps/main. Does anyone know what that might be the case?

Ian
  • 33,605
  • 26
  • 118
  • 198

1 Answers1

0

Turns out this was down to the current working directory not being set correctly when using spawn.

Ian
  • 33,605
  • 26
  • 118
  • 198