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

Commit

Permalink
Merge pull request #57 from postcss/postcss-8
Browse files Browse the repository at this point in the history
  • Loading branch information
Semigradsky authored Jan 12, 2021
2 parents ca22cf6 + 31bd6a6 commit d861c70
Show file tree
Hide file tree
Showing 6 changed files with 2,046 additions and 32 deletions.
9 changes: 5 additions & 4 deletions .rollup.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import babel from 'rollup-plugin-babel';
import babel from '@rollup/plugin-babel';

export default {
input: 'index.js',
output: [
{ file: 'index.cjs.js', format: 'cjs', sourcemap: true },
{ file: 'index.es.mjs', format: 'es', sourcemap: true }
{ file: 'index.cjs.js', format: 'cjs', sourcemap: true, exports: 'default' },
{ file: 'index.es.mjs', format: 'es', sourcemap: true, exports: 'default' }
],
plugins: [
babel({
babelHelpers: 'bundled',
plugins: [
'@babel/plugin-syntax-dynamic-import'
],
presets: [
['@babel/env', { modules: false, targets: { node: 6 } }]
['@babel/env', { modules: false, targets: { node: 10 } }]
]
})
]
Expand Down
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
language: node_js

node_js:
- 6
- 14
- 12
- 10

install:
- npm install --ignore-scripts
28 changes: 17 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import postcss from 'postcss';
import getCustomMediaFromRoot from './lib/custom-media-from-root';
import getCustomMediaFromImports from './lib/get-custom-media-from-imports';
import transformAtrules from './lib/transform-atrules';
import writeCustomMediaToExports from './lib/write-custom-media-to-exports';

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

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

return async root => {
const customMedia = Object.assign(
await customMediaPromise,
getCustomMediaFromRoot(root, { preserve })
);
return {
postcssPlugin: 'postcss-custom-media',
Once: async root => {
const customMedia = Object.assign(
await customMediaPromise,
getCustomMediaFromRoot(root, { preserve })
);

await writeCustomMediaToExports(customMedia, exportTo);
await writeCustomMediaToExports(customMedia, exportTo);

transformAtrules(root, customMedia, { preserve });
};
});
transformAtrules(root, customMedia, { preserve });
}
}
};

creator.postcss = true

export default creator
4 changes: 2 additions & 2 deletions lib/get-custom-media-from-imports.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fs from 'fs';
import path from 'path';
import postcss from 'postcss';
import { parse } from 'postcss';
import getMediaAstFromMediaString from './media-ast-from-string';
import getCustomMedia from './custom-media-from-root';

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

async function getCustomMediaFromCSSFile(from) {
const css = await readFile(from);
const root = postcss.parse(css, { from });
const root = parse(css, { from });

return getCustomMedia(root, { preserve: true });
}
Expand Down
38 changes: 24 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,36 @@
"test:tape": "postcss-tape"
},
"engines": {
"node": ">=6.0.0"
"node": ">=10.0.0"
},
"dependencies": {
"postcss": "^7.0.14"
"peerDependencies": {
"postcss": "^8.1.0"
},
"devDependencies": {
"@babel/core": "^7.4.0",
"@babel/plugin-syntax-dynamic-import": "^7.2.0",
"@babel/preset-env": "^7.4.2",
"babel-eslint": "^10.0.1",
"eslint": "^5.16.0",
"eslint-config-dev": "^2.0.0",
"postcss-tape": "^4.0.0",
"@babel/core": "^7.11.6",
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
"@babel/preset-env": "^7.11.5",
"@rollup/plugin-babel": "^5.2.1",
"babel-eslint": "^10.1.0",
"eslint": "^7.10.0",
"postcss": "^8.1.0",
"postcss-tape": "^6.0.0",
"pre-commit": "^1.2.2",
"rollup": "^1.7.4",
"rollup-plugin-babel": "^4.3.2"
"rollup": "^2.28.2"
},
"eslintConfig": {
"extends": "dev",
"parser": "babel-eslint"
"env": {
"browser": true,
"es6": true,
"node": true
},
"extends": "eslint:recommended",
"parser": "babel-eslint",
"parserOptions": {
"ecmaVersion": 2018,
"impliedStrict": true,
"sourceType": "module"
}
},
"keywords": [
"postcss",
Expand Down
Loading

0 comments on commit d861c70

Please sign in to comment.