Skip to content
Draft
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions app/electron/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import { ChildProcessWithoutNullStreams, exec, execSync, spawn } from 'child_process';
import { ChildProcessWithoutNullStreams, exec, execFileSync, spawn } from 'child_process';
import { randomBytes } from 'crypto';
import dotenv from 'dotenv';
import {
Expand Down Expand Up @@ -91,7 +91,7 @@ const args = yargs(hideBin(process.argv))
() => {
try {
const backendPath = path.join(process.resourcesPath, 'headlamp-server');
const stdout = execSync(`${backendPath} list-plugins`);
const stdout = execFileSync(backendPath, ['list-plugins']);
process.stdout.write(stdout);
process.exit(0);
} catch (error) {
Expand Down Expand Up @@ -1090,7 +1090,7 @@ async function getRunningHeadlampPIDs() {
function killProcess(pid: number) {
if (process.platform === 'win32') {
// Otherwise on Windows the process will stick around.
execSync('taskkill /pid ' + pid + ' /T /F');
execFileSync('taskkill', ['/pid', String(pid), '/T', '/F']);
} else {
process.kill(pid, 'SIGHUP');
}
Expand Down
4 changes: 2 additions & 2 deletions app/scripts/build-backend.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const { execSync } = require('child_process');
const { execFileSync } = require('child_process');

exports.default = async context => {
let arch = context.arch;
Expand All @@ -15,7 +15,7 @@ exports.default = async context => {
osName = 'Windows_NT';
}

execSync('make backend', {
execFileSync('make', ['backend'], {
env: {
...process.env, // needed otherwise important vars like PATH and GOROOT are not set
GOARCH: arch,
Expand Down
4 changes: 1 addition & 3 deletions app/scripts/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@
*
* Assumes being run from within the app/ folder
*/
const { spawn } = require('child_process');
const { spawn, spawnSync } = require('child_process');
const { statSync, existsSync } = require('fs');
const { join } = require('path');
const { execSync } = require('child_process');
const { spawnSync } = require('child_process');

/**
* @returns the last commit date of the backend/ in milliseconds since epoch,
Expand Down
6 changes: 4 additions & 2 deletions frontend/make-env.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@

'use strict';
// Creates the .env file
import { execSync } from 'child_process';
import { execFileSync } from 'child_process';
import fs from 'fs';
const appInfo = JSON.parse(fs.readFileSync('../app/package.json', 'utf8'));

const gitVersion = execSync('git rev-parse HEAD').toString().trim();
const gitVersion = execFileSync('git', ['rev-parse', 'HEAD'], {
encoding: 'utf8',
}).trim();

const envContents = {
REACT_APP_HEADLAMP_VERSION: appInfo.version,
Expand Down
7 changes: 3 additions & 4 deletions plugins/headlamp-plugin/bin/headlamp-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ function create(name, link, noInstall) {
} else {
console.log('Installing dependencies...');
try {
child_process.execSync('npm ci', {
child_process.execFileSync('npm', ['ci'], {
stdio: 'inherit',
cwd: dstFolder,
encoding: 'utf8',
Expand Down Expand Up @@ -603,7 +603,7 @@ function runScriptOnPackages(packageFolder, scriptName, cmdLine, env) {
console.log(`No node_modules in "${folder}" found. Running npm install...`);

try {
child_process.execSync('npm install', {
child_process.execFileSync('npm', ['install'], {
stdio: 'inherit',
encoding: 'utf8',
});
Expand Down Expand Up @@ -864,7 +864,7 @@ function getNpmOutdated() {
let result = null;

try {
result = child_process.execSync('npm outdated --json', {
result = child_process.execFileSync('npm', ['outdated', '--json'], {
encoding: 'utf8',
});
} catch (error) {
Expand Down Expand Up @@ -1030,7 +1030,6 @@ function upgrade(packageFolder, skipPackageUpdates, headlampPluginVersion) {
encoding: 'utf8',
});
} catch (e) {
console.error(`Problem running ${cmd}`);
return e.status;
}
return 0;
Expand Down
7 changes: 5 additions & 2 deletions tools/releaser/src/commands/start.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import chalk from 'chalk';
import path from 'path';
import fs from 'fs';
import { execSync } from 'child_process';
import { execFileSync } from 'child_process';
import { getRepoRoot, commitVersionChange } from '../utils/git.js';
import { sanitizeVersion } from '../utils/version.js';

Expand All @@ -22,7 +22,10 @@ export function startRelease(releaseVersion: string): void {

// Run npm install in app directory
console.log(chalk.blue('Running npm install in app directory...'));
execSync('npm install', { stdio: 'inherit', cwd: path.join(repoRoot, 'app') });
execFileSync('npm', ['install'], {
stdio: 'inherit',
cwd: path.join(repoRoot, 'app'),
Copy link

Copilot AI Nov 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On Windows, npm is typically a .cmd file, not an executable. Using execFileSync('npm', ...) without shell: true will fail on Windows. Consider adding shell: true to the options or using a cross-platform solution like checking process.platform === 'win32' and adjusting the command accordingly (e.g., 'npm.cmd' on Windows).

Suggested change
cwd: path.join(repoRoot, 'app'),
cwd: path.join(repoRoot, 'app'),
shell: true,

Copilot uses AI. Check for mistakes.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a real issue, I tested it in node on windows with cmd.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this could probably be reverted, doing this now

});
console.log(chalk.green('✅ npm install completed'));

// Commit the changes
Expand Down
18 changes: 12 additions & 6 deletions tools/releaser/src/utils/git.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { execSync } from 'child_process';
import { execFileSync } from 'child_process';
import path from 'path';
import fs from 'fs';

export function getRepoRoot(): string {
try {
const gitRoot = execSync('git rev-parse --show-toplevel', { encoding: 'utf-8' }).trim();
const gitRoot = execFileSync('git', ['rev-parse', '--show-toplevel'], {
encoding: 'utf-8',
}).trim();
return gitRoot;
} catch (error) {
console.error('Error: Not in a git repository');
Expand All @@ -31,8 +33,10 @@ export function commitVersionChange(version: string): void {
const packageLockJsonPath = path.join(repoRoot, 'app', 'package-lock.json');

try {
execSync(`git add "${packageJsonPath}" "${packageLockJsonPath}"`);
execSync(`git commit --signoff -m "app: Bump version to ${version}"`);
execFileSync('git', ['add', packageJsonPath, packageLockJsonPath], { stdio: 'inherit' });
execFileSync('git', ['commit', '--signoff', '-m', `app: Bump version to ${version}`], {
stdio: 'inherit',
});
} catch (error) {
console.error('Error: Failed to commit version change');
console.error(error);
Expand All @@ -42,7 +46,9 @@ export function commitVersionChange(version: string): void {

export function createReleaseTag(version: string): void {
try {
execSync(`git tag -a v${version} -m "Release ${version}"`);
execFileSync('git', ['tag', '-a', `v${version}`, '-m', `Release ${version}`], {
stdio: 'inherit',
});
} catch (error) {
console.error(`Error: Failed to create tag v${version}`);
console.error(error);
Expand All @@ -52,7 +58,7 @@ export function createReleaseTag(version: string): void {

export function pushTag(version: string): void {
try {
execSync(`git push origin v${version}`);
execFileSync('git', ['push', 'origin', `v${version}`], { stdio: 'inherit' });
} catch (error) {
console.error(`Error: Failed to push tag v${version} to origin`);
console.error(error);
Expand Down
Loading