diff --git a/src/formatter/htmlbeautifier.ts b/src/formatter/htmlbeautifier.ts
index f38e4a5..f0bf9a8 100644
--- a/src/formatter/htmlbeautifier.ts
+++ b/src/formatter/htmlbeautifier.ts
@@ -33,12 +33,15 @@ export default class HtmlBeautifier {
private executeCommand(input: string): Promise {
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) {
@@ -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