New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

gulp-purgecss

Package Overview
Dependencies
Maintainers
0
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gulp-purgecss - npm Package Compare versions

Comparing version 6.0.0 to 7.0.1-alpha.0

LICENSE

2

lib/gulp-purgecss.d.ts

@@ -1,3 +0,1 @@

/// <reference types="node" />
import * as internal from 'stream';

@@ -4,0 +2,0 @@ import * as postcss from 'postcss';

@@ -1,1 +0,99 @@

import*as e from"glob";import r from"plugin-error";import{PurgeCSS as t}from"purgecss";import o from"through2";import n from"vinyl-sourcemaps-apply";const s="gulp-purgecss";function c(c){return o.obj((async function(i,a,u){if(i.isNull())return u(null,i);if(i.isBuffer())try{const r={...c,content:(p=c.content,f=c.skippedContentGlobs,p.reduce(((r,t)=>[...r,...e.sync(t,{ignore:f})]),[])),css:[{raw:i.contents.toString()}],stdin:!0,sourceMap:!!i.sourceMap},o=(await(new t).purge(r))[0],s=r.rejected&&o.rejected?o.rejected.join(" {}\n")+" {}":o.css;i.contents=Buffer.from(s,"utf-8"),i.sourceMap&&n(i,o.sourceMap),u(null,i)}catch(e){e instanceof Error&&this.emit("error",new r(s,e.message))}var p,f;if(i.isStream()){let e="";i.contents.on("data",(r=>{e+=r.toString()})).on("end",(async()=>{try{const r={...c,css:[{raw:e}],sourceMap:!!i.sourceMap},s=(await(new t).purge(r))[0],a=r.rejected&&s.rejected?s.rejected.join(" {}\n")+" {}":s.css,p=o();p.write(Buffer.from(a,"utf-8")),i.contents=i.contents.pipe(p),i.sourceMap&&n(i,s.sourceMap),u(null,i)}catch(e){e instanceof Error&&this.emit("error",new r(s,e.message))}}))}}))}export{c as default};
import * as glob from 'glob';
import PluginError from 'plugin-error';
import { PurgeCSS } from 'purgecss';
import through from 'through2';
import applySourceMap from 'vinyl-sourcemaps-apply';
const PLUGIN_NAME = "gulp-purgecss";
function getFiles(contentArray, ignore) {
return contentArray.reduce((acc, content) => {
return [...acc, ...glob.sync(content, { ignore })];
}, []);
}
/**
*
* @param options - options
* @returns
*
* @public
*/
function gulpPurgeCSS(options) {
return through.obj(async function (file, _encoding, callback) {
// empty
if (file.isNull())
return callback(null, file);
// buffer
if (file.isBuffer()) {
try {
const optionsGulp = {
...options,
content: getFiles(options.content, options.skippedContentGlobs),
css: [
{
raw: file.contents.toString(),
},
],
stdin: true,
sourceMap: !!file.sourceMap,
};
const purgedCSSResults = await new PurgeCSS().purge(optionsGulp);
const purge = purgedCSSResults[0];
const result = optionsGulp.rejected && purge.rejected
? purge.rejected.join(" {}\n") + " {}"
: purge.css;
file.contents = Buffer.from(result, "utf-8");
// apply source map to the chain
if (file.sourceMap) {
applySourceMap(file, purge.sourceMap);
}
callback(null, file);
}
catch (e) {
if (e instanceof Error) {
this.emit("error", new PluginError(PLUGIN_NAME, e.message));
}
}
}
// stream
if (file.isStream()) {
let css = "";
file.contents
.on("data", (buffer) => {
css += buffer.toString();
})
.on("end", async () => {
try {
const optionsGulp = {
...options,
css: [
{
raw: css,
},
],
sourceMap: !!file.sourceMap,
};
const purgedCSSResults = await new PurgeCSS().purge(optionsGulp);
const purge = purgedCSSResults[0];
const result = optionsGulp.rejected && purge.rejected
? purge.rejected.join(" {}\n") + " {}"
: purge.css;
const streamResult = through();
streamResult.write(Buffer.from(result, "utf-8"));
file.contents = file.contents.pipe(streamResult);
// apply source map to the chain
if (file.sourceMap) {
applySourceMap(file, purge.sourceMap);
}
callback(null, file);
}
catch (e) {
if (e instanceof Error) {
this.emit("error", new PluginError(PLUGIN_NAME, e.message));
}
}
});
}
});
}
export { gulpPurgeCSS as default };

@@ -1,1 +0,120 @@

