@e-mc/document 0.10.11 → 0.10.13
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/LICENSE +3 -7
- package/README.md +10 -10
- package/index.js +18 -13
- package/package.json +5 -5
- package/util.js +1 -1
package/LICENSE
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
Copyright 2024 An Pham
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
|
10
|
-
|
|
11
|
-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
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.10.
|
|
12
|
+
* [View Source](https://www.unpkg.com/@e-mc/types@0.10.13/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.10.
|
|
187
|
-
- https://www.unpkg.com/@e-mc/types@0.10.
|
|
188
|
-
- https://www.unpkg.com/@e-mc/types@0.10.
|
|
189
|
-
- https://www.unpkg.com/@e-mc/types@0.10.
|
|
190
|
-
- https://www.unpkg.com/@e-mc/types@0.10.
|
|
191
|
-
- https://www.unpkg.com/@e-mc/types@0.10.
|
|
192
|
-
- https://www.unpkg.com/@e-mc/types@0.10.
|
|
193
|
-
- https://www.unpkg.com/@e-mc/types@0.10.
|
|
186
|
+
- https://www.unpkg.com/@e-mc/types@0.10.13/lib/squared.d.ts
|
|
187
|
+
- https://www.unpkg.com/@e-mc/types@0.10.13/lib/asset.d.ts
|
|
188
|
+
- https://www.unpkg.com/@e-mc/types@0.10.13/lib/core.d.ts
|
|
189
|
+
- https://www.unpkg.com/@e-mc/types@0.10.13/lib/document.d.ts
|
|
190
|
+
- https://www.unpkg.com/@e-mc/types@0.10.13/lib/filemanager.d.ts
|
|
191
|
+
- https://www.unpkg.com/@e-mc/types@0.10.13/lib/logger.d.ts
|
|
192
|
+
- https://www.unpkg.com/@e-mc/types@0.10.13/lib/settings.d.ts
|
|
193
|
+
- https://www.unpkg.com/@e-mc/types@0.10.13/lib/watch.d.ts
|
|
194
194
|
|
|
195
195
|
## LICENSE
|
|
196
196
|
|
|
197
|
-
|
|
197
|
+
MIT
|
package/index.js
CHANGED
|
@@ -16,6 +16,7 @@ const CACHE_ETAG = {};
|
|
|
16
16
|
const CACHE_CODE = {};
|
|
17
17
|
const CACHE_HASH = {};
|
|
18
18
|
const CACHE_TEMPLATE = {};
|
|
19
|
+
const CACHE_VIEWENGINE = new Map();
|
|
19
20
|
const CACHE_EXTERNAL = {};
|
|
20
21
|
const CACHE_PICOMATCH = new Map();
|
|
21
22
|
let CACHE_TOTAL = 0;
|
|
@@ -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 spliceSource = (source, startIndex, endIndex, content) => source.substring(0, startIndex) + content + source.substring(endIndex);
|
|
@@ -348,6 +349,7 @@ class Document extends core_1.Client {
|
|
|
348
349
|
delete cache[name];
|
|
349
350
|
}
|
|
350
351
|
}
|
|
352
|
+
CACHE_VIEWENGINE.clear();
|
|
351
353
|
CACHE_PICOMATCH.clear();
|
|
352
354
|
CACHE_TOTAL = 0;
|
|
353
355
|
}
|
|
@@ -909,34 +911,33 @@ class Document extends core_1.Client {
|
|
|
909
911
|
}
|
|
910
912
|
const importsStrict = this.getUserSettings()?.imports_strict ?? this.settings.imports_strict;
|
|
911
913
|
const scopes = (importsStrict ? this.findSourceScope(uri, imports) : []).concat([imports]);
|
|
912
|
-
const
|
|
914
|
+
const protocol = core_1.Client.isURL(uri);
|
|
913
915
|
let result;
|
|
914
916
|
for (const scope of scopes) {
|
|
915
917
|
for (const url in scope) {
|
|
916
918
|
if (uri === url && (0, types_1.isString)(result = scope[url])) {
|
|
917
919
|
if (importsStrict) {
|
|
918
|
-
if (
|
|
919
|
-
|
|
920
|
+
if (core_1.Client.isPath(result) && !(protocol ? url : toPosix(url)).endsWith('/')) {
|
|
921
|
+
return toPosix(result);
|
|
920
922
|
}
|
|
921
|
-
|
|
923
|
+
continue;
|
|
922
924
|
}
|
|
923
925
|
return result;
|
|
924
926
|
}
|
|
925
927
|
}
|
|
926
928
|
}
|
|
927
|
-
const remote = toPosix(uri);
|
|
928
929
|
const found = [];
|
|
929
930
|
if (importsStrict) {
|
|
930
|
-
const
|
|
931
|
+
const remote = protocol ? uri : toPosix(uri);
|
|
931
932
|
for (const scope of scopes) {
|
|
932
933
|
for (const url in scope) {
|
|
933
934
|
const local = protocol ? url : toPosix(url);
|
|
934
|
-
if (
|
|
935
|
+
if (local.endsWith('/') && remote.startsWith(local) && (result = scope[url]) && result.endsWith('/')) {
|
|
935
936
|
if (protocol) {
|
|
936
937
|
found.push([url, result]);
|
|
937
938
|
}
|
|
938
939
|
else if (core_1.Client.isPath(result = path.join(result, remote.substring(local.length)))) {
|
|
939
|
-
return
|
|
940
|
+
return toPosix(result);
|
|
940
941
|
}
|
|
941
942
|
}
|
|
942
943
|
}
|
|
@@ -971,7 +972,7 @@ class Document extends core_1.Client {
|
|
|
971
972
|
result = toPath(uri, found[0]);
|
|
972
973
|
}
|
|
973
974
|
if (result) {
|
|
974
|
-
return
|
|
975
|
+
return toPosix(result);
|
|
975
976
|
}
|
|
976
977
|
}
|
|
977
978
|
}
|
|
@@ -1088,8 +1089,12 @@ class Document extends core_1.Client {
|
|
|
1088
1089
|
target = this.settings.view_engine?.[viewEngine];
|
|
1089
1090
|
const userConfig = this.getUserSettings()?.view_engine?.[viewEngine];
|
|
1090
1091
|
if ((0, types_1.isPlainObject)(userConfig)) {
|
|
1091
|
-
if (
|
|
1092
|
-
|
|
1092
|
+
if (CACHE_VIEWENGINE.has(userConfig)) {
|
|
1093
|
+
target = CACHE_VIEWENGINE.get(userConfig);
|
|
1094
|
+
}
|
|
1095
|
+
else if ((0, types_1.isPlainObject)(target)) {
|
|
1096
|
+
target = (0, types_1.cloneObject)(userConfig, { target: { ...target }, deep: true, preserve: true });
|
|
1097
|
+
CACHE_VIEWENGINE.set(userConfig, target);
|
|
1093
1098
|
}
|
|
1094
1099
|
else {
|
|
1095
1100
|
target = userConfig;
|
|
@@ -1100,7 +1105,7 @@ class Document extends core_1.Client {
|
|
|
1100
1105
|
else {
|
|
1101
1106
|
target = viewEngine;
|
|
1102
1107
|
}
|
|
1103
|
-
if (!((0, types_1.isPlainObject)(target) && target.name)) {
|
|
1108
|
+
if (!((0, types_1.isPlainObject)(target) && (0, types_1.isString)(target.name))) {
|
|
1104
1109
|
this.abort('view_engine');
|
|
1105
1110
|
const from = typeof viewEngine === 'string' ? viewEngine : this.moduleName;
|
|
1106
1111
|
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.10.
|
|
3
|
+
"version": "0.10.13",
|
|
4
4
|
"description": "Document constructor for E-mc.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -17,12 +17,12 @@
|
|
|
17
17
|
"squared-functions"
|
|
18
18
|
],
|
|
19
19
|
"author": "An Pham <anpham6@gmail.com>",
|
|
20
|
-
"license": "
|
|
20
|
+
"license": "MIT",
|
|
21
21
|
"homepage": "https://github.com/anpham6/e-mc#readme",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@e-mc/core": "0.10.
|
|
24
|
-
"@e-mc/db": "0.10.
|
|
25
|
-
"@e-mc/types": "0.10.
|
|
23
|
+
"@e-mc/core": "0.10.13",
|
|
24
|
+
"@e-mc/db": "0.10.13",
|
|
25
|
+
"@e-mc/types": "0.10.13",
|
|
26
26
|
"chalk": "4.1.2",
|
|
27
27
|
"domhandler": "^5.0.3",
|
|
28
28
|
"domutils": "^3.1.0",
|
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
|
}
|