@pi-r/chrome 0.7.1 → 0.7.2
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 +25 -17
- package/package.json +5 -5
package/index.js
CHANGED
|
@@ -13,6 +13,7 @@ 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();
|
|
16
17
|
const CACHE_DATASET = {};
|
|
17
18
|
const CACHE_ATRULES = {};
|
|
18
19
|
let CACHE_TOTAL = 0;
|
|
@@ -898,6 +899,7 @@ const getEndIndex = (match) => match.index + match[0].length;
|
|
|
898
899
|
const getRelativeURL = (file) => joinPath(file.moveTo, file.pathname, file.inlineFilename || file.filename) + (!file.static ? restoreSearchParams(file.url?.search) : '');
|
|
899
900
|
const errorHtml = ({ tagName, tagIndex = -1 }) => (0, types_1.errorMessage)('html', 'Location did not resolve', tagName.toLowerCase() + (tagIndex >= 0 ? ': ' + tagIndex : ''));
|
|
900
901
|
const errorDataSource = (value, hint) => (0, types_1.errorMessage)('data-source', value, hint);
|
|
902
|
+
const isHtmlOnly = (assets, items, htmlFile) => !items.find(item => item !== htmlFile && assets.includes(item));
|
|
901
903
|
class ChromeDocument extends Document {
|
|
902
904
|
static INTERNAL_ASSIGNUUID = "__assign__";
|
|
903
905
|
static INTERNAL_SERVERROOT = "__serverroot__";
|
|
@@ -931,33 +933,39 @@ class ChromeDocument extends Document {
|
|
|
931
933
|
}
|
|
932
934
|
CACHE_QUERY.clear();
|
|
933
935
|
CACHE_SELECTOR.clear();
|
|
936
|
+
CACHE_ETAG.clear();
|
|
934
937
|
}
|
|
935
938
|
return result + (parent && result > 0 ? await super.purgeMemory(typeof parent === 'number' && parent > 0 ? parent : percent, limit, true) : 0);
|
|
936
939
|
}
|
|
937
940
|
static async finalize(instance) {
|
|
938
941
|
if (instance.aborted) {
|
|
939
|
-
return
|
|
942
|
+
return (0, types_1.createAbortError)(true);
|
|
940
943
|
}
|
|
941
|
-
const
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
const outHtml = htmlFile && !isIgnored(htmlFile, true);
|
|
945
|
-
if (db && await db.commit()) {
|
|
946
|
-
db.writeTimeElapsed('DB', ["Transactions were committed", db.moduleName], processing.startTime, { ...Document.LOG_STYLE_SUCCESS, type: 65536 });
|
|
944
|
+
const startTime = process.hrtime();
|
|
945
|
+
if (instance.Db && await instance.Db.commit()) {
|
|
946
|
+
instance.Db.writeTimeElapsed('DB', ["Transactions were committed", instance.Db.moduleName], startTime, { ...Document.LOG_STYLE_SUCCESS, type: 65536 });
|
|
947
947
|
}
|
|
948
|
+
const productionRelease = !!instance.productionRelease;
|
|
949
|
+
const processing = { host: this, startTime, hashed: new Set(), contentMap: {}, bufferMap: {}, cacheMiss: [], productionRelease: productionRelease ? true : undefined };
|
|
950
|
+
const htmlFile = instance.htmlFile;
|
|
951
|
+
const outHtml = !!htmlFile && !isIgnored(htmlFile, true);
|
|
948
952
|
if (instance.dataSource.length === 0 && outHtml) {
|
|
949
953
|
const incremental = htmlFile.incremental ?? this.incremental;
|
|
950
954
|
if (incremental === 'etag' || incremental === 'exists') {
|
|
951
955
|
const fetched = this.fetchedAssets;
|
|
952
|
-
|
|
953
|
-
if (!productionRelease || instance.productionIncremental && (isHtmlOnly() || !fetched.find(item => item.hash))) {
|
|
956
|
+
if (!productionRelease || instance.productionIncremental && (isHtmlOnly(instance.assets, fetched, htmlFile) || !fetched.find(item => item.hash))) {
|
|
954
957
|
let hint = '';
|
|
955
958
|
switch (incremental) {
|
|
956
959
|
case 'etag': {
|
|
957
960
|
if (outHtml) {
|
|
958
961
|
const { etag, initialValue } = htmlFile;
|
|
959
962
|
let buffer;
|
|
960
|
-
if (!initialValue || !(etag && initialValue.etag === etag && (buffer = initialValue.buffer)) || fetched.find(item => item.bundleReplace && (!(0, types_1.isArray)(item.from) || item.from.includes('style')))) {
|
|
963
|
+
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
|
+
fetched.forEach(item => {
|
|
965
|
+
if (item.etag && item !== htmlFile && !item.invalid) {
|
|
966
|
+
CACHE_ETAG.set(item.localUri, item.etag);
|
|
967
|
+
}
|
|
968
|
+
});
|
|
961
969
|
break;
|
|
962
970
|
}
|
|
963
971
|
try {
|
|
@@ -982,10 +990,10 @@ class ChromeDocument extends Document {
|
|
|
982
990
|
instance.svgFiles = svg;
|
|
983
991
|
await instance.applyTransforms(processing);
|
|
984
992
|
}
|
|
985
|
-
hint = assets.filter(item => item.etag).length + ' assets';
|
|
993
|
+
hint = instance.assets.filter(item => item.etag).length + ' assets';
|
|
986
994
|
}
|
|
987
995
|
case 'exists':
|
|
988
|
-
if (hint || isHtmlOnly()) {
|
|
996
|
+
if (hint || isHtmlOnly(instance.assets, fetched, htmlFile)) {
|
|
989
997
|
this.formatMessage(4, 'HTML', ['No changes detected', 'incremental: ' + incremental], hint, { ...Document.LOG_STYLE_NOTICE, messageBgColor: 'bgWhite', messageColor: 'black' });
|
|
990
998
|
return super.finalize.call(this, instance);
|
|
991
999
|
}
|
|
@@ -998,7 +1006,7 @@ class ChromeDocument extends Document {
|
|
|
998
1006
|
if (instance.editing.length) {
|
|
999
1007
|
await instance.applyTransforms(processing);
|
|
1000
1008
|
if (instance.aborted) {
|
|
1001
|
-
return
|
|
1009
|
+
return (0, types_1.createAbortError)(true);
|
|
1002
1010
|
}
|
|
1003
1011
|
}
|
|
1004
1012
|
if (productionRelease) {
|
|
@@ -1011,7 +1019,7 @@ class ChromeDocument extends Document {
|
|
|
1011
1019
|
}
|
|
1012
1020
|
static async cleanup(instance) {
|
|
1013
1021
|
if (instance.aborted) {
|
|
1014
|
-
return
|
|
1022
|
+
return (0, types_1.createAbortError)(true);
|
|
1015
1023
|
}
|
|
1016
1024
|
if (this.Watch) {
|
|
1017
1025
|
const related = instance.related;
|
|
@@ -1314,7 +1322,7 @@ class ChromeDocument extends Document {
|
|
|
1314
1322
|
}
|
|
1315
1323
|
async using(data) {
|
|
1316
1324
|
if (this.aborted) {
|
|
1317
|
-
return
|
|
1325
|
+
return (0, types_1.createAbortError)(true);
|
|
1318
1326
|
}
|
|
1319
1327
|
const file = data.file;
|
|
1320
1328
|
if (file.editing) {
|
|
@@ -1735,7 +1743,7 @@ class ChromeDocument extends Document {
|
|
|
1735
1743
|
}
|
|
1736
1744
|
async cloudFinalize(state) {
|
|
1737
1745
|
if (this.aborted) {
|
|
1738
|
-
return
|
|
1746
|
+
return (0, types_1.createAbortError)(true);
|
|
1739
1747
|
}
|
|
1740
1748
|
const { host, instance, localStorage } = state;
|
|
1741
1749
|
const htmlFile = this.htmlFile;
|
|
@@ -1773,7 +1781,7 @@ class ChromeDocument extends Document {
|
|
|
1773
1781
|
}
|
|
1774
1782
|
}
|
|
1775
1783
|
if (this.aborted) {
|
|
1776
|
-
return
|
|
1784
|
+
return (0, types_1.createAbortError)(true);
|
|
1777
1785
|
}
|
|
1778
1786
|
}
|
|
1779
1787
|
if (htmlFile) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-r/chrome",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.2",
|
|
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.4",
|
|
24
|
+
"@e-mc/core": "^0.9.4",
|
|
25
|
+
"@e-mc/document": "^0.9.4",
|
|
26
|
+
"@e-mc/types": "^0.9.4"
|
|
27
27
|
}
|
|
28
28
|
}
|