-
Notifications
You must be signed in to change notification settings - Fork 3
Command line quirk: Node's require isolation policy
An interesting gotcha of Washigton's CLI is that when executed it actually creates a script named .washington
in the current working directory. That file is the one that does the require
of the target file and it then executes that the example suite. The CLI tool creates this transition file and then runs it by spawning a new node
process and piping the stdout
and stderr
. Finally, the .washington
artifact is destroyed.
This has to be done like this because of the isolation policy of Node.js that limits access to variables declared but not explicitly exported with module.exports
if the required script is located in a different part of the directory tree. The upside is that in theory this means that Washington examples in dependencies are loaded to the runtime but immediately garbage collected, since they are not accessible. If true, this would go a long way to make inlined examples in production code a reality.