Skip to content

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

Description

@cspotcode

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions