MCPcopy Create free account
hub / github.com/cujojs/poly / localRequire

Function localRequire

test/curl.js:240–268  ·  view source on GitHub ↗
(ids, callback)

Source from the content-addressed store, hash-verified

238 }
239
240 function localRequire (ids, callback) {
241 var cb, rvid, childDef, earlyExport;
242
243 // this is public, so send pure function
244 // also fixes issue #41
245 cb = callback && function () { callback.apply(undef, arguments[0]); };
246
247 // RValue require (CommonJS)
248 if (isType(ids, 'String')) {
249 // return resource
250 rvid = toAbsId(ids);
251 childDef = cache[rvid];
252 earlyExport = isPromise(childDef) && childDef.exports;
253 if (!(rvid in cache)) {
254 // this should only happen when devs attempt their own
255 // manual wrapping of cjs modules or get confused with
256 // the callback syntax:
257 throw new Error('Module not resolved: ' + rvid);
258 }
259 if (cb) {
260 throw new Error('require(id, callback) not allowed');
261 }
262 return earlyExport || childDef;
263 }
264 else {
265 // use same id so that relative modules are normalized correctly
266 when(core.getDeps(core.createContext(cfg, def.id, ids, isPreload)), cb);
267 }
268 }
269
270 def.require = localRequire;
271 localRequire['toUrl'] = toUrl;

Callers

nothing calls this directly

Calls 4

isTypeFunction · 0.85
toAbsIdFunction · 0.85
isPromiseFunction · 0.85
whenFunction · 0.85

Tested by

no test coverage detected