@veryfront/ext-css-purgecss 0.1.1186 → 0.1.1188
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/esm/deno.d.ts +28 -0
- package/esm/deno.d.ts.map +1 -0
- package/esm/deno.js +23 -0
- package/esm/src/index.d.ts +6 -0
- package/esm/src/index.d.ts.map +1 -0
- package/esm/src/index.js +220 -0
- package/package.json +3 -3
package/esm/deno.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
declare namespace _default {
|
|
2
|
+
let name: string;
|
|
3
|
+
let version: string;
|
|
4
|
+
let exports: string;
|
|
5
|
+
namespace veryfront {
|
|
6
|
+
let extension: boolean;
|
|
7
|
+
let activation: string;
|
|
8
|
+
namespace contracts {
|
|
9
|
+
let provides: string[];
|
|
10
|
+
}
|
|
11
|
+
let capabilities: {
|
|
12
|
+
type: string;
|
|
13
|
+
apis: string[];
|
|
14
|
+
}[];
|
|
15
|
+
}
|
|
16
|
+
let imports: {
|
|
17
|
+
purgecss: string;
|
|
18
|
+
"@std/assert": string;
|
|
19
|
+
"@std/testing/bdd": string;
|
|
20
|
+
"veryfront/extensions": string;
|
|
21
|
+
"veryfront/extensions/css": string;
|
|
22
|
+
};
|
|
23
|
+
namespace tasks {
|
|
24
|
+
let test: string;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export default _default;
|
|
28
|
+
//# sourceMappingURL=deno.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deno.d.ts","sourceRoot":"","sources":["../src/deno.js"],"names":[],"mappings":""}
|
package/esm/deno.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
"name": "@veryfront/ext-css-purgecss",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"exports": "./src/index.ts",
|
|
5
|
+
"veryfront": {
|
|
6
|
+
"extension": true,
|
|
7
|
+
"activation": "explicit",
|
|
8
|
+
"contracts": {
|
|
9
|
+
"provides": ["CSSPurgingEngine"]
|
|
10
|
+
},
|
|
11
|
+
"capabilities": [{ "type": "system:read", "apis": ["cpus"] }]
|
|
12
|
+
},
|
|
13
|
+
"imports": {
|
|
14
|
+
"purgecss": "npm:purgecss@8.0.0",
|
|
15
|
+
"@std/assert": "jsr:@std/assert@1.0.19",
|
|
16
|
+
"@std/testing/bdd": "jsr:@std/testing@1.0.17/bdd",
|
|
17
|
+
"veryfront/extensions": "../../src/extensions/types.ts",
|
|
18
|
+
"veryfront/extensions/css": "../../src/extensions/css/index.ts"
|
|
19
|
+
},
|
|
20
|
+
"tasks": {
|
|
21
|
+
"test": "deno test --frozen --no-check --allow-sys=cpus src/"
|
|
22
|
+
}
|
|
23
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** PurgeCSS implementation of the provider-neutral CSS purging contract. */
|
|
2
|
+
import "../_dnt.polyfills.js";
|
|
3
|
+
import type { ExtensionFactory } from "veryfront/extensions";
|
|
4
|
+
declare const extCSSPurgeCSS: ExtensionFactory;
|
|
5
|
+
export default extCSSPurgeCSS;
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/src/index.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,OAAO,sBAAsB,CAAC;AAG9B,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AA6P7D,QAAA,MAAM,cAAc,EAAE,gBAerB,CAAC;AAEF,eAAe,cAAc,CAAC"}
|
package/esm/src/index.js
ADDED
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
/** PurgeCSS implementation of the provider-neutral CSS purging contract. */
|
|
2
|
+
import "../_dnt.polyfills.js";
|
|
3
|
+
import { CSSPurgingEngineName, } from "veryfront/extensions/css";
|
|
4
|
+
import { PurgeCSS } from "purgecss";
|
|
5
|
+
import extensionPackage from "../deno.js";
|
|
6
|
+
const arrayIsArray = Array.isArray;
|
|
7
|
+
const freeze = Object.freeze;
|
|
8
|
+
const getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
|
|
9
|
+
const getOwnPropertyDescriptors = Object.getOwnPropertyDescriptors;
|
|
10
|
+
const getPrototypeOf = Object.getPrototypeOf;
|
|
11
|
+
const hasOwn = Object.hasOwn;
|
|
12
|
+
const objectPrototype = Object.prototype;
|
|
13
|
+
const ownKeys = Reflect.ownKeys;
|
|
14
|
+
const executeRegularExpression = RegExp.prototype.exec;
|
|
15
|
+
const apply = Reflect.apply;
|
|
16
|
+
const purgeCSSPurge = PurgeCSS.prototype.purge;
|
|
17
|
+
const EXACT_NPM_SPECIFIER_PATTERN = /^npm:purgecss@((?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*))$/;
|
|
18
|
+
const ENGINE_SEMANTICS_VERSION = "veryfront.css-purgecss.v1";
|
|
19
|
+
const PROVIDER_RESULT_KEYS = freeze([
|
|
20
|
+
"css",
|
|
21
|
+
"file",
|
|
22
|
+
"rejectedCss",
|
|
23
|
+
]);
|
|
24
|
+
function dependencyVersion(specifier) {
|
|
25
|
+
const match = apply(executeRegularExpression, EXACT_NPM_SPECIFIER_PATTERN, [
|
|
26
|
+
specifier,
|
|
27
|
+
]);
|
|
28
|
+
if (match?.[1] === undefined) {
|
|
29
|
+
throw new TypeError("ext-css-purgecss dependency must use an exact npm version");
|
|
30
|
+
}
|
|
31
|
+
return match[1];
|
|
32
|
+
}
|
|
33
|
+
function assertEmptyConfig(value) {
|
|
34
|
+
if (value === undefined)
|
|
35
|
+
return;
|
|
36
|
+
if (typeof value !== "object" || value === null) {
|
|
37
|
+
throw new TypeError("ext-css-purgecss config must be an object");
|
|
38
|
+
}
|
|
39
|
+
let isArray;
|
|
40
|
+
let prototype;
|
|
41
|
+
let keys;
|
|
42
|
+
try {
|
|
43
|
+
isArray = arrayIsArray(value);
|
|
44
|
+
prototype = getPrototypeOf(value);
|
|
45
|
+
keys = ownKeys(getOwnPropertyDescriptors(value));
|
|
46
|
+
}
|
|
47
|
+
catch (cause) {
|
|
48
|
+
throw new TypeError("ext-css-purgecss config could not be inspected", {
|
|
49
|
+
cause,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
if (isArray) {
|
|
53
|
+
throw new TypeError("ext-css-purgecss config must be an object");
|
|
54
|
+
}
|
|
55
|
+
if (prototype !== objectPrototype && prototype !== null) {
|
|
56
|
+
throw new TypeError("ext-css-purgecss config must not inherit configuration");
|
|
57
|
+
}
|
|
58
|
+
if (keys.length !== 0) {
|
|
59
|
+
throw new TypeError("ext-css-purgecss does not accept configuration properties");
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
function inspectArray(value, label) {
|
|
63
|
+
try {
|
|
64
|
+
return arrayIsArray(value);
|
|
65
|
+
}
|
|
66
|
+
catch (cause) {
|
|
67
|
+
throw new TypeError(`${label} could not be inspected`, { cause });
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
function descriptorValue(value, property, label, required, enumerable = true) {
|
|
71
|
+
let descriptor;
|
|
72
|
+
try {
|
|
73
|
+
descriptor = getOwnPropertyDescriptor(value, property);
|
|
74
|
+
}
|
|
75
|
+
catch (cause) {
|
|
76
|
+
throw new TypeError(`${label} could not be inspected`, { cause });
|
|
77
|
+
}
|
|
78
|
+
if (descriptor === undefined) {
|
|
79
|
+
if (!required)
|
|
80
|
+
return undefined;
|
|
81
|
+
throw new TypeError(`${label} must define ${property}`);
|
|
82
|
+
}
|
|
83
|
+
if (!hasOwn(descriptor, "value") || descriptor.enumerable !== enumerable) {
|
|
84
|
+
throw new TypeError(`${label} ${property} must be an own data property`);
|
|
85
|
+
}
|
|
86
|
+
return descriptor.value;
|
|
87
|
+
}
|
|
88
|
+
function copyContent(content) {
|
|
89
|
+
const copied = [];
|
|
90
|
+
for (let index = 0; index < content.length; index++) {
|
|
91
|
+
const source = content[index];
|
|
92
|
+
copied[index] = { raw: source.raw, extension: source.extension };
|
|
93
|
+
}
|
|
94
|
+
return copied;
|
|
95
|
+
}
|
|
96
|
+
function copyStrings(values) {
|
|
97
|
+
const copied = [];
|
|
98
|
+
for (let index = 0; index < values.length; index++) {
|
|
99
|
+
copied[index] = values[index];
|
|
100
|
+
}
|
|
101
|
+
return copied;
|
|
102
|
+
}
|
|
103
|
+
function providerResult(value, includeRejectedCSS) {
|
|
104
|
+
if (!inspectArray(value, "PurgeCSS result")) {
|
|
105
|
+
throw new TypeError("PurgeCSS returned a non-array result");
|
|
106
|
+
}
|
|
107
|
+
const length = descriptorValue(value, "length", "PurgeCSS result", true, false);
|
|
108
|
+
if (length !== 1) {
|
|
109
|
+
throw new TypeError("PurgeCSS must return exactly one result");
|
|
110
|
+
}
|
|
111
|
+
let arrayKeys;
|
|
112
|
+
try {
|
|
113
|
+
arrayKeys = ownKeys(getOwnPropertyDescriptors(value));
|
|
114
|
+
}
|
|
115
|
+
catch (cause) {
|
|
116
|
+
throw new TypeError("PurgeCSS result could not be inspected", { cause });
|
|
117
|
+
}
|
|
118
|
+
let hasEntry = false;
|
|
119
|
+
let hasLength = false;
|
|
120
|
+
for (let index = 0; index < arrayKeys.length; index++) {
|
|
121
|
+
if (arrayKeys[index] === "0")
|
|
122
|
+
hasEntry = true;
|
|
123
|
+
if (arrayKeys[index] === "length")
|
|
124
|
+
hasLength = true;
|
|
125
|
+
}
|
|
126
|
+
if (arrayKeys.length !== 2 || !hasEntry || !hasLength) {
|
|
127
|
+
throw new TypeError("PurgeCSS returned unsupported result entries");
|
|
128
|
+
}
|
|
129
|
+
const entry = descriptorValue(value, "0", "PurgeCSS result", true);
|
|
130
|
+
if (typeof entry !== "object" ||
|
|
131
|
+
entry === null ||
|
|
132
|
+
inspectArray(entry, "PurgeCSS result entry")) {
|
|
133
|
+
throw new TypeError("PurgeCSS returned an invalid result entry");
|
|
134
|
+
}
|
|
135
|
+
let keys;
|
|
136
|
+
try {
|
|
137
|
+
keys = ownKeys(getOwnPropertyDescriptors(entry));
|
|
138
|
+
}
|
|
139
|
+
catch (cause) {
|
|
140
|
+
throw new TypeError("PurgeCSS result entry could not be inspected", {
|
|
141
|
+
cause,
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
for (let keyIndex = 0; keyIndex < keys.length; keyIndex++) {
|
|
145
|
+
const key = keys[keyIndex];
|
|
146
|
+
let allowed = false;
|
|
147
|
+
for (let index = 0; index < PROVIDER_RESULT_KEYS.length; index++) {
|
|
148
|
+
if (PROVIDER_RESULT_KEYS[index] === key) {
|
|
149
|
+
allowed = true;
|
|
150
|
+
break;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
if (!allowed) {
|
|
154
|
+
throw new TypeError("PurgeCSS returned unsupported result properties");
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
const css = descriptorValue(entry, "css", "PurgeCSS result entry", true);
|
|
158
|
+
if (typeof css !== "string") {
|
|
159
|
+
throw new TypeError("PurgeCSS result css must be a string");
|
|
160
|
+
}
|
|
161
|
+
const file = descriptorValue(entry, "file", "PurgeCSS result entry", false);
|
|
162
|
+
if (file !== undefined) {
|
|
163
|
+
throw new TypeError("PurgeCSS returned an unexpected file-backed result");
|
|
164
|
+
}
|
|
165
|
+
let rejectedDescriptor;
|
|
166
|
+
try {
|
|
167
|
+
rejectedDescriptor = getOwnPropertyDescriptor(entry, "rejectedCss");
|
|
168
|
+
}
|
|
169
|
+
catch (cause) {
|
|
170
|
+
throw new TypeError("PurgeCSS result entry could not be inspected", {
|
|
171
|
+
cause,
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
const rejectedCSS = includeRejectedCSS
|
|
175
|
+
? descriptorValue(entry, "rejectedCss", "PurgeCSS result entry", true)
|
|
176
|
+
: undefined;
|
|
177
|
+
if (includeRejectedCSS && typeof rejectedCSS !== "string") {
|
|
178
|
+
throw new TypeError("PurgeCSS omitted requested rejected CSS");
|
|
179
|
+
}
|
|
180
|
+
if (!includeRejectedCSS && rejectedDescriptor !== undefined) {
|
|
181
|
+
throw new TypeError("PurgeCSS returned unrequested rejected CSS");
|
|
182
|
+
}
|
|
183
|
+
return freeze({
|
|
184
|
+
css,
|
|
185
|
+
...(typeof rejectedCSS === "string" ? { rejectedCSS } : {}),
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
/** Explicit PurgeCSS provider. Invoke it through core's validated session. */
|
|
189
|
+
class PurgeCSSPurgingEngine {
|
|
190
|
+
cacheIdentity;
|
|
191
|
+
constructor() {
|
|
192
|
+
this.cacheIdentity =
|
|
193
|
+
`${ENGINE_SEMANTICS_VERSION};ext-css-purgecss@${extensionPackage.version};purgecss@${dependencyVersion(extensionPackage.imports.purgecss)}`;
|
|
194
|
+
freeze(this);
|
|
195
|
+
}
|
|
196
|
+
async purge(request) {
|
|
197
|
+
const results = await apply(purgeCSSPurge, new PurgeCSS(), [{
|
|
198
|
+
content: copyContent(request.content),
|
|
199
|
+
css: [{ raw: request.css }],
|
|
200
|
+
safelist: copyStrings(request.safelist),
|
|
201
|
+
rejectedCss: request.includeRejectedCSS,
|
|
202
|
+
}]);
|
|
203
|
+
return providerResult(results, request.includeRejectedCSS);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
const extCSSPurgeCSS = (config) => {
|
|
207
|
+
assertEmptyConfig(config);
|
|
208
|
+
const engine = new PurgeCSSPurgingEngine();
|
|
209
|
+
return {
|
|
210
|
+
name: "ext-css-purgecss",
|
|
211
|
+
version: extensionPackage.version,
|
|
212
|
+
contracts: { provides: ["CSSPurgingEngine"] },
|
|
213
|
+
capabilities: [{ type: "system:read", apis: ["cpus"] }],
|
|
214
|
+
setup(ctx) {
|
|
215
|
+
ctx.provide(CSSPurgingEngineName, engine);
|
|
216
|
+
ctx.logger.debug(`[ext-css-purgecss] ${CSSPurgingEngineName} registered`);
|
|
217
|
+
},
|
|
218
|
+
};
|
|
219
|
+
};
|
|
220
|
+
export default extCSSPurgeCSS;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@veryfront/ext-css-purgecss",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1188",
|
|
4
4
|
"description": "Veryfront first-party extension package for ext-css-purgecss",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"veryfront",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
},
|
|
28
28
|
"scripts": {},
|
|
29
29
|
"engines": {
|
|
30
|
-
"node": ">=
|
|
30
|
+
"node": ">=22.3.0"
|
|
31
31
|
},
|
|
32
32
|
"publishConfig": {
|
|
33
33
|
"access": "public"
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"purgecss": "8.0.0"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
|
-
"veryfront": "^0.1.
|
|
56
|
+
"veryfront": "^0.1.1188"
|
|
57
57
|
},
|
|
58
58
|
"type": "module",
|
|
59
59
|
"types": "./esm/src/index.d.ts",
|