0

I have a line in my package.json

"deploy": "yarn build && cd ../../..

build script that should change directory (cd ../../..) after running the first command (yarn build). However, this doesn't seem to trigger changing directory to the root of the project. I have also tried using a separate node task to do so using process.chdir('../../..'); or process.cwd('../../..');, but these don't work either.

I've also tried using a separate node.js file (changedirectory.js) with the following to change directory in my build command "deploy": "yarn build && node changedirectory.js && cf login:

try {
    process.chdir('../../../');
    console.log(`New directory: ${process.cwd()}`);
} catch (err) {
    console.error(`chdir: ${err}`);
}

This does show the correct new directory in terminal, but doesn't actually change the working directory.

Is there something I'm missing or can this not be done with node?

user3438917
  • 417
  • 1
  • 7
  • 26
  • Windows or Linux? Also, npm runs scripts in a sub shell, so the directory change will have no effect on your current shell session. – rveerd Jun 09 '20 at 14:52
  • OSX. So there's no way to do this through a node script? – user3438917 Jun 09 '20 at 15:24
  • Oh yeah, there is also OSX :). You can change the directory _within_ the script but this will not have any effect _outside_ the script. – rveerd Jun 10 '20 at 07:14

0 Answers0