Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: error invalid arg type on WSL systems on url open #118

Closed
27 changes: 22 additions & 5 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,11 @@
}
realArgs.push('/d', '/s', '/c', script)
options.windowsVerbatimArguments = true
} else {
} else if(opts.isWSL) {

Check failure on line 117 in lib/index.js

View workflow job for this annotation

GitHub Actions / Lint

Expected space(s) after "if"
//handling for WSL

Check failure on line 118 in lib/index.js

View workflow job for this annotation

GitHub Actions / Lint

Expected space or tab after '//' in comment
script = `${cmd} ${args.join(' ')}`

Check failure on line 119 in lib/index.js

View workflow job for this annotation

GitHub Actions / Lint

Expected indentation of 4 spaces but found 6
realArgs = ['-Command', script]

Check failure on line 120 in lib/index.js

View workflow job for this annotation

GitHub Actions / Lint

Expected indentation of 4 spaces but found 6

Check failure on line 120 in lib/index.js

View workflow job for this annotation

GitHub Actions / Lint

'realArgs' is constant
Fixed Show fixed Hide fixed
}else {

Check failure on line 121 in lib/index.js

View workflow job for this annotation

GitHub Actions / Lint

Expected space(s) before "else"
for (const arg of args) {
script += ` ${escape.sh(arg)}`
}
Expand All @@ -126,16 +130,22 @@

// open a file with the default application as defined by the user's OS
const open = (_args, opts = {}, extra = {}) => {
const options = { ...opts, shell: true }
const args = [].concat(_args)

let platform = process.platform
let isWSL = false
// process.platform === 'linux' may actually indicate WSL, if that's the case
// we want to treat things as win32 anyway so the host can open the argument
if (platform === 'linux' && os.release().toLowerCase().includes('microsoft')) {
platform = 'win32'

if (platform === 'linux') {
const osRelease = os.release().toLowerCase()
if(osRelease.includes('microsoft') || osRelease.includes('wsl')){

Check failure on line 142 in lib/index.js

View workflow job for this annotation

GitHub Actions / Lint

Expected space(s) after "if"

Check failure on line 142 in lib/index.js

View workflow job for this annotation

GitHub Actions / Lint

Missing space before opening brace
platform = 'win32'
isWSL = true
}
}

const options = { ...opts, shell: true, isWSL }
let command = options.command
if (!command) {
if (platform === 'win32') {
Expand All @@ -145,7 +155,14 @@
// also, the start command accepts a title so to make sure that we don't
// accidentally interpret the first arg as the title, we stick an empty
// string immediately after the start command
command = 'start ""'
if(isWSL) {

Check failure on line 158 in lib/index.js

View workflow job for this annotation

GitHub Actions / Lint

Expected space(s) after "if"
//For WSL, use wslpath to convert the path if necessary

Check failure on line 159 in lib/index.js

View workflow job for this annotation

GitHub Actions / Lint

Expected space or tab after '//' in comment
command = 'powershell.exe -Command'
args.unshift('Start-Process')
args = args.map(arg => `"$(wslpath -w '${arg}')"`)

Check failure on line 162 in lib/index.js

View workflow job for this annotation

GitHub Actions / Test - Linux - 16.14.0

Assignment to constant variable.

Check failure on line 162 in lib/index.js

View workflow job for this annotation

GitHub Actions / Test - Linux - 16.14.0

Assignment to constant variable.

Check failure on line 162 in lib/index.js

View workflow job for this annotation

GitHub Actions / Test - macOS - 16.14.0

Assignment to constant variable.

Check failure on line 162 in lib/index.js

View workflow job for this annotation

GitHub Actions / Test - macOS - 16.14.0

Assignment to constant variable.

Check failure on line 162 in lib/index.js

View workflow job for this annotation

GitHub Actions / Test - Linux - 18.0.0

Assignment to constant variable.

Check failure on line 162 in lib/index.js

View workflow job for this annotation

GitHub Actions / Test - Linux - 18.0.0

Assignment to constant variable.

Check failure on line 162 in lib/index.js

View workflow job for this annotation

GitHub Actions / Test - macOS - 16.x

Assignment to constant variable.

Check failure on line 162 in lib/index.js

View workflow job for this annotation

GitHub Actions / Test - macOS - 16.x

Assignment to constant variable.

Check failure on line 162 in lib/index.js

View workflow job for this annotation

GitHub Actions / Test - Linux - 16.x

Assignment to constant variable.

Check failure on line 162 in lib/index.js

View workflow job for this annotation

GitHub Actions / Test - Linux - 16.x

Assignment to constant variable.

Check failure on line 162 in lib/index.js

View workflow job for this annotation

GitHub Actions / Test - macOS - 20.x

Assignment to constant variable.

Check failure on line 162 in lib/index.js

View workflow job for this annotation

GitHub Actions / Test - macOS - 20.x

Assignment to constant variable.

Check failure on line 162 in lib/index.js

View workflow job for this annotation

GitHub Actions / Test - macOS - 22.x

Assignment to constant variable.

Check failure on line 162 in lib/index.js

View workflow job for this annotation

GitHub Actions / Test - macOS - 22.x

Assignment to constant variable.

Check failure on line 162 in lib/index.js

View workflow job for this annotation

GitHub Actions / Test - Linux - 20.x

Assignment to constant variable.

Check failure on line 162 in lib/index.js

View workflow job for this annotation

GitHub Actions / Test - Linux - 20.x

Assignment to constant variable.

Check failure on line 162 in lib/index.js

View workflow job for this annotation

GitHub Actions / Test - macOS - 18.x

Assignment to constant variable.

Check failure on line 162 in lib/index.js

View workflow job for this annotation

GitHub Actions / Test - macOS - 18.x

Assignment to constant variable.

Check failure on line 162 in lib/index.js

View workflow job for this annotation

GitHub Actions / Test - macOS - 18.0.0

Assignment to constant variable.

Check failure on line 162 in lib/index.js

View workflow job for this annotation

GitHub Actions / Test - macOS - 18.0.0

Assignment to constant variable.

Check failure on line 162 in lib/index.js

View workflow job for this annotation

GitHub Actions / Test - Linux - 22.x

Assignment to constant variable.

Check failure on line 162 in lib/index.js

View workflow job for this annotation

GitHub Actions / Test - Linux - 22.x

Assignment to constant variable.

Check failure on line 162 in lib/index.js

View workflow job for this annotation

GitHub Actions / Test - Linux - 18.x

Assignment to constant variable.

Check failure on line 162 in lib/index.js

View workflow job for this annotation

GitHub Actions / Test - Linux - 18.x

Assignment to constant variable.
} else {
command = 'start ""'
}
} else if (platform === 'darwin') {
command = 'open'
} else {
Expand Down
Loading