TypeStrong / ts-loader

TypeScript loader for webpack
https://johnnyreilly.com/ts-loader-goes-webpack-5
MIT License
3.45k stars 429 forks source link

Using InputFileSystem from Webpack #649

Closed LukeSheard closed 1 year ago

LukeSheard commented 7 years ago

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.

johnnyreilly commented 7 years ago

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)

LukeSheard commented 6 years ago

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.

johnnyreilly commented 6 years ago

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

LukeSheard commented 6 years ago

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!

johnnyreilly commented 6 years ago

Sweet!

LukeSheard commented 6 years ago

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.

johnnyreilly commented 6 years ago

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 commented 6 years ago

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!

LukeSheard commented 5 years ago

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)

WJsjtu commented 4 years ago

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.