development-docs/isExternalLibraryImport.md
isExternalLibraryImport is a boolean returned by node's module resolver that is true
if the target module is inside a node_modules directory.
This has 2x effects inside the compiler:
a) compiler refuses to emit JS for external modules
b) increments node_module depth +1, which affects maxNodeModulesJsDepth
If someone require()s a file inside node_modules, we need to override this flag to overcome (a).
When you try to require() a file that's previously been deemed "external", we mark the entire module's
directory as "must be internal" and add the file to rootFiles to trigger a re-resolve.
When you try to require() a file that's totally unknown to the compiler, we have to add it to rootFiles
to trigger a recompile. This is a separate issue.
In updateMemoryCache:
TODO: WHAT IF WE MUST MARK FILEA INTERNAL; WILL FILEB AUTOMATICALLY GET THE SAME TREATMENT?
TODO if noResolve, force adding to rootFileNames?
TODO if noResolve are the resolvers called anyway?
TODO eagerly classify .ts as internal, only use the "bucket" behavior for .js?
require() .ts file where TS didn't know about it before require() .js file where TS didn't know about it before, w/allowJs import {} ./node_modules//.ts import {} ./node_modules//.js w/allowJs (initially external; will be switched to internal) import {} ./node_modules//.ts from another file within node_modules import {} ./node_modules//.js from another file within node_modules require() from ./node_modules when it is ignored; ensure is not forced internal and maxNodeModulesJsDepth is respected (type info does not change)
These may jog my memory the next time I need to read TypeScript's source and remember how this works.
currentNodeModulesDepth sourceFilesFoundSearchingNodeModules
isExternalLibraryImport is used to increment currentNodeModulesDepth currentNodeModulesDepth is used to put things into sourceFilesFoundSearchingNodeModules
getSourceFilesToEmit / sourceFileMayBeEmitted obeys internal "external" state, is responsible for preventing emit of external modules