Skip to content

Commit

Permalink
fix(postcss-reduce-initial): ensure options are always read (#1482)
Browse files Browse the repository at this point in the history
Fix #1436

Ensure options are read also when the plugin is configured
in cssnano instead as a standalone PostCSS plugin.
  • Loading branch information
ludofischer committed Mar 23, 2023
1 parent 99d1e6a commit 91a7cdb
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
14 changes: 14 additions & 0 deletions packages/cssnano/test/presets.js
Expand Up @@ -106,6 +106,20 @@ test('should be able to exclude plugins (exclude syntax)', () => {
});
});

test('should be able to exclude pointer-events plugin', () => {
return cssnano({
preset: [
'default',
{
reduceInitial: { ignore: ['pointer-events'] },
},
],
})
.process('.selector { pointer-events: initial; }', { from: undefined })
.then((result) => {
assert.is(result.css, '.selector{pointer-events:initial}');
});
});
test('should error on a bad preset', async () => {
try {
await postcss([cssnano({ preset: 'avanced' })])
Expand Down
8 changes: 5 additions & 3 deletions packages/postcss-reduce-initial/src/index.js
Expand Up @@ -8,12 +8,14 @@ const initial = 'initial';

// In most of the browser including chrome the initial for `writing-mode` is not `horizontal-tb`. Ref https://github.com/cssnano/cssnano/pull/905
const defaultIgnoreProps = ['writing-mode', 'transform-box'];
/** @typedef {{ignore?: string[]}} Options */

/**
* @type {import('postcss').PluginCreator<void>}
* @type {import('postcss').PluginCreator<Options>}
* @param {Options} options
* @return {import('postcss').Plugin}
*/
function pluginCreator() {
function pluginCreator(options = {}) {
return {
postcssPlugin: 'postcss-reduce-initial',
/** @param {import('postcss').Result & {opts: browserslist.Options & {ignore?: string[]}}} result */
Expand All @@ -31,7 +33,7 @@ function pluginCreator() {
css.walkDecls((decl) => {
const lowerCasedProp = decl.prop.toLowerCase();
const ignoreProp = new Set(
defaultIgnoreProps.concat(resultOpts.ignore || [])
defaultIgnoreProps.concat(options.ignore || [])
);

if (ignoreProp.has(lowerCasedProp)) {
Expand Down
12 changes: 9 additions & 3 deletions packages/postcss-reduce-initial/types/index.d.ts
@@ -1,9 +1,15 @@
export = pluginCreator;
/** @typedef {{ignore?: string[]}} Options */
/**
* @type {import('postcss').PluginCreator<void>}
* @type {import('postcss').PluginCreator<Options>}
* @param {Options} options
* @return {import('postcss').Plugin}
*/
declare function pluginCreator(): import('postcss').Plugin;
declare function pluginCreator(options?: Options): import('postcss').Plugin;
declare namespace pluginCreator {
const postcss: true;
export { postcss, Options };
}
type Options = {
ignore?: string[];
};
declare var postcss: true;

0 comments on commit 91a7cdb

Please sign in to comment.