rollup-plugin-purgecss 4.1.3 → 6.0.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,5 @@
1
- import fs from "fs";
2
- import path from "path";
1
+ import * as fs from "fs";
2
+ import * as path from "path";
3
3
  import { rollup } from "rollup";
4
4
  import purgecss from "./../src/";
5
5
 
package/build.ts ADDED
@@ -0,0 +1,25 @@
1
+ import {
2
+ buildRollup,
3
+ createRollupConfig,
4
+ extractAPI,
5
+ } from "../../scripts/build";
6
+ import { promises as asyncFs } from "fs";
7
+ import * as path from "path";
8
+
9
+ (async () => {
10
+ await asyncFs.rm(path.resolve(__dirname, "lib"), {
11
+ recursive: true,
12
+ force: true,
13
+ });
14
+ const rollupConfig = createRollupConfig("rollup-plugin-purgecss", [
15
+ "fs",
16
+ "rollup-pluginutils",
17
+ "purgecss",
18
+ ]);
19
+ await buildRollup(rollupConfig);
20
+ await extractAPI(__dirname);
21
+ await asyncFs.rm(path.resolve(__dirname, "lib", ".temp"), {
22
+ recursive: true,
23
+ force: true,
24
+ });
25
+ })();
package/jest.config.ts ADDED
@@ -0,0 +1,2 @@
1
+ import { createConfig } from "./../../jest.config";
2
+ export default createConfig(__dirname, "rollup-plugin-purgecss");
@@ -1,43 +1,164 @@
1
- import { Plugin } from "rollup";
2
- type StringRegExpArray = Array<RegExp | string>;
3
- type ComplexSafelist = {
4
- standard?: StringRegExpArray;
5
- deep?: RegExp[];
6
- greedy?: RegExp[];
7
- variables?: StringRegExpArray;
8
- keyframes?: StringRegExpArray;
9
- };
10
- type UserDefinedSafelist = StringRegExpArray | ComplexSafelist;
11
- interface RawContent$0<T = string> {
12
- extension: string;
13
- raw: T;
14
- }
15
- type ExtractorFunction$0<T = string> = (content: T) => string[];
16
- interface Extractors$0 {
17
- extensions: string[];
18
- extractor: ExtractorFunction$0;
19
- }
20
- type OutputFunction = (css: string, styles: string[]) => void;
21
- interface UserDefinedOptions$0 {
22
- content: Array<string | RawContent$0>;
23
- contentFunction?: (sourceFile: string) => Array<string | RawContent$0>;
24
- defaultExtractor?: ExtractorFunction$0;
25
- extractors?: Array<Extractors$0>;
26
- fontFace?: boolean;
27
- keyframes?: boolean;
28
- output?: string | OutputFunction | boolean;
29
- rejected?: boolean;
30
- stdin?: boolean;
31
- stdout?: boolean;
32
- variables?: boolean;
33
- safelist?: UserDefinedSafelist;
34
- blocklist?: StringRegExpArray;
35
- skippedContentGlobs?: Array<string>;
36
- dynamicAttributes?: string[];
37
- insert?: boolean;
38
- include?: string | RegExp | (string | RegExp)[];
39
- exclude?: string | RegExp | (string | RegExp)[];
40
- dest?: string;
41
- }
42
- declare function pluginPurgeCSS(options: UserDefinedOptions$0): Plugin;
43
- export { pluginPurgeCSS as default };
1
+ import { Plugin as Plugin_2 } from 'rollup';
2
+ import * as postcss from 'postcss';
3
+
4
+ /**
5
+ * @public
6
+ */
7
+ declare type ComplexSafelist = {
8
+ standard?: StringRegExpArray;
9
+ /**
10
+ * You can safelist selectors and their children based on a regular
11
+ * expression with `safelist.deep`
12
+ *
13
+ * @example
14
+ *
15
+ * ```ts
16
+ * const purgecss = await new PurgeCSS().purge({
17
+ * content: [],
18
+ * css: [],
19
+ * safelist: {
20
+ * deep: [/red$/]
21
+ * }
22
+ * })
23
+ * ```
24
+ *
25
+ * In this example, selectors such as `.bg-red .child-of-bg` will be left
26
+ * in the final CSS, even if `child-of-bg` is not found.
27
+ *
28
+ */
29
+ deep?: RegExp[];
30
+ greedy?: RegExp[];
31
+ variables?: StringRegExpArray;
32
+ keyframes?: StringRegExpArray;
33
+ };
34
+
35
+ /**
36
+ * @public
37
+ */
38
+ declare type ExtractorFunction<T = string> = (content: T) => ExtractorResult;
39
+
40
+ /**
41
+ * @public
42
+ */
43
+ declare type ExtractorResult = ExtractorResultDetailed | string[];
44
+
45
+ /**
46
+ * @public
47
+ */
48
+ declare interface ExtractorResultDetailed {
49
+ attributes: {
50
+ names: string[];
51
+ values: string[];
52
+ };
53
+ classes: string[];
54
+ ids: string[];
55
+ tags: string[];
56
+ undetermined: string[];
57
+ }
58
+
59
+ /**
60
+ * @public
61
+ */
62
+ declare interface Extractors {
63
+ extensions: string[];
64
+ extractor: ExtractorFunction;
65
+ }
66
+
67
+ /**
68
+ * @public
69
+ */
70
+ export declare type OutputFunction = (css: string, styles: string[]) => void;
71
+
72
+ /**
73
+ *
74
+ * @param options - options
75
+ * @returns
76
+ *
77
+ * @public
78
+ */
79
+ declare function pluginPurgeCSS(options: UserDefinedOptions): Plugin_2;
80
+ export default pluginPurgeCSS;
81
+
82
+ /**
83
+ * @public
84
+ */
85
+ declare interface RawContent<T = string> {
86
+ extension: string;
87
+ raw: T;
88
+ }
89
+
90
+ /**
91
+ * @public
92
+ */
93
+ declare interface RawCSS {
94
+ raw: string;
95
+ name?: string;
96
+ }
97
+
98
+ /**
99
+ * @public
100
+ */
101
+ declare type StringRegExpArray = Array<RegExp | string>;
102
+
103
+ /**
104
+ * {@inheritDoc purgecss#UserDefinedOptions}
105
+ *
106
+ * @public
107
+ */
108
+ export declare type UserDefinedOptions = Omit<UserDefinedOptions_2, "css" | "output" | "rejectedCss"> & {
109
+ contentFunction?: (sourceFile: string) => Array<string | RawContent>;
110
+ output: UserDefinedOptions_2["output"] | OutputFunction | boolean;
111
+ insert?: boolean;
112
+ include?: string | RegExp | (string | RegExp)[];
113
+ exclude?: string | RegExp | (string | RegExp)[];
114
+ dest?: string;
115
+ };
116
+
117
+ /**
118
+ * Options used by PurgeCSS to remove unused CSS
119
+ *
120
+ * @public
121
+ */
122
+ declare interface UserDefinedOptions_2 {
123
+ /** {@inheritDoc purgecss#Options.content} */
124
+ content: Array<string | RawContent>;
125
+ /** {@inheritDoc purgecss#Options.css} */
126
+ css: Array<string | RawCSS>;
127
+ /** {@inheritDoc purgecss#Options.defaultExtractor} */
128
+ defaultExtractor?: ExtractorFunction;
129
+ /** {@inheritDoc purgecss#Options.extractors} */
130
+ extractors?: Array<Extractors>;
131
+ /** {@inheritDoc purgecss#Options.fontFace} */
132
+ fontFace?: boolean;
133
+ /** {@inheritDoc purgecss#Options.keyframes} */
134
+ keyframes?: boolean;
135
+ /** {@inheritDoc purgecss#Options.output} */
136
+ output?: string;
137
+ /** {@inheritDoc purgecss#Options.rejected} */
138
+ rejected?: boolean;
139
+ /** {@inheritDoc purgecss#Options.rejectedCss} */
140
+ rejectedCss?: boolean;
141
+ /** {@inheritDoc purgecss#Options.sourceMap } */
142
+ sourceMap?: boolean | (postcss.SourceMapOptions & { to?: string });
143
+ /** {@inheritDoc purgecss#Options.stdin} */
144
+ stdin?: boolean;
145
+ /** {@inheritDoc purgecss#Options.stdout} */
146
+ stdout?: boolean;
147
+ /** {@inheritDoc purgecss#Options.variables} */
148
+ variables?: boolean;
149
+ /** {@inheritDoc purgecss#Options.safelist} */
150
+ safelist?: UserDefinedSafelist;
151
+ /** {@inheritDoc purgecss#Options.blocklist} */
152
+ blocklist?: StringRegExpArray;
153
+ /** {@inheritDoc purgecss#Options.skippedContentGlobs} */
154
+ skippedContentGlobs?: Array<string>;
155
+ /** {@inheritDoc purgecss#Options.dynamicAttributes} */
156
+ dynamicAttributes?: string[];
157
+ }
158
+
159
+ /**
160
+ * @public
161
+ */
162
+ declare type UserDefinedSafelist = StringRegExpArray | ComplexSafelist;
163
+
164
+ export { }
@@ -1 +1 @@
1
- import t from"fs";import{PurgeCSS as e}from"purgecss";import{createFilter as n}from"rollup-pluginutils";function r(r){const u=n(r.include||["**/*.css"],r.exclude||"node_modules/**"),s=[];let o="";return{name:"purgecss",transform:async(t,n)=>{if(!u(n))return null;let o=(await(new e).purge({content:r.content,css:[{raw:t}]}))[0].css;return s.push(o),o=JSON.stringify(o),r.insert||(t=r.output?'"";':o),{code:`export default ${t}`,map:{mappings:""}}},generateBundle(){if(!(r.insert||s.length&&!1!==r.output))return;const e=s.reduce(((t,e)=>t+e),"");return"string"==typeof r.output?t.writeFileSync(r.output,e):"function"==typeof r.output?r.output(e,s):!r.insert&&o?((o.endsWith(".js")||o.endsWith(".ts"))&&(o=o.slice(0,-3)),o=`${o}.css`,t.writeFileSync(o,e)):void 0}}}export{r as default};
1
+ import*as t from"fs";import{PurgeCSS as e}from"purgecss";import{createFilter as n}from"rollup-pluginutils";function r(r){const u=n(r.include||["**/*.css"],r.exclude||"node_modules/**"),s=[];let o="";return{name:"purgecss",transform:async(t,n)=>{if(!u(n))return null;let o=(await(new e).purge({content:r.content,css:[{raw:t}]}))[0].css;return s.push(o),o=JSON.stringify(o),r.insert||(t=r.output?'"";':o),{code:`export default ${t}`,map:{mappings:""}}},generateBundle(){if(!(r.insert||s.length&&!1!==r.output))return;const e=s.reduce(((t,e)=>t+e),"");return"string"==typeof r.output?t.writeFileSync(r.output,e):"function"==typeof r.output?r.output(e,s):!r.insert&&o?((o.endsWith(".js")||o.endsWith(".ts"))&&(o=o.slice(0,-3)),o=`${o}.css`,t.writeFileSync(o,e)):void 0}}}export{r as default};
@@ -1 +1 @@
1
- "use strict";var e=require("fs"),t=require("purgecss"),u=require("rollup-pluginutils");function r(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var n=r(e);module.exports=function(e){const r=u.createFilter(e.include||["**/*.css"],e.exclude||"node_modules/**"),s=[];let i="";return{name:"purgecss",transform:async(u,n)=>{if(!r(n))return null;let i=(await(new t.PurgeCSS).purge({content:e.content,css:[{raw:u}]}))[0].css;return s.push(i),i=JSON.stringify(i),e.insert||(u=e.output?'"";':i),{code:`export default ${u}`,map:{mappings:""}}},generateBundle(){if(!(e.insert||s.length&&!1!==e.output))return;const t=s.reduce(((e,t)=>e+t),"");return"string"==typeof e.output?n.default.writeFileSync(e.output,t):"function"==typeof e.output?e.output(t,s):!e.insert&&i?((i.endsWith(".js")||i.endsWith(".ts"))&&(i=i.slice(0,-3)),i=`${i}.css`,n.default.writeFileSync(i,t)):void 0}}};
1
+ "use strict";var e=require("fs"),t=require("purgecss"),r=require("rollup-pluginutils");function u(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var u=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,u.get?u:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}var n=u(e);module.exports=function(e){const u=r.createFilter(e.include||["**/*.css"],e.exclude||"node_modules/**"),s=[];let i="";return{name:"purgecss",transform:async(r,n)=>{if(!u(n))return null;let i=(await(new t.PurgeCSS).purge({content:e.content,css:[{raw:r}]}))[0].css;return s.push(i),i=JSON.stringify(i),e.insert||(r=e.output?'"";':i),{code:`export default ${r}`,map:{mappings:""}}},generateBundle(){if(!(e.insert||s.length&&!1!==e.output))return;const t=s.reduce(((e,t)=>e+t),"");return"string"==typeof e.output?n.writeFileSync(e.output,t):"function"==typeof e.output?e.output(t,s):!e.insert&&i?((i.endsWith(".js")||i.endsWith(".ts"))&&(i=i.slice(0,-3)),i=`${i}.css`,n.writeFileSync(i,t)):void 0}}};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rollup-plugin-purgecss",
3
- "version": "4.1.3",
3
+ "version": "6.0.0",
4
4
  "description": "Rollup plugin for purgecss",
5
5
  "main": "lib/rollup-plugin-purgecss.js",
6
6
  "module": "./lib/rollup-plugin-purgecss.es.js",
@@ -10,7 +10,8 @@
10
10
  "test": "__tests__"
11
11
  },
