Skip to content
This repository was archived by the owner on Jun 6, 2022. It is now read-only.

Commit 31bd6a6

Browse files
committed
Support PostCSS 8
1 parent ca22cf6 commit 31bd6a6

File tree

6 files changed

+2046
-32
lines changed

6 files changed

+2046
-32
lines changed

.rollup.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
1-
import babel from 'rollup-plugin-babel';
1+
import babel from '@rollup/plugin-babel';
22

33
export default {
44
input: 'index.js',
55
output: [
6-
{ file: 'index.cjs.js', format: 'cjs', sourcemap: true },
7-
{ file: 'index.es.mjs', format: 'es', sourcemap: true }
6+
{ file: 'index.cjs.js', format: 'cjs', sourcemap: true, exports: 'default' },
7+
{ file: 'index.es.mjs', format: 'es', sourcemap: true, exports: 'default' }
88
],
99
plugins: [
1010
babel({
11+
babelHelpers: 'bundled',
1112
plugins: [
1213
'@babel/plugin-syntax-dynamic-import'
1314
],
1415
presets: [
15-
['@babel/env', { modules: false, targets: { node: 6 } }]
16+
['@babel/env', { modules: false, targets: { node: 10 } }]
1617
]
1718
})
1819
]

.travis.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
language: node_js
44

55
node_js:
6-
- 6
6+
- 14
7+
- 12
8+
- 10
79

810
install:
911
- npm install --ignore-scripts

index.js

+17-11
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import postcss from 'postcss';
21
import getCustomMediaFromRoot from './lib/custom-media-from-root';
32
import getCustomMediaFromImports from './lib/get-custom-media-from-imports';
43
import transformAtrules from './lib/transform-atrules';
54
import writeCustomMediaToExports from './lib/write-custom-media-to-exports';
65

7-
export default postcss.plugin('postcss-custom-media', opts => {
6+
const creator = opts => {
87
// whether to preserve custom media and at-rules using them
98
const preserve = 'preserve' in Object(opts) ? Boolean(opts.preserve) : false;
109

@@ -17,14 +16,21 @@ export default postcss.plugin('postcss-custom-media', opts => {
1716
// promise any custom media are imported
1817
const customMediaPromise = getCustomMediaFromImports(importFrom);
1918

20-
return async root => {
21-
const customMedia = Object.assign(
22-
await customMediaPromise,
23-
getCustomMediaFromRoot(root, { preserve })
24-
);
19+
return {
20+
postcssPlugin: 'postcss-custom-media',
21+
Once: async root => {
22+
const customMedia = Object.assign(
23+
await customMediaPromise,
24+
getCustomMediaFromRoot(root, { preserve })
25+
);
2526

26-
await writeCustomMediaToExports(customMedia, exportTo);
27+
await writeCustomMediaToExports(customMedia, exportTo);
2728

28-
transformAtrules(root, customMedia, { preserve });
29-
};
30-
});
29+
transformAtrules(root, customMedia, { preserve });
30+
}
31+
}
32+
};
33+
34+
creator.postcss = true
35+
36+
export default creator

lib/get-custom-media-from-imports.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import fs from 'fs';
22
import path from 'path';
3-
import postcss from 'postcss';
3+
import { parse } from 'postcss';
44
import getMediaAstFromMediaString from './media-ast-from-string';
55
import getCustomMedia from './custom-media-from-root';
66

@@ -9,7 +9,7 @@ import getCustomMedia from './custom-media-from-root';
99

1010
async function getCustomMediaFromCSSFile(from) {
1111
const css = await readFile(from);
12-
const root = postcss.parse(css, { from });
12+
const root = parse(css, { from });
1313

1414
return getCustomMedia(root, { preserve: true });
1515
}

package.json

+24-14
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,36 @@
2424
"test:tape": "postcss-tape"
2525
},
2626
"engines": {
27-
"node": ">=6.0.0"
27+
"node": ">=10.0.0"
2828
},
29-
"dependencies": {
30-
"postcss": "^7.0.14"
29+
"peerDependencies": {
30+
"postcss": "^8.1.0"
3131
},
3232
"devDependencies": {
33-
"@babel/core": "^7.4.0",
34-
"@babel/plugin-syntax-dynamic-import": "^7.2.0",
35-
"@babel/preset-env": "^7.4.2",
36-
"babel-eslint": "^10.0.1",
37-
"eslint": "^5.16.0",
38-
"eslint-config-dev": "^2.0.0",
39-
"postcss-tape": "^4.0.0",
33+
"@babel/core": "^7.11.6",
34+
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
35+
"@babel/preset-env": "^7.11.5",
36+
"@rollup/plugin-babel": "^5.2.1",
37+
"babel-eslint": "^10.1.0",
38+
"eslint": "^7.10.0",
39+
"postcss": "^8.1.0",
40+
"postcss-tape": "^6.0.0",
4041
"pre-commit": "^1.2.2",
41-
"rollup": "^1.7.4",
42-
"rollup-plugin-babel": "^4.3.2"
42+
"rollup": "^2.28.2"
4343
},
4444
"eslintConfig": {
45-
"extends": "dev",
46-
"parser": "babel-eslint"
45+
"env": {
46+
"browser": true,
47+
"es6": true,
48+
"node": true
49+
},
50+
"extends": "eslint:recommended",
51+
"parser": "babel-eslint",
52+
"parserOptions": {
53+
"ecmaVersion": 2018,
54+
"impliedStrict": true,
55+
"sourceType": "module"
56+
}
4757
},
4858
"keywords": [
4959
"postcss",

0 commit comments

Comments
 (0)