Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@fullhuman/postcss-purgecss

Package Overview
Dependencies
Maintainers
2
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@fullhuman/postcss-purgecss - npm Package Compare versions

Comparing version 6.0.0 to 7.0.1-alpha.0

LICENSE

1

lib/postcss-purgecss.d.ts

@@ -85,2 +85,3 @@ /**

export default purgeCSSPlugin;
export { purgeCSSPlugin }

@@ -87,0 +88,0 @@ /**

@@ -1,1 +0,89 @@

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};
import * as path from 'path';
import { PurgeCSS, defaultOptions, standardizeSafelist, mergeExtractorSelectors } from 'purgecss';
/**
* PostCSS Plugin for PurgeCSS
*
* Most bundlers and frameworks to build websites are using PostCSS.
* The easiest way to configure PurgeCSS is with its PostCSS plugin.
*
* @packageDocumentation
*/
const PLUGIN_NAME = "postcss-purgecss";
/**
* Execute PurgeCSS process on the postCSS root node
*
* @param opts - PurgeCSS options
* @param root - root node of postCSS
* @param helpers - postCSS helpers
*/
async function purgeCSS(opts, root, { result }) {
const purgeCSS = new PurgeCSS();
let configFileOptions;
try {
const t = path.resolve(process.cwd(), "purgecss.config.js");
configFileOptions = await import(t);
}
catch {
// no config file present
}
const options = {
...defaultOptions,
...configFileOptions,
...opts,
safelist: standardizeSafelist((opts === null || opts === void 0 ? void 0 : opts.safelist) || (configFileOptions === null || configFileOptions === void 0 ? void 0 : configFileOptions.safelist)),
};
if (opts && typeof opts.contentFunction === "function") {
options.content = opts.contentFunction((root.source && root.source.input.file) || "");
}
purgeCSS.options = options;
if (options.variables) {
purgeCSS.variablesStructure.safelist = options.safelist.variables || [];
}
const { content, extractors } = options;
const fileFormatContents = content.filter((o) => typeof o === "string");
const rawFormatContents = content.filter((o) => typeof o === "object");
const cssFileSelectors = await purgeCSS.extractSelectorsFromFiles(fileFormatContents, extractors);
const cssRawSelectors = await purgeCSS.extractSelectorsFromString(rawFormatContents, extractors);
const selectors = mergeExtractorSelectors(cssFileSelectors, cssRawSelectors);
//purge unused selectors
purgeCSS.walkThroughCSS(root, selectors);
if (purgeCSS.options.fontFace)
purgeCSS.removeUnusedFontFaces();
if (purgeCSS.options.keyframes)
purgeCSS.removeUnusedKeyframes();
if (purgeCSS.options.variables)
purgeCSS.removeUnusedCSSVariables();
if (purgeCSS.options.rejected && purgeCSS.selectorsRemoved.size > 0) {
result.messages.push({
type: "purgecss",
plugin: "postcss-purgecss",
text: `purging ${purgeCSS.selectorsRemoved.size} selectors:
${Array.from(purgeCSS.selectorsRemoved)
.map((selector) => selector.trim())
.join("\n ")}`,
});
purgeCSS.selectorsRemoved.clear();
}
}
/**
* PostCSS Plugin for PurgeCSS
*
* @param opts - PurgeCSS Options
* @returns the postCSS plugin
*
* @public
*/
const purgeCSSPlugin = function (opts) {
if (typeof opts === "undefined")
throw new Error("PurgeCSS plugin does not have the correct options");
return {
postcssPlugin: PLUGIN_NAME,
OnceExit(root, helpers) {
return purgeCSS(opts, root, helpers);
},
};
};
purgeCSSPlugin.postcss = true;
export { purgeCSSPlugin as default, purgeCSSPlugin };

@@ -1,1 +0,113 @@

