|
1 | 1 | import { EOL } from "os"; |
2 | | -import os from 'os'; |
3 | 2 | import { execFileSync } from "child_process"; |
4 | 3 | import { PackageURL } from "packageurl-js"; |
5 | 4 |
|
@@ -75,24 +74,16 @@ export function environmentVariableIsPopulated(envVariableName) { |
75 | 74 | } |
76 | 75 |
|
77 | 76 | /** |
78 | | - * |
| 77 | + * Utility function for handling spaces in paths on Windows |
79 | 78 | * @param {string} path - path to be checked if contains spaces |
80 | 79 | * @return {string} a path with all spaces escaped or manipulated so it will be able to be part |
81 | 80 | * of commands that will be invoked without errors in os' shell. |
82 | 81 | */ |
83 | 82 | export function handleSpacesInPath(path) { |
84 | 83 | let transformedPath = path |
85 | 84 | // if operating system is windows |
86 | | - if (os.platform() === "win32") { |
87 | | - if(hasSpaces(path)) { |
88 | | - transformedPath = `"${path}"` |
89 | | - } |
90 | | - } |
91 | | - // linux, darwin.. |
92 | | - else { |
93 | | - if(hasSpaces(path)) { |
94 | | - transformedPath = path.replaceAll(" ", "\\ ") |
95 | | - } |
| 85 | + if(hasSpaces(path)) { |
| 86 | + transformedPath = `"${path}"` |
96 | 87 | } |
97 | 88 | return transformedPath |
98 | 89 | } |
@@ -161,10 +152,9 @@ export function invokeCommand(bin, args, opts={}) { |
161 | 152 | // https://github.com/nodejs/node/issues/52681#issuecomment-2076426887 |
162 | 153 | if (process.platform === 'win32') { |
163 | 154 | opts = {...opts, shell: true} |
| 155 | + args = args.map(arg => handleSpacesInPath(arg)) |
| 156 | + bin = handleSpacesInPath(bin) |
164 | 157 | } |
165 | | - // Handle spaces in paths for all platforms |
166 | | - args = args.map(arg => handleSpacesInPath(arg)) |
167 | | - bin = handleSpacesInPath(bin) |
168 | 158 |
|
169 | 159 | opts = { |
170 | 160 | ...opts, |
|
0 commit comments