Skip to content

Parse required extensions from composer.json #58

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 36 additions & 3 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ const INSTALLABLE_VERSIONS = [

/**
* @param {Object} composerJson
* @return {Array}
* @return {Array<string>}
*/
function gatherVersions (composerJson) {
function gatherVersions(composerJson) {
if (JSON.stringify(composerJson) === '{}') {
return [];
}
Expand All @@ -38,6 +38,33 @@ function gatherVersions (composerJson) {
return versions;
}

/**
* @param {Object} composerJson
* @return {Array<string>}
*/
function gatherExtensions(composerJson) {
let extensions = new Set;
const EXTENSION_EXPRESSION = new RegExp(/^ext-/);

if (typeof composerJson.require === 'object') {
Object.keys(composerJson.require).forEach(function (requirement) {
if (requirement.match(EXTENSION_EXPRESSION)) {
extensions = extensions.add(requirement.replace(EXTENSION_EXPRESSION, ""));
}
})
}

if (typeof composerJson["require-dev"] === "object") {
Object.keys(composerJson["require-dev"]).forEach(function (requirement) {
if (requirement.match(EXTENSION_EXPRESSION)) {
extensions = extensions.add(requirement.replace(EXTENSION_EXPRESSION, ""));
}
})
}

return Array.from(extensions);
}

class Config {
code_checks = true;
doc_linting = true;
Expand Down Expand Up @@ -66,6 +93,7 @@ class Config {
this.code_checks = requirements.code_checks;
this.doc_linting = requirements.doc_linting;
this.versions = gatherVersions(composerJson);
this.extensions = gatherExtensions(composerJson);

if (configuration["stablePHP"] !== undefined) {
this.stable_version = configuration["stablePHP"];
Expand All @@ -79,7 +107,12 @@ class Config {
}

if (configuration.extensions !== undefined && Array.isArray(configuration.extensions)) {
this.extensions = configuration.extensions;
let extensions = new Set(this.extensions);
configuration.extensions.forEach(function (extension) {
extensions = extensions.add(extension);
});

this.extensions = Array.from(extensions);
}

if (configuration.ini !== undefined && Array.isArray(configuration.ini)) {
Expand Down