"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;
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var path = require('path');
var purgecss = require('purgecss');
function _interopNamespaceDefault(e) {
var n = Object.create(null);
if (e) {
Object.keys(e).forEach(function (k) {
if (k !== 'default') {
var d = Object.getOwnPropertyDescriptor(e, k);
Object.defineProperty(n, k, d.get ? d : {
enumerable: true,
get: function () { return e[k]; }
});
}
});
}
n.default = e;
return Object.freeze(n);
}
var path__namespace = /*#__PURE__*/_interopNamespaceDefault(path);
/**
* PostCSS Plugin for PurgeCSS
*
* Most bundlers and frameworks to build websites are using PostCSS.
* The easiest way to configure PurgeCSS is with its PostCSS plugin.
*
* @packageDocumentation
*/
const PLUGIN_NAME = "postcss-purgecss";
/**
* Execute PurgeCSS process on the postCSS root node
*
* @param opts - PurgeCSS options
* @param root - root node of postCSS
* @param helpers - postCSS helpers
*/
async function purgeCSS(opts, root, { result }) {
const purgeCSS = new purgecss.PurgeCSS();
let configFileOptions;
try {
const t = path__namespace.resolve(process.cwd(), "purgecss.config.js");
configFileOptions = await import(t);
}
catch {
// no config file present
}
const options = {
...purgecss.defaultOptions,
...configFileOptions,
...opts,
safelist: purgecss.standardizeSafelist((opts === null || opts === void 0 ? void 0 : opts.safelist) || (configFileOptions === null || configFileOptions === void 0 ? void 0 : configFileOptions.safelist)),
};
if (opts && typeof opts.contentFunction === "function") {
options.content = opts.contentFunction((root.source && root.source.input.file) || "");
}
purgeCSS.options = options;
if (options.variables) {
purgeCSS.variablesStructure.safelist = options.safelist.variables || [];
}
const { content, extractors } = options;
const fileFormatContents = content.filter((o) => typeof o === "string");
const rawFormatContents = content.filter((o) => typeof o === "object");
const cssFileSelectors = await purgeCSS.extractSelectorsFromFiles(fileFormatContents, extractors);
const cssRawSelectors = await purgeCSS.extractSelectorsFromString(rawFormatContents, extractors);
const selectors = purgecss.mergeExtractorSelectors(cssFileSelectors, cssRawSelectors);
//purge unused selectors
purgeCSS.walkThroughCSS(root, selectors);
if (purgeCSS.options.fontFace)
purgeCSS.removeUnusedFontFaces();
if (purgeCSS.options.keyframes)
purgeCSS.removeUnusedKeyframes();
if (purgeCSS.options.variables)
purgeCSS.removeUnusedCSSVariables();
if (purgeCSS.options.rejected && purgeCSS.selectorsRemoved.size > 0) {
result.messages.push({
type: "purgecss",
plugin: "postcss-purgecss",
text: `purging ${purgeCSS.selectorsRemoved.size} selectors:
${Array.from(purgeCSS.selectorsRemoved)
.map((selector) => selector.trim())
.join("\n ")}`,
});
purgeCSS.selectorsRemoved.clear();
}
}
/**
* PostCSS Plugin for PurgeCSS
*
* @param opts - PurgeCSS Options
* @returns the postCSS plugin
*
* @public
*/
const purgeCSSPlugin = function (opts) {
if (typeof opts === "undefined")
throw new Error("PurgeCSS plugin does not have the correct options");
return {
postcssPlugin: PLUGIN_NAME,
OnceExit(root, helpers) {
return purgeCSS(opts, root, helpers);
},
};
};
purgeCSSPlugin.postcss = true;
exports.default = purgeCSSPlugin;
exports.purgeCSSPlugin = purgeCSSPlugin;

9

package.json
{
"name": "@fullhuman/postcss-purgecss",
"version": "6.0.0",
"version": "7.0.1-alpha.0",
"description": "PostCSS plugin for PurgeCSS",

@@ -30,6 +30,6 @@ "author": "FoundrySH <no-reply@foundry.sh>",

"dependencies": {
"purgecss": "^6.0.0"
"purgecss": "^7.0.1-alpha.0"
},
"devDependencies": {
"postcss": "^8.4.4"
"postcss": "^8.4.47"
},

@@ -42,3 +42,4 @@ "peerDependencies": {

"registry": "https://registry.npmjs.org/"
}
},
"gitHead": "5a51b05a191ba48b5e55440ac2e66822f9e182fe"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc