append-transform
Advanced tools
Comparing version 0.2.2 to 0.3.0
15
index.js
@@ -8,3 +8,4 @@ 'use strict'; | ||
function appendTransform(transform, ext, extensions) { | ||
var key = __dirname + count; | ||
// Generate a unique key for this transform | ||
var key = __dirname + count; // eslint-disable-line | ||
count++; | ||
@@ -17,3 +18,3 @@ ext = ext || '.js'; | ||
var descriptor = Object.getOwnPropertyDescriptor(extensions, ext); | ||
var descriptor = Object.getOwnPropertyDescriptor(extensions, ext) || {value: undefined, configurable: true}; | ||
@@ -28,2 +29,3 @@ if ( | ||
if (descriptor.get) { | ||
// wrap a previous append-transform install and pass through to the getter/setter pair it created | ||
forwardGet = function () { | ||
@@ -46,4 +48,12 @@ return descriptor.get(); | ||
function hookWasUndefined(module, filename) { | ||
throw new Error('Can not load ' + filename + '. No require extension has been installed for ' + ext + ' files'); | ||
} | ||
function wrapCustomHook(hook) { | ||
if (hook === undefined) { | ||
return hookWasUndefined; | ||
} | ||
return function (module, filename) { | ||
// We wrap every added extension, but we only apply the transform to the one on top of the stack | ||
if (!module[key]) { | ||
@@ -75,2 +85,3 @@ module[key] = true; | ||
} else { | ||
// we have already scene this hook, and it is being reverted (proxyquire, etc) - don't wrap again. | ||
hooks.splice(restoreIndex + 1, hooks.length); | ||
@@ -77,0 +88,0 @@ forwardSet(hook); |
{ | ||
"name": "append-transform", | ||
"version": "0.2.2", | ||
"version": "0.3.0", | ||
"description": "Install a transform to `require.extensions` that always runs last, even if additional extensions are added later.", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7865
77