@e-mc/document 0.11.8 → 0.11.10

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/README.md +9 -9
  2. package/index.js +16 -4
  3. package/package.json +4 -4
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.8/lib/index.d.ts)
12
+ * [View Source](https://www.unpkg.com/@e-mc/types@0.11.10/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.8/lib/squared.d.ts
189
- - https://www.unpkg.com/@e-mc/types@0.11.8/lib/asset.d.ts
190
- - https://www.unpkg.com/@e-mc/types@0.11.8/lib/core.d.ts
191
- - https://www.unpkg.com/@e-mc/types@0.11.8/lib/document.d.ts
192
- - https://www.unpkg.com/@e-mc/types@0.11.8/lib/filemanager.d.ts
193
- - https://www.unpkg.com/@e-mc/types@0.11.8/lib/logger.d.ts
194
- - https://www.unpkg.com/@e-mc/types@0.11.8/lib/settings.d.ts
195
- - https://www.unpkg.com/@e-mc/types@0.11.8/lib/watch.d.ts
188
+ - https://www.unpkg.com/@e-mc/types@0.11.10/lib/squared.d.ts
189
+ - https://www.unpkg.com/@e-mc/types@0.11.10/lib/asset.d.ts
190
+ - https://www.unpkg.com/@e-mc/types@0.11.10/lib/core.d.ts
191
+ - https://www.unpkg.com/@e-mc/types@0.11.10/lib/document.d.ts
192
+ - https://www.unpkg.com/@e-mc/types@0.11.10/lib/filemanager.d.ts
193
+ - https://www.unpkg.com/@e-mc/types@0.11.10/lib/logger.d.ts
194
+ - https://www.unpkg.com/@e-mc/types@0.11.10/lib/settings.d.ts
195
+ - https://www.unpkg.com/@e-mc/types@0.11.10/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 = {};
@@ -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
  }
@@ -1078,8 +1080,12 @@ class Document extends core_1.Client {
1078
1080
  target = this.settings.view_engine?.[viewEngine];
1079
1081
  const userConfig = this.getUserSettings()?.view_engine?.[viewEngine];
1080
1082
  if ((0, types_1.isPlainObject)(userConfig)) {
1081
- if ((0, types_1.isPlainObject)(target)) {
1082
- (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);
1083
1089
  }
1084
1090
  else {
1085
1091
  target = userConfig;
@@ -1090,7 +1096,7 @@ class Document extends core_1.Client {
1090
1096
  else {
1091
1097
  target = viewEngine;
1092
1098
  }
1093
- if (!((0, types_1.isPlainObject)(target) && target.name)) {
1099
+ if (!((0, types_1.isPlainObject)(target) && (0, types_1.isString)(target.name))) {
1094
1100
  this.abort('view_engine');
1095
1101
  const from = typeof viewEngine === 'string' ? viewEngine : this.moduleName;
1096
1102
  this.writeFail(["Unable to load configuration", from], (0, types_1.errorMessage)('view-engine', from, "Unknown"));
@@ -1101,7 +1107,13 @@ class Document extends core_1.Client {
1101
1107
  return '';
1102
1108
  }
1103
1109
  try {
1104
- const context = require(target.name);
1110
+ let context;
1111
+ try {
1112
+ context = require(target.name);
1113
+ }
1114
+ catch {
1115
+ context = await (0, types_1.importESM)(target.name);
1116
+ }
1105
1117
  let { singleRow, expires, options = {} } = target;
1106
1118
  const { compile, output } = options;
1107
1119
  if (this.settingsOf('view_engine', 'coerce') === true) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/document",
3
- "version": "0.11.8",
3
+ "version": "0.11.10",
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.8",
24
- "@e-mc/db": "0.11.8",
25
- "@e-mc/types": "0.11.8",
23
+ "@e-mc/core": "0.11.10",
24
+ "@e-mc/db": "0.11.10",
25
+ "@e-mc/types": "0.11.10",
26
26
  "chalk": "4.1.2",
27
27
  "domhandler": "^5.0.3",
28
28
  "domutils": "^3.2.2",