New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move to language service compiler api #362
Conversation
other note:
It looks like ts compiler trying to write js (and not ts, what is interesting) files to fs. UPD: |
I think that the cache (which would be created at compile time) will not be available when
The compiler transpiles the ts-jest files to js and puts them in the dist directory. This should only happen when installing ts-jest - not when running tests.
I think there's an issue which required outDir to be removed. |
looking at typescript source code, it's not emitting js code to fs. It just makes checks for filenames on program creation. Which is not valid for custom writer, which in our case is pushing to array (https://github.com/Microsoft/TypeScript/blob/8fc651870e44efd12598a42ae84fb0e19067fcfd/src/compiler/builder.ts#L19-L26) So in this case we can just override |
I think you might be conflating two issues here. The javascript files in the dist directory (within the ts-jest package) are created when ts-jest is installed. These files should not affect the actual tests (which the project using ts-jest would be running). Either this, or I'm likely missing something. |
Look like some missunderstanding here. So in this pr
So when I'm creating languageService for future emitting - it checks if it can write js files to fs. This all is relevant for tests transpiling step, not building ts-jest itself. |
that clears things a bit. Thanks.
So if I understand this right, the issue is that the new API that this PR uses to transpile is trying to generate js files.
Doesn't setting
If we're going to use a new API, we should avoid using workarounds - at least for the core parts. |
it doesn't trying. It emitting file to string. Typescript thinks that it will emit js files to fs, so it runs some general checks, one of them is irrelevant in out case.
with noEmit with running getEmitOutput we will have empty data. |
I see. I now understand the issue. This does sound like a bug in ts.
Right, of course. |
so still problems are
|
This seems like it would entail some serious restructuring. While any improvement would be welcome, you might want to consider if it's worth your time. It seems that Babel 7 will have typescript support and depending on how that is done, ts-jest itself might not be required in future (See #358) That said, any improvement is welcome here! |
In my case |
@goloveychuk is this still an active issue? |
#281 is still an active Issue which is a valid use case. I think we should fix this problem in some way like this PR. |
@incleaf I asked because this PR has been inactive for 2+ months. |
so I'm using it in my project - works ok, but have a big problem. With using
|
@goloveychuk yeah, it's a tricky issue. Anyway, I was just checking. I don't mind leaving this PR open if it is still of interest to you :) |
So maybe leave it open, mb someone find it useful and help with concurrency problem. Or maybe I'll fix it when have free time. Or close it, and reopen when needed. Your choice) |
@goloveychuk As long as you're interested in this, it can be left open. I don't mean it has to be active with updates. Just that you are the owner of this PR and its status is completely up to you 😄 |
if (file !== undefined) { | ||
return file.snapshot; | ||
} | ||
if (!fs.existsSync(fileName)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure how bad this would be for large apps with loads of files.
But maybe in order to avoid an extra IO operation you can do
try {
return ts.ScriptSnapshot.fromString(fs.readFileSync(fileName).toString());
} catch {
return undefined;
}
} | ||
|
||
private formatErrors(fileName: string) { | ||
let allDiagnostics = this.service |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Though maybe you can test it on a system with loads of files? I was trying to do this as well over the past 2 days, and so far tests where like 10x slower when you have a lot of files and resolutions let's say over 5K files.
I can through download your branch and test this out, if you'd like. Probably tomorrow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is not main problem.
In ts-jest master currently you have smth like
fileSources.map(s => transpileModiule(s)
And transpile module don't compile any imported files. This means that it could be easilly paralellized.
With program api it looks like we can't paralelize build. You could try to run tests with this branch - it works faster in single thread mode, than with multithreading. It recompiling same files in different processes. I don't know how to fix this. Maybe it could be common shared storage of snapshots.
Closing due to inactivity. Feel free to reopen |
#281
also makes easy to fix #303
Notes:
preprocessor.js
context for every process (or even reimport it on overy transpile). If yes, this means that we have multiplecompiler
instances, so it will recompile same files for every jest worker. It could be optimized by using sharedDocumentRegistry
(https://github.com/Microsoft/TypeScript/blob/master/lib/typescript.d.ts#L4465)sourceMap=true
in CompilerOptions, on callingservice.getEmitOutput
we can get sourcemaps. We can push it to some cache and oninstall()
useI guess this way we can avoid second run of
transpileModule
.