@e-mc/document 0.9.19 → 0.9.21
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/README.md +10 -10
- package/index.js +18 -13
- package/package.json +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.9.
|
|
12
|
+
* [View Source](https://www.unpkg.com/@e-mc/types@0.9.21/lib/index.d.ts)
|
|
13
13
|
|
|
14
14
|
```typescript
|
|
15
15
|
import type { DataSource, ViewEngine } from "./squared";
|
|
@@ -183,15 +183,15 @@ NOTE: **@e-mc/document** is an abstract base class and cannot be instantiated. *
|
|
|
183
183
|
|
|
184
184
|
## References
|
|
185
185
|
|
|
186
|
-
- https://www.unpkg.com/@e-mc/types@0.9.
|
|
187
|
-
- https://www.unpkg.com/@e-mc/types@0.9.
|
|
188
|
-
- https://www.unpkg.com/@e-mc/types@0.9.
|
|
189
|
-
- https://www.unpkg.com/@e-mc/types@0.9.
|
|
190
|
-
- https://www.unpkg.com/@e-mc/types@0.9.
|
|
191
|
-
- https://www.unpkg.com/@e-mc/types@0.9.
|
|
192
|
-
- https://www.unpkg.com/@e-mc/types@0.9.
|
|
193
|
-
- https://www.unpkg.com/@e-mc/types@0.9.
|
|
186
|
+
- https://www.unpkg.com/@e-mc/types@0.9.21/lib/squared.d.ts
|
|
187
|
+
- https://www.unpkg.com/@e-mc/types@0.9.21/lib/asset.d.ts
|
|
188
|
+
- https://www.unpkg.com/@e-mc/types@0.9.21/lib/core.d.ts
|
|
189
|
+
- https://www.unpkg.com/@e-mc/types@0.9.21/lib/document.d.ts
|
|
190
|
+
- https://www.unpkg.com/@e-mc/types@0.9.21/lib/filemanager.d.ts
|
|
191
|
+
- https://www.unpkg.com/@e-mc/types@0.9.21/lib/logger.d.ts
|
|
192
|
+
- https://www.unpkg.com/@e-mc/types@0.9.21/lib/settings.d.ts
|
|
193
|
+
- https://www.unpkg.com/@e-mc/types@0.9.21/lib/watch.d.ts
|
|
194
194
|
|
|
195
195
|
## LICENSE
|
|
196
196
|
|
|
197
|
-
|
|
197
|
+
MIT
|
package/index.js
CHANGED
|
@@ -17,6 +17,7 @@ const CACHE_ETAG = {};
|
|
|
17
17
|
const CACHE_CODE = {};
|
|
18
18
|
const CACHE_HASH = {};
|
|
19
19
|
const CACHE_TEMPLATE = {};
|
|
20
|
+
const CACHE_VIEWENGINE = new Map();
|
|
20
21
|
const CACHE_EXTERNAL = {};
|
|
21
22
|
const CACHE_PICOMATCH = new Map();
|
|
22
23
|
let CACHE_TOTAL = 0;
|
|
@@ -106,6 +107,7 @@ class Document extends core_1.Client {
|
|
|
106
107
|
delete cache[name];
|
|
107
108
|
}
|
|
108
109
|
}
|
|
110
|
+
CACHE_VIEWENGINE.clear();
|
|
109
111
|
CACHE_PICOMATCH.clear();
|
|
110
112
|
CACHE_TOTAL = 0;
|
|
111
113
|
}
|
|
@@ -737,7 +739,7 @@ class Document extends core_1.Client {
|
|
|
737
739
|
if (!(0, types_1.isPlainObject)(imports)) {
|
|
738
740
|
return;
|
|
739
741
|
}
|
|
740
|
-
const toPosix = (value) => value.replace(/(?:^\\|\\+)/g, '/');
|
|
742
|
+
const toPosix = (value) => PLATFORM_WIN32 ? value.trim().replace(/(?:^\\|\\+)/g, '/') : value;
|
|
741
743
|
const normalizeDir = (value, check) => {
|
|
742
744
|
const sep = !check && value.includes('\\') && !value.includes('/') ? '\\' : '/';
|
|
743
745
|
if (check) {
|
|
@@ -747,34 +749,33 @@ class Document extends core_1.Client {
|
|
|
747
749
|
};
|
|
748
750
|
const importsStrict = this.getUserSettings()?.imports_strict ?? this.settings.imports_strict;
|
|
749
751
|
const scopes = (importsStrict ? this.findSourceScope(uri, imports) : []).concat([imports]);
|
|
750
|
-
const
|
|
752
|
+
const protocol = core_1.Client.isURL(uri);
|
|
751
753
|
let result;
|
|
752
754
|
for (const scope of scopes) {
|
|
753
755
|
for (const url in scope) {
|
|
754
756
|
if (uri === url && (0, types_1.isString)(result = scope[url])) {
|
|
755
757
|
if (importsStrict) {
|
|
756
|
-
if (
|
|
757
|
-
|
|
758
|
+
if (core_1.Client.isPath(result) && !(protocol ? url : toPosix(url)).endsWith('/')) {
|
|
759
|
+
return toPosix(result);
|
|
758
760
|
}
|
|
759
|
-
|
|
761
|
+
continue;
|
|
760
762
|
}
|
|
761
763
|
return result;
|
|
762
764
|
}
|
|
763
765
|
}
|
|
764
766
|
}
|
|
765
|
-
const remote = toPosix(uri);
|
|
766
767
|
const found = [];
|
|
767
768
|
if (importsStrict) {
|
|
768
|
-
const
|
|
769
|
+
const remote = protocol ? uri : toPosix(uri);
|
|
769
770
|
for (const scope of scopes) {
|
|
770
771
|
for (const url in scope) {
|
|
771
772
|
const local = protocol ? url : toPosix(url);
|
|
772
|
-
if (
|
|
773
|
+
if (local.endsWith('/') && remote.startsWith(local) && (result = scope[url]) && result.endsWith('/')) {
|
|
773
774
|
if (protocol) {
|
|
774
775
|
found.push([url, result]);
|
|
775
776
|
}
|
|
776
777
|
else if (core_1.Client.isPath(result = path.join(result, remote.substring(local.length)))) {
|
|
777
|
-
return
|
|
778
|
+
return toPosix(result);
|
|
778
779
|
}
|
|
779
780
|
}
|
|
780
781
|
}
|
|
@@ -810,7 +811,7 @@ class Document extends core_1.Client {
|
|
|
810
811
|
result = toPath(found[0]);
|
|
811
812
|
}
|
|
812
813
|
if (result) {
|
|
813
|
-
return
|
|
814
|
+
return toPosix(result);
|
|
814
815
|
}
|
|
815
816
|
}
|
|
816
817
|
}
|
|
@@ -927,8 +928,12 @@ class Document extends core_1.Client {
|
|
|
927
928
|
target = this.settings.view_engine?.[viewEngine];
|
|
928
929
|
const userConfig = this.getUserSettings()?.view_engine?.[viewEngine];
|
|
929
930
|
if ((0, types_1.isPlainObject)(userConfig)) {
|
|
930
|
-
if (
|
|
931
|
-
|
|
931
|
+
if (CACHE_VIEWENGINE.has(userConfig)) {
|
|
932
|
+
target = CACHE_VIEWENGINE.get(userConfig);
|
|
933
|
+
}
|
|
934
|
+
else if ((0, types_1.isPlainObject)(target)) {
|
|
935
|
+
target = (0, types_1.cloneObject)(userConfig, { target: { ...target }, deep: true, preserve: true });
|
|
936
|
+
CACHE_VIEWENGINE.set(userConfig, target);
|
|
932
937
|
}
|
|
933
938
|
else {
|
|
934
939
|
target = userConfig;
|
|
@@ -939,7 +944,7 @@ class Document extends core_1.Client {
|
|
|
939
944
|
else {
|
|
940
945
|
target = viewEngine;
|
|
941
946
|
}
|
|
942
|
-
if (!((0, types_1.isPlainObject)(target) && target.name)) {
|
|
947
|
+
if (!((0, types_1.isPlainObject)(target) && (0, types_1.isString)(target.name))) {
|
|
943
948
|
this.abort('view_engine');
|
|
944
949
|
const from = typeof viewEngine === 'string' ? viewEngine : this.moduleName;
|
|
945
950
|
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.9.
|
|
3
|
+
"version": "0.9.21",
|
|
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.9.
|
|
24
|
-
"@e-mc/db": "0.9.
|
|
25
|
-
"@e-mc/types": "0.9.
|
|
23
|
+
"@e-mc/core": "0.9.21",
|
|
24
|
+
"@e-mc/db": "0.9.21",
|
|
25
|
+
"@e-mc/types": "0.9.21",
|
|
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
|
}
|