Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#67: Fix spawn EINVAL #70

Merged
merged 1 commit into from
Aug 24, 2024
Merged
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
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