diff --git a/src/node_sea_bin.cc b/src/node_sea_bin.cc index dc9c9e614f8fca..e0993607cb7ba0 100644 --- a/src/node_sea_bin.cc +++ b/src/node_sea_bin.cc @@ -388,7 +388,7 @@ ExitCode BuildSingleExecutable(const std::string& sea_config_path, SeaConfig config = opt_config.value(); if (config.executable_path.empty()) { - config.executable_path = args[0]; + config.executable_path = Environment::GetExecPath(args); } // Get file permissions from source executable to copy over later. diff --git a/test/sea/test-build-sea-custom-argv0.js b/test/sea/test-build-sea-custom-argv0.js new file mode 100644 index 00000000000000..2c8b6b83e02cdb --- /dev/null +++ b/test/sea/test-build-sea-custom-argv0.js @@ -0,0 +1,34 @@ +'use strict'; +// This tests --build-sea with a custom argv0 value. + +require('../common'); + +const { skipIfBuildSEAIsNotSupported } = require('../common/sea'); + +skipIfBuildSEAIsNotSupported(); + +const tmpdir = require('../common/tmpdir'); +const fixtures = require('../common/fixtures'); +const { copyFileSync } = require('fs'); + +const { spawnSyncAndAssert } = require('../common/child_process'); +tmpdir.refresh(); + +copyFileSync( + fixtures.path('sea', 'basic', 'sea-config.json'), + tmpdir.resolve('sea-config.json'), +); + +copyFileSync( + fixtures.path('sea', 'basic', 'sea.js'), + tmpdir.resolve('sea.js'), +); + +spawnSyncAndAssert( + process.execPath, + ['--build-sea', tmpdir.resolve('sea-config.json')], { + cwd: tmpdir.path, + argv0: 'argv0', + }, { + stdout: /Generated single executable/, + });