Wednesday, 3 June 2020

__dirname points back to the class definition, and not the calling file?

In ./src/classes/wizard/wizardSetup.ts I have class defined to write a file two levels up. That is because the file where the class is instantiated is one level down, in classes. And my target folder is the project root. fs.writeFileSync(path.join(__dirname, "../../configuration.json"), ""); After the compile step I found the new file in the ./compiled folder. I then changed it to go three levels up: fs.writeFileSync(path.join(__dirname, "../../../configuration.json"), ""); This worked as expected; configuration.json was placed in the project root.Does this mean the path is determined from the class definition, and not the file where it is instantiated? I did not expect that behavior.

Submitted June 04, 2020 at 04:14AM by fpuen

No comments:

Post a Comment