Skip to content
This repository was archived by the owner on Dec 19, 2024. It is now read-only.

Commit db0f0fa

Browse files
committedJul 5, 2017
Add a warning for custom property sets that are going to be removed + an option to hide the warning
1 parent cc7c864 commit db0f0fa

File tree

5 files changed

+113
-4
lines changed

5 files changed

+113
-4
lines changed
 

‎docs/content/usage.md

+7
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,13 @@ and show provide duplicates in their examples.
8484
(eg: autoprefixer + cssnext - but cssnext already includes autoprefixer).**
8585
_In order to fix this, here is a warning. You are welcome._
8686

87+
## `warnForDeprecations`
88+
89+
_(default: true)_
90+
91+
This option should be left with its default value, unless you are aware of the
92+
risk and plan to handle the situation.
93+
8794
---
8895

8996
**To know all available options, please check corresponding postcss plugin by
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import tape from "tape"
2+
3+
import postcss from "postcss"
4+
import cssnext from ".."
5+
import { resetWarning } from "../warn-for-deprecations"
6+
7+
const reportFail = (t) => (error) => {
8+
console.log(error)
9+
t.fail()
10+
}
11+
12+
tape("cssnext warnForDeprecation option", (t) => {
13+
const messages = []
14+
resetWarning()
15+
const instance = postcss([
16+
cssnext({
17+
console: { log: (msg) => messages.push(msg) },
18+
}),
19+
])
20+
21+
instance.process("body{}").then(() => {
22+
t.equal(
23+
messages.length,
24+
0,
25+
"should not add warning there is no deprecated stuff"
26+
)
27+
t.end()
28+
}, reportFail(t))
29+
})
30+
31+
tape("cssnext warnForDeprecation option", (t) => {
32+
const messages = []
33+
resetWarning()
34+
const instance = postcss([
35+
cssnext({
36+
console: { log: (msg) => messages.push(msg) },
37+
}),
38+
])
39+
40+
instance.process(`
41+
:root {
42+
--toolbar-theme: {
43+
border: 1px solid green;
44+
};
45+
}
46+
.Toolbar {
47+
@apply --toolbar-theme;
48+
@apply --toolbar-theme;
49+
}
50+
`)
51+
.then(() => {
52+
t.equal(
53+
messages.length,
54+
1,
55+
"should add a single warning if there are deprecated stuff"
56+
)
57+
t.end()
58+
}, reportFail(t))
59+
})

‎src/index.js

+8
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ import { isSupported } from "caniuse-api"
44
import libraryFeatures from "./features"
55
import featuresActivationMap from "./features-activation-map"
66
import warnForDuplicates from "./warn-for-duplicates"
7+
import warnForDeprecations from "./warn-for-deprecations"
78

89
const plugin = postcss.plugin("postcss-cssnext", (options) => {
910
options = {
1011
console: console,
1112
warnForDuplicates: true,
13+
warnForDeprecations: true,
1214
features: {},
1315
// options.browsers is deliberately undefined by default to inherit
1416
// browserslist default behavior
@@ -41,6 +43,12 @@ const plugin = postcss.plugin("postcss-cssnext", (options) => {
4143

4244
const processor = postcss()
4345

46+
if (options.warnForDeprecations) {
47+
processor.use(warnForDeprecations({
48+
console: options.console,
49+
}))
50+
}
51+
4452
// features
4553
Object.keys(libraryFeatures).forEach(key => {
4654
// feature is auto enabled if: not disable && (enabled || no data yet ||

‎src/warn-for-deprecations.js

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import postcss from "postcss"
2+
import color from "chalk"
3+
4+
let shouldGlobalWarn = true
5+
export const resetWarning = () => shouldGlobalWarn = true
6+
7+
const warnForDeprecations = postcss.plugin(
8+
"postcss-cssnext-warn-for-deprecations",
9+
({ console: messenger }) => {
10+
return (style) => {
11+
// warn for removed @apply
12+
style.walkAtRules("apply", () => {
13+
if (shouldGlobalWarn) {
14+
shouldGlobalWarn = false
15+
messenger.log(
16+
color.yellow.bold(
17+
"You are using @apply rule and custom property sets. \n" +
18+
19+
"This feature won't be included in next the major release "+
20+
"of postcss-cssnext. \n"
21+
) +
22+
23+
color.grey(
24+
"This most likely won't get any more support from browser vendors as the " +
25+
"spec is yet considered deprecated and alternative solutions are being "+
26+
"discussed. \n"
27+
) +
28+
29+
"Read more about the reason here https://github.com/pascalduez/postcss-apply."
30+
)
31+
}
32+
})
33+
}
34+
}
35+
)
36+
37+
export default warnForDeprecations

‎src/warn-for-duplicates.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,9 @@ const globalWarning = (
1818
export const spotted = []
1919

2020
const warnForDuplicates = postcss.plugin(
21-
"postcss-warn-for-duplicates",
22-
(options) => {
21+
"postcss-cssnext-warn-for-duplicates",
22+
({ keys, console: messenger }) => {
2323
return (style, result) => {
24-
// https://github.com/postcss/postcss/issues/768
25-
const { keys, console: messenger } = options
2624
const pluginNames = []
2725
result.processor.plugins.forEach((plugin) => {
2826
const name = plugin.postcssPlugin

0 commit comments

Comments
 (0)
This repository has been archived.