gulp-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.
@@ -1,5 +1,3 @@
1
- /// <reference types="node" />
2
-
3
1
  import * as internal from 'stream';
4
2
  import * as postcss from 'postcss';
5
3
 
@@ -1 +1,99 @@
1
- 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";function s(s){return o.obj((async function(c,u,i){if(c.isNull())return i(null,c);if(c.isBuffer())try{const r={...s,content:(a=s.content,p=s.skippedContentGlobs,a.reduce(((r,t)=>[...r,...e.sync(t,{ignore:p})]),[])),css:[{raw:c.contents.toString()}],stdin:!0,sourceMap:!!c.sourceMap},o=(await(new t).purge(r))[0],u=r.rejected&&o.rejected?o.rejected.join(" {}\n")+" {}":o.css;c.contents=Buffer.from(u,"utf-8"),c.sourceMap&&n(c,o.sourceMap),i(null,c)}catch(e){e instanceof Error&&this.emit("error",new r("gulp-purgecss",e.message))}var a,p;if(c.isStream()){let e="";c.contents.on("data",(r=>{e+=r.toString()})).on("end",(async()=>{try{const r={...s,css:[{raw:e}],sourceMap:!!c.sourceMap},u=(await(new t).purge(r))[0],a=r.rejected&&u.rejected?u.rejected.join(" {}\n")+" {}":u.css,p=o();p.write(Buffer.from(a,"utf-8")),c.contents=c.contents.pipe(p),c.sourceMap&&n(c,u.sourceMap),i(null,c)}catch(e){e instanceof Error&&this.emit("error",new r("gulp-purgecss",e.message))}}))}}))}export{s as default};
1
+ import * as glob from 'glob';
2
+ import PluginError from 'plugin-error';
3
+ import { PurgeCSS } from 'purgecss';
4
+ import through from 'through2';
5
+ import applySourceMap from 'vinyl-sourcemaps-apply';
6
+
7
+ const PLUGIN_NAME = "gulp-purgecss";
8
+ function getFiles(contentArray, ignore) {
9
+ return contentArray.reduce((acc, content) => {
10
+ return [...acc, ...glob.sync(content, { ignore })];
11
+ }, []);
12
+ }
13
+ /**
14
+ *
15
+ * @param options - options
16
+ * @returns
17
+ *
18
+ * @public
19
+ */
20
+ function gulpPurgeCSS(options) {
21
+ return through.obj(async function (file, _encoding, callback) {
22
+ // empty
23
+ if (file.isNull())
24
+ return callback(null, file);
25
+ // buffer
26
+ if (file.isBuffer()) {
27
+ try {
28
+ const optionsGulp = {
29
+ ...options,
30
+ content: getFiles(options.content, options.skippedContentGlobs),
31
+ css: [
32
+ {
33
+ raw: file.contents.toString(),
34
+ },
35
+ ],
36
+ stdin: true,
37
+ sourceMap: !!file.sourceMap,
38
+ };
39
+ const purgedCSSResults = await new PurgeCSS().purge(optionsGulp);
40
+ const purge = purgedCSSResults[0];
41
+ const result = optionsGulp.rejected && purge.rejected
42
+ ? purge.rejected.join(" {}\n") + " {}"
43
+ : purge.css;
44
+ file.contents = Buffer.from(result, "utf-8");
45
+ // apply source map to the chain
46
+ if (file.sourceMap) {
47
+ applySourceMap(file, purge.sourceMap);
48
+ }
49
+ callback(null, file);
50
+ }
51
+ catch (e) {
52
+ if (e instanceof Error) {
53
+ this.emit("error", new PluginError(PLUGIN_NAME, e.message));
54
+ }
55
+ }
56
+ }
57
+ // stream
58
+ if (file.isStream()) {
59
+ let css = "";
60
+ file.contents
61
+ .on("data", (buffer) => {
62
+ css += buffer.toString();
63
+ })
64
+ .on("end", async () => {
65
+ try {
66
+ const optionsGulp = {
67
+ ...options,
68
+ css: [
69
+ {
70
+ raw: css,
71
+ },
72
+ ],
73
+ sourceMap: !!file.sourceMap,
74
+ };
75
+ const purgedCSSResults = await new PurgeCSS().purge(optionsGulp);
76
+ const purge = purgedCSSResults[0];
77
+ const result = optionsGulp.rejected && purge.rejected
78
+ ? purge.rejected.join(" {}\n") + " {}"
79
+ : purge.css;
80
+ const streamResult = through();
81
+ streamResult.write(Buffer.from(result, "utf-8"));
82
+ file.contents = file.contents.pipe(streamResult);
83
+ // apply source map to the chain
84
+ if (file.sourceMap) {
85
+ applySourceMap(file, purge.sourceMap);
86
+ }
87
+ callback(null, file);
88
+ }
89
+ catch (e) {
90
+ if (e instanceof Error) {
91
+ this.emit("error", new PluginError(PLUGIN_NAME, e.message));
92
+ }
93
+ }
94
+ });
95
+ }
96
+ });
97
+ }
98
+
99
+ export { gulpPurgeCSS as default };
@@ -1 +1,120 @@
1
- "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);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("gulp-purgecss",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("gulp-purgecss",e.message))}}))}}))};
1
+ 'use strict';
2
+
3
+ var glob = require('glob');
4
+ var PluginError = require('plugin-error');
5
+ var purgecss = require('purgecss');
6
+ var through = require('through2');
7
+ var applySourceMap = require('vinyl-sourcemaps-apply');
8
+
9
+ function _interopNamespaceDefault(e) {
10
+ var n = Object.create(null);
11
+ if (e) {
12
+ Object.keys(e).forEach(function (k) {
13
+ if (k !== 'default') {
14
+ var d = Object.getOwnPropertyDescriptor(e, k);
15
+ Object.defineProperty(n, k, d.get ? d : {
16
+ enumerable: true,
17
+ get: function () { return e[k]; }
18
+ });
19
+ }
20
+ });
21
+ }
22
+ n.default = e;
23
+ return Object.freeze(n);
24
+ }
25
+
26
+ var glob__namespace = /*#__PURE__*/_interopNamespaceDefault(glob);
27
+
28
+ const PLUGIN_NAME = "gulp-purgecss";
29
+ function getFiles(contentArray, ignore) {
30
+ return contentArray.reduce((acc, content) => {
31
+ return [...acc, ...glob__namespace.sync(content, { ignore })];
32
+ }, []);
33
+ }
34
+ /**
35
+ *
36
+ * @param options - options
37
+ * @returns
38
+ *
39
+ * @public
40
+ */
41
+ function gulpPurgeCSS(options) {
42
+ return through.obj(async function (file, _encoding, callback) {
43
+ // empty
44
+ if (file.isNull())
45
+ return callback(null, file);
46
+ // buffer
47
+ if (file.isBuffer()) {
48
+ try {
49
+ const optionsGulp = {
50
+ ...options,
51
+ content: getFiles(options.content, options.skippedContentGlobs),
52
+ css: [
53
+ {
54
+ raw: file.contents.toString(),
55
+ },
56
+ ],
57
+ stdin: true,
58
+ sourceMap: !!file.sourceMap,
59
+ };
60
+ const purgedCSSResults = await new purgecss.PurgeCSS().purge(optionsGulp);
61
+ const purge = purgedCSSResults[0];
62
+ const result = optionsGulp.rejected && purge.rejected
63
+ ? purge.rejected.join(" {}\n") + " {}"
64
+ : purge.css;
65
+ file.contents = Buffer.from(result, "utf-8");
66
+ // apply source map to the chain
67
+ if (file.sourceMap) {
68
+ applySourceMap(file, purge.sourceMap);
69
+ }
70
+ callback(null, file);
71
+ }
72
+ catch (e) {
73
+ if (e instanceof Error) {
74
+ this.emit("error", new PluginError(PLUGIN_NAME, e.message));
75
+ }
76
+ }
77
+ }
78
+ // stream
79
+ if (file.isStream()) {
80
+ let css = "";
81
+ file.contents
82
+ .on("data", (buffer) => {
83
+ css += buffer.toString();
84
+ })
85
+ .on("end", async () => {
86
+ try {
87
+ const optionsGulp = {
88
+ ...options,
89
+ css: [
90
+ {
91
+ raw: css,
92
+ },
93
+ ],
94
+ sourceMap: !!file.sourceMap,
95
+ };
96
+ const purgedCSSResults = await new purgecss.PurgeCSS().purge(optionsGulp);
97
+ const purge = purgedCSSResults[0];
98
+ const result = optionsGulp.rejected && purge.rejected
99
+ ? purge.rejected.join(" {}\n") + " {}"
100
+ : purge.css;
101
+ const streamResult = through();
102
+ streamResult.write(Buffer.from(result, "utf-8"));
103
+ file.contents = file.contents.pipe(streamResult);
104
+ // apply source map to the chain
105
+ if (file.sourceMap) {
106
+ applySourceMap(file, purge.sourceMap);
107
+ }
108
+ callback(null, file);
109
+ }
110
+ catch (e) {
111
+ if (e instanceof Error) {
112
+ this.emit("error", new PluginError(PLUGIN_NAME, e.message));
113
+ }
114
+ }
115
+ });
116
+ }
117
+ });
118
+ }
119
+
120
+ module.exports = gulpPurgeCSS;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gulp-purgecss",
3
- "version": "6.0.0-alpha.0",
3
+ "version": "7.0.1-alpha.0",
4
4
  "description": "Gulp plugin for purgecss",
5
5
  "author": "Ffloriel",
6
6
  "homepage": "https://purgecss.com",
@@ -36,9 +36,9 @@
36
36
  "test": "jest"
37
37
  },
38
38
  "dependencies": {
39
- "glob": "^8.0.3",
39
+ "glob": "^11.0.0",
40
40
  "plugin-error": "^2.0.0",
41
- "purgecss": "^6.0.0-alpha.0",
41
+ "purgecss": "^7.0.1-alpha.0",
42
42
  "through2": "^4.0.1",
43
43
  "vinyl-sourcemaps-apply": "^0.2.1"
44
44
  },
@@ -57,5 +57,5 @@
57
57
  "access": "public",
58
58
  "registry": "https://registry.npmjs.org/"
59
59
  },
60
- "gitHead": "152ccba46e781902f302b7adca1788a6909e9569"
60
+ "gitHead": "5a51b05a191ba48b5e55440ac2e66822f9e182fe"
61
61
  }