@e-mc/document 0.7.1 → 0.7.2
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 +1 -1
- package/README.md +5 -3
- package/index.js +58 -64
- package/package.json +6 -6
- package/parse/dom.js +13 -13
- package/parse/index.js +6 -6
- package/transform/index.js +3 -7
- package/util.js +1 -1
package/LICENSE
CHANGED
package/README.md
CHANGED
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 CACHE_PACKAGE = {};
|
|
15
15
|
const CACHE_REQUIRE = {};
|
|
16
16
|
const CACHE_ETAG = {};
|
|
@@ -34,7 +34,7 @@ function deleteTransform(map, key, timeout) {
|
|
|
34
34
|
--CACHE_TOTAL;
|
|
35
35
|
}
|
|
36
36
|
function getSourceMappingURL(value, css) {
|
|
37
|
-
if (value.
|
|
37
|
+
if (value.includes(' ')) {
|
|
38
38
|
value = encodeURIComponent(value);
|
|
39
39
|
}
|
|
40
40
|
return css ? `\n/*# sourceMappingURL=${value} */\n` : `\n//# sourceMappingURL=${value}\n`;
|
|
@@ -94,17 +94,16 @@ class Document extends core_1.Client {
|
|
|
94
94
|
}
|
|
95
95
|
try {
|
|
96
96
|
const args = [instance];
|
|
97
|
-
|
|
98
|
-
if (ext["__cjs__" /* INTERNAL.CJS */]) {
|
|
97
|
+
if (ext["__cjs__"]) {
|
|
99
98
|
args.push(__dirname);
|
|
100
99
|
}
|
|
101
|
-
else if (core_1.Client.enabled("node.require.inline"
|
|
100
|
+
else if (core_1.Client.enabled("node.require.inline")) {
|
|
102
101
|
args.push(require);
|
|
103
102
|
}
|
|
104
103
|
await ext.apply(this, args);
|
|
105
104
|
}
|
|
106
105
|
catch (err) {
|
|
107
|
-
instance.writeFail(["Unknown"
|
|
106
|
+
instance.writeFail(["Unknown", this.moduleName], err);
|
|
108
107
|
}
|
|
109
108
|
}
|
|
110
109
|
}
|
|
@@ -126,7 +125,7 @@ class Document extends core_1.Client {
|
|
|
126
125
|
map.sources = [""];
|
|
127
126
|
}
|
|
128
127
|
try {
|
|
129
|
-
let css = mimeType === 'text/css', flags = 0
|
|
128
|
+
let css = mimeType === 'text/css', flags = 0;
|
|
130
129
|
const output = JSON.stringify(map);
|
|
131
130
|
const toBase64 = () => 'data:application/json;base64,' + Buffer.from(output).toString('base64');
|
|
132
131
|
if (!inlineMap) {
|
|
@@ -147,24 +146,24 @@ class Document extends core_1.Client {
|
|
|
147
146
|
}
|
|
148
147
|
}
|
|
149
148
|
let code = data.code.replace(transform_1.SourceMap.RE_SOURCE_MAPPING_URL, (...capture) => {
|
|
150
|
-
flags |= 1
|
|
149
|
+
flags |= 1;
|
|
151
150
|
if (capture[2] && capture[5]) {
|
|
152
151
|
css = true;
|
|
153
152
|
}
|
|
154
153
|
if (inlineMap || capture[3]) {
|
|
155
|
-
flags |= 2
|
|
154
|
+
flags |= 2;
|
|
156
155
|
return getSourceMappingURL(toBase64(), css);
|
|
157
156
|
}
|
|
158
157
|
return capture[1] || css ? getSourceMappingURL(sourceMappingURL, css) : capture[0];
|
|
159
158
|
});
|
|
160
|
-
if (inlineMap || flags & 2
|
|
161
|
-
if (flags === 0
|
|
159
|
+
if (inlineMap || flags & 2) {
|
|
160
|
+
if (flags === 0) {
|
|
162
161
|
code += getSourceMappingURL(toBase64(), css);
|
|
163
162
|
}
|
|
164
163
|
data.code = code;
|
|
165
164
|
}
|
|
166
165
|
else {
|
|
167
|
-
if (flags === 0
|
|
166
|
+
if (flags === 0) {
|
|
168
167
|
code += getSourceMappingURL(sourceMappingURL, css);
|
|
169
168
|
}
|
|
170
169
|
const result = path.join(path.dirname(uri), sourceMappingURL);
|
|
@@ -275,7 +274,7 @@ class Document extends core_1.Client {
|
|
|
275
274
|
for (const { severity, line, column, ruleId, message, fatal } of messages) {
|
|
276
275
|
let error;
|
|
277
276
|
if (severity) {
|
|
278
|
-
if (error = severity === 2
|
|
277
|
+
if (error = severity === 2 || severity === "error") {
|
|
279
278
|
++errorCount;
|
|
280
279
|
}
|
|
281
280
|
else {
|
|
@@ -353,20 +352,18 @@ class Document extends core_1.Client {
|
|
|
353
352
|
for (const pattern in pages) {
|
|
354
353
|
const item = pages[pattern];
|
|
355
354
|
if ((0, types_1.isPlainObject)(item)) {
|
|
356
|
-
|
|
357
|
-
if (!(isMatch = CACHE_PICOMATCH.get(pattern)) && (0, types_1.hasGlob)(pattern)) {
|
|
358
|
-
isMatch = pm(pattern, { matchBase: true });
|
|
359
|
-
CACHE_PICOMATCH.set(pattern, isMatch);
|
|
360
|
-
}
|
|
361
|
-
else {
|
|
362
|
-
continue;
|
|
363
|
-
}
|
|
364
|
-
if (isMatch(baseUrl)) {
|
|
355
|
+
if (pattern === baseUrl) {
|
|
365
356
|
items.push(item);
|
|
366
357
|
}
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
358
|
+
else if ((0, types_1.hasGlob)(pattern)) {
|
|
359
|
+
let isMatch = CACHE_PICOMATCH.get(pattern);
|
|
360
|
+
if (!isMatch) {
|
|
361
|
+
CACHE_PICOMATCH.set(pattern, isMatch = pm(pattern, { matchBase: true }));
|
|
362
|
+
}
|
|
363
|
+
if (isMatch(baseUrl)) {
|
|
364
|
+
items.push(item);
|
|
365
|
+
}
|
|
366
|
+
}
|
|
370
367
|
}
|
|
371
368
|
}
|
|
372
369
|
if (items.length > 1) {
|
|
@@ -395,19 +392,18 @@ class Document extends core_1.Client {
|
|
|
395
392
|
const handler = db.handler;
|
|
396
393
|
const database = this.dataSource.filter(this.forDb.bind(this));
|
|
397
394
|
let instance;
|
|
398
|
-
if ((0, types_1.isString)(handler) && handler !== "@e-mc/db"
|
|
395
|
+
if ((0, types_1.isString)(handler) && handler !== "@e-mc/db") {
|
|
399
396
|
try {
|
|
400
397
|
const Handler = require(handler);
|
|
401
398
|
if (isFunction(Handler) && Handler.prototype instanceof core_1.ClientDb) {
|
|
402
|
-
// @ts-ignore
|
|
403
399
|
instance = new Handler(db, database);
|
|
404
400
|
}
|
|
405
401
|
else {
|
|
406
|
-
throw (0, types_1.errorMessage)(this.moduleName, "Not a Db constructor"
|
|
402
|
+
throw (0, types_1.errorMessage)(this.moduleName, "Not a Db constructor", handler);
|
|
407
403
|
}
|
|
408
404
|
}
|
|
409
405
|
catch (err) {
|
|
410
|
-
this.checkPackage(err, handler, ["Unable to load handler"
|
|
406
|
+
this.checkPackage(err, handler, ["Unable to load handler", this.moduleName], 65536);
|
|
411
407
|
}
|
|
412
408
|
}
|
|
413
409
|
else {
|
|
@@ -581,7 +577,7 @@ class Document extends core_1.Client {
|
|
|
581
577
|
return getObject(result, false);
|
|
582
578
|
}
|
|
583
579
|
else {
|
|
584
|
-
warning(path.isAbsolute(value) ? "Unsupported access"
|
|
580
|
+
warning(path.isAbsolute(value) ? "Unsupported access" + ` (${value})` : "Unknown");
|
|
585
581
|
}
|
|
586
582
|
break;
|
|
587
583
|
}
|
|
@@ -624,7 +620,7 @@ class Document extends core_1.Client {
|
|
|
624
620
|
result = CACHE_REQUIRE[pkgName];
|
|
625
621
|
}
|
|
626
622
|
if (!result) {
|
|
627
|
-
if (!core_1.Client.enabled("node.require.npm"
|
|
623
|
+
if (!core_1.Client.enabled("node.require.npm")) {
|
|
628
624
|
return null;
|
|
629
625
|
}
|
|
630
626
|
try {
|
|
@@ -636,11 +632,11 @@ class Document extends core_1.Client {
|
|
|
636
632
|
CACHE_REQUIRE[pkgName] = result;
|
|
637
633
|
}
|
|
638
634
|
if (typeof result === 'function') {
|
|
639
|
-
return Object.defineProperty(result, "__cjs__"
|
|
635
|
+
return Object.defineProperty(result, "__cjs__", { value: true });
|
|
640
636
|
}
|
|
641
637
|
}
|
|
642
638
|
catch (err) {
|
|
643
|
-
this.checkPackage(err, pkgName, "Unknown"
|
|
639
|
+
this.checkPackage(err, pkgName, "Unknown");
|
|
644
640
|
}
|
|
645
641
|
if (!result) {
|
|
646
642
|
return null;
|
|
@@ -659,13 +655,12 @@ class Document extends core_1.Client {
|
|
|
659
655
|
catch {
|
|
660
656
|
}
|
|
661
657
|
}
|
|
662
|
-
|
|
663
|
-
if ((0, types_1.isObject)(result) || typeof result === 'function' && (result["__cjs__" /* INTERNAL.CJS */] || this.hasEval('function'))) {
|
|
658
|
+
if ((0, types_1.isObject)(result) || typeof result === 'function' && (result["__cjs__"] || this.hasEval('function'))) {
|
|
664
659
|
return result;
|
|
665
660
|
}
|
|
666
661
|
}
|
|
667
662
|
catch (err) {
|
|
668
|
-
this.writeFail(["Unable to read file"
|
|
663
|
+
this.writeFail(["Unable to read file", path.basename(value)], err, 8192);
|
|
669
664
|
}
|
|
670
665
|
return null;
|
|
671
666
|
}
|
|
@@ -690,7 +685,7 @@ class Document extends core_1.Client {
|
|
|
690
685
|
if (imports) {
|
|
691
686
|
const normalizeDir = (value) => {
|
|
692
687
|
const sep = value.includes('\\') && !value.includes('/') ? '\\' : '/';
|
|
693
|
-
return value + (value
|
|
688
|
+
return value + (!value.endsWith(sep) ? sep : '');
|
|
694
689
|
};
|
|
695
690
|
for (const url in imports) {
|
|
696
691
|
if (uri === url || normalizeDir(uri) === normalizeDir(url)) {
|
|
@@ -743,7 +738,7 @@ class Document extends core_1.Client {
|
|
|
743
738
|
}
|
|
744
739
|
}
|
|
745
740
|
catch (err) {
|
|
746
|
-
this.writeFail(["Unable to read file"
|
|
741
|
+
this.writeFail(["Unable to read file", localUri && path.basename(localUri)], 32);
|
|
747
742
|
}
|
|
748
743
|
}
|
|
749
744
|
else if (bundleContent) {
|
|
@@ -799,7 +794,7 @@ class Document extends core_1.Client {
|
|
|
799
794
|
catch (err) {
|
|
800
795
|
const name = (0, util_1.getModuleName)(err);
|
|
801
796
|
if (name) {
|
|
802
|
-
this.checkPackage(err, (0, util_1.getModuleName)(err), "Unknown"
|
|
797
|
+
this.checkPackage(err, (0, util_1.getModuleName)(err), "Unknown");
|
|
803
798
|
}
|
|
804
799
|
throw err;
|
|
805
800
|
}
|
|
@@ -838,7 +833,7 @@ class Document extends core_1.Client {
|
|
|
838
833
|
if (!((0, types_1.isPlainObject)(target) && target.name)) {
|
|
839
834
|
this.abort('view_engine');
|
|
840
835
|
const from = typeof viewEngine === 'string' ? viewEngine : this.moduleName;
|
|
841
|
-
this.writeFail(["Unable to load configuration"
|
|
836
|
+
this.writeFail(["Unable to load configuration", from], (0, types_1.errorMessage)('view-engine', from, "Unknown"));
|
|
842
837
|
return null;
|
|
843
838
|
}
|
|
844
839
|
const length = data.length;
|
|
@@ -866,10 +861,10 @@ class Document extends core_1.Client {
|
|
|
866
861
|
const cacheKey = username + core_1.Client.asHash(template + (compile ? core_1.Client.asString(compile) : ''));
|
|
867
862
|
let result = '', render, valid;
|
|
868
863
|
if (!(render = cache[cacheKey])) {
|
|
869
|
-
render = await context.compile(template, compile);
|
|
864
|
+
render = await context.compile(template, compile);
|
|
870
865
|
cache[cacheKey] = render;
|
|
871
|
-
if (!core_1.Client.enabled("memory.settings.users"
|
|
872
|
-
setTimeout(() => delete cache[cacheKey], 60000
|
|
866
|
+
if (!core_1.Client.enabled("memory.settings.users", username)) {
|
|
867
|
+
setTimeout(() => delete cache[cacheKey], 60000);
|
|
873
868
|
}
|
|
874
869
|
}
|
|
875
870
|
for (let i = 0, j = 0, row; i < length; ++i) {
|
|
@@ -880,11 +875,11 @@ class Document extends core_1.Client {
|
|
|
880
875
|
}
|
|
881
876
|
}
|
|
882
877
|
else if (!(0, types_1.isObject)(row)) {
|
|
883
|
-
this.addLog(types_1.STATUS_TYPE.WARN, joinString(`view engine[${name}]`, `row #${i + 1}`, core_1.Client.asString(row) || "Unknown"
|
|
878
|
+
this.addLog(types_1.STATUS_TYPE.WARN, joinString(`view engine[${name}]`, `row #${i + 1}`, core_1.Client.asString(row) || "Unknown"));
|
|
884
879
|
continue;
|
|
885
880
|
}
|
|
886
881
|
if (!singleRow) {
|
|
887
|
-
const content = await render.call(context, row);
|
|
882
|
+
const content = await render.call(context, row);
|
|
888
883
|
if (content !== undefined && content !== null) {
|
|
889
884
|
result += content;
|
|
890
885
|
valid = true;
|
|
@@ -895,7 +890,7 @@ class Document extends core_1.Client {
|
|
|
895
890
|
}
|
|
896
891
|
catch (err) {
|
|
897
892
|
this.abort('view_engine');
|
|
898
|
-
this.checkPackage(err, name, "Unknown"
|
|
893
|
+
this.checkPackage(err, name, "Unknown", 4);
|
|
899
894
|
}
|
|
900
895
|
return null;
|
|
901
896
|
}
|
|
@@ -909,7 +904,7 @@ class Document extends core_1.Client {
|
|
|
909
904
|
const username = this.host?.username || '';
|
|
910
905
|
const config = this._transformConfig;
|
|
911
906
|
const cacheData = config && options.cacheData;
|
|
912
|
-
const cacheType = username && core_1.Client.enabled("memory.settings.users"
|
|
907
|
+
const cacheType = username && core_1.Client.enabled("memory.settings.users", username) ? true : this.cacheDir || core_1.Client.enabled("memory.settings.users");
|
|
913
908
|
let formatKey, hashKey, excludeKey;
|
|
914
909
|
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)))) {
|
|
915
910
|
const { uri, etag } = cacheData;
|
|
@@ -985,7 +980,7 @@ class Document extends core_1.Client {
|
|
|
985
980
|
}
|
|
986
981
|
if (result) {
|
|
987
982
|
result.storedLog?.forEach(log => this.addLog(log));
|
|
988
|
-
this.formatMessage(4
|
|
983
|
+
this.formatMessage(4, type, [joinString(cacheName, format.filter(value => value).join(' | '), options.filename), 'cache'], uri, { ...core_1.Client.LOG_STYLE_NOTICE, hintBold: true });
|
|
989
984
|
return result;
|
|
990
985
|
}
|
|
991
986
|
}
|
|
@@ -1063,7 +1058,7 @@ class Document extends core_1.Client {
|
|
|
1063
1058
|
if (typeof value !== 'string' || (0, types_1.isArray)(out.sourceFiles) && this.hasOwnPermission() && out.sourceFiles.some(item => !this.canRead(item, { ownPermissionOnly: true }))) {
|
|
1064
1059
|
failed = true;
|
|
1065
1060
|
ignoreCache = true;
|
|
1066
|
-
this.writeFail(["Unable to transform document"
|
|
1061
|
+
this.writeFail(["Unable to transform document", plugin], (0, types_1.errorMessage)(plugin, name, typeof value === 'string' ? "Unsupported access" : 'Empty'), { type: 4, startTime });
|
|
1067
1062
|
}
|
|
1068
1063
|
else if (source !== value) {
|
|
1069
1064
|
series.code = value;
|
|
@@ -1095,19 +1090,18 @@ class Document extends core_1.Client {
|
|
|
1095
1090
|
}
|
|
1096
1091
|
this.writeTimeProcess(failed ? 'CHECK' : type, joinString(hint, options.filename) + (series.out.messageAppend || ''), startTime, { failed, bypassLog });
|
|
1097
1092
|
};
|
|
1098
|
-
this.formatMessage(4
|
|
1093
|
+
this.formatMessage(4, type, ['Transforming source...', hint], options.filename, { hintColor: 'cyan' });
|
|
1099
1094
|
try {
|
|
1100
1095
|
let context = require(plugin);
|
|
1101
1096
|
series.packageName = plugin;
|
|
1102
1097
|
if (typeof baseConfig === 'function') {
|
|
1103
1098
|
series.baseConfig = outputConfig;
|
|
1104
|
-
|
|
1105
|
-
if (baseConfig["__cjs__" /* INTERNAL.CJS */]) {
|
|
1099
|
+
if (baseConfig["__cjs__"]) {
|
|
1106
1100
|
next(await baseConfig(context, source, series));
|
|
1107
1101
|
}
|
|
1108
1102
|
else {
|
|
1109
|
-
const thisArg = core_1.Client.enabled("node.process.inline"
|
|
1110
|
-
const inline = core_1.Client.enabled("node.require.inline"
|
|
1103
|
+
const thisArg = core_1.Client.enabled("node.process.inline") ? process : null;
|
|
1104
|
+
const inline = core_1.Client.enabled("node.require.inline");
|
|
1111
1105
|
const args = [context, source, series];
|
|
1112
1106
|
if (baseConfig.toString().startsWith('async')) {
|
|
1113
1107
|
if (inline) {
|
|
@@ -1141,7 +1135,7 @@ class Document extends core_1.Client {
|
|
|
1141
1135
|
}
|
|
1142
1136
|
else {
|
|
1143
1137
|
transformer = context;
|
|
1144
|
-
context = this;
|
|
1138
|
+
context = this;
|
|
1145
1139
|
pkg = undefined;
|
|
1146
1140
|
}
|
|
1147
1141
|
if (transformer && typeof transformer !== 'function') {
|
|
@@ -1156,7 +1150,7 @@ class Document extends core_1.Client {
|
|
|
1156
1150
|
}
|
|
1157
1151
|
catch (err) {
|
|
1158
1152
|
abort();
|
|
1159
|
-
this.writeFail(["Unknown"
|
|
1153
|
+
this.writeFail(["Unknown", username ? plugin + ':' + username : hint], err, { type: 4, startTime });
|
|
1160
1154
|
continue;
|
|
1161
1155
|
}
|
|
1162
1156
|
}
|
|
@@ -1166,7 +1160,7 @@ class Document extends core_1.Client {
|
|
|
1166
1160
|
}
|
|
1167
1161
|
catch (err) {
|
|
1168
1162
|
abort();
|
|
1169
|
-
this.checkPackage(err, (0, util_1.getModuleName)(err), ["Unable to transform document"
|
|
1163
|
+
this.checkPackage(err, (0, util_1.getModuleName)(err), ["Unable to transform document", hint], { type: 4, startTime });
|
|
1170
1164
|
if (i < length - 1) {
|
|
1171
1165
|
series.reset();
|
|
1172
1166
|
}
|
|
@@ -1175,10 +1169,10 @@ class Document extends core_1.Client {
|
|
|
1175
1169
|
else {
|
|
1176
1170
|
abort();
|
|
1177
1171
|
if (plugin) {
|
|
1178
|
-
this.writeFail("Unable to load configuration"
|
|
1172
|
+
this.writeFail("Unable to load configuration", (0, types_1.errorMessage)(plugin, name, 'Invalid config'), 4);
|
|
1179
1173
|
}
|
|
1180
1174
|
else {
|
|
1181
|
-
this.writeFail('Format method was not found', (0, types_1.errorValue)(name, "Unknown"
|
|
1175
|
+
this.writeFail('Format method was not found', (0, types_1.errorValue)(name, "Unknown"), 4);
|
|
1182
1176
|
}
|
|
1183
1177
|
}
|
|
1184
1178
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@e-mc/document",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.2",
|
|
4
4
|
"description": "Document constructor for E-mc.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
},
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|
|
12
|
-
"url": "https://github.com/anpham6/e-mc.git",
|
|
12
|
+
"url": "git+https://github.com/anpham6/e-mc.git",
|
|
13
13
|
"directory": "src/document"
|
|
14
14
|
},
|
|
15
15
|
"keywords": [
|
|
@@ -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.7.
|
|
24
|
-
"@e-mc/db": "0.7.
|
|
25
|
-
"@e-mc/types": "0.7.
|
|
23
|
+
"@e-mc/core": "0.7.2",
|
|
24
|
+
"@e-mc/db": "0.7.2",
|
|
25
|
+
"@e-mc/types": "0.7.2",
|
|
26
26
|
"chalk": "4.1.2",
|
|
27
27
|
"htmlparser2": "^9.0.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;
|
|
@@ -30,7 +30,7 @@ class DomWriter extends index_1.XmlWriter {
|
|
|
30
30
|
if (ignoreTagGroup) {
|
|
31
31
|
for (let i = 0, length = ignoreTagGroup.length; i < length; i += 2) {
|
|
32
32
|
const start = ignoreTagGroup[i];
|
|
33
|
-
if (start
|
|
33
|
+
if (start.startsWith('<')) {
|
|
34
34
|
tagGroup.push(new RegExp('^' + (0, types_1.escapePattern)(start)));
|
|
35
35
|
}
|
|
36
36
|
const end = ignoreTagGroup[i + 1];
|
|
@@ -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
|
@@ -4,8 +4,8 @@ exports.XmlElement = exports.XmlWriter = exports.IGNORE_FLAG = 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 module_1 = require("
|
|
7
|
+
const types_1 = require("@e-mc/types");
|
|
8
|
+
const module_1 = require("@e-mc/module");
|
|
9
9
|
var IGNORE_FLAG;
|
|
10
10
|
(function (IGNORE_FLAG) {
|
|
11
11
|
IGNORE_FLAG[IGNORE_FLAG["NONE"] = 0] = "NONE";
|
|
@@ -174,7 +174,7 @@ class XmlWriter {
|
|
|
174
174
|
}
|
|
175
175
|
static getNewlineString(leading, trailing, newline) {
|
|
176
176
|
const value = leading + trailing;
|
|
177
|
-
return getNewlineCount(value) > 1 ? newline || (value.
|
|
177
|
+
return getNewlineCount(value) > 1 ? newline || (value.includes('\r') ? '\r\n' : '\n') : '';
|
|
178
178
|
}
|
|
179
179
|
static findCloseTag(source, startIndex = 0) {
|
|
180
180
|
const length = source.length;
|
|
@@ -910,11 +910,11 @@ class XmlWriter {
|
|
|
910
910
|
}
|
|
911
911
|
let tagName = this.ignoreTagName || '';
|
|
912
912
|
if (tagName) {
|
|
913
|
-
if (value
|
|
913
|
+
if (!value.startsWith('|') && !tagName.endsWith('|')) {
|
|
914
914
|
tagName += '|';
|
|
915
915
|
}
|
|
916
916
|
}
|
|
917
|
-
else if (value
|
|
917
|
+
else if (value.startsWith('|')) {
|
|
918
918
|
value = value.substring(1);
|
|
919
919
|
}
|
|
920
920
|
this.ignoreTagName = tagName + value;
|
|
@@ -1260,7 +1260,7 @@ class XmlElement {
|
|
|
1260
1260
|
const { tagName, tagIndex = -1, tagCount = Infinity, ignoreCase } = node;
|
|
1261
1261
|
const id = this.id;
|
|
1262
1262
|
const flags = ignoreCase ? 'gi' : 'g';
|
|
1263
|
-
const hasId = (startIndex, endIndex) => source.substring(startIndex, endIndex).
|
|
1263
|
+
const hasId = (startIndex, endIndex) => source.substring(startIndex, endIndex).includes(id);
|
|
1264
1264
|
const errorResult = () => ['', '', (0, types_1.errorValue)('Element was not found', tagName.toUpperCase() + (isIndex(tagIndex) ? ' @ ' + tagIndex : ''))];
|
|
1265
1265
|
let position;
|
|
1266
1266
|
if (XmlWriter.isTagVoid(this.documentType, tagName)) {
|
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');
|
|
@@ -16,7 +16,7 @@ const kUsername = Symbol('username');
|
|
|
16
16
|
const kProductionRelease = Symbol('productionRelease');
|
|
17
17
|
function parseMap(data, value) {
|
|
18
18
|
let [mimeType, encoding] = data.split(';');
|
|
19
|
-
if (!encoding && mimeType.
|
|
19
|
+
if (!encoding && !mimeType.includes('/')) {
|
|
20
20
|
encoding = mimeType;
|
|
21
21
|
}
|
|
22
22
|
return encoding.includes('base64') ? Buffer.from(value, 'base64').toString() : value;
|
|
@@ -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",
|