gulp-purgecss 6.0.0 → 7.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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 Full Human
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -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";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};
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);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))}}))}}))};
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",
3
+ "version": "7.0.2",
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": "^10.3.10",
39
+ "glob": "^11.0.0",
40
40
  "plugin-error": "^2.0.0",
41
- "purgecss": "^6.0.0",
41
+ "purgecss": "^7.0.2",
42
42
  "through2": "^4.0.1",
43
43
  "vinyl-sourcemaps-apply": "^0.2.1"
44
44
  },
@@ -56,5 +56,6 @@
56
56
  "publishConfig": {
57
57
  "access": "public",
58
58
  "registry": "https://registry.npmjs.org/"
59
- }
59
+ },
60
+ "gitHead": "e95398d961e03a809b5e3da75e3dae1813b46b68"
60
61
  }