@projectwallace/css-code-coverage 0.4.1 → 0.5.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.
- package/dist/cli.js +19 -11192
- package/dist/esm--VCpEgdH.js +11177 -0
- package/dist/esm-CWr4VY0v.js +11013 -0
- package/dist/index.d.ts +2 -12
- package/dist/index.js +13 -8
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -24,16 +24,6 @@ declare function parse_coverage(input: string): {
|
|
|
24
24
|
}[];
|
|
25
25
|
}[];
|
|
26
26
|
//#endregion
|
|
27
|
-
//#region src/lib/types.d.ts
|
|
28
|
-
type NodeList = Iterable<{
|
|
29
|
-
textContent: string;
|
|
30
|
-
}> | NodeListOf<HTMLStyleElement>;
|
|
31
|
-
interface Parser {
|
|
32
|
-
(html: string): {
|
|
33
|
-
querySelectorAll: (selector: string) => NodeList;
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
//#endregion
|
|
37
27
|
//#region src/lib/index.d.ts
|
|
38
28
|
type CoverageData = {
|
|
39
29
|
unused_bytes: number;
|
|
@@ -73,6 +63,6 @@ type CoverageResult = CoverageData & {
|
|
|
73
63
|
* 4. Calculate used/unused CSS bytes (fastest path, no inspection of the actual CSS needed)
|
|
74
64
|
* 5. Calculate line-coverage, byte-coverage per stylesheet
|
|
75
65
|
*/
|
|
76
|
-
declare function calculate_coverage(coverage: Coverage[]
|
|
66
|
+
declare function calculate_coverage(coverage: Coverage[]): Promise<CoverageResult>;
|
|
77
67
|
//#endregion
|
|
78
|
-
export { type Coverage, CoverageData, CoverageResult, type
|
|
68
|
+
export { type Coverage, CoverageData, CoverageResult, type Range, StylesheetCoverage, calculate_coverage, parse_coverage };
|
package/dist/index.js
CHANGED
|
@@ -135,8 +135,15 @@ function ext(url) {
|
|
|
135
135
|
|
|
136
136
|
//#endregion
|
|
137
137
|
//#region src/lib/remap-html.ts
|
|
138
|
-
function
|
|
139
|
-
|
|
138
|
+
async function get_dom_parser() {
|
|
139
|
+
if (typeof window !== "undefined" && "DOMParser" in window)
|
|
140
|
+
/* v8 ignore */
|
|
141
|
+
return new window.DOMParser();
|
|
142
|
+
let { DOMParser } = await import("./esm-CWr4VY0v.js");
|
|
143
|
+
return new DOMParser();
|
|
144
|
+
}
|
|
145
|
+
async function remap_html(html, old_ranges) {
|
|
146
|
+
let doc = (await get_dom_parser()).parseFromString(html, "text/html");
|
|
140
147
|
let combined_css = "";
|
|
141
148
|
let new_ranges = [];
|
|
142
149
|
let current_offset = 0;
|
|
@@ -164,7 +171,7 @@ function remap_html(parse_html, html, old_ranges) {
|
|
|
164
171
|
function is_html(text) {
|
|
165
172
|
return /<\/?(html|body|head|div|span|script|style)/i.test(text);
|
|
166
173
|
}
|
|
167
|
-
function filter_coverage(coverage
|
|
174
|
+
async function filter_coverage(coverage) {
|
|
168
175
|
let result = [];
|
|
169
176
|
for (let entry of coverage) {
|
|
170
177
|
let extension = ext(entry.url).toLowerCase();
|
|
@@ -174,8 +181,7 @@ function filter_coverage(coverage, parse_html) {
|
|
|
174
181
|
continue;
|
|
175
182
|
}
|
|
176
183
|
if (is_html(entry.text)) {
|
|
177
|
-
|
|
178
|
-
let { css, ranges } = remap_html(parse_html, entry.text, entry.ranges);
|
|
184
|
+
let { css, ranges } = await remap_html(entry.text, entry.ranges);
|
|
179
185
|
result.push({
|
|
180
186
|
url: entry.url,
|
|
181
187
|
text: css,
|
|
@@ -209,10 +215,9 @@ function ratio(fraction, total) {
|
|
|
209
215
|
* 4. Calculate used/unused CSS bytes (fastest path, no inspection of the actual CSS needed)
|
|
210
216
|
* 5. Calculate line-coverage, byte-coverage per stylesheet
|
|
211
217
|
*/
|
|
212
|
-
function calculate_coverage(coverage
|
|
218
|
+
async function calculate_coverage(coverage) {
|
|
213
219
|
let total_files_found = coverage.length;
|
|
214
|
-
|
|
215
|
-
let coverage_per_stylesheet = deduplicate_entries(prettify(filter_coverage(coverage, parse_html))).map(({ text, url, ranges }) => {
|
|
220
|
+
let coverage_per_stylesheet = deduplicate_entries(prettify(await filter_coverage(coverage))).map(({ text, url, ranges }) => {
|
|
216
221
|
function is_line_covered(line, start_offset) {
|
|
217
222
|
let end = start_offset + line.length;
|
|
218
223
|
let next_offset = end + 1;
|