diff --git a/package-lock.json b/package-lock.json index 2eb653831..4d535ad2c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -72,7 +72,7 @@ }, "experimental/css-has-pseudo": { "name": "@csstools/css-has-pseudo-experimental", - "version": "0.1.0", + "version": "0.1.1", "license": "CC0-1.0", "dependencies": { "postcss-selector-parser": "^6.0.8" @@ -4932,6 +4932,15 @@ "url": "https://github.com/sponsors/jonschlinkert" } }, + "node_modules/pify": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/pify/-/pify-2.3.0.tgz", + "integrity": "sha1-7RQaasBDqEnqWISY59yosVMw6Qw=", + "dev": true, + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/pkg-dir": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/pkg-dir/-/pkg-dir-4.2.0.tgz", @@ -5049,6 +5058,23 @@ "resolved": "plugins/postcss-image-set-function", "link": true }, + "node_modules/postcss-import": { + "version": "14.0.2", + "resolved": "https://registry.npmjs.org/postcss-import/-/postcss-import-14.0.2.tgz", + "integrity": "sha512-BJ2pVK4KhUyMcqjuKs9RijV5tatNzNa73e/32aBVE/ejYPe37iH+6vAu9WvqUkB5OAYgLHzbSvzHnorybJCm9g==", + "dev": true, + "dependencies": { + "postcss-value-parser": "^4.0.0", + "read-cache": "^1.0.0", + "resolve": "^1.1.7" + }, + "engines": { + "node": ">=10.0.0" + }, + "peerDependencies": { + "postcss": "^8.0.0" + } + }, "node_modules/postcss-initial": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/postcss-initial/-/postcss-initial-4.0.1.tgz", @@ -5299,6 +5325,15 @@ "safe-buffer": "^5.1.0" } }, + "node_modules/read-cache": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/read-cache/-/read-cache-1.0.0.tgz", + "integrity": "sha1-5mTvMRYRZsl1HNvo28+GtftY93Q=", + "dev": true, + "dependencies": { + "pify": "^2.3.0" + } + }, "node_modules/readable-stream": { "version": "3.6.0", "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz", @@ -6397,6 +6432,7 @@ }, "devDependencies": { "postcss": "^8.3.6", + "postcss-import": "^14.0.2", "postcss-tape": "^6.0.1" }, "engines": { @@ -10158,6 +10194,12 @@ "integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==", "dev": true }, + "pify": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/pify/-/pify-2.3.0.tgz", + "integrity": "sha1-7RQaasBDqEnqWISY59yosVMw6Qw=", + "dev": true + }, "pkg-dir": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/pkg-dir/-/pkg-dir-4.2.0.tgz", @@ -10219,6 +10261,7 @@ "version": "file:plugins/postcss-custom-properties", "requires": { "postcss": "^8.3.6", + "postcss-import": "^14.0.2", "postcss-tape": "^6.0.1", "postcss-value-parser": "^4.2.0" } @@ -10292,6 +10335,17 @@ "postcss-value-parser": "^4.2.0" } }, + "postcss-import": { + "version": "14.0.2", + "resolved": "https://registry.npmjs.org/postcss-import/-/postcss-import-14.0.2.tgz", + "integrity": "sha512-BJ2pVK4KhUyMcqjuKs9RijV5tatNzNa73e/32aBVE/ejYPe37iH+6vAu9WvqUkB5OAYgLHzbSvzHnorybJCm9g==", + "dev": true, + "requires": { + "postcss-value-parser": "^4.0.0", + "read-cache": "^1.0.0", + "resolve": "^1.1.7" + } + }, "postcss-initial": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/postcss-initial/-/postcss-initial-4.0.1.tgz", @@ -10528,6 +10582,15 @@ "safe-buffer": "^5.1.0" } }, + "read-cache": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/read-cache/-/read-cache-1.0.0.tgz", + "integrity": "sha1-5mTvMRYRZsl1HNvo28+GtftY93Q=", + "dev": true, + "requires": { + "pify": "^2.3.0" + } + }, "readable-stream": { "version": "3.6.0", "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz", diff --git a/plugins/postcss-custom-properties/.tape.js b/plugins/postcss-custom-properties/.tape.js index e0589a6d5..c5593174f 100644 --- a/plugins/postcss-custom-properties/.tape.js +++ b/plugins/postcss-custom-properties/.tape.js @@ -1,3 +1,5 @@ +const importWithProps = require('./test/import'); + module.exports = { 'basic': { message: 'supports basic usage' @@ -311,5 +313,13 @@ module.exports = { options: { importFrom: {} } + }, + 'import': { + message: 'supports "postcss-import"', + options: { + expect: 'import.expect.css', + result: 'import.result.css' + }, + plugin: importWithProps } }; diff --git a/plugins/postcss-custom-properties/package.json b/plugins/postcss-custom-properties/package.json index 0ef854602..6a67c82ea 100644 --- a/plugins/postcss-custom-properties/package.json +++ b/plugins/postcss-custom-properties/package.json @@ -36,6 +36,7 @@ }, "devDependencies": { "postcss": "^8.3.6", + "postcss-import": "^14.0.2", "postcss-tape": "^6.0.1" }, "peerDependencies": { diff --git a/plugins/postcss-custom-properties/src/index.js b/plugins/postcss-custom-properties/src/index.js index 7d755450a..cc750fc91 100755 --- a/plugins/postcss-custom-properties/src/index.js +++ b/plugins/postcss-custom-properties/src/index.js @@ -23,11 +23,12 @@ const creator = opts => { return { postcssPlugin: 'postcss-custom-properties', - prepare ({ root }) { + prepare () { if (canReturnSyncFunction) { - customProperties = getCustomPropertiesFromRoot(root, { preserve }); - return { + Once: (root) => { + customProperties = getCustomPropertiesFromRoot(root, { preserve }); + }, Declaration: (decl) => transformProperties(decl, customProperties, { preserve }), }; } else { diff --git a/plugins/postcss-custom-properties/test/import.css b/plugins/postcss-custom-properties/test/import.css new file mode 100644 index 000000000..64636398d --- /dev/null +++ b/plugins/postcss-custom-properties/test/import.css @@ -0,0 +1,5 @@ +@import "./imported-file.css"; + +a { + color: var(--color); +} diff --git a/plugins/postcss-custom-properties/test/import.expect.css b/plugins/postcss-custom-properties/test/import.expect.css new file mode 100644 index 000000000..c7fcc0ac0 --- /dev/null +++ b/plugins/postcss-custom-properties/test/import.expect.css @@ -0,0 +1,8 @@ +:root { + --color: blue; +} + +a { + color: blue; + color: var(--color); +} diff --git a/plugins/postcss-custom-properties/test/import.js b/plugins/postcss-custom-properties/test/import.js new file mode 100644 index 000000000..34dcc2b23 --- /dev/null +++ b/plugins/postcss-custom-properties/test/import.js @@ -0,0 +1,12 @@ +const postcssImport = require('postcss-import'); + +const importWithProps = () => { + return { + postcssPlugin: 'postcss-custom-properties (with postcss-import)', + plugins: [postcssImport(), require('../dist/index.cjs')()], + }; +}; + +importWithProps.postcss = true; + +module.exports = importWithProps; diff --git a/plugins/postcss-custom-properties/test/imported-file.css b/plugins/postcss-custom-properties/test/imported-file.css new file mode 100644 index 000000000..eb0ff0d59 --- /dev/null +++ b/plugins/postcss-custom-properties/test/imported-file.css @@ -0,0 +1,3 @@ +:root { + --color: blue; +}