UNPKG

commonjs-everywhere

Version:

CommonJS browser bundler with aliasing, extensibility, and source maps from the minified JS bundle

82 lines (81 loc) 2.34 kB
// Generated by CoffeeScript 2.0.0-beta7 void function () { var canonicalise, CORE_MODULES, fs, isCore, path, resolve, resolvePath; fs = require('fs'); path = require('path'); resolve = require('resolve').sync; CORE_MODULES = require('./core-modules'); isCore = require('./is-core'); canonicalise = require('./canonicalise'); resolvePath = function (param$) { var aliases, cache$, corePath, cwd, e, extensions, givenPath, root; { cache$ = param$; extensions = cache$.extensions; aliases = cache$.aliases; root = cache$.root; cwd = cache$.cwd; givenPath = cache$.path; } if (null != aliases) aliases; else aliases = {}; if (isCore(givenPath)) { if ({}.hasOwnProperty.call(aliases, givenPath)) return; corePath = CORE_MODULES[givenPath]; if (!fs.existsSync(corePath)) throw new Error('Core module "' + givenPath + '" has not yet been ported to the browser'); givenPath = corePath; } try { return resolve(givenPath, { extensions: extensions, basedir: cwd || root }); } catch (e$) { e = e$; try { return resolve(path.join(root, givenPath), { extensions: extensions }); } catch (e$1) { e = e$1; throw new Error('Cannot find module "' + givenPath + '" in "' + root + '"'); } } }; module.exports = function (param$) { var aliases, cache$, canonicalName, cwd, extensions, givenPath, resolved, root; { cache$ = param$; extensions = cache$.extensions; aliases = cache$.aliases; root = cache$.root; cwd = cache$.cwd; givenPath = cache$.path; } if (null != aliases) aliases; else aliases = {}; resolved = resolvePath({ extensions: extensions, aliases: aliases, root: root, cwd: cwd, path: givenPath }); canonicalName = isCore(givenPath) ? givenPath : canonicalise(root, resolved); if ({}.hasOwnProperty.call(aliases, canonicalName)) resolved = aliases[canonicalName] && resolvePath({ extensions: extensions, aliases: aliases, root: root, path: aliases[canonicalName] }); return { filename: resolved, canonicalName: canonicalName }; }; }.call(this);