Skip to content

Commit

Permalink
Add composer support
Browse files Browse the repository at this point in the history
Not sure the best method of getting the current version of the composer package.
Requesting directly to packagist returns all versions and their metadata which is just enormous.
Too much data for very little benefit, so currently investigating a better way
  • Loading branch information
BrainMaestro committed Feb 18, 2017
1 parent 6eac1af commit 8bb50b4
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 11 deletions.
9 changes: 8 additions & 1 deletion src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ window.packageConfig = [
file: 'package.json',
registry: window.registry.npm,
parse: window.parser.json,
keys: ['dependencies', 'devDependencies']
keys: ['dependencies', 'devDependencies'],
},
{
name: 'composer',
file: 'composer.json',
registry: window.registry.composer,
parse: window.parser.json,
keys: ['require', 'require-dev'],
},
];
6 changes: 4 additions & 2 deletions src/display.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ function display(deps, devDeps, config) {
}

function addDependencies(body, deps, registry, dev) {
body.appendChild(subHeader(dev))
if (deps) {
body.appendChild(subHeader(dev))
}

for (dep in deps) {
var row = document.createElement('tr');
Expand All @@ -42,7 +44,7 @@ function subHeader(dev) {
var row = document.createElement('tr');
var td = document.createElement('td');
var header = document.createElement('strong');

header.textContent = dev ? 'Development Dependencies' : 'Project Dependencies';
td.colSpan = tableHeaders.length;
td.appendChild(header);
Expand Down
11 changes: 3 additions & 8 deletions src/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,7 @@
}
],
"permissions": [
"https://registry.npmjs.org/"
],
"background": {
"scripts": [
"registry.js"
],
"persistent": false
}
"https://registry.npmjs.org/",
"https://packagist.org/"
]
}
12 changes: 12 additions & 0 deletions src/registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,22 @@ function npm(packageName, callback) {
}
}

function composer(packageName, callback) {
var url = registryConfig.composer + packageName;
getExtraPackageData(url, listener);

function listener() {
var data = JSON.parse(this.responseText)['results'][0];
callback('-', data.description, data.repository);
}
}

var registryConfig = {
npm: 'https://registry.npmjs.org/',
composer: 'https://packagist.org/search.json?q=',
};

window.registry = {
npm: npm,
composer: composer,
};

0 comments on commit 8bb50b4

Please sign in to comment.