Skip to content

Commit

Permalink
Update generate-pnp-map-api.tpl.js
Browse files Browse the repository at this point in the history
  • Loading branch information
arcanis committed Oct 22, 2018
1 parent aa4e713 commit 3013ef1
Showing 1 changed file with 37 additions and 4 deletions.
41 changes: 37 additions & 4 deletions src/util/generate-pnp-map-api.tpl.js
Expand Up @@ -646,12 +646,45 @@ exports.setup = function setup() {
if (!enableNativeHooks) {
return originalModuleResolveFilename.call(Module, request, parent, isMain, options);
}

let issuers;

if (options) {
const optionNames = new Set(Object.keys(optionNames));
optionNames.delete('paths');

if (options.size > 0) {
throw makeError(`UNSUPPORTED`, `Some options passed to require() aren't supported by PnP yet (${Array.from(optionNames).join(', ')})`);
}

if (options.paths) {
issuers = options.paths.map(entry => `${path.normalize(entry)}/`);
}
}

if (!issuers) {
const issuerModule = getIssuerModule(parent);
const issuer = issuerModule ? issuerModule.filename : `${process.cwd()}/`;

issuers = [issuer];
}

let firstError;

const issuerModule = getIssuerModule(parent);
const issuer = issuerModule ? issuerModule.filename : process.cwd() + '/';
for (const issuer of issuers) {
let resolution;

try {
resolution = exports.resolveRequest(request, issuer);
} catch (error) {
firstError = firstError || error;
continue;
}

const resolution = exports.resolveRequest(request, issuer);
return resolution !== null ? resolution : request;
return resolution !== null ? resolution : request;
}

throw firstError;
};

const originalFindPath = Module._findPath;
Expand Down

0 comments on commit 3013ef1

Please sign in to comment.