Skip to content

Commit 1c2082f

Browse files
committed
Use PostCSS 8 API
1 parent a9074d1 commit 1c2082f

File tree

2 files changed

+33
-36
lines changed

2 files changed

+33
-36
lines changed

lib/autoprefixer.js

+33-26
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ const WARNING =
1313
' Replace Autoprefixer `browsers` option to Browserslist config.\n' +
1414
' Use `browserslist` key in `package.json` or `.browserslistrc` file.\n' +
1515
'\n' +
16-
' Using `browsers` option can cause errors. Browserslist config \n' +
17-
' can be used for Babel, Autoprefixer, postcss-normalize and other tools.\n' +
16+
' Using `browsers` option can cause errors. Browserslist config can\n' +
17+
' be used for Babel, Autoprefixer, postcss-normalize and other tools.\n' +
1818
'\n' +
1919
' If you really need to use option, rename it to `overrideBrowserslist`.\n' +
2020
'\n' +
@@ -48,7 +48,7 @@ function timeCapsule (result, prefixes) {
4848
)
4949
}
5050

51-
module.exports = postcss.plugin('autoprefixer', (...reqs) => {
51+
module.exports = (...reqs) => {
5252
let options
5353
if (reqs.length === 1 && isPlainObject(reqs[0])) {
5454
options = reqs[0]
@@ -111,33 +111,40 @@ module.exports = postcss.plugin('autoprefixer', (...reqs) => {
111111
return cache[key]
112112
}
113113

114-
function plugin (css, result) {
115-
let prefixes = loadPrefixes({
116-
from: css.source && css.source.input.file,
117-
env: options.env
118-
})
119-
timeCapsule(result, prefixes)
120-
if (options.remove !== false) {
121-
prefixes.processor.remove(css, result)
122-
}
123-
if (options.add !== false) {
124-
prefixes.processor.add(css, result)
125-
}
126-
}
127-
128-
plugin.options = options
129-
130-
plugin.browsers = reqs
114+
return {
115+
postcssPlugin: 'autoprefixer',
116+
117+
prepare (result) {
118+
let prefixes = loadPrefixes({
119+
from: result.opts.from,
120+
env: options.env
121+
})
122+
123+
return {
124+
Root (root) {
125+
timeCapsule(result, prefixes)
126+
if (options.remove !== false) {
127+
prefixes.processor.remove(root, result)
128+
}
129+
if (options.add !== false) {
130+
prefixes.processor.add(root, result)
131+
}
132+
}
133+
}
134+
},
131135

132-
plugin.info = function (opts) {
133-
opts = opts || {}
134-
opts.from = opts.from || process.cwd()
136+
info (opts) {
137+
opts = opts || {}
138+
opts.from = opts.from || process.cwd()
139+
return info(loadPrefixes(opts))
140+
},
135141

136-
return info(loadPrefixes(opts))
142+
options,
143+
browsers: reqs
137144
}
145+
}
138146

139-
return plugin
140-
})
147+
module.exports.postcss = true
141148

142149
/**
143150
* Autoprefixer data

test/autoprefixer.test.js

-10
Original file line numberDiff line numberDiff line change
@@ -475,16 +475,6 @@ it('sets browserslist environment', () => {
475475
expect(processor.process(input, { from }).css).toEqual(output)
476476
})
477477

478-
it('works without source in nodes', () => {
479-
let root = postcss.root()
480-
root.append({ selector: 'a' })
481-
root.first.append({ prop: 'display', value: 'flex' })
482-
compiler(root)
483-
expect(root.toString()).toEqual(
484-
'a {\n display: -webkit-flex;\n display: flex\n}'
485-
)
486-
})
487-
488478
it('takes values from other PostCSS plugins', () => {
489479
function plugin (root) {
490480
root.walkDecls(i => {

0 commit comments

Comments
 (0)