postcss-preset-env
Advanced tools
Comparing version 6.7.1 to 6.7.2
164
index.js
@@ -52,20 +52,7 @@ 'use strict'; | ||
const whitespace = '[\\f\\n\\r\\x09\\x20]'; | ||
const systemUiFamily = ['system-ui', | ||
/* macOS 10.11-10.12 */ | ||
'-apple-system', | ||
/* Windows 6+ */ | ||
'Segoe UI', | ||
/* Android 4+ */ | ||
'Roboto', | ||
/* Ubuntu 10.10+ */ | ||
'Ubuntu', | ||
/* Gnome 3+ */ | ||
'Cantarell', | ||
/* KDE Plasma 5+ */ | ||
'Noto Sans', | ||
/* fallback */ | ||
'sans-serif']; | ||
const systemUiFamily = ['system-ui', /* macOS 10.11-10.12 */'-apple-system', /* Windows 6+ */'Segoe UI', /* Android 4+ */'Roboto', /* Ubuntu 10.10+ */'Ubuntu', /* Gnome 3+ */'Cantarell', /* KDE Plasma 5+ */'Noto Sans', /* fallback */'sans-serif']; | ||
const systemUiMatch = new RegExp(`(^|,|${whitespace}+)(?:system-ui${whitespace}*)(?:,${whitespace}*(?:${systemUiFamily.join('|')})${whitespace}*)?(,|$)`, 'i'); | ||
const systemUiReplace = `$1${systemUiFamily.join(', ')}$2`; | ||
// postcss plugins ordered by id | ||
var plugins = { | ||
@@ -116,8 +103,11 @@ 'all-property': postcssInitial, | ||
// return a list of browsers that do not support the feature | ||
function getUnsupportedBrowsersByFeature(feature) { | ||
const caniuseFeature = caniuse.features[feature]; // if feature support can be determined | ||
const caniuseFeature = caniuse.features[feature]; | ||
// if feature support can be determined | ||
if (caniuseFeature) { | ||
const stats = caniuse.feature(caniuseFeature).stats; // return an array of browsers and versions that do not support the feature | ||
const stats = caniuse.feature(caniuseFeature).stats; | ||
// return an array of browsers and versions that do not support the feature | ||
const results = Object.keys(stats).reduce((browsers, browser) => browsers.concat(Object.keys(stats[browser]).filter(version => stats[browser][version].indexOf('y') !== 0).map(version => `${browser} ${version}`)), []); | ||
@@ -132,12 +122,22 @@ return results; | ||
// ids ordered by required execution, then alphabetically | ||
var idsByExecutionOrder = ['custom-media-queries', 'custom-properties', 'environment-variables', // run environment-variables here to access transpiled custom media params and properties | ||
'image-set-function', // run images-set-function before nesting-rules so that it may fix nested media | ||
'media-query-ranges', // run media-query-range and | ||
'prefers-color-scheme-query', // run prefers-color-scheme-query here to prevent duplicate transpilation after nesting-rules | ||
'nesting-rules', 'custom-selectors', // run custom-selectors after nesting-rules to correctly transpile &:--custom-selector | ||
'any-link-pseudo-class', 'case-insensitive-attributes', 'focus-visible-pseudo-class', 'focus-within-pseudo-class', 'matches-pseudo-class', // run matches-pseudo-class and | ||
'not-pseudo-class', // run not-pseudo-class after other selectors have been transpiled | ||
'logical-properties-and-values', // run logical-properties-and-values before dir-pseudo-class | ||
'dir-pseudo-class', 'all-property', // run all-property before other property polyfills | ||
'color-functional-notation', 'double-position-gradients', 'gray-function', 'hexadecimal-alpha-notation', 'lab-function', 'rebeccapurple-color', 'color-mod-function', // run color-mod after other color modifications have finished | ||
var idsByExecutionOrder = ['custom-media-queries', 'custom-properties', 'environment-variables', | ||
// run environment-variables here to access transpiled custom media params and properties | ||
'image-set-function', | ||
// run images-set-function before nesting-rules so that it may fix nested media | ||
'media-query-ranges', | ||
// run media-query-range and | ||
'prefers-color-scheme-query', | ||
// run prefers-color-scheme-query here to prevent duplicate transpilation after nesting-rules | ||
'nesting-rules', 'custom-selectors', | ||
// run custom-selectors after nesting-rules to correctly transpile &:--custom-selector | ||
'any-link-pseudo-class', 'case-insensitive-attributes', 'focus-visible-pseudo-class', 'focus-within-pseudo-class', 'matches-pseudo-class', | ||
// run matches-pseudo-class and | ||
'not-pseudo-class', | ||
// run not-pseudo-class after other selectors have been transpiled | ||
'logical-properties-and-values', | ||
// run logical-properties-and-values before dir-pseudo-class | ||
'dir-pseudo-class', 'all-property', | ||
// run all-property before other property polyfills | ||
'color-functional-notation', 'double-position-gradients', 'gray-function', 'hexadecimal-alpha-notation', 'lab-function', 'rebeccapurple-color', 'color-mod-function', | ||
// run color-mod after other color modifications have finished | ||
'blank-pseudo-class', 'break-properties', 'font-variant-property', 'has-pseudo-class', 'gap-properties', 'overflow-property', 'overflow-wrap-property', 'place-properties', 'system-ui-font-family']; | ||
@@ -153,3 +153,2 @@ | ||
} | ||
if (info.done) { | ||
@@ -161,18 +160,14 @@ resolve(value); | ||
} | ||
function _asyncToGenerator(fn) { | ||
return function () { | ||
var self = this, | ||
args = arguments; | ||
args = arguments; | ||
return new Promise(function (resolve, reject) { | ||
var gen = fn.apply(self, args); | ||
function _next(value) { | ||
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); | ||
} | ||
function _throw(err) { | ||
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); | ||
} | ||
_next(undefined); | ||
@@ -194,3 +189,2 @@ }); | ||
} | ||
function getCustomPropertiesAsCss(customProperties) { | ||
@@ -204,3 +198,2 @@ const cssContent = Object.keys(customProperties).reduce((cssLines, name) => { | ||
} | ||
function getCustomSelectorsAsCss(customSelectors) { | ||
@@ -214,3 +207,2 @@ const cssContent = Object.keys(customSelectors).reduce((cssLines, name) => { | ||
} | ||
function writeExportsToCssFile(_x, _x2, _x3, _x4) { | ||
@@ -221,4 +213,2 @@ return _writeExportsToCssFile.apply(this, arguments); | ||
/* ========================================================================== */ | ||
function _writeExportsToCssFile() { | ||
@@ -234,3 +224,2 @@ _writeExportsToCssFile = _asyncToGenerator(function* (to, customMedia, customProperties, customSelectors) { | ||
} | ||
function writeExportsToJsonFile(_x5, _x6, _x7, _x8) { | ||
@@ -241,4 +230,2 @@ return _writeExportsToJsonFile.apply(this, arguments); | ||
/* ========================================================================== */ | ||
function _writeExportsToJsonFile() { | ||
@@ -256,3 +243,2 @@ _writeExportsToJsonFile = _asyncToGenerator(function* (to, customMedia, customProperties, customSelectors) { | ||
} | ||
function getObjectWithKeyAsCjs(key, object) { | ||
@@ -266,3 +252,2 @@ const jsContents = Object.keys(object).reduce((jsLines, name) => { | ||
} | ||
function writeExportsToCjsFile(_x9, _x10, _x11, _x12) { | ||
@@ -273,4 +258,2 @@ return _writeExportsToCjsFile.apply(this, arguments); | ||
/* ========================================================================== */ | ||
function _writeExportsToCjsFile() { | ||
@@ -286,3 +269,2 @@ _writeExportsToCjsFile = _asyncToGenerator(function* (to, customMedia, customProperties, customSelectors) { | ||
} | ||
function getObjectWithKeyAsMjs(key, object) { | ||
@@ -296,3 +278,2 @@ const mjsContents = Object.keys(object).reduce((mjsLines, name) => { | ||
} | ||
function writeExportsToMjsFile(_x13, _x14, _x15, _x16) { | ||
@@ -303,4 +284,2 @@ return _writeExportsToMjsFile.apply(this, arguments); | ||
/* ========================================================================== */ | ||
function _writeExportsToMjsFile() { | ||
@@ -316,3 +295,2 @@ _writeExportsToMjsFile = _asyncToGenerator(function* (to, customMedia, customProperties, customSelectors) { | ||
} | ||
function writeToExports(customExports, destinations) { | ||
@@ -331,6 +309,6 @@ return Promise.all([].concat(destinations).map( /*#__PURE__*/function () { | ||
to: String(destination) | ||
}; // transformer for Exports into a JSON-compatible object | ||
}; | ||
// transformer for Exports into a JSON-compatible object | ||
const toJSON = opts.toJSON || getObjectWithStringifiedKeys; | ||
if ('customMedia' in opts || 'customProperties' in opts || 'customSelectors' in opts) { | ||
@@ -348,22 +326,20 @@ // write directly to an object as customProperties | ||
// destination pathname | ||
const to = String(opts.to || ''); // type of file being written to | ||
const to = String(opts.to || ''); | ||
const type = (opts.type || path.extname(opts.to).slice(1)).toLowerCase(); // transformed Exports | ||
// type of file being written to | ||
const type = (opts.type || path.extname(opts.to).slice(1)).toLowerCase(); | ||
// transformed Exports | ||
const customMediaJSON = toJSON(customExports.customMedia); | ||
const customPropertiesJSON = toJSON(customExports.customProperties); | ||
const customSelectorsJSON = toJSON(customExports.customSelectors); | ||
if (type === 'css') { | ||
yield writeExportsToCssFile(to, customMediaJSON, customPropertiesJSON, customSelectorsJSON); | ||
} | ||
if (type === 'js') { | ||
yield writeExportsToCjsFile(to, customMediaJSON, customPropertiesJSON, customSelectorsJSON); | ||
} | ||
if (type === 'json') { | ||
yield writeExportsToJsonFile(to, customMediaJSON, customPropertiesJSON, customSelectorsJSON); | ||
} | ||
if (type === 'mjs') { | ||
@@ -375,3 +351,2 @@ yield writeExportsToMjsFile(to, customMediaJSON, customPropertiesJSON, customSelectorsJSON); | ||
}); | ||
return function (_x17) { | ||
@@ -382,2 +357,3 @@ return _ref.apply(this, arguments); | ||
} | ||
/* Helper utilities | ||
@@ -392,3 +368,2 @@ /* ========================================================================== */ | ||
} | ||
function writeFile(to, text) { | ||
@@ -405,3 +380,2 @@ return new Promise((resolve, reject) => { | ||
} | ||
function escapeForJS(string) { | ||
@@ -422,9 +396,15 @@ return string.replace(/\\([\s\S])|(')/g, '\\$1$2').replace(/\n/g, '\\n').replace(/\r/g, '\\r'); | ||
overrideBrowserslist: browsers | ||
}, autoprefixerOptions)); // polyfillable features (those with an available postcss plugin) | ||
}, autoprefixerOptions)); | ||
const polyfillableFeatures = cssdb.concat( // additional features to be inserted before cssdb features | ||
getTransformedInsertions(insertBefore, 'insertBefore'), // additional features to be inserted after cssdb features | ||
getTransformedInsertions(insertAfter, 'insertAfter')).filter( // inserted features or features with an available postcss plugin | ||
feature => feature.insertBefore || feature.id in plugins).sort( // features sorted by execution order and then insertion order | ||
(a, b) => idsByExecutionOrder.indexOf(a.id) - idsByExecutionOrder.indexOf(b.id) || (a.insertBefore ? -1 : b.insertBefore ? 1 : 0) || (a.insertAfter ? 1 : b.insertAfter ? -1 : 0)).map( // polyfillable features as an object | ||
// polyfillable features (those with an available postcss plugin) | ||
const polyfillableFeatures = cssdb.concat( | ||
// additional features to be inserted before cssdb features | ||
getTransformedInsertions(insertBefore, 'insertBefore'), | ||
// additional features to be inserted after cssdb features | ||
getTransformedInsertions(insertAfter, 'insertAfter')).filter( | ||
// inserted features or features with an available postcss plugin | ||
feature => feature.insertBefore || feature.id in plugins).sort( | ||
// features sorted by execution order and then insertion order | ||
(a, b) => idsByExecutionOrder.indexOf(a.id) - idsByExecutionOrder.indexOf(b.id) || (a.insertBefore ? -1 : b.insertBefore ? 1 : 0) || (a.insertAfter ? 1 : b.insertAfter ? -1 : 0)).map( | ||
// polyfillable features as an object | ||
feature => { | ||
@@ -444,19 +424,27 @@ // target browsers for the polyfill | ||
}; | ||
}); // staged features (those at or above the selected stage) | ||
}); | ||
// staged features (those at or above the selected stage) | ||
const stagedFeatures = polyfillableFeatures.filter(feature => feature.id in features ? features[feature.id] : feature.stage >= stage).map(feature => ({ | ||
browsers: feature.browsers, | ||
plugin: typeof feature.plugin.process === 'function' ? features[feature.id] === true ? sharedOpts // if the plugin is enabled and has shared options | ||
? feature.plugin(Object.assign({}, sharedOpts)) // otherwise, if the plugin is enabled | ||
: feature.plugin() : sharedOpts // if the plugin has shared options and individual options | ||
? feature.plugin(Object.assign({}, sharedOpts, features[feature.id])) // if the plugin has individual options | ||
: feature.plugin(Object.assign({}, features[feature.id])) // if the plugin is already initialized | ||
plugin: typeof feature.plugin.process === 'function' ? features[feature.id] === true ? sharedOpts | ||
// if the plugin is enabled and has shared options | ||
? feature.plugin(Object.assign({}, sharedOpts)) | ||
// otherwise, if the plugin is enabled | ||
: feature.plugin() : sharedOpts | ||
// if the plugin has shared options and individual options | ||
? feature.plugin(Object.assign({}, sharedOpts, features[feature.id])) | ||
// if the plugin has individual options | ||
: feature.plugin(Object.assign({}, features[feature.id])) | ||
// if the plugin is already initialized | ||
: feature.plugin, | ||
id: feature.id | ||
})); // browsers supported by the configuration | ||
})); | ||
// browsers supported by the configuration | ||
const supportedBrowsers = browserslist(browsers, { | ||
ignoreUnknownVersions: true | ||
}); // features supported by the stage and browsers | ||
}); | ||
// features supported by the stage and browsers | ||
const supportedFeatures = stagedFeatures.filter(feature => supportedBrowsers.some(supportedBrowser => browserslist(feature.browsers, { | ||
@@ -466,21 +454,3 @@ ignoreUnknownVersions: true | ||
return (root, result) => { | ||
const majorVersion = parseInt(result.processor.version.split('.')[0]); | ||
if (majorVersion > 7) { | ||
console.log(''); | ||
console.log(` | ||
┌─────────────────────────────────────────────────────────────────────────────────┐ | ||
│ │ | ||
│ This version of postcss-preset-env is not optimised to work with PostCSS 8. │ | ||
│ Please update to version 7 of PostCSS Preset Env. │ | ||
│ │ | ||
│ If you find issues, you can report it at: │ | ||
│ https://github.com/csstools/postcss-plugins/issues/new/choose │ | ||
│ │ | ||
└─────────────────────────────────────────────────────────────────────────────────┘ | ||
`); | ||
console.log(''); | ||
} // polyfills run in execution order | ||
// polyfills run in execution order | ||
const polyfills = supportedFeatures.reduce((promise, feature) => promise.then(() => feature.plugin(result.root, result)), Promise.resolve()).then(() => stagedAutoprefixer(result.root, result)).then(() => { | ||
@@ -494,11 +464,8 @@ if (Object(opts).exportTo) { | ||
}); | ||
const initializeSharedOpts = opts => { | ||
if ('importFrom' in opts || 'exportTo' in opts || 'preserve' in opts) { | ||
const sharedOpts = {}; | ||
if ('importFrom' in opts) { | ||
sharedOpts.importFrom = opts.importFrom; | ||
} | ||
if ('exportTo' in opts) { | ||
@@ -511,10 +478,7 @@ sharedOpts.exportTo = { | ||
} | ||
if ('preserve' in opts) { | ||
sharedOpts.preserve = opts.preserve; | ||
} | ||
return sharedOpts; | ||
} | ||
return false; | ||
@@ -521,0 +485,0 @@ }; |
{ | ||
"name": "postcss-preset-env", | ||
"version": "6.7.1", | ||
"version": "6.7.2", | ||
"description": "Convert modern CSS into something browsers understand", | ||
@@ -20,2 +20,3 @@ "author": "Jonathan Neal <jonathantneal@hotmail.com>", | ||
"build": "rollup -c .rollup.js --silent", | ||
"prepublishOnly": "npm test", | ||
"pretest:tape": "npm run build", | ||
@@ -22,0 +23,0 @@ "test": "npm run test:js && npm run test:tape", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
870
135564