MCPcopy Index your code
hub / github.com/nodejs/node / embedderRunCjs

Function embedderRunCjs

lib/internal/main/embedding.js:46–100  ·  view source on GitHub ↗
(content, filename)

Source from the content-addressed store, hash-verified

44//
45// TODO(RaisinTen): Find a way to deduplicate this.
46function embedderRunCjs(content, filename) {
47 // The filename of the module (used for CJS module lookup)
48 // is always the same as the location of the executable itself
49 // at the time of the loading (which means it changes depending
50 // on where the executable is in the file system).
51 const customModule = new Module(filename, null);
52
53 const {
54 function: compiledWrapper,
55 cachedDataRejected,
56 sourceMapURL,
57 sourceURL,
58 } = compileFunctionForCJSLoader(
59 content,
60 filename,
61 isLoadingSea, // is_sea_main
62 false, // should_detect_module, ESM should be supported differently for embedded code
63 true, // is_embedder
64 );
65 // Cache the source map for the module if present.
66 if (sourceMapURL) {
67 maybeCacheSourceMap(
68 filename,
69 content,
70 customModule,
71 false, // isGeneratedSource
72 sourceURL,
73 sourceMapURL,
74 );
75 }
76
77 // cachedDataRejected is only set if cache from SEA is used.
78 if (cachedDataRejected !== false && isLoadingSea) {
79 emitWarningSync('Code cache data rejected.');
80 }
81
82 // Patch the module to make it look almost like a regular CJS module
83 // instance.
84 customModule.filename = process.execPath;
85 customModule.paths = Module._nodeModulePaths(process.execPath);
86 embedderRequire.main = customModule;
87
88 // This currently returns what the wrapper returns i.e. if the code
89 // happens to have a return statement, it returns that; Otherwise it's
90 // undefined.
91 // TODO(joyeecheung): we may want to return the customModule or put it in an
92 // out parameter.
93 return compiledWrapper(
94 customModule.exports, // exports
95 embedderRequire, // require
96 customModule, // module
97 filename, // __filename
98 customModule.path, // __dirname
99 );
100}
101
102function embedderRequire(id) {
103 return loadBuiltinModuleForEmbedder(id).exports;

Callers 1

embedderRunEntryPointFunction · 0.85

Calls 2

maybeCacheSourceMapFunction · 0.85
emitWarningSyncFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…