This repository has been archived by the owner on Mar 18, 2019. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a warning for custom property sets that are going to be removed +…
… an option to hide the warning
- Loading branch information
Showing
5 changed files
with
113 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import tape from "tape" | ||
|
||
import postcss from "postcss" | ||
import cssnext from ".." | ||
import { resetWarning } from "../warn-for-deprecations" | ||
|
||
const reportFail = (t) => (error) => { | ||
console.log(error) | ||
t.fail() | ||
} | ||
|
||
tape("cssnext warnForDeprecation option", (t) => { | ||
const messages = [] | ||
resetWarning() | ||
const instance = postcss([ | ||
cssnext({ | ||
console: { log: (msg) => messages.push(msg) }, | ||
}), | ||
]) | ||
|
||
instance.process("body{}").then(() => { | ||
t.equal( | ||
messages.length, | ||
0, | ||
"should not add warning there is no deprecated stuff" | ||
) | ||
t.end() | ||
}, reportFail(t)) | ||
}) | ||
|
||
tape("cssnext warnForDeprecation option", (t) => { | ||
const messages = [] | ||
resetWarning() | ||
const instance = postcss([ | ||
cssnext({ | ||
console: { log: (msg) => messages.push(msg) }, | ||
}), | ||
]) | ||
|
||
instance.process(` | ||
:root { | ||
--toolbar-theme: { | ||
border: 1px solid green; | ||
}; | ||
} | ||
.Toolbar { | ||
@apply --toolbar-theme; | ||
@apply --toolbar-theme; | ||
} | ||
`) | ||
.then(() => { | ||
t.equal( | ||
messages.length, | ||
1, | ||
"should add a single warning if there are deprecated stuff" | ||
) | ||
t.end() | ||
}, reportFail(t)) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import postcss from "postcss" | ||
import color from "chalk" | ||
|
||
let shouldGlobalWarn = true | ||
export const resetWarning = () => shouldGlobalWarn = true | ||
|
||
const warnForDeprecations = postcss.plugin( | ||
"postcss-cssnext-warn-for-deprecations", | ||
({ console: messenger }) => { | ||
return (style) => { | ||
// warn for removed @apply | ||
style.walkAtRules("apply", () => { | ||
if (shouldGlobalWarn) { | ||
shouldGlobalWarn = false | ||
messenger.log( | ||
color.yellow.bold( | ||
"You are using @apply rule and custom property sets. \n" + | ||
|
||
"This feature won't be included in next the major release "+ | ||
"of postcss-cssnext. \n" | ||
) + | ||
|
||
color.grey( | ||
"This most likely won't get any more support from browser vendors as the " + | ||
"spec is yet considered deprecated and alternative solutions are being "+ | ||
"discussed. \n" | ||
) + | ||
|
||
"Read more about the reason here https://github.com/pascalduez/postcss-apply." | ||
) | ||
} | ||
}) | ||
} | ||
} | ||
) | ||
|
||
export default warnForDeprecations |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters