Skip to content

Commit

Permalink
feat(cli): add --inspect-brk-electron option (#1328)
Browse files Browse the repository at this point in the history
* feat(cli): add --inspect-brk-electron option

* chore: fix lint

Co-authored-by: Samuel Attard <[email protected]>
Co-authored-by: Keeley Hammond <[email protected]>
  • Loading branch information
3 people authored Feb 24, 2022
1 parent 60ec190 commit c5a6ea1
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
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

0 comments on commit c5a6ea1

Please sign in to comment.