From d64a537618ecc2369c422daf3144377cb505c851 Mon Sep 17 00:00:00 2001 From: Christopher Campanale Date: Mon, 8 Jun 2020 17:14:34 -0500 Subject: [PATCH] feat: adds support for WSL (#107) - adds is-wsl module as dependency - adds additional 'wsl' string literal to PlatformTypes - uses module to supplement os.platform() logic to account for possible WSL host --- package.json | 1 + src/config.ts | 6 ++++-- yarn.lock | 12 ++++++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 2ec9c8de..08c64273 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,7 @@ "@oclif/parser": "^3.8.0", "debug": "^4.1.1", "globby": "^9.2.0", + "is-wsl": "^2.1.1", "tslib": "^1.9.3" }, "devDependencies": { diff --git a/src/config.ts b/src/config.ts index 3122a2cf..900bfdba 100644 --- a/src/config.ts +++ b/src/config.ts @@ -14,7 +14,7 @@ import {Topic} from './topic' import {tsPath} from './ts-node' import {compact, flatMap, loadJSON, uniq} from './util' -export type PlatformTypes = 'darwin' | 'linux' | 'win32' | 'aix' | 'freebsd' | 'openbsd' | 'sunos' +export type PlatformTypes = 'darwin' | 'linux' | 'win32' | 'aix' | 'freebsd' | 'openbsd' | 'sunos' | 'wsl' export type ArchTypes = 'arm' | 'arm64' | 'mips' | 'mipsel' | 'ppc' | 'ppc64' | 's390' | 's390x' | 'x32' | 'x64' | 'x86' export interface Options extends Plugin.Options { devPlugins?: boolean; @@ -151,6 +151,8 @@ function hasManifest(p: string): boolean { } } +const WSL = require('is-wsl') + export class Config implements IConfig { _base = `${_pjson.name}@${_pjson.version}` @@ -218,7 +220,7 @@ export class Config implements IConfig { this.valid = plugin.valid this.arch = (os.arch() === 'ia32' ? 'x86' : os.arch() as any) - this.platform = os.platform() as any + this.platform = WSL ? 'wsl' : os.platform() as any this.windows = this.platform === 'win32' this.bin = this.pjson.oclif.bin || this.name this.dirname = this.pjson.oclif.dirname || this.name diff --git a/yarn.lock b/yarn.lock index 34b1be6d..4d86f9a8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1708,6 +1708,11 @@ is-descriptor@^1.0.0, is-descriptor@^1.0.2: is-data-descriptor "^1.0.0" kind-of "^6.0.2" +is-docker@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/is-docker/-/is-docker-2.0.0.tgz#2cb0df0e75e2d064fe1864c37cdeacb7b2dcf25b" + integrity sha512-pJEdRugimx4fBMra5z2/5iRdZ63OhYV0vr0Dwm5+xtW4D1FvRkB8hamMIhnWfyJeDdyr/aa7BDyNbtG38VxgoQ== + is-extendable@^0.1.0, is-extendable@^0.1.1: version "0.1.1" resolved "https://registry.yarnpkg.com/is-extendable/-/is-extendable-0.1.1.tgz#62b110e289a471418e3ec36a617d472e301dfc89" @@ -1833,6 +1838,13 @@ is-windows@^1.0.2: resolved "https://registry.yarnpkg.com/is-windows/-/is-windows-1.0.2.tgz#d1850eb9791ecd18e6182ce12a30f396634bb19d" integrity sha512-eXK1UInq2bPmjyX6e3VHIzMLobc4J94i4AWn+Hpq3OU5KkrRC96OAcR3PRJ/pGu6m8TRnBHP9dkXQVsT/COVIA== +is-wsl@^2.1.1: + version "2.2.0" + resolved "https://registry.yarnpkg.com/is-wsl/-/is-wsl-2.2.0.tgz#74a4c76e77ca9fd3f932f290c17ea326cd157271" + integrity sha512-fKzAra0rGJUUBwGBgNkHZuToZcn+TtXHpeCgmkMJMMYx1sQDYaCSyjJBSCa2nH1DGm7s3n1oBnohoVTBaN7Lww== + dependencies: + is-docker "^2.0.0" + isarray@1.0.0, isarray@~1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/isarray/-/isarray-1.0.0.tgz#bb935d48582cba168c06834957a54a3e07124f11"