@fullhuman/postcss-purgecss 6.0.0-alpha.0 → 7.0.1-alpha.0

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.
@@ -82,6 +82,7 @@ export declare interface Extractors {
82
82
  */
83
83
  declare const purgeCSSPlugin: postcss.PluginCreator<UserDefinedOptions>;
84
84
  export default purgeCSSPlugin;
85
+ export { purgeCSSPlugin }
85
86
 
86
87
  /**
87
88
  * Options used by PurgeCSS to remove unused CSS
@@ -1 +1,89 @@
1
- import*as e from"path";import{PurgeCSS as s,defaultOptions as t,standardizeSafelist as o,mergeExtractorSelectors as r}from"purgecss";const n=function(n){if(void 0===n)throw new Error("PurgeCSS plugin does not have the correct options");return{postcssPlugin:"postcss-purgecss",OnceExit:(c,i)=>async function(n,c,{result:i}){const a=new s;let l;try{const s=e.resolve(process.cwd(),"purgecss.config.js");l=await import(s)}catch{}const p={...t,...l,...n,safelist:o((null==n?void 0:n.safelist)||(null==l?void 0:l.safelist))};n&&"function"==typeof n.contentFunction&&(p.content=n.contentFunction(c.source&&c.source.input.file||"")),a.options=p,p.variables&&(a.variablesStructure.safelist=p.safelist.variables||[]);const{content:u,extractors:f}=p,m=u.filter((e=>"string"==typeof e)),g=u.filter((e=>"object"==typeof e)),v=await a.extractSelectorsFromFiles(m,f),d=await a.extractSelectorsFromString(g,f),S=r(v,d);a.walkThroughCSS(c,S),a.options.fontFace&&a.removeUnusedFontFaces(),a.options.keyframes&&a.removeUnusedKeyframes(),a.options.variables&&a.removeUnusedCSSVariables(),a.options.rejected&&a.selectorsRemoved.size>0&&(i.messages.push({type:"purgecss",plugin:"postcss-purgecss",text:`purging ${a.selectorsRemoved.size} selectors:\n ${Array.from(a.selectorsRemoved).map((e=>e.trim())).join("\n ")}`}),a.selectorsRemoved.clear())}(n,c,i)}};n.postcss=!0;export{n as default};
1
+ import * as path from 'path';
2
+ import { PurgeCSS, defaultOptions, standardizeSafelist, mergeExtractorSelectors } from 'purgecss';
3
+
4
+ /**
5
+ * PostCSS Plugin for PurgeCSS
6
+ *
7
+ * Most bundlers and frameworks to build websites are using PostCSS.
8
+ * The easiest way to configure PurgeCSS is with its PostCSS plugin.
9
+ *
10
+ * @packageDocumentation
11
+ */
12
+ const PLUGIN_NAME = "postcss-purgecss";
13
+ /**
14
+ * Execute PurgeCSS process on the postCSS root node
15
+ *
16
+ * @param opts - PurgeCSS options
17
+ * @param root - root node of postCSS
18
+ * @param helpers - postCSS helpers
19
+ */
20
+ async function purgeCSS(opts, root, { result }) {
21
+ const purgeCSS = new PurgeCSS();
22
+ let configFileOptions;
23
+ try {
24
+ const t = path.resolve(process.cwd(), "purgecss.config.js");
25
+ configFileOptions = await import(t);
26
+ }
27
+ catch {
28
+ // no config file present
29
+ }
30
+ const options = {
31
+ ...defaultOptions,
32
+ ...configFileOptions,
33
+ ...opts,
34
+ safelist: standardizeSafelist((opts === null || opts === void 0 ? void 0 : opts.safelist) || (configFileOptions === null || configFileOptions === void 0 ? void 0 : configFileOptions.safelist)),
35
+ };
36
+ if (opts && typeof opts.contentFunction === "function") {
37
+ options.content = opts.contentFunction((root.source && root.source.input.file) || "");
38
+ }
39
+ purgeCSS.options = options;
40
+ if (options.variables) {
41
+ purgeCSS.variablesStructure.safelist = options.safelist.variables || [];
42
+ }
43
+ const { content, extractors } = options;
44
+ const fileFormatContents = content.filter((o) => typeof o === "string");
45
+ const rawFormatContents = content.filter((o) => typeof o === "object");
46
+ const cssFileSelectors = await purgeCSS.extractSelectorsFromFiles(fileFormatContents, extractors);
47
+ const cssRawSelectors = await purgeCSS.extractSelectorsFromString(rawFormatContents, extractors);
48
+ const selectors = mergeExtractorSelectors(cssFileSelectors, cssRawSelectors);
49
+ //purge unused selectors
50
+ purgeCSS.walkThroughCSS(root, selectors);
51
+ if (purgeCSS.options.fontFace)
52
+ purgeCSS.removeUnusedFontFaces();
53
+ if (purgeCSS.options.keyframes)
54
+ purgeCSS.removeUnusedKeyframes();
55
+ if (purgeCSS.options.variables)
56
+ purgeCSS.removeUnusedCSSVariables();
57
+ if (purgeCSS.options.rejected && purgeCSS.selectorsRemoved.size > 0) {
58
+ result.messages.push({
59
+ type: "purgecss",
60
+ plugin: "postcss-purgecss",
61
+ text: `purging ${purgeCSS.selectorsRemoved.size} selectors:
62
+ ${Array.from(purgeCSS.selectorsRemoved)
63
+ .map((selector) => selector.trim())
64
+ .join("\n ")}`,
65
+ });
66
+ purgeCSS.selectorsRemoved.clear();
67
+ }
68
+ }
69
+ /**
70
+ * PostCSS Plugin for PurgeCSS
71
+ *
72
+ * @param opts - PurgeCSS Options
73
+ * @returns the postCSS plugin
74
+ *
75
+ * @public
76
+ */
77
+ const purgeCSSPlugin = function (opts) {
78
+ if (typeof opts === "undefined")
79
+ throw new Error("PurgeCSS plugin does not have the correct options");
80
+ return {
81
+ postcssPlugin: PLUGIN_NAME,
82
+ OnceExit(root, helpers) {
83
+ return purgeCSS(opts, root, helpers);
84
+ },
85
+ };
86
+ };
87
+ purgeCSSPlugin.postcss = true;
88
+
89
+ export { purgeCSSPlugin as default, purgeCSSPlugin };
@@ -1 +1,113 @@
1
- "use strict";var e=require("path"),t=require("purgecss");function r(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var s=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,s.get?s:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}var s=r(e);const o=function(e){if(void 0===e)throw new Error("PurgeCSS plugin does not have the correct options");return{postcssPlugin:"postcss-purgecss",OnceExit:(o,n)=>async function(e,o,{result:n}){const c=new t.PurgeCSS;let i;try{const e=s.resolve(process.cwd(),"purgecss.config.js");i=await function(e){return Promise.resolve().then((function(){return r(require(e))}))}(e)}catch{}const a={...t.defaultOptions,...i,...e,safelist:t.standardizeSafelist((null==e?void 0:e.safelist)||(null==i?void 0:i.safelist))};e&&"function"==typeof e.contentFunction&&(a.content=e.contentFunction(o.source&&o.source.input.file||"")),c.options=a,a.variables&&(c.variablesStructure.safelist=a.safelist.variables||[]);const{content:u,extractors:l}=a,f=u.filter((e=>"string"==typeof e)),p=u.filter((e=>"object"==typeof e)),d=await c.extractSelectorsFromFiles(f,l),g=await c.extractSelectorsFromString(p,l),v=t.mergeExtractorSelectors(d,g);c.walkThroughCSS(o,v),c.options.fontFace&&c.removeUnusedFontFaces(),c.options.keyframes&&c.removeUnusedKeyframes(),c.options.variables&&c.removeUnusedCSSVariables(),c.options.rejected&&c.selectorsRemoved.size>0&&(n.messages.push({type:"purgecss",plugin:"postcss-purgecss",text:`purging ${c.selectorsRemoved.size} selectors:\n ${Array.from(c.selectorsRemoved).map((e=>e.trim())).join("\n ")}`}),c.selectorsRemoved.clear())}(e,o,n)}};o.postcss=!0,module.exports=o;
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var path = require('path');
6
+ var purgecss = require('purgecss');
7
+
8
+ function _interopNamespaceDefault(e) {
9
+ var n = Object.create(null);
10
+ if (e) {
11
+ Object.keys(e).forEach(function (k) {
12
+ if (k !== 'default') {
13
+ var d = Object.getOwnPropertyDescriptor(e, k);
14
+ Object.defineProperty(n, k, d.get ? d : {
15
+ enumerable: true,
16
+ get: function () { return e[k]; }
17
+ });
18
+ }
19
+ });
20
+ }
21
+ n.default = e;
22
+ return Object.freeze(n);
23
+ }
24
+
25
+ var path__namespace = /*#__PURE__*/_interopNamespaceDefault(path);
26
+
27
+ /**
28
+ * PostCSS Plugin for PurgeCSS
29
+ *
30
+ * Most bundlers and frameworks to build websites are using PostCSS.
31
+ * The easiest way to configure PurgeCSS is with its PostCSS plugin.
32
+ *
33
+ * @packageDocumentation
34
+ */
35
+ const PLUGIN_NAME = "postcss-purgecss";
36
+ /**
37
+ * Execute PurgeCSS process on the postCSS root node
38
+ *
39
+ * @param opts - PurgeCSS options
40
+ * @param root - root node of postCSS
41
+ * @param helpers - postCSS helpers
42
+ */
43
+ async function purgeCSS(opts, root, { result }) {
44
+ const purgeCSS = new purgecss.PurgeCSS();
45
+ let configFileOptions;
46
+ try {
47
+ const t = path__namespace.resolve(process.cwd(), "purgecss.config.js");
48
+ configFileOptions = await import(t);
49
+ }
50
+ catch {
51
+ // no config file present
52
+ }
53
+ const options = {
54
+ ...purgecss.defaultOptions,
55
+ ...configFileOptions,
56
+ ...opts,
57
+ safelist: purgecss.standardizeSafelist((opts === null || opts === void 0 ? void 0 : opts.safelist) || (configFileOptions === null || configFileOptions === void 0 ? void 0 : configFileOptions.safelist)),
58
+ };
59
+ if (opts && typeof opts.contentFunction === "function") {
60
+ options.content = opts.contentFunction((root.source && root.source.input.file) || "");
61
+ }
62
+ purgeCSS.options = options;
63
+ if (options.variables) {
64
+ purgeCSS.variablesStructure.safelist = options.safelist.variables || [];
65
+ }
66
+ const { content, extractors } = options;
67
+ const fileFormatContents = content.filter((o) => typeof o === "string");
68
+ const rawFormatContents = content.filter((o) => typeof o === "object");
69
+ const cssFileSelectors = await purgeCSS.extractSelectorsFromFiles(fileFormatContents, extractors);
70
+ const cssRawSelectors = await purgeCSS.extractSelectorsFromString(rawFormatContents, extractors);
71
+ const selectors = purgecss.mergeExtractorSelectors(cssFileSelectors, cssRawSelectors);
72
+ //purge unused selectors
73
+ purgeCSS.walkThroughCSS(root, selectors);
74
+ if (purgeCSS.options.fontFace)
75
+ purgeCSS.removeUnusedFontFaces();
76
+ if (purgeCSS.options.keyframes)
77
+ purgeCSS.removeUnusedKeyframes();
78
+ if (purgeCSS.options.variables)
79
+ purgeCSS.removeUnusedCSSVariables();
80
+ if (purgeCSS.options.rejected && purgeCSS.selectorsRemoved.size > 0) {
81
+ result.messages.push({
82
+ type: "purgecss",
83
+ plugin: "postcss-purgecss",
84
+ text: `purging ${purgeCSS.selectorsRemoved.size} selectors:
85
+ ${Array.from(purgeCSS.selectorsRemoved)
86
+ .map((selector) => selector.trim())
87
+ .join("\n ")}`,
88
+ });
89
+ purgeCSS.selectorsRemoved.clear();
90
+ }
91
+ }
92
+ /**
93
+ * PostCSS Plugin for PurgeCSS
94
+ *
95
+ * @param opts - PurgeCSS Options
96
+ * @returns the postCSS plugin
97
+ *
98
+ * @public
99
+ */
100
+ const purgeCSSPlugin = function (opts) {
101
+ if (typeof opts === "undefined")
102
+ throw new Error("PurgeCSS plugin does not have the correct options");
103
+ return {
104
+ postcssPlugin: PLUGIN_NAME,
105
+ OnceExit(root, helpers) {
106
+ return purgeCSS(opts, root, helpers);
107
+ },
108
+ };
109
+ };
110
+ purgeCSSPlugin.postcss = true;
111
+
112
+ exports.default = purgeCSSPlugin;
113
+ exports.purgeCSSPlugin = purgeCSSPlugin;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fullhuman/postcss-purgecss",
3
- "version": "6.0.0-alpha.0",
3
+ "version": "7.0.1-alpha.0",
4
4
  "description": "PostCSS plugin for PurgeCSS",
5
5
  "author": "FoundrySH <no-reply@foundry.sh>",
6
6
  "homepage": "https://purgecss.com",
@@ -27,10 +27,10 @@
27
27
  "url": "https://github.com/FullHuman/purgecss/issues"
28
28
  },
29
29
  "dependencies": {
30
- "purgecss": "^6.0.0-alpha.0"
30
+ "purgecss": "^7.0.1-alpha.0"
31
31
  },
32
32
  "devDependencies": {
33
- "postcss": "^8.4.4"
33
+ "postcss": "^8.4.47"
34
34
  },
35
35
  "peerDependencies": {
36
36
  "postcss": "^8.0.0"
@@ -39,5 +39,5 @@
39
39
  "access": "public",
40
40
  "registry": "https://registry.npmjs.org/"
41
41
  },
42
- "gitHead": "152ccba46e781902f302b7adca1788a6909e9569"
42
+ "gitHead": "5a51b05a191ba48b5e55440ac2e66822f9e182fe"
43
43
  }