mirror of
https://github.com/shivammathur/setup-php.git
synced 2024-11-26 05:23:03 +07:00
Add support to remove all shared extensions
This commit is contained in:
parent
4beeea41b4
commit
b2d037d560
@ -3,10 +3,11 @@ 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, 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',
|
'7.4',
|
||||||
'win32'
|
'win32'
|
||||||
);
|
);
|
||||||
|
expect(win32).toContain('Disable-AllShared');
|
||||||
expect(win32).toContain('Add-Extension xdebug');
|
expect(win32).toContain('Add-Extension xdebug');
|
||||||
expect(win32).toContain('Add-Extension pcov');
|
expect(win32).toContain('Add-Extension pcov');
|
||||||
expect(win32).toContain('Add-Extension sqlite3');
|
expect(win32).toContain('Add-Extension sqlite3');
|
||||||
@ -72,10 +73,11 @@ describe('Extension tests', () => {
|
|||||||
|
|
||||||
it('checking addExtensionOnLinux', async () => {
|
it('checking addExtensionOnLinux', async () => {
|
||||||
let linux: string = await extensions.addExtension(
|
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',
|
'7.4',
|
||||||
'linux'
|
'linux'
|
||||||
);
|
);
|
||||||
|
expect(linux).toContain('disable_all_shared');
|
||||||
expect(linux).toContain('add_extension xdebug');
|
expect(linux).toContain('add_extension xdebug');
|
||||||
expect(linux).toContain('add_extension sqlite3');
|
expect(linux).toContain('add_extension sqlite3');
|
||||||
expect(linux).toContain('disable_extension intl');
|
expect(linux).toContain('disable_extension intl');
|
||||||
@ -160,10 +162,11 @@ describe('Extension tests', () => {
|
|||||||
|
|
||||||
it('checking addExtensionOnDarwin', async () => {
|
it('checking addExtensionOnDarwin', async () => {
|
||||||
let darwin: string = await extensions.addExtension(
|
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',
|
'7.2',
|
||||||
'darwin'
|
'darwin'
|
||||||
);
|
);
|
||||||
|
expect(darwin).toContain('disable_all_shared');
|
||||||
expect(darwin).toContain('add_brew_extension amqp extension');
|
expect(darwin).toContain('add_brew_extension amqp extension');
|
||||||
expect(darwin).toContain('add_brew_extension apcu extension');
|
expect(darwin).toContain('add_brew_extension apcu extension');
|
||||||
expect(darwin).toContain('add_brew_extension xdebug zend_extension');
|
expect(darwin).toContain('add_brew_extension xdebug zend_extension');
|
||||||
|
@ -127,8 +127,8 @@ describe('Utils tests', () => {
|
|||||||
|
|
||||||
it('checking extensionArray', async () => {
|
it('checking extensionArray', async () => {
|
||||||
expect(
|
expect(
|
||||||
await utils.extensionArray('a, :b, php_c, php-d, Zend e, :Zend f')
|
await utils.extensionArray('a, :b, php_c, none, php-d, Zend e, :Zend f')
|
||||||
).toEqual(['a', ':b', 'c', 'd', 'e', ':f']);
|
).toEqual(['none', 'a', ':b', 'c', 'd', 'e', ':f']);
|
||||||
|
|
||||||
expect(await utils.extensionArray('')).toEqual([]);
|
expect(await utils.extensionArray('')).toEqual([]);
|
||||||
expect(await utils.extensionArray(' ')).toEqual([]);
|
expect(await utils.extensionArray(' ')).toEqual([]);
|
||||||
|
17
dist/index.js
vendored
17
dist/index.js
vendored
@ -212,6 +212,9 @@ async function addExtensionDarwin(extension_csv, version) {
|
|||||||
case /^:/.test(ext_name):
|
case /^:/.test(ext_name):
|
||||||
remove_script += '\ndisable_extension' + ext_name.replace(/:/g, ' ');
|
remove_script += '\ndisable_extension' + ext_name.replace(/:/g, ' ');
|
||||||
return;
|
return;
|
||||||
|
case /^none$/.test(ext_name):
|
||||||
|
add_script += '\ndisable_all_shared';
|
||||||
|
return;
|
||||||
case /.+-.+\/.+@.+/.test(extension):
|
case /.+-.+\/.+@.+/.test(extension):
|
||||||
add_script += await utils.parseExtensionSource(extension, ext_prefix);
|
add_script += await utils.parseExtensionSource(extension, ext_prefix);
|
||||||
return;
|
return;
|
||||||
@ -258,6 +261,9 @@ async function addExtensionWindows(extension_csv, version) {
|
|||||||
case /^:/.test(ext_name):
|
case /^:/.test(ext_name):
|
||||||
remove_script += '\nDisable-Extension' + ext_name.replace(/:/g, ' ');
|
remove_script += '\nDisable-Extension' + ext_name.replace(/:/g, ' ');
|
||||||
break;
|
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 /^(5\.[3-6]|7\.[0-4]|8\.0)blackfire(-\d+\.\d+\.\d+)?$/.test(version_extension):
|
||||||
case /^pdo_oci$|^oci8$|^pdo_firebird$/.test(extension):
|
case /^pdo_oci$|^oci8$|^pdo_firebird$/.test(extension):
|
||||||
case /^(5\.[3-6]|7\.[0-4])ioncube$/.test(version_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):
|
case /^:/.test(ext_name):
|
||||||
remove_script += '\ndisable_extension' + ext_name.replace(/:/g, ' ');
|
remove_script += '\ndisable_extension' + ext_name.replace(/:/g, ' ');
|
||||||
return;
|
return;
|
||||||
|
case /^none$/.test(ext_name):
|
||||||
|
add_script += '\ndisable_all_shared';
|
||||||
|
return;
|
||||||
case /.+-.+\/.+@.+/.test(extension):
|
case /.+-.+\/.+@.+/.test(extension):
|
||||||
add_script += await utils.parseExtensionSource(extension, ext_prefix);
|
add_script += await utils.parseExtensionSource(extension, ext_prefix);
|
||||||
return;
|
return;
|
||||||
@ -1041,7 +1050,9 @@ async function extensionArray(extension_csv) {
|
|||||||
case ' ':
|
case ' ':
|
||||||
return [];
|
return [];
|
||||||
default:
|
default:
|
||||||
return extension_csv
|
return [
|
||||||
|
extension_csv.match(/(^|,\s?)none(\s?,|$)/) ? 'none' : '',
|
||||||
|
...extension_csv
|
||||||
.split(',')
|
.split(',')
|
||||||
.map(function (extension) {
|
.map(function (extension) {
|
||||||
if (/.+-.+\/.+@.+/.test(extension)) {
|
if (/.+-.+\/.+@.+/.test(extension)) {
|
||||||
@ -1050,9 +1061,9 @@ async function extensionArray(extension_csv) {
|
|||||||
return extension
|
return extension
|
||||||
.trim()
|
.trim()
|
||||||
.toLowerCase()
|
.toLowerCase()
|
||||||
.replace(/^(:)?(php[-_]|zend )/, '$1');
|
.replace(/^(:)?(php[-_]|none|zend )/, '$1');
|
||||||
})
|
})
|
||||||
.filter(Boolean);
|
].filter(Boolean);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
exports.extensionArray = extensionArray;
|
exports.extensionArray = extensionArray;
|
||||||
|
@ -23,6 +23,10 @@ export async function addExtensionDarwin(
|
|||||||
case /^:/.test(ext_name):
|
case /^:/.test(ext_name):
|
||||||
remove_script += '\ndisable_extension' + ext_name.replace(/:/g, ' ');
|
remove_script += '\ndisable_extension' + ext_name.replace(/:/g, ' ');
|
||||||
return;
|
return;
|
||||||
|
// Match none
|
||||||
|
case /^none$/.test(ext_name):
|
||||||
|
add_script += '\ndisable_all_shared';
|
||||||
|
return;
|
||||||
// match extensions for compiling from source
|
// match extensions for compiling from source
|
||||||
case /.+-.+\/.+@.+/.test(extension):
|
case /.+-.+\/.+@.+/.test(extension):
|
||||||
add_script += await utils.parseExtensionSource(extension, ext_prefix);
|
add_script += await utils.parseExtensionSource(extension, ext_prefix);
|
||||||
@ -117,6 +121,10 @@ export async function addExtensionWindows(
|
|||||||
case /^:/.test(ext_name):
|
case /^:/.test(ext_name):
|
||||||
remove_script += '\nDisable-Extension' + ext_name.replace(/:/g, ' ');
|
remove_script += '\nDisable-Extension' + ext_name.replace(/:/g, ' ');
|
||||||
break;
|
break;
|
||||||
|
// Match none
|
||||||
|
case /^none$/.test(ext_name):
|
||||||
|
add_script += '\nDisable-AllShared';
|
||||||
|
break;
|
||||||
// match 5.3blackfire...8.0blackfire
|
// match 5.3blackfire...8.0blackfire
|
||||||
// match 5.3blackfire-(semver)...8.0blackfire-(semver)
|
// match 5.3blackfire-(semver)...8.0blackfire-(semver)
|
||||||
// match pdo_oci and oci8
|
// match pdo_oci and oci8
|
||||||
@ -229,6 +237,10 @@ export async function addExtensionLinux(
|
|||||||
case /^:/.test(ext_name):
|
case /^:/.test(ext_name):
|
||||||
remove_script += '\ndisable_extension' + ext_name.replace(/:/g, ' ');
|
remove_script += '\ndisable_extension' + ext_name.replace(/:/g, ' ');
|
||||||
return;
|
return;
|
||||||
|
// Match none
|
||||||
|
case /^none$/.test(ext_name):
|
||||||
|
add_script += '\ndisable_all_shared';
|
||||||
|
return;
|
||||||
// match extensions for compiling from source
|
// match extensions for compiling from source
|
||||||
case /.+-.+\/.+@.+/.test(extension):
|
case /.+-.+\/.+@.+/.test(extension):
|
||||||
add_script += await utils.parseExtensionSource(extension, ext_prefix);
|
add_script += await utils.parseExtensionSource(extension, ext_prefix);
|
||||||
|
@ -183,6 +183,13 @@ disable_extension() {
|
|||||||
fi
|
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
|
# Function to configure PHP
|
||||||
configure_php() {
|
configure_php() {
|
||||||
(
|
(
|
||||||
|
@ -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 to configure composer.
|
||||||
Function Edit-ComposerConfig() {
|
Function Edit-ComposerConfig() {
|
||||||
Param(
|
Param(
|
||||||
|
@ -280,8 +280,11 @@ export async function extensionArray(
|
|||||||
case ' ':
|
case ' ':
|
||||||
return [];
|
return [];
|
||||||
default:
|
default:
|
||||||
return extension_csv
|
return [
|
||||||
|
extension_csv.match(/(^|,\s?)none(\s?,|$)/) ? 'none' : '',
|
||||||
|
...extension_csv
|
||||||
.split(',')
|
.split(',')
|
||||||
|
|
||||||
.map(function (extension: string) {
|
.map(function (extension: string) {
|
||||||
if (/.+-.+\/.+@.+/.test(extension)) {
|
if (/.+-.+\/.+@.+/.test(extension)) {
|
||||||
return extension;
|
return extension;
|
||||||
@ -289,9 +292,9 @@ export async function extensionArray(
|
|||||||
return extension
|
return extension
|
||||||
.trim()
|
.trim()
|
||||||
.toLowerCase()
|
.toLowerCase()
|
||||||
.replace(/^(:)?(php[-_]|zend )/, '$1');
|
.replace(/^(:)?(php[-_]|none|zend )/, '$1');
|
||||||
})
|
})
|
||||||
.filter(Boolean);
|
].filter(Boolean);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user