@pi-r/chrome 0.7.0 → 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.
Files changed (3) hide show
  1. package/index.d.ts +6 -6
  2. package/index.js +26 -20
  3. package/package.json +5 -5
package/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import type { IFileManager } from '@e-mc/types/lib';
2
-
3
- import type { ChromeDocumentConstructor, DocumentAsset } from './types';
4
-
5
- declare const Chrome: ChromeDocumentConstructor<IFileManager<DocumentAsset>>;
6
-
1
+ import type { IFileManager } from '@e-mc/types/lib';
2
+
3
+ import type { ChromeDocumentConstructor, DocumentAsset } from './types';
4
+
5
+ declare const Chrome: ChromeDocumentConstructor<IFileManager<DocumentAsset>>;
6
+
7
7
  export = Chrome;
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;
@@ -180,9 +181,7 @@ function spliceSource(source, startIndex, endIndex, pattern, leading = '', trail
180
181
  if (leading || trailing) {
181
182
  content += getNewlineString(leading, trailing);
182
183
  }
183
- if (pattern && content) {
184
- pattern.lastIndex = startIndex + content.length;
185
- }
184
+ pattern.lastIndex = startIndex + content.length;
186
185
  return spliceString(source, startIndex, endIndex, content);
187
186
  }
188
187
  function hasCondition(data, condition) {
@@ -900,6 +899,7 @@ const getEndIndex = (match) => match.index + match[0].length;
900
899
  const getRelativeURL = (file) => joinPath(file.moveTo, file.pathname, file.inlineFilename || file.filename) + (!file.static ? restoreSearchParams(file.url?.search) : '');
901
900
  const errorHtml = ({ tagName, tagIndex = -1 }) => (0, types_1.errorMessage)('html', 'Location did not resolve', tagName.toLowerCase() + (tagIndex >= 0 ? ': ' + tagIndex : ''));
902
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));
903
903
  class ChromeDocument extends Document {
904
904
  static INTERNAL_ASSIGNUUID = "__assign__";
905
905
  static INTERNAL_SERVERROOT = "__serverroot__";
@@ -933,33 +933,39 @@ class ChromeDocument extends Document {
933
933
  }
934
934
  CACHE_QUERY.clear();
935
935
  CACHE_SELECTOR.clear();
936
+ CACHE_ETAG.clear();
936
937
  }
937
938
  return result + (parent && result > 0 ? await super.purgeMemory(typeof parent === 'number' && parent > 0 ? parent : percent, limit, true) : 0);
938
939
  }
939
940
  static async finalize(instance) {
940
941
  if (instance.aborted) {
941
- return Promise.reject((0, types_1.createAbortError)());
942
+ return (0, types_1.createAbortError)(true);
942
943
  }
943
- const productionRelease = instance.productionRelease;
944
- const processing = { host: this, startTime: process.hrtime(), hashed: new Set(), contentMap: {}, bufferMap: {}, cacheMiss: [], productionRelease: productionRelease ? true : undefined };
945
- const { Db: db, htmlFile, assets } = instance;
946
- const outHtml = htmlFile && !isIgnored(htmlFile, true);
947
- if (db && await db.commit()) {
948
- 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 });
949
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);
950
952
  if (instance.dataSource.length === 0 && outHtml) {
951
953
  const incremental = htmlFile.incremental ?? this.incremental;
952
954
  if (incremental === 'etag' || incremental === 'exists') {
953
955
  const fetched = this.fetchedAssets;
954
- const isHtmlOnly = () => !fetched.find(item => item !== htmlFile && assets.includes(item));
955
- 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))) {
956
957
  let hint = '';
957
958
  switch (incremental) {
958
959
  case 'etag': {
959
960
  if (outHtml) {
960
961
  const { etag, initialValue } = htmlFile;
961
962
  let buffer;
962
- 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
+ });
963
969
  break;
964
970
  }
965
971
  try {
@@ -984,10 +990,10 @@ class ChromeDocument extends Document {
984
990
  instance.svgFiles = svg;
985
991
  await instance.applyTransforms(processing);
986
992
  }
987
- hint = assets.filter(item => item.etag).length + ' assets';
993
+ hint = instance.assets.filter(item => item.etag).length + ' assets';
988
994
  }
989
995
  case 'exists':
990
- if (hint || isHtmlOnly()) {
996
+ if (hint || isHtmlOnly(instance.assets, fetched, htmlFile)) {
991
997
  this.formatMessage(4, 'HTML', ['No changes detected', 'incremental: ' + incremental], hint, { ...Document.LOG_STYLE_NOTICE, messageBgColor: 'bgWhite', messageColor: 'black' });
992
998
  return super.finalize.call(this, instance);
993
999
  }
@@ -1000,7 +1006,7 @@ class ChromeDocument extends Document {
1000
1006
  if (instance.editing.length) {
1001
1007
  await instance.applyTransforms(processing);
1002
1008
  if (instance.aborted) {
1003
- return Promise.reject((0, types_1.createAbortError)());
1009
+ return (0, types_1.createAbortError)(true);
1004
1010
  }
1005
1011
  }
1006
1012
  if (productionRelease) {
@@ -1013,7 +1019,7 @@ class ChromeDocument extends Document {
1013
1019
  }
1014
1020
  static async cleanup(instance) {
1015
1021
  if (instance.aborted) {
1016
- return Promise.reject((0, types_1.createAbortError)());
1022
+ return (0, types_1.createAbortError)(true);
1017
1023
  }
1018
1024
  if (this.Watch) {
1019
1025
  const related = instance.related;
@@ -1316,7 +1322,7 @@ class ChromeDocument extends Document {
1316
1322
  }
1317
1323
  async using(data) {
1318
1324
  if (this.aborted) {
1319
- return Promise.reject((0, types_1.createAbortError)());
1325
+ return (0, types_1.createAbortError)(true);
1320
1326
  }
1321
1327
  const file = data.file;
1322
1328
  if (file.editing) {
@@ -1737,7 +1743,7 @@ class ChromeDocument extends Document {
1737
1743
  }
1738
1744
  async cloudFinalize(state) {
1739
1745
  if (this.aborted) {
1740
- return Promise.reject((0, types_1.createAbortError)());
1746
+ return (0, types_1.createAbortError)(true);
1741
1747
  }
1742
1748
  const { host, instance, localStorage } = state;
1743
1749
  const htmlFile = this.htmlFile;
@@ -1775,7 +1781,7 @@ class ChromeDocument extends Document {
1775
1781
  }
1776
1782
  }
1777
1783
  if (this.aborted) {
1778
- return Promise.reject((0, types_1.createAbortError)());
1784
+ return (0, types_1.createAbortError)(true);
1779
1785
  }
1780
1786
  }
1781
1787
  if (htmlFile) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-r/chrome",
3
- "version": "0.7.0",
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.0",
24
- "@e-mc/core": "^0.9.0",
25
- "@e-mc/document": "^0.9.0",
26
- "@e-mc/types": "^0.9.0"
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
  }