-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
module.exports = appendTransform; | ||
|
||
function appendTransform(transform, ext, extensions) { | ||
var key = __filename + ':' + Math.random(); // eslint-disable-line | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
novemberborn
|
||
ext = ext || '.js'; | ||
extensions = extensions || require.extensions; | ||
|
||
|
@@ -36,28 +37,24 @@ function appendTransform(transform, ext, extensions) { | |
}; | ||
} | ||
|
||
var isEntry = true; | ||
|
||
function wrapCustomHook(hook) { | ||
return function (module, filename) { | ||
var wasEntry = isEntry; | ||
isEntry = false; | ||
var isEntry = !module[key]; | ||
if (isEntry) { | ||
module[key] = true; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
jamestalmage
Author
Member
|
||
} | ||
|
||
var originalCompile = module._compile; | ||
|
||
module._compile = function replacementCompile(code) { | ||
module._compile = originalCompile; | ||
if (wasEntry) { | ||
if (isEntry) { | ||
code = transform(code, filename); | ||
} | ||
module._compile(code, filename); | ||
}; | ||
|
||
hook(module, filename); | ||
|
||
if (wasEntry) { | ||
isEntry = true; | ||
} | ||
}; | ||
} | ||
|
||
|
I think this could probably be better.
__filename
protects against multiple non-deduped copies ofappend-transform
being used. I don't know thatrandom()
is necessary. I could just increment an integer with every call (if you install more thanNumber.MAX_VALUE
require extensions your system is not going to accomplish much.I'm not sure why I chose random. Maybe to protect against require cache deletions? Seems unlikely.