Improve extension support

This commit is contained in:
Shivam Mathur 2020-03-14 07:42:02 +05:30
parent 0da52b1327
commit 6a4159ba98
No known key found for this signature in database
GPG Key ID: 3E13E4C8591ACC2A
4 changed files with 96 additions and 51 deletions

View File

@ -3,12 +3,13 @@ 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, phalcon4, ast-beta', 'Xdebug, pcov, sqlite, phalcon4, ast-beta',
'7.4', '7.4',
'win32' 'win32'
); );
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('phalcon.ps1 phalcon4'); expect(win32).toContain('phalcon.ps1 phalcon4');
expect(win32).toContain('Add-Extension ast beta'); expect(win32).toContain('Add-Extension ast beta');
@ -27,13 +28,14 @@ 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, ast-beta, xdebug-alpha', 'Xdebug, pcov, sqlite, ast-beta, xdebug-alpha',
'7.4', '7.4',
'linux' 'linux'
); );
expect(linux).toContain('update_extension xdebug 2.9.0'); expect(linux).toContain('update_extension xdebug 2.9.2');
expect(linux).toContain('sudo $debconf_fix apt-get install -y php7.4-pcov');
expect(linux).toContain( expect(linux).toContain(
'sudo DEBIAN_FRONTEND=noninteractive apt-get install -y php7.4-pcov' 'sudo $debconf_fix apt-get install -y php7.4-sqlite3'
); );
expect(linux).toContain('add_unstable_extension ast beta extension'); expect(linux).toContain('add_unstable_extension ast beta extension');
expect(linux).toContain( expect(linux).toContain(
@ -64,12 +66,13 @@ describe('Extension tests', () => {
it('checking addExtensionOnDarwin', async () => { it('checking addExtensionOnDarwin', async () => {
let darwin: string = await extensions.addExtension( let darwin: string = await extensions.addExtension(
'xdebug, pcov, ast-beta', 'Xdebug, pcov, sqlite3, ast-beta',
'7.2', '7.2',
'darwin' 'darwin'
); );
expect(darwin).toContain('sudo pecl install -f xdebug'); expect(darwin).toContain('sudo pecl install -f xdebug');
expect(darwin).toContain('sudo pecl install -f pcov'); expect(darwin).toContain('sudo pecl install -f pcov');
expect(darwin).toContain('sudo pecl install -f sqlite3');
expect(darwin).toContain('add_unstable_extension ast beta extension'); expect(darwin).toContain('add_unstable_extension ast beta extension');
darwin = await extensions.addExtension('phalcon3', '7.0', 'darwin'); darwin = await extensions.addExtension('phalcon3', '7.0', 'darwin');

67
dist/index.js vendored
View File

@ -1177,6 +1177,7 @@ function extensionArray(extension_csv) {
.map(function (extension) { .map(function (extension) {
return extension return extension
.trim() .trim()
.toLowerCase()
.replace('php-', '') .replace('php-', '')
.replace('php_', ''); .replace('php_', '');
}) })
@ -2645,11 +2646,11 @@ function addExtensionDarwin(extension_csv, version, pipe) {
let script = '\n'; let script = '\n';
yield utils.asyncForEach(extensions, function (extension) { yield utils.asyncForEach(extensions, function (extension) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
extension = extension.toLowerCase();
const version_extension = version + extension; const version_extension = version + extension;
const [extension_name, stability] = extension.split('-'); const [extension_name, stability] = extension.split('-');
const prefix = yield utils.getExtensionPrefix(extension_name); const ext_prefix = yield utils.getExtensionPrefix(extension_name);
let install_command = ''; const command_prefix = 'sudo pecl install -f ';
let command = '';
switch (true) { switch (true) {
// match pre-release versions // match pre-release versions
case /.*-(beta|alpha|devel|snapshot)/.test(version_extension): case /.*-(beta|alpha|devel|snapshot)/.test(version_extension):
@ -2659,24 +2660,36 @@ function addExtensionDarwin(extension_csv, version, pipe) {
' ' + ' ' +
stability + stability +
' ' + ' ' +
prefix; ext_prefix;
return; return;
// match 5.6xdebug
case /5\.6xdebug/.test(version_extension): case /5\.6xdebug/.test(version_extension):
install_command = 'sudo pecl install -f xdebug-2.5.5' + pipe; command = command_prefix + 'xdebug-2.5.5' + pipe;
break; break;
// match 7.0xdebug
case /7\.0xdebug/.test(version_extension): case /7\.0xdebug/.test(version_extension):
install_command = 'sudo pecl install -f xdebug-2.9.0' + pipe; command = command_prefix + 'xdebug-2.9.0' + pipe;
break; break;
// match 5.6redis
case /5\.6redis/.test(version_extension): case /5\.6redis/.test(version_extension):
install_command = 'sudo pecl install -f redis-2.2.8' + pipe; command = command_prefix + 'redis-2.2.8' + pipe;
break; break;
case /[5-9]\.\dimagick/.test(version_extension): // match imagick
install_command = case /imagick/.test(extension):
command =
'brew install pkg-config imagemagick' + 'brew install pkg-config imagemagick' +
pipe + pipe +
' && sudo pecl install -f imagick' + ' && ' +
command_prefix +
'imagick' +
pipe; pipe;
break; break;
// match sqlite
case /sqlite/.test(extension):
extension = 'sqlite3';
command = command_prefix + extension + pipe;
break;
// match 7.0phalcon3...7.3phalcon3 and 7.2phalcon4...7.4phalcon4
case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version_extension): case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version_extension):
script += script +=
'sh ' + 'sh ' +
@ -2687,14 +2700,14 @@ function addExtensionDarwin(extension_csv, version, pipe) {
version; version;
return; return;
default: default:
install_command = 'sudo pecl install -f ' + extension + pipe; command = command_prefix + extension + pipe;
break; break;
} }
script += script +=
'\nadd_extension ' + '\nadd_extension ' +
extension + extension +
' "' + ' "' +
install_command + command +
'" ' + '" ' +
(yield utils.getExtensionPrefix(extension)); (yield utils.getExtensionPrefix(extension));
}); });
@ -2716,7 +2729,6 @@ function addExtensionWindows(extension_csv, version, pipe) {
let script = '\n'; let script = '\n';
yield utils.asyncForEach(extensions, function (extension) { yield utils.asyncForEach(extensions, function (extension) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
extension = extension.toLowerCase();
const [extension_name, stability] = extension.split('-'); const [extension_name, stability] = extension.split('-');
const version_extension = version + extension; const version_extension = version + extension;
switch (true) { switch (true) {
@ -2724,6 +2736,11 @@ function addExtensionWindows(extension_csv, version, pipe) {
case /.*-(beta|alpha|devel|snapshot)/.test(version_extension): case /.*-(beta|alpha|devel|snapshot)/.test(version_extension):
script += '\nAdd-Extension ' + extension_name + ' ' + stability; script += '\nAdd-Extension ' + extension_name + ' ' + stability;
break; break;
// match sqlite
case /sqlite/.test(extension):
extension = 'sqlite3';
script += '\nAdd-Extension ' + extension;
break;
// match 7.0phalcon3...7.3phalcon3 and 7.2phalcon4...7.4phalcon4 // match 7.0phalcon3...7.3phalcon3 and 7.2phalcon4...7.4phalcon4
case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version_extension): case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version_extension):
script += script +=
@ -2758,11 +2775,11 @@ function addExtensionLinux(extension_csv, version, pipe) {
let script = '\n'; let script = '\n';
yield utils.asyncForEach(extensions, function (extension) { yield utils.asyncForEach(extensions, function (extension) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
extension = extension.toLowerCase();
const version_extension = version + extension; const version_extension = version + extension;
const [extension_name, stability] = extension.split('-'); const [extension_name, stability] = extension.split('-');
const prefix = yield utils.getExtensionPrefix(extension_name); const ext_prefix = yield utils.getExtensionPrefix(extension_name);
let install_command = ''; const command_prefix = 'sudo $debconf_fix apt-get install -y php';
let command = '';
switch (true) { switch (true) {
// match pre-release versions // match pre-release versions
case /.*-(beta|alpha|devel|snapshot)/.test(version_extension): case /.*-(beta|alpha|devel|snapshot)/.test(version_extension):
@ -2772,11 +2789,11 @@ function addExtensionLinux(extension_csv, version, pipe) {
' ' + ' ' +
stability + stability +
' ' + ' ' +
prefix; ext_prefix;
return; return;
// match 5.6gearman..7.4gearman // match 5.6gearman..7.4gearman
case /^((5\.6)|(7\.[0-4]))gearman$/.test(version_extension): case /^((5\.6)|(7\.[0-4]))gearman$/.test(version_extension):
install_command = command =
'sh ' + 'sh ' +
path.join(__dirname, '../src/scripts/ext/gearman.sh') + path.join(__dirname, '../src/scripts/ext/gearman.sh') +
' ' + ' ' +
@ -2796,14 +2813,18 @@ function addExtensionLinux(extension_csv, version, pipe) {
// match 7.0xdebug..7.4xdebug // match 7.0xdebug..7.4xdebug
case /^7\.[0-4]xdebug$/.test(version_extension): case /^7\.[0-4]xdebug$/.test(version_extension):
script += script +=
'\nupdate_extension xdebug 2.9.0' + '\nupdate_extension xdebug 2.9.2' +
pipe + pipe +
'\n' + '\n' +
(yield utils.addLog('$tick', 'xdebug', 'Enabled', 'linux')); (yield utils.addLog('$tick', 'xdebug', 'Enabled', 'linux'));
return; return;
case /sqlite/.test(extension):
extension = 'sqlite3';
command = command_prefix + version + '-' + extension + pipe;
break;
default: default:
install_command = command =
'sudo DEBIAN_FRONTEND=noninteractive apt-get install -y php' + command_prefix +
version + version +
'-' + '-' +
extension.replace('pdo_', '').replace('pdo-', '') + extension.replace('pdo_', '').replace('pdo-', '') +
@ -2811,7 +2832,7 @@ function addExtensionLinux(extension_csv, version, pipe) {
break; break;
} }
script += script +=
'\nadd_extension ' + extension + ' "' + install_command + '" ' + prefix; '\nadd_extension ' + extension + ' "' + command + '" ' + ext_prefix;
}); });
}); });
return script; return script;
@ -2824,7 +2845,7 @@ exports.addExtensionLinux = addExtensionLinux;
* @param extension_csv * @param extension_csv
* @param version * @param version
* @param os_version * @param os_version
* @param log_prefix * @param no_step
*/ */
function addExtension(extension_csv, version, os_version, no_step = false) { function addExtension(extension_csv, version, os_version, no_step = false) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {

View File

@ -16,11 +16,11 @@ export async function addExtensionDarwin(
const extensions: Array<string> = await utils.extensionArray(extension_csv); const extensions: Array<string> = await utils.extensionArray(extension_csv);
let script = '\n'; let script = '\n';
await utils.asyncForEach(extensions, async function(extension: string) { await utils.asyncForEach(extensions, async function(extension: string) {
extension = extension.toLowerCase();
const version_extension: string = version + extension; const version_extension: string = version + extension;
const [extension_name, stability]: string[] = extension.split('-'); const [extension_name, stability]: string[] = extension.split('-');
const prefix = await utils.getExtensionPrefix(extension_name); const ext_prefix = await utils.getExtensionPrefix(extension_name);
let install_command = ''; const command_prefix = 'sudo pecl install -f ';
let command = '';
switch (true) { switch (true) {
// match pre-release versions // match pre-release versions
case /.*-(beta|alpha|devel|snapshot)/.test(version_extension): case /.*-(beta|alpha|devel|snapshot)/.test(version_extension):
@ -30,24 +30,36 @@ export async function addExtensionDarwin(
' ' + ' ' +
stability + stability +
' ' + ' ' +
prefix; ext_prefix;
return; return;
// match 5.6xdebug
case /5\.6xdebug/.test(version_extension): case /5\.6xdebug/.test(version_extension):
install_command = 'sudo pecl install -f xdebug-2.5.5' + pipe; command = command_prefix + 'xdebug-2.5.5' + pipe;
break; break;
// match 7.0xdebug
case /7\.0xdebug/.test(version_extension): case /7\.0xdebug/.test(version_extension):
install_command = 'sudo pecl install -f xdebug-2.9.0' + pipe; command = command_prefix + 'xdebug-2.9.0' + pipe;
break; break;
// match 5.6redis
case /5\.6redis/.test(version_extension): case /5\.6redis/.test(version_extension):
install_command = 'sudo pecl install -f redis-2.2.8' + pipe; command = command_prefix + 'redis-2.2.8' + pipe;
break; break;
case /[5-9]\.\dimagick/.test(version_extension): // match imagick
install_command = case /imagick/.test(extension):
command =
'brew install pkg-config imagemagick' + 'brew install pkg-config imagemagick' +
pipe + pipe +
' && sudo pecl install -f imagick' + ' && ' +
command_prefix +
'imagick' +
pipe; pipe;
break; break;
// match sqlite
case /sqlite/.test(extension):
extension = 'sqlite3';
command = command_prefix + extension + pipe;
break;
// match 7.0phalcon3...7.3phalcon3 and 7.2phalcon4...7.4phalcon4
case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version_extension): case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version_extension):
script += script +=
'sh ' + 'sh ' +
@ -58,14 +70,14 @@ export async function addExtensionDarwin(
version; version;
return; return;
default: default:
install_command = 'sudo pecl install -f ' + extension + pipe; command = command_prefix + extension + pipe;
break; break;
} }
script += script +=
'\nadd_extension ' + '\nadd_extension ' +
extension + extension +
' "' + ' "' +
install_command + command +
'" ' + '" ' +
(await utils.getExtensionPrefix(extension)); (await utils.getExtensionPrefix(extension));
}); });
@ -87,7 +99,6 @@ export async function addExtensionWindows(
const extensions: Array<string> = await utils.extensionArray(extension_csv); const extensions: Array<string> = await utils.extensionArray(extension_csv);
let script = '\n'; let script = '\n';
await utils.asyncForEach(extensions, async function(extension: string) { await utils.asyncForEach(extensions, async function(extension: string) {
extension = extension.toLowerCase();
const [extension_name, stability]: string[] = extension.split('-'); const [extension_name, stability]: string[] = extension.split('-');
const version_extension: string = version + extension; const version_extension: string = version + extension;
switch (true) { switch (true) {
@ -95,6 +106,11 @@ export async function addExtensionWindows(
case /.*-(beta|alpha|devel|snapshot)/.test(version_extension): case /.*-(beta|alpha|devel|snapshot)/.test(version_extension):
script += '\nAdd-Extension ' + extension_name + ' ' + stability; script += '\nAdd-Extension ' + extension_name + ' ' + stability;
break; break;
// match sqlite
case /sqlite/.test(extension):
extension = 'sqlite3';
script += '\nAdd-Extension ' + extension;
break;
// match 7.0phalcon3...7.3phalcon3 and 7.2phalcon4...7.4phalcon4 // match 7.0phalcon3...7.3phalcon3 and 7.2phalcon4...7.4phalcon4
case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version_extension): case /^7\.[0-3]phalcon3$|^7\.[2-4]phalcon4$/.test(version_extension):
script += script +=
@ -129,11 +145,11 @@ export async function addExtensionLinux(
const extensions: Array<string> = await utils.extensionArray(extension_csv); const extensions: Array<string> = await utils.extensionArray(extension_csv);
let script = '\n'; let script = '\n';
await utils.asyncForEach(extensions, async function(extension: string) { await utils.asyncForEach(extensions, async function(extension: string) {
extension = extension.toLowerCase();
const version_extension: string = version + extension; const version_extension: string = version + extension;
const [extension_name, stability]: string[] = extension.split('-'); const [extension_name, stability]: string[] = extension.split('-');
const prefix = await utils.getExtensionPrefix(extension_name); const ext_prefix = await utils.getExtensionPrefix(extension_name);
let install_command = ''; const command_prefix = 'sudo $debconf_fix apt-get install -y php';
let command = '';
switch (true) { switch (true) {
// match pre-release versions // match pre-release versions
case /.*-(beta|alpha|devel|snapshot)/.test(version_extension): case /.*-(beta|alpha|devel|snapshot)/.test(version_extension):
@ -143,11 +159,11 @@ export async function addExtensionLinux(
' ' + ' ' +
stability + stability +
' ' + ' ' +
prefix; ext_prefix;
return; return;
// match 5.6gearman..7.4gearman // match 5.6gearman..7.4gearman
case /^((5\.6)|(7\.[0-4]))gearman$/.test(version_extension): case /^((5\.6)|(7\.[0-4]))gearman$/.test(version_extension):
install_command = command =
'sh ' + 'sh ' +
path.join(__dirname, '../src/scripts/ext/gearman.sh') + path.join(__dirname, '../src/scripts/ext/gearman.sh') +
' ' + ' ' +
@ -167,14 +183,18 @@ export async function addExtensionLinux(
// match 7.0xdebug..7.4xdebug // match 7.0xdebug..7.4xdebug
case /^7\.[0-4]xdebug$/.test(version_extension): case /^7\.[0-4]xdebug$/.test(version_extension):
script += script +=
'\nupdate_extension xdebug 2.9.0' + '\nupdate_extension xdebug 2.9.2' +
pipe + pipe +
'\n' + '\n' +
(await utils.addLog('$tick', 'xdebug', 'Enabled', 'linux')); (await utils.addLog('$tick', 'xdebug', 'Enabled', 'linux'));
return; return;
case /sqlite/.test(extension):
extension = 'sqlite3';
command = command_prefix + version + '-' + extension + pipe;
break;
default: default:
install_command = command =
'sudo DEBIAN_FRONTEND=noninteractive apt-get install -y php' + command_prefix +
version + version +
'-' + '-' +
extension.replace('pdo_', '').replace('pdo-', '') + extension.replace('pdo_', '').replace('pdo-', '') +
@ -182,7 +202,7 @@ export async function addExtensionLinux(
break; break;
} }
script += script +=
'\nadd_extension ' + extension + ' "' + install_command + '" ' + prefix; '\nadd_extension ' + extension + ' "' + command + '" ' + ext_prefix;
}); });
return script; return script;
} }
@ -193,7 +213,7 @@ export async function addExtensionLinux(
* @param extension_csv * @param extension_csv
* @param version * @param version
* @param os_version * @param os_version
* @param log_prefix * @param no_step
*/ */
export async function addExtension( export async function addExtension(
extension_csv: string, extension_csv: string,

View File

@ -196,6 +196,7 @@ export async function extensionArray(
.map(function(extension: string) { .map(function(extension: string) {
return extension return extension
.trim() .trim()
.toLowerCase()
.replace('php-', '') .replace('php-', '')
.replace('php_', ''); .replace('php_', '');
}) })