Comparing version 1.2.0 to 1.3.0
27
index.js
@@ -6,2 +6,3 @@ 'use strict'; | ||
var isDevelopment = !env || env === 'dev' || env === 'development'; | ||
var showModuleComplains = typeof process !== 'undefined' && Boolean(process.env.SHOW_MODULE_COMPLAINS); | ||
var logger = typeof console !== 'undefined' && console.warn && console; | ||
@@ -22,5 +23,6 @@ var cwd = typeof process !== 'undefined' && process.cwd() + '/' || ''; | ||
complain.colors = { warning:'\x1b[31;1m', message:false, location:'\u001b[90m' }; | ||
complain.getModuleName = getModuleName; | ||
/* istanbul ignore next */ | ||
if(typeof module !== 'undefined' && module.exports) { | ||
if (typeof module !== 'undefined' && module.exports) { | ||
module.exports = complain; | ||
@@ -55,3 +57,16 @@ } else if(typeof window !== 'undefined') { | ||
location = options.location || getLocation(getCallToDeprecate); | ||
var moduleName = complain.getModuleName(location); | ||
if (moduleName && !showModuleComplains) { | ||
if (!hits[moduleName]) { | ||
var output = format('WARNING!!', complain.colors.warning) | ||
output += linebreak + format('The module ['+moduleName+'] is using deprecated features.', complain.colors.message); | ||
output += linebreak + format('Run with process.env.SHOW_MODULE_COMPLAINS=1 to see all warnings.', complain.colors.message); | ||
complain.log(linebreak + output + linebreak); | ||
hits[moduleName] = true; | ||
} | ||
return; | ||
} | ||
/* istanbul ignore next */ | ||
@@ -133,3 +148,13 @@ // Location is only missing in older browsers. | ||
function getModuleName(location) { | ||
var locationParts = location.replace(cwd, '').split(/\/|\\/g); | ||
for(var i = locationParts.length-1; i >= 0; i--) { | ||
if (locationParts[i] === 'node_modules') { | ||
var moduleName = locationParts[i+1]; | ||
return (moduleName[0] === '@') ? moduleName+'/'+locationParts[i+2] : moduleName; | ||
} | ||
} | ||
} | ||
function noop(){}; | ||
function noopReturn(r) { return r; }; |
{ | ||
"name": "complain", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"description": "Mark methods as deprecated and warn the user when they're called", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -92,4 +92,10 @@ # complain | ||
### complain.getModuleName(location) | ||
The function that determines if a complaint is coming from a `node_module`. If the location for a complaint is inside a dependent module, a single generic warning is logged once per module. You can replace this with your own function for environments (like browsers) that might not have `node_modules` in the path. | ||
> Run with the enviornment variable SHOW_MODULE_COMPLAINS=1 to disable the generic module warning | ||
## 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
Debug access
Supply chain riskUses debug, reflection and dynamic code execution features.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
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
15296
7
302
101
5