"use strict";var e=require("glob"),r=require("plugin-error"),t=require("purgecss"),n=require("through2"),u=require("vinyl-sourcemaps-apply");function c(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function o(e){if(e&&e.__esModule)return e;var r=Object.create(null);return e&&Object.keys(e).forEach((function(t){if("default"!==t){var n=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,n.get?n:{enumerable:!0,get:function(){return e[t]}})}})),r.default=e,Object.freeze(r)}var s=o(e),a=c(r),i=c(n),f=c(u);const l="gulp-purgecss";module.exports=function(e){return i.default.obj((async function(r,n,u){if(r.isNull())return u(null,r);if(r.isBuffer())try{const n={...e,content:(c=e.content,o=e.skippedContentGlobs,c.reduce(((e,r)=>[...e,...s.sync(r,{ignore:o})]),[])),css:[{raw:r.contents.toString()}],stdin:!0,sourceMap:!!r.sourceMap},a=(await(new t.PurgeCSS).purge(n))[0],i=n.rejected&&a.rejected?a.rejected.join(" {}\n")+" {}":a.css;r.contents=Buffer.from(i,"utf-8"),r.sourceMap&&f.default(r,a.sourceMap),u(null,r)}catch(e){e instanceof Error&&this.emit("error",new a.default(l,e.message))}var c,o;if(r.isStream()){let n="";r.contents.on("data",(e=>{n+=e.toString()})).on("end",(async()=>{try{const c={...e,css:[{raw:n}],sourceMap:!!r.sourceMap},o=(await(new t.PurgeCSS).purge(c))[0],s=c.rejected&&o.rejected?o.rejected.join(" {}\n")+" {}":o.css,a=i.default();a.write(Buffer.from(s,"utf-8")),r.contents=r.contents.pipe(a),r.sourceMap&&f.default(r,o.sourceMap),u(null,r)}catch(e){e instanceof Error&&this.emit("error",new a.default(l,e.message))}}))}}))};
'use strict';
var glob = require('glob');
var PluginError = require('plugin-error');
var purgecss = require('purgecss');
var through = require('through2');
var applySourceMap = require('vinyl-sourcemaps-apply');
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 glob__namespace = /*#__PURE__*/_interopNamespaceDefault(glob);
const PLUGIN_NAME = "gulp-purgecss";
function getFiles(contentArray, ignore) {
return contentArray.reduce((acc, content) => {
return [...acc, ...glob__namespace.sync(content, { ignore })];
}, []);
}
/**
*
* @param options - options
* @returns
*
* @public
*/
function gulpPurgeCSS(options) {
return through.obj(async function (file, _encoding, callback) {
// empty
if (file.isNull())
return callback(null, file);
// buffer
if (file.isBuffer()) {
try {
const optionsGulp = {
...options,
content: getFiles(options.content, options.skippedContentGlobs),
css: [
{
raw: file.contents.toString(),
},
],
stdin: true,
sourceMap: !!file.sourceMap,
};
const purgedCSSResults = await new purgecss.PurgeCSS().purge(optionsGulp);
const purge = purgedCSSResults[0];
const result = optionsGulp.rejected && purge.rejected
? purge.rejected.join(" {}\n") + " {}"
: purge.css;
file.contents = Buffer.from(result, "utf-8");
// apply source map to the chain
if (file.sourceMap) {
applySourceMap(file, purge.sourceMap);
}
callback(null, file);
}
catch (e) {
if (e instanceof Error) {
this.emit("error", new PluginError(PLUGIN_NAME, e.message));
}
}
}
// stream
if (file.isStream()) {
let css = "";
file.contents
.on("data", (buffer) => {
css += buffer.toString();
})
.on("end", async () => {
try {
const optionsGulp = {
...options,
css: [
{
raw: css,
},
],
sourceMap: !!file.sourceMap,
};
const purgedCSSResults = await new purgecss.PurgeCSS().purge(optionsGulp);
const purge = purgedCSSResults[0];
const result = optionsGulp.rejected && purge.rejected
? purge.rejected.join(" {}\n") + " {}"
: purge.css;
const streamResult = through();
streamResult.write(Buffer.from(result, "utf-8"));
file.contents = file.contents.pipe(streamResult);
// apply source map to the chain
if (file.sourceMap) {
applySourceMap(file, purge.sourceMap);
}
callback(null, file);
}
catch (e) {
if (e instanceof Error) {
this.emit("error", new PluginError(PLUGIN_NAME, e.message));
}
}
});
}
});
}
module.exports = gulpPurgeCSS;
{
"name": "gulp-purgecss",
"version": "6.0.0",
"version": "7.0.1-alpha.0",
"description": "Gulp plugin for purgecss",

@@ -39,5 +39,5 @@ "author": "Ffloriel",

"dependencies": {
"glob": "^10.3.10",
"glob": "^11.0.0",
"plugin-error": "^2.0.0",
"purgecss": "^6.0.0",
"purgecss": "^7.0.1-alpha.0",
"through2": "^4.0.1",

@@ -60,3 +60,4 @@ "vinyl-sourcemaps-apply": "^0.2.1"

"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