12
12
  "scripts": {
13
- "test": "echo \"Error: run tests from root\" && exit 1"
13
+ "build": "ts-node build.ts",
14
+ "test": "jest"
14
15
  },
15
16
  "repository": {
16
17
  "type": "git",
@@ -30,12 +31,11 @@
30
31
  },
31
32
  "homepage": "https://purgecss.com",
32
33
  "dependencies": {
33
- "purgecss": "^4.1.3",
34
+ "purgecss": "^5.0.0",
34
35
  "rollup-pluginutils": "^2.8.0"
35
36
  },
36
37
  "publishConfig": {
37
38
  "access": "public",
38
39
  "registry": "https://registry.npmjs.org/"
39
- },
40
- "gitHead": "37e5053a446880d12fd2f55abfc362c3dac9c49c"
40
+ }
41
41
  }
package/src/index.ts CHANGED
@@ -1,13 +1,22 @@
1
- import fs from "fs";
1
+ import * as fs from "fs";
2
2
  import { PurgeCSS } from "purgecss";
3
3
  import { Plugin } from "rollup";
4
4
  import { createFilter } from "rollup-pluginutils";
5
5
  import { UserDefinedOptions } from "./types";
6
6
 
7
+ export * from "./types";
8
+
9
+ /**
10
+ *
11
+ * @param options - options
12
+ * @returns
13
+ *
14
+ * @public
15
+ */
7
16
  function pluginPurgeCSS(options: UserDefinedOptions): Plugin {
8
17
  const filter = createFilter(
9
18
  options.include || ["**/*.css"],
10
- options.exclude || "node_modules/**"
19
+ options.exclude || "node_modules/**",
11
20
  );
12
21
 
13
22
  const styles: string[] = [];
@@ -1,42 +1,26 @@
1
- import {
2
- StringRegExpArray,
3
- UserDefinedSafelist,
4
- } from "../../../purgecss/src/types/index";
1
+ import type {
2
+ RawContent,
3
+ UserDefinedOptions as PurgeCSSUserDefinedOptions,
4
+ } from "purgecss";
5
5
 
6
- export interface RawContent<T = string> {
7
- extension: string;
8
- raw: T;
9
- }
10
- export interface RawCSS {
11
- raw: string;
12
- }
13
- type ExtractorFunction<T = string> = (content: T) => string[];
14
- export interface Extractors {
15
- extensions: string[];
16
- extractor: ExtractorFunction;
17
- }
6
+ /**
7
+ * @public
8
+ */
9
+ export type OutputFunction = (css: string, styles: string[]) => void;
18
10
 
19
- type OutputFunction = (css: string, styles: string[]) => void;
20
-
21
- export interface UserDefinedOptions {
22
- content: Array<string | RawContent>;
11
+ /**
12
+ * {@inheritDoc purgecss#UserDefinedOptions}
13
+ *
14
+ * @public
15
+ */
16
+ export type UserDefinedOptions = Omit<
17
+ PurgeCSSUserDefinedOptions,
18
+ "css" | "output" | "rejectedCss"
19
+ > & {
23
20
  contentFunction?: (sourceFile: string) => Array<string | RawContent>;
24
- defaultExtractor?: ExtractorFunction;
25
- extractors?: Array<Extractors>;
26
- fontFace?: boolean;
27
- keyframes?: boolean;
28
- output?: string | OutputFunction | boolean;
29
- rejected?: boolean;
30
- stdin?: boolean;
31
- stdout?: boolean;
32
- variables?: boolean;
33
- safelist?: UserDefinedSafelist;
34
- blocklist?: StringRegExpArray;
35
- skippedContentGlobs?: Array<string>;
36
- dynamicAttributes?: string[];
37
-
21
+ output: PurgeCSSUserDefinedOptions["output"] | OutputFunction | boolean;
38
22
  insert?: boolean;
39
23
  include?: string | RegExp | (string | RegExp)[];
40
24
  exclude?: string | RegExp | (string | RegExp)[];
41
25
  dest?: string;
42
- }
26
+ };
package/tsconfig.json ADDED
@@ -0,0 +1,14 @@
1
+ {
2
+ "extends": "./../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "declaration": true,
5
+ "outDir": "./lib",
6
+ "declarationDir": "./.temp/",
7
+ "baseUrl": ".",
8
+ "paths": {
9
+ "purgecss": ["../purgecss/src"],
10
+ }
11
+ },
12
+ "include": ["./src/**/*", "./../purgecss/src/*"],
13
+ "exclude": ["./lib"]
14
+ }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
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,43 +0,0 @@
1
- import { Plugin } from "rollup";
2
- type StringRegExpArray = Array<RegExp | string>;
3
- type ComplexSafelist = {
4
- standard?: StringRegExpArray;
5
- deep?: RegExp[];
6
- greedy?: RegExp[];
7
- variables?: StringRegExpArray;
8
- keyframes?: StringRegExpArray;
9
- };
10
- type UserDefinedSafelist = StringRegExpArray | ComplexSafelist;
11
- interface RawContent$0<T = string> {
12
- extension: string;
13
- raw: T;
14
- }
15
- type ExtractorFunction$0<T = string> = (content: T) => string[];
16
- interface Extractors$0 {
17
- extensions: string[];
18
- extractor: ExtractorFunction$0;
19
- }
20
- type OutputFunction = (css: string, styles: string[]) => void;
21
- interface UserDefinedOptions$0 {
22
- content: Array<string | RawContent$0>;
23
- contentFunction?: (sourceFile: string) => Array<string | RawContent$0>;
24
- defaultExtractor?: ExtractorFunction$0;
25
- extractors?: Array<Extractors$0>;
26
- fontFace?: boolean;
27
- keyframes?: boolean;
28
- output?: string | OutputFunction | boolean;
29
- rejected?: boolean;
30
- stdin?: boolean;
31
- stdout?: boolean;
32
- variables?: boolean;
33
- safelist?: UserDefinedSafelist;
34
- blocklist?: StringRegExpArray;
35
- skippedContentGlobs?: Array<string>;
36
- dynamicAttributes?: string[];
37
- insert?: boolean;
38
- include?: string | RegExp | (string | RegExp)[];
39
- exclude?: string | RegExp | (string | RegExp)[];
40
- dest?: string;
41
- }
42
- declare function pluginPurgeCSS(options: UserDefinedOptions$0): Plugin;
43
- export { pluginPurgeCSS as default };