11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ciconst { 31cb0ef41Sopenharmony_ci prepareMainThreadExecution, 41cb0ef41Sopenharmony_ci markBootstrapComplete, 51cb0ef41Sopenharmony_ci} = require('internal/process/pre_execution'); 61cb0ef41Sopenharmony_ciconst { getSingleExecutableCode } = internalBinding('sea'); 71cb0ef41Sopenharmony_ciconst { emitExperimentalWarning } = require('internal/util'); 81cb0ef41Sopenharmony_ciconst { Module, wrapSafe } = require('internal/modules/cjs/loader'); 91cb0ef41Sopenharmony_ciconst { codes: { ERR_UNKNOWN_BUILTIN_MODULE } } = require('internal/errors'); 101cb0ef41Sopenharmony_ciconst { BuiltinModule: { normalizeRequirableId } } = require('internal/bootstrap/realm'); 111cb0ef41Sopenharmony_ci 121cb0ef41Sopenharmony_ciprepareMainThreadExecution(false, true); 131cb0ef41Sopenharmony_cimarkBootstrapComplete(); 141cb0ef41Sopenharmony_ci 151cb0ef41Sopenharmony_ciemitExperimentalWarning('Single executable application'); 161cb0ef41Sopenharmony_ci 171cb0ef41Sopenharmony_ci// This is roughly the same as: 181cb0ef41Sopenharmony_ci// 191cb0ef41Sopenharmony_ci// const mod = new Module(filename); 201cb0ef41Sopenharmony_ci// mod._compile(contents, filename); 211cb0ef41Sopenharmony_ci// 221cb0ef41Sopenharmony_ci// but the code has been duplicated because currently there is no way to set the 231cb0ef41Sopenharmony_ci// value of require.main to module. 241cb0ef41Sopenharmony_ci// 251cb0ef41Sopenharmony_ci// TODO(RaisinTen): Find a way to deduplicate this. 261cb0ef41Sopenharmony_ci 271cb0ef41Sopenharmony_ciconst filename = process.execPath; 281cb0ef41Sopenharmony_ciconst contents = getSingleExecutableCode(); 291cb0ef41Sopenharmony_ciconst compiledWrapper = wrapSafe(filename, contents); 301cb0ef41Sopenharmony_ci 311cb0ef41Sopenharmony_ciconst customModule = new Module(filename, null); 321cb0ef41Sopenharmony_cicustomModule.filename = filename; 331cb0ef41Sopenharmony_cicustomModule.paths = Module._nodeModulePaths(customModule.path); 341cb0ef41Sopenharmony_ci 351cb0ef41Sopenharmony_ciconst customExports = customModule.exports; 361cb0ef41Sopenharmony_ci 371cb0ef41Sopenharmony_cifunction customRequire(id) { 381cb0ef41Sopenharmony_ci const normalizedId = normalizeRequirableId(id); 391cb0ef41Sopenharmony_ci if (!normalizedId) { 401cb0ef41Sopenharmony_ci throw new ERR_UNKNOWN_BUILTIN_MODULE(id); 411cb0ef41Sopenharmony_ci } 421cb0ef41Sopenharmony_ci 431cb0ef41Sopenharmony_ci return require(normalizedId); 441cb0ef41Sopenharmony_ci} 451cb0ef41Sopenharmony_ci 461cb0ef41Sopenharmony_cicustomRequire.main = customModule; 471cb0ef41Sopenharmony_ci 481cb0ef41Sopenharmony_ciconst customFilename = customModule.filename; 491cb0ef41Sopenharmony_ci 501cb0ef41Sopenharmony_ciconst customDirname = customModule.path; 511cb0ef41Sopenharmony_ci 521cb0ef41Sopenharmony_cicompiledWrapper( 531cb0ef41Sopenharmony_ci customExports, 541cb0ef41Sopenharmony_ci customRequire, 551cb0ef41Sopenharmony_ci customModule, 561cb0ef41Sopenharmony_ci customFilename, 571cb0ef41Sopenharmony_ci customDirname); 58