diff --git a/src/asar_monkey_patch.js b/src/asar_monkey_patch.js index f1c896b..cde6083 100644 --- a/src/asar_monkey_patch.js +++ b/src/asar_monkey_patch.js @@ -3,7 +3,7 @@ const path = require('path') const util = require('util') // The root dir of asar archive. -const rootDir = path._makeLong(path.join(execPath, 'asar')) +const rootDir = path._makeLong(path.join(process.execPath, 'asar')) // Convert asar archive's Stats object to fs's Stats object. let nextInode = 0 @@ -208,7 +208,7 @@ exports.wrapFsWithAsar = function(fs) { if (info.unpacked) return real else - return path.join(func(execPath), 'asar', real) + return path.join(func(process.execPath), 'asar', real) } } @@ -232,7 +232,7 @@ exports.wrapFsWithAsar = function(fs) { if (info.unpacked) { callback(null, real) } else { - func(execPath, function(err, p) { + func(process.execPath, function(err, p) { if (err) return callback(err) return callback(null, path.join(p, 'asar', real)) @@ -358,7 +358,7 @@ exports.wrapFsWithAsar = function(fs) { } const buffer = Buffer.alloc(info.size) - fs.open(execPath, 'r', function(error, fd) { + fs.open(process.execPath, 'r', function(error, fd) { if (error) return callback(error) fs.read(fd, buffer, 0, info.size, info.offset, function(error) { diff --git a/src/bootstrap.js b/src/bootstrap.js index b290a5c..2ed9b4b 100644 --- a/src/bootstrap.js +++ b/src/bootstrap.js @@ -59,7 +59,9 @@ function wrapWithActivateUvLoop(func) { require('asar_monkey_patch').wrapFsWithAsar(require('fs')) // Redirect Node to execute from current ASAR archive. - return dirname + const {executeUserEntryPoint} = internalRequire('internal/modules/run_main') + process.argv.splice(1, 0, dirname) + executeUserEntryPoint(dirname) } catch (error) { // Not an ASAR archive, continue to Node's default routine. if (error.message != 'Not an ASAR archive') diff --git a/src/yode.cc b/src/yode.cc index 345bb15..9833206 100644 --- a/src/yode.cc +++ b/src/yode.cc @@ -65,16 +65,10 @@ void Bootstrap(node::Environment* env, // Invoke the |bootstrap| with |exports|. std::vector> args = { process, require, exports }; TryCatchScope try_catch(env, TryCatchScope::CatchMode::kFatal); - v8::MaybeLocal ret = bootstrap->Call(env->context(), - env->context()->Global(), - args.size(), - args.data()); - // Change process.argv if the binary starts itself. - v8::Local r; - if (ret.ToLocal(&r) && r->IsString()) { - auto& argv = const_cast&>(env->argv()); - argv.insert(++argv.begin(), *v8::String::Utf8Value(env->isolate(), r)); - } + bootstrap->Call(env->context(), + env->context()->Global(), + args.size(), + args.data()).ToLocalChecked(); } // Like SpinEventLoop but replaces the uv_run with RunLoop. @@ -145,13 +139,11 @@ int Start(int argc, char* argv[]) { g_node_integration->Init(); } - // Load bootstrap script. - if (g_node_integration) - env->set_embedder_preload(&Bootstrap); - // Load node. { - node::LoadEnvironment(env.get(), node::StartExecutionCallback{}); + node::LoadEnvironment(env.get(), + node::StartExecutionCallback{}, + g_node_integration ? &Bootstrap : nullptr); // Enter event loop. if (g_node_integration) { g_node_integration->UvRunOnce();