Skip to content

Commit

Permalink
Fix Windows Compatibility Issues (#41)
Browse files Browse the repository at this point in the history
* Switch to using execFile instead of exec
* Fix npm scripts not working on windows
* Fix package-lock.json after adding shx
  • Loading branch information
riccardopiola authored Dec 13, 2024
1 parent f620370 commit de48d57
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 12 deletions.
55 changes: 55 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -135,23 +135,23 @@
]
},
"scripts": {
"clean": "rm -rf out/",
"clean": "shx rm -rf out/",
"build": "npm run clean && npm run build:pkl && npm run build:code && npm run build:tree-sitter && npm run build:download-lsp",
"build:local": "npm run clean && npm run build:pkl && npm run build:code && npm run build:tree-sitter:local && npm run build:download-lsp",
"build:pkl": "pkl eval -m . src/pkl/index.pkl",
"build:download-lsp": "ts-node scripts/download-lsp-jar.ts",
"build:tree-sitter": "mkdir -p out/grammar/ && cd node_modules/@apple/tree-sitter-pkl && tree-sitter build-wasm && cd - && mv node_modules/@apple/tree-sitter-pkl/tree-sitter-pkl.wasm out/pkl.wasm",
"build:tree-sitter:local": "mkdir -p out/grammar/ && cd node_modules/@apple/tree-sitter-pkl && tree-sitter build-wasm --docker && cd - && mv node_modules/@apple/tree-sitter-pkl/tree-sitter-pkl.wasm out/pkl.wasm",
"esbuild-base": "mkdir -p out/ && cp node_modules/web-tree-sitter/tree-sitter.wasm out/ && esbuild ./src/ts/extension.ts --bundle --outfile=out/main.js --external:vscode --format=cjs --platform=node",
"build:tree-sitter": "shx mkdir -p out/grammar/ && cd node_modules/@apple/tree-sitter-pkl && tree-sitter build-wasm && shx mv tree-sitter-pkl.wasm ../../../out/pkl.wasm",
"build:tree-sitter:local": "shx mkdir -p out/grammar/ && cd node_modules/@apple/tree-sitter-pkl && tree-sitter build-wasm --docker && cd - && mv node_modules/@apple/tree-sitter-pkl/tree-sitter-pkl.wasm out/pkl.wasm",
"esbuild-base": "shx mkdir -p out/ && shx cp node_modules/web-tree-sitter/tree-sitter.wasm out/ && esbuild ./src/ts/extension.ts --bundle --outfile=out/main.js --external:vscode --format=cjs --platform=node",
"build:code": "npm run esbuild-base -- --sourcemap",
"lint:fix": "prettier -w src/",
"lint": "prettier -c src/",
"watch": "npm run esbuild-base -- --sourcemap --watch",
"test": "node scripts/license-header.js test && npm run test:grammar",
"test:grammar": "sh scripts/check-grammar",
"prepackage": "npm run build",
"package": "mkdir -p .dist/vscode && vsce package --out .dist/vscode/pkl-vscode-$npm_package_version.vsix",
"package-only": "mkdir -p .dist/vscode && vsce package --out .dist/vscode/pkl-vscode-$npm_package_version.vsix",
"package": "shx mkdir -p .dist/vscode && vsce package --out .dist/vscode/pkl-vscode-$npm_package_version.vsix",
"package-only": "shx mkdir -p .dist/vscode && vsce package --out .dist/vscode/pkl-vscode-$npm_package_version.vsix",
"preinstallextension": "npm run package",
"installextension": "code --install-extension .dist/vscode/pkl-vscode-$npm_package_version.vsix",
"add-license-headers": "node scripts/license-header.js",
Expand All @@ -166,6 +166,7 @@
"@types/vscode": "^1.59.0",
"esbuild": "^0.14.54",
"prettier": "^2.6.2",
"shx": "^0.3.4",
"tree-sitter": "^0.20.0",
"tree-sitter-cli": "^0.20.8",
"ts-node": "^10.9.2",
Expand Down
4 changes: 2 additions & 2 deletions src/ts/javaDistribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import fs from "node:fs/promises";
import path from "node:path";
import * as vscode from "vscode";
import { debounce, exec } from "./utils";
import { debounce, execFile } from "./utils";
import { COMMAND_OPEN_WORKSPACE_SETTINGS, CONFIG_JAVA_PATH } from "./consts";
import config from "./config";
import logger from "./clients/logger";
Expand Down Expand Up @@ -69,7 +69,7 @@ const resolveJava = async (path: string): Promise<JavaDistribution | null> => {
if (!stats.isFile()) {
return null;
}
const result = await exec(`${path} -version`);
const result = await execFile(path, ["-version"]);
const { stderr } = result;
const versionStr = stderr.split('"')[1];
if (versionStr == null) {
Expand Down
4 changes: 2 additions & 2 deletions src/ts/pklLspDistribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import path from "node:path";
import config from "./config";
import { getJavaDistribution } from "./javaDistribution";
import { debounce, exec, isRegularFile } from "./utils";
import { debounce, execFile, isRegularFile } from "./utils";
import Semver from "./Semver";
import * as vscode from "vscode";
import fs from "fs/promises";
Expand Down Expand Up @@ -65,7 +65,7 @@ export const bundledDistribution: LspDistribution = {

const getLspVersion = async (jarPath: string): Promise<Semver | undefined> => {
const javaDistribution = await getJavaDistribution();
const { stdout } = await exec(`${javaDistribution.path} -jar ${jarPath} --version`);
const { stdout } = await execFile(javaDistribution.path, ["-jar", jarPath, "--version"]);
const versionStr = stdout
.replace(/\r?\n$/, "")
.split(" version ")
Expand Down
4 changes: 2 additions & 2 deletions src/ts/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
//===----------------------------------------------------------------------===//

import { promisify } from "node:util";
import { exec as _exec } from "node:child_process";
import { execFile as _execFile } from "node:child_process";
import fs from "node:fs/promises";
import { createWriteStream } from "node:fs";
import https from "node:https";
import crypto from "node:crypto";
import os from "node:os";
import path from "node:path";

export const exec = promisify(_exec);
export const execFile = promisify(_execFile);

export const debounce = <A extends any[]>(
f: (...args: A) => any,
Expand Down

0 comments on commit de48d57

Please sign in to comment.