Skip to content

postcss-custom-properties : fix types and some small bugs #139

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

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
21 changes: 21 additions & 0 deletions plugin-packs/postcss-preset-env/.tape.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,27 @@ module.exports = {
stage: 0
}
},
'import:ch88': {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is very much broken.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see : #140

message: 'supports { browsers: "chrome >= 88", importFrom: { customMedia, customProperties, customSelectors, environmentVariables } } usage',
options: {
browsers: 'chrome >= 88',
importFrom: {
customMedia: {
'--narrow-window': '(max-width: env(--sm))'
},
customProperties: {
'--order': '1'
},
customSelectors: {
':--heading': 'h1, h2, h3, h4, h5, h6'
},
environmentVariables: {
'--sm': '40rem'
}
},
stage: 0
}
},
'basic:export': {
message: 'supports { stage: 0 } usage',
options: {
Expand Down
14 changes: 14 additions & 0 deletions plugin-packs/postcss-preset-env/test/import.ch88.expect.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.test-custom-properties {
order: var(--order);
}

@media (max-width: 40rem) {
.test-custom-media-queries {
order: 2;
}
}

h1.test-custom-selectors,h2.test-custom-selectors,h3.test-custom-selectors,h4.test-custom-selectors,h5.test-custom-selectors,h6.test-custom-selectors {
order: 3;
}

59 changes: 38 additions & 21 deletions plugins/postcss-custom-properties/.tape.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const importWithProps = require('./test/import');
const assert = require('assert').strict;

module.exports = {
'basic': {
Expand Down Expand Up @@ -80,6 +81,17 @@ module.exports = {
expect: 'basic.import.expect.css',
result: 'basic.import.result.css'
},
'basic:import-cjs': {
message: 'supports { importFrom: "test/import-properties{-2}?.cjs" } usage',
options: {
importFrom: [
'test/import-properties.cjs',
'test/import-properties-2.cjs'
]
},
expect: 'basic.import.expect.css',
result: 'basic.import.result.css'
},
'basic:import-css': {
message: 'supports { importFrom: "test/import-properties{-2}?.css" } usage',
options: {
Expand Down Expand Up @@ -153,6 +165,25 @@ module.exports = {
expect: 'basic.import-override.expect.css',
result: 'basic.import-override.result.css'
},
'basic:import-override:inverse': {
message: 'importFrom with { preserve: false, overrideImportFromWithRoot: true } should override importFrom properties',
options: {
preserve: false,
overrideImportFromWithRoot: true,
importFrom: {
customProperties: {
'--color': 'rgb(0, 0, 0)',
'--color-2': 'yellow',
'--ref-color': 'var(--color)',
'--margin': '0 10px 20px 30px',
'--shadow-color': 'rgb(0,0,0)',
'--z-index': 10
}
}
},
expect: 'basic.import-override.inverse.expect.css',
result: 'basic.import-override.inverse.result.css'
},
'basic:export': {
message: 'supports { exportTo: { customProperties: { ... } } } usage',
options: {
Expand Down Expand Up @@ -207,9 +238,7 @@ module.exports = {
global.__exportPropertiesString = require('fs').readFileSync('test/export-properties.scss', 'utf8');
},
after() {
if (global.__exportPropertiesString !== require('fs').readFileSync('test/export-properties.scss', 'utf8')) {
throw new Error('The original file did not match the freshly exported copy');
}
assert.strictEqual(global.__exportPropertiesString, require('fs').readFileSync('test/export-properties.scss', 'utf8'));
}
},
'basic:export-json': {
Expand All @@ -223,9 +252,7 @@ module.exports = {
global.__exportPropertiesString = require('fs').readFileSync('test/export-properties.json', 'utf8');
},
after() {
if (global.__exportPropertiesString !== require('fs').readFileSync('test/export-properties.json', 'utf8')) {
throw new Error('The original file did not match the freshly exported copy');
}
assert.strictEqual(global.__exportPropertiesString, require('fs').readFileSync('test/export-properties.json', 'utf8'));
}
},
'basic:export-js': {
Expand All @@ -239,9 +266,7 @@ module.exports = {
global.__exportPropertiesString = require('fs').readFileSync('test/export-properties.js', 'utf8');
},
after() {
if (global.__exportPropertiesString !== require('fs').readFileSync('test/export-properties.js', 'utf8')) {
throw new Error('The original file did not match the freshly exported copy');
}
assert.strictEqual(global.__exportPropertiesString, require('fs').readFileSync('test/export-properties.js', 'utf8'));
}
},
'basic:export-mjs': {
Expand All @@ -255,9 +280,7 @@ module.exports = {
global.__exportPropertiesString = require('fs').readFileSync('test/export-properties.mjs', 'utf8');
},
after() {
if (global.__exportPropertiesString !== require('fs').readFileSync('test/export-properties.mjs', 'utf8')) {
throw new Error('The original file did not match the freshly exported copy');
}
assert.strictEqual(global.__exportPropertiesString, require('fs').readFileSync('test/export-properties.mjs', 'utf8'));
}
},
'basic:export-css': {
Expand All @@ -271,9 +294,7 @@ module.exports = {
global.__exportPropertiesString = require('fs').readFileSync('test/export-properties.css', 'utf8');
},
after() {
if (global.__exportPropertiesString !== require('fs').readFileSync('test/export-properties.css', 'utf8')) {
throw new Error('The original file did not match the freshly exported copy');
}
assert.strictEqual(global.__exportPropertiesString, require('fs').readFileSync('test/export-properties.css', 'utf8'));
}
},
'basic:export-css-to': {
Expand All @@ -287,9 +308,7 @@ module.exports = {
global.__exportPropertiesString = require('fs').readFileSync('test/export-properties.css', 'utf8');
},
after() {
if (global.__exportPropertiesString !== require('fs').readFileSync('test/export-properties.css', 'utf8')) {
throw new Error('The original file did not match the freshly exported copy');
}
assert.strictEqual(global.__exportPropertiesString, require('fs').readFileSync('test/export-properties.css', 'utf8'));
}
},
'basic:export-css-to-type': {
Expand All @@ -303,9 +322,7 @@ module.exports = {
global.__exportPropertiesString = require('fs').readFileSync('test/export-properties.css', 'utf8');
},
after() {
if (global.__exportPropertiesString !== require('fs').readFileSync('test/export-properties.css', 'utf8')) {
throw new Error('The original file did not match the freshly exported copy');
}
assert.strictEqual(global.__exportPropertiesString, require('fs').readFileSync('test/export-properties.css', 'utf8'));
}
},
'basic:import-is-empty': {
Expand Down
8 changes: 8 additions & 0 deletions plugins/postcss-custom-properties/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changes to PostCSS Custom Properties

### Unreleased

- Add `overrideImportFromWithRoot` option
- Allow `.mjs` in `importFrom`
- Converted to typescript
- Correct typings for plugin options
- Fix unicode support in custom property names

### 12.0.4 (January 7, 2022)

- Fixed an issue that was causing synchronous mode to not being able to pick and transform properties that were added as part of the PostCSS flow. ([#132](https://github.com/csstools/postcss-plugins/issues/132))
Expand Down
11 changes: 11 additions & 0 deletions plugins/postcss-custom-properties/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,17 @@ postcssCustomProperties({
See example imports written in [CSS](test/import-properties.css),
[JS](test/import-properties.js), and [JSON](test/import-properties.json).

### overrideImportFromWithRoot

The `overrideImportFromWithRoot` option determines if properties added via `importFrom` are overridden by properties that exist in `:root`.
Defaults to `false`.

```js
postcssCustomProperties({
overrideImportFromWithRoot: true
});
```

### exportTo

The `exportTo` option specifies destinations where Custom Properties can be exported
Expand Down
39 changes: 0 additions & 39 deletions plugins/postcss-custom-properties/index.d.ts

This file was deleted.

9 changes: 8 additions & 1 deletion plugins/postcss-custom-properties/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@
"bugs": "https://github.com/csstools/postcss-plugins/issues",
"main": "dist/index.cjs",
"module": "dist/index.mjs",
"types": "index.d.ts",
"types": "dist/index.d.ts",
"exports": {
".": {
"import": "./dist/index.mjs",
"require": "./dist/index.cjs",
"default": "./dist/index.mjs"
}
},
"files": [
"CHANGELOG.md",
"LICENSE.md",
Expand Down
54 changes: 0 additions & 54 deletions plugins/postcss-custom-properties/src/index.js

This file was deleted.

Loading