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

Avoid rootFiles mutation via synthetic $$ts-node-rootfiles.ts script #1092

Open
cspotcode opened this issue Aug 3, 2020 · 0 comments
Open

Comments

@cspotcode
Copy link
Collaborator

While working on #970, I'm realizing that modifying the rootFiles array feels super-slow, and it might be way slower than modifying existing files to import extra stuff.

We can maintain a synthetic $$ts-node-rootfiles.ts script in memory. When we need to trigger inclusion of another file, we append a /// <reference path="" /> to our synthetic script.

This wouldn't work with noResolve, but honestly who uses noResolve? And those users will need to turn on --files which avoids the whole problem anyway.

Blocked by #970, since overriding isExternalLibraryImport eliminates the need to add external files to rootFiles.

Older notes to myself below this line


Crazy idea to avoid rootFiles

ts-node maintains a synthetic /<project-dir>/$$ts-node-requires$$.ts script in memory.

Every time our require() hook is called, check if the target file is already in the program. If not, we want to pull the target file into the program. We append an import statement to our synthetic script.

We ask the language service for diagnostics and emit. TS compiler does incremental parsing of our synthetic file, resolves the appended import statement, and pulls in the require() target.

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

1 participant