From 9f5e4530b9bf810fd871ad71bb9f0cb841791bae Mon Sep 17 00:00:00 2001 From: Gabriele Tomassetti Date: Thu, 22 Feb 2024 15:46:09 +0100 Subject: [PATCH 1/2] Adapt npm and npx to support Windows --- .../languageserver/plugin/LanguageServerPlugin.kt | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/plugin/src/main/kotlin/com/strumenta/kolasu/languageserver/plugin/LanguageServerPlugin.kt b/plugin/src/main/kotlin/com/strumenta/kolasu/languageserver/plugin/LanguageServerPlugin.kt index 0572ba7..cd33a8e 100644 --- a/plugin/src/main/kotlin/com/strumenta/kolasu/languageserver/plugin/LanguageServerPlugin.kt +++ b/plugin/src/main/kotlin/com/strumenta/kolasu/languageserver/plugin/LanguageServerPlugin.kt @@ -99,6 +99,9 @@ class LanguageServerPlugin : Plugin { } } + fun isWindows(): Boolean { + return System.getProperty("os.name").toLowerCase().contains("win") + } private fun createVscodeExtension(project: Project) { val shadowJar = project.tasks.getByName("shadowJar") as ShadowJar val entryPoint = shadowJar.manifest.attributes["Main-Class"] as String @@ -218,8 +221,11 @@ class LanguageServerPlugin : Plugin { Files.copy(configuration.serverJarPath, Paths.get(configuration.outputPath.toString(), "server.jar"), StandardCopyOption.REPLACE_EXISTING) - ProcessBuilder("npm", "install", "--prefix", "build", "vscode-languageclient").directory(project.projectDir).start().waitFor() - ProcessBuilder("npx", "esbuild", "build/vscode/client.js", "--bundle", "--external:vscode", "--format=cjs", "--platform=node", "--outfile=build/vscode/client.js", "--allow-overwrite").directory(project.projectDir).start().waitFor() + val npm = if(isWindows()) "npm.cmd" else "npm" + val npx = if(isWindows()) "npx.cmd" else "npx" + + ProcessBuilder(npm, "install", "--prefix", "build", "vscode-languageclient").directory(project.projectDir).start().waitFor() + ProcessBuilder(npx, "esbuild", "build/vscode/client.js", "--bundle", "--external:vscode", "--format=cjs", "--platform=node", "--outfile=build/vscode/client.js", "--allow-overwrite").directory(project.projectDir).start().waitFor() if (Files.exists(configuration.textmateGrammarPath)) { Files.copy(configuration.textmateGrammarPath, Paths.get(configuration.outputPath.toString(), "grammar.tmLanguage"), StandardCopyOption.REPLACE_EXISTING) @@ -241,6 +247,6 @@ class LanguageServerPlugin : Plugin { ProcessBuilder("curl", "https://repo1.maven.org/maven2/org/apache/lucene/lucene-core/9.8.0/lucene-core-9.8.0.jar", "-o", Paths.get(configuration.outputPath.toString(), "lucene-core-9.8.0.jar").toString()).start().waitFor() ProcessBuilder("curl", "https://repo1.maven.org/maven2/org/apache/lucene/lucene-codecs/9.8.0/lucene-codecs-9.8.0.jar", "-o", Paths.get(configuration.outputPath.toString(), "lucene-codecs-9.8.0.jar").toString()).start().waitFor() - ProcessBuilder("npx", "vsce@2.15", "package").directory(configuration.outputPath.toFile()).start().waitFor() + ProcessBuilder(npx, "vsce@2.15", "package").directory(configuration.outputPath.toFile()).start().waitFor() } } From f6bf6227f47aac0ca07f1eb5150fab539c7b2f4a Mon Sep 17 00:00:00 2001 From: Gabriele Tomassetti Date: Thu, 22 Feb 2024 16:33:34 +0100 Subject: [PATCH 2/2] Change npm build directory --- .../kolasu/languageserver/plugin/LanguageServerPlugin.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin/src/main/kotlin/com/strumenta/kolasu/languageserver/plugin/LanguageServerPlugin.kt b/plugin/src/main/kotlin/com/strumenta/kolasu/languageserver/plugin/LanguageServerPlugin.kt index cd33a8e..c4b74b9 100644 --- a/plugin/src/main/kotlin/com/strumenta/kolasu/languageserver/plugin/LanguageServerPlugin.kt +++ b/plugin/src/main/kotlin/com/strumenta/kolasu/languageserver/plugin/LanguageServerPlugin.kt @@ -202,7 +202,7 @@ class LanguageServerPlugin : Plugin { Files.writeString( Paths.get(configuration.outputPath.toString(), "client.js"), """ - let {LanguageClient} = require("../node_modules/vscode-languageclient/node"); + let {LanguageClient} = require("./node_modules/vscode-languageclient/node"); async function activate (context) { @@ -224,7 +224,7 @@ class LanguageServerPlugin : Plugin { val npm = if(isWindows()) "npm.cmd" else "npm" val npx = if(isWindows()) "npx.cmd" else "npx" - ProcessBuilder(npm, "install", "--prefix", "build", "vscode-languageclient").directory(project.projectDir).start().waitFor() + ProcessBuilder(npm, "install", "--prefix", "build/vscode/", "vscode-languageclient").directory(project.projectDir).start().waitFor() ProcessBuilder(npx, "esbuild", "build/vscode/client.js", "--bundle", "--external:vscode", "--format=cjs", "--platform=node", "--outfile=build/vscode/client.js", "--allow-overwrite").directory(project.projectDir).start().waitFor() if (Files.exists(configuration.textmateGrammarPath)) {