Add support to remove all shared extensions

This commit is contained in:
Shivam Mathur 2021-08-26 21:29:38 +05:30
parent 4beeea41b4
commit b2d037d560
No known key found for this signature in database
GPG Key ID: 3E13E4C8591ACC2A
7 changed files with 71 additions and 29 deletions

View File

@ -3,10 +3,11 @@ import * as extensions from '../src/extensions';
describe('Extension tests', () => {
it('checking addExtensionOnWindows', async () => {
let win32: string = await extensions.addExtension(
'Xdebug, pcov, sqlite, :intl, phalcon4, pecl_http, ioncube, oci8, pdo_oci, ast-beta, grpc-1.2.3, inotify-1.2.3alpha2, sqlsrv-1.2.3preview1',
'none, Xdebug, pcov, sqlite, :intl, phalcon4, pecl_http, ioncube, oci8, pdo_oci, ast-beta, grpc-1.2.3, inotify-1.2.3alpha2, sqlsrv-1.2.3preview1',
'7.4',
'win32'
);
expect(win32).toContain('Disable-AllShared');
expect(win32).toContain('Add-Extension xdebug');
expect(win32).toContain('Add-Extension pcov');
expect(win32).toContain('Add-Extension sqlite3');
@ -72,10 +73,11 @@ describe('Extension tests', () => {
it('checking addExtensionOnLinux', async () => {
let linux: string = await extensions.addExtension(
'Xdebug, pcov, sqlite, :intl, ast, ast-beta, pdo_mysql, pdo-odbc, xdebug-alpha, grpc-1.2.3',
'none, Xdebug, pcov, sqlite, :intl, ast, ast-beta, pdo_mysql, pdo-odbc, xdebug-alpha, grpc-1.2.3',
'7.4',
'linux'
);
expect(linux).toContain('disable_all_shared');
expect(linux).toContain('add_extension xdebug');
expect(linux).toContain('add_extension sqlite3');
expect(linux).toContain('disable_extension intl');
@ -160,10 +162,11 @@ describe('Extension tests', () => {
it('checking addExtensionOnDarwin', async () => {
let darwin: string = await extensions.addExtension(
'amqp, apcu, Xdebug, pcov, grpc, igbinary, imagick, imap, memcache, memcached, mongodb, msgpack, phalcon3, phalcon4, protobuf, psr, rdkafka, redis, swoole, yaml, sqlite, oci8, pdo_oci, :intl, ast-beta, grpc-1.2.3',
'none, amqp, apcu, Xdebug, pcov, grpc, igbinary, imagick, imap, memcache, memcached, mongodb, msgpack, phalcon3, phalcon4, protobuf, psr, rdkafka, redis, swoole, yaml, sqlite, oci8, pdo_oci, :intl, ast-beta, grpc-1.2.3',
'7.2',
'darwin'
);
expect(darwin).toContain('disable_all_shared');
expect(darwin).toContain('add_brew_extension amqp extension');
expect(darwin).toContain('add_brew_extension apcu extension');
expect(darwin).toContain('add_brew_extension xdebug zend_extension');

View File

@ -127,8 +127,8 @@ describe('Utils tests', () => {
it('checking extensionArray', async () => {
expect(
await utils.extensionArray('a, :b, php_c, php-d, Zend e, :Zend f')
).toEqual(['a', ':b', 'c', 'd', 'e', ':f']);
await utils.extensionArray('a, :b, php_c, none, php-d, Zend e, :Zend f')
).toEqual(['none', 'a', ':b', 'c', 'd', 'e', ':f']);
expect(await utils.extensionArray('')).toEqual([]);
expect(await utils.extensionArray(' ')).toEqual([]);

17
dist/index.js vendored
View File

@ -212,6 +212,9 @@ async function addExtensionDarwin(extension_csv, version) {
case /^:/.test(ext_name):
remove_script += '\ndisable_extension' + ext_name.replace(/:/g, ' ');
return;
case /^none$/.test(ext_name):
add_script += '\ndisable_all_shared';
return;
case /.+-.+\/.+@.+/.test(extension):
add_script += await utils.parseExtensionSource(extension, ext_prefix);
return;
@ -258,6 +261,9 @@ async function addExtensionWindows(extension_csv, version) {
case /^:/.test(ext_name):
remove_script += '\nDisable-Extension' + ext_name.replace(/:/g, ' ');
break;
case /^none$/.test(ext_name):
add_script += '\nDisable-AllShared';
break;
case /^(5\.[3-6]|7\.[0-4]|8\.0)blackfire(-\d+\.\d+\.\d+)?$/.test(version_extension):
case /^pdo_oci$|^oci8$|^pdo_firebird$/.test(extension):
case /^(5\.[3-6]|7\.[0-4])ioncube$/.test(version_extension):
@ -315,6 +321,9 @@ async function addExtensionLinux(extension_csv, version) {
case /^:/.test(ext_name):
remove_script += '\ndisable_extension' + ext_name.replace(/:/g, ' ');
return;
case /^none$/.test(ext_name):
add_script += '\ndisable_all_shared';
return;
case /.+-.+\/.+@.+/.test(extension):
add_script += await utils.parseExtensionSource(extension, ext_prefix);
return;
@ -1041,7 +1050,9 @@ async function extensionArray(extension_csv) {
case ' ':
return [];
default:
return extension_csv
return [
extension_csv.match(/(^|,\s?)none(\s?,|$)/) ? 'none' : '',
...extension_csv
.split(',')
.map(function (extension) {
if (/.+-.+\/.+@.+/.test(extension)) {
@ -1050,9 +1061,9 @@ async function extensionArray(extension_csv) {
return extension
.trim()
.toLowerCase()
.replace(/^(:)?(php[-_]|zend )/, '$1');
.replace(/^(:)?(php[-_]|none|zend )/, '$1');
})
.filter(Boolean);
].filter(Boolean);
}
}
exports.extensionArray = extensionArray;

View File

@ -23,6 +23,10 @@ export async function addExtensionDarwin(
case /^:/.test(ext_name):
remove_script += '\ndisable_extension' + ext_name.replace(/:/g, ' ');
return;
// Match none
case /^none$/.test(ext_name):
add_script += '\ndisable_all_shared';
return;
// match extensions for compiling from source
case /.+-.+\/.+@.+/.test(extension):
add_script += await utils.parseExtensionSource(extension, ext_prefix);
@ -117,6 +121,10 @@ export async function addExtensionWindows(
case /^:/.test(ext_name):
remove_script += '\nDisable-Extension' + ext_name.replace(/:/g, ' ');
break;
// Match none
case /^none$/.test(ext_name):
add_script += '\nDisable-AllShared';
break;
// match 5.3blackfire...8.0blackfire
// match 5.3blackfire-(semver)...8.0blackfire-(semver)
// match pdo_oci and oci8
@ -229,6 +237,10 @@ export async function addExtensionLinux(
case /^:/.test(ext_name):
remove_script += '\ndisable_extension' + ext_name.replace(/:/g, ' ');
return;
// Match none
case /^none$/.test(ext_name):
add_script += '\ndisable_all_shared';
return;
// match extensions for compiling from source
case /.+-.+\/.+@.+/.test(extension):
add_script += await utils.parseExtensionSource(extension, ext_prefix);

View File

@ -183,6 +183,13 @@ disable_extension() {
fi
}
# Function to disable shared extensions.
disable_all_shared() {
sudo sed -i.orig -E -e "/^(zend_)?extension\s*=/d" "${ini_file[@]}" "$pecl_file" 2>/dev/null || true
sudo find "${ini_dir:-$scan_dir}"/.. -name "*.ini" -not -path "*php.ini" -not -path "*mods-available*" -delete >/dev/null 2>&1 || true
add_log "${tick:?}" "none" "Disabled all shared extensions"
}
# Function to configure PHP
configure_php() {
(

View File

@ -307,6 +307,12 @@ Function Disable-Extension() {
}
}
# Function to disable shared extensions.
Function Disable-AllShared() {
(Get-Content $php_dir\php.ini) | Where-Object {$_ -notmatch '^(zend_)?extension\s*='} | Set-Content $php_dir\php.ini
Add-Log $tick "none" "Disabled all shared extensions"
}
# Function to configure composer.
Function Edit-ComposerConfig() {
Param(

View File

@ -280,8 +280,11 @@ export async function extensionArray(
case ' ':
return [];
default:
return extension_csv
return [
extension_csv.match(/(^|,\s?)none(\s?,|$)/) ? 'none' : '',
...extension_csv
.split(',')
.map(function (extension: string) {
if (/.+-.+\/.+@.+/.test(extension)) {
return extension;
@ -289,9 +292,9 @@ export async function extensionArray(
return extension
.trim()
.toLowerCase()
.replace(/^(:)?(php[-_]|zend )/, '$1');
.replace(/^(:)?(php[-_]|none|zend )/, '$1');
})
.filter(Boolean);
].filter(Boolean);
}
}