Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cli): add --inspect-brk-electron option #1328

Merged
merged 3 commits into from
Feb 24, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/api/cli/src/electron-forge-start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import workingDir from './util/working-dir';
.option('-n, --run-as-node', 'Run the Electron app as a Node.JS script')
.option('--vscode', 'Used to enable arg transformation for debugging Electron through VSCode. Do not use yourself.')
.option('-i, --inspect-electron', 'Triggers inspect mode on Electron to allow debugging the main process. Electron >1.7 only')
.option('--inspect-brk-electron', 'Triggers inspect-brk mode on Electron to allow debugging the main process. Electron >1.7 only')
.action((cwd) => {
dir = workingDir(dir, cwd);
})
Expand All @@ -45,6 +46,7 @@ import workingDir from './util/working-dir';
enableLogging: !!program.enableLogging,
runAsNode: !!program.runAsNode,
inspect: !!program.inspectElectron,
inspectBrk: !!program.inspectBrkElectron,
};

if (program.vscode && appArgs) {
Expand Down
5 changes: 5 additions & 0 deletions packages/api/core/src/api/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export default async ({
args = [],
runAsNode = false,
inspect = false,
inspectBrk = false,
}: StartOptions): Promise<ElectronProcess> => {
asyncOra.interactive = interactive;

Expand Down Expand Up @@ -63,6 +64,7 @@ export default async ({
args,
runAsNode,
inspect,
inspectBrk,
});
let prefixArgs: string[] = [];
if (typeof spawnedPluginChild === 'string') {
Expand Down Expand Up @@ -103,6 +105,9 @@ export default async ({
if (inspect) {
args = ['--inspect' as string | number].concat(args);
}
if (inspectBrk) {
args = ['--inspect-brk' as (string|number)].concat(args);
}

let spawned!: ElectronProcess;

Expand Down
15 changes: 15 additions & 0 deletions packages/api/core/test/fast/start_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,21 @@ describe('start', () => {
expect(spawnStub.firstCall.args[1].slice(1)).to.deep.equal(['--inspect'].concat(args));
});

it('should pass --inspect-brk at the start of the args if inspectBrk is set', async () => {
const args = ['magic'];
resolveStub.returnsArg(0);
spawnStub.returns(0);
await start({
args,
dir: __dirname,
interactive: false,
inspectBrk: true,
});
expect(spawnStub.callCount).to.equal(1);
expect(spawnStub.firstCall.args[0]).to.equal('fake_electron_path');
expect(spawnStub.firstCall.args[1].slice(1)).to.deep.equal(['--inspect-brk'].concat(args));
});

it('should resolve with a handle to the spawned instance', async () => {
resolveStub.returnsArg(0);
const fakeChild = {
Expand Down
5 changes: 5 additions & 0 deletions packages/utils/types/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ export interface StartOptions {
* Enables the node inspector, you can connect to this from chrome://inspect
*/
inspect?: boolean;
/**
* Enables the node inspector, you can connect to this from chrome://inspect
* Pauses the execution on first JavaScript line until debugger connects.
*/
inspectBrk?: boolean;
}

export type StartResult = ElectronProcess | string | string[] | false;
Expand Down