Skip to content

Commit

Permalink
fix: vscode v1_92 breaking api change when spawning .bat or .cmd files
Browse files Browse the repository at this point in the history
Signed-off-by: Zoupers <[email protected]>
  • Loading branch information
Zoupers committed Aug 6, 2024
1 parent 6a2f0cd commit 665776f
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 15 deletions.
30 changes: 25 additions & 5 deletions src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

import { spawn, spawnSync } from 'child_process';
import { CommonSpawnOptions, spawn, spawnSync } from 'child_process';
import { platform } from 'os';
import { window } from 'vscode';
import { GaugeCommands, GRADLE_COMMAND, MAVEN_COMMAND } from './constants';
Expand Down Expand Up @@ -28,7 +28,15 @@ export class CLI {
let mvnCommand = this.getCommand(MAVEN_COMMAND);
let gradleCommand = this.getGradleCommand();
if (!gaugeCommand || gaugeCommand === '') return new CLI(gaugeCommand, {}, mvnCommand, gradleCommand);
let gv = spawnSync(gaugeCommand, [GaugeCommands.Version, GaugeCommands.MachineReadable]);
let options: CommonSpawnOptions = {};
if(platform() === "win32") {
options.shell = true;
}
let gv = spawnSync(
gaugeCommand,
[GaugeCommands.Version, GaugeCommands.MachineReadable],
options
);
let gaugeVersionInfo;
try {
gaugeVersionInfo = JSON.parse(gv.stdout.toString());
Expand Down Expand Up @@ -67,7 +75,15 @@ export class CLI {
let oc = window.createOutputChannel("Gauge Install");
let chan = new OutputChannel(oc, `Installing gauge ${language} plugin ...\n`, "");
return new Promise((resolve, reject) => {
let childProcess = spawn(this._gaugeCommand, [GaugeCommands.Install, language]);
let options: CommonSpawnOptions = {};
if (platform() === "win32") {
options.shell = true;
}
let childProcess = spawn(
this._gaugeCommand,
[GaugeCommands.Install, language],
options
);
childProcess.stdout.on('data', (chunk) => chan.appendOutBuf(chunk.toString()));
childProcess.stderr.on('data', (chunk) => chan.appendErrBuf(chunk.toString()));
childProcess.on('exit', (code) => {
Expand Down Expand Up @@ -102,10 +118,14 @@ export class CLI {

private static getCommand(command: string): string {
let validExecExt = [""];
if (platform() === 'win32') validExecExt.push(".bat", ".exe", ".cmd");
let options: CommonSpawnOptions = {};
if (platform() === 'win32') {
validExecExt.push(".bat", ".exe", ".cmd");
options.shell = true;
}
for (const ext of validExecExt) {
let executable = `${command}${ext}`;
if (!spawnSync(executable).error) return executable;
if (!spawnSync(executable, [], options).error) return executable;
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/execution/gaugeExecutor.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

import { ChildProcess, spawn } from 'child_process';
import { ChildProcess, spawn, SpawnOptions } from 'child_process';
import { platform } from 'os';
import {
CancellationTokenSource, commands, Disposable, Position,
Expand Down Expand Up @@ -67,9 +67,11 @@ export class GaugeExecutor extends Disposable {
const relPath = relative(config.getProject().root(), config.getStatus());
this.preExecute.forEach((f) => { f.call(null, env, relPath); });
this.aborted = false;
let options = { cwd: config.getProject().root(), env: env , detached: false};
let options: SpawnOptions = { cwd: config.getProject().root(), env: env , detached: false };
if (platform() !== 'win32') {
options.detached = true;
} else {
options.shell = true;
}
this.childProcess = spawn(cmd, args, options);
this.childProcess.stdout.on('data', this.filterStdoutDataDumpsToTextLines((lineText: string) => {
Expand Down
14 changes: 9 additions & 5 deletions src/gaugeWorkspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
CancellationTokenSource, commands, Disposable, OutputChannel, Uri,
window, workspace, WorkspaceConfiguration, WorkspaceFoldersChangeEvent
} from "vscode";
import { DynamicFeature, LanguageClient, LanguageClientOptions, RevealOutputChannelOn } from "vscode-languageclient/node";
import { DynamicFeature, LanguageClient, LanguageClientOptions, RevealOutputChannelOn, ServerOptions } from "vscode-languageclient/node";
import { CLI } from './cli';
import GaugeConfig from './config/gaugeConfig';
import { GaugeJavaProjectConfig } from './config/gaugeProjectConfig';
Expand Down Expand Up @@ -146,12 +146,16 @@ export class GaugeWorkspace extends Disposable {
let project = ProjectFactory.get(folder);
if (this._clientsMap.has(project.root())) return;
process.env.GAUGE_IGNORE_RUNNER_BUILD_FAILURES = "true";
let serverOptions = {
command: this.cli.gaugeCommand(),
args: ["daemon", "--lsp", "--dir=" + project.root()],
options: { env: { ...process.env, ...project.envs(this.cli) } }
let serverOptions: ServerOptions = {
command: this.cli.gaugeCommand(),
args: ["daemon", "--lsp", "--dir=" + project.root()],
options: { env: { ...process.env, ...project.envs(this.cli) } },
};

if(platform() == "win32") {
serverOptions.options.shell = true;
}

this._launchConfig = workspace.getConfiguration(GAUGE_LAUNCH_CONFIG);
if (this._launchConfig.get(DEBUG_LOG_LEVEL_CONFIG)) {
serverOptions.args.push("-l");
Expand Down
14 changes: 11 additions & 3 deletions src/init/projectInit.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
'use strict';

import { spawn, spawnSync } from 'child_process';
import { CommonSpawnOptions, spawn, spawnSync } from 'child_process';
import * as fs from 'fs-extra';
import * as path from 'path';
import { commands, Disposable, Progress, Uri, window, workspace } from 'vscode';
import { CLI } from '../cli';
import { GaugeCommands, GaugeVSCodeCommands, INSTALL_INSTRUCTION_URI, VSCodeCommands } from "../constants";
import { FileListItem } from '../types/fileListItem';
import { platform } from 'os';
export class ProjectInitializer extends Disposable {
private readonly _disposable: Disposable;

Expand Down Expand Up @@ -67,7 +68,10 @@ export class ProjectInitializer extends Disposable {

private async createFromCommandLine(template: FileListItem, projectFolder: Uri, p: ProgressHandler) {
let args = [GaugeCommands.Init, template.label];
let options = { cwd: projectFolder.fsPath, env: process.env };
let options: CommonSpawnOptions = { cwd: projectFolder.fsPath, env: process.env };
if (platform() === "win32") {
options.shell = true;
}
p.report("Initializing project...");
let proc = spawn(this.cli.gaugeCommand(), args, options);
proc.addListener('error', async (err) => {
Expand All @@ -82,7 +86,11 @@ export class ProjectInitializer extends Disposable {

private async getTemplatesList(): Promise<Array<FileListItem>> {
let args = ["template", "--list", "--machine-readable"];
let cp = spawnSync(this.cli.gaugeCommand(), args, { env: process.env });
let options: CommonSpawnOptions = { env: process.env };
if (platform() === "win32") {
options.shell = true;
}
let cp = spawnSync(this.cli.gaugeCommand(), args, options);
try {
let _templates = JSON.parse(cp.stdout.toString());
return _templates.map((tmpl) => new FileListItem(tmpl.key, tmpl.Description, tmpl.value));
Expand Down

0 comments on commit 665776f

Please sign in to comment.