diff --git a/src/registry/routes/helpers/get-available-dependencies.js b/src/registry/routes/helpers/get-available-dependencies.js new file mode 100644 index 000000000..03fb6698c --- /dev/null +++ b/src/registry/routes/helpers/get-available-dependencies.js @@ -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 }; +}); diff --git a/src/registry/routes/index.js b/src/registry/routes/index.js index dce41b0f0..6e19758e4 100644 --- a/src/registry/routes/index.js +++ b/src/registry/routes/index.js @@ -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'); @@ -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, diff --git a/src/registry/views/components-dependencies.pug b/src/registry/views/components-dependencies.pug new file mode 100644 index 000000000..55e3d2f63 --- /dev/null +++ b/src/registry/views/components-dependencies.pug @@ -0,0 +1,8 @@ +#components-dependencies.box + each dependency in availableDependencies + .componentRow.row.table + a(href=dependency.link, target="_blank") + if dependency.core + p.release #{dependency.name} (node.js core dependency) + else + p.release #{dependency.name}@#{dependency.version} diff --git a/src/registry/views/index.pug b/src/registry/views/index.pug index 06e9f74e1..3a82df2f0 100644 --- a/src/registry/views/index.pug +++ b/src/registry/views/index.pug @@ -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 diff --git a/test/unit/registry-routes-helpers-get-available-dependencies.js b/test/unit/registry-routes-helpers-get-available-dependencies.js new file mode 100644 index 000000000..b75727ae1 --- /dev/null +++ b/test/unit/registry-routes-helpers-get-available-dependencies.js @@ -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' + }]); + }); + }); +});