Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Interop Issue with Import and Custom Properties #133

Merged
merged 4 commits into from
Jan 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}