Skip to content

Commit 1124fd4

Browse files
committed
We now estimate the resolved module path before resolving using node-resolve to
see if the resolved path matches any file in `options.excludeFiles`; previously, it was a lot more likely that missing files in the `excludeFiles` array would throw an error Push to 2.1.4
1 parent 4a1ff16 commit 1124fd4

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

lib/moduleConcatStream.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,10 +202,23 @@ class ModuleConcatStream extends Readable {
202202
opts.excludeNodeModules.indexOf(modulePath) >= 0
203203
) )
204204
{
205+
// Module is excluded; do not replace
205206
return match;
206207
}
207208
// Get ready to resolve the module
208209
opts.basedir = path.dirname(filePath);
210+
/* Take a guess on the resolved path and ignore any modules
211+
found in `excludeFiles` array */
212+
let estResolvedPath = modulePath.charAt(0) === "/" ?
213+
modulePath :
214+
path.resolve(opts.basedir + "/" + modulePath);
215+
if(opts.excludeFiles.indexOf(estResolvedPath) >= 0 ||
216+
opts.extensions.some((ext) =>
217+
opts.excludeFiles.indexOf(estResolvedPath + ext) >= 0) )
218+
{
219+
// File is excluded; do not replace
220+
return match;
221+
}
209222
// Thank you, node-resolve for making this easy!
210223
try {
211224
// Resolve the module path
@@ -223,7 +236,9 @@ class ModuleConcatStream extends Readable {
223236
// Lookup this module's ID
224237
var index = this._files.indexOf(modulePath);
225238
if(index < 0) {
226-
// Not added to project yet; try to add it
239+
/* Not added to project yet; try to add it after we
240+
double check to see if we should exclude it or not.
241+
*/
227242
if(opts.excludeFiles.indexOf(modulePath) < 0)
228243
{
229244
// Not excluded, so we're good to go!

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "module-concat",
3-
"version": "2.1.2",
3+
"version": "2.1.4",
44
"description": "Lightweight CommonJS module concatenation tool",
55
"main": "index.js",
66
"dependencies": {

0 commit comments

Comments
 (0)