aboutsummaryrefslogtreecommitdiff
path: root/node_modules/enhanced-resolve/lib/SymlinkPlugin.js
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/enhanced-resolve/lib/SymlinkPlugin.js')
-rw-r--r--node_modules/enhanced-resolve/lib/SymlinkPlugin.js49
1 files changed, 49 insertions, 0 deletions
diff --git a/node_modules/enhanced-resolve/lib/SymlinkPlugin.js b/node_modules/enhanced-resolve/lib/SymlinkPlugin.js
new file mode 100644
index 000000000..85caf36da
--- /dev/null
+++ b/node_modules/enhanced-resolve/lib/SymlinkPlugin.js
@@ -0,0 +1,49 @@
+/*
+ MIT License http://www.opensource.org/licenses/mit-license.php
+ Author Tobias Koppers @sokra
+*/
+var getPaths = require("./getPaths");
+var forEachBail = require("./forEachBail");
+
+function SymlinkPlugin(source, target) {
+ this.source = source;
+ this.target = target;
+}
+module.exports = SymlinkPlugin;
+
+SymlinkPlugin.prototype.apply = function(resolver) {
+ var target = this.target;
+ resolver.plugin(this.source, function(request, callback) {
+ var _this = this;
+ var fs = _this.fileSystem;
+ var pathsResult = getPaths(request.path);
+ var pathSeqments = pathsResult.seqments;
+ var paths = pathsResult.paths;
+
+ var containsSymlink = false;
+ forEachBail(paths.map(function(_, i) {
+ return i;
+ }), function(idx, callback) {
+ fs.readlink(paths[idx], function(err, result) {
+ if(!err && result) {
+ pathSeqments[idx] = result;
+ containsSymlink = true;
+ // Shortcut when absolute symlink found
+ if(/^(\/|[a-zA-z]:($|\\))/.test(result))
+ return callback(null, idx);
+ }
+ callback();
+ });
+ }, function(err, idx) {
+ if(!containsSymlink) return callback();
+ var resultSeqments = typeof idx === "number" ? pathSeqments.slice(0, idx + 1) : pathSeqments.slice();
+ var result = resultSeqments.reverse().reduce(function(a, b) {
+ return _this.join(a, b);
+ });
+ var obj = Object.assign({}, request, {
+ path: result
+ });
+ resolver.doResolve(target, obj, "resolved symlink to " + result, callback);
+ });
+ });
+};