Skip to content
This repository was archived by the owner on Oct 24, 2023. It is now read-only.

Commit ea8c3b5

Browse files
Release updates (#214)
* Updating as per plugin spec See postcss/postcss-font-variant#15 * Adding all property back * Updating System UI plugin to be compatible with PostCSS 8 * Removing no longer existing property * Autoprefixer false doesn't mess with the rest of the file * Updating with up to spec from image set plugin * Using last mod since color-mod was rejected and no longer within pack * Updating main file to be up to PostCSS 8
1 parent 4b1106d commit ea8c3b5

13 files changed

+216
-88
lines changed

.tape.js

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -89,29 +89,18 @@ module.exports = {
8989
}
9090
},
9191
'insert:after': {
92-
message: 'supports { stage: 1, features: { "color-mod-function": { unresolved: "warn" } }, insertAfter: { "color-mod-function": [ require("postcss-simple-vars")() ] } } usage',
92+
message: 'supports { stage: 1, insertAfter: { "color-mod-function": [ require("postcss-simple-vars")() ] } } usage',
9393
options: {
9494
stage: 1,
95-
features: {
96-
'color-mod-function': {
97-
unresolved: 'warn'
98-
}
99-
},
10095
insertAfter: {
10196
'color-mod-function': require('postcss-simple-vars')
10297
}
10398
},
104-
warnings: 2
10599
},
106100
'insert:after:exec': {
107101
message: 'supports { stage: 2, features: { "color-mod-function": { unresolved: "ignore" } }, insertAfter: { "color-mod-function": require("postcss-simple-vars")() } } usage',
108102
options: {
109103
stage: 2,
110-
features: {
111-
'color-mod-function': {
112-
unresolved: 'ignore'
113-
}
114-
},
115104
insertAfter: {
116105
'color-mod-function': require('postcss-simple-vars')()
117106
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
"postcss-font-variant": "^5.0.0",
5353
"postcss-gap-properties": "^3.0.0",
5454
"postcss-image-set-function": "^4.0.0",
55+
"postcss-initial": "^3.0.4",
5556
"postcss-lab-function": "^4.0.0",
5657
"postcss-logical": "^5.0.0",
5758
"postcss-media-minmax": "^5.0.0",

src/lib/plugins-by-id.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import postcssFontFamilySystemUi from '../patch/postcss-system-ui-font-family';
1616
import postcssGapProperties from 'postcss-gap-properties';
1717
import postcssHasPseudo from 'css-has-pseudo/postcss';
1818
import postcssImageSetPolyfill from 'postcss-image-set-function';
19+
import postcssInitial from 'postcss-initial';
1920
import postcssLabFunction from 'postcss-lab-function';
2021
import postcssLogical from 'postcss-logical';
2122
import postcssMediaMinmax from 'postcss-media-minmax';
@@ -30,6 +31,7 @@ import postcssSelectorNot from 'postcss-selector-not';
3031

3132
// postcss plugins ordered by id
3233
export default {
34+
'all-property': postcssInitial,
3335
'any-link-pseudo-class': postcssPseudoClassAnyLink,
3436
'blank-pseudo-class': postcssBlankPseudo,
3537
'break-properties': postcssPageBreak,

src/patch/postcss-system-ui-font-family.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@ export default function postcssSystemUiFont() {
33
postcssPlugin: 'postcss-system-ui-font',
44
Declaration(/** @type {import('postcss').Declaration} */ node) {
55
if (propertyRegExp.test(node.prop)) {
6-
node.value = node.value.replace(systemUiMatch, systemUiReplace);
6+
if (!node.value.includes(systemUiFamily.join(', '))) {
7+
node.value = node.value.replace(systemUiMatch, systemUiReplace);
8+
}
79
}
810
}
911
}
1012
}
1113

14+
postcssSystemUiFont.postcss = true;
15+
1216
const propertyRegExp = /(?:^(?:-|\\002d){2})|(?:^font(?:-family)?$)/i;
1317
const whitespace = '[\\f\\n\\r\\x09\\x20]';
1418
const systemUiFamily = [

src/postcss.js

Lines changed: 53 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
import autoprefixer from 'autoprefixer'
1+
import autoprefixer from 'autoprefixer';
22
import browserslist from 'browserslist';
33
import cssdb from 'cssdb';
4-
import postcss from 'postcss';
54
import plugins from './lib/plugins-by-id';
65
import getTransformedInsertions from './lib/get-transformed-insertions';
76
import getUnsupportedBrowsersByFeature from './lib/get-unsupported-browsers-by-feature';
87
import idsByExecutionOrder from './lib/ids-by-execution-order';
98
import writeToExports from './lib/write-to-exports';
109

11-
export default postcss.plugin('postcss-preset-env', opts => {
10+
const plugin = opts => {
1211
// initialize options
1312
const features = Object(Object(opts).features);
1413
const insertBefore = Object(Object(opts).insertBefore);
@@ -17,13 +16,13 @@ export default postcss.plugin('postcss-preset-env', opts => {
1716
const stage = 'stage' in Object(opts)
1817
? opts.stage === false
1918
? 5
20-
: parseInt(opts.stage) || 0
21-
: 2;
19+
: parseInt(opts.stage) || 0
20+
: 2;
2221
const autoprefixerOptions = Object(opts).autoprefixer;
2322
const sharedOpts = initializeSharedOpts(Object(opts));
2423
const stagedAutoprefixer = autoprefixerOptions === false
2524
? () => {}
26-
: autoprefixer(Object.assign({ overrideBrowserslist: browsers }, autoprefixerOptions));
25+
: autoprefixer(Object.assign({ overrideBrowserslist: browsers }, autoprefixerOptions));
2726

2827
// polyfillable features (those with an available postcss plugin)
2928
const polyfillableFeatures = cssdb.concat(
@@ -61,26 +60,35 @@ export default postcss.plugin('postcss-preset-env', opts => {
6160
const stagedFeatures = polyfillableFeatures.filter(
6261
feature => feature.id in features
6362
? features[feature.id]
64-
: feature.stage >= stage
63+
: feature.stage >= stage
6564
).map(
66-
feature => ({
67-
browsers: feature.browsers,
68-
plugin: typeof feature.plugin.process === 'function'
69-
? features[feature.id] === true
70-
? sharedOpts
71-
// if the plugin is enabled and has shared options
72-
? feature.plugin(Object.assign({}, sharedOpts))
73-
// otherwise, if the plugin is enabled
74-
: feature.plugin()
75-
: sharedOpts
65+
feature => {
66+
let options;
67+
let plugin;
68+
69+
if (features[feature.id] === true) {
70+
// if the plugin is enabled
71+
options = sharedOpts ? Object.assign({}, sharedOpts) : undefined;
72+
} else {
73+
options = sharedOpts
7674
// if the plugin has shared options and individual options
77-
? feature.plugin(Object.assign({}, sharedOpts, features[feature.id]))
78-
// if the plugin has individual options
79-
: feature.plugin(Object.assign({}, features[feature.id]))
80-
// if the plugin is already initialized
81-
: feature.plugin,
82-
id: feature.id
83-
})
75+
? Object.assign({}, sharedOpts, features[feature.id])
76+
// if the plugin has individual options
77+
: Object.assign({}, features[feature.id]);
78+
}
79+
80+
if (feature.plugin.postcss) {
81+
plugin = feature.plugin(options);
82+
} else {
83+
plugin = feature.plugin;
84+
}
85+
86+
return {
87+
browsers: feature.browsers,
88+
plugin,
89+
id: feature.id
90+
};
91+
}
8492
);
8593

8694
// browsers supported by the configuration
@@ -90,35 +98,28 @@ export default postcss.plugin('postcss-preset-env', opts => {
9098
const supportedFeatures = stagedFeatures.filter(
9199
feature => feature.id in features
92100
? features[feature.id]
93-
: supportedBrowsers.some(
94-
supportedBrowser => browserslist(feature.browsers, {
95-
ignoreUnknownVersions: true
96-
}).some(
97-
polyfillBrowser => polyfillBrowser === supportedBrowser
101+
: supportedBrowsers.some(
102+
supportedBrowser => browserslist(feature.browsers, {
103+
ignoreUnknownVersions: true
104+
}).some(
105+
polyfillBrowser => polyfillBrowser === supportedBrowser
106+
)
98107
)
99-
)
100108
);
101109

102-
return (root, result) => {
103-
// polyfills run in execution order
104-
const polyfills = supportedFeatures.reduce(
105-
(promise, feature) => promise.then(
106-
() => feature.plugin(result.root, result)
107-
),
108-
Promise.resolve()
109-
).then(
110-
() => stagedAutoprefixer(result.root, result)
111-
).then(
112-
() => {
113-
if (Object(opts).exportTo) {
114-
writeToExports(sharedOpts.exportTo, opts.exportTo);
115-
}
116-
}
117-
)
110+
const usedPlugins = supportedFeatures.map(feature => feature.plugin);
111+
usedPlugins.push(stagedAutoprefixer);
118112

119-
return polyfills;
113+
return {
114+
postcssPlugin: 'postcss-preset-env',
115+
plugins: usedPlugins,
116+
OnceExit: function() {
117+
if ( Object( opts ).exportTo ) {
118+
writeToExports( sharedOpts.exportTo, opts.exportTo );
119+
}
120+
}
120121
};
121-
});
122+
}
122123

123124
const initializeSharedOpts = opts => {
124125
if ('importFrom' in opts || 'exportTo' in opts || 'preserve' in opts) {
@@ -145,3 +146,7 @@ const initializeSharedOpts = opts => {
145146

146147
return false;
147148
};
149+
150+
plugin.postcss = true;
151+
152+
export default plugin;

test/basic.autoprefixer.expect.css

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@
108108
}
109109

110110
.test-font-variant-property {
111-
font-feature-settings: "c2sc";
111+
font-feature-settings: "smcp";
112112
font-variant-caps: small-caps;
113113
order: 16;
114114
}
@@ -132,7 +132,6 @@
132132
columns: auto;
133133
column-count: auto;
134134
column-fill: balance;
135-
grid-column-gap: normal;
136135
column-gap: normal;
137136
column-rule: medium none currentColor;
138137
column-span: 1;

0 commit comments

Comments
 (0)