-
Notifications
You must be signed in to change notification settings - Fork 65
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
Feature Request: Throw fatal error if compilation fails #10
Comments
Apparently TypeScript doesn't call It's simple to replicate this. Just write a malformed TypeScript file, e.g. don't match a curly brace, and try to require it. |
I've added exitOnError flag. Default is true. Ohhh, we need npm publush now. |
Published! |
This doesn't fix the issue. Here's a simple example.
require('typescript-require');
var tsfile = require('./tsfile.ts');
console.log("I'm still running.");
if (false) {} Run once, and you get the following output, as expected:
Now, change if (false) { Run again:
After inserting a debug print, TypeScript does call
I imagine this is the price you pay for trying to emulate a synchronous |
The problem is that when that script is compiled by node synchronous method vm.runInThisContext() the execution goes further but exit callback is called later asynchonously. Thus in this version of node it's impossible to rely on process.exit, so this code (it's taken from typescript-require index.js file) will never call exit synchronously: var proc = merge(merge({}, process), {
argv: compact(argv),
exit: function(code) {
exitCode = code;
}
}); So we need a different way of knowing if there ware compilation errors. I pushed this solution to the branch "process.stderr" please review it. |
I can test this tomorrow... but I found an alternative solution relying on an external package, if you're interested.
|
Looks very good. I will try it later. |
What do you guys think about using typescript-compiler to do the compilation? |
Keeping the compiler running on on its own process ensures it will not affect the execution of the program. The memory and performance requirements of the compiler could affect larger programs. That makes me think that it is better to keep the compiler isolated in its own process. But there might be other benefits in running in in-process, such as faster execution, or better error handling, or even just-in-time compile. |
One thing doesn't affect the other. We can use typescript-compiler and still spawn a new process for the compilation. What I don't know is if spawn processes for compilation is really beneficial. Specially because on a large source base this could mean a lot of processes. |
I guess I was under the assumption that there wouldn't be so many processes since the compiler builds dependencies as well and caches them as .js files for later use. |
The require cache helps a lot. The compiler will only build dependencies if they are |
Currently, if
typescript-require
encounters errors during compilation but a previous compiled version of the TypeScript file is present, it will use the old one and chug on.This is undesired behavior for me, as it's easy to miss the compilation errors and think that your changes did not fix an issue.
If this is desired default behavior, could you expose a configuration option that turns this into a fatal error?
Thanks!
The text was updated successfully, but these errors were encountered: