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

Commit 0929148

Browse files
committed
7.0.5
1 parent 1d9d913 commit 0929148

File tree

7 files changed

+67
-67
lines changed

7 files changed

+67
-67
lines changed

.rollup.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import babel from 'rollup-plugin-babel';
33
export default {
44
input: 'index.js',
55
output: [
6-
{ file: 'index.cjs.js', format: 'cjs' },
7-
{ file: 'index.es.mjs', format: 'es' }
6+
{ file: 'index.cjs.js', format: 'cjs', sourcemap: true },
7+
{ file: 'index.es.mjs', format: 'es', sourcemap: true }
88
],
99
plugins: [
1010
babel({

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changes to PostCSS Custom Media
22

3+
### 7.0.5 (October 5, 2018)
4+
5+
- Fixed: Possible issues resolving paths to imports and exports
6+
- Added: Imports from `customMedia` and `custom-media` simultaneously
7+
- Updated: `postcss` to 7.0.5
8+
39
### 7.0.4 (September 23, 2018)
410

511
- Added: `importFromPlugins` option to process imports

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,10 @@ postcssCustomMedia({
160160
});
161161
```
162162

163+
See example exports written to [CSS](test/export-media.css),
164+
[JS](test/export-media.js), [MJS](test/export-media.mjs), and
165+
[JSON](test/export-media.json).
166+
163167
[cli-img]: https://img.shields.io/travis/postcss/postcss-custom-media.svg
164168
[cli-url]: https://travis-ci.org/postcss/postcss-custom-media
165169
[css-img]: https://cssdb.org/badge/custom-media-queries.svg

index.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
import postcss from 'postcss';
2-
import getCustomMedia from './lib/custom-media-from-root';
2+
import getCustomMediaFromRoot from './lib/custom-media-from-root';
3+
import getCustomMediaFromImports from './lib/get-custom-media-from-imports';
34
import transformAtrules from './lib/transform-atrules';
4-
import importCustomMediaFromSources from './lib/import-from';
5-
import exportCustomMediaToDestinations from './lib/export-to';
5+
import writeCustomMediaToExports from './lib/write-custom-media-to-exports';
66

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

11-
// sources to import custom selectors from
11+
// sources to import custom media from
1212
const importFrom = [].concat(Object(opts).importFrom || []);
1313

14-
// destinations to export custom selectors to
14+
// destinations to export custom media to
1515
const exportTo = [].concat(Object(opts).exportTo || []);
1616

17-
// promise any custom selectors are imported
18-
const customMediaPromise = importCustomMediaFromSources(importFrom);
17+
// promise any custom media are imported
18+
const customMediaPromise = getCustomMediaFromImports(importFrom);
1919

2020
return async root => {
2121
const customMedia = Object.assign(
2222
await customMediaPromise,
23-
getCustomMedia(root, { preserve })
23+
getCustomMediaFromRoot(root, { preserve })
2424
);
2525

26-
await exportCustomMediaToDestinations(customMedia, exportTo);
26+
await writeCustomMediaToExports(customMedia, exportTo);
2727

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

lib/import-from.js renamed to lib/get-custom-media-from-imports.js

Lines changed: 24 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,24 @@ import postcss from 'postcss';
44
import getMediaAstFromMediaString from './media-ast-from-string';
55
import getCustomMedia from './custom-media-from-root';
66

7-
/* Import Custom Media from CSS AST
7+
/* Get Custom Media from CSS File
88
/* ========================================================================== */
99

10-
function importCustomMediaFromCSSAST(root) {
11-
return getCustomMedia(root, { preserve: true });
12-
}
13-
14-
/* Import Custom Media from CSS File
15-
/* ========================================================================== */
10+
async function getCustomMediaFromCSSFile(from) {
11+
const css = await readFile(from);
12+
const root = postcss.parse(css, { from });
1613

17-
async function importCustomMediaFromCSSFile(from) {
18-
const css = await readFile(path.resolve(from));
19-
const root = postcss.parse(css, { from: path.resolve(from) });
20-
21-
return importCustomMediaFromCSSAST(root);
14+
return getCustomMedia(root, { preserve: true });
2215
}
2316

24-
/* Import Custom Media from Object
17+
/* Get Custom Media from Object
2518
/* ========================================================================== */
2619

27-
function importCustomMediaFromObject(object) {
20+
function getCustomMediaFromObject(object) {
2821
const customMedia = Object.assign(
2922
{},
30-
Object(object).customMedia || Object(object)['custom-media']
23+
Object(object).customMedia,
24+
Object(object)['custom-media']
3125
);
3226

3327
for (const key in customMedia) {
@@ -37,28 +31,28 @@ function importCustomMediaFromObject(object) {
3731
return customMedia;
3832
}
3933

40-
/* Import Custom Media from JSON file
34+
/* Get Custom Media from JSON file
4135
/* ========================================================================== */
4236

43-
async function importCustomMediaFromJSONFile(from) {
44-
const object = await readJSON(path.resolve(from));
37+
async function getCustomMediaFromJSONFile(from) {
38+
const object = await readJSON(from);
4539

46-
return importCustomMediaFromObject(object);
40+
return getCustomMediaFromObject(object);
4741
}
4842

49-
/* Import Custom Media from JS file
43+
/* Get Custom Media from JS file
5044
/* ========================================================================== */
5145

52-
async function importCustomMediaFromJSFile(from) {
53-
const object = await import(path.resolve(from));
46+
async function getCustomMediaFromJSFile(from) {
47+
const object = await import(from);
5448

55-
return importCustomMediaFromObject(object);
49+
return getCustomMediaFromObject(object);
5650
}
5751

58-
/* Import Custom Media from Sources
52+
/* Get Custom Media from Sources
5953
/* ========================================================================== */
6054

61-
export default function importCustomMediaFromSources(sources) {
55+
export default function getCustomMediaFromSources(sources) {
6256
return sources.map(source => {
6357
if (source instanceof Promise) {
6458
return source;
@@ -75,7 +69,7 @@ export default function importCustomMediaFromSources(sources) {
7569
}
7670

7771
// source pathname
78-
const from = String(opts.from || '');
72+
const from = path.resolve(String(opts.from || ''));
7973

8074
// type of file being read from
8175
const type = (opts.type || path.extname(from).slice(1)).toLowerCase();
@@ -84,23 +78,19 @@ export default function importCustomMediaFromSources(sources) {
8478
}).reduce(async (customMedia, source) => {
8579
const { type, from } = await source;
8680

87-
if (type === 'ast') {
88-
return Object.assign(customMedia, importCustomMediaFromCSSAST(from));
89-
}
90-
9181
if (type === 'css') {
92-
return Object.assign(customMedia, await importCustomMediaFromCSSFile(from));
82+
return Object.assign(await customMedia, await getCustomMediaFromCSSFile(from));
9383
}
9484

9585
if (type === 'js') {
96-
return Object.assign(customMedia, await importCustomMediaFromJSFile(from));
86+
return Object.assign(await customMedia, await getCustomMediaFromJSFile(from));
9787
}
9888

9989
if (type === 'json') {
100-
return Object.assign(customMedia, await importCustomMediaFromJSONFile(from));
90+
return Object.assign(await customMedia, await getCustomMediaFromJSONFile(from));
10191
}
10292

103-
return Object.assign(customMedia, importCustomMediaFromObject(await source));
93+
return Object.assign(await customMedia, getCustomMediaFromObject(await source));
10494
}, {});
10595
}
10696

lib/export-to.js renamed to lib/write-custom-media-to-exports.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import fs from 'fs';
22
import path from 'path';
33

4-
/* Import Custom Media from CSS File
4+
/* Write Custom Media from CSS File
55
/* ========================================================================== */
66

7-
async function exportCustomMediaToCssFile(to, customMedia) {
7+
async function writeCustomMediaToCssFile(to, customMedia) {
88
const cssContent = Object.keys(customMedia).reduce((cssLines, name) => {
99
cssLines.push(`@custom-media ${name} ${customMedia[name]};`);
1010

@@ -15,10 +15,10 @@ async function exportCustomMediaToCssFile(to, customMedia) {
1515
await writeFile(to, css);
1616
}
1717

18-
/* Import Custom Media from JSON file
18+
/* Write Custom Media from JSON file
1919
/* ========================================================================== */
2020

21-
async function exportCustomMediaToJsonFile(to, customMedia) {
21+
async function writeCustomMediaToJsonFile(to, customMedia) {
2222
const jsonContent = JSON.stringify({
2323
'custom-media': customMedia
2424
}, null, ' ');
@@ -27,10 +27,10 @@ async function exportCustomMediaToJsonFile(to, customMedia) {
2727
await writeFile(to, json);
2828
}
2929

30-
/* Import Custom Media from Common JS file
30+
/* Write Custom Media from Common JS file
3131
/* ========================================================================== */
3232

33-
async function exportCustomMediaToCjsFile(to, customMedia) {
33+
async function writeCustomMediaToCjsFile(to, customMedia) {
3434
const jsContents = Object.keys(customMedia).reduce((jsLines, name) => {
3535
jsLines.push(`\t\t'${escapeForJS(name)}': '${escapeForJS(customMedia[name])}'`);
3636

@@ -41,10 +41,10 @@ async function exportCustomMediaToCjsFile(to, customMedia) {
4141
await writeFile(to, js);
4242
}
4343

44-
/* Import Custom Media from Module JS file
44+
/* Write Custom Media from Module JS file
4545
/* ========================================================================== */
4646

47-
async function exportCustomMediaToMjsFile(to, customMedia) {
47+
async function writeCustomMediaToMjsFile(to, customMedia) {
4848
const mjsContents = Object.keys(customMedia).reduce((mjsLines, name) => {
4949
mjsLines.push(`\t'${escapeForJS(name)}': '${escapeForJS(customMedia[name])}'`);
5050

@@ -55,10 +55,10 @@ async function exportCustomMediaToMjsFile(to, customMedia) {
5555
await writeFile(to, mjs);
5656
}
5757

58-
/* Export Custom Media to Destinations
58+
/* Write Custom Media to Exports
5959
/* ========================================================================== */
6060

61-
export default function exportCustomMediaToDestinations(customMedia, destinations) {
61+
export default function writeCustomMediaToExports(customMedia, destinations) {
6262
return Promise.all(destinations.map(async destination => {
6363
if (destination instanceof Function) {
6464
await destination(defaultCustomMediaToJSON(customMedia));
@@ -86,19 +86,19 @@ export default function exportCustomMediaToDestinations(customMedia, destination
8686
const customMediaJSON = toJSON(customMedia);
8787

8888
if (type === 'css') {
89-
await exportCustomMediaToCssFile(to, customMediaJSON);
89+
await writeCustomMediaToCssFile(to, customMediaJSON);
9090
}
9191

9292
if (type === 'js') {
93-
await exportCustomMediaToCjsFile(to, customMediaJSON);
93+
await writeCustomMediaToCjsFile(to, customMediaJSON);
9494
}
9595

9696
if (type === 'json') {
97-
await exportCustomMediaToJsonFile(to, customMediaJSON);
97+
await writeCustomMediaToJsonFile(to, customMediaJSON);
9898
}
9999

100100
if (type === 'mjs') {
101-
await exportCustomMediaToMjsFile(to, customMediaJSON);
101+
await writeCustomMediaToMjsFile(to, customMediaJSON);
102102
}
103103
}
104104
}

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "postcss-custom-media",
3-
"version": "7.0.4",
3+
"version": "7.0.5",
44
"description": "Use Custom Media Queries in CSS",
55
"author": "Jonathan Neal <[email protected]>",
66
"contributors": [
@@ -27,18 +27,18 @@
2727
"node": ">=6.0.0"
2828
},
2929
"dependencies": {
30-
"postcss": "^7.0.2"
30+
"postcss": "^7.0.5"
3131
},
3232
"devDependencies": {
33-
"@babel/core": "^7.1.0",
33+
"@babel/core": "^7.1.2",
3434
"@babel/plugin-syntax-dynamic-import": "^7.0.0",
3535
"@babel/preset-env": "^7.1.0",
36-
"babel-eslint": "^9.0.0",
37-
"eslint": "^5.6.0",
36+
"babel-eslint": "^10.0.1",
37+
"eslint": "^5.6.1",
3838
"eslint-config-dev": "^2.0.0",
3939
"postcss-tape": "^2.2.0",
4040
"pre-commit": "^1.2.2",
41-
"rollup": "^0.66.2",
41+
"rollup": "^0.66.4",
4242
"rollup-plugin-babel": "^4.0.3"
4343
},
4444
"eslintConfig": {

0 commit comments

Comments
 (0)