Skip to content

Commit

Permalink
feat(cli): support --noSandbox option for dev and preview command
Browse files Browse the repository at this point in the history
  • Loading branch information
alex8088 committed Nov 8, 2023
1 parent ac47dac commit 7369960
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,15 @@ interface DevCLIOptions {
inspect?: boolean | string
inspectBrk?: boolean | string
remoteDebuggingPort?: string
noSandbox?: boolean
rendererOnly?: boolean
}

interface PreviewCLIOptions {
noSandbox?: boolean
skipBuild?: boolean
}

function createInlineConfig(root: string, options: GlobalCLIOptions): InlineConfig {
return {
root,
Expand Down Expand Up @@ -71,6 +77,7 @@ cli
.option('--inspect [port]', `[boolean | number] enable V8 inspector on the specified port`)
.option('--inspectBrk [port]', `[boolean | number] enable V8 inspector on the specified port`)
.option('--remoteDebuggingPort <port>', `[string] port for remote debugging`)
.option('--noSandbox', `[boolean] forces renderer process to run un-sandboxed`)
.option('--rendererOnly', `[boolean] only dev server for the renderer`)
.action(async (root: string, options: DevCLIOptions & GlobalCLIOptions) => {
if (options.remoteDebuggingPort) {
Expand All @@ -85,6 +92,10 @@ cli
process.env.V8_INSPECTOR_BRK_PORT = typeof options.inspectBrk === 'number' ? `${options.inspectBrk}` : '5858'
}

if (options.noSandbox) {
process.env.NO_SANDBOX = '1'
}

if (options.entry) {
process.env.ELECTRON_ENTRY = options.entry
}
Expand Down Expand Up @@ -125,11 +136,16 @@ cli.command('build [root]', 'build for production').action(async (root: string,
// preview
cli
.command('preview [root]', 'start electron app to preview production build')
.option('--noSandbox', `[boolean] forces renderer process to run un-sandboxed`)
.option('--skipBuild', `[boolean] skip build`)
.action(async (root: string, options: { skipBuild?: boolean } & GlobalCLIOptions) => {
.action(async (root: string, options: PreviewCLIOptions & GlobalCLIOptions) => {
const { preview } = await import('./preview')
const inlineConfig = createInlineConfig(root, options)

if (options.noSandbox) {
process.env.NO_SANDBOX = '1'
}

if (options.entry) {
process.env.ELECTRON_ENTRY = options.entry
}
Expand Down
4 changes: 4 additions & 0 deletions src/electron.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ export function startElectron(root: string | undefined): ChildProcess {
args.push(`--inspect-brk=${process.env.V8_INSPECTOR_BRK_PORT}`)
}

if (process.env.NO_SANDBOX === '1') {
args.push('--no-sandbox')
}

const entry = process.env.ELECTRON_ENTRY || '.'

const ps = spawn(electronPath, [entry].concat(args), { stdio: 'inherit' })
Expand Down

0 comments on commit 7369960

Please sign in to comment.