@pi-r/chrome 0.5.4 → 0.5.5
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/index.js +57 -9
- package/package.json +5 -5
package/index.js
CHANGED
|
@@ -13,6 +13,9 @@ const CACHE_DBRESULT = new Map();
|
|
|
13
13
|
const CACHE_LOCALFILE = new Map();
|
|
14
14
|
const CACHE_QUERY = new Map();
|
|
15
15
|
const CACHE_SELECTOR = new Map();
|
|
16
|
+
const CACHE_ETAG = new Map();
|
|
17
|
+
const CACHE_CONTENT = new Map();
|
|
18
|
+
const CACHE_FORMAT = new Map();
|
|
16
19
|
const CACHE_DATASET = {};
|
|
17
20
|
const CACHE_ATRULES = {};
|
|
18
21
|
let CACHE_TOTAL = 0;
|
|
@@ -973,6 +976,9 @@ class ChromeDocument extends Document {
|
|
|
973
976
|
}
|
|
974
977
|
CACHE_QUERY.clear();
|
|
975
978
|
CACHE_SELECTOR.clear();
|
|
979
|
+
CACHE_ETAG.clear();
|
|
980
|
+
CACHE_CONTENT.clear();
|
|
981
|
+
CACHE_FORMAT.clear();
|
|
976
982
|
}
|
|
977
983
|
return result + (parent && result > 0 ? await super.purgeMemory(typeof parent === 'number' && parent > 0 ? parent : percent, limit, true) : 0);
|
|
978
984
|
}
|
|
@@ -1000,12 +1006,27 @@ class ChromeDocument extends Document {
|
|
|
1000
1006
|
if (outHtml) {
|
|
1001
1007
|
const { etag, initialValue } = htmlFile;
|
|
1002
1008
|
let buffer;
|
|
1003
|
-
if (!initialValue || !(etag && initialValue.etag === etag && (buffer = initialValue.buffer)) || fetched.find(item => item.
|
|
1009
|
+
if (!initialValue || !(etag && initialValue.etag === etag && (buffer = initialValue.buffer)) || fetched.find(item => item !== htmlFile && item.etag && CACHE_ETAG.get(item.localUri) !== item.etag && (item.inlineContent || item.bundleReplace && (!Array.isArray(item.from) || item.from.includes('style'))))) {
|
|
1010
|
+
const isValid = (item) => !!item.localUri && item !== htmlFile && !item.invalid;
|
|
1011
|
+
for (const item of fetched) {
|
|
1012
|
+
if (item.etag && !item.content && isValid(item)) {
|
|
1013
|
+
CACHE_ETAG.set(item.localUri, item.etag);
|
|
1014
|
+
}
|
|
1015
|
+
}
|
|
1016
|
+
for (const item of instance.assets) {
|
|
1017
|
+
if (isValid(item)) {
|
|
1018
|
+
if (item.content) {
|
|
1019
|
+
CACHE_CONTENT.set(item.localUri, item.content);
|
|
1020
|
+
}
|
|
1021
|
+
if (item.format) {
|
|
1022
|
+
CACHE_FORMAT.set(item.localUri, item.format.toString());
|
|
1023
|
+
}
|
|
1024
|
+
}
|
|
1025
|
+
}
|
|
1004
1026
|
break;
|
|
1005
1027
|
}
|
|
1006
1028
|
try {
|
|
1007
|
-
|
|
1008
|
-
fs.writeFileSync(localUri, buffer, (0, types_1.getEncoding)(encoding));
|
|
1029
|
+
fs.writeFileSync(htmlFile.localUri, buffer, (0, types_1.getEncoding)(htmlFile.encoding));
|
|
1009
1030
|
htmlFile.buffer = buffer;
|
|
1010
1031
|
htmlFile.sourceUTF8 = undefined;
|
|
1011
1032
|
}
|
|
@@ -1013,12 +1034,39 @@ class ChromeDocument extends Document {
|
|
|
1013
1034
|
break;
|
|
1014
1035
|
}
|
|
1015
1036
|
}
|
|
1016
|
-
const
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1037
|
+
const wasModified = (item) => {
|
|
1038
|
+
const localUri = item.localUri;
|
|
1039
|
+
let result = fetched.includes(item) || Array.isArray(item.from) && item.from.includes('style');
|
|
1040
|
+
if (localUri) {
|
|
1041
|
+
if (item.etag && !item.content && !item.invalid) {
|
|
1042
|
+
CACHE_ETAG.set(localUri, item.etag);
|
|
1043
|
+
}
|
|
1044
|
+
else {
|
|
1045
|
+
CACHE_ETAG.delete(localUri);
|
|
1046
|
+
}
|
|
1047
|
+
if (!item.content || item.invalid) {
|
|
1048
|
+
CACHE_CONTENT.delete(localUri);
|
|
1049
|
+
}
|
|
1050
|
+
else if (CACHE_CONTENT.get(localUri) !== item.content || !item.inlineContent && !Document.isPath(localUri)) {
|
|
1051
|
+
CACHE_CONTENT.set(localUri, item.content);
|
|
1052
|
+
result = true;
|
|
1053
|
+
}
|
|
1054
|
+
if (!item.format || item.invalid) {
|
|
1055
|
+
CACHE_FORMAT.delete(localUri);
|
|
1056
|
+
}
|
|
1057
|
+
else {
|
|
1058
|
+
const format = item.format.toString();
|
|
1059
|
+
if (CACHE_FORMAT.get(localUri) !== format || !item.inlineContent && !Document.isPath(localUri)) {
|
|
1060
|
+
CACHE_FORMAT.set(localUri, format);
|
|
1061
|
+
result = true;
|
|
1062
|
+
}
|
|
1063
|
+
}
|
|
1064
|
+
}
|
|
1065
|
+
return result || this.copiedAssets.includes(item) && (!(0, types_1.isEmpty)(item.bundleId) || !(0, types_1.isEmpty)(item.trailingContent));
|
|
1066
|
+
};
|
|
1067
|
+
const js = instance.jsFiles.filter(item => wasModified(item) || !!item.imports);
|
|
1068
|
+
const css = instance.cssFiles.filter(wasModified);
|
|
1069
|
+
const svg = instance.svgFiles.filter(wasModified);
|
|
1022
1070
|
if (js.length || css.length || svg.length) {
|
|
1023
1071
|
instance.jsFiles = js;
|
|
1024
1072
|
instance.cssFiles = css;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-r/chrome",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.5",
|
|
4
4
|
"description": "Chrome document constructor for E-mc.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"publishConfig": {
|
|
@@ -20,9 +20,9 @@
|
|
|
20
20
|
"license": "MIT",
|
|
21
21
|
"homepage": "https://github.com/anpham6/pi-r#readme",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@e-mc/cloud": "^0.7.
|
|
24
|
-
"@e-mc/core": "^0.7.
|
|
25
|
-
"@e-mc/document": "^0.7.
|
|
26
|
-
"@e-mc/types": "^0.7.
|
|
23
|
+
"@e-mc/cloud": "^0.7.10",
|
|
24
|
+
"@e-mc/core": "^0.7.10",
|
|
25
|
+
"@e-mc/document": "^0.7.10",
|
|
26
|
+
"@e-mc/types": "^0.7.10"
|
|
27
27
|
}
|
|
28
28
|
}
|