Skip to content

Commit

Permalink
feat(electron): enable vscode debugger for electron
Browse files Browse the repository at this point in the history
  • Loading branch information
pengx17 committed Dec 26, 2024
1 parent 96fae47 commit 5d7454e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
7 changes: 6 additions & 1 deletion packages/frontend/apps/electron/scripts/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@ function spawnOrReloadElectron() {
const ext = process.platform === 'win32' ? '.cmd' : '';
const exe = resolve(rootDir, 'node_modules', '.bin', `electron${ext}`);

delete process.env['NODE_OPTIONS'];
// remove import loader option
const NODE_OPTIONS = process.env.NODE_OPTIONS;
if (NODE_OPTIONS) {
process.env.NODE_OPTIONS = NODE_OPTIONS.replace(/--import=[^\s]*/, '');
}

spawnProcess = spawn(exe, ['.'], {
cwd: electronDir,
env: process.env,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { Display } from 'electron';
import { BrowserWindow, screen } from 'electron';

import { isMacOS } from '../../shared/utils';
import { isDev } from '../config';
import { onboardingViewUrl } from '../constants';
// import { getExposedMeta } from './exposed';
import { logger } from '../logger';
Expand Down Expand Up @@ -90,6 +91,10 @@ async function createOnboardingWindow(additionalArguments: string[]) {
fullscreenAndCenter(browserWindow);
});

if (isDev) {
browserWindow.webContents.openDevTools();
}

await browserWindow.loadURL(onboardingViewUrl);

return browserWindow;
Expand Down
8 changes: 7 additions & 1 deletion tools/cli/src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,18 @@ export class RunCommand extends PackageCommand {
new RegExp(ignore).test(scriptName)
);

const loaderOption =
'--import=' + currentDir.join('../register.js').toFileUrl();
let nodeOptions = process.env.NODE_OPTIONS
? process.env.NODE_OPTIONS + ` ${loaderOption}`
: loaderOption;

await execAsync(pkg.name, ['yarn', scriptName, ...args], {
cwd: pkg.path.value,
...(isLoaderRequired
? {
env: {
NODE_OPTIONS: `--import=${currentDir.join('../register.js').toFileUrl()}`,
NODE_OPTIONS: nodeOptions,
},
}
: {}),
Expand Down
2 changes: 1 addition & 1 deletion tools/utils/src/path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class Path {
return './' + this.path.slice(ProjectRoot.path.length).replace(/\\/g, '/');
}

constructor(public readonly path: string) {}
constructor(public readonly path: string) { }

join(...paths: string[]) {
return new Path(join(this.path, ...paths));
Expand Down

0 comments on commit 5d7454e

Please sign in to comment.