ts-loader icon indicating copy to clipboard operation
ts-loader copied to clipboard

Using InputFileSystem from Webpack

Open LukeSheard opened this issue 8 years ago • 10 comments

In instances.ts the loader reads the file from the fs.readFileSync (https://github.com/TypeStrong/ts-loader/blob/fbd64be5bdb010e79ef0f702896c5d470f6fc619/src/instances.ts#L114). Should this not be using this.fs from the web pack InputFileSystem.

I noticed this when trying to bundle code using a virtual filesystem replacing the InputFileSystem with one that uses an in memory fs, thus files cannot be found.

LukeSheard avatar Oct 06 '17 10:10 LukeSheard

Tbh I'm not sure - I think that was implemented by @jbrantly and he may be able to advise as to why. If you wanted to submit a PR that changed that we'd definitely consider it. Feel free to open one and we can see where it leads (don't initially worry about the tests - they can be fiddly)

johnnyreilly avatar Oct 06 '17 11:10 johnnyreilly

Sorry only just had a chance to get back to this, I think it might be a bigger issue where we actually have to create a new compilerHost instance and override the typescript fs methods that are used there? I can have a go at the simple PR case where we just replace any fs import with using the webpack inputFileSystem though.

LukeSheard avatar Dec 30 '17 16:12 LukeSheard

Give it a shot - let's see how it pans out!

johnnyreilly avatar Dec 30 '17 18:12 johnnyreilly

So actually looking at it, you've done most of the work in servicesHost.ts, so it should be the case of just overriding those files. I'll see if I can create a demo and a PR and then look at tests!

LukeSheard avatar Dec 30 '17 19:12 LukeSheard

Sweet!

johnnyreilly avatar Dec 30 '17 19:12 johnnyreilly

So I made some good progress yesterday and today and put together some simple demos using my fork of ts-loader. https://github.com/LukeSheard/ts-loader-memory-fs/tree/master

As far as I can tell at this point the issue is just the diagnostics which use the compiler.sys, so do all the file reads. I think just replacing those with loader.fs should work... If you've got any better observations that would be super useful though. I've been having some issues with diagnostic issues when trying to change them over.

LukeSheard avatar Dec 31 '17 13:12 LukeSheard

As far as I can tell at this point the issue is just the diagnostics which use the compiler.sys, so do all the file reads. I think just replacing those with loader.fs should work...

Could you elaborate what you mean by this please? An example of the issue you are facing would be helpful.

johnnyreilly avatar Dec 31 '17 13:12 johnnyreilly

Btw I'm away from computers right now so feel free to guide me by the hand. Good as the github UI is it's not conducive to grokking code!

johnnyreilly avatar Dec 31 '17 14:12 johnnyreilly

This took a long time, but I'm finally starting work (in open source) land to try and add real support for this (now that we have systems at work relying on a different approach)

LukeSheard avatar Oct 31 '18 01:10 LukeSheard

Any thing new for this issue? I've met the same problem. My loader do some proeprocess for ts files before ts-loader handle files, however the getScriptSnapshot for makeServicesHost just use fs.readFileSync (utils.js) which skip the preprocessed result and got some diagnostics error.

WJsjtu avatar Aug 21 '20 08:08 WJsjtu