@e-mc/document 0.8.25 → 0.8.27

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 +18 -13
  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
- - https://www.unpkg.com/@e-mc/types@0.8.25/lib/index.d.ts
12
+ - https://www.unpkg.com/@e-mc/types@0.8.27/lib/index.d.ts
13
13
 
14
14
  ```typescript
15
15
  import type { DataSource, ViewEngine } from "./squared";
@@ -85,14 +85,14 @@ interface DocumentConstructor extends ModuleConstructor {
85
85
 
86
86
  ## References
87
87
 
88
- - https://www.unpkg.com/@e-mc/types@0.8.25/lib/squared.d.ts
89
- - https://www.unpkg.com/@e-mc/types@0.8.25/lib/asset.d.ts
90
- - https://www.unpkg.com/@e-mc/types@0.8.25/lib/core.d.ts
91
- - https://www.unpkg.com/@e-mc/types@0.8.25/lib/document.d.ts
92
- - https://www.unpkg.com/@e-mc/types@0.8.25/lib/filemanager.d.ts
93
- - https://www.unpkg.com/@e-mc/types@0.8.25/lib/logger.d.ts
94
- - https://www.unpkg.com/@e-mc/types@0.8.25/lib/settings.d.ts
95
- - https://www.unpkg.com/@e-mc/types@0.8.25/lib/watch.d.ts
88
+ - https://www.unpkg.com/@e-mc/types@0.8.27/lib/squared.d.ts
89
+ - https://www.unpkg.com/@e-mc/types@0.8.27/lib/asset.d.ts
90
+ - https://www.unpkg.com/@e-mc/types@0.8.27/lib/core.d.ts
91
+ - https://www.unpkg.com/@e-mc/types@0.8.27/lib/document.d.ts
92
+ - https://www.unpkg.com/@e-mc/types@0.8.27/lib/filemanager.d.ts
93
+ - https://www.unpkg.com/@e-mc/types@0.8.27/lib/logger.d.ts
94
+ - https://www.unpkg.com/@e-mc/types@0.8.27/lib/settings.d.ts
95
+ - https://www.unpkg.com/@e-mc/types@0.8.27/lib/watch.d.ts
96
96
 
97
97
  ## LICENSE
98
98
 
package/index.js CHANGED
@@ -18,6 +18,7 @@ const CACHE_ETAG = {};
18
18
  const CACHE_CODE = {};
19
19
  const CACHE_HASH = {};
20
20
  const CACHE_TEMPLATE = {};
21
+ const CACHE_VIEWENGINE = new Map();
21
22
  const CACHE_EXTERNAL = {};
22
23
  const CACHE_PICOMATCH = new Map();
23
24
  let CACHE_TOTAL = 0;
@@ -65,6 +66,7 @@ class Document extends core_1.Client {
65
66
  delete cache[name];
66
67
  }
67
68
  }
69
+ CACHE_VIEWENGINE.clear();
68
70
  CACHE_PICOMATCH.clear();
69
71
  CACHE_TOTAL = 0;
70
72
  }
@@ -702,7 +704,7 @@ class Document extends core_1.Client {
702
704
  if (!(0, types_1.isPlainObject)(imports)) {
703
705
  return;
704
706
  }
705
- const toPosix = (value) => value.replace(/(?:^\\|\\+)/g, '/');
707
+ const toPosix = (value) => PLATFORM_WIN32 ? value.trim().replace(/(?:^\\|\\+)/g, '/') : value;
706
708
  const normalizeDir = (value, check) => {
707
709
  const sep = !check && value.includes('\\') && !value.includes('/') ? '\\' : '/';
708
710
  if (check) {
@@ -712,34 +714,33 @@ class Document extends core_1.Client {
712
714
  };
713
715
  const importsStrict = (_b = (_a = this.getUserSettings()) === null || _a === void 0 ? void 0 : _a.imports_strict) !== null && _b !== void 0 ? _b : this.settings.imports_strict;
714
716
  const scopes = (importsStrict ? this.findSourceScope(uri, imports) : []).concat([imports]);
715
- const isDir = /[\\/]$/;
717
+ const protocol = core_1.Client.isURL(uri);
716
718
  let result;
717
719
  for (const scope of scopes) {
718
720
  for (const url in scope) {
719
721
  if (uri === url && (0, types_1.isString)(result = scope[url])) {
720
722
  if (importsStrict) {
721
- if (isDir.test(url) || !core_1.Client.isPath(result)) {
722
- continue;
723
+ if (core_1.Client.isPath(result) && !(protocol ? url : toPosix(url)).endsWith('/')) {
724
+ return toPosix(result);
723
725
  }
724
- return toPosix(result);
726
+ continue;
725
727
  }
726
728
  return result;
727
729
  }
728
730
  }
729
731
  }
730
- const remote = toPosix(uri);
731
732
  const found = [];
732
733
  if (importsStrict) {
733
- const protocol = core_1.Client.isURL(remote);
734
+ const remote = protocol ? uri : toPosix(uri);
734
735
  for (const scope of scopes) {
735
736
  for (const url in scope) {
736
737
  const local = protocol ? url : toPosix(url);
737
- if (isDir.test(local) && remote.startsWith(local) && (result = scope[url]) && isDir.test(result)) {
738
+ if (local.endsWith('/') && remote.startsWith(local) && (result = scope[url]) && result.endsWith('/')) {
738
739
  if (protocol) {
739
740
  found.push([url, result]);
740
741
  }
741
742
  else if (core_1.Client.isPath(result = path.join(result, remote.substring(local.length)))) {
742
- return PLATFORM_WIN32 ? toPosix(result) : result;
743
+ return toPosix(result);
743
744
  }
744
745
  }
745
746
  }
@@ -775,7 +776,7 @@ class Document extends core_1.Client {
775
776
  result = toPath(found[0]);
776
777
  }
777
778
  if (result) {
778
- return PLATFORM_WIN32 ? toPosix(result) : result;
779
+ return toPosix(result);
779
780
  }
780
781
  }
781
782
  }
@@ -897,8 +898,12 @@ class Document extends core_1.Client {
897
898
  target = (_a = this.settings.view_engine) === null || _a === void 0 ? void 0 : _a[viewEngine];
898
899
  const userConfig = (_c = (_b = this.getUserSettings()) === null || _b === void 0 ? void 0 : _b.view_engine) === null || _c === void 0 ? void 0 : _c[viewEngine];
899
900
  if ((0, types_1.isPlainObject)(userConfig)) {
900
- if ((0, types_1.isPlainObject)(target)) {
901
- (0, types_1.cloneObject)(userConfig, { target, deep: true, preserve: true });
901
+ if (CACHE_VIEWENGINE.has(userConfig)) {
902
+ target = CACHE_VIEWENGINE.get(userConfig);
903
+ }
904
+ else if ((0, types_1.isPlainObject)(target)) {
905
+ target = (0, types_1.cloneObject)(userConfig, { target: { ...target }, deep: true, preserve: true });
906
+ CACHE_VIEWENGINE.set(userConfig, target);
902
907
  }
903
908
  else {
904
909
  target = userConfig;
@@ -909,7 +914,7 @@ class Document extends core_1.Client {
909
914
  else {
910
915
  target = viewEngine;
911
916
  }
912
- if (!((0, types_1.isPlainObject)(target) && target.name)) {
917
+ if (!((0, types_1.isPlainObject)(target) && (0, types_1.isString)(target.name))) {
913
918
  this.abort('view_engine');
914
919
  const from = typeof viewEngine === 'string' ? viewEngine : this.moduleName;
915
920
  this.writeFail(["Unable to load configuration", from], (0, types_1.errorMessage)('view-engine', from, "Unknown"));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/document",
3
- "version": "0.8.25",
3
+ "version": "0.8.27",
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": "MIT",
21
21
  "homepage": "https://github.com/anpham6/e-mc#readme",
22
22
  "dependencies": {
23
- "@e-mc/core": "0.8.25",
24
- "@e-mc/db": "0.8.25",
25
- "@e-mc/types": "0.8.25",
23
+ "@e-mc/core": "0.8.27",
24
+ "@e-mc/db": "0.8.27",
25
+ "@e-mc/types": "0.8.27",
26
26
  "chalk": "4.1.2",
27
27
  "domhandler": "^5.0.3",
28
28
  "domutils": "^3.1.0",
package/util.js CHANGED
@@ -215,7 +215,7 @@ function hasValue(target, ...values) {
215
215
  }
216
216
  exports.hasValue = hasValue;
217
217
  function getModuleName(err) {
218
- const match = err instanceof Error && /Cannot find module '([^']+)'/.exec(err.message);
218
+ const match = err instanceof Error && /Cannot find (?:module|package) '([^']+)'/.exec(err.message);
219
219
  if (match) {
220
220
  return match[1];
221
221
  }