From 326dfd1e76eb31eda0cd9035d68f8fb88cd1d2e5 Mon Sep 17 00:00:00 2001 From: Shivam Mathur Date: Wed, 5 Feb 2020 20:58:44 +0530 Subject: [PATCH] Add support for old PHP versions on darwin --- __tests__/extensions.test.ts | 9 +++ dist/index.js | 8 ++- package-lock.json | 44 +++++++-------- package.json | 6 +- src/extensions.ts | 8 ++- src/scripts/darwin.sh | 106 +++++++++++++++++++++++++++-------- 6 files changed, 132 insertions(+), 49 deletions(-) diff --git a/__tests__/extensions.test.ts b/__tests__/extensions.test.ts index e83efbf7..e1191c0b 100644 --- a/__tests__/extensions.test.ts +++ b/__tests__/extensions.test.ts @@ -84,6 +84,15 @@ describe('Extension tests', () => { darwin = await extensions.addExtension('pcov', '7.2', 'darwin'); expect(darwin).toContain('sudo pecl install -f pcov'); + darwin = await extensions.addExtension('xdebug', '5.3', 'darwin'); + expect(darwin).toContain('sudo pecl install -f xdebug-2.2.7'); + + darwin = await extensions.addExtension('xdebug', '5.4', 'darwin'); + expect(darwin).toContain('sudo pecl install -f xdebug-2.4.1'); + + darwin = await extensions.addExtension('xdebug', '5.5', 'darwin'); + expect(darwin).toContain('sudo pecl install -f xdebug-2.5.5'); + darwin = await extensions.addExtension('xdebug', '5.6', 'darwin'); expect(darwin).toContain('sudo pecl install -f xdebug-2.5.5'); diff --git a/dist/index.js b/dist/index.js index 5525fcea..dc3d507f 100644 --- a/dist/index.js +++ b/dist/index.js @@ -2663,7 +2663,13 @@ function addExtensionDarwin(extension_csv, version, pipe) { ' ' + prefix; return; - case /5\.6xdebug/.test(version_extension): + case /5\.3xdebug/.test(version_extension): + install_command = 'sudo pecl install -f xdebug-2.2.7' + pipe; + break; + case /5\.4xdebug/.test(version_extension): + install_command = 'sudo pecl install -f xdebug-2.4.1' + pipe; + break; + case /5\.[5-6]xdebug/.test(version_extension): install_command = 'sudo pecl install -f xdebug-2.5.5' + pipe; break; case /7\.0xdebug/.test(version_extension): diff --git a/package-lock.json b/package-lock.json index 860ea479..d8710f6b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -711,12 +711,12 @@ "dev": true }, "@typescript-eslint/eslint-plugin": { - "version": "2.18.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-2.18.0.tgz", - "integrity": "sha512-kuO8WQjV+RCZvAXVRJfXWiJ8iYEtfHlKgcqqqXg9uUkIolEHuUaMmm8/lcO4xwCOtaw6mY0gStn2Lg4/eUXXYQ==", + "version": "2.19.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-2.19.0.tgz", + "integrity": "sha512-u7IcQ9qwsB6U806LupZmINRnQjC+RJyv36sV/ugaFWMHTbFm/hlLTRx3gGYJgHisxcGSTnf+I/fPDieRMhPSQQ==", "dev": true, "requires": { - "@typescript-eslint/experimental-utils": "2.18.0", + "@typescript-eslint/experimental-utils": "2.19.0", "eslint-utils": "^1.4.3", "functional-red-black-tree": "^1.0.1", "regexpp": "^3.0.0", @@ -724,32 +724,32 @@ } }, "@typescript-eslint/experimental-utils": { - "version": "2.18.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/experimental-utils/-/experimental-utils-2.18.0.tgz", - "integrity": "sha512-J6MopKPHuJYmQUkANLip7g9I82ZLe1naCbxZZW3O2sIxTiq/9YYoOELEKY7oPg0hJ0V/AQ225h2z0Yp+RRMXhw==", + "version": "2.19.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/experimental-utils/-/experimental-utils-2.19.0.tgz", + "integrity": "sha512-zwpg6zEOPbhB3+GaQfufzlMUOO6GXCNZq6skk+b2ZkZAIoBhVoanWK255BS1g5x9bMwHpLhX0Rpn5Fc3NdCZdg==", "dev": true, "requires": { "@types/json-schema": "^7.0.3", - "@typescript-eslint/typescript-estree": "2.18.0", + "@typescript-eslint/typescript-estree": "2.19.0", "eslint-scope": "^5.0.0" } }, "@typescript-eslint/parser": { - "version": "2.18.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-2.18.0.tgz", - "integrity": "sha512-SJJPxFMEYEWkM6pGfcnjLU+NJIPo+Ko1QrCBL+i0+zV30ggLD90huEmMMhKLHBpESWy9lVEeWlQibweNQzyc+A==", + "version": "2.19.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-2.19.0.tgz", + "integrity": "sha512-s0jZoxAWjHnuidbbN7aA+BFVXn4TCcxEVGPV8lWMxZglSs3NRnFFAlL+aIENNmzB2/1jUJuySi6GiM6uACPmpg==", "dev": true, "requires": { "@types/eslint-visitor-keys": "^1.0.0", - "@typescript-eslint/experimental-utils": "2.18.0", - "@typescript-eslint/typescript-estree": "2.18.0", + "@typescript-eslint/experimental-utils": "2.19.0", + "@typescript-eslint/typescript-estree": "2.19.0", "eslint-visitor-keys": "^1.1.0" } }, "@typescript-eslint/typescript-estree": { - "version": "2.18.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-2.18.0.tgz", - "integrity": "sha512-gVHylf7FDb8VSi2ypFuEL3hOtoC4HkZZ5dOjXvVjoyKdRrvXAOPSzpNRnKMfaUUEiSLP8UF9j9X9EDLxC0lfZg==", + "version": "2.19.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-2.19.0.tgz", + "integrity": "sha512-n6/Xa37k0jQdwpUszffi19AlNbVCR0sdvCs3DmSKMD7wBttKY31lhD2fug5kMD91B2qW4mQldaTEc1PEzvGu8w==", "dev": true, "requires": { "debug": "^4.1.1", @@ -3036,9 +3036,9 @@ "dev": true }, "istanbul-lib-instrument": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/istanbul-lib-instrument/-/istanbul-lib-instrument-4.0.0.tgz", - "integrity": "sha512-Nm4wVHdo7ZXSG30KjZ2Wl5SU/Bw7bDx1PdaiIFzEStdjs0H12mOTncn1GVYuqQSaZxpg87VGBRsVRPGD2cD1AQ==", + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/istanbul-lib-instrument/-/istanbul-lib-instrument-4.0.1.tgz", + "integrity": "sha512-imIchxnodll7pvQBYOqUu88EufLCU56LMeFPZZM/fJZ1irYcYdqroaV+ACK1Ila8ls09iEYArp+nqyC6lW1Vfg==", "dev": true, "requires": { "@babel/core": "^7.7.5", @@ -5524,9 +5524,9 @@ } }, "ts-jest": { - "version": "25.1.0", - "resolved": "https://registry.npmjs.org/ts-jest/-/ts-jest-25.1.0.tgz", - "integrity": "sha512-1Lf576ulKhbxX5og+tG8udVg/5cgcMLPBxp1iCqbbf6VvUK4gEsgAtzMjl8u98izhLrzKMPB0LxCBKEZ5l19Hw==", + "version": "25.2.0", + "resolved": "https://registry.npmjs.org/ts-jest/-/ts-jest-25.2.0.tgz", + "integrity": "sha512-VaRdb0da46eorLfuHEFf0G3d+jeREcV+Wb/SvW71S4y9Oe8SHWU+m1WY/3RaMknrBsnvmVH0/rRjT8dkgeffNQ==", "dev": true, "requires": { "bs-logger": "0.x", diff --git a/package.json b/package.json index 1ffed5cb..8bdd36c0 100644 --- a/package.json +++ b/package.json @@ -32,8 +32,8 @@ "devDependencies": { "@types/jest": "^25.1.1", "@types/node": "^13.7.0", - "@typescript-eslint/eslint-plugin": "^2.18.0", - "@typescript-eslint/parser": "^2.18.0", + "@typescript-eslint/eslint-plugin": "^2.19.0", + "@typescript-eslint/parser": "^2.19.0", "@zeit/ncc": "^0.21.0", "eslint": "^6.8.0", "eslint-config-prettier": "^6.10.0", @@ -44,7 +44,7 @@ "jest": "^25.1.0", "jest-circus": "^25.1.0", "prettier": "^1.19.1", - "ts-jest": "^25.1.0", + "ts-jest": "^25.2.0", "typescript": "^3.7.5" }, "husky": { diff --git a/src/extensions.ts b/src/extensions.ts index 86cb4144..246c8f82 100644 --- a/src/extensions.ts +++ b/src/extensions.ts @@ -32,7 +32,13 @@ export async function addExtensionDarwin( ' ' + prefix; return; - case /5\.6xdebug/.test(version_extension): + case /5\.3xdebug/.test(version_extension): + install_command = 'sudo pecl install -f xdebug-2.2.7' + pipe; + break; + case /5\.4xdebug/.test(version_extension): + install_command = 'sudo pecl install -f xdebug-2.4.1' + pipe; + break; + case /5\.[5-6]xdebug/.test(version_extension): install_command = 'sudo pecl install -f xdebug-2.5.5' + pipe; break; case /7\.0xdebug/.test(version_extension): diff --git a/src/scripts/darwin.sh b/src/scripts/darwin.sh index d2972565..9f88a97b 100644 --- a/src/scripts/darwin.sh +++ b/src/scripts/darwin.sh @@ -29,12 +29,18 @@ add_extension() { install_command=$2 prefix=$3 if ! php -m | grep -i -q -w "$extension" && [ -e "$ext_dir/$extension.so" ]; then - echo "$prefix=$extension" >>"$ini_file" && add_log "$tick" "$extension" "Enabled" + echo "$prefix=$ext_dir/$extension.so" >>"$ini_file" && add_log "$tick" "$extension" "Enabled" elif php -m | grep -i -q -w "$extension"; then add_log "$tick" "$extension" "Enabled" elif ! php -m | grep -i -q -w "$extension"; then - (eval "$install_command" >/dev/null 2>&1 && add_log "$tick" "$extension" "Installed and enabled") || - add_log "$cross" "$extension" "Could not install $extension on PHP $semver" + if [[ "$version" =~ $old_versions ]]; then + (eval "$install_command" >/dev/null 2>&1 && echo "$prefix=$ext_dir/$extension.so" >>"$ini_file" && add_log "$tick" "$extension" "Installed and enabled") || + (sudo port install php"$nodot_version"-"$extension" >/dev/null 2>&1 && add_log "$tick" "$extension" "Installed and enabled") || + add_log "$cross" "$extension" "Could not install $extension on PHP $semver" + else + (eval "$install_command" >/dev/null 2>&1 && add_log "$tick" "$extension" "Installed and enabled") || + add_log "$cross" "$extension" "Could not install $extension on PHP $semver" + fi fi } @@ -101,7 +107,7 @@ add_tool() { add_extension xml >/dev/null 2>&1 elif [ "$tool" = "cs2pr" ]; then sudo sed -i '' 's/exit(9)/exit(0)/' "$tool_path" - tr -d '\r' < "$tool_path" | sudo tee "$tool_path" >/dev/null 2>&1 + tr -d '\r' < "$tool_path" | sudo tee "$tool_path.tmp" >/dev/null 2>&1 && sudo mv "$tool_path.tmp" "$tool_path" fi add_log "$tick" "$tool" "Added" else @@ -124,11 +130,13 @@ add_composer_tool() { # Function to configure PECL configure_pecl() { - for tool in pear pecl; do - sudo "$tool" config-set php_ini "$ini_file" >/dev/null 2>&1 - sudo "$tool" config-set auto_discover 1 >/dev/null 2>&1 - sudo "$tool" channel-update "$tool".php.net >/dev/null 2>&1 - done + if [[ ! "$version" =~ $old_versions ]]; then + for tool in pear pecl; do + sudo "$tool" config-set php_ini "$ini_file" >/dev/null 2>&1 + sudo "$tool" config-set auto_discover 1 >/dev/null 2>&1 + sudo "$tool" channel-update "$tool".php.net >/dev/null 2>&1 + done + fi } # Function to log PECL, it is installed along with PHP @@ -136,27 +144,81 @@ add_pecl() { add_log "$tick" "PECL" "Added" } -# Function to setup PHP and composer -setup_php_and_composer() { - export HOMEBREW_NO_INSTALL_CLEANUP=TRUE - brew tap shivammathur/homebrew-php >/dev/null 2>&1 - brew install shivammathur/php/php@"$version" >/dev/null 2>&1 - brew link --force --overwrite php@"$version" >/dev/null 2>&1 +# Function to add PECL when macports is used +add_pecl_old() { + pecl_version='master' + if [ "$1" = "53" ]; then + pecl_version='v1.9.5' + fi + curl -o pear.phar -sSL https://github.com/pear/pearweb_phars/raw/$pecl_version/install-pear-nozlib.phar + sudo php pear.phar -d /opt/local/lib/php$1 -b /usr/local/bin && rm -rf pear.phar +} + +add_macports() { + uri=$(curl -sSL https://github.com/macports/macports-base/releases | grep -Eo "(\/.*Catalina.pkg)" | head -n 1) + curl -o port.pkg -sSL https://github.com"$uri" + sudo installer -pkg port.pkg -target / && rm -rf port.pkg +} + +sync_macports() { + while true; do + status=0 + sudo port sync || status=$? + if [[ "$status" -eq 0 ]]; then + break + fi + sleep 2 + done +} + +port_setup_php() { + sudo port install php$1 php$1-curl php$1-mbstring php$1-xmlrpc php$1-openssl php$1-opcache + sudo cp /opt/local/etc/php$1/php.ini-development /opt/local/etc/php$1/php.ini + sudo port select --set php php$1 + sudo ln -sf /opt/local/bin/* /usr/local/bin + add_pecl_old "$1" +} + +# Function to setup PHP +setup_php() { + if [[ "$version" =~ $old_versions ]]; then + step_log "Setup Macports" + add_macports >/dev/null 2>&1 + add_log "$tick" "Macports" "Installed" + sync_macports >/dev/null 2>&1 + add_log "$tick" "Macports" "Synced" + + step_log "Setup PHP" + port_setup_php $nodot_version >/dev/null 2>&1 + else + step_log "Setup PHP" + export HOMEBREW_NO_INSTALL_CLEANUP=TRUE >/dev/null 2>&1 + brew tap shivammathur/homebrew-php >/dev/null 2>&1 + brew install shivammathur/php/php@"$version" >/dev/null 2>&1 + brew link --force --overwrite php@"$version" >/dev/null 2>&1 + fi } # Variables tick="✓" cross="✗" version=$1 +nodot_version=${1/./} +old_versions="5.[3-5]" -# Setup PHP and composer -step_log "Setup PHP" -setup_php_and_composer +# Setup Environment +if [[ "$version" =~ $old_versions ]]; then + export PATH="/opt/local/bin:/opt/local/sbin:$PATH" + export TERM=xterm +fi + +# Setup PHP +setup_php ini_file=$(php -d "date.timezone=UTC" --ini | grep "Loaded Configuration" | sed -e "s|.*:s*||" | sed "s/ //g") -echo "date.timezone=UTC" >>"$ini_file" -ext_dir=$(php -i | grep "extension_dir => /usr" | sed -e "s|.*=> s*||") sudo chmod 777 "$ini_file" -mkdir -p "$(pecl config-get ext_dir)" +echo "date.timezone=UTC" >>"$ini_file" +ext_dir=$(php -i | grep -Ei "extension_dir => /(usr|opt)" | sed -e "s|.*=> s*||") +sudo mkdir -p "$ext_dir" semver=$(php -v | head -n 1 | cut -f 2 -d ' ') -add_log "$tick" "PHP" "Installed PHP $semver" configure_pecl +add_log "$tick" "PHP" "Installed PHP $semver" \ No newline at end of file