fetch-css 4.0.12 → 4.0.13
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/README.md +1 -1
- package/index.js +13 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -22,7 +22,7 @@ const [{css}] = await fetchCss([{crx: "hlepfoohegkhhmjieoechaddaejaokhf"}]);
|
|
|
22
22
|
|
|
23
23
|
- `sources`: *Array* Array of source objects
|
|
24
24
|
- `source`: *Object*
|
|
25
|
-
- `url`: *string* An absolute URL pointing to either a website or directly to a CSS or JS file (to extract inlined CSS strings from)
|
|
25
|
+
- `url`: *string* or *Array* An absolute URL pointing to either a website or directly to a CSS or JS file (to extract inlined CSS strings from)
|
|
26
26
|
- `fetchOpts`: *Object* Options passed to [fetch](https://github.com/npm/make-fetch-happen#fetch)
|
|
27
27
|
- `crx`: *string* A Chrome extension id
|
|
28
28
|
- `contentScriptsOnly`: *boolean* Whether to pull only content scripts from a extension. Default: `false`
|
package/index.js
CHANGED
|
@@ -185,16 +185,24 @@ export default async function fetchCss(sources) { // eslint-disable-line import/
|
|
|
185
185
|
const sourceResponses = await Promise.all(sources.map(source => {
|
|
186
186
|
if (!source.url) return null;
|
|
187
187
|
const {pathname} = new URL(source.url);
|
|
188
|
-
|
|
188
|
+
if (pathname.endsWith(".css") || pathname.endsWith(".js")) return null;
|
|
189
|
+
|
|
190
|
+
if (Array.isArray(source.url)) {
|
|
191
|
+
return source.url.map(url => doFetch(url, source.fetchOpts));
|
|
192
|
+
} else {
|
|
193
|
+
return doFetch(source.url, source.fetchOpts);
|
|
194
|
+
}
|
|
189
195
|
}));
|
|
190
196
|
|
|
191
197
|
for (const [index, res] of Object.entries(sourceResponses)) {
|
|
192
198
|
const source = sources[index];
|
|
193
199
|
if (res) {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
200
|
+
for (const r of Array.isArray(res) ? res : [res]) {
|
|
201
|
+
validateStatus(r, source.url, source.strict);
|
|
202
|
+
const [styleUrls, styleTags] = await extract(r);
|
|
203
|
+
source.urls.push(...styleUrls);
|
|
204
|
+
source.styleTags.push(...styleTags);
|
|
205
|
+
}
|
|
198
206
|
} else if (source.url) {
|
|
199
207
|
source.urls = [source.url];
|
|
200
208
|
}
|