Skip to content
This repository has been archived by the owner on Jan 16, 2023. It is now read-only.

Commit

Permalink
Merge pull request #13 from storybookjs/Hypnosphi-patch-1
Browse files Browse the repository at this point in the history
Support `req.resolve(key)`
  • Loading branch information
kylemh authored Sep 6, 2019
2 parents b360e99 + 89b8abd commit e49d5ff
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions context.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,19 @@ function context(basedir, directory, useSubdirectories = false, regExp = /^\.\//
const absoluteDirectory = path.resolve(basedir, directory);
const keys = enumerateFiles(absoluteDirectory, '.');

function requireContext(key) {
function resolve(key) {
if (!keys.includes(key)) {
throw new Error(`Cannot find module '${key}'.`);
}
const fullKey = require('path').resolve(absoluteDirectory, key);
return require(fullKey);
return require('path').resolve(absoluteDirectory, key);
}

function requireContext(key) {
return require(resolve(fullKey));
}

requireContext.keys = () => keys;
requireContext.resolve = resolve;

return requireContext;
}
Expand Down

0 comments on commit e49d5ff

Please sign in to comment.