@pi-r/chrome 0.7.2 → 0.7.3
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 +52 -11
- package/package.json +5 -5
package/index.js
CHANGED
|
@@ -14,6 +14,8 @@ const CACHE_LOCALFILE = new Map();
|
|
|
14
14
|
const CACHE_QUERY = new Map();
|
|
15
15
|
const CACHE_SELECTOR = new Map();
|
|
16
16
|
const CACHE_ETAG = new Map();
|
|
17
|
+
const CACHE_CONTENT = new Map();
|
|
18
|
+
const CACHE_FORMAT = new Map();
|
|
17
19
|
const CACHE_DATASET = {};
|
|
18
20
|
const CACHE_ATRULES = {};
|
|
19
21
|
let CACHE_TOTAL = 0;
|
|
@@ -934,6 +936,8 @@ class ChromeDocument extends Document {
|
|
|
934
936
|
CACHE_QUERY.clear();
|
|
935
937
|
CACHE_SELECTOR.clear();
|
|
936
938
|
CACHE_ETAG.clear();
|
|
939
|
+
CACHE_CONTENT.clear();
|
|
940
|
+
CACHE_FORMAT.clear();
|
|
937
941
|
}
|
|
938
942
|
return result + (parent && result > 0 ? await super.purgeMemory(typeof parent === 'number' && parent > 0 ? parent : percent, limit, true) : 0);
|
|
939
943
|
}
|
|
@@ -961,16 +965,26 @@ class ChromeDocument extends Document {
|
|
|
961
965
|
const { etag, initialValue } = htmlFile;
|
|
962
966
|
let buffer;
|
|
963
967
|
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 && (!(0, types_1.isArray)(item.from) || item.from.includes('style'))))) {
|
|
964
|
-
|
|
965
|
-
|
|
968
|
+
const isValid = (item) => !!item.localUri && item !== htmlFile && !item.invalid;
|
|
969
|
+
for (const item of fetched) {
|
|
970
|
+
if (item.etag && !item.content && isValid(item)) {
|
|
966
971
|
CACHE_ETAG.set(item.localUri, item.etag);
|
|
967
972
|
}
|
|
968
|
-
}
|
|
973
|
+
}
|
|
974
|
+
for (const item of instance.assets) {
|
|
975
|
+
if (isValid(item)) {
|
|
976
|
+
if (item.content) {
|
|
977
|
+
CACHE_CONTENT.set(item.localUri, item.content);
|
|
978
|
+
}
|
|
979
|
+
if (item.format) {
|
|
980
|
+
CACHE_FORMAT.set(item.localUri, item.format.toString());
|
|
981
|
+
}
|
|
982
|
+
}
|
|
983
|
+
}
|
|
969
984
|
break;
|
|
970
985
|
}
|
|
971
986
|
try {
|
|
972
|
-
|
|
973
|
-
fs.writeFileSync(localUri, buffer, (0, types_1.getEncoding)(encoding));
|
|
987
|
+
fs.writeFileSync(htmlFile.localUri, buffer, (0, types_1.getEncoding)(htmlFile.encoding));
|
|
974
988
|
htmlFile.buffer = buffer;
|
|
975
989
|
htmlFile.sourceUTF8 = undefined;
|
|
976
990
|
}
|
|
@@ -978,12 +992,39 @@ class ChromeDocument extends Document {
|
|
|
978
992
|
break;
|
|
979
993
|
}
|
|
980
994
|
}
|
|
981
|
-
const
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
995
|
+
const wasModified = (item) => {
|
|
996
|
+
const localUri = item.localUri;
|
|
997
|
+
let result = fetched.includes(item) || Array.isArray(item.from) && item.from.includes('style');
|
|
998
|
+
if (localUri) {
|
|
999
|
+
if (item.etag && !item.content && !item.invalid) {
|
|
1000
|
+
CACHE_ETAG.set(localUri, item.etag);
|
|
1001
|
+
}
|
|
1002
|
+
else {
|
|
1003
|
+
CACHE_ETAG.delete(localUri);
|
|
1004
|
+
}
|
|
1005
|
+
if (!item.content || item.invalid) {
|
|
1006
|
+
CACHE_CONTENT.delete(localUri);
|
|
1007
|
+
}
|
|
1008
|
+
else if (CACHE_CONTENT.get(localUri) !== item.content || !item.inlineContent && !Document.isPath(localUri)) {
|
|
1009
|
+
CACHE_CONTENT.set(localUri, item.content);
|
|
1010
|
+
result = true;
|
|
1011
|
+
}
|
|
1012
|
+
if (!item.format || item.invalid) {
|
|
1013
|
+
CACHE_FORMAT.delete(localUri);
|
|
1014
|
+
}
|
|
1015
|
+
else {
|
|
1016
|
+
const format = item.format.toString();
|
|
1017
|
+
if (CACHE_FORMAT.get(localUri) !== format || !item.inlineContent && !Document.isPath(localUri)) {
|
|
1018
|
+
CACHE_FORMAT.set(localUri, format);
|
|
1019
|
+
result = true;
|
|
1020
|
+
}
|
|
1021
|
+
}
|
|
1022
|
+
}
|
|
1023
|
+
return result || this.copiedAssets.includes(item) && (!(0, types_1.isEmpty)(item.bundleId) || !(0, types_1.isEmpty)(item.trailingContent));
|
|
1024
|
+
};
|
|
1025
|
+
const js = instance.jsFiles.filter(item => wasModified(item) || !!item.imports);
|
|
1026
|
+
const css = instance.cssFiles.filter(wasModified);
|
|
1027
|
+
const svg = instance.svgFiles.filter(wasModified);
|
|
987
1028
|
if (js.length || css.length || svg.length) {
|
|
988
1029
|
instance.jsFiles = js;
|
|
989
1030
|
instance.cssFiles = css;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-r/chrome",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.3",
|
|
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.9.
|
|
24
|
-
"@e-mc/core": "^0.9.
|
|
25
|
-
"@e-mc/document": "^0.9.
|
|
26
|
-
"@e-mc/types": "^0.9.
|
|
23
|
+
"@e-mc/cloud": "^0.9.6",
|
|
24
|
+
"@e-mc/core": "^0.9.6",
|
|
25
|
+
"@e-mc/document": "^0.9.6",
|
|
26
|
+
"@e-mc/types": "^0.9.6"
|
|
27
27
|
}
|
|
28
28
|
}
|