Improve regexes for pre-release extensions

This commit is contained in:
Shivam Mathur 2020-10-31 19:04:20 +05:30
parent 215b040f0d
commit 02445f719d
No known key found for this signature in database
GPG Key ID: 3E13E4C8591ACC2A
5 changed files with 12 additions and 13 deletions

View File

@ -3,7 +3,7 @@ import * as extensions from '../src/extensions';
describe('Extension tests', () => { describe('Extension tests', () => {
it('checking addExtensionOnWindows', async () => { it('checking addExtensionOnWindows', async () => {
let win32: string = await extensions.addExtension( let win32: string = await extensions.addExtension(
'Xdebug, pcov, sqlite, :intl, phalcon4, ioncube, oci8, pdo_oci, ast-beta, grpc-1.2.3, inotify-1.2.3alpha2', 'Xdebug, pcov, sqlite, :intl, phalcon4, ioncube, oci8, pdo_oci, ast-beta, grpc-1.2.3, inotify-1.2.3alpha2, sqlsrv-1.2.3preview1',
'7.4', '7.4',
'win32' 'win32'
); );
@ -18,6 +18,7 @@ describe('Extension tests', () => {
expect(win32).toContain('Add-Extension ast beta'); expect(win32).toContain('Add-Extension ast beta');
expect(win32).toContain('Add-Extension grpc stable 1.2.3'); expect(win32).toContain('Add-Extension grpc stable 1.2.3');
expect(win32).toContain('Add-Extension inotify alpha 1.2.3'); expect(win32).toContain('Add-Extension inotify alpha 1.2.3');
expect(win32).toContain('Add-Extension sqlsrv devel 1.2.3');
win32 = await extensions.addExtension('pcov', '5.6', 'win32'); win32 = await extensions.addExtension('pcov', '5.6', 'win32');
expect(win32).toContain( expect(win32).toContain(

6
dist/index.js vendored
View File

@ -2974,9 +2974,9 @@ async function addExtensionWindows(extension_csv, version) {
add_script += await utils.joins('\nAdd-Extension', ext_name, 'stable', ext_version); add_script += await utils.joins('\nAdd-Extension', ext_name, 'stable', ext_version);
break; break;
// match semver with state // match semver with state
case /.*-(\d+\.\d+\.\d)(beta|alpha|devel|snapshot)\d*/.test(version_extension): case /.*-(\d+\.\d+\.\d)([a-zA-Z+]+)\d*/.test(version_extension):
matches = /.*-(\d+\.\d+\.\d)(beta|alpha|devel|snapshot)\d*/.exec(version_extension); matches = /.*-(\d+\.\d+\.\d)([a-zA-Z+]+)\d*/.exec(version_extension);
add_script += await utils.joins('\nAdd-Extension', ext_name, matches[2], matches[1]); add_script += await utils.joins('\nAdd-Extension', ext_name, matches[2].replace('preview', 'devel'), matches[1]);
break; break;
// match 5.3pcov to 7.0pcov // match 5.3pcov to 7.0pcov
case /(5\.[3-6]|7\.0)pcov/.test(version_extension): case /(5\.[3-6]|7\.0)pcov/.test(version_extension):

View File

@ -164,16 +164,14 @@ export async function addExtensionWindows(
); );
break; break;
// match semver with state // match semver with state
case /.*-(\d+\.\d+\.\d)(beta|alpha|devel|snapshot)\d*/.test( case /.*-(\d+\.\d+\.\d)([a-zA-Z+]+)\d*/.test(version_extension):
version_extension matches = /.*-(\d+\.\d+\.\d)([a-zA-Z+]+)\d*/.exec(
):
matches = /.*-(\d+\.\d+\.\d)(beta|alpha|devel|snapshot)\d*/.exec(
version_extension version_extension
) as RegExpExecArray; ) as RegExpExecArray;
add_script += await utils.joins( add_script += await utils.joins(
'\nAdd-Extension', '\nAdd-Extension',
ext_name, ext_name,
matches[2], matches[2].replace('preview', 'devel'),
matches[1] matches[1]
); );
break; break;

View File

@ -71,7 +71,7 @@ check_extension() {
# Function to get the PECL version. # Function to get the PECL version.
get_pecl_version() { get_pecl_version() {
extension=$1 extension=$1
stability="$(echo "$2" | grep -m 1 -Eio "(alpha|beta|rc|snapshot)")" stability="$(echo "$2" | grep -m 1 -Eio "(alpha|beta|rc|snapshot|preview)")"
pecl_rest='https://pecl.php.net/rest/r/' pecl_rest='https://pecl.php.net/rest/r/'
response=$(curl "${curl_opts[@]}" "$pecl_rest$extension"/allreleases.xml) response=$(curl "${curl_opts[@]}" "$pecl_rest$extension"/allreleases.xml)
pecl_version=$(echo "$response" | grep -m 1 -Eio "(\d*\.\d*\.\d*$stability\d*)") pecl_version=$(echo "$response" | grep -m 1 -Eio "(\d*\.\d*\.\d*$stability\d*)")
@ -92,7 +92,7 @@ add_pecl_extension() {
extension=$1 extension=$1
pecl_version=$2 pecl_version=$2
prefix=$3 prefix=$3
if [[ $pecl_version =~ .*(alpha|beta|rc|snapshot).* ]]; then if [[ $pecl_version =~ .*(alpha|beta|rc|snapshot|preview).* ]]; then
pecl_version=$(get_pecl_version "$extension" "$pecl_version") pecl_version=$(get_pecl_version "$extension" "$pecl_version")
fi fi
if ! check_extension "$extension" && [ -e "$ext_dir/$extension.so" ]; then if ! check_extension "$extension" && [ -e "$ext_dir/$extension.so" ]; then

View File

@ -92,7 +92,7 @@ configure_pecl() {
# Function to get the PECL version of an extension. # Function to get the PECL version of an extension.
get_pecl_version() { get_pecl_version() {
extension=$1 extension=$1
stability="$(echo "$2" | grep -m 1 -Eio "(alpha|beta|rc|snapshot)")" stability="$(echo "$2" | grep -m 1 -Eio "(alpha|beta|rc|snapshot|preview)")"
pecl_rest='https://pecl.php.net/rest/r/' pecl_rest='https://pecl.php.net/rest/r/'
response=$(curl "${curl_opts[@]}" "$pecl_rest$extension"/allreleases.xml) response=$(curl "${curl_opts[@]}" "$pecl_rest$extension"/allreleases.xml)
pecl_version=$(echo "$response" | grep -m 1 -Pio "(\d*\.\d*\.\d*$stability\d*)") pecl_version=$(echo "$response" | grep -m 1 -Pio "(\d*\.\d*\.\d*$stability\d*)")
@ -202,7 +202,7 @@ add_pecl_extension() {
extension=$1 extension=$1
pecl_version=$2 pecl_version=$2
prefix=$3 prefix=$3
if [[ $pecl_version =~ .*(alpha|beta|rc|snapshot).* ]]; then if [[ $pecl_version =~ .*(alpha|beta|rc|snapshot|preview).* ]]; then
pecl_version=$(get_pecl_version "$extension" "$pecl_version") pecl_version=$(get_pecl_version "$extension" "$pecl_version")
fi fi
if ! check_extension "$extension" && [ -e "$ext_dir/$extension.so" ]; then if ! check_extension "$extension" && [ -e "$ext_dir/$extension.so" ]; then