Skip to content
Open
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
11 changes: 11 additions & 0 deletions packages/oc-external-dependencies-handler/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ const coreModules = require('builtin-modules');
const strings = require('oc-templates-messages');
const _ = require('lodash');

function getPosition(string, subString, index) {
return string.split(subString, index).join(subString).length;
}


module.exports = dependencies => {
const deps = dependencies || {};

Expand All @@ -30,6 +35,12 @@ module.exports = dependencies => {
dependencyName.indexOf('/')
);
}
if (/^(@).*\//g.test(dependencyName)) {
dependencyName = dependencyName.substring(
0,
getPosition(dependencyName, "/", 2)
);
}
if (missingExternalDependency(dependencyName, deps)) {
return callback(
new Error(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ test('The handler matcher should correctly match aganinst valid modules', () =>
expect(handlerMatcher.test('@org/module/path')).toBe(true);
});

test('The handler function should detect valid scoped modules that import paths', (done) => {
const handler = externalDependenciesHandler({ lodash: '4.17.4', "@org/module": '1.0.0' });
const handlerFunction = handler[0];

handlerFunction({ request: '@org/module/path' }, err => {
expect(err).toBeUndefined();
done();
});
});

test('The handler matcher should correctly match aganinst not valid modules', () => {
const handler = externalDependenciesHandler({ lodash: '4.17.4' });
const handlerMatcher = handler[1];
Expand Down