[d565449] | 1 | 'use strict'
|
---|
| 2 |
|
---|
| 3 | let CssSyntaxError = require('./css-syntax-error')
|
---|
| 4 | let Declaration = require('./declaration')
|
---|
| 5 | let LazyResult = require('./lazy-result')
|
---|
| 6 | let Container = require('./container')
|
---|
| 7 | let Processor = require('./processor')
|
---|
| 8 | let stringify = require('./stringify')
|
---|
| 9 | let fromJSON = require('./fromJSON')
|
---|
| 10 | let Document = require('./document')
|
---|
| 11 | let Warning = require('./warning')
|
---|
| 12 | let Comment = require('./comment')
|
---|
| 13 | let AtRule = require('./at-rule')
|
---|
| 14 | let Result = require('./result.js')
|
---|
| 15 | let Input = require('./input')
|
---|
| 16 | let parse = require('./parse')
|
---|
| 17 | let list = require('./list')
|
---|
| 18 | let Rule = require('./rule')
|
---|
| 19 | let Root = require('./root')
|
---|
| 20 | let Node = require('./node')
|
---|
| 21 |
|
---|
| 22 | function postcss(...plugins) {
|
---|
| 23 | if (plugins.length === 1 && Array.isArray(plugins[0])) {
|
---|
| 24 | plugins = plugins[0]
|
---|
| 25 | }
|
---|
| 26 | return new Processor(plugins)
|
---|
| 27 | }
|
---|
| 28 |
|
---|
| 29 | postcss.plugin = function plugin(name, initializer) {
|
---|
| 30 | let warningPrinted = false
|
---|
| 31 | function creator(...args) {
|
---|
| 32 | // eslint-disable-next-line no-console
|
---|
| 33 | if (console && console.warn && !warningPrinted) {
|
---|
| 34 | warningPrinted = true
|
---|
| 35 | // eslint-disable-next-line no-console
|
---|
| 36 | console.warn(
|
---|
| 37 | name +
|
---|
| 38 | ': postcss.plugin was deprecated. Migration guide:\n' +
|
---|
| 39 | 'https://evilmartians.com/chronicles/postcss-8-plugin-migration'
|
---|
| 40 | )
|
---|
| 41 | if (process.env.LANG && process.env.LANG.startsWith('cn')) {
|
---|
| 42 | /* c8 ignore next 7 */
|
---|
| 43 | // eslint-disable-next-line no-console
|
---|
| 44 | console.warn(
|
---|
| 45 | name +
|
---|
| 46 | ': 里面 postcss.plugin 被弃用. 迁移指南:\n' +
|
---|
| 47 | 'https://www.w3ctech.com/topic/2226'
|
---|
| 48 | )
|
---|
| 49 | }
|
---|
| 50 | }
|
---|
| 51 | let transformer = initializer(...args)
|
---|
| 52 | transformer.postcssPlugin = name
|
---|
| 53 | transformer.postcssVersion = new Processor().version
|
---|
| 54 | return transformer
|
---|
| 55 | }
|
---|
| 56 |
|
---|
| 57 | let cache
|
---|
| 58 | Object.defineProperty(creator, 'postcss', {
|
---|
| 59 | get() {
|
---|
| 60 | if (!cache) cache = creator()
|
---|
| 61 | return cache
|
---|
| 62 | }
|
---|
| 63 | })
|
---|
| 64 |
|
---|
| 65 | creator.process = function (css, processOpts, pluginOpts) {
|
---|
| 66 | return postcss([creator(pluginOpts)]).process(css, processOpts)
|
---|
| 67 | }
|
---|
| 68 |
|
---|
| 69 | return creator
|
---|
| 70 | }
|
---|
| 71 |
|
---|
| 72 | postcss.stringify = stringify
|
---|
| 73 | postcss.parse = parse
|
---|
| 74 | postcss.fromJSON = fromJSON
|
---|
| 75 | postcss.list = list
|
---|
| 76 |
|
---|
| 77 | postcss.comment = defaults => new Comment(defaults)
|
---|
| 78 | postcss.atRule = defaults => new AtRule(defaults)
|
---|
| 79 | postcss.decl = defaults => new Declaration(defaults)
|
---|
| 80 | postcss.rule = defaults => new Rule(defaults)
|
---|
| 81 | postcss.root = defaults => new Root(defaults)
|
---|
| 82 | postcss.document = defaults => new Document(defaults)
|
---|
| 83 |
|
---|
| 84 | postcss.CssSyntaxError = CssSyntaxError
|
---|
| 85 | postcss.Declaration = Declaration
|
---|
| 86 | postcss.Container = Container
|
---|
| 87 | postcss.Processor = Processor
|
---|
| 88 | postcss.Document = Document
|
---|
| 89 | postcss.Comment = Comment
|
---|
| 90 | postcss.Warning = Warning
|
---|
| 91 | postcss.AtRule = AtRule
|
---|
| 92 | postcss.Result = Result
|
---|
| 93 | postcss.Input = Input
|
---|
| 94 | postcss.Rule = Rule
|
---|
| 95 | postcss.Root = Root
|
---|
| 96 | postcss.Node = Node
|
---|
| 97 |
|
---|
| 98 | LazyResult.registerPostcss(postcss)
|
---|
| 99 |
|
---|
| 100 | module.exports = postcss
|
---|
| 101 | postcss.default = postcss
|
---|