Hello,
I would like to use your module for a browser-based visual programing project. But I cannot use it because of "fs". Even if I use a custom file system wrapper my browser complains that "fs" is not available.
I investigate a bit and it's because you import "DefaultFileSystemHost" even in the case of custom FileSystem (with barrels for example).
Do you have any workaround for browsers ?
I'm on the same situation - wanted to test ts-simple-ast here : https://cancerberosgx.github.io/typescript-in-the-browser/typescript-compiler/ (just loading typescript.ts and implementing very basic LShost and CompilerHost) and also here https://cancerberosgx.github.io/typescript-in-the-browser/candombed/ (which uses monaco-editor typescript language service implementation but with no luck.
In the first one, I'm already able to run most of API and even other libraries around it (like tsquery) but no luck with ts-simple-ast
In my case, I'm using browserify which can emulate 'fs' and most of the other standard ones, but the problem was with "fs-extra"- I would like to have some tips or if it's possible to isolate the "logic" of the library from the language service host and compiler host concrete implementations.
Also I wonder if the library could help me to implement (or already has) hosts that support the browser, ike the virtual filesystem one.
To be sincere I didn't investigate too much that's why I didn't wanted to ask yet, but since we are here, any idea is most welcome, thanks!
@GrandSchtroumpf thanks for reporting this. I wasn't aware it wasn't working and should be fixed in 12.5.0. Just make sure to specify to use a virtual file system when creating the project:
const project = new Project({ useVirtualFileSystem: true });
// and in case you need the file system...
const fileSystem = project.getFileSystem();
@cancerberoSgx you can create your own FileSystemHost by implementing FileSystemHost on a class and then passing it into the constructor of new Project({ /* options*/ }, specifyAnInstanceOfYourClassHere);
Wow! I miss this somehow. Testing it I see that globby and probably others have the same problem. I'm trying to fix it and PR you. Also demoing and adding a couple of comments in the docs. Give me a couple of days. Thanks!
See it working in the browser here: https://cancerberosgx.github.io/typescript-in-the-browser/typescript-compiler/#example=tsSimpleAst1