postcss-discard-unused 8.0.1 → 8.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE-MIT CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) Ben Briggs <beneb.info@gmail.com> (http://beneb.info)
1
+ Copyright (c) Ben Briggs <beneb.info@gmail.com> (https://beneb.info)
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person
4
4
  obtaining a copy of this software and associated documentation
package/README.md CHANGED
@@ -120,7 +120,7 @@ See [CONTRIBUTORS.md](https://github.com/cssnano/cssnano/blob/master/CONTRIBUTOR
120
120
 
121
121
  ## License
122
122
 
123
- MIT © [Ben Briggs](http://beneb.info)
123
+ MIT © [Ben Briggs](https://beneb.info)
124
124
 
125
125
 
126
126
  [postcss]: https://github.com/postcss/postcss
package/package.json CHANGED
@@ -1,9 +1,17 @@
1
1
  {
2
2
  "name": "postcss-discard-unused",
3
- "version": "8.0.1",
3
+ "version": "8.0.2",
4
4
  "description": "Discard unused counter styles, keyframes and fonts.",
5
- "main": "src/index.js",
6
- "types": "types/index.d.ts",
5
+ "exports": {
6
+ ".": {
7
+ "types": "./types/index.d.ts",
8
+ "default": "./src/index.js"
9
+ },
10
+ "./src": "./src/index.js",
11
+ "./src/index": "./src/index.js",
12
+ "./src/index.js": "./src/index.js",
13
+ "./package.json": "./package.json"
14
+ },
7
15
  "files": [
8
16
  "LICENSE-MIT",
9
17
  "src",
@@ -22,11 +30,14 @@
22
30
  "author": {
23
31
  "name": "Ben Briggs",
24
32
  "email": "beneb.info@gmail.com",
25
- "url": "http://beneb.info"
33
+ "url": "https://beneb.info"
34
+ },
35
+ "repository": {
36
+ "type": "git",
37
+ "url": "cssnano/cssnano"
26
38
  },
27
- "repository": "cssnano/cssnano",
28
39
  "dependencies": {
29
- "postcss-selector-parser": "^7.1.2"
40
+ "postcss-selector-parser": "^7.1.4"
30
41
  },
31
42
  "bugs": {
32
43
  "url": "https://github.com/cssnano/cssnano/issues"
@@ -35,9 +46,9 @@
35
46
  "node": "^22.11.0 || ^24.11.0 || >=26.0"
36
47
  },
37
48
  "devDependencies": {
38
- "postcss": "^8.5.15"
49
+ "postcss": "^8.5.25"
39
50
  },
40
51
  "peerDependencies": {
41
- "postcss": "^8.5.15"
52
+ "postcss": "^8.5.25"
42
53
  }
43
54
  }
package/src/index.js CHANGED
@@ -4,6 +4,12 @@ const selectorParser = require('postcss-selector-parser');
4
4
  const atrule = 'atrule';
5
5
  const decl = 'decl';
6
6
  const rule = 'rule';
7
+ const animationRegex = /animation/;
8
+ const listStyleRegex = /list-style|system/;
9
+ const fontRegex = /font(|-family)/;
10
+ const counterStyleRegex = /counter-style/;
11
+ const keyframesRegex = /keyframes/;
12
+
7
13
  /**
8
14
  * @param {{value: string}} arg
9
15
  * @param {(input: string) => string[]} comma
@@ -65,7 +71,7 @@ function hasFont(fontFamily, cache, comma) {
65
71
  return comma(fontFamily).some((font) => cache.some((c) => c.includes(font)));
66
72
  }
67
73
 
68
- /**
74
+ /**
69
75
  * fonts have slightly different logic
70
76
 
71
77
  * @param {{atRules: import('postcss').AtRule[], values: string[]}} cache
@@ -97,9 +103,22 @@ function filterFont({ atRules, values }, comma) {
97
103
  }
98
104
  }
99
105
 
106
+ /**
107
+ *
108
+ * @param {{atRules: import('postcss').AtRule[], rules: (string | true)[]}} namespaceCache
109
+ * @param {import('postcss').Rule} node
110
+ * @return {void}
111
+ */
112
+ function processAttributeSelector(namespaceCache, node) {
113
+ selectorParser((ast) => {
114
+ ast.walkAttributes(({ namespace: ns }) => {
115
+ namespaceCache.rules = namespaceCache.rules.concat(ns);
116
+ });
117
+ }).process(node.selector);
118
+ }
119
+
100
120
  /**@typedef {{fontFace?: boolean, counterStyle?: boolean, keyframes?: boolean, namespace?: boolean}} Options */
101
121
  /**
102
- * @type {import('postcss').PluginCreator<Options>}
103
122
  * @param {Options} opts
104
123
  * @return {import('postcss').Plugin}
105
124
  */
@@ -129,6 +148,10 @@ function pluginCreator(opts) {
129
148
  const fontCache = { atRules: [], values: [] };
130
149
 
131
150
  return {
151
+ /**
152
+ * @param {import('postcss').Root} css
153
+ * @param {import('postcss').Helpers} helpers
154
+ */
132
155
  OnceExit(css, { list }) {
133
156
  const { comma, space } = list;
134
157
  css.walk((node) => {
@@ -137,11 +160,7 @@ function pluginCreator(opts) {
137
160
  if (type === rule && namespace && node.selector.includes('|')) {
138
161
  if (node.selector.includes('[')) {
139
162
  // Attribute selector, so we should parse further.
140
- selectorParser((ast) => {
141
- ast.walkAttributes(({ namespace: ns }) => {
142
- namespaceCache.rules = namespaceCache.rules.concat(ns);
143
- });
144
- }).process(node.selector);
163
+ processAttributeSelector(namespaceCache, node);
145
164
  } else {
146
165
  // Use a simple split function for the namespace
147
166
  namespaceCache.rules = namespaceCache.rules.concat(
@@ -153,7 +172,7 @@ function pluginCreator(opts) {
153
172
 
154
173
  if (type === decl) {
155
174
  const { prop } = node;
156
- if (counterStyle && /list-style|system/.test(prop)) {
175
+ if (counterStyle && listStyleRegex.test(prop)) {
157
176
  counterStyleCache.values = counterStyleCache.values.concat(
158
177
  splitValues(node, comma, space)
159
178
  );
@@ -163,14 +182,14 @@ function pluginCreator(opts) {
163
182
  fontFace &&
164
183
  node.parent !== undefined &&
165
184
  node.parent.type === rule &&
166
- /font(|-family)/.test(prop)
185
+ fontRegex.test(prop)
167
186
  ) {
168
187
  fontCache.values = fontCache.values.concat(
169
188
  comma(node.value.toLowerCase())
170
189
  );
171
190
  }
172
191
 
173
- if (keyframes && /animation/.test(prop)) {
192
+ if (keyframes && animationRegex.test(prop)) {
174
193
  keyframesCache.values = keyframesCache.values.concat(
175
194
  splitValues(node, comma, space)
176
195
  );
@@ -181,7 +200,7 @@ function pluginCreator(opts) {
181
200
 
182
201
  if (type === atrule) {
183
202
  const { name } = node;
184
- if (counterStyle && /counter-style/.test(name)) {
203
+ if (counterStyle && counterStyleRegex.test(name)) {
185
204
  counterStyleCache.atRules.push(node);
186
205
  }
187
206
 
@@ -189,22 +208,28 @@ function pluginCreator(opts) {
189
208
  fontCache.atRules.push(node);
190
209
  }
191
210
 
192
- if (keyframes && /keyframes/.test(name)) {
211
+ if (keyframes && keyframesRegex.test(name)) {
193
212
  keyframesCache.atRules.push(node);
194
213
  }
195
214
 
196
215
  if (namespace && name === 'namespace') {
197
216
  namespaceCache.atRules.push(node);
198
217
  }
199
-
200
- return;
201
218
  }
202
219
  });
203
220
 
204
- counterStyle && filterAtRule(counterStyleCache);
205
- fontFace && filterFont(fontCache, comma);
206
- keyframes && filterAtRule(keyframesCache);
207
- namespace && filterNamespace(namespaceCache);
221
+ if (counterStyle) {
222
+ filterAtRule(counterStyleCache);
223
+ }
224
+ if (fontFace) {
225
+ filterFont(fontCache, comma);
226
+ }
227
+ if (keyframes) {
228
+ filterAtRule(keyframesCache);
229
+ }
230
+ if (namespace) {
231
+ filterNamespace(namespaceCache);
232
+ }
208
233
  },
209
234
  };
210
235
  },
@@ -212,4 +237,6 @@ function pluginCreator(opts) {
212
237
  }
213
238
 
214
239
  pluginCreator.postcss = true;
215
- module.exports = pluginCreator;
240
+ module.exports = /** @type {import('postcss').PluginCreator<Options>}*/ (
241
+ pluginCreator
242
+ );
package/types/index.d.ts CHANGED
@@ -1,16 +1,6 @@
1
- export = pluginCreator;
2
- /**@typedef {{fontFace?: boolean, counterStyle?: boolean, keyframes?: boolean, namespace?: boolean}} Options */
3
- /**
4
- * @type {import('postcss').PluginCreator<Options>}
5
- * @param {Options} opts
6
- * @return {import('postcss').Plugin}
7
- */
8
- declare function pluginCreator(opts: Options): import("postcss").Plugin;
9
- declare namespace pluginCreator {
10
- export { postcss, Options };
11
- }
12
- declare var postcss: true;
13
- type Options = {
1
+ declare const _exports: import("postcss").PluginCreator<Options>;
2
+ export = _exports;
3
+ export type Options = {
14
4
  fontFace?: boolean;
15
5
  counterStyle?: boolean;
16
6
  keyframes?: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":";AAmGA,+GAA+G;AAC/G;;;;GAIG;AACH,qCAHW,OAAO,GACN,OAAO,SAAS,EAAE,MAAM,CA4GnC;;;;;eAhHY;IAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;IAAC,YAAY,CAAC,EAAE,OAAO,CAAC;IAAC,SAAS,CAAC,EAAE,OAAO,CAAC;IAAC,SAAS,CAAC,EAAE,OAAO,CAAA;CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":";;AAuHG,YAAkG,OAAO,GAA/F;IAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;IAAC,YAAY,CAAC,EAAE,OAAO,CAAC;IAAC,SAAS,CAAC,EAAE,OAAO,CAAC;IAAC,SAAS,CAAC,EAAE,OAAO,CAAA;CAAC,CAAS"}