Skip to content

Commit

Permalink
Fix spawn EINVAL (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
aliariff authored Aug 24, 2024
1 parent f7b1679 commit 492aa1b
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/formatter/htmlbeautifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,15 @@ export default class HtmlBeautifier {

private executeCommand(input: string): Promise<string> {
return new Promise((resolve, reject) => {
// Handle spawn EINVAL error on Windows. See https://github.com/nodejs/node/issues/52554
const shellOptions = this.isWindows() ? { shell: true } : {};
const htmlbeautifier = cp.spawn(this.exe, this.cliOptions, {
cwd: vscode.workspace.rootPath || __dirname,
env: {
...process.env,
...this.customEnvVars,
},
...shellOptions,
});

if (htmlbeautifier.stdin === null || htmlbeautifier.stdout === null) {
Expand Down Expand Up @@ -104,10 +107,18 @@ export default class HtmlBeautifier {
const executePath = config.get("executePath", "htmlbeautifier");
const useBundler = config.get("useBundler", false);
const bundlerPath = config.get("bundlerPath", "bundle");
const ext = process.platform === "win32" && !isWsl ? ".bat" : "";
const ext = this.isWindows() ? ".bat" : "";
return useBundler ? `${bundlerPath}${ext}` : `${executePath}${ext}`;
}

/**
* Determines if the current platform is Windows (excluding WSL)
* @returns {boolean} True if the platform is Windows, false otherwise
*/
private isWindows(): boolean {
return process.platform === "win32" && !isWsl;
}

/**
* Returns the command-line options for HTML Beautifier
* @returns {string[]} The command-line options
Expand Down

0 comments on commit 492aa1b

Please sign in to comment.