Skip to content
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

ts-node's require hook is replicating the TS compiler too much #157

Closed
weswigham opened this issue Jul 25, 2016 · 6 comments
Closed

ts-node's require hook is replicating the TS compiler too much #157

weswigham opened this issue Jul 25, 2016 · 6 comments

Comments

@weswigham
Copy link

weswigham commented Jul 25, 2016

With 1.2, ts-node swapped to using tsconfig to "simplify loading the tsconfig". The new dependency used to load a tsconfig file goes too far in trying to replicate tsc's default settings for compilation. At version 1.1 when using the require hook when there was no tsconfig present, ts-node only compiled the required file and anything it included. With version 1.2, it attempts to traverse the entire directory the required file is in and all subdirectories.

See this issue over at TypeScript for the problems this change caused.

I'd ask that you reconsider the change in behavior; while this behavior is OK for the TS compiler itself, it seems inappropriate for a require hook (which was invoked on a specific entrypoint).

@blakeembrey
Copy link
Member

I'm not sure why it'd cause any issues, and I agree it's replicating too much of the compiler - you can read existing discussions on that point. The problem is, the hooks provided by the compiler for loading tsconfig is not enough and buggy - for instance, can't resolve on Windows.

@blakeembrey
Copy link
Member

If you want to let me know why the change would have made any impact, definitely let me know - I'm not sure how fixing the functionality could have caused this, as far as I know both the typescript method and mine is just resolving and parsing a JSON file.

@blakeembrey
Copy link
Member

Sorry, on mobile but I think I see what it'd be. The fallback for no tsconfig file is an empty object - I'll make a change in the tsconfig project to return the old style object - empty files array and compiler options.

@blakeembrey
Copy link
Member

blakeembrey commented Jul 26, 2016

@weswigham FWIW, no functionality has fundamentally changed here so I'm still unsure about the core premise of the issue. ts-node will always have to follow whatever tsconfig.json says because that's required by the TypeScript compiler. The place this particular bug does affect is only no tsconfig.json instances. I wish I could use tsc for resolving tsconfig.json, but it's just been too buggy and unreliable over the last year - initially by not working for traversing up directories when a file existed in the current directory, next for resolving on Windows. Finally, the actual --project behaviour in tsc is not exposed either, so it can't be re-used (hence it was previously hard-coded in this project but now moved into the tsconfig dependency).

I've updated a patch on tsconfig. Anyone installing again will work as it used to.

Edit: TypeStrong/tsconfig@cbdaae6.

@blakeembrey
Copy link
Member

@weswigham How should an empty tsconfig.json be treated? Is returning an empty object (meaning it tries to parse the entire project like the original issue) the correct behaviour? Is there some hook that runtimes can use for TypeScript to optimise compilation - of course, it's possible half the stuff someone puts in tsconfig.json is not actually required for compilation, we really only need the .d.ts files.

@weswigham
Copy link
Author

weswigham commented Jul 26, 2016

@blakeembrey The only semantic change which was important here was the presence or absence of a files key. Without one, the ts compiler will search the current directory and all subfolders for ts files to build. With it, it does not. For the compiler itself, this is the desired behavior for an empty or missing tsconfig - we want to build whatever we can find if you don't have any configuration. Here in ts-node, since you're requireing what you want to build, you don't want to build everything (or even search through everything for things to build). The file you're requireing is simply a better heuristic. You just needed to have a different default than the compiler, as you were supporting a different usecase.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants