
Security News
The Changelog Podcast: Practical Steps to Stay Safe on npm
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.
babel-plugin-log-deprecated
Advanced tools
Adds a console.warn statement to the functions annotated with @deprecated tag.
Adds a console.warn statement to the functions annotated with the JSDoc @deprecated tag.
The console.warn is added at the beginning of the function body.
Input:
/**
* @deprecated Deprecated in favour of quux.
*/
function foo () {
bar();
};
Output:
/**
* @deprecated Deprecated in favour of quux.
*/
function foo () {
console.warn("Deprecated: Function \"foo\" is deprecated in /fixtures/preset-options/adds-console-warn-to-function-declaration/actual.js on line 4", {
functionName: "foo",
message: "Deprecated in favour of quux.",
packageName: "bar",
packageVersion: "1.0.0",
scriptColumn: 0,
scriptLine: 4,
scriptPath: "fixtures/preset-options/adds-console-warn-to-function-declaration/actual.js"
});
bar();
};
Working on a code base that has a large public API surface requires a method to instruct the consumer about deprecation of methods. The most common approach at the moment is to add an ad-hoc console.warn statement used to warn the consumer. There are multiple problems with this approach:
@deprecated tag.console.log messages that can be hard to filter out.To address these issues, babel-plugin-log-deprecated:
@deprecated tag to construct the deprecation log message property.package.json configuration, script path) to enrich the deprecation message.This transpiler can be used to produce code for client-side use and Node.js. Whether to leave the warnings in the production build depends on the use case.
Regarding the client-side use, I have been asked:
inu-no-policemen:
Wouldn't it make more sense to get these messages at compile time?
Messages which only appear if a particular path is taken through the application are easy to miss.
I am using this plugin to add warning messages that are visible at a runtime on purpose. Think about large organizations that have multiple teams working on a frontend of the same website. There is a lot of code in the window namespace:
| Website | Object.keys(window).length |
|---|---|
| https://www.google.com/blank.html | 181 (base figure) |
| https://www.ft.com/ | 229 (+48) |
| https://www.theguardian.com/uk | 269 (+88) |
| http://www.dailymail.co.uk/home/index.html | 599 (+418) |
| http://time.com/ | 669 (+488) |
Furthermore, this is just the count of the properties in the window namespace. A number of these properties will expose complex APIs that tie together the entire website (think user targeting, advertising, utilities, etc.).
You cannot simply remove properties because you risk of breaking things. Therefore, a sensible solution is to communicate the upcoming changes to the other teams and add deprecation warnings well ahead of making the change.
In a similar fashion, a public library can use the deprecation warning to inform the consumers of the upcoming changes.
| Name | Value |
|---|---|
functionName | Name of the function that has the @deprecated tag associated with. In case of an anonymous function - name of the left hand side identifier. |
message | Message provided in the description of the JSDoc @deprecated tag |
packageName | Value of the name property in the package.json. See package.json resolution. |
packageVersion | Value of the version property in the package.json. See package.json resolution. |
scriptColumn | Number of the column where the function is declared. |
scriptLine | Number of the line where the function is declared. |
scriptPath | Path to the script file relative to package.json. See package.json resolution. |
package.json resolutionpackage.json is resolved relative to the file being transpiled.
FAQs
Adds a console.warn statement to the functions annotated with @deprecated tag.
We found that babel-plugin-log-deprecated demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.

Security News
Ruby's creator Matz assumes control of RubyGems and Bundler repositories while former maintainers agree to step back and transfer all rights to end the dispute.