mirror of
https://github.com/electron/electron.git
synced 2026-04-10 03:01:51 -04:00
fix: NODE_OPTIONS parsing for child processes on macOS (#46242)
* fix: NODE_OPTIONS parsing for child processes on macOS Co-authored-by: deepak1556 <hop2deep@gmail.com> * chore: temporarily disable test Co-authored-by: deepak1556 <hop2deep@gmail.com> * chore: apply review feedback Co-authored-by: deepak1556 <hop2deep@gmail.com> * chore: fix build Co-authored-by: deepak1556 <hop2deep@gmail.com> --------- Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: deepak1556 <hop2deep@gmail.com>
This commit is contained in:
@@ -90,7 +90,10 @@
|
||||
|
||||
#if BUILDFLAG(IS_MAC)
|
||||
#include <CoreFoundation/CoreFoundation.h>
|
||||
#include "base/no_destructor.h"
|
||||
#include "content/browser/mac_helpers.h"
|
||||
#include "shell/browser/ui/cocoa/electron_bundle_mover.h"
|
||||
#include "shell/common/process_util.h"
|
||||
#endif
|
||||
|
||||
#if BUILDFLAG(IS_LINUX)
|
||||
@@ -898,6 +901,21 @@ bool App::IsPackaged() {
|
||||
|
||||
#if BUILDFLAG(IS_WIN)
|
||||
return base_name != FILE_PATH_LITERAL("electron.exe");
|
||||
#elif BUILDFLAG(IS_MAC)
|
||||
static const base::NoDestructor<std::string> default_helper(
|
||||
"electron helper" +
|
||||
base::ToLowerASCII(content::kMacHelperSuffix_default));
|
||||
static const base::NoDestructor<std::string> renderer_helper(
|
||||
"electron helper" +
|
||||
base::ToLowerASCII(content::kMacHelperSuffix_renderer));
|
||||
static const base::NoDestructor<std::string> plugin_helper(
|
||||
"electron helper" + base::ToLowerASCII(content::kMacHelperSuffix_plugin));
|
||||
if (IsRendererProcess()) {
|
||||
return base_name != *renderer_helper;
|
||||
} else if (IsUtilityProcess()) {
|
||||
return base_name != *default_helper && base_name != *plugin_helper;
|
||||
}
|
||||
return base_name != FILE_PATH_LITERAL("electron");
|
||||
#else
|
||||
return base_name != FILE_PATH_LITERAL("electron");
|
||||
#endif
|
||||
|
||||
1
spec/fixtures/apps/node-options-utility-process/fail.js
vendored
Normal file
1
spec/fixtures/apps/node-options-utility-process/fail.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
process.exit(1);
|
||||
15
spec/fixtures/apps/node-options-utility-process/main.js
vendored
Normal file
15
spec/fixtures/apps/node-options-utility-process/main.js
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
const { app, utilityProcess } = require('electron');
|
||||
|
||||
const path = require('node:path');
|
||||
|
||||
app.whenReady().then(() => {
|
||||
const child = utilityProcess.fork(path.join(__dirname, 'noop.js'), [], {
|
||||
stdio: 'inherit',
|
||||
env: {
|
||||
...process.env,
|
||||
NODE_OPTIONS: `--require ${path.join(__dirname, 'fail.js')}`
|
||||
}
|
||||
});
|
||||
|
||||
child.once('exit', (code) => app.exit(code));
|
||||
});
|
||||
1
spec/fixtures/apps/node-options-utility-process/noop.js
vendored
Normal file
1
spec/fixtures/apps/node-options-utility-process/noop.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
process.exit(0);
|
||||
4
spec/fixtures/apps/node-options-utility-process/package.json
vendored
Normal file
4
spec/fixtures/apps/node-options-utility-process/package.json
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"name": "electron-test-node-options-utility-process",
|
||||
"main": "main.js"
|
||||
}
|
||||
@@ -697,6 +697,29 @@ describe('node feature', () => {
|
||||
expect(code).to.equal(1);
|
||||
});
|
||||
|
||||
it('does allow --require in utility process of non-packaged apps', async () => {
|
||||
const appPath = path.join(fixtures, 'apps', 'node-options-utility-process');
|
||||
// App should exit with code 1.
|
||||
const child = childProcess.spawn(process.execPath, [appPath]);
|
||||
const [code] = await once(child, 'exit');
|
||||
expect(code).to.equal(1);
|
||||
});
|
||||
|
||||
// TODO(deepak1556): will be enabled in follow-up PR
|
||||
// https://github.com/electron/electron/pull/46210
|
||||
it.skip('does not allow --require in utility process of packaged apps', async () => {
|
||||
const appPath = path.join(fixtures, 'apps', 'node-options-utility-process');
|
||||
// App should exit with code 1.
|
||||
const child = childProcess.spawn(process.execPath, [appPath], {
|
||||
env: {
|
||||
...process.env,
|
||||
ELECTRON_FORCE_IS_PACKAGED: 'true'
|
||||
}
|
||||
});
|
||||
const [code] = await once(child, 'exit');
|
||||
expect(code).to.equal(0);
|
||||
});
|
||||
|
||||
it('does not allow --require in packaged apps', async () => {
|
||||
const appPath = path.join(fixtures, 'module', 'noop.js');
|
||||
const env = {
|
||||
|
||||
Reference in New Issue
Block a user