1 |
|
2 | void function () {
|
3 | var canonicalise, CORE_MODULES, fs, isCore, path, resolve, resolvePath;
|
4 | fs = require('fs');
|
5 | path = require('path');
|
6 | resolve = require('resolve').sync;
|
7 | CORE_MODULES = require('./core-modules');
|
8 | isCore = require('./is-core');
|
9 | canonicalise = require('./canonicalise');
|
10 | resolvePath = function (param$) {
|
11 | var aliases, cache$, corePath, cwd, e, extensions, givenPath, root;
|
12 | {
|
13 | cache$ = param$;
|
14 | extensions = cache$.extensions;
|
15 | aliases = cache$.aliases;
|
16 | root = cache$.root;
|
17 | cwd = cache$.cwd;
|
18 | givenPath = cache$.path;
|
19 | }
|
20 | if (null != aliases)
|
21 | aliases;
|
22 | else
|
23 | aliases = {};
|
24 | if (isCore(givenPath)) {
|
25 | if ({}.hasOwnProperty.call(aliases, givenPath))
|
26 | return;
|
27 | corePath = CORE_MODULES[givenPath];
|
28 | if (!fs.existsSync(corePath))
|
29 | throw new Error('Core module "' + givenPath + '" has not yet been ported to the browser');
|
30 | givenPath = corePath;
|
31 | }
|
32 | try {
|
33 | return resolve(givenPath, {
|
34 | extensions: extensions,
|
35 | basedir: cwd || root
|
36 | });
|
37 | } catch (e$) {
|
38 | e = e$;
|
39 | try {
|
40 | return resolve(path.join(root, givenPath), { extensions: extensions });
|
41 | } catch (e$1) {
|
42 | e = e$1;
|
43 | throw new Error('Cannot find module "' + givenPath + '" in "' + root + '"');
|
44 | }
|
45 | }
|
46 | };
|
47 | module.exports = function (param$) {
|
48 | var aliases, cache$, canonicalName, cwd, extensions, givenPath, resolved, root;
|
49 | {
|
50 | cache$ = param$;
|
51 | extensions = cache$.extensions;
|
52 | aliases = cache$.aliases;
|
53 | root = cache$.root;
|
54 | cwd = cache$.cwd;
|
55 | givenPath = cache$.path;
|
56 | }
|
57 | if (null != aliases)
|
58 | aliases;
|
59 | else
|
60 | aliases = {};
|
61 | resolved = resolvePath({
|
62 | extensions: extensions,
|
63 | aliases: aliases,
|
64 | root: root,
|
65 | cwd: cwd,
|
66 | path: givenPath
|
67 | });
|
68 | canonicalName = isCore(givenPath) ? givenPath : canonicalise(root, resolved);
|
69 | if ({}.hasOwnProperty.call(aliases, canonicalName))
|
70 | resolved = aliases[canonicalName] && resolvePath({
|
71 | extensions: extensions,
|
72 | aliases: aliases,
|
73 | root: root,
|
74 | path: aliases[canonicalName]
|
75 | });
|
76 | return {
|
77 | filename: resolved,
|
78 | canonicalName: canonicalName
|
79 | };
|
80 | };
|
81 | }.call(this);
|