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