@e-mc/document 0.8.5 → 0.8.7
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 +8 -4
- package/README.md +94 -2
- package/index.js +52 -53
- package/package.json +5 -5
- package/parse/dom.js +12 -12
- package/parse/index.js +2 -3
- package/transform/index.js +2 -6
- package/util.js +2 -2
package/LICENSE
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
Copyright 2024
|
|
1
|
+
Copyright 2024 An Pham
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
|
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.
|
package/README.md
CHANGED
|
@@ -1,7 +1,99 @@
|
|
|
1
1
|
# @e-mc/document
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
* NodeJS 14
|
|
4
|
+
* ES2020
|
|
5
|
+
|
|
6
|
+
## General Usage
|
|
7
|
+
|
|
8
|
+
* [Read the Docs](https://e-mc.readthedocs.io)
|
|
9
|
+
|
|
10
|
+
## Interface
|
|
11
|
+
|
|
12
|
+
- https://www.unpkg.com/@e-mc/types@0.8.7/lib/index.d.ts
|
|
13
|
+
|
|
14
|
+
```typescript
|
|
15
|
+
import type { DataSource, ViewEngine } from "./squared";
|
|
16
|
+
|
|
17
|
+
import type { IFileManager, IScopeOrigin } from "./index";
|
|
18
|
+
import type { ExternalAsset, FileCommand, IFileThread, OutputFinalize } from "./asset";
|
|
19
|
+
import type { HostInitConfig, IClient } from "./core";
|
|
20
|
+
import type { AsSourceFileOptions, ConfigOrTransformer, CustomizeOptions, GenerateLintTableOptions, LintMessage, PluginConfig, SourceCode, SourceInput, SourceMap, SourceMapOptions, TransformAction, TransformCallback, TransformOutput, TransformResult, UpdateGradleOptions } from "./document";
|
|
21
|
+
import type { PostFinalizeCallback } from "./filemanager";
|
|
22
|
+
import type { LogComponent } from "./logger";
|
|
23
|
+
import type { DocumentComponent, DocumentComponentOption, DocumentModule } from "./settings";
|
|
24
|
+
import type { IFileGroup, WatchInitResult } from "./watch";
|
|
25
|
+
|
|
26
|
+
interface IDocument extends IClient<IFileManager, DocumentModule, TransformCallback<IFileManager, ExternalAsset>> {
|
|
27
|
+
Db: IDb | null;
|
|
28
|
+
assets: ExternalAsset[];
|
|
29
|
+
config: Record<string, any>;
|
|
30
|
+
init(assets: ExternalAsset[], config?: HostInitConfig): this;
|
|
31
|
+
customize(options?: CustomizeOptions): void;
|
|
32
|
+
findConfig(data: object, name: string, type?: string): PluginConfig;
|
|
33
|
+
loadConfig(data: object, name: string): ConfigOrTransformer | null | undefined;
|
|
34
|
+
asSourceFile(value: string, options?: AsSourceFileOptions | boolean): unknown;
|
|
35
|
+
findVersion(name: string | string[], fallback?: string): string;
|
|
36
|
+
findSourceScope(uri: string, imports: Record<string, unknown>): Record<string, string | undefined>[];
|
|
37
|
+
findSourceRoot(uri: string, imports?: Record<string, string | undefined>): string | undefined;
|
|
38
|
+
resolveDir(name: string, ...paths: string[]): string | undefined;
|
|
39
|
+
locateSourceFiles(file: ExternalAsset, code?: string, bundleContent?: string[]): (imports?: Record<string, string | undefined>) => SourceInput | undefined;
|
|
40
|
+
resolveSourceFile(file: ExternalAsset): (code?: string, imports?: Record<string, string | undefined>) => SourceInput<string> | undefined;
|
|
41
|
+
tryParse(source: string, format: string, options?: Record<string | number | symbol, unknown>): unknown;
|
|
42
|
+
forDb(item: DataSource): boolean;
|
|
43
|
+
hasEval(name: string): boolean;
|
|
44
|
+
settingsOf(name: keyof DocumentComponent, option: keyof DocumentComponentOption): unknown;
|
|
45
|
+
parseTemplate(viewEngine: ViewEngine | string, template: string, data: unknown[]): Promise<string | null>;
|
|
46
|
+
transform(type: string, code: string, format: string | string[], options?: TransformOutput & TransformAction): Promise<TransformResult | void>;
|
|
47
|
+
abort(name?: keyof DocumentComponent | Error, reason?: unknown): void;
|
|
48
|
+
restart(): void;
|
|
49
|
+
using?(data: IFileThread): Promise<unknown>;
|
|
50
|
+
setLocalUri?(file: ExternalAsset, replace?: boolean): void;
|
|
51
|
+
resolveUri?(file: ExternalAsset, source: string): string;
|
|
52
|
+
resolveUri?(file: ExternalAsset, source: string, trailing: string): [string, string];
|
|
53
|
+
resolveImports?(file: ExternalAsset, code: string, baseFile?: string | ExternalAsset): string | undefined;
|
|
54
|
+
replaceContent?(source: string, statement: RegExpExecArray | string, mimeType?: string): string | undefined;
|
|
55
|
+
addCopy?(data: FileCommand<ExternalAsset>, saveAs: string, replace?: boolean): string | undefined;
|
|
56
|
+
writeImage?(output: OutputFinalize<ExternalAsset>): boolean;
|
|
57
|
+
cloudInit?(state: IScopeOrigin<IFileManager, ICloud>): void;
|
|
58
|
+
cloudObject?(state: IScopeOrigin<IFileManager, ICloud>, file: ExternalAsset): boolean;
|
|
59
|
+
cloudUpload?(state: IScopeOrigin<IFileManager, ICloud>, file: ExternalAsset, url: string, active: boolean): Promise<boolean>;
|
|
60
|
+
cloudFinalize?(state: IScopeOrigin<IFileManager, ICloud>): Promise<unknown[]>;
|
|
61
|
+
watchInit?(watch: IFileGroup<ExternalAsset>, assets: ExternalAsset[], sanitize?: boolean): WatchInitResult | undefined;
|
|
62
|
+
watchModified?(watch: IFileGroup<ExternalAsset>, assets?: ExternalAsset[]): PostFinalizeCallback;
|
|
63
|
+
set dataSource(value: DataSource[]);
|
|
64
|
+
get dataSource(): DataSource[];
|
|
65
|
+
set imports(value);
|
|
66
|
+
get imports(): Record<string, string | undefined>;
|
|
67
|
+
get watching(): boolean;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
interface DocumentConstructor extends ModuleConstructor {
|
|
71
|
+
finalize(this: IFileManager, instance: IDocument): Promise<unknown>;
|
|
72
|
+
createSourceMap(code: string, remove: boolean): SourceMap;
|
|
73
|
+
createSourceMap(code: string, uri?: string, remove?: boolean): SourceMap;
|
|
74
|
+
writeSourceMap(uri: string, data: SourceCode, options?: SourceMapOptions): string | undefined;
|
|
75
|
+
updateGradle(source: string, namespaces: string[], value: string, options?: UpdateGradleOptions | boolean): string;
|
|
76
|
+
generateLintTable(messages: LintMessage[], options: GenerateLintTableOptions): LogComponent[];
|
|
77
|
+
/* @deprecated - IDocument.using */
|
|
78
|
+
using?(this: IFileManager, instance: IDocument, file: ExternalAsset): Promise<unknown>;
|
|
79
|
+
cleanup?(this: IFileManager, instance: IDocument): Promise<unknown>;
|
|
80
|
+
sanitizeAssets?(assets: ExternalAsset[], exclusions?: ExternalAsset[]): ExternalAsset[];
|
|
81
|
+
readonly prototype: IDocument;
|
|
82
|
+
new(module?: DocumentModule, ...args: unknown[]): IDocument;
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## References
|
|
87
|
+
|
|
88
|
+
- https://www.unpkg.com/@e-mc/types@0.8.7/lib/squared.d.ts
|
|
89
|
+
- https://www.unpkg.com/@e-mc/types@0.8.7/lib/asset.d.ts
|
|
90
|
+
- https://www.unpkg.com/@e-mc/types@0.8.7/lib/core.d.ts
|
|
91
|
+
- https://www.unpkg.com/@e-mc/types@0.8.7/lib/document.d.ts
|
|
92
|
+
- https://www.unpkg.com/@e-mc/types@0.8.7/lib/filemanager.d.ts
|
|
93
|
+
- https://www.unpkg.com/@e-mc/types@0.8.7/lib/logger.d.ts
|
|
94
|
+
- https://www.unpkg.com/@e-mc/types@0.8.7/lib/settings.d.ts
|
|
95
|
+
- https://www.unpkg.com/@e-mc/types@0.8.7/lib/watch.d.ts
|
|
4
96
|
|
|
5
97
|
## LICENSE
|
|
6
98
|
|
|
7
|
-
|
|
99
|
+
BSD 3-Clause
|
package/index.js
CHANGED
|
@@ -5,12 +5,12 @@ const fs = require("fs");
|
|
|
5
5
|
const pm = require("picomatch");
|
|
6
6
|
const yaml = require("js-yaml");
|
|
7
7
|
const chalk = require("chalk");
|
|
8
|
-
const types_1 = require("
|
|
9
|
-
const core_1 = require("
|
|
10
|
-
const db_1 = require("
|
|
11
|
-
const util_1 = require("
|
|
12
|
-
const transform_1 = require("
|
|
13
|
-
const parse_1 = require("
|
|
8
|
+
const types_1 = require("@e-mc/types");
|
|
9
|
+
const core_1 = require("@e-mc/core");
|
|
10
|
+
const db_1 = require("@e-mc/db");
|
|
11
|
+
const util_1 = require("@e-mc/document/util");
|
|
12
|
+
const transform_1 = require("@e-mc/document/transform");
|
|
13
|
+
const parse_1 = require("@e-mc/document/parse");
|
|
14
14
|
const PLATFORM_WIN32 = process.platform === 'win32';
|
|
15
15
|
const CACHE_PACKAGE = {};
|
|
16
16
|
const CACHE_REQUIRE = {};
|
|
@@ -95,17 +95,16 @@ class Document extends core_1.Client {
|
|
|
95
95
|
}
|
|
96
96
|
try {
|
|
97
97
|
const args = [instance];
|
|
98
|
-
|
|
99
|
-
if (ext["__cjs__" /* INTERNAL.CJS */]) {
|
|
98
|
+
if (ext["__cjs__"]) {
|
|
100
99
|
args.push(__dirname);
|
|
101
100
|
}
|
|
102
|
-
else if (core_1.Client.enabled("node.require.inline"
|
|
101
|
+
else if (core_1.Client.enabled("node.require.inline")) {
|
|
103
102
|
args.push(require);
|
|
104
103
|
}
|
|
105
104
|
await ext.apply(this, args);
|
|
106
105
|
}
|
|
107
106
|
catch (err) {
|
|
108
|
-
instance.writeFail(["Unknown"
|
|
107
|
+
instance.writeFail(["Unknown", this.moduleName], err);
|
|
109
108
|
}
|
|
110
109
|
}
|
|
111
110
|
}
|
|
@@ -127,7 +126,7 @@ class Document extends core_1.Client {
|
|
|
127
126
|
map.sources = [""];
|
|
128
127
|
}
|
|
129
128
|
try {
|
|
130
|
-
let css = mimeType === 'text/css', flags = 0
|
|
129
|
+
let css = mimeType === 'text/css', flags = 0;
|
|
131
130
|
const output = JSON.stringify(map);
|
|
132
131
|
const toBase64 = () => 'data:application/json;base64,' + Buffer.from(output).toString('base64');
|
|
133
132
|
if (!inlineMap) {
|
|
@@ -148,24 +147,24 @@ class Document extends core_1.Client {
|
|
|
148
147
|
}
|
|
149
148
|
}
|
|
150
149
|
let code = data.code.replace(transform_1.SourceMap.RE_SOURCE_MAPPING_URL, (...capture) => {
|
|
151
|
-
flags |= 1
|
|
150
|
+
flags |= 1;
|
|
152
151
|
if (capture[2] && capture[5]) {
|
|
153
152
|
css = true;
|
|
154
153
|
}
|
|
155
154
|
if (inlineMap || capture[3]) {
|
|
156
|
-
flags |= 2
|
|
155
|
+
flags |= 2;
|
|
157
156
|
return getSourceMappingURL(toBase64(), css);
|
|
158
157
|
}
|
|
159
158
|
return capture[1] || css ? getSourceMappingURL(sourceMappingURL, css) : capture[0];
|
|
160
159
|
});
|
|
161
|
-
if (inlineMap || flags & 2
|
|
162
|
-
if (flags === 0
|
|
160
|
+
if (inlineMap || flags & 2) {
|
|
161
|
+
if (flags === 0) {
|
|
163
162
|
code += getSourceMappingURL(toBase64(), css);
|
|
164
163
|
}
|
|
165
164
|
data.code = code;
|
|
166
165
|
}
|
|
167
166
|
else {
|
|
168
|
-
if (flags === 0
|
|
167
|
+
if (flags === 0) {
|
|
169
168
|
code += getSourceMappingURL(sourceMappingURL, css);
|
|
170
169
|
}
|
|
171
170
|
const result = path.join(path.dirname(uri), sourceMappingURL);
|
|
@@ -219,7 +218,7 @@ class Document extends core_1.Client {
|
|
|
219
218
|
let match;
|
|
220
219
|
while (match = pattern.exec(source)) {
|
|
221
220
|
const preceding = source.substring(lastIndex, match.index);
|
|
222
|
-
let opening = 0, closing =
|
|
221
|
+
let opening = 0, closing = 0;
|
|
223
222
|
for (let j = 0, q = preceding.length; j < q; ++j) {
|
|
224
223
|
switch (preceding[j]) {
|
|
225
224
|
case '{':
|
|
@@ -230,8 +229,11 @@ class Document extends core_1.Client {
|
|
|
230
229
|
break;
|
|
231
230
|
}
|
|
232
231
|
}
|
|
233
|
-
if (opening === closing
|
|
234
|
-
|
|
232
|
+
if (opening === closing) {
|
|
233
|
+
if (!multiple || match[1] && sanitizeValue(match[1]) === sanitizeValue(local[3])) {
|
|
234
|
+
return upgrade ? parse_1.XmlWriter.replaceMatch(match, source, value, pattern) : source;
|
|
235
|
+
}
|
|
236
|
+
lastIndex = match.index + match[0].length;
|
|
235
237
|
}
|
|
236
238
|
}
|
|
237
239
|
return spliceSource(source, lastIndex, lastIndex, ident.repeat(length) + value + newline);
|
|
@@ -276,7 +278,7 @@ class Document extends core_1.Client {
|
|
|
276
278
|
for (const { severity, line, column, ruleId, message, fatal } of messages) {
|
|
277
279
|
let error;
|
|
278
280
|
if (severity) {
|
|
279
|
-
if (error = severity === 2
|
|
281
|
+
if (error = severity === 2 || severity === "error") {
|
|
280
282
|
++errorCount;
|
|
281
283
|
}
|
|
282
284
|
else {
|
|
@@ -389,19 +391,18 @@ class Document extends core_1.Client {
|
|
|
389
391
|
const handler = db.handler;
|
|
390
392
|
const database = this.dataSource.filter(this.forDb.bind(this));
|
|
391
393
|
let instance;
|
|
392
|
-
if ((0, types_1.isString)(handler) && handler !== "@e-mc/db"
|
|
394
|
+
if ((0, types_1.isString)(handler) && handler !== "@e-mc/db") {
|
|
393
395
|
try {
|
|
394
396
|
const Handler = require(handler);
|
|
395
397
|
if (isFunction(Handler) && Handler.prototype instanceof core_1.ClientDb) {
|
|
396
|
-
// @ts-ignore
|
|
397
398
|
instance = new Handler(db, database);
|
|
398
399
|
}
|
|
399
400
|
else {
|
|
400
|
-
throw (0, types_1.errorMessage)(this.moduleName, "Not a Db constructor"
|
|
401
|
+
throw (0, types_1.errorMessage)(this.moduleName, "Not a Db constructor", handler);
|
|
401
402
|
}
|
|
402
403
|
}
|
|
403
404
|
catch (err) {
|
|
404
|
-
this.checkPackage(err, handler, ["Unable to load handler"
|
|
405
|
+
this.checkPackage(err, handler, ["Unable to load handler", this.moduleName], 65536);
|
|
405
406
|
}
|
|
406
407
|
}
|
|
407
408
|
else {
|
|
@@ -578,7 +579,7 @@ class Document extends core_1.Client {
|
|
|
578
579
|
return getObject(result, false);
|
|
579
580
|
}
|
|
580
581
|
else {
|
|
581
|
-
warning(path.isAbsolute(value) ? "Unsupported access"
|
|
582
|
+
warning(path.isAbsolute(value) ? "Unsupported access" + ` (${value})` : "Unknown");
|
|
582
583
|
}
|
|
583
584
|
break;
|
|
584
585
|
}
|
|
@@ -621,7 +622,7 @@ class Document extends core_1.Client {
|
|
|
621
622
|
result = CACHE_REQUIRE[pkgName];
|
|
622
623
|
}
|
|
623
624
|
if (!result) {
|
|
624
|
-
if (!core_1.Client.enabled("node.require.npm"
|
|
625
|
+
if (!core_1.Client.enabled("node.require.npm")) {
|
|
625
626
|
return null;
|
|
626
627
|
}
|
|
627
628
|
try {
|
|
@@ -630,11 +631,11 @@ class Document extends core_1.Client {
|
|
|
630
631
|
CACHE_REQUIRE[pkgName] = result;
|
|
631
632
|
}
|
|
632
633
|
if (typeof result === 'function') {
|
|
633
|
-
return Object.defineProperty(result, "__cjs__"
|
|
634
|
+
return Object.defineProperty(result, "__cjs__", { value: true });
|
|
634
635
|
}
|
|
635
636
|
}
|
|
636
637
|
catch (err) {
|
|
637
|
-
this.checkPackage(err, pkgName, "Unknown"
|
|
638
|
+
this.checkPackage(err, pkgName, "Unknown");
|
|
638
639
|
}
|
|
639
640
|
if (!result) {
|
|
640
641
|
return null;
|
|
@@ -653,13 +654,12 @@ class Document extends core_1.Client {
|
|
|
653
654
|
catch {
|
|
654
655
|
}
|
|
655
656
|
}
|
|
656
|
-
|
|
657
|
-
if ((0, types_1.isObject)(result) || typeof result === 'function' && (result["__cjs__" /* INTERNAL.CJS */] || this.hasEval('function'))) {
|
|
657
|
+
if ((0, types_1.isObject)(result) || typeof result === 'function' && (result["__cjs__"] || this.hasEval('function'))) {
|
|
658
658
|
return result;
|
|
659
659
|
}
|
|
660
660
|
}
|
|
661
661
|
catch (err) {
|
|
662
|
-
this.writeFail(["Unable to read file"
|
|
662
|
+
this.writeFail(["Unable to read file", path.basename(value)], err, 8192);
|
|
663
663
|
}
|
|
664
664
|
return null;
|
|
665
665
|
}
|
|
@@ -809,7 +809,7 @@ class Document extends core_1.Client {
|
|
|
809
809
|
}
|
|
810
810
|
}
|
|
811
811
|
catch (err) {
|
|
812
|
-
this.writeFail(["Unable to read file"
|
|
812
|
+
this.writeFail(["Unable to read file", localUri && path.basename(localUri)], 32);
|
|
813
813
|
}
|
|
814
814
|
}
|
|
815
815
|
else if (bundleContent) {
|
|
@@ -865,7 +865,7 @@ class Document extends core_1.Client {
|
|
|
865
865
|
catch (err) {
|
|
866
866
|
const name = (0, util_1.getModuleName)(err);
|
|
867
867
|
if (name) {
|
|
868
|
-
this.checkPackage(err, (0, util_1.getModuleName)(err), "Unknown"
|
|
868
|
+
this.checkPackage(err, (0, util_1.getModuleName)(err), "Unknown");
|
|
869
869
|
}
|
|
870
870
|
throw err;
|
|
871
871
|
}
|
|
@@ -903,7 +903,7 @@ class Document extends core_1.Client {
|
|
|
903
903
|
if (!((0, types_1.isPlainObject)(target) && target.name)) {
|
|
904
904
|
this.abort('view_engine');
|
|
905
905
|
const from = typeof viewEngine === 'string' ? viewEngine : this.moduleName;
|
|
906
|
-
this.writeFail(["Unable to load configuration"
|
|
906
|
+
this.writeFail(["Unable to load configuration", from], (0, types_1.errorMessage)('view-engine', from, "Unknown"));
|
|
907
907
|
return null;
|
|
908
908
|
}
|
|
909
909
|
const length = data.length;
|
|
@@ -931,10 +931,10 @@ class Document extends core_1.Client {
|
|
|
931
931
|
const cacheKey = username + core_1.Client.asHash(template + (compile ? core_1.Client.asString(compile) : ''));
|
|
932
932
|
let result = '', render, valid;
|
|
933
933
|
if (!(render = cache[cacheKey])) {
|
|
934
|
-
render = await context.compile(template, compile);
|
|
934
|
+
render = await context.compile(template, compile);
|
|
935
935
|
cache[cacheKey] = render;
|
|
936
|
-
if (!core_1.Client.enabled("memory.settings.users"
|
|
937
|
-
setTimeout(() => delete cache[cacheKey], 60000
|
|
936
|
+
if (!core_1.Client.enabled("memory.settings.users", username)) {
|
|
937
|
+
setTimeout(() => delete cache[cacheKey], 60000);
|
|
938
938
|
}
|
|
939
939
|
}
|
|
940
940
|
for (let i = 0, j = 0, row; i < length; ++i) {
|
|
@@ -945,11 +945,11 @@ class Document extends core_1.Client {
|
|
|
945
945
|
}
|
|
946
946
|
}
|
|
947
947
|
else if (!(0, types_1.isObject)(row)) {
|
|
948
|
-
this.addLog(types_1.STATUS_TYPE.WARN, joinString(`view engine[${name}]`, `row #${i + 1}`, core_1.Client.asString(row) || "Unknown"
|
|
948
|
+
this.addLog(types_1.STATUS_TYPE.WARN, joinString(`view engine[${name}]`, `row #${i + 1}`, core_1.Client.asString(row) || "Unknown"));
|
|
949
949
|
continue;
|
|
950
950
|
}
|
|
951
951
|
if (!singleRow) {
|
|
952
|
-
const content = await render.call(context, row);
|
|
952
|
+
const content = await render.call(context, row);
|
|
953
953
|
if (content !== undefined && content !== null) {
|
|
954
954
|
result += content;
|
|
955
955
|
valid = true;
|
|
@@ -960,7 +960,7 @@ class Document extends core_1.Client {
|
|
|
960
960
|
}
|
|
961
961
|
catch (err) {
|
|
962
962
|
this.abort('view_engine');
|
|
963
|
-
this.checkPackage(err, name, "Unknown"
|
|
963
|
+
this.checkPackage(err, name, "Unknown", 4);
|
|
964
964
|
}
|
|
965
965
|
return null;
|
|
966
966
|
}
|
|
@@ -974,7 +974,7 @@ class Document extends core_1.Client {
|
|
|
974
974
|
const username = this.host?.username || '';
|
|
975
975
|
const config = this._transformConfig;
|
|
976
976
|
const cacheData = config && options.cacheData;
|
|
977
|
-
const cacheType = username && core_1.Client.enabled("memory.settings.users"
|
|
977
|
+
const cacheType = username && core_1.Client.enabled("memory.settings.users", username) ? true : this.cacheDir || core_1.Client.enabled("memory.settings.users");
|
|
978
978
|
let formatKey, hashKey, excludeKey;
|
|
979
979
|
if (cacheData && cacheType && !CACHE_EXTERNAL[excludeKey = moduleName + '_' + type + '_' + format] && (!config.exclude[type] || Array.isArray(config.exclude[type]) && !format.some(value => config.exclude[type].includes(value)) || Array.isArray(config.include[type]) && format.every(value => config.include[type].includes(value)))) {
|
|
980
980
|
const { uri, etag } = cacheData;
|
|
@@ -1050,7 +1050,7 @@ class Document extends core_1.Client {
|
|
|
1050
1050
|
}
|
|
1051
1051
|
if (result) {
|
|
1052
1052
|
result.storedLog?.forEach(log => this.addLog(log));
|
|
1053
|
-
this.formatMessage(4
|
|
1053
|
+
this.formatMessage(4, type, [joinString(cacheName, format.filter(value => value).join(' | '), options.filename), 'cache'], uri, { ...core_1.Client.LOG_STYLE_NOTICE, hintBold: true });
|
|
1054
1054
|
return result;
|
|
1055
1055
|
}
|
|
1056
1056
|
}
|
|
@@ -1128,7 +1128,7 @@ class Document extends core_1.Client {
|
|
|
1128
1128
|
if (typeof value !== 'string' || (0, types_1.isArray)(out.sourceFiles) && this.hasOwnPermission() && out.sourceFiles.some(item => !this.canRead(item, { ownPermissionOnly: true }))) {
|
|
1129
1129
|
failed = true;
|
|
1130
1130
|
ignoreCache = true;
|
|
1131
|
-
this.writeFail(["Unable to transform document"
|
|
1131
|
+
this.writeFail(["Unable to transform document", plugin], (0, types_1.errorMessage)(plugin, name, typeof value === 'string' ? "Unsupported access" : 'Empty'), { type: 4, startTime });
|
|
1132
1132
|
}
|
|
1133
1133
|
else if (source !== value) {
|
|
1134
1134
|
series.code = value;
|
|
@@ -1160,19 +1160,18 @@ class Document extends core_1.Client {
|
|
|
1160
1160
|
}
|
|
1161
1161
|
this.writeTimeProcess(failed ? 'CHECK' : type, joinString(hint, options.filename) + (series.out.messageAppend || ''), startTime, { failed, bypassLog });
|
|
1162
1162
|
};
|
|
1163
|
-
this.formatMessage(4
|
|
1163
|
+
this.formatMessage(4, type, ['Transforming source...', hint], options.filename, { hintColor: 'cyan' });
|
|
1164
1164
|
try {
|
|
1165
1165
|
let context = require(plugin);
|
|
1166
1166
|
series.packageName = plugin;
|
|
1167
1167
|
if (typeof baseConfig === 'function') {
|
|
1168
1168
|
series.baseConfig = outputConfig;
|
|
1169
|
-
|
|
1170
|
-
if (baseConfig["__cjs__" /* INTERNAL.CJS */]) {
|
|
1169
|
+
if (baseConfig["__cjs__"]) {
|
|
1171
1170
|
next(await baseConfig(context, source, series));
|
|
1172
1171
|
}
|
|
1173
1172
|
else {
|
|
1174
|
-
const thisArg = core_1.Client.enabled("node.process.inline"
|
|
1175
|
-
const inline = core_1.Client.enabled("node.require.inline"
|
|
1173
|
+
const thisArg = core_1.Client.enabled("node.process.inline") ? process : null;
|
|
1174
|
+
const inline = core_1.Client.enabled("node.require.inline");
|
|
1176
1175
|
const args = [context, source, series];
|
|
1177
1176
|
if (baseConfig.toString().startsWith('async')) {
|
|
1178
1177
|
if (inline) {
|
|
@@ -1206,7 +1205,7 @@ class Document extends core_1.Client {
|
|
|
1206
1205
|
}
|
|
1207
1206
|
else {
|
|
1208
1207
|
transformer = context;
|
|
1209
|
-
context = this;
|
|
1208
|
+
context = this;
|
|
1210
1209
|
pkg = undefined;
|
|
1211
1210
|
}
|
|
1212
1211
|
if (transformer && typeof transformer !== 'function') {
|
|
@@ -1221,7 +1220,7 @@ class Document extends core_1.Client {
|
|
|
1221
1220
|
}
|
|
1222
1221
|
catch (err) {
|
|
1223
1222
|
abort();
|
|
1224
|
-
this.writeFail(["Unknown"
|
|
1223
|
+
this.writeFail(["Unknown", username ? plugin + ':' + username : hint], err, { type: 4, startTime });
|
|
1225
1224
|
continue;
|
|
1226
1225
|
}
|
|
1227
1226
|
}
|
|
@@ -1231,7 +1230,7 @@ class Document extends core_1.Client {
|
|
|
1231
1230
|
}
|
|
1232
1231
|
catch (err) {
|
|
1233
1232
|
abort();
|
|
1234
|
-
this.checkPackage(err, (0, util_1.getModuleName)(err), ["Unable to transform document"
|
|
1233
|
+
this.checkPackage(err, (0, util_1.getModuleName)(err), ["Unable to transform document", hint], { type: 4, startTime });
|
|
1235
1234
|
if (i < length - 1) {
|
|
1236
1235
|
series.reset();
|
|
1237
1236
|
}
|
|
@@ -1240,10 +1239,10 @@ class Document extends core_1.Client {
|
|
|
1240
1239
|
else {
|
|
1241
1240
|
abort();
|
|
1242
1241
|
if (plugin) {
|
|
1243
|
-
this.writeFail("Unable to load configuration"
|
|
1242
|
+
this.writeFail("Unable to load configuration", (0, types_1.errorMessage)(plugin, name, 'Invalid config'), 4);
|
|
1244
1243
|
}
|
|
1245
1244
|
else {
|
|
1246
|
-
this.writeFail('Format method was not found', (0, types_1.errorValue)(name, "Unknown"
|
|
1245
|
+
this.writeFail('Format method was not found', (0, types_1.errorValue)(name, "Unknown"), 4);
|
|
1247
1246
|
}
|
|
1248
1247
|
}
|
|
1249
1248
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@e-mc/document",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.7",
|
|
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": "BSD 3-Clause",
|
|
21
21
|
"homepage": "https://github.com/anpham6/e-mc#readme",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@e-mc/core": "0.8.
|
|
24
|
-
"@e-mc/db": "0.8.
|
|
25
|
-
"@e-mc/types": "0.8.
|
|
23
|
+
"@e-mc/core": "0.8.7",
|
|
24
|
+
"@e-mc/db": "0.8.7",
|
|
25
|
+
"@e-mc/types": "0.8.7",
|
|
26
26
|
"chalk": "4.1.2",
|
|
27
27
|
"htmlparser2": "^9.1.0",
|
|
28
28
|
"js-yaml": "^4.1.0",
|
package/parse/dom.js
CHANGED
|
@@ -4,9 +4,9 @@ exports.IGNORE_FLAG = exports.HtmlElement = exports.DomWriter = void 0;
|
|
|
4
4
|
const htmlparser2 = require("htmlparser2");
|
|
5
5
|
const domhandler = require("domhandler");
|
|
6
6
|
const domutils = require("domutils");
|
|
7
|
-
const types_1 = require("
|
|
8
|
-
const util_1 = require("
|
|
9
|
-
const index_1 = require("
|
|
7
|
+
const types_1 = require("@e-mc/types");
|
|
8
|
+
const util_1 = require("@e-mc/document/util");
|
|
9
|
+
const index_1 = require("@e-mc/document/parse");
|
|
10
10
|
Object.defineProperty(exports, "IGNORE_FLAG", { enumerable: true, get: function () { return index_1.IGNORE_FLAG; } });
|
|
11
11
|
const Parser = htmlparser2.Parser;
|
|
12
12
|
const DomHandler = domhandler.DomHandler;
|
|
@@ -89,7 +89,7 @@ class DomWriter extends index_1.XmlWriter {
|
|
|
89
89
|
const result = { element: null, error: null };
|
|
90
90
|
new Parser(new DomHandler((err, dom) => {
|
|
91
91
|
if (!err) {
|
|
92
|
-
result.element = domutils.findOne(elem => elem.tagName === "html"
|
|
92
|
+
result.element = domutils.findOne(elem => elem.tagName === "html", dom);
|
|
93
93
|
}
|
|
94
94
|
else {
|
|
95
95
|
result.error = err;
|
|
@@ -111,8 +111,8 @@ class DomWriter extends index_1.XmlWriter {
|
|
|
111
111
|
parser || (parser = { ...PARSER_OPTIONS });
|
|
112
112
|
super(documentName, source, elements, { parser });
|
|
113
113
|
this.documentElement = null;
|
|
114
|
-
this.ignoreTagName = "title|style|script"
|
|
115
|
-
this.rootName = "html"
|
|
114
|
+
this.ignoreTagName = "title|style|script";
|
|
115
|
+
this.rootName = "html";
|
|
116
116
|
this.ignoreCaseTagName = true;
|
|
117
117
|
const items = [];
|
|
118
118
|
let outerXml = '', documentElement, offsetMap, startIndex = -1;
|
|
@@ -121,7 +121,7 @@ class DomWriter extends index_1.XmlWriter {
|
|
|
121
121
|
item.tagName = item.tagName.toLowerCase();
|
|
122
122
|
item.ignoreCase = true;
|
|
123
123
|
}
|
|
124
|
-
if (item.tagName === "html"
|
|
124
|
+
if (item.tagName === "html") {
|
|
125
125
|
items.push(item);
|
|
126
126
|
if (!documentElement && item.innerXml) {
|
|
127
127
|
documentElement = item;
|
|
@@ -198,7 +198,7 @@ class DomWriter extends index_1.XmlWriter {
|
|
|
198
198
|
if (this.modified && this.documentElement) {
|
|
199
199
|
let innerXml;
|
|
200
200
|
for (const item of this.elements) {
|
|
201
|
-
if (item.tagName === "html"
|
|
201
|
+
if (item.tagName === "html") {
|
|
202
202
|
if (!innerXml && index_1.XmlWriter.isIndex(item.endIndex)) {
|
|
203
203
|
innerXml = this.source.substring(item.endIndex + 1, this.source.length - 7).trim();
|
|
204
204
|
}
|
|
@@ -223,7 +223,7 @@ class HtmlElement extends index_1.XmlElement {
|
|
|
223
223
|
constructor(documentName, node, attributes, options = {}) {
|
|
224
224
|
options.parser || (options.parser = { ...PARSER_OPTIONS });
|
|
225
225
|
super(documentName, node, attributes, { ...options, tagVoid: TAG_VOID.includes(node.tagName) });
|
|
226
|
-
this._documentType = "HTML"
|
|
226
|
+
this._documentType = "HTML";
|
|
227
227
|
}
|
|
228
228
|
getTagOffset(source) {
|
|
229
229
|
switch (this.node.append?.tagName || this.tagName) {
|
|
@@ -233,7 +233,7 @@ class HtmlElement extends index_1.XmlElement {
|
|
|
233
233
|
case 'script':
|
|
234
234
|
return;
|
|
235
235
|
default:
|
|
236
|
-
return super.getTagOffset(source, { ignoreCase: this.ignoreCase, ignoreTagName: "title|style|script"
|
|
236
|
+
return super.getTagOffset(source, { ignoreCase: this.ignoreCase, ignoreTagName: "title|style|script", parser: this.parser });
|
|
237
237
|
}
|
|
238
238
|
}
|
|
239
239
|
findIndexOf(source) {
|
|
@@ -244,8 +244,8 @@ class HtmlElement extends index_1.XmlElement {
|
|
|
244
244
|
}
|
|
245
245
|
get outerXml() {
|
|
246
246
|
const [tagName, items, innerXml] = this.getOuterContent();
|
|
247
|
-
return '<' + tagName + HtmlElement.writeAttributes(items) + '>' + (DomWriter.hasInnerXml(tagName) && tagName !== "html"
|
|
247
|
+
return '<' + tagName + HtmlElement.writeAttributes(items) + '>' + (DomWriter.hasInnerXml(tagName) && tagName !== "html" ? (tagName === 'title' ? index_1.XmlWriter.escapeXmlString(innerXml) : innerXml) + `</${tagName}>` : '');
|
|
248
248
|
}
|
|
249
249
|
}
|
|
250
250
|
exports.HtmlElement = HtmlElement;
|
|
251
|
-
index_1.XmlWriter.namesOfTagVoid("HTML"
|
|
251
|
+
index_1.XmlWriter.namesOfTagVoid("HTML", TAG_VOID);
|
package/parse/index.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
/* eslint @typescript-eslint/prefer-includes: off */
|
|
3
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
3
|
exports.XmlElement = exports.XmlWriter = exports.IGNORE_FLAG = void 0;
|
|
5
4
|
const htmlparser2 = require("htmlparser2");
|
|
6
5
|
const domhandler = require("domhandler");
|
|
7
6
|
const domutils = require("domutils");
|
|
8
|
-
const types_1 = require("
|
|
9
|
-
const module_1 = require("
|
|
7
|
+
const types_1 = require("@e-mc/types");
|
|
8
|
+
const module_1 = require("@e-mc/module");
|
|
10
9
|
var IGNORE_FLAG;
|
|
11
10
|
(function (IGNORE_FLAG) {
|
|
12
11
|
IGNORE_FLAG[IGNORE_FLAG["NONE"] = 0] = "NONE";
|
package/transform/index.js
CHANGED
|
@@ -3,8 +3,8 @@ var _a, _b, _c, _d;
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.SourceMap = exports.TransformSeries = void 0;
|
|
5
5
|
const path = require("path");
|
|
6
|
-
const types_1 = require("
|
|
7
|
-
const core_1 = require("
|
|
6
|
+
const types_1 = require("@e-mc/types");
|
|
7
|
+
const core_1 = require("@e-mc/core");
|
|
8
8
|
const kCode = Symbol('code');
|
|
9
9
|
const kMap = Symbol('map');
|
|
10
10
|
const kOut = Symbol('out');
|
|
@@ -185,20 +185,16 @@ class TransformSeries extends core_1.Module {
|
|
|
185
185
|
return this.options.external;
|
|
186
186
|
}
|
|
187
187
|
set version(value) {
|
|
188
|
-
// @ts-ignore
|
|
189
188
|
this.metadata.__version__ = value;
|
|
190
189
|
}
|
|
191
190
|
get version() {
|
|
192
|
-
// @ts-ignore
|
|
193
191
|
return this.metadata.__version__ || '';
|
|
194
192
|
}
|
|
195
193
|
set packageName(value) {
|
|
196
|
-
// @ts-ignore
|
|
197
194
|
this.metadata.__packagename__ = value;
|
|
198
195
|
this.version = 'latest';
|
|
199
196
|
}
|
|
200
197
|
get packageName() {
|
|
201
|
-
// @ts-ignore
|
|
202
198
|
return this.metadata.__packagename__ || '';
|
|
203
199
|
}
|
|
204
200
|
get packageVersion() {
|
package/util.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isObject = exports.removeInternalProperties = exports.getModuleName = exports.hasValue = exports.getHashData = exports.getNewline = exports.getIndent = exports.appendSuffix = exports.splitEnclosing = exports.concatString = exports.replaceAll = exports.loadPlugins = exports.IMPORTS = void 0;
|
|
4
4
|
const path = require("path");
|
|
5
|
-
const types_1 = require("
|
|
5
|
+
const types_1 = require("@e-mc/types");
|
|
6
6
|
Object.defineProperty(exports, "isObject", { enumerable: true, get: function () { return types_1.isObject; } });
|
|
7
7
|
exports.IMPORTS = {
|
|
8
8
|
"@babel/core": "@pi-r/babel",
|
|
@@ -50,7 +50,7 @@ function replaceAll(source, valueOf, opening = '{{', closing = '}}') {
|
|
|
50
50
|
exports.replaceAll = replaceAll;
|
|
51
51
|
function concatString(values, newline) {
|
|
52
52
|
if ((0, types_1.isArray)(values)) {
|
|
53
|
-
newline || (newline = values.find(item => item.indexOf('\r') !== -1) ? '\r\n' : '\n');
|
|
53
|
+
newline || (newline = values.find(item => item.indexOf('\r') !== -1) ? '\r\n' : '\n');
|
|
54
54
|
return values.reduce((a, b) => a + newline + b, '');
|
|
55
55
|
}
|
|
56
56
|
return typeof values === 'string' ? values : '';
|