postcss-custom-properties
Advanced tools
Comparing version 8.0.11 to 9.0.1
# Changes to PostCSS Custom Properties | ||
### 9.0.1 (June 20, 2019) | ||
- Updated: `postcss-values-parser` to 3.0.4 (major) | ||
- Updated: Node 8+ compatibility (major) | ||
> This release is identical to v9.0.0, only `npm publish` failed to publish v9.0.0 and threw the following error: | ||
> ``` | ||
> You cannot publish over the previously published versions: 9.0.0. | ||
> ``` | ||
> I did not want this issue to distract me, and so I thoughtfully and impatiently published v9.0.0 as v9.0.1. | ||
### 8.0.11 (June 20, 2019) | ||
@@ -4,0 +15,0 @@ |
344
index.cjs.js
@@ -6,46 +6,6 @@ 'use strict'; | ||
var postcss = _interopDefault(require('postcss')); | ||
var valueParser = _interopDefault(require('postcss-values-parser')); | ||
var postcssValuesParser = require('postcss-values-parser'); | ||
var fs = _interopDefault(require('fs')); | ||
var path = _interopDefault(require('path')); | ||
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { | ||
try { | ||
var info = gen[key](arg); | ||
var value = info.value; | ||
} catch (error) { | ||
reject(error); | ||
return; | ||
} | ||
if (info.done) { | ||
resolve(value); | ||
} else { | ||
Promise.resolve(value).then(_next, _throw); | ||
} | ||
} | ||
function _asyncToGenerator(fn) { | ||
return function () { | ||
var self = this, | ||
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); | ||
}); | ||
}; | ||
} | ||
function parse(string) { | ||
return valueParser(string).parse(); | ||
} | ||
function isBlockIgnored(ruleOrDeclaration) { | ||
@@ -72,5 +32,7 @@ var rule = ruleOrDeclaration.selector ? ruleOrDeclaration : ruleOrDeclaration.parent; | ||
if (isCustomDecl(decl) && !isBlockIgnored(decl)) { | ||
const prop = decl.prop; // write the parsed value to the custom property | ||
const { | ||
prop | ||
} = decl; // write the parsed value to the custom property | ||
customPropertiesObject[prop] = parse(decl.value).nodes; // conditionally remove the custom property declaration | ||
customPropertiesObject[prop] = postcssValuesParser.parse(decl.value).nodes; // conditionally remove the custom property declaration | ||
@@ -109,4 +71,10 @@ if (!opts.preserve) { | ||
function getCustomPropertiesFromCSSFile(_x) { | ||
return _getCustomPropertiesFromCSSFile.apply(this, arguments); | ||
async function getCustomPropertiesFromCSSFile(from) { | ||
const css = await readFile(from); | ||
const root = postcss.parse(css, { | ||
from | ||
}); | ||
return getCustomPropertiesFromRoot(root, { | ||
preserve: true | ||
}); | ||
} | ||
@@ -117,15 +85,2 @@ /* Get Custom Properties from Object | ||
function _getCustomPropertiesFromCSSFile() { | ||
_getCustomPropertiesFromCSSFile = _asyncToGenerator(function* (from) { | ||
const css = yield readFile(from); | ||
const root = postcss.parse(css, { | ||
from | ||
}); | ||
return getCustomPropertiesFromRoot(root, { | ||
preserve: true | ||
}); | ||
}); | ||
return _getCustomPropertiesFromCSSFile.apply(this, arguments); | ||
} | ||
function getCustomPropertiesFromObject(object) { | ||
@@ -135,3 +90,3 @@ const customProperties = Object.assign({}, Object(object).customProperties, Object(object)['custom-properties']); | ||
for (const key in customProperties) { | ||
customProperties[key] = parse(String(customProperties[key])).nodes; | ||
customProperties[key] = postcssValuesParser.parse(String(customProperties[key])).nodes; | ||
} | ||
@@ -145,4 +100,5 @@ | ||
function getCustomPropertiesFromJSONFile(_x2) { | ||
return _getCustomPropertiesFromJSONFile.apply(this, arguments); | ||
async function getCustomPropertiesFromJSONFile(from) { | ||
const object = await readJSON(from); | ||
return getCustomPropertiesFromObject(object); | ||
} | ||
@@ -153,13 +109,6 @@ /* Get Custom Properties from JS file | ||
function _getCustomPropertiesFromJSONFile() { | ||
_getCustomPropertiesFromJSONFile = _asyncToGenerator(function* (from) { | ||
const object = yield readJSON(from); | ||
return getCustomPropertiesFromObject(object); | ||
}); | ||
return _getCustomPropertiesFromJSONFile.apply(this, arguments); | ||
async function getCustomPropertiesFromJSFile(from) { | ||
const object = await Promise.resolve(require(from)); | ||
return getCustomPropertiesFromObject(object); | ||
} | ||
function getCustomPropertiesFromJSFile(_x3) { | ||
return _getCustomPropertiesFromJSFile.apply(this, arguments); | ||
} | ||
/* Get Custom Properties from Imports | ||
@@ -169,10 +118,2 @@ /* ========================================================================== */ | ||
function _getCustomPropertiesFromJSFile() { | ||
_getCustomPropertiesFromJSFile = _asyncToGenerator(function* (from) { | ||
const object = yield Promise.resolve(require(from)); | ||
return getCustomPropertiesFromObject(object); | ||
}); | ||
return _getCustomPropertiesFromJSFile.apply(this, arguments); | ||
} | ||
function getCustomPropertiesFromImports(sources) { | ||
@@ -203,29 +144,22 @@ return sources.map(source => { | ||
}; | ||
}).reduce( | ||
/*#__PURE__*/ | ||
function () { | ||
var _ref = _asyncToGenerator(function* (customProperties, source) { | ||
const _ref2 = yield source, | ||
type = _ref2.type, | ||
from = _ref2.from; | ||
}).reduce(async (customProperties, source) => { | ||
const { | ||
type, | ||
from | ||
} = await source; | ||
if (type === 'css') { | ||
return Object.assign((yield customProperties), (yield getCustomPropertiesFromCSSFile(from))); | ||
} | ||
if (type === 'css') { | ||
return Object.assign((await customProperties), (await getCustomPropertiesFromCSSFile(from))); | ||
} | ||
if (type === 'js') { | ||
return Object.assign((yield customProperties), (yield getCustomPropertiesFromJSFile(from))); | ||
} | ||
if (type === 'js') { | ||
return Object.assign((await customProperties), (await getCustomPropertiesFromJSFile(from))); | ||
} | ||
if (type === 'json') { | ||
return Object.assign((yield customProperties), (yield getCustomPropertiesFromJSONFile(from))); | ||
} | ||
if (type === 'json') { | ||
return Object.assign((await customProperties), (await getCustomPropertiesFromJSONFile(from))); | ||
} | ||
return Object.assign((yield customProperties), (yield getCustomPropertiesFromObject((yield source)))); | ||
}); | ||
return function (_x4, _x5) { | ||
return _ref.apply(this, arguments); | ||
}; | ||
}(), {}); | ||
return Object.assign((await customProperties), (await getCustomPropertiesFromObject((await source)))); | ||
}, {}); | ||
} | ||
@@ -245,14 +179,4 @@ /* Helper utilities | ||
const readJSON = | ||
/*#__PURE__*/ | ||
function () { | ||
var _ref3 = _asyncToGenerator(function* (from) { | ||
return JSON.parse((yield readFile(from))); | ||
}); | ||
const readJSON = async from => JSON.parse((await readFile(from))); | ||
return function readJSON(_x6) { | ||
return _ref3.apply(this, arguments); | ||
}; | ||
}(); | ||
function transformValueAST(root, customProperties) { | ||
@@ -263,9 +187,7 @@ if (root.nodes && root.nodes.length) { | ||
// eslint-disable-next-line no-unused-vars | ||
const _child$nodes$slice = child.nodes.slice(1, -1), | ||
propertyNode = _child$nodes$slice[0], | ||
comma = _child$nodes$slice[1], | ||
fallbacks = _child$nodes$slice.slice(2); | ||
const [propertyNode, comma, ...fallbacks] = child.nodes; | ||
const { | ||
value: name | ||
} = propertyNode; | ||
const name = propertyNode.value; | ||
if (name in Object(customProperties)) { | ||
@@ -306,3 +228,3 @@ // conditionally replace a known custom property | ||
const isVarFunction = node => node.type === 'func' && varRegExp.test(node.value) && Object(node.nodes).length > 0; // return an array with its nodes cloned, preserving the raw | ||
const isVarFunction = node => node.type === 'func' && varRegExp.test(node.name) && Object(node.nodes).length > 0; // return an array with its nodes cloned, preserving the raw | ||
@@ -345,3 +267,3 @@ | ||
const originalValue = decl.value; | ||
const valueAST = parse(originalValue); | ||
const valueAST = postcssValuesParser.parse(originalValue); | ||
const value = String(transformValueAST(valueAST, customProperties)); // conditionally transform values that have changed | ||
@@ -371,4 +293,9 @@ | ||
function writeCustomPropertiesToCssFile(_x, _x2) { | ||
return _writeCustomPropertiesToCssFile.apply(this, arguments); | ||
async function writeCustomPropertiesToCssFile(to, customProperties) { | ||
const cssContent = Object.keys(customProperties).reduce((cssLines, name) => { | ||
cssLines.push(`\t${name}: ${customProperties[name]};`); | ||
return cssLines; | ||
}, []).join('\n'); | ||
const css = `:root {\n${cssContent}\n}\n`; | ||
await writeFile(to, css); | ||
} | ||
@@ -379,17 +306,9 @@ /* Write Custom Properties to JSON file | ||
function _writeCustomPropertiesToCssFile() { | ||
_writeCustomPropertiesToCssFile = _asyncToGenerator(function* (to, customProperties) { | ||
const cssContent = Object.keys(customProperties).reduce((cssLines, name) => { | ||
cssLines.push(`\t${name}: ${customProperties[name]};`); | ||
return cssLines; | ||
}, []).join('\n'); | ||
const css = `:root {\n${cssContent}\n}\n`; | ||
yield writeFile(to, css); | ||
}); | ||
return _writeCustomPropertiesToCssFile.apply(this, arguments); | ||
async function writeCustomPropertiesToJsonFile(to, customProperties) { | ||
const jsonContent = JSON.stringify({ | ||
'custom-properties': customProperties | ||
}, null, ' '); | ||
const json = `${jsonContent}\n`; | ||
await writeFile(to, json); | ||
} | ||
function writeCustomPropertiesToJsonFile(_x3, _x4) { | ||
return _writeCustomPropertiesToJsonFile.apply(this, arguments); | ||
} | ||
/* Write Custom Properties to Common JS file | ||
@@ -399,16 +318,10 @@ /* ========================================================================== */ | ||
function _writeCustomPropertiesToJsonFile() { | ||
_writeCustomPropertiesToJsonFile = _asyncToGenerator(function* (to, customProperties) { | ||
const jsonContent = JSON.stringify({ | ||
'custom-properties': customProperties | ||
}, null, ' '); | ||
const json = `${jsonContent}\n`; | ||
yield writeFile(to, json); | ||
}); | ||
return _writeCustomPropertiesToJsonFile.apply(this, arguments); | ||
async function writeCustomPropertiesToCjsFile(to, customProperties) { | ||
const jsContents = Object.keys(customProperties).reduce((jsLines, name) => { | ||
jsLines.push(`\t\t'${escapeForJS(name)}': '${escapeForJS(customProperties[name])}'`); | ||
return jsLines; | ||
}, []).join(',\n'); | ||
const js = `module.exports = {\n\tcustomProperties: {\n${jsContents}\n\t}\n};\n`; | ||
await writeFile(to, js); | ||
} | ||
function writeCustomPropertiesToCjsFile(_x5, _x6) { | ||
return _writeCustomPropertiesToCjsFile.apply(this, arguments); | ||
} | ||
/* Write Custom Properties to Module JS file | ||
@@ -418,17 +331,10 @@ /* ========================================================================== */ | ||
function _writeCustomPropertiesToCjsFile() { | ||
_writeCustomPropertiesToCjsFile = _asyncToGenerator(function* (to, customProperties) { | ||
const jsContents = Object.keys(customProperties).reduce((jsLines, name) => { | ||
jsLines.push(`\t\t'${escapeForJS(name)}': '${escapeForJS(customProperties[name])}'`); | ||
return jsLines; | ||
}, []).join(',\n'); | ||
const js = `module.exports = {\n\tcustomProperties: {\n${jsContents}\n\t}\n};\n`; | ||
yield writeFile(to, js); | ||
}); | ||
return _writeCustomPropertiesToCjsFile.apply(this, arguments); | ||
async function writeCustomPropertiesToMjsFile(to, customProperties) { | ||
const mjsContents = Object.keys(customProperties).reduce((mjsLines, name) => { | ||
mjsLines.push(`\t'${escapeForJS(name)}': '${escapeForJS(customProperties[name])}'`); | ||
return mjsLines; | ||
}, []).join(',\n'); | ||
const mjs = `export const customProperties = {\n${mjsContents}\n};\n`; | ||
await writeFile(to, mjs); | ||
} | ||
function writeCustomPropertiesToMjsFile(_x7, _x8) { | ||
return _writeCustomPropertiesToMjsFile.apply(this, arguments); | ||
} | ||
/* Write Custom Properties to Exports | ||
@@ -438,66 +344,46 @@ /* ========================================================================== */ | ||
function _writeCustomPropertiesToMjsFile() { | ||
_writeCustomPropertiesToMjsFile = _asyncToGenerator(function* (to, customProperties) { | ||
const mjsContents = Object.keys(customProperties).reduce((mjsLines, name) => { | ||
mjsLines.push(`\t'${escapeForJS(name)}': '${escapeForJS(customProperties[name])}'`); | ||
return mjsLines; | ||
}, []).join(',\n'); | ||
const mjs = `export const customProperties = {\n${mjsContents}\n};\n`; | ||
yield writeFile(to, mjs); | ||
}); | ||
return _writeCustomPropertiesToMjsFile.apply(this, arguments); | ||
} | ||
function writeCustomPropertiesToExports(customProperties, destinations) { | ||
return Promise.all(destinations.map( | ||
/*#__PURE__*/ | ||
function () { | ||
var _ref = _asyncToGenerator(function* (destination) { | ||
if (destination instanceof Function) { | ||
yield destination(defaultCustomPropertiesToJSON(customProperties)); | ||
} else { | ||
// read the destination as an object | ||
const opts = destination === Object(destination) ? destination : { | ||
to: String(destination) | ||
}; // transformer for Custom Properties into a JSON-compatible object | ||
return Promise.all(destinations.map(async destination => { | ||
if (destination instanceof Function) { | ||
await destination(defaultCustomPropertiesToJSON(customProperties)); | ||
} else { | ||
// read the destination as an object | ||
const opts = destination === Object(destination) ? destination : { | ||
to: String(destination) | ||
}; // transformer for Custom Properties into a JSON-compatible object | ||
const toJSON = opts.toJSON || defaultCustomPropertiesToJSON; | ||
const toJSON = opts.toJSON || defaultCustomPropertiesToJSON; | ||
if ('customProperties' in opts) { | ||
// write directly to an object as customProperties | ||
opts.customProperties = toJSON(customProperties); | ||
} else if ('custom-properties' in opts) { | ||
// write directly to an object as custom-properties | ||
opts['custom-properties'] = toJSON(customProperties); | ||
} else { | ||
// destination pathname | ||
const to = String(opts.to || ''); // type of file being written to | ||
if ('customProperties' in opts) { | ||
// write directly to an object as customProperties | ||
opts.customProperties = toJSON(customProperties); | ||
} else if ('custom-properties' in opts) { | ||
// write directly to an object as custom-properties | ||
opts['custom-properties'] = toJSON(customProperties); | ||
} else { | ||
// destination pathname | ||
const to = String(opts.to || ''); // type of file being written to | ||
const type = (opts.type || path.extname(opts.to).slice(1)).toLowerCase(); // transformed Custom Properties | ||
const type = (opts.type || path.extname(opts.to).slice(1)).toLowerCase(); // transformed Custom Properties | ||
const customPropertiesJSON = toJSON(customProperties); | ||
const customPropertiesJSON = toJSON(customProperties); | ||
if (type === 'css') { | ||
yield writeCustomPropertiesToCssFile(to, customPropertiesJSON); | ||
} | ||
if (type === 'css') { | ||
await writeCustomPropertiesToCssFile(to, customPropertiesJSON); | ||
} | ||
if (type === 'js') { | ||
yield writeCustomPropertiesToCjsFile(to, customPropertiesJSON); | ||
} | ||
if (type === 'js') { | ||
await writeCustomPropertiesToCjsFile(to, customPropertiesJSON); | ||
} | ||
if (type === 'json') { | ||
yield writeCustomPropertiesToJsonFile(to, customPropertiesJSON); | ||
} | ||
if (type === 'json') { | ||
await writeCustomPropertiesToJsonFile(to, customPropertiesJSON); | ||
} | ||
if (type === 'mjs') { | ||
yield writeCustomPropertiesToMjsFile(to, customPropertiesJSON); | ||
} | ||
if (type === 'mjs') { | ||
await writeCustomPropertiesToMjsFile(to, customPropertiesJSON); | ||
} | ||
} | ||
}); | ||
return function (_x9) { | ||
return _ref.apply(this, arguments); | ||
}; | ||
}())); | ||
} | ||
})); | ||
} | ||
@@ -546,21 +432,13 @@ /* Helper utilities | ||
const asyncTransform = | ||
/*#__PURE__*/ | ||
function () { | ||
var _ref = _asyncToGenerator(function* (root) { | ||
const customProperties = Object.assign({}, (yield customPropertiesPromise), getCustomPropertiesFromRoot(root, { | ||
preserve | ||
})); | ||
yield writeCustomPropertiesToExports(customProperties, exportTo); | ||
transformProperties(root, customProperties, { | ||
preserve | ||
}); | ||
const asyncTransform = async root => { | ||
const customProperties = Object.assign({}, (await customPropertiesPromise), getCustomPropertiesFromRoot(root, { | ||
preserve | ||
})); | ||
await writeCustomPropertiesToExports(customProperties, exportTo); | ||
transformProperties(root, customProperties, { | ||
preserve | ||
}); | ||
}; // whether to return synchronous function if no asynchronous operations are requested | ||
return function asyncTransform(_x) { | ||
return _ref.apply(this, arguments); | ||
}; | ||
}(); // whether to return synchronous function if no asynchronous operations are requested | ||
const canReturnSyncFunction = importFrom.length === 0 && exportTo.length === 0; | ||
@@ -567,0 +445,0 @@ return canReturnSyncFunction ? syncTransform : asyncTransform; |
{ | ||
"name": "postcss-custom-properties", | ||
"version": "8.0.11", | ||
"version": "9.0.1", | ||
"description": "Use Custom Properties Queries in CSS", | ||
@@ -29,7 +29,7 @@ "author": "Jonathan Neal <jonathantneal@hotmail.com>", | ||
"engines": { | ||
"node": ">=6.0.0" | ||
"node": ">=8.0.0" | ||
}, | ||
"dependencies": { | ||
"postcss": "^7.0.17", | ||
"postcss-values-parser": "^2.0.1" | ||
"postcss-values-parser": "^3.0.4" | ||
}, | ||
@@ -42,3 +42,3 @@ "devDependencies": { | ||
"eslint": "^5.16.0", | ||
"postcss-tape": "^4.0.0", | ||
"postcss-tape": "^5.0.0", | ||
"pre-commit": "^1.2.2", | ||
@@ -45,0 +45,0 @@ "rollup": "^1.15.6", |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
0
105243
664
+ Addedcolor-name@1.1.4(transitive)
+ Addedip-regex@4.3.0(transitive)
+ Addedis-url-superb@3.0.0(transitive)
+ Addedpostcss-values-parser@3.2.1(transitive)
+ Addedtlds@1.255.0(transitive)
+ Addedurl-regex@5.0.0(transitive)
- Removedflatten@1.0.3(transitive)
- Removedindexes-of@1.0.1(transitive)
- Removedpostcss-values-parser@2.0.1(transitive)
- Removeduniq@1.0.1(transitive)
Updatedpostcss-values-parser@^3.0.4