Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ import {promisify} from 'util'

import path = require('path')
import isWindows = require('is-windows')
const isCygwin = () => isWindows() && (process.env.TERM === 'CYGWIN' || process.env.MSYSTEM !== undefined)
import CMD_EXTENSION = require('cmd-extension')
const shebangExpr = /^#!\s*(?:\/usr\/bin\/env(?:\s+-S\s*)?)?\s*([^ \t]+)(.*)$/
const DEFAULT_OPTIONS = {
Expand Down Expand Up @@ -437,7 +438,11 @@ function generateShShim (src: string, to: string, opts: InternalOptions): string
// basedir=`dirname "$0"`
//
// case `uname` in
// *CYGWIN*) basedir=`cygpath -w "$basedir"`;;
// *CYGWIN*|*MINGW*|*MSYS*)
// if command -v cygpath > /dev/null 2>&1; then
// basedir=`cygpath -w "$basedir"`
// fi
// ;;
// esac
//
// export NODE_PATH="<nodepath>"
Expand All @@ -453,7 +458,11 @@ function generateShShim (src: string, to: string, opts: InternalOptions): string
basedir=$(dirname "$(echo "$0" | sed -e 's,\\\\,/,g')")

case \`uname\` in
*CYGWIN*) basedir=\`cygpath -w "$basedir"\`;;
*CYGWIN*|*MINGW*|*MSYS*)
if command -v cygpath > /dev/null 2>&1; then
basedir=\`cygpath -w "$basedir"\`
fi
;;
esac

`
Expand Down Expand Up @@ -663,7 +672,7 @@ function normalizePathEnvVar (nodePath: undefined | string | string[]): Normaliz
let result = {} as NormalizedPathEnvVar
for (let i = 0; i < split.length; i++) {
const win32 = split[i].split('/').join('\\')
const posix = isWindows() ? split[i].split('\\').join('/').replace(/^([^:\\/]*):/, (_, $1) => `/mnt/${$1.toLowerCase()}`) : split[i]
const posix = isWindows() ? split[i].split('\\').join('/').replace(/^([^:\\/]*):/, (_, $1) => `${isCygwin() ? '/proc/cygdrive' : '/mnt'}/${$1.toLowerCase()}`) : split[i]

result.win32 = result.win32 ? `${result.win32};${win32}` : win32
result.posix = result.posix ? `${result.posix}:${posix}` : posix
Expand Down
6 changes: 5 additions & 1 deletion test/__snapshots__/e2e.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ exports[`create a command shim for a .exe file 1`] = `
basedir=$(dirname "$(echo "$0" | sed -e 's,\\\\,/,g')")

case \`uname\` in
*CYGWIN*) basedir=\`cygpath -w "$basedir"\`;;
*CYGWIN*|*MINGW*|*MSYS*)
if command -v cygpath > /dev/null 2>&1; then
basedir=\`cygpath -w "$basedir"\`
fi
;;
esac

"$basedir/foo" "$@"
Expand Down
84 changes: 70 additions & 14 deletions test/__snapshots__/test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ exports[`custom node executable env.shim 1`] = `
basedir=$(dirname "$(echo "$0" | sed -e 's,\\\\,/,g')")

case \`uname\` in
*CYGWIN*) basedir=\`cygpath -w "$basedir"\`;;
*CYGWIN*|*MINGW*|*MSYS*)
if command -v cygpath > /dev/null 2>&1; then
basedir=\`cygpath -w "$basedir"\`
fi
;;
esac

"/.pnpm/nodejs/16.0.0/node" "$basedir/src.env" "$@"
Expand Down Expand Up @@ -44,7 +48,11 @@ exports[`env shebang env.shim 1`] = `
basedir=$(dirname "$(echo "$0" | sed -e 's,\\\\,/,g')")

case \`uname\` in
*CYGWIN*) basedir=\`cygpath -w "$basedir"\`;;
*CYGWIN*|*MINGW*|*MSYS*)
if command -v cygpath > /dev/null 2>&1; then
basedir=\`cygpath -w "$basedir"\`
fi
;;
esac

if [ -x "$basedir/node" ]; then
Expand Down Expand Up @@ -103,7 +111,11 @@ exports[`env shebang with NODE_PATH env.shim 1`] = `
basedir=$(dirname "$(echo "$0" | sed -e 's,\\\\,/,g')")

case \`uname\` in
*CYGWIN*) basedir=\`cygpath -w "$basedir"\`;;
*CYGWIN*|*MINGW*|*MSYS*)
if command -v cygpath > /dev/null 2>&1; then
basedir=\`cygpath -w "$basedir"\`
fi
;;
esac

if [ -z "$NODE_PATH" ]; then
Expand Down Expand Up @@ -185,7 +197,11 @@ exports[`env shebang with PATH extending env.shim 1`] = `
basedir=$(dirname "$(echo "$0" | sed -e 's,\\\\,/,g')")

case \`uname\` in
*CYGWIN*) basedir=\`cygpath -w "$basedir"\`;;
*CYGWIN*|*MINGW*|*MSYS*)
if command -v cygpath > /dev/null 2>&1; then
basedir=\`cygpath -w "$basedir"\`
fi
;;
esac

export PATH="/add-to-path:$PATH"
Expand Down Expand Up @@ -256,7 +272,11 @@ exports[`env shebang with args env.args.shim 1`] = `
basedir=$(dirname "$(echo "$0" | sed -e 's,\\\\,/,g')")

case \`uname\` in
*CYGWIN*) basedir=\`cygpath -w "$basedir"\`;;
*CYGWIN*|*MINGW*|*MSYS*)
if command -v cygpath > /dev/null 2>&1; then
basedir=\`cygpath -w "$basedir"\`
fi
;;
esac

if [ -x "$basedir/node" ]; then
Expand Down Expand Up @@ -315,7 +335,11 @@ exports[`env shebang with default args env.shim 1`] = `
basedir=$(dirname "$(echo "$0" | sed -e 's,\\\\,/,g')")

case \`uname\` in
*CYGWIN*) basedir=\`cygpath -w "$basedir"\`;;
*CYGWIN*|*MINGW*|*MSYS*)
if command -v cygpath > /dev/null 2>&1; then
basedir=\`cygpath -w "$basedir"\`
fi
;;
esac

if [ -x "$basedir/node" ]; then
Expand Down Expand Up @@ -374,7 +398,11 @@ exports[`env shebang with no NODE_PATH env.shim 1`] = `
basedir=$(dirname "$(echo "$0" | sed -e 's,\\\\,/,g')")

case \`uname\` in
*CYGWIN*) basedir=\`cygpath -w "$basedir"\`;;
*CYGWIN*|*MINGW*|*MSYS*)
if command -v cygpath > /dev/null 2>&1; then
basedir=\`cygpath -w "$basedir"\`
fi
;;
esac

if [ -x "$basedir/node" ]; then
Expand Down Expand Up @@ -433,7 +461,11 @@ exports[`explicit shebang sh.shim 1`] = `
basedir=$(dirname "$(echo "$0" | sed -e 's,\\\\,/,g')")

case \`uname\` in
*CYGWIN*) basedir=\`cygpath -w "$basedir"\`;;
*CYGWIN*|*MINGW*|*MSYS*)
if command -v cygpath > /dev/null 2>&1; then
basedir=\`cygpath -w "$basedir"\`
fi
;;
esac

if [ -x "$basedir//usr/bin/sh" ]; then
Expand Down Expand Up @@ -492,7 +524,11 @@ exports[`explicit shebang with args sh.args.shim 1`] = `
basedir=$(dirname "$(echo "$0" | sed -e 's,\\\\,/,g')")

case \`uname\` in
*CYGWIN*) basedir=\`cygpath -w "$basedir"\`;;
*CYGWIN*|*MINGW*|*MSYS*)
if command -v cygpath > /dev/null 2>&1; then
basedir=\`cygpath -w "$basedir"\`
fi
;;
esac

if [ -x "$basedir//usr/bin/sh" ]; then
Expand Down Expand Up @@ -551,7 +587,11 @@ exports[`explicit shebang with args, linking to another drive on Windows sh.args
basedir=$(dirname "$(echo "$0" | sed -e 's,\\\\,/,g')")

case \`uname\` in
*CYGWIN*) basedir=\`cygpath -w "$basedir"\`;;
*CYGWIN*|*MINGW*|*MSYS*)
if command -v cygpath > /dev/null 2>&1; then
basedir=\`cygpath -w "$basedir"\`
fi
;;
esac

if [ -x "$basedir//usr/bin/sh" ]; then
Expand Down Expand Up @@ -610,7 +650,11 @@ exports[`explicit shebang with prog args sh.args.shim 1`] = `
basedir=$(dirname "$(echo "$0" | sed -e 's,\\\\,/,g')")

case \`uname\` in
*CYGWIN*) basedir=\`cygpath -w "$basedir"\`;;
*CYGWIN*|*MINGW*|*MSYS*)
if command -v cygpath > /dev/null 2>&1; then
basedir=\`cygpath -w "$basedir"\`
fi
;;
esac

if [ -x "$basedir//usr/bin/sh" ]; then
Expand Down Expand Up @@ -669,7 +713,11 @@ exports[`no cmd file exe.shim 1`] = `
basedir=$(dirname "$(echo "$0" | sed -e 's,\\\\,/,g')")

case \`uname\` in
*CYGWIN*) basedir=\`cygpath -w "$basedir"\`;;
*CYGWIN*|*MINGW*|*MSYS*)
if command -v cygpath > /dev/null 2>&1; then
basedir=\`cygpath -w "$basedir"\`
fi
;;
esac

"$basedir/src.exe" "$@"
Expand Down Expand Up @@ -702,7 +750,11 @@ exports[`no shebang exe.shim 1`] = `
basedir=$(dirname "$(echo "$0" | sed -e 's,\\\\,/,g')")

case \`uname\` in
*CYGWIN*) basedir=\`cygpath -w "$basedir"\`;;
*CYGWIN*|*MINGW*|*MSYS*)
if command -v cygpath > /dev/null 2>&1; then
basedir=\`cygpath -w "$basedir"\`
fi
;;
esac

"$basedir/src.exe" "$@"
Expand Down Expand Up @@ -741,7 +793,11 @@ exports[`shebang with -S from.env.S.shim 1`] = `
basedir=$(dirname "$(echo "$0" | sed -e 's,\\\\,/,g')")

case \`uname\` in
*CYGWIN*) basedir=\`cygpath -w "$basedir"\`;;
*CYGWIN*|*MINGW*|*MSYS*)
if command -v cygpath > /dev/null 2>&1; then
basedir=\`cygpath -w "$basedir"\`
fi
;;
esac

if [ -x "$basedir/node" ]; then
Expand Down