Skip to main content

install_entry_globals

Function install_entry_globals 

Source
pub fn install_entry_globals(origin: &str)
Expand description

Install the CJS wrapper variables the ENTRY script sees.

A required module already receives exports/require/module/__dirname /__filename as wrapper parameters (see compile_wrapper); the entry script used to receive none of them, so typeof module was "undefined" there and every UMD header took its browser branch. Node gives the entry script the same five names, with values that DEPEND ON THE ENTRY POINT:

node f.jsnode -enode - / piped
__filenameresolved abs path[eval][stdin]
__dirnameits directory..
module.id.[eval][stdin]
module.pathits directory..

module.filename is path.resolve(__filename) in every case, so under -e it is <cwd>/[eval] — a path that does not exist, which is Node’s own value. Measured on node v26.7.0.

origin is the __filename value: an absolute script path, or [eval] / [stdin] for the two source-on-the-command-line entry points.