From de48d57df69ba418422580a6dd4c1c6d41db8932 Mon Sep 17 00:00:00 2001 From: Riccardo Piola Date: Fri, 13 Dec 2024 18:13:54 +0100 Subject: [PATCH] Fix Windows Compatibility Issues (#41) * Switch to using execFile instead of exec * Fix npm scripts not working on windows * Fix package-lock.json after adding shx --- package-lock.json | 55 ++++++++++++++++++++++++++++++++++++ package.json | 13 +++++---- src/ts/javaDistribution.ts | 4 +-- src/ts/pklLspDistribution.ts | 4 +-- src/ts/utils.ts | 4 +-- 5 files changed, 68 insertions(+), 12 deletions(-) diff --git a/package-lock.json b/package-lock.json index e68e5e4..95b26fd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17,6 +17,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", @@ -1477,6 +1478,15 @@ "integrity": "sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew==", "dev": true }, + "node_modules/interpret": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/interpret/-/interpret-1.4.0.tgz", + "integrity": "sha512-agE4QfB2Lkp9uICn7BAqoscw4SZP9kTE2hxiFI3jBPmXJfdqiahTbUuKGsMoN2GtqL9AxhYioAcVvgsb1HvRbA==", + "dev": true, + "engines": { + "node": ">= 0.10" + } + }, "node_modules/is-core-module": { "version": "2.15.1", "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.15.1.tgz", @@ -1939,6 +1949,18 @@ "node": ">= 6" } }, + "node_modules/rechoir": { + "version": "0.6.2", + "resolved": "https://registry.npmjs.org/rechoir/-/rechoir-0.6.2.tgz", + "integrity": "sha512-HFM8rkZ+i3zrV+4LQjwQ0W+ez98pApMGM3HUrN04j3CqzPOzl9nmP15Y8YXNm8QHGv/eacOVEjqhmWpkRV0NAw==", + "dev": true, + "dependencies": { + "resolve": "^1.1.6" + }, + "engines": { + "node": ">= 0.10" + } + }, "node_modules/resolve": { "version": "1.22.8", "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.8.tgz", @@ -2038,6 +2060,39 @@ "integrity": "sha512-MATJdZp8sLqDl/68LfQmbP8zKPLQNV6BIZoIgrscFDQ+RsvK/BxeDQOgyxKKoh0y/8h3BqVFnCqQ/gd+reiIXA==", "dev": true }, + "node_modules/shelljs": { + "version": "0.8.5", + "resolved": "https://registry.npmjs.org/shelljs/-/shelljs-0.8.5.tgz", + "integrity": "sha512-TiwcRcrkhHvbrZbnRcFYMLl30Dfov3HKqzp5tO5b4pt6G/SezKcYhmDg15zXVBswHmctSAQKznqNW2LO5tTDow==", + "dev": true, + "dependencies": { + "glob": "^7.0.0", + "interpret": "^1.0.0", + "rechoir": "^0.6.2" + }, + "bin": { + "shjs": "bin/shjs" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/shx": { + "version": "0.3.4", + "resolved": "https://registry.npmjs.org/shx/-/shx-0.3.4.tgz", + "integrity": "sha512-N6A9MLVqjxZYcVn8hLmtneQWIJtp8IKzMP4eMnx+nqkvXoqinUPCbUFLp2UcWTEIUONhlk0ewxr/jaVGlc+J+g==", + "dev": true, + "dependencies": { + "minimist": "^1.2.3", + "shelljs": "^0.8.5" + }, + "bin": { + "shx": "lib/cli.js" + }, + "engines": { + "node": ">=6" + } + }, "node_modules/side-channel": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.6.tgz", diff --git a/package.json b/package.json index 7f660a9..ee0ceed 100644 --- a/package.json +++ b/package.json @@ -135,14 +135,14 @@ ] }, "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/", @@ -150,8 +150,8 @@ "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", @@ -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", diff --git a/src/ts/javaDistribution.ts b/src/ts/javaDistribution.ts index 0b6d896..7758e28 100644 --- a/src/ts/javaDistribution.ts +++ b/src/ts/javaDistribution.ts @@ -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"; @@ -69,7 +69,7 @@ const resolveJava = async (path: string): Promise => { 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) { diff --git a/src/ts/pklLspDistribution.ts b/src/ts/pklLspDistribution.ts index 8996c9a..e9f9898 100644 --- a/src/ts/pklLspDistribution.ts +++ b/src/ts/pklLspDistribution.ts @@ -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"; @@ -65,7 +65,7 @@ export const bundledDistribution: LspDistribution = { const getLspVersion = async (jarPath: string): Promise => { 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 ") diff --git a/src/ts/utils.ts b/src/ts/utils.ts index 6a401d6..533c7c5 100644 --- a/src/ts/utils.ts +++ b/src/ts/utils.ts @@ -15,7 +15,7 @@ //===----------------------------------------------------------------------===// 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"; @@ -23,7 +23,7 @@ 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 = ( f: (...args: A) => any,