Skip to content

Commit e709a66

Browse files
refactor postcss-custom-properties and cleanup in postcss-preset-env (#603)
* postcss-custom-properties * cleanup more tests * cleanup * docs and changelog * cleanup * more cleanup * docs * Update plugins/postcss-custom-properties/docs/README.md Co-authored-by: Antonio Laguna <sombragriselros@gmail.com> * docs Co-authored-by: Antonio Laguna <sombragriselros@gmail.com>
1 parent edb25ce commit e709a66

File tree

86 files changed

+698
-2064
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+698
-2064
lines changed

package-lock.json

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugin-packs/postcss-preset-env/.tape.mjs

Lines changed: 0 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import postcssTape from '../../packages/postcss-tape/dist/index.mjs';
22
import plugin from 'postcss-preset-env';
3-
import fs from 'fs';
43

54
const orderDetectionPlugin = (prop, changeWhenMatches) => {
65
return {
@@ -383,128 +382,6 @@ postcssTape(plugin)({
383382
}
384383
}
385384
},
386-
'import': {
387-
message: 'supports { importFrom: { customMedia, customProperties, customSelectors, environmentVariables } } usage',
388-
warnings: 2,
389-
options: {
390-
importFrom: {
391-
customMedia: {
392-
'--narrow-window': '(max-width: env(--sm))'
393-
},
394-
customProperties: {
395-
'--order': '1'
396-
},
397-
customSelectors: {
398-
':--heading': 'h1, h2, h3, h4, h5, h6'
399-
},
400-
environmentVariables: {
401-
'--sm': '40rem'
402-
}
403-
},
404-
stage: 0
405-
}
406-
},
407-
'import:ch87': {
408-
message: 'supports { browsers: "chrome >= 87", importFrom: { customMedia, customProperties, customSelectors, environmentVariables } } usage',
409-
warnings: 2,
410-
options: {
411-
browsers: 'chrome >= 87',
412-
importFrom: {
413-
customMedia: {
414-
'--narrow-window': '(max-width: env(--sm))'
415-
},
416-
customProperties: {
417-
'--order': '1'
418-
},
419-
customSelectors: {
420-
':--heading': 'h1, h2, h3, h4, h5, h6'
421-
},
422-
environmentVariables: {
423-
'--sm': '40rem'
424-
}
425-
},
426-
stage: 0
427-
}
428-
},
429-
'import:ch87:array': {
430-
message: 'supports { browsers: "chrome >= 87", importFrom: [{ customMedia, customProperties, customSelectors, environmentVariables }] } usage',
431-
warnings: 2,
432-
options: {
433-
browsers: 'chrome >= 87',
434-
importFrom: [{
435-
customMedia: {
436-
'--narrow-window': '(max-width: env(--sm))'
437-
},
438-
customProperties: {
439-
'--order': '1'
440-
},
441-
customSelectors: {
442-
':--heading': 'h1, h2, h3, h4, h5, h6'
443-
},
444-
environmentVariables: {
445-
'--sm': '40rem'
446-
}
447-
}],
448-
stage: 0
449-
}
450-
},
451-
'import:ch87:incorrect-options': {
452-
message: 'supports { browsers: "chrome >= 87", importFrom: false } usage',
453-
options: {
454-
browsers: 'chrome >= 87',
455-
importFrom: false,
456-
stage: 0
457-
}
458-
},
459-
'basic:export': {
460-
message: 'supports { stage: 0 } usage',
461-
warnings: 1,
462-
options: {
463-
stage: 0,
464-
exportTo: [
465-
'test/generated-custom-exports.css',
466-
'test/generated-custom-exports.js',
467-
'test/generated-custom-exports.json',
468-
'test/generated-custom-exports.mjs'
469-
]
470-
},
471-
expect: 'basic.stage0.expect.css',
472-
result: 'basic.stage0.result.css',
473-
before() {
474-
try {
475-
global.__exportTo = {
476-
css: fs.readFileSync('test/generated-custom-exports.css', 'utf8'),
477-
js: fs.readFileSync('test/generated-custom-exports.js', 'utf8'),
478-
json: fs.readFileSync('test/generated-custom-exports.json', 'utf8'),
479-
mjs: fs.readFileSync('test/generated-custom-exports.mjs', 'utf8')
480-
};
481-
482-
fs.rmSync('test/generated-custom-exports.css');
483-
fs.rmSync('test/generated-custom-exports.js');
484-
fs.rmSync('test/generated-custom-exports.json');
485-
fs.rmSync('test/generated-custom-exports.mjs');
486-
} catch (_) {
487-
// ignore errors here.
488-
// If the files are removed manually test run will regenerate these.
489-
// The after step will still fail.
490-
// The real test is in the after step.
491-
}
492-
},
493-
after() {
494-
global.__exportAs = {
495-
css: fs.readFileSync('test/generated-custom-exports.css', 'utf8'),
496-
js: fs.readFileSync('test/generated-custom-exports.js', 'utf8'),
497-
json: fs.readFileSync('test/generated-custom-exports.json', 'utf8'),
498-
mjs: fs.readFileSync('test/generated-custom-exports.mjs', 'utf8')
499-
};
500-
501-
Object.keys(global.__exportTo).forEach(key => {
502-
if (global.__exportTo[key] !== global.__exportAs[key]) {
503-
throw new Error(`The original ${key} file did not match the freshly exported copy`);
504-
}
505-
});
506-
}
507-
},
508385
'progressive-custom-properties': {
509386
message: 'supports progressive custom properties plugin',
510387
options: {

plugin-packs/postcss-preset-env/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
### Unreleased (8.0.0-alpha.1)
44

55
- Updated: Support for Node v14+ (major).
6+
- Remove `postcss-env-function` (breaking).
67

78
### 8.0.0-alpha.0 (July 8, 2022)
89

plugin-packs/postcss-preset-env/FEATURES.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ The `ID` listed is the key for PostCSS Preset Env configuration in your project.
1919
| `dir-pseudo-class` | `:dir` Directionality Pseudo-Class | [example](https://preset-env.cssdb.org/features/#dir-pseudo-class) | [docs](https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-dir-pseudo-class#readme) |
2020
| `display-two-values` | Two values syntax for `display` | [example](https://preset-env.cssdb.org/features/#display-two-values) | [docs](https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-normalize-display-values#readme) |
2121
| `double-position-gradients` | Double Position Gradients | [example](https://preset-env.cssdb.org/features/#double-position-gradients) | [docs](https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-double-position-gradients#readme) |
22-
| `environment-variables` | Custom Environment Variables | [example](https://preset-env.cssdb.org/features/#environment-variables) | [docs](https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-env-function#readme) |
2322
| `focus-visible-pseudo-class` | `:focus-visible` Focus-Indicated Pseudo-Class | [example](https://preset-env.cssdb.org/features/#focus-visible-pseudo-class) | [docs](https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-focus-visible#readme) |
2423
| `focus-within-pseudo-class` | `:focus-within` Focus Container Pseudo-Class | [example](https://preset-env.cssdb.org/features/#focus-within-pseudo-class) | [docs](https://github.com/csstools/postcss-plugins/tree/main/plugins/postcss-focus-within#readme) |
2524
| `font-format-keywords` | Font `format()` Keywords | [example](https://preset-env.cssdb.org/features/#font-format-keywords) | [docs](https://github.com/valtlai/postcss-font-format-keywords#readme) |

plugin-packs/postcss-preset-env/README.md

Lines changed: 0 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -326,134 +326,6 @@ postcssPresetEnv({
326326
});
327327
```
328328

329-
### importFrom
330-
331-
The `importFrom` option specifies sources where variables like Custom Media,
332-
Custom Properties, Custom Selectors, and Environment Variables can be imported
333-
from, which might be CSS, JS, and JSON files, functions, and directly passed
334-
objects.
335-
336-
```js
337-
postcssPresetEnv({
338-
/*
339-
@custom-media --small-viewport (max-width: 30em);
340-
@custom-selector :--heading h1, h2, h3;
341-
:root { --color: red; }
342-
*/
343-
importFrom: 'path/to/file.css'
344-
});
345-
```
346-
347-
Multiple sources can be passed into this option, and they will be parsed in the
348-
order they are received. JavaScript files, JSON files, functions, and objects
349-
will use different namespaces to import different kinds of variables.
350-
351-
```js
352-
postcssPresetEnv({
353-
importFrom: [
354-
/*
355-
@custom-media --small-viewport (max-width: 30em);
356-
@custom-selector :--heading h1, h2, h3;
357-
:root { --color: red; }
358-
*/
359-
'path/to/file.css',
360-
361-
/* module.exports = {
362-
customMedia: { '--small-viewport': '(max-width: 30em)' },
363-
customProperties: { '--color': 'red' },
364-
customSelectors: { ':--heading': 'h1, h2, h3' },
365-
environmentVariables: { '--branding-padding': '20px' }
366-
} */
367-
'and/then/this.js',
368-
369-
/* {
370-
"custom-media": { "--small-viewport": "(max-width: 30em)" }
371-
"custom-properties": { "--color": "red" },
372-
"custom-selectors": { ":--heading": "h1, h2, h3" },
373-
"environment-variables": { "--branding-padding": "20px" }
374-
} */
375-
'and/then/that.json',
376-
377-
{
378-
customMedia: { '--small-viewport': '(max-width: 30em)' },
379-
customProperties: { '--color': 'red' },
380-
customSelectors: { ':--heading': 'h1, h2, h3' },
381-
environmentVariables: { '--branding-padding': '20px' }
382-
},
383-
() => {
384-
const customMedia = { '--small-viewport': '(max-width: 30em)' };
385-
const customProperties = { '--color': 'red' };
386-
const customSelectors = { ':--heading': 'h1, h2, h3' };
387-
const environmentVariables = { '--branding-padding': '20px' };
388-
389-
return { customMedia, customProperties, customSelectors, environmentVariables };
390-
}
391-
]
392-
});
393-
```
394-
395-
### exportTo
396-
397-
The `exportTo` option specifies destinations where variables like Custom Media,
398-
Custom Properties, Custom Selectors, and Environment Variables can be exported
399-
to, which might be CSS, JS, and JSON files, functions, and directly passed
400-
objects.
401-
402-
```js
403-
postcssPresetEnv({
404-
/*
405-
@custom-media --small-viewport (max-width: 30em);
406-
@custom-selector :--heading h1, h2, h3;
407-
:root { --color: red; }
408-
*/
409-
exportTo: 'path/to/file.css'
410-
});
411-
```
412-
413-
Multiple destinations can be passed into this option as well, and they will be
414-
parsed in the order they are received. JavaScript files, JSON files, and
415-
objects will use different namespaces to import different kinds of variables.
416-
417-
```js
418-
const cachedObject = {};
419-
420-
postcssPresetEnv({
421-
exportTo: [
422-
/*
423-
@custom-media --small-viewport (max-width: 30em);
424-
@custom-selector :--heading h1, h2, h3;
425-
:root { --color: red; }
426-
*/
427-
'path/to/file.css',
428-
429-
/* module.exports = {
430-
customMedia: { '--small-viewport': '(max-width: 30em)' },
431-
customProperties: { '--color': 'red' },
432-
customSelectors: { ':--heading': 'h1, h2, h3' },
433-
environmentVariables: { '--branding-padding': '20px' }
434-
} */
435-
'and/then/this.js',
436-
437-
/* {
438-
"custom-media": { "--small-viewport": "(max-width: 30em)" }
439-
"custom-properties": { "--color": "red" },
440-
"custom-selectors": { ":--heading": "h1, h2, h3" },
441-
"environment-variables": { "--branding-padding": "20px" }
442-
} */
443-
'and/then/that.json',
444-
445-
cachedObject,
446-
variables => {
447-
if ('customProperties' in variables) {
448-
// do something special with customProperties
449-
}
450-
451-
Object.assign(cachedObject, variables);
452-
}
453-
]
454-
});
455-
```
456-
457329
### debug
458330

459331
The `debug` option enables debugging messages to stdout which should be useful to help you debug which features have been enabled/disabled and why.

plugin-packs/postcss-preset-env/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@
5757
"postcss-custom-selectors": "^6.0.3",
5858
"postcss-dir-pseudo-class": "^6.0.5",
5959
"postcss-double-position-gradients": "^3.1.2",
60-
"postcss-env-function": "^4.0.6",
6160
"postcss-focus-visible": "^7.0.0",
6261
"postcss-focus-within": "^6.0.0",
6362
"postcss-font-variant": "^5.0.0",

plugin-packs/postcss-preset-env/scripts/plugins-data.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,6 @@
6969
"id": "double-position-gradients",
7070
"importName": "postcssDoublePositionGradients"
7171
},
72-
{
73-
"packageName": "postcss-env-function",
74-
"id": "environment-variables",
75-
"importName": "postcssEnvFunction"
76-
},
7772
{
7873
"packageName": "postcss-focus-visible",
7974
"id": "focus-visible-pseudo-class",

plugin-packs/postcss-preset-env/src/index.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import autoprefixer from 'autoprefixer';
22
import cssdb from 'cssdb';
33
import logFeaturesList from './log/features-list.mjs';
44
import postcssProgressiveCustomProperties from '@csstools/postcss-progressive-custom-properties';
5-
import writeToExports from './side-effects/write-to-exports.mjs';
65
import { initializeSharedOptions } from './lib/shared-options.mjs';
76
import { listFeatures } from './lib/list-features.mjs';
87
import { newLogger } from './log/helper.mjs';
@@ -47,10 +46,6 @@ const plugin = (opts) => {
4746

4847
// Always reset the logger, if when debug is false
4948
logger.resetLogger();
50-
51-
if (options.exportTo) {
52-
writeToExports(sharedOptions.exportTo, opts.exportTo);
53-
}
5449
},
5550
};
5651
};

plugin-packs/postcss-preset-env/src/lib/list-features.mjs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import browserslist from 'browserslist';
2-
import { pluginHasSideEffects } from '../side-effects/plugins.mjs';
32
import { featuresWithClientSide } from '../client-side-polyfills/plugins.mjs';
43
import { stageFromOptions } from './stage.mjs';
54
import { prepareFeaturesList } from './prepare-features-list.mjs';
@@ -109,10 +108,6 @@ export function listFeatures(cssdbList, options, sharedOptions, logger) {
109108
return features[feature.id];
110109
}
111110

112-
if (pluginHasSideEffects(feature)) {
113-
return true;
114-
}
115-
116111
const unsupportedBrowsers = browserslist(feature.browsers, {
117112
ignoreUnknownVersions: true,
118113
});

plugin-packs/postcss-preset-env/src/lib/shared-options.mjs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,7 @@
1-
21
export function initializeSharedOptions(opts) {
3-
if ('importFrom' in opts || 'exportTo' in opts || 'preserve' in opts) {
2+
if ('preserve' in opts) {
43
const sharedOptions = {};
54

6-
if ('importFrom' in opts) {
7-
sharedOptions.importFrom = opts.importFrom;
8-
}
9-
10-
if ('exportTo' in opts) {
11-
sharedOptions.exportTo = {
12-
customMedia: {},
13-
customProperties: {},
14-
customSelectors: {},
15-
};
16-
}
17-
185
if ('preserve' in opts) {
196
sharedOptions.preserve = opts.preserve;
207
}

plugin-packs/postcss-preset-env/src/plugins/plugins-by-id.mjs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import postcssCustomSelectors from 'postcss-custom-selectors';
1313
import postcssDirPseudoClass from 'postcss-dir-pseudo-class';
1414
import postcssNormalizeDisplayValues from '@csstools/postcss-normalize-display-values';
1515
import postcssDoublePositionGradients from 'postcss-double-position-gradients';
16-
import postcssEnvFunction from 'postcss-env-function';
1716
import postcssFocusVisible from 'postcss-focus-visible';
1817
import postcssFocusWithin from 'postcss-focus-within';
1918
import postcssFontFormatKeywords from '@csstools/postcss-font-format-keywords';
@@ -62,7 +61,6 @@ export const pluginsById = new Map(
6261
['dir-pseudo-class', postcssDirPseudoClass],
6362
['display-two-values', postcssNormalizeDisplayValues],
6463
['double-position-gradients', postcssDoublePositionGradients],
65-
['environment-variables', postcssEnvFunction],
6664
['focus-visible-pseudo-class', postcssFocusVisible],
6765
['focus-within-pseudo-class', postcssFocusWithin],
6866
['font-format-keywords', postcssFontFormatKeywords],

0 commit comments

Comments
 (0)