Skip to content

Remove the usage of exec for variable cases#33544

Open
dxvladislavvolkov wants to merge 13 commits into
DevExpress:26_1from
dxvladislavvolkov:fix-lint
Open

Remove the usage of exec for variable cases#33544
dxvladislavvolkov wants to merge 13 commits into
DevExpress:26_1from
dxvladislavvolkov:fix-lint

Conversation

@dxvladislavvolkov
Copy link
Copy Markdown
Contributor

Fix the eslint rule - security/detect-child-process

GoodDayForSurf
GoodDayForSurf previously approved these changes May 11, 2026
@dxvladislavvolkov dxvladislavvolkov marked this pull request as ready for review May 12, 2026 07:50
Copilot AI review requested due to automatic review settings May 12, 2026 07:50
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR aims to address ESLint security/detect-child-process warnings by replacing child_process.exec usage (especially with variable input) with child_process.spawn in demo utility scripts.

Changes:

  • Switched TypeScript compilation in the TS→JS converter from exec("tsc ...") to spawn("tsc", [...]).
  • Switched Angular demo build invocation from exec("npm run ...") to spawn("npm", [...]).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
apps/demos/utils/ts-to-js-converter/converter.ts Replaces exec-based tsc invocation with spawn and updates call site to pass arguments as an array.
apps/demos/utils/create-bundles/Angular/bundler.ts Replaces exec-based Angular build command with spawn('npm', [...]).
Comments suppressed due to low confidence (1)

apps/demos/utils/create-bundles/Angular/bundler.ts:55

  • spawn('npm', ...) should handle the child process error event. If spawning fails, the unhandled error event can crash the process and res() will never be called (hanging the batch). Add an ngBuildProcess.on('error', ...) handler (and consider treating non-zero exit codes as failures rather than always calling res() as success).
    const ngBuildProcess = spawn('npm', ['run', 'build-angular', '--', getProjectNameByDemo(demo)]);
    ngBuildProcess.stdout.on('data', (data) => {
      console.log(`stdout: ${data}`);
    });
    ngBuildProcess.stderr.on('data', (data) => {
      console.error(`stderr: ${data}`);
    });
    ngBuildProcess.on('close', (code) => {
      console.log(`child process exited with code ${code}`);
      res();
    });

Comment thread apps/demos/utils/ts-to-js-converter/converter.ts Outdated
Comment thread apps/demos/utils/ts-to-js-converter/converter.ts Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

apps/demos/utils/create-bundles/Angular/bundler.ts:55

  • spawn('npm', ...) can emit an error event (e.g., if npm is not found). Right now there is no error handler, which can crash the process and also leave res() never called. Add an error listener that logs/reports the failure and completes the callback (and consider failing the build when the exit code is non-zero).
    const ngBuildProcess = spawn('npm', ['run', 'build-angular', '--', getProjectNameByDemo(demo)]);
    ngBuildProcess.stdout.on('data', (data) => {
      console.log(`stdout: ${data}`);
    });
    ngBuildProcess.stderr.on('data', (data) => {
      console.error(`stderr: ${data}`);
    });
    ngBuildProcess.on('close', (code) => {
      console.log(`child process exited with code ${code}`);
      res();
    });

Comment thread apps/demos/utils/ts-to-js-converter/converter.ts Outdated
Copilot AI review requested due to automatic review settings May 12, 2026 12:52
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

Comments suppressed due to low confidence (1)

apps/demos/utils/create-bundles/Angular/bundler.ts:52

  • There is no 'error' handler for the spawned process. If the process fails to start (e.g., missing npm/PATH issues), neither 'close' nor stdout/stderr handlers will guarantee res() is called, which can leave the caller hanging. Add an 'error' listener that logs and calls res() (or rejects, depending on expected control flow).
    const ngBuildProcess = spawn('npm', ['run', 'build-angular', '--', getProjectNameByDemo(demo)]);
    ngBuildProcess.stdout.on('data', (data) => {
      console.log(`stdout: ${data}`);
    });
    ngBuildProcess.stderr.on('data', (data) => {
      console.error(`stderr: ${data}`);
    });
    ngBuildProcess.on('close', (code) => {

Comment thread apps/demos/utils/ts-to-js-converter/converter.ts
Comment thread apps/demos/utils/ts-to-js-converter/converter.ts
Comment thread apps/demos/utils/create-bundles/Angular/bundler.ts Outdated
Copilot AI review requested due to automatic review settings May 12, 2026 13:15
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

Comments suppressed due to low confidence (1)

apps/demos/utils/create-bundles/Angular/bundler.ts:55

  • The spawned process has no 'error' handler. If npm cannot be spawned (e.g., PATH issues), Node will emit an error event that can crash the script or leave the demo build promise unresolved. Add an ngBuildProcess.on('error', ...) handler and ensure res() (or an error propagation path) is triggered.
    const ngBuildProcess = spawn('npm', ['run', 'build-angular', '--', getProjectNameByDemo(demo)], { shell: process.platform === 'win32' });
    ngBuildProcess.stdout.on('data', (data) => {
      console.log(`stdout: ${data}`);
    });
    ngBuildProcess.stderr.on('data', (data) => {
      console.error(`stderr: ${data}`);
    });
    ngBuildProcess.on('close', (code) => {
      console.log(`child process exited with code ${code}`);
      res();
    });

Comment thread apps/demos/utils/ts-to-js-converter/converter.ts
Comment thread apps/demos/utils/ts-to-js-converter/converter.ts
Comment thread apps/demos/utils/create-bundles/Angular/bundler.ts
Copilot AI review requested due to automatic review settings May 12, 2026 13:25
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

Comment thread apps/demos/utils/ts-to-js-converter/converter.ts
Comment thread apps/demos/utils/create-bundles/Angular/bundler.ts
Comment thread apps/demos/utils/create-bundles/Angular/bundler.ts
Copilot AI review requested due to automatic review settings May 12, 2026 15:05
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

cps.exec(`tsc ${args}`, (error, stdout, stderr) => {
if (error != null) {
const execTsc = (directory: string, args: string[]): Promise<string> => new Promise((resolve, reject) => {
const proc = cps.spawn('tsc', args, { cwd: directory, shell: isWindows() });

const ngBuildCommand = `npm run build-angular -- ${getProjectNameByDemo(demo)}`;
const ngBuildProcess = exec(ngBuildCommand);
const ngBuildProcess = spawn('npm', ['run', 'build-angular', '--', getProjectNameByDemo(demo)], { shell: process.platform === 'win32' });
Comment thread apps/demos/utils/ts-to-js-converter/converter.ts
Comment on lines +92 to +95
if (signal !== null) {
// eslint-disable-next-line prefer-promise-reject-errors
return reject(`tsc killed by signal ${signal}\n${stderr}\n${stdout}`);
}
Comment on lines +96 to 99
if (code !== 0) {
// eslint-disable-next-line prefer-promise-reject-errors
return reject(`${error}\n${stderr}\n${stdout}`);
return reject(`tsc exited with code ${code}\n${stderr}\n${stdout}`);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants