Skip to content

Commit c4863ca

Browse files
authored
postcss-custom-properties : fix types and some small bugs (#139)
* postcss-custom-properties: fix types * cleanup * update change log * more fixes * add overrideImportFromWithRoot option * cleanup
1 parent d09226f commit c4863ca

37 files changed

+673
-315
lines changed

plugin-packs/postcss-preset-env/.tape.js

+21
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,27 @@ module.exports = {
235235
stage: 0
236236
}
237237
},
238+
'import:ch88': {
239+
message: 'supports { browsers: "chrome >= 88", importFrom: { customMedia, customProperties, customSelectors, environmentVariables } } usage',
240+
options: {
241+
browsers: 'chrome >= 88',
242+
importFrom: {
243+
customMedia: {
244+
'--narrow-window': '(max-width: env(--sm))'
245+
},
246+
customProperties: {
247+
'--order': '1'
248+
},
249+
customSelectors: {
250+
':--heading': 'h1, h2, h3, h4, h5, h6'
251+
},
252+
environmentVariables: {
253+
'--sm': '40rem'
254+
}
255+
},
256+
stage: 0
257+
}
258+
},
238259
'basic:export': {
239260
message: 'supports { stage: 0 } usage',
240261
options: {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
.test-custom-properties {
2+
order: var(--order);
3+
}
4+
5+
@media (max-width: 40rem) {
6+
.test-custom-media-queries {
7+
order: 2;
8+
}
9+
}
10+
11+
h1.test-custom-selectors,h2.test-custom-selectors,h3.test-custom-selectors,h4.test-custom-selectors,h5.test-custom-selectors,h6.test-custom-selectors {
12+
order: 3;
13+
}
14+

plugins/postcss-custom-properties/.tape.js

+38-21
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const importWithProps = require('./test/import');
2+
const assert = require('assert').strict;
23

34
module.exports = {
45
'basic': {
@@ -80,6 +81,17 @@ module.exports = {
8081
expect: 'basic.import.expect.css',
8182
result: 'basic.import.result.css'
8283
},
84+
'basic:import-cjs': {
85+
message: 'supports { importFrom: "test/import-properties{-2}?.cjs" } usage',
86+
options: {
87+
importFrom: [
88+
'test/import-properties.cjs',
89+
'test/import-properties-2.cjs'
90+
]
91+
},
92+
expect: 'basic.import.expect.css',
93+
result: 'basic.import.result.css'
94+
},
8395
'basic:import-css': {
8496
message: 'supports { importFrom: "test/import-properties{-2}?.css" } usage',
8597
options: {
@@ -153,6 +165,25 @@ module.exports = {
153165
expect: 'basic.import-override.expect.css',
154166
result: 'basic.import-override.result.css'
155167
},
168+
'basic:import-override:inverse': {
169+
message: 'importFrom with { preserve: false, overrideImportFromWithRoot: true } should override importFrom properties',
170+
options: {
171+
preserve: false,
172+
overrideImportFromWithRoot: true,
173+
importFrom: {
174+
customProperties: {
175+
'--color': 'rgb(0, 0, 0)',
176+
'--color-2': 'yellow',
177+
'--ref-color': 'var(--color)',
178+
'--margin': '0 10px 20px 30px',
179+
'--shadow-color': 'rgb(0,0,0)',
180+
'--z-index': 10
181+
}
182+
}
183+
},
184+
expect: 'basic.import-override.inverse.expect.css',
185+
result: 'basic.import-override.inverse.result.css'
186+
},
156187
'basic:export': {
157188
message: 'supports { exportTo: { customProperties: { ... } } } usage',
158189
options: {
@@ -207,9 +238,7 @@ module.exports = {
207238
global.__exportPropertiesString = require('fs').readFileSync('test/export-properties.scss', 'utf8');
208239
},
209240
after() {
210-
if (global.__exportPropertiesString !== require('fs').readFileSync('test/export-properties.scss', 'utf8')) {
211-
throw new Error('The original file did not match the freshly exported copy');
212-
}
241+
assert.strictEqual(global.__exportPropertiesString, require('fs').readFileSync('test/export-properties.scss', 'utf8'));
213242
}
214243
},
215244
'basic:export-json': {
@@ -223,9 +252,7 @@ module.exports = {
223252
global.__exportPropertiesString = require('fs').readFileSync('test/export-properties.json', 'utf8');
224253
},
225254
after() {
226-
if (global.__exportPropertiesString !== require('fs').readFileSync('test/export-properties.json', 'utf8')) {
227-
throw new Error('The original file did not match the freshly exported copy');
228-
}
255+
assert.strictEqual(global.__exportPropertiesString, require('fs').readFileSync('test/export-properties.json', 'utf8'));
229256
}
230257
},
231258
'basic:export-js': {
@@ -239,9 +266,7 @@ module.exports = {
239266
global.__exportPropertiesString = require('fs').readFileSync('test/export-properties.js', 'utf8');
240267
},
241268
after() {
242-
if (global.__exportPropertiesString !== require('fs').readFileSync('test/export-properties.js', 'utf8')) {
243-
throw new Error('The original file did not match the freshly exported copy');
244-
}
269+
assert.strictEqual(global.__exportPropertiesString, require('fs').readFileSync('test/export-properties.js', 'utf8'));
245270
}
246271
},
247272
'basic:export-mjs': {
@@ -255,9 +280,7 @@ module.exports = {
255280
global.__exportPropertiesString = require('fs').readFileSync('test/export-properties.mjs', 'utf8');
256281
},
257282
after() {
258-
if (global.__exportPropertiesString !== require('fs').readFileSync('test/export-properties.mjs', 'utf8')) {
259-
throw new Error('The original file did not match the freshly exported copy');
260-
}
283+
assert.strictEqual(global.__exportPropertiesString, require('fs').readFileSync('test/export-properties.mjs', 'utf8'));
261284
}
262285
},
263286
'basic:export-css': {
@@ -271,9 +294,7 @@ module.exports = {
271294
global.__exportPropertiesString = require('fs').readFileSync('test/export-properties.css', 'utf8');
272295
},
273296
after() {
274-
if (global.__exportPropertiesString !== require('fs').readFileSync('test/export-properties.css', 'utf8')) {
275-
throw new Error('The original file did not match the freshly exported copy');
276-
}
297+
assert.strictEqual(global.__exportPropertiesString, require('fs').readFileSync('test/export-properties.css', 'utf8'));
277298
}
278299
},
279300
'basic:export-css-to': {
@@ -287,9 +308,7 @@ module.exports = {
287308
global.__exportPropertiesString = require('fs').readFileSync('test/export-properties.css', 'utf8');
288309
},
289310
after() {
290-
if (global.__exportPropertiesString !== require('fs').readFileSync('test/export-properties.css', 'utf8')) {
291-
throw new Error('The original file did not match the freshly exported copy');
292-
}
311+
assert.strictEqual(global.__exportPropertiesString, require('fs').readFileSync('test/export-properties.css', 'utf8'));
293312
}
294313
},
295314
'basic:export-css-to-type': {
@@ -303,9 +322,7 @@ module.exports = {
303322
global.__exportPropertiesString = require('fs').readFileSync('test/export-properties.css', 'utf8');
304323
},
305324
after() {
306-
if (global.__exportPropertiesString !== require('fs').readFileSync('test/export-properties.css', 'utf8')) {
307-
throw new Error('The original file did not match the freshly exported copy');
308-
}
325+
assert.strictEqual(global.__exportPropertiesString, require('fs').readFileSync('test/export-properties.css', 'utf8'));
309326
}
310327
},
311328
'basic:import-is-empty': {

plugins/postcss-custom-properties/CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Changes to PostCSS Custom Properties
22

3+
### Unreleased
4+
5+
- Add `overrideImportFromWithRoot` option
6+
- Allow `.mjs` in `importFrom`
7+
- Converted to typescript
8+
- Correct typings for plugin options
9+
- Fix unicode support in custom property names
10+
311
### 12.0.4 (January 7, 2022)
412

513
- 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))

plugins/postcss-custom-properties/README.md

+11
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,17 @@ postcssCustomProperties({
137137
See example imports written in [CSS](test/import-properties.css),
138138
[JS](test/import-properties.js), and [JSON](test/import-properties.json).
139139

140+
### overrideImportFromWithRoot
141+
142+
The `overrideImportFromWithRoot` option determines if properties added via `importFrom` are overridden by properties that exist in `:root`.
143+
Defaults to `false`.
144+
145+
```js
146+
postcssCustomProperties({
147+
overrideImportFromWithRoot: true
148+
});
149+
```
150+
140151
### exportTo
141152

142153
The `exportTo` option specifies destinations where Custom Properties can be exported

plugins/postcss-custom-properties/index.d.ts

-39
This file was deleted.

plugins/postcss-custom-properties/package.json

+8-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,14 @@
1111
"bugs": "https://github.com/csstools/postcss-plugins/issues",
1212
"main": "dist/index.cjs",
1313
"module": "dist/index.mjs",
14-
"types": "index.d.ts",
14+
"types": "dist/index.d.ts",
15+
"exports": {
16+
".": {
17+
"import": "./dist/index.mjs",
18+
"require": "./dist/index.cjs",
19+
"default": "./dist/index.mjs"
20+
}
21+
},
1522
"files": [
1623
"CHANGELOG.md",
1724
"LICENSE.md",

plugins/postcss-custom-properties/src/index.js

-54
This file was deleted.

0 commit comments

Comments
 (0)