1 |
3a515b92
|
cagy
|
/*
|
2 |
|
|
MIT License http://www.opensource.org/licenses/mit-license.php
|
3 |
|
|
Author Tobias Koppers @sokra
|
4 |
|
|
*/
|
5 |
|
|
"use strict";
|
6 |
|
|
|
7 |
|
|
const ResolverFactory = require("./ResolverFactory");
|
8 |
|
|
|
9 |
|
|
const NodeJsInputFileSystem = require("./NodeJsInputFileSystem");
|
10 |
|
|
const CachedInputFileSystem = require("./CachedInputFileSystem");
|
11 |
|
|
|
12 |
|
|
const nodeFileSystem = new CachedInputFileSystem(new NodeJsInputFileSystem(), 4000);
|
13 |
|
|
|
14 |
|
|
const nodeContext = {
|
15 |
|
|
environments: [
|
16 |
|
|
"node+es3+es5+process+native"
|
17 |
|
|
]
|
18 |
|
|
};
|
19 |
|
|
|
20 |
|
|
const asyncResolver = ResolverFactory.createResolver({
|
21 |
|
|
extensions: [".js", ".json", ".node"],
|
22 |
|
|
fileSystem: nodeFileSystem
|
23 |
|
|
});
|
24 |
|
|
module.exports = function resolve(context, path, request, resolveContext, callback) {
|
25 |
|
|
if(typeof context === "string") {
|
26 |
|
|
callback = resolveContext;
|
27 |
|
|
resolveContext = request;
|
28 |
|
|
request = path;
|
29 |
|
|
path = context;
|
30 |
|
|
context = nodeContext;
|
31 |
|
|
}
|
32 |
|
|
if(typeof callback !== "function") {
|
33 |
|
|
callback = resolveContext;
|
34 |
|
|
}
|
35 |
|
|
asyncResolver.resolve(context, path, request, resolveContext, callback);
|
36 |
|
|
};
|
37 |
|
|
|
38 |
|
|
const syncResolver = ResolverFactory.createResolver({
|
39 |
|
|
extensions: [".js", ".json", ".node"],
|
40 |
|
|
useSyncFileSystemCalls: true,
|
41 |
|
|
fileSystem: nodeFileSystem
|
42 |
|
|
});
|
43 |
|
|
module.exports.sync = function resolveSync(context, path, request) {
|
44 |
|
|
if(typeof context === "string") {
|
45 |
|
|
request = path;
|
46 |
|
|
path = context;
|
47 |
|
|
context = nodeContext;
|
48 |
|
|
}
|
49 |
|
|
return syncResolver.resolveSync(context, path, request);
|
50 |
|
|
};
|
51 |
|
|
|
52 |
|
|
const asyncContextResolver = ResolverFactory.createResolver({
|
53 |
|
|
extensions: [".js", ".json", ".node"],
|
54 |
|
|
resolveToContext: true,
|
55 |
|
|
fileSystem: nodeFileSystem
|
56 |
|
|
});
|
57 |
|
|
module.exports.context = function resolveContext(context, path, request, resolveContext, callback) {
|
58 |
|
|
if(typeof context === "string") {
|
59 |
|
|
callback = resolveContext;
|
60 |
|
|
resolveContext = request;
|
61 |
|
|
request = path;
|
62 |
|
|
path = context;
|
63 |
|
|
context = nodeContext;
|
64 |
|
|
}
|
65 |
|
|
if(typeof callback !== "function") {
|
66 |
|
|
callback = resolveContext;
|
67 |
|
|
}
|
68 |
|
|
asyncContextResolver.resolve(context, path, request, resolveContext, callback);
|
69 |
|
|
};
|
70 |
|
|
|
71 |
|
|
const syncContextResolver = ResolverFactory.createResolver({
|
72 |
|
|
extensions: [".js", ".json", ".node"],
|
73 |
|
|
resolveToContext: true,
|
74 |
|
|
useSyncFileSystemCalls: true,
|
75 |
|
|
fileSystem: nodeFileSystem
|
76 |
|
|
});
|
77 |
|
|
module.exports.context.sync = function resolveContextSync(context, path, request) {
|
78 |
|
|
if(typeof context === "string") {
|
79 |
|
|
request = path;
|
80 |
|
|
path = context;
|
81 |
|
|
context = nodeContext;
|
82 |
|
|
}
|
83 |
|
|
return syncContextResolver.resolveSync(context, path, request);
|
84 |
|
|
};
|
85 |
|
|
|
86 |
|
|
const asyncLoaderResolver = ResolverFactory.createResolver({
|
87 |
|
|
extensions: [".js", ".json", ".node"],
|
88 |
|
|
moduleExtensions: ["-loader"],
|
89 |
|
|
mainFields: ["loader", "main"],
|
90 |
|
|
fileSystem: nodeFileSystem
|
91 |
|
|
});
|
92 |
|
|
module.exports.loader = function resolveLoader(context, path, request, resolveContext, callback) {
|
93 |
|
|
if(typeof context === "string") {
|
94 |
|
|
callback = resolveContext;
|
95 |
|
|
resolveContext = request;
|
96 |
|
|
request = path;
|
97 |
|
|
path = context;
|
98 |
|
|
context = nodeContext;
|
99 |
|
|
}
|
100 |
|
|
if(typeof callback !== "function") {
|
101 |
|
|
callback = resolveContext;
|
102 |
|
|
}
|
103 |
|
|
asyncLoaderResolver.resolve(context, path, request, resolveContext, callback);
|
104 |
|
|
};
|
105 |
|
|
|
106 |
|
|
const syncLoaderResolver = ResolverFactory.createResolver({
|
107 |
|
|
extensions: [".js", ".json", ".node"],
|
108 |
|
|
moduleExtensions: ["-loader"],
|
109 |
|
|
mainFields: ["loader", "main"],
|
110 |
|
|
useSyncFileSystemCalls: true,
|
111 |
|
|
fileSystem: nodeFileSystem
|
112 |
|
|
});
|
113 |
|
|
module.exports.loader.sync = function resolveLoaderSync(context, path, request) {
|
114 |
|
|
if(typeof context === "string") {
|
115 |
|
|
request = path;
|
116 |
|
|
path = context;
|
117 |
|
|
context = nodeContext;
|
118 |
|
|
}
|
119 |
|
|
return syncLoaderResolver.resolveSync(context, path, request);
|
120 |
|
|
};
|
121 |
|
|
|
122 |
|
|
module.exports.create = function create(options) {
|
123 |
|
|
options = Object.assign({
|
124 |
|
|
fileSystem: nodeFileSystem
|
125 |
|
|
}, options);
|
126 |
|
|
const resolver = ResolverFactory.createResolver(options);
|
127 |
|
|
return function(context, path, request, resolveContext, callback) {
|
128 |
|
|
if(typeof context === "string") {
|
129 |
|
|
callback = resolveContext;
|
130 |
|
|
resolveContext = request;
|
131 |
|
|
request = path;
|
132 |
|
|
path = context;
|
133 |
|
|
context = nodeContext;
|
134 |
|
|
}
|
135 |
|
|
if(typeof callback !== "function") {
|
136 |
|
|
callback = resolveContext;
|
137 |
|
|
}
|
138 |
|
|
resolver.resolve(context, path, request, resolveContext, callback);
|
139 |
|
|
};
|
140 |
|
|
};
|
141 |
|
|
|
142 |
|
|
module.exports.create.sync = function createSync(options) {
|
143 |
|
|
options = Object.assign({
|
144 |
|
|
useSyncFileSystemCalls: true,
|
145 |
|
|
fileSystem: nodeFileSystem
|
146 |
|
|
}, options);
|
147 |
|
|
const resolver = ResolverFactory.createResolver(options);
|
148 |
|
|
return function(context, path, request) {
|
149 |
|
|
if(typeof context === "string") {
|
150 |
|
|
request = path;
|
151 |
|
|
path = context;
|
152 |
|
|
context = nodeContext;
|
153 |
|
|
}
|
154 |
|
|
return resolver.resolveSync(context, path, request);
|
155 |
|
|
};
|
156 |
|
|
};
|
157 |
|
|
|
158 |
|
|
// Export Resolver, FileSystems and Plugins
|
159 |
|
|
module.exports.ResolverFactory = ResolverFactory;
|
160 |
|
|
|
161 |
|
|
module.exports.NodeJsInputFileSystem = NodeJsInputFileSystem;
|
162 |
|
|
module.exports.CachedInputFileSystem = CachedInputFileSystem;
|