@e-mc/document 0.11.7 → 0.11.9

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 (4) hide show
  1. package/README.md +9 -9
  2. package/index.js +19 -14
  3. package/package.json +4 -4
  4. package/util.js +1 -1
package/README.md CHANGED
@@ -9,7 +9,7 @@
9
9
 
10
10
  ## Interface
11
11
 
12
- * [View Source](https://www.unpkg.com/@e-mc/types@0.11.7/lib/index.d.ts)
12
+ * [View Source](https://www.unpkg.com/@e-mc/types@0.11.9/lib/index.d.ts)
13
13
 
14
14
  ```typescript
15
15
  import type { DataSource, ViewEngine } from "./squared";
@@ -185,14 +185,14 @@ NOTE: **@e-mc/document** is an abstract base class and cannot be instantiated. *
185
185
 
186
186
  ## References
187
187
 
188
- - https://www.unpkg.com/@e-mc/types@0.11.7/lib/squared.d.ts
189
- - https://www.unpkg.com/@e-mc/types@0.11.7/lib/asset.d.ts
190
- - https://www.unpkg.com/@e-mc/types@0.11.7/lib/core.d.ts
191
- - https://www.unpkg.com/@e-mc/types@0.11.7/lib/document.d.ts
192
- - https://www.unpkg.com/@e-mc/types@0.11.7/lib/filemanager.d.ts
193
- - https://www.unpkg.com/@e-mc/types@0.11.7/lib/logger.d.ts
194
- - https://www.unpkg.com/@e-mc/types@0.11.7/lib/settings.d.ts
195
- - https://www.unpkg.com/@e-mc/types@0.11.7/lib/watch.d.ts
188
+ - https://www.unpkg.com/@e-mc/types@0.11.9/lib/squared.d.ts
189
+ - https://www.unpkg.com/@e-mc/types@0.11.9/lib/asset.d.ts
190
+ - https://www.unpkg.com/@e-mc/types@0.11.9/lib/core.d.ts
191
+ - https://www.unpkg.com/@e-mc/types@0.11.9/lib/document.d.ts
192
+ - https://www.unpkg.com/@e-mc/types@0.11.9/lib/filemanager.d.ts
193
+ - https://www.unpkg.com/@e-mc/types@0.11.9/lib/logger.d.ts
194
+ - https://www.unpkg.com/@e-mc/types@0.11.9/lib/settings.d.ts
195
+ - https://www.unpkg.com/@e-mc/types@0.11.9/lib/watch.d.ts
196
196
 
197
197
  ## LICENSE
198
198
 
package/index.js CHANGED
@@ -13,6 +13,7 @@ const parse_1 = require("@e-mc/document/parse");
13
13
  const util_1 = require("@e-mc/document/util");
14
14
  const CACHE_PACKAGE = {};
15
15
  const CACHE_TEMPLATE = {};
16
+ const CACHE_VIEWENGINE = new Map();
16
17
  const CACHE_EXTERNAL = {};
17
18
  const CACHE_ETAG = {};
18
19
  const CACHE_CODE = {};
@@ -54,7 +55,7 @@ const fixHint = (warningCount, errorCount, value) => warningCount > 0 || errorCo
54
55
  const compareValue = (value) => value.replace(/["'()]/g, '').trim();
55
56
  const toPath = (uri, hostname) => path.resolve(hostname[1], uri.substring(normalizeDir(hostname[0]).length).split('?')[0]);
56
57
  const toBase64 = (value) => 'data:application/json;base64,' + Buffer.from(value).toString('base64');
57
- const toPosix = (value) => value.replace(/(?:^\\|\\+)/g, '/');
58
+ const toPosix = (value) => core_1.Client.PLATFORM_WIN32 ? value.trim().replace(/(?:^\\|\\+)/g, '/') : value;
58
59
  const joinString = (name, ...values) => (name ? name + ': ' : '') + values.reduce((a, b) => b ? a + (a ? ' -> ' : '') + b : a, '');
59
60
  const truncateString = (value, width) => value.length > width ? value.substring(0, width - 3) + '...' : value.padStart(width);
60
61
  const isFunction = (value) => typeof value === 'function';
@@ -347,6 +348,7 @@ class Document extends core_1.Client {
347
348
  delete cache[name];
348
349
  }
349
350
  }
351
+ CACHE_VIEWENGINE.clear();
350
352
  CACHE_PICOMATCH.clear();
351
353
  CACHE_TOTAL = 0;
352
354
  }
@@ -900,34 +902,33 @@ class Document extends core_1.Client {
900
902
  }
901
903
  const importsStrict = this.getUserSettings()?.imports_strict ?? this.settings.imports_strict;
902
904
  const scopes = (importsStrict ? this.findSourceScope(uri, imports) : []).concat([imports]);
903
- const isDir = /[\\/]$/;
905
+ const protocol = core_1.Client.isURL(uri);
904
906
  let result;
905
907
  for (const scope of scopes) {
906
908
  for (const url in scope) {
907
909
  if (uri === url && (0, types_1.isString)(result = scope[url])) {
908
910
  if (importsStrict) {
909
- if (isDir.test(url) || !core_1.Client.isPath(result)) {
910
- continue;
911
+ if (core_1.Client.isPath(result) && !(protocol ? url : toPosix(url)).endsWith('/')) {
912
+ return toPosix(result);
911
913
  }
912
- return toPosix(result);
914
+ continue;
913
915
  }
914
916
  return result;
915
917
  }
916
918
  }
917
919
  }
918
- const remote = toPosix(uri);
919
920
  const found = [];
920
921
  if (importsStrict) {
921
- const protocol = core_1.Client.isURL(remote);
922
+ const remote = protocol ? uri : toPosix(uri);
922
923
  for (const scope of scopes) {
923
924
  for (const url in scope) {
924
925
  const local = protocol ? url : toPosix(url);
925
- if (isDir.test(local) && remote.startsWith(local) && (result = scope[url]) && isDir.test(result)) {
926
+ if (local.endsWith('/') && remote.startsWith(local) && (result = scope[url]) && result.endsWith('/')) {
926
927
  if (protocol) {
927
928
  found.push([url, result]);
928
929
  }
929
930
  else if (core_1.Client.isPath(result = path.join(result, remote.substring(local.length)))) {
930
- return core_1.Client.PLATFORM_WIN32 ? toPosix(result) : result;
931
+ return toPosix(result);
931
932
  }
932
933
  }
933
934
  }
@@ -962,7 +963,7 @@ class Document extends core_1.Client {
962
963
  result = toPath(uri, found[0]);
963
964
  }
964
965
  if (result) {
965
- return core_1.Client.PLATFORM_WIN32 ? toPosix(result) : result;
966
+ return toPosix(result);
966
967
  }
967
968
  }
968
969
  }
@@ -1079,8 +1080,12 @@ class Document extends core_1.Client {
1079
1080
  target = this.settings.view_engine?.[viewEngine];
1080
1081
  const userConfig = this.getUserSettings()?.view_engine?.[viewEngine];
1081
1082
  if ((0, types_1.isPlainObject)(userConfig)) {
1082
- if ((0, types_1.isPlainObject)(target)) {
1083
- (0, types_1.cloneObject)(userConfig, { target, deep: true, preserve: true });
1083
+ if (CACHE_VIEWENGINE.has(userConfig)) {
1084
+ target = CACHE_VIEWENGINE.get(userConfig);
1085
+ }
1086
+ else if ((0, types_1.isPlainObject)(target)) {
1087
+ target = (0, types_1.cloneObject)(userConfig, { target: { ...target }, deep: true, preserve: true });
1088
+ CACHE_VIEWENGINE.set(userConfig, target);
1084
1089
  }
1085
1090
  else {
1086
1091
  target = userConfig;
@@ -1091,7 +1096,7 @@ class Document extends core_1.Client {
1091
1096
  else {
1092
1097
  target = viewEngine;
1093
1098
  }
1094
- if (!((0, types_1.isPlainObject)(target) && target.name)) {
1099
+ if (!((0, types_1.isPlainObject)(target) && (0, types_1.isString)(target.name))) {
1095
1100
  this.abort('view_engine');
1096
1101
  const from = typeof viewEngine === 'string' ? viewEngine : this.moduleName;
1097
1102
  this.writeFail(["Unable to load configuration", from], (0, types_1.errorMessage)('view-engine', from, "Unknown"));
@@ -1131,7 +1136,7 @@ class Document extends core_1.Client {
1131
1136
  if (expires !== 0) {
1132
1137
  cache[cacheKey] = render;
1133
1138
  if (core_1.Client.enabled("memory.settings.users", username)) {
1134
- expires = typeof expires === 'number' && expires !== Infinity ? expires : 0;
1139
+ expires = typeof expires === 'number' && expires !== Infinity ? Math.min(expires, core_1.Client.MAX_TIMEOUT) : 0;
1135
1140
  }
1136
1141
  else {
1137
1142
  expires = 60000;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/document",
3
- "version": "0.11.7",
3
+ "version": "0.11.9",
4
4
  "description": "Document constructor for E-mc.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -20,9 +20,9 @@
20
20
  "license": "BSD-3-Clause",
21
21
  "homepage": "https://github.com/anpham6/e-mc#readme",
22
22
  "dependencies": {
23
- "@e-mc/core": "0.11.7",
24
- "@e-mc/db": "0.11.7",
25
- "@e-mc/types": "0.11.7",
23
+ "@e-mc/core": "0.11.9",
24
+ "@e-mc/db": "0.11.9",
25
+ "@e-mc/types": "0.11.9",
26
26
  "chalk": "4.1.2",
27
27
  "domhandler": "^5.0.3",
28
28
  "domutils": "^3.2.2",
package/util.js CHANGED
@@ -212,7 +212,7 @@ function hasValue(target, ...values) {
212
212
  return false;
213
213
  }
214
214
  function getModuleName(err) {
215
- const match = err instanceof Error && /Cannot find module '([^']+)'/.exec(err.message);
215
+ const match = err instanceof Error && /Cannot find (?:module|package) '([^']+)'/.exec(err.message);
216
216
  if (match) {
217
217
  return match[1];
218
218
  }