You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Calling addSourceFileAtPathIfExists has a side effect of internally remembering directories that don't exist which causes subsequent operations to fail
#1554
Open
kronodeus opened this issue
Jul 8, 2024
· 0 comments
If you call addSourceFileAtPathIfExists with a path where some of the directories in that path do not exist, trying to add those directories later via addDirectoryAtPath or addDirectoryAtPathIfExists will fail with an error.
How to reproduce
This only occurs if you have { recursive: true } so it has something to do with the recursive logic.
import{Project}from"ts-morph";constproject=newProject();project.addDirectoryAtPathIfExists('/some/path/that/doesnt/exist',{recursive: true})project.addSourceFileAtPathIfExists('/some/path/that/doesnt/exist/file.ts')// This call will throw an error: "Directory not found: /some/path/that/doesnt/exist"project.addDirectoryAtPathIfExists('/some/path/that/doesnt/exist',{recursive: true})
Expected behavior
Adding a source file or directory using the *IfExists functions should be "safe" operations. They should not have side effects that create error states. It should be possible to attempt to add a directory or source file that doesn't exist, and then attempt again later without errors being thrown.
The text was updated successfully, but these errors were encountered:
Description
Version: 23.0.0
If you call
addSourceFileAtPathIfExists
with a path where some of the directories in that path do not exist, trying to add those directories later viaaddDirectoryAtPath
oraddDirectoryAtPathIfExists
will fail with an error.How to reproduce
This only occurs if you have
{ recursive: true }
so it has something to do with the recursive logic.Expected behavior
Adding a source file or directory using the
*IfExists
functions should be "safe" operations. They should not have side effects that create error states. It should be possible to attempt to add a directory or source file that doesn't exist, and then attempt again later without errors being thrown.The text was updated successfully, but these errors were encountered: