Skip to content
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

Show available dependencies in the UI #500

Merged
merged 2 commits into from
Jun 5, 2017
Merged
Show file tree
Hide file tree
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
17 changes: 17 additions & 0 deletions src/registry/routes/helpers/get-available-dependencies.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
'use strict';

const coreModules = require('builtin-modules');
const _ = require('lodash');

const RequireWrapper = require('../../domain/require-wrapper');

module.exports = (dependencies) => _.map(dependencies, (dependency) => {

const requirer = RequireWrapper(dependencies);
const core = _.includes(coreModules, dependency);
const packageJson = !core && requirer(`${dependency}/package.json`);
const version = packageJson && packageJson.version;
const link = core ? `https://nodejs.org/api/${dependency}.html` : packageJson.homepage;

return { core, name: dependency, version, link };
});
3 changes: 2 additions & 1 deletion src/registry/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const _ = require('lodash');

const dateStringified = require('../../utils/date-stringify');
const getComponentsHistory = require('./helpers/get-components-history');
const getAvailableDependencies = require('./helpers/get-available-dependencies');
const packageInfo = require('../../../package.json');
const urlBuilder = require('../domain/url-builder');

Expand Down Expand Up @@ -47,7 +48,7 @@ module.exports = function(repository){
repository.getComponentsDetails((err, details) => {

res.render('index', _.extend(baseResponse, {
availableDependencies: res.conf.dependencies,
availableDependencies: getAvailableDependencies(res.conf.dependencies),
availablePlugins: res.conf.plugins,
components: componentsInfo,
componentsReleases,
Expand Down
8 changes: 8 additions & 0 deletions src/registry/views/components-dependencies.pug
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#components-dependencies.box
each dependency in availableDependencies
.componentRow.row.table
a(href=dependency.link, target="_blank")
if dependency.core
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you think we should list core dependencies?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Core deps are subject to be whitelisted too, so I think it's useful to show them. You can see 'url' in the screenshot example

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, I see. I thought they were implicitly available for us 😊

p.release #{dependency.name} (node.js core dependency)
else
p.release #{dependency.name}@#{dependency.version}
5 changes: 5 additions & 0 deletions src/registry/views/index.pug
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,17 @@ block content

h2#menuList
a(href="#components-list" class="tab-link") Components

if componentsHistory
|  | 
a(href="#components-history" class="tab-link") History

|  | 
a(href="#components-dependencies" class="tab-link") Available dependencies

include components-list
include components-history
include components-dependencies

block scripts
script
Expand Down
35 changes: 35 additions & 0 deletions test/unit/registry-routes-helpers-get-available-dependencies.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
'use strict';

const expect = require('chai').expect;
const injectr = require('injectr');

describe('registry : routes : helpers : get-available-dependencies', () => {

const getAvailableDependencies = injectr('../../src/registry/routes/helpers/get-available-dependencies.js', {
'builtin-modules': ['url'],
'../../domain/require-wrapper': () => (pathToPackageJson) => ({
version: '1.2.3',
homepage: `https://${pathToPackageJson.split('\/')[0]}.com/`
})
});

describe('happy path', () => {

let result;
before(() => result = getAvailableDependencies(['moment', 'url']));

it('should map to structured view-model', () => {
expect(result).to.eql([{
core: false,
name: 'moment',
version: '1.2.3',
link: 'https://moment.com/'
}, {
core: true,
name: 'url',
version: false,
link: 'https://nodejs.org/api/url.html'
}]);
});
});
});