|
4 | 4 | */ |
5 | 5 | var parse = require("./parse"); |
6 | 6 | var resolve = require("./resolve"); |
| 7 | +var execLoaders = require("./execLoaders"); |
7 | 8 | var fs = require("fs"); |
8 | 9 | var path = require("path"); |
9 | 10 | var assert = require("assert"); |
@@ -72,85 +73,6 @@ module.exports = function buildDeps(context, mainModule, options, callback) { |
72 | 73 | } |
73 | 74 | } |
74 | 75 |
|
75 | | -function execLoaders(request, loaders, filenames, contents, options, callback) { |
76 | | - if(loaders.length === 0) |
77 | | - callback(null, contents[0]); |
78 | | - else { |
79 | | - var loaderFunctions = []; |
80 | | - try { |
81 | | - loaders.forEach(function(name) { |
82 | | - var loader = require(name); |
83 | | - loaderFunctions.push(loader); |
84 | | - }); |
85 | | - } catch(e) { |
86 | | - callback(e); |
87 | | - return; |
88 | | - } |
89 | | - function nextLoader() { |
90 | | - var args = Array.prototype.slice.apply(arguments); |
91 | | - var err = args.shift(); |
92 | | - if(err) { |
93 | | - callback(err); |
94 | | - return; |
95 | | - } |
96 | | - if(loaderFunctions.length > 0) { |
97 | | - var async = false; |
98 | | - var done = false; |
99 | | - try { |
100 | | - var context = { |
101 | | - request: request, |
102 | | - filenames: filenames, |
103 | | - exec: function(code, filename) { |
104 | | - var Module = require("module"); |
105 | | - var m = new Module("exec in " + request, module); |
106 | | - m.filename = filenames[0]; |
107 | | - m._compile(code, filename); |
108 | | - return m.exports; |
109 | | - }, |
110 | | - resolve: function(context, path, cb) { |
111 | | - resolve(context, "!"+path, options.resolve, cb); |
112 | | - }, |
113 | | - async: function() { |
114 | | - async = true; |
115 | | - return nextLoader; |
116 | | - }, |
117 | | - callback: function() { |
118 | | - async = true; |
119 | | - assert(!done); |
120 | | - done = true; |
121 | | - nextLoader.apply(null, arguments); |
122 | | - }, |
123 | | - web: true, |
124 | | - debug: options.debug, |
125 | | - minimize: options.minimize, |
126 | | - values: undefined, |
127 | | - options: options |
128 | | - }; |
129 | | - var retVal = loaderFunctions.pop().apply(context, args); |
130 | | - if(!async) { |
131 | | - done = true; |
132 | | - nextLoader(retVal === undefined ? new Error("loader did not return a value") : null, retVal); |
133 | | - } |
134 | | - } catch(e) { |
135 | | - if(!done) { |
136 | | - done = true; |
137 | | - callback("Loader throwed exeception: " + (e.stack ? e.stack : e)); |
138 | | - } else { |
139 | | - if(e.stack) console.error(e.stack); |
140 | | - else console.error(e); |
141 | | - } |
142 | | - return; |
143 | | - } |
144 | | - } else { |
145 | | - callback(null, args[0]); |
146 | | - } |
147 | | - } |
148 | | - contents.unshift(null); |
149 | | - nextLoader.apply(null, contents); |
150 | | - } |
151 | | - |
152 | | -} |
153 | | - |
154 | 76 | function addModule(depTree, context, modu, options, reason, finalCallback) { |
155 | 77 | options.events.emit("task"); |
156 | 78 | function callback(err, result) { |
@@ -178,7 +100,7 @@ function addModule(depTree, context, modu, options, reason, finalCallback) { |
178 | 100 | var loaders = filename.split(/!/g); |
179 | 101 | filename = loaders.pop(); |
180 | 102 | options.events.emit("module", modu, filename); |
181 | | - fs.readFile(filename, "utf-8", function(err, content) { |
| 103 | + fs.readFile(filename, function(err, content) { |
182 | 104 | if(err) { |
183 | 105 | callback(err); |
184 | 106 | return; |
|
0 commit comments