From 87f213b1dbaa3c647a34dbb98fcc82aae8c2879c Mon Sep 17 00:00:00 2001 From: Ross Light Date: Fri, 31 Jul 2020 06:50:25 -0700 Subject: [PATCH] Add option to run yb under WSL Fixes #1 [ch1741] --- CHANGELOG.md | 6 ++++++ package.json | 6 ++++++ src/ybTaskProvider.ts | 18 +++++++++++++++++- 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6da4aeb..823a398 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 [Unreleased]: https://github.com/yourbase/yourbase-vscode/compare/v0.2.2...HEAD +### Added + +- Added option to run `yb` under WSL ([#1][]) + +[#1]: https://github.com/yourbase/yourbase-vscode/issues/1 + ### Fixed - Update elliptic to address [CVE-2020-13822][]. diff --git a/package.json b/package.json index 2dc308a..578487a 100644 --- a/package.json +++ b/package.json @@ -38,6 +38,12 @@ "default": false, "description": "Run builds on the YourBase service. Must log in using `yb login` first.", "scope": "resource" + }, + "yourbase.useWSL": { + "type": "boolean", + "default": false, + "description": "Use WSL to start a build. Only used on Windows.", + "scope": "machine" } } }, diff --git a/src/ybTaskProvider.ts b/src/ybTaskProvider.ts index 64246f1..0d986ec 100644 --- a/src/ybTaskProvider.ts +++ b/src/ybTaskProvider.ts @@ -1,5 +1,6 @@ import * as fs from 'fs'; import * as path from 'path'; +import * as process from 'process'; import * as vscode from 'vscode'; import * as yaml from 'yaml'; @@ -146,10 +147,25 @@ function workspaceUsesRemoteBuilds(folder: vscode.WorkspaceFolder): boolean { return vscode.workspace.getConfiguration(configSection, folder).get('remoteBuild', false); } +function useWsl(): boolean { + return process.platform === 'win32' && + vscode.workspace.getConfiguration(configSection).get('useWSL', false); +} + /** Return the invocation for a task. */ function taskExecution(definition: YbTaskDefinition, remote: boolean): vscode.ProcessExecution { + let process: string; + let args: string[]; + if (!useWsl()) { + process = 'yb'; + args = []; + } else { + process = 'wsl'; + args = ['yb']; + } const subcmd = remote ? 'remotebuild' : 'build'; - return new vscode.ProcessExecution('yb', [subcmd, '--', definition.target]); + args.push(subcmd, '--', definition.target); + return new vscode.ProcessExecution(process, args); } /** YAML definition of a build target. */