Skip to content
Open
Changes from all 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
41 changes: 34 additions & 7 deletions packages/capacitor/src/executors/cap/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import {
readJsonFile,
runExecutor as nxRunExecutor,
} from '@nx/devkit';
import { execSync, spawn } from 'node:child_process';
import { existsSync, rmSync } from 'node:fs';
import runCommands from 'nx/src/executors/run-commands/run-commands.impl';
import { CommandExecutorSchema } from './schema';
import { existsSync, rmSync } from 'node:fs';
import { execSync } from 'node:child_process';

export default async function* runExecutor(
options: CommandExecutorSchema,
Expand Down Expand Up @@ -59,14 +59,41 @@ export default async function* runExecutor(
const cmd = sanitizeCapacitorCommand(options.cmd);

let success = false;
try {
execSync(`npx --package=${packageName}@${packageVersion} cap ${cmd}`, {
// Use spawn for long-running commands (when -l or --livereload is present)
const isLongRunning =
/(^|\s)-(l|\-livereload)(\s|$)/.test(cmd) ||
/(^|\s)--livereload(\s|$)/.test(cmd);
if (isLongRunning) {
// Split the command into args for spawn
const args = [
`--package=${packageName}@${packageVersion}`,
'cap',
...cmd.split(' '),
];
const child = spawn('npx', args, {
stdio: 'inherit',
cwd: projectRootPath,
shell: false,
});
// Wait for the process to exit
success = await new Promise((resolve) => {
child.on('exit', (code) => {
resolve(code === 0);
});
child.on('error', () => {
resolve(false);
});
});
success = true;
} catch {
success = false;
} else {
try {
execSync(`npx --package=${packageName}@${packageVersion} cap ${cmd}`, {
stdio: 'inherit',
cwd: projectRootPath,
});
success = true;
} catch {
success = false;
}
}

const nodeModulesPath = normalizePath(`${projectRootPath}/node_modules`);
Expand Down