single-file-core 1.0.17 → 1.0.18

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/single-file-core.js +27 -25
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "single-file-core",
3
- "version": "1.0.17",
3
+ "version": "1.0.18",
4
4
  "description": "SingleFile Core",
5
5
  "author": "Gildas Lormeau",
6
6
  "license": "AGPL-3.0-or-later",
@@ -1620,33 +1620,35 @@ class ProcessorHelper {
1620
1620
  const imports = getImportFunctions(stylesheet);
1621
1621
  await Promise.all(imports.map(async node => {
1622
1622
  const urlNode = cssTree.find(node, node => node.type == "Url") || cssTree.find(node, node => node.type == "String");
1623
- let resourceURL = normalizeURL(urlNode.value);
1624
- if (!testIgnoredPath(resourceURL) && testValidPath(resourceURL)) {
1625
- urlNode.value = util.EMPTY_RESOURCE;
1626
- try {
1627
- resourceURL = util.resolveURL(resourceURL, baseURI);
1628
- } catch (error) {
1629
- // ignored
1630
- }
1631
- if (testValidURL(resourceURL) && !importedStyleSheets.has(resourceURL)) {
1632
- const content = await getStylesheetContent(resourceURL);
1633
- resourceURL = content.resourceURL;
1634
- content.data = getUpdatedResourceContent(resourceURL, content, options);
1635
- if (content.data && content.data.match(/^<!doctype /i)) {
1636
- content.data = "";
1637
- }
1638
- const mediaQueryListNode = cssTree.find(node, node => node.type == "MediaQueryList");
1639
- if (mediaQueryListNode) {
1640
- content.data = wrapMediaQuery(content.data, cssTree.generate(mediaQueryListNode));
1623
+ if (urlNode) {
1624
+ let resourceURL = normalizeURL(urlNode.value);
1625
+ if (!testIgnoredPath(resourceURL) && testValidPath(resourceURL)) {
1626
+ urlNode.value = util.EMPTY_RESOURCE;
1627
+ try {
1628
+ resourceURL = util.resolveURL(resourceURL, baseURI);
1629
+ } catch (error) {
1630
+ // ignored
1641
1631
  }
1642
- const importedStylesheet = cssTree.parse(content.data, { context: "stylesheet", parseCustomProperty: true });
1643
- const ancestorStyleSheets = new Set(importedStyleSheets);
1644
- ancestorStyleSheets.add(resourceURL);
1645
- await ProcessorHelper.resolveImportURLs(importedStylesheet, resourceURL, options, workStylesheet, ancestorStyleSheets);
1646
- for (let keyName of Object.keys(importedStylesheet)) {
1647
- node[keyName] = importedStylesheet[keyName];
1632
+ if (testValidURL(resourceURL) && !importedStyleSheets.has(resourceURL)) {
1633
+ const content = await getStylesheetContent(resourceURL);
1634
+ resourceURL = content.resourceURL;
1635
+ content.data = getUpdatedResourceContent(resourceURL, content, options);
1636
+ if (content.data && content.data.match(/^<!doctype /i)) {
1637
+ content.data = "";
1638
+ }
1639
+ const mediaQueryListNode = cssTree.find(node, node => node.type == "MediaQueryList");
1640
+ if (mediaQueryListNode) {
1641
+ content.data = wrapMediaQuery(content.data, cssTree.generate(mediaQueryListNode));
1642
+ }
1643
+ const importedStylesheet = cssTree.parse(content.data, { context: "stylesheet", parseCustomProperty: true });
1644
+ const ancestorStyleSheets = new Set(importedStyleSheets);
1645
+ ancestorStyleSheets.add(resourceURL);
1646
+ await ProcessorHelper.resolveImportURLs(importedStylesheet, resourceURL, options, workStylesheet, ancestorStyleSheets);
1647
+ for (let keyName of Object.keys(importedStylesheet)) {
1648
+ node[keyName] = importedStylesheet[keyName];
1649
+ }
1650
+ importFound = true;
1648
1651
  }
1649
- importFound = true;
1650
1652
  }
1651
1653
  }
1652
1654
  }));