@automattic/jetpack-critical-css-gen 1.0.0 → 1.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/CHANGELOG.md +16 -4
- package/build/browser-interface-iframe.d.ts +31 -0
- package/build/browser-interface-iframe.js +130 -0
- package/build/browser-interface-iframe.js.map +1 -0
- package/build/browser-interface-playwright.d.ts +53 -0
- package/build/browser-interface-playwright.js +94 -0
- package/build/browser-interface-playwright.js.map +1 -0
- package/build/browser-interface.d.ts +77 -0
- package/build/browser-interface.js +124 -0
- package/build/browser-interface.js.map +1 -0
- package/build/browser.d.ts +5 -0
- package/build/browser.js +6 -0
- package/build/browser.js.map +1 -0
- package/build/css-file-set.d.ts +100 -0
- package/build/css-file-set.js +210 -0
- package/build/css-file-set.js.map +1 -0
- package/build/errors.d.ts +101 -0
- package/build/errors.js +103 -0
- package/build/errors.js.map +1 -0
- package/build/generate-critical-css.d.ts +24 -0
- package/build/generate-critical-css.js +162 -0
- package/build/generate-critical-css.js.map +1 -0
- package/build/ignored-pseudo-elements.d.ts +8 -0
- package/build/ignored-pseudo-elements.js +35 -0
- package/build/ignored-pseudo-elements.js.map +1 -0
- package/build/minify-css.d.ts +11 -0
- package/build/minify-css.js +19 -0
- package/build/minify-css.js.map +1 -0
- package/build/object-promise-all.d.ts +12 -0
- package/build/object-promise-all.js +16 -0
- package/build/object-promise-all.js.map +1 -0
- package/build/playwright.d.ts +5 -0
- package/build/playwright.js +6 -0
- package/build/playwright.js.map +1 -0
- package/build/style-ast.d.ts +164 -0
- package/build/style-ast.js +540 -0
- package/build/style-ast.js.map +1 -0
- package/build/types.d.ts +14 -0
- package/build/types.js +2 -0
- package/build/types.js.map +1 -0
- package/package.json +4 -3
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { BrowserInterface } from './browser-interface.js';
|
|
2
|
+
import { StyleAST } from './style-ast.js';
|
|
3
|
+
import { FilterSpec } from './types.js';
|
|
4
|
+
type CSSFile = {
|
|
5
|
+
css: string;
|
|
6
|
+
ast: StyleAST;
|
|
7
|
+
pages: string[];
|
|
8
|
+
urls: string[];
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Represents a set of CSS files found on one or more HTML page. Automatically de-duplicates
|
|
12
|
+
* CSS files by URL and by content, and parses each into an Abstract Syntax Tree. Also tracks
|
|
13
|
+
* all errors that occur while loading or parsing CSS.
|
|
14
|
+
*/
|
|
15
|
+
export declare class CSSFileSet {
|
|
16
|
+
private browserInterface;
|
|
17
|
+
private knownUrls;
|
|
18
|
+
private cssFiles;
|
|
19
|
+
private errors;
|
|
20
|
+
private internalStyles;
|
|
21
|
+
constructor(browserInterface: BrowserInterface);
|
|
22
|
+
/**
|
|
23
|
+
* Add a set of CSS URLs from an HTML page to this set.
|
|
24
|
+
*
|
|
25
|
+
* @param {string} page - URL of the page the CSS URLs were found on.
|
|
26
|
+
* @param {object} cssIncludes - Included CSS Files. Keyed by URL.
|
|
27
|
+
*/
|
|
28
|
+
addMultiple(page: string, cssIncludes: {
|
|
29
|
+
[url: string]: {
|
|
30
|
+
media: string;
|
|
31
|
+
};
|
|
32
|
+
}): Promise<void>;
|
|
33
|
+
addInternalStyles(page: string, internalStyles: string): Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
* Add a CSS URL from an HTML page to this set.
|
|
36
|
+
*
|
|
37
|
+
* @param {string} page - URL of the page the CSS URL was found on.
|
|
38
|
+
* @param {string} cssUrl - The CSS file URL.
|
|
39
|
+
* @param {object} settings - Additional settings for the CSS file.
|
|
40
|
+
*/
|
|
41
|
+
add(page: string, cssUrl: string, settings?: {
|
|
42
|
+
[url: string]: string;
|
|
43
|
+
}): Promise<void>;
|
|
44
|
+
/**
|
|
45
|
+
* Collates an object describing the selectors found in the CSS files in this set, and which
|
|
46
|
+
* HTML page URLs include them (via CSS files)
|
|
47
|
+
*
|
|
48
|
+
* @return {object} - An object with selector text keys, each containing a Set of page URLs (strings)
|
|
49
|
+
*/
|
|
50
|
+
collateSelectorPages(): {
|
|
51
|
+
[selector: string]: Set<string>;
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Applies filters to the properties or atRules in each AST in this set of CSS files.
|
|
55
|
+
* Mutates each AST in-place.
|
|
56
|
+
*
|
|
57
|
+
* @param {FilterSpec} filters - Object containing property and atRule filter functions.
|
|
58
|
+
*/
|
|
59
|
+
applyFilters(filters: FilterSpec): void;
|
|
60
|
+
/**
|
|
61
|
+
* Returns a new AST which is pruned appropriately for the specified contentWindow, and the
|
|
62
|
+
* set of selectors that are worth keeping. (i.e.: appear above the fold).
|
|
63
|
+
*
|
|
64
|
+
* @param {Set<string>} usefulSelectors - Set of selectors to keep.
|
|
65
|
+
* @return {StyleAST[]} Array of pruned StyleAST objects.
|
|
66
|
+
*/
|
|
67
|
+
prunedAsts(usefulSelectors: Set<string>): StyleAST[];
|
|
68
|
+
/**
|
|
69
|
+
* Internal method: Store the specified css found at the cssUrl for an HTML page,
|
|
70
|
+
* de-duplicating CSS files by content along the way.
|
|
71
|
+
*
|
|
72
|
+
* @param {string} page - URL of HTML page this CSS file was found on.
|
|
73
|
+
* @param {string} cssUrl - URL of the CSS file.
|
|
74
|
+
* @param {string} css - Content of the CSS File.
|
|
75
|
+
*/
|
|
76
|
+
storeCss(page: string, cssUrl: string, css: string): void;
|
|
77
|
+
/**
|
|
78
|
+
* Internal method: Add an extra reference to a previously known CSS file found either
|
|
79
|
+
* on a new HTML page, or at a new URL.
|
|
80
|
+
*
|
|
81
|
+
* @param {string} page - URL of the page this CSS file was found on.
|
|
82
|
+
* @param {string} cssUrl - URL of the CSS File.
|
|
83
|
+
* @param {object} matchingFile - Internal CSS File object.
|
|
84
|
+
*/
|
|
85
|
+
addExtraReference(page: string, cssUrl: string, matchingFile: CSSFile): void;
|
|
86
|
+
/**
|
|
87
|
+
* Stores an error that occurred while fetching or parsing CSS at the given URL.
|
|
88
|
+
*
|
|
89
|
+
* @param {string} url - CSS URL that failed to fetch or parse.
|
|
90
|
+
* @param {Error} err - Error object describing the problem.
|
|
91
|
+
*/
|
|
92
|
+
storeError(url: string, err: Error): void;
|
|
93
|
+
/**
|
|
94
|
+
* Returns a list of errors that occurred while fetching or parsing these CSS files.
|
|
95
|
+
*
|
|
96
|
+
* @return {Error[]} - List of errors that occurred.
|
|
97
|
+
*/
|
|
98
|
+
getErrors(): Error[];
|
|
99
|
+
}
|
|
100
|
+
export {};
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import { HttpError, UnknownError, UrlError } from './errors.js';
|
|
2
|
+
import { StyleAST } from './style-ast.js';
|
|
3
|
+
// Maximum number of iterations when pruning unused variables.
|
|
4
|
+
const maxVarPruneIterations = 10;
|
|
5
|
+
/**
|
|
6
|
+
* Represents a set of CSS files found on one or more HTML page. Automatically de-duplicates
|
|
7
|
+
* CSS files by URL and by content, and parses each into an Abstract Syntax Tree. Also tracks
|
|
8
|
+
* all errors that occur while loading or parsing CSS.
|
|
9
|
+
*/
|
|
10
|
+
export class CSSFileSet {
|
|
11
|
+
constructor(browserInterface) {
|
|
12
|
+
this.browserInterface = browserInterface;
|
|
13
|
+
this.internalStyles = {};
|
|
14
|
+
this.knownUrls = {};
|
|
15
|
+
this.cssFiles = [];
|
|
16
|
+
this.errors = [];
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Add a set of CSS URLs from an HTML page to this set.
|
|
20
|
+
*
|
|
21
|
+
* @param {string} page - URL of the page the CSS URLs were found on.
|
|
22
|
+
* @param {object} cssIncludes - Included CSS Files. Keyed by URL.
|
|
23
|
+
*/
|
|
24
|
+
async addMultiple(page, cssIncludes) {
|
|
25
|
+
await Promise.all(Object.keys(cssIncludes).map(url => this.add(page, url, cssIncludes[url])));
|
|
26
|
+
}
|
|
27
|
+
async addInternalStyles(page, internalStyles) {
|
|
28
|
+
this.internalStyles[page] = StyleAST.parse(internalStyles);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Add a CSS URL from an HTML page to this set.
|
|
32
|
+
*
|
|
33
|
+
* @param {string} page - URL of the page the CSS URL was found on.
|
|
34
|
+
* @param {string} cssUrl - The CSS file URL.
|
|
35
|
+
* @param {object} settings - Additional settings for the CSS file.
|
|
36
|
+
*/
|
|
37
|
+
async add(page, cssUrl, settings = {}) {
|
|
38
|
+
// Add by reference if we already know this file.
|
|
39
|
+
if (Object.prototype.hasOwnProperty.call(this.knownUrls, cssUrl)) {
|
|
40
|
+
if (this.knownUrls[cssUrl] instanceof Error) {
|
|
41
|
+
// We already know this URL failed. Bail early.
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
this.addExtraReference(page, cssUrl, this.knownUrls[cssUrl]);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
// Try to load this URL.
|
|
48
|
+
try {
|
|
49
|
+
const response = await this.browserInterface.fetch(cssUrl, {}, 'css');
|
|
50
|
+
if (!response.ok) {
|
|
51
|
+
throw new HttpError({ code: response.status, url: cssUrl });
|
|
52
|
+
}
|
|
53
|
+
let css = await response.text();
|
|
54
|
+
// If there is an implied media query from the css's <link> tag, wrap the CSS in it.
|
|
55
|
+
if (settings.media) {
|
|
56
|
+
css = '@media ' + settings.media + ' {\n' + css + '\n}';
|
|
57
|
+
}
|
|
58
|
+
this.storeCss(page, cssUrl, css);
|
|
59
|
+
}
|
|
60
|
+
catch (err) {
|
|
61
|
+
let wrappedError = err;
|
|
62
|
+
// Wrap any unfamiliar fetch errors in an unknown error.
|
|
63
|
+
if (!(err instanceof UrlError)) {
|
|
64
|
+
wrappedError = new UnknownError({
|
|
65
|
+
url: cssUrl,
|
|
66
|
+
message: err.message,
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
this.storeError(cssUrl, wrappedError);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Collates an object describing the selectors found in the CSS files in this set, and which
|
|
74
|
+
* HTML page URLs include them (via CSS files)
|
|
75
|
+
*
|
|
76
|
+
* @return {object} - An object with selector text keys, each containing a Set of page URLs (strings)
|
|
77
|
+
*/
|
|
78
|
+
collateSelectorPages() {
|
|
79
|
+
const selectors = {};
|
|
80
|
+
for (const file of this.cssFiles) {
|
|
81
|
+
file.ast.forEachSelector(selector => {
|
|
82
|
+
if (!selectors[selector]) {
|
|
83
|
+
selectors[selector] = new Set();
|
|
84
|
+
}
|
|
85
|
+
file.pages.forEach(pageUrl => selectors[selector].add(pageUrl));
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
return selectors;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Applies filters to the properties or atRules in each AST in this set of CSS files.
|
|
92
|
+
* Mutates each AST in-place.
|
|
93
|
+
*
|
|
94
|
+
* @param {FilterSpec} filters - Object containing property and atRule filter functions.
|
|
95
|
+
*/
|
|
96
|
+
applyFilters(filters) {
|
|
97
|
+
for (const file of this.cssFiles) {
|
|
98
|
+
file.ast.applyFilters(filters);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Returns a new AST which is pruned appropriately for the specified contentWindow, and the
|
|
103
|
+
* set of selectors that are worth keeping. (i.e.: appear above the fold).
|
|
104
|
+
*
|
|
105
|
+
* @param {Set<string>} usefulSelectors - Set of selectors to keep.
|
|
106
|
+
* @return {StyleAST[]} Array of pruned StyleAST objects.
|
|
107
|
+
*/
|
|
108
|
+
prunedAsts(usefulSelectors) {
|
|
109
|
+
// Perform basic pruning.
|
|
110
|
+
let asts = this.cssFiles.map(file => {
|
|
111
|
+
return file.ast.pruned(usefulSelectors);
|
|
112
|
+
});
|
|
113
|
+
const internallyUsedVariables = new Set();
|
|
114
|
+
Object.values(this.internalStyles).reduce((set, ast) => {
|
|
115
|
+
ast.getUsedVariables().forEach(v => set.add(v));
|
|
116
|
+
return set;
|
|
117
|
+
}, internallyUsedVariables);
|
|
118
|
+
// Repeatedly prune unused variables (up to maxVarPruneIterations), to catch vars which are
|
|
119
|
+
// only used to define other vars which aren't used.
|
|
120
|
+
let prevUsedVariables;
|
|
121
|
+
for (let i = 0; i < maxVarPruneIterations; i++) {
|
|
122
|
+
// Gather the set of used variables.
|
|
123
|
+
const usedVariables = asts.reduce((set, ast) => {
|
|
124
|
+
ast.getUsedVariables().forEach(v => set.add(v));
|
|
125
|
+
return set;
|
|
126
|
+
}, new Set());
|
|
127
|
+
// If the number of used vars hasn't changed since last iteration, stop early.
|
|
128
|
+
if (prevUsedVariables && prevUsedVariables.size === usedVariables.size) {
|
|
129
|
+
break;
|
|
130
|
+
}
|
|
131
|
+
// Prune unused variables, keep a sum of pruned variables.
|
|
132
|
+
const prunedCount = asts.reduce((sum, ast) => {
|
|
133
|
+
sum += ast.pruneUnusedVariables(new Set([...usedVariables, ...internallyUsedVariables]));
|
|
134
|
+
return sum;
|
|
135
|
+
}, 0);
|
|
136
|
+
// If no variables were pruned this iteration, stop early.
|
|
137
|
+
if (prunedCount === 0) {
|
|
138
|
+
break;
|
|
139
|
+
}
|
|
140
|
+
prevUsedVariables = usedVariables;
|
|
141
|
+
}
|
|
142
|
+
// Find all fonts used across all ASTs, and prune all that are not referenced.
|
|
143
|
+
const fontWhitelist = asts.reduce((set, ast) => {
|
|
144
|
+
ast.getUsedFontFamilies().forEach(font => set.add(font));
|
|
145
|
+
return set;
|
|
146
|
+
}, new Set());
|
|
147
|
+
// Remove any fonts that aren't used above the fold.
|
|
148
|
+
asts.forEach(ast => ast.pruneNonCriticalFonts(fontWhitelist));
|
|
149
|
+
// Throw away any ASTs without rules.
|
|
150
|
+
asts = asts.filter(ast => ast.ruleCount() > 0);
|
|
151
|
+
return asts;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Internal method: Store the specified css found at the cssUrl for an HTML page,
|
|
155
|
+
* de-duplicating CSS files by content along the way.
|
|
156
|
+
*
|
|
157
|
+
* @param {string} page - URL of HTML page this CSS file was found on.
|
|
158
|
+
* @param {string} cssUrl - URL of the CSS file.
|
|
159
|
+
* @param {string} css - Content of the CSS File.
|
|
160
|
+
*/
|
|
161
|
+
storeCss(page, cssUrl, css) {
|
|
162
|
+
// De-duplicate css contents in case cache busters in URLs or WAFs, etc confound URL de-duplication.
|
|
163
|
+
const matchingFile = this.cssFiles.find(file => file.css === css);
|
|
164
|
+
if (matchingFile) {
|
|
165
|
+
this.addExtraReference(page, cssUrl, matchingFile);
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
// Parse the CSS into an AST.
|
|
169
|
+
const ast = StyleAST.parse(css);
|
|
170
|
+
// Make sure relative URLs in the AST are absolute.
|
|
171
|
+
ast.absolutifyUrls(cssUrl);
|
|
172
|
+
const file = { css, ast, pages: [page], urls: [cssUrl] };
|
|
173
|
+
this.knownUrls[cssUrl] = file;
|
|
174
|
+
this.cssFiles.push(file);
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Internal method: Add an extra reference to a previously known CSS file found either
|
|
178
|
+
* on a new HTML page, or at a new URL.
|
|
179
|
+
*
|
|
180
|
+
* @param {string} page - URL of the page this CSS file was found on.
|
|
181
|
+
* @param {string} cssUrl - URL of the CSS File.
|
|
182
|
+
* @param {object} matchingFile - Internal CSS File object.
|
|
183
|
+
*/
|
|
184
|
+
addExtraReference(page, cssUrl, matchingFile) {
|
|
185
|
+
this.knownUrls[cssUrl] = matchingFile;
|
|
186
|
+
matchingFile.pages.push(page);
|
|
187
|
+
if (!matchingFile.urls.includes(cssUrl)) {
|
|
188
|
+
matchingFile.urls.push(cssUrl);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Stores an error that occurred while fetching or parsing CSS at the given URL.
|
|
193
|
+
*
|
|
194
|
+
* @param {string} url - CSS URL that failed to fetch or parse.
|
|
195
|
+
* @param {Error} err - Error object describing the problem.
|
|
196
|
+
*/
|
|
197
|
+
storeError(url, err) {
|
|
198
|
+
this.knownUrls[url] = err;
|
|
199
|
+
this.errors.push(err);
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Returns a list of errors that occurred while fetching or parsing these CSS files.
|
|
203
|
+
*
|
|
204
|
+
* @return {Error[]} - List of errors that occurred.
|
|
205
|
+
*/
|
|
206
|
+
getErrors() {
|
|
207
|
+
return this.errors;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
//# sourceMappingURL=css-file-set.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"css-file-set.js","sourceRoot":"","sources":["../src/css-file-set.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAChE,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAG1C,8DAA8D;AAC9D,MAAM,qBAAqB,GAAG,EAAE,CAAC;AASjC;;;;GAIG;AACH,MAAM,OAAO,UAAU;IAMtB,YAAqB,gBAAkC;QAAlC,qBAAgB,GAAhB,gBAAgB,CAAkB;QAF/C,mBAAc,GAAkC,EAAE,CAAC;QAG1D,IAAI,CAAC,SAAS,GAAG,EAAE,CAAC;QACpB,IAAI,CAAC,QAAQ,GAAG,EAAE,CAAC;QACnB,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC;IAClB,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,WAAW,CAAE,IAAY,EAAE,WAAmD;QACnF,MAAM,OAAO,CAAC,GAAG,CAChB,MAAM,CAAC,IAAI,CAAE,WAAW,CAAE,CAAC,GAAG,CAAE,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG,CAAE,IAAI,EAAE,GAAG,EAAE,WAAW,CAAE,GAAG,CAAE,CAAE,CAAE,CAClF,CAAC;IACH,CAAC;IAED,KAAK,CAAC,iBAAiB,CAAE,IAAY,EAAE,cAAsB;QAC5D,IAAI,CAAC,cAAc,CAAE,IAAI,CAAE,GAAG,QAAQ,CAAC,KAAK,CAAE,cAAc,CAAE,CAAC;IAChE,CAAC;IAED;;;;;;O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AS,CAAE,MAAM,CAAE,GAAG,YAAY,CAAC;QACxC,YAAY,CAAC,KAAK,CAAC,IAAI,CAAE,IAAI,CAAE,CAAC;QAEhC,IAAK,CAAE,YAAY,CAAC,IAAI,CAAC,QAAQ,CAAE,MAAM,CAAE,EAAG;YAC7C,YAAY,CAAC,IAAI,CAAC,IAAI,CAAE,MAAM,CAAE,CAAC;SACjC;IACF,CAAC;IAED;;;;;OAKG;IACH,UAAU,CAAE,GAAW,EAAE,GAAU;QAClC,IAAI,CAAC,SAAS,CAAE,GAAG,CAAE,GAAG,GAAG,CAAC;QAC5B,IAAI,CAAC,MAAM,CAAC,IAAI,CAAE,GAAG,CAAE,CAAC;IACzB,CAAC;IAED;;;;OAIG;IACH,SAAS;QACR,OAAO,IAAI,CAAC,MAAM,CAAC;IACpB,CAAC;CACD"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
export type MetaType = {
|
|
2
|
+
[key: string]: string | number;
|
|
3
|
+
};
|
|
4
|
+
export type ErrorSpec = {
|
|
5
|
+
message: string;
|
|
6
|
+
type: string;
|
|
7
|
+
meta: MetaType;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* SuccessTargetError - Indicates that insufficient pages loaded to meet
|
|
11
|
+
* a specified success target. Contains information about each error that caused
|
|
12
|
+
* problems and the URLs they affect.
|
|
13
|
+
*/
|
|
14
|
+
export declare class SuccessTargetError extends Error {
|
|
15
|
+
readonly isSuccessTargetError: boolean;
|
|
16
|
+
readonly urlErrors: {
|
|
17
|
+
[url: string]: ErrorSpec;
|
|
18
|
+
};
|
|
19
|
+
constructor(urlErrors: {
|
|
20
|
+
[url: string]: UrlError;
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Base class for URL specific errors, which can be bundled inside a
|
|
25
|
+
* SuccessTargetError.
|
|
26
|
+
*/
|
|
27
|
+
export declare class UrlError extends Error {
|
|
28
|
+
readonly type: string;
|
|
29
|
+
readonly meta: MetaType;
|
|
30
|
+
constructor(type: string, meta: MetaType, message: string);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* HttpError - Indicates an HTTP request has failed with a non-2xx status code.
|
|
34
|
+
*/
|
|
35
|
+
export declare class HttpError extends UrlError {
|
|
36
|
+
constructor({ url, code }: {
|
|
37
|
+
url: string;
|
|
38
|
+
code: number;
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* UnknownError - Indicates that fetch() threw an error with its own error string.
|
|
43
|
+
* Contains a raw (and difficult to translate) error message generated by fetch.
|
|
44
|
+
*/
|
|
45
|
+
export declare class UnknownError extends UrlError {
|
|
46
|
+
constructor({ url, message }: {
|
|
47
|
+
url: string;
|
|
48
|
+
message: string;
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* CrossDomainError - Indicates that a requested URL failed due to CORS / security
|
|
53
|
+
* limitations imposed by the browser.
|
|
54
|
+
*/
|
|
55
|
+
export declare class CrossDomainError extends UrlError {
|
|
56
|
+
constructor({ url }: {
|
|
57
|
+
url: string;
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* LoadTimeoutError - Indicates that an HTTP request failed due to a timeout.
|
|
62
|
+
*/
|
|
63
|
+
export declare class LoadTimeoutError extends UrlError {
|
|
64
|
+
constructor({ url }: {
|
|
65
|
+
url: string;
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* RedirectError - Indicates that a requested URL failed due to an HTTP redirection of that url.
|
|
70
|
+
*/
|
|
71
|
+
export declare class RedirectError extends UrlError {
|
|
72
|
+
constructor({ url, redirectUrl }: {
|
|
73
|
+
url: string;
|
|
74
|
+
redirectUrl: string;
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* UrlVerifyError - Indicates that a provided BrowserInterface verifyUrl
|
|
79
|
+
* callback returned false for a page which was otherwise loaded successfully.
|
|
80
|
+
*/
|
|
81
|
+
export declare class UrlVerifyError extends UrlError {
|
|
82
|
+
constructor({ url }: {
|
|
83
|
+
url: string;
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* EmptyCSSError - Indicates that a requested URL does not have any CSS in its external style sheet(s) and therefore Critical CSS could not be generated.
|
|
88
|
+
*/
|
|
89
|
+
export declare class EmptyCSSError extends UrlError {
|
|
90
|
+
constructor({ url }: {
|
|
91
|
+
url: string;
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* XFrameDenyError - Indicates that a requested URL failed due to x-frame-options deny configuration
|
|
96
|
+
*/
|
|
97
|
+
export declare class XFrameDenyError extends UrlError {
|
|
98
|
+
constructor({ url }: {
|
|
99
|
+
url: any;
|
|
100
|
+
});
|
|
101
|
+
}
|
package/build/errors.js
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SuccessTargetError - Indicates that insufficient pages loaded to meet
|
|
3
|
+
* a specified success target. Contains information about each error that caused
|
|
4
|
+
* problems and the URLs they affect.
|
|
5
|
+
*/
|
|
6
|
+
export class SuccessTargetError extends Error {
|
|
7
|
+
constructor(urlErrors) {
|
|
8
|
+
super('Insufficient pages loaded to meet success target. Errors:\n' +
|
|
9
|
+
Object.values(urlErrors)
|
|
10
|
+
.map(e => e.message)
|
|
11
|
+
.join('\n'));
|
|
12
|
+
// Mark this as a SuccessTargetError in an easy way for other code to check.
|
|
13
|
+
this.isSuccessTargetError = true;
|
|
14
|
+
// Convert any Error object into reliable {message,type,meta} objects.
|
|
15
|
+
this.urlErrors = {};
|
|
16
|
+
for (const [url, errorObject] of Object.entries(urlErrors)) {
|
|
17
|
+
this.urlErrors[url] = {
|
|
18
|
+
message: errorObject.message,
|
|
19
|
+
type: errorObject.type || 'UnknownError',
|
|
20
|
+
meta: errorObject.meta || {},
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Base class for URL specific errors, which can be bundled inside a
|
|
27
|
+
* SuccessTargetError.
|
|
28
|
+
*/
|
|
29
|
+
export class UrlError extends Error {
|
|
30
|
+
constructor(type, meta, message) {
|
|
31
|
+
super(message);
|
|
32
|
+
this.type = type;
|
|
33
|
+
this.meta = meta;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* HttpError - Indicates an HTTP request has failed with a non-2xx status code.
|
|
38
|
+
*/
|
|
39
|
+
export class HttpError extends UrlError {
|
|
40
|
+
constructor({ url, code }) {
|
|
41
|
+
super('HttpError', { url, code }, `HTTP error ${code} on URL ${url}`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* UnknownError - Indicates that fetch() threw an error with its own error string.
|
|
46
|
+
* Contains a raw (and difficult to translate) error message generated by fetch.
|
|
47
|
+
*/
|
|
48
|
+
export class UnknownError extends UrlError {
|
|
49
|
+
constructor({ url, message }) {
|
|
50
|
+
super('UnknownError', { url, message }, `Error while loading ${url}: ${message}`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* CrossDomainError - Indicates that a requested URL failed due to CORS / security
|
|
55
|
+
* limitations imposed by the browser.
|
|
56
|
+
*/
|
|
57
|
+
export class CrossDomainError extends UrlError {
|
|
58
|
+
constructor({ url }) {
|
|
59
|
+
super('CrossDomainError', { url }, `Failed to fetch cross-domain content at ${url}`);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* LoadTimeoutError - Indicates that an HTTP request failed due to a timeout.
|
|
64
|
+
*/
|
|
65
|
+
export class LoadTimeoutError extends UrlError {
|
|
66
|
+
constructor({ url }) {
|
|
67
|
+
super('LoadTimeoutError', { url }, `Timeout while reading ${url}`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* RedirectError - Indicates that a requested URL failed due to an HTTP redirection of that url.
|
|
72
|
+
*/
|
|
73
|
+
export class RedirectError extends UrlError {
|
|
74
|
+
constructor({ url, redirectUrl }) {
|
|
75
|
+
super('RedirectError', { url, redirectUrl }, `Failed to process ${url} because it redirects to ${redirectUrl} which cannot be verified`);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* UrlVerifyError - Indicates that a provided BrowserInterface verifyUrl
|
|
80
|
+
* callback returned false for a page which was otherwise loaded successfully.
|
|
81
|
+
*/
|
|
82
|
+
export class UrlVerifyError extends UrlError {
|
|
83
|
+
constructor({ url }) {
|
|
84
|
+
super('UrlVerifyError', { url }, `Failed to verify page at ${url}`);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* EmptyCSSError - Indicates that a requested URL does not have any CSS in its external style sheet(s) and therefore Critical CSS could not be generated.
|
|
89
|
+
*/
|
|
90
|
+
export class EmptyCSSError extends UrlError {
|
|
91
|
+
constructor({ url }) {
|
|
92
|
+
super('EmptyCSSError', { url }, `The ${url} does not have any CSS in its external style sheet(s).`);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* XFrameDenyError - Indicates that a requested URL failed due to x-frame-options deny configuration
|
|
97
|
+
*/
|
|
98
|
+
export class XFrameDenyError extends UrlError {
|
|
99
|
+
constructor({ url }) {
|
|
100
|
+
super('XFrameDenyError', { url }, `Failed to load ${url} due to the "X-Frame-Options: DENY" header`);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAUA;;;;GAIG;AACH,MAAM,OAAO,kBAAmB,SAAQ,KAAK;IAI5C,YAAa,SAAwC;QACpD,KAAK,CACJ,6DAA6D;YAC5D,MAAM,CAAC,MAAM,CAAE,SAAS,CAAE;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';
|
|
3
|
+
/**
|
|
4
|
+
* Generates critical CSS for the given URLs and viewports.
|
|
5
|
+
*
|
|
6
|
+
* @param {object} root0 - The options object
|
|
7
|
+
* @param {BrowserInterface} root0.browserInterface - Interface to interact with the browser
|
|
8
|
+
* @param {Function} root0.progressCallback - Optional callback function to report progress
|
|
9
|
+
* @param {string[]} root0.urls - Array of URLs to generate critical CSS for
|
|
10
|
+
* @param {Viewport[]} root0.viewports - Array of viewport sizes to consider
|
|
11
|
+
* @param {FilterSpec} root0.filters - Optional filters to apply to the CSS
|
|
12
|
+
* @param {number} root0.successRatio - Ratio of successful URLs required (default: 1)
|
|
13
|
+
* @param {number} root0.maxPages - Maximum number of pages to process (default: 10)
|
|
14
|
+
* @return {Promise<[string, Error[]]>} A promise that resolves to an array containing the critical CSS string and an array of errors.
|
|
15
|
+
*/
|
|
16
|
+
export declare function generateCriticalCSS({ browserInterface, progressCallback, urls, viewports, filters, successRatio, maxPages, }: {
|
|
17
|
+
browserInterface: BrowserInterface;
|
|
18
|
+
progressCallback?: (step: number, total: number) => void;
|
|
19
|
+
urls: string[];
|
|
20
|
+
viewports: Viewport[];
|
|
21
|
+
filters?: FilterSpec;
|
|
22
|
+
successRatio?: number;
|
|
23
|
+
maxPages?: number;
|
|
24
|
+
}): Promise<[string, Error[]]>;
|