* Escape values in a string template literal. On Windows, this function * does not escape anything (which is fine for paths, as `"` is not a valid char * in a path on Windows), so you should use it only to escape paths – or other * values on tests which are skipped on Windows. * This function is
(cmdParts, ...args)
| 908 | * arguments to `exec` or `execSync`. |
| 909 | */ |
| 910 | function escapePOSIXShell(cmdParts, ...args) { |
| 911 | if (common.isWindows) { |
| 912 | // On Windows, paths cannot contain `"`, so we can return the string unchanged. |
| 913 | return [String.raw({ raw: cmdParts }, ...args)]; |
| 914 | } |
| 915 | // On POSIX shells, we can pass values via the env, as there's a standard way for referencing a variable. |
| 916 | const env = { ...process.env }; |
| 917 | let cmd = cmdParts[0]; |
| 918 | for (let i = 0; i < args.length; i++) { |
| 919 | const envVarName = `ESCAPED_${i}`; |
| 920 | env[envVarName] = args[i]; |
| 921 | cmd += '${' + envVarName + '}' + cmdParts[i + 1]; |
| 922 | } |
| 923 | |
| 924 | return [cmd, { env }]; |
| 925 | }; |
| 926 | |
| 927 | /** |
| 928 | * Check the exports of require(esm). |
no test coverage detected
searching dependent graphs…