Skip to content

Commit

Permalink
fix: print deprecation warning only when plugin is used
Browse files Browse the repository at this point in the history
  • Loading branch information
zardoy committed May 13, 2022
1 parent 80608c6 commit fc19f1b
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions lib/postcss.js
Expand Up @@ -27,25 +27,27 @@ function postcss(...plugins) {
}

postcss.plugin = function plugin(name, initializer) {
// eslint-disable-next-line no-console
if (console && console.warn) {
let warningPrinted = false
function creator(...args) {
// eslint-disable-next-line no-console
console.warn(
name +
': postcss.plugin was deprecated. Migration guide:\n' +
'https://evilmartians.com/chronicles/postcss-8-plugin-migration'
)
if (process.env.LANG && process.env.LANG.startsWith('cn')) {
/* c8 ignore next 7 */
if (console && console.warn && !warningPrinted) {
warningPrinted = true
// eslint-disable-next-line no-console
console.warn(
name +
': 里面 postcss.plugin 被弃用. 迁移指南:\n' +
'https://www.w3ctech.com/topic/2226'
': postcss.plugin was deprecated. Migration guide:\n' +
'https://evilmartians.com/chronicles/postcss-8-plugin-migration'
)
if (process.env.LANG && process.env.LANG.startsWith('cn')) {
/* c8 ignore next 7 */
// eslint-disable-next-line no-console
console.warn(
name +
': 里面 postcss.plugin 被弃用. 迁移指南:\n' +
'https://www.w3ctech.com/topic/2226'
)
}
}
}
function creator(...args) {
let transformer = initializer(...args)
transformer.postcssPlugin = name
transformer.postcssVersion = new Processor().version
Expand Down

0 comments on commit fc19f1b

Please sign in to comment.