Skip to content

Commit

Permalink
Fix Interop Issue with Import and Custom Properties (#133)
Browse files Browse the repository at this point in the history
* Creating test case

* Fixing test

* Removing synchronous code

* Keeping the previous functionality
  • Loading branch information
Antonio-Laguna authored Jan 7, 2022
1 parent 0309cc8 commit 581678f
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 4 deletions.
65 changes: 64 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions plugins/postcss-custom-properties/.tape.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const importWithProps = require('./test/import');

module.exports = {
'basic': {
message: 'supports basic usage'
Expand Down Expand Up @@ -311,5 +313,13 @@ module.exports = {
options: {
importFrom: {}
}
},
'import': {
message: 'supports "postcss-import"',
options: {
expect: 'import.expect.css',
result: 'import.result.css'
},
plugin: importWithProps
}
};
1 change: 1 addition & 0 deletions plugins/postcss-custom-properties/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
},
"devDependencies": {
"postcss": "^8.3.6",
"postcss-import": "^14.0.2",
"postcss-tape": "^6.0.1"
},
"peerDependencies": {
Expand Down
7 changes: 4 additions & 3 deletions plugins/postcss-custom-properties/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions plugins/postcss-custom-properties/test/import.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@import "./imported-file.css";

a {
color: var(--color);
}
8 changes: 8 additions & 0 deletions plugins/postcss-custom-properties/test/import.expect.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
:root {
--color: blue;
}

a {
color: blue;
color: var(--color);
}
12 changes: 12 additions & 0 deletions plugins/postcss-custom-properties/test/import.js
Original file line number Diff line number Diff line change
@@ -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;
3 changes: 3 additions & 0 deletions plugins/postcss-custom-properties/test/imported-file.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
:root {
--color: blue;
}

0 comments on commit 581678f

Please sign in to comment.