@pi-r/chrome 0.3.0 → 0.3.3
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 +4 -2
- package/index.d.ts +6 -6
- package/index.js +65 -63
- package/package.json +6 -6
- package/types/index.d.ts +7 -7
package/LICENSE
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Copyright 2023
|
|
1
|
+
Copyright 2023 Lisa Mishima
|
|
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
|
|
package/README.md
CHANGED
package/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { IFileManager } from '@e-mc/types/lib';
|
|
2
|
-
|
|
3
|
-
import type { ChromeDocumentConstructor, DocumentAsset } from './types';
|
|
4
|
-
|
|
5
|
-
declare const Chrome: ChromeDocumentConstructor<IFileManager<DocumentAsset>>;
|
|
6
|
-
|
|
1
|
+
import type { IFileManager } from '@e-mc/types/lib';
|
|
2
|
+
|
|
3
|
+
import type { ChromeDocumentConstructor, DocumentAsset } from './types';
|
|
4
|
+
|
|
5
|
+
declare const Chrome: ChromeDocumentConstructor<IFileManager<DocumentAsset>>;
|
|
6
|
+
|
|
7
7
|
export = Chrome;
|
package/index.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
2
|
const path = require("path");
|
|
4
3
|
const fs = require("fs");
|
|
5
4
|
const asset_1 = require("@e-mc/document/asset");
|
|
@@ -25,6 +24,14 @@ const [PATTERN_STRING_SOME, PATTERN_STRING_MANY] = (function () {
|
|
|
25
24
|
const pattern = '(?:\\s|' + dom_1.DomWriter.PATTERN_COMMENT + '|`[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}`)';
|
|
26
25
|
return [pattern + '*', pattern + '+'];
|
|
27
26
|
})();
|
|
27
|
+
const [REGEXP_NTHCHILD, REGEXP_NTHCHILD_UNSAFE, REGEXP_REPLACECSS] = (function () {
|
|
28
|
+
const parenthesis = '(?:,[^()]+(?=\\))|[^()]|\\([^()]*\\(+|\\([^()]*\\)|(?:\\)[^()]+)?\\)*?)+';
|
|
29
|
+
return [
|
|
30
|
+
new RegExp(`\\(${PATTERN_STRING_SOME}([+-])?(?:(\\d*)[nN]|(0))?${PATTERN_STRING_SOME}([+-])?${PATTERN_STRING_SOME}(\\d*)(?:${PATTERN_STRING_MANY}[oO][fF]${PATTERN_STRING_MANY}(${parenthesis})${PATTERN_STRING_SOME}\\)|${PATTERN_STRING_SOME}\\))`, 'g'),
|
|
31
|
+
new RegExp(`\\(\\s*([+-])?(?:(\\d*)[nN]|(0))?\\s*([+-])?\\s*(\\d*)(?:\\s+[oO][fF]\\s+(${parenthesis})\\s*\\)|\\s*\\))`, 'g'),
|
|
32
|
+
new RegExp(`^@import\\s+(?:url\\((?:[^)]|(?<=\\\\)\\))+\\)|"(?:[^"]|(?<=\\\\)")+"|'(?:[^']|(?<=\\\\)')+')(\\s*layer(?:\\(([^)]*)\\)|\\b))?(?:\\s*supports\\((${parenthesis})\\))?(.*?);?$`)
|
|
33
|
+
];
|
|
34
|
+
})();
|
|
28
35
|
const REGEXP_COMMENT = new RegExp(dom_1.DomWriter.PATTERN_COMMENT, 'g');
|
|
29
36
|
const REGEXP_CONTENT = new RegExp(`\\bcontent${PATTERN_STRING_SOME}:${PATTERN_STRING_SOME}(?:"[^"]*"|'[^']*')`, 'gi');
|
|
30
37
|
const REGEXP_STYLE = new RegExp(`(<style${dom_1.DomWriter.PATTERN_TAGOPEN}*>)([\\S\\s]*?)(<\\/style\\s*>)`, 'gi');
|
|
@@ -32,12 +39,10 @@ const REGEXP_VARIABLES = new RegExp(`(\\s*)(--[^\\s:]*)${PATTERN_STRING_SOME}:[^
|
|
|
32
39
|
const REGEXP_FONTFACE = new RegExp(`(\\s*)@font-face${PATTERN_STRING_SOME}{([^}]+)}` + dom_1.DomWriter.PATTERN_TRAILINGSPACE, 'gi');
|
|
33
40
|
const REGEXP_FONTFAMILY = new RegExp(`font-family${PATTERN_STRING_SOME}:([^;}]+)`, 'i');
|
|
34
41
|
const REGEXP_KEYFRAMES = new RegExp(`(\\s*)@keyframes${PATTERN_STRING_MANY}([^{]+){`, 'gi');
|
|
35
|
-
const REGEXP_NTHCHILD = new RegExp(`\\(${PATTERN_STRING_SOME}([+-])?(?:(\\d*)[nN]|(0))${PATTERN_STRING_SOME}([+-])?${PATTERN_STRING_SOME}(\\d*)${PATTERN_STRING_SOME}\\)`, 'g');
|
|
36
42
|
const REGEXP_VARIABLES_UNSAFE = new RegExp(`(\\s*)(--[^\\s:]*)\\s*:[^;}]*([;}])` + dom_1.DomWriter.PATTERN_TRAILINGSPACE, 'g');
|
|
37
43
|
const REGEXP_FONTFACE_UNSAFE = new RegExp(`(\\s*)@font-face\\s*{([^}]+)}` + dom_1.DomWriter.PATTERN_TRAILINGSPACE, 'gi');
|
|
38
44
|
const REGEXP_FONTFAMILY_UNSAFE = /font-family\s*:([^;}]+)/i;
|
|
39
45
|
const REGEXP_KEYFRAMES_UNSAFE = /(\s*)@keyframes\s+([^{]+){/gi;
|
|
40
|
-
const REGEXP_NTHCHILD_UNSAFE = /\(\s*([+-])?(?:(\d*)[nN]|(0))\s*([+-])?\s*(\d*)\s*\)/g;
|
|
41
46
|
const REGEXP_OBJECT_NAME = /([^[.\s]+)((?:\s*\[[^\]]+\]\s*)+)?\s*\.?\s*/g;
|
|
42
47
|
const REGEXP_OBJECT_SUBSCRIPT = /\[\s*(["'])?(.+?)\1\s*\]/g;
|
|
43
48
|
const REGEXP_TEMPLATE_LEADING = /\s*\{\{- \s*((?:[^}]|}(?!}))+?)\}\}/g;
|
|
@@ -148,7 +153,7 @@ function addCacheItem(map, key, data, timeout) {
|
|
|
148
153
|
map.set(key, [
|
|
149
154
|
Date.now(),
|
|
150
155
|
data,
|
|
151
|
-
setTimeout(() => deleteCacheItem(map, key), timeout * 1000
|
|
156
|
+
setTimeout(() => deleteCacheItem(map, key), timeout * 1000)
|
|
152
157
|
]);
|
|
153
158
|
}
|
|
154
159
|
function deleteCacheItem(map, key) {
|
|
@@ -206,10 +211,10 @@ function hasCondition(data, condition) {
|
|
|
206
211
|
if (arg2) {
|
|
207
212
|
switch (item[0]) {
|
|
208
213
|
case 'eq':
|
|
209
|
-
valid = parseArg(arg1) == parseArg(arg2);
|
|
214
|
+
valid = parseArg(arg1) == parseArg(arg2);
|
|
210
215
|
break;
|
|
211
216
|
case 'ne':
|
|
212
|
-
valid = parseArg(arg1) != parseArg(arg2);
|
|
217
|
+
valid = parseArg(arg1) != parseArg(arg2);
|
|
213
218
|
break;
|
|
214
219
|
case 'lt':
|
|
215
220
|
valid = parseArg(arg1) < parseArg(arg2);
|
|
@@ -338,7 +343,7 @@ function createHash(host, file, bufferMap) {
|
|
|
338
343
|
throw (0, types_1.errorMessage)('hash', 'Source not found', filename);
|
|
339
344
|
}
|
|
340
345
|
catch (err) {
|
|
341
|
-
host.writeFail(["Unable to read file"
|
|
346
|
+
host.writeFail(["Unable to read file", filename], err, 32);
|
|
342
347
|
}
|
|
343
348
|
}
|
|
344
349
|
function getSrcURL(parent, file) {
|
|
@@ -479,7 +484,7 @@ function transformURL(host, parent, type, source, importFile) {
|
|
|
479
484
|
}
|
|
480
485
|
}
|
|
481
486
|
if (asset.initialValue && !asset.initialValue.cacheable) {
|
|
482
|
-
parent.flags |= 16
|
|
487
|
+
parent.flags |= 16;
|
|
483
488
|
}
|
|
484
489
|
related.push(asset);
|
|
485
490
|
}
|
|
@@ -575,7 +580,7 @@ function transformURL(host, parent, type, source, importFile) {
|
|
|
575
580
|
else {
|
|
576
581
|
related.push(asset);
|
|
577
582
|
if (!(0, types_1.existsFlag)(asset.flags)) {
|
|
578
|
-
asset.flags |= 8
|
|
583
|
+
asset.flags |= 8;
|
|
579
584
|
}
|
|
580
585
|
}
|
|
581
586
|
modified = true;
|
|
@@ -735,12 +740,12 @@ function transformJs(host, file, output) {
|
|
|
735
740
|
});
|
|
736
741
|
}
|
|
737
742
|
else {
|
|
738
|
-
this.writeFail(['Unable to create element entry point', path.basename(chunkUri)], (0, types_1.errorMessage)('js', 'Element not found', chunkUri), 4
|
|
743
|
+
this.writeFail(['Unable to create element entry point', path.basename(chunkUri)], (0, types_1.errorMessage)('js', 'Element not found', chunkUri), 4);
|
|
739
744
|
}
|
|
740
745
|
}
|
|
741
746
|
}
|
|
742
747
|
catch (err) {
|
|
743
|
-
this.writeFail(["Unable to write file"
|
|
748
|
+
this.writeFail(["Unable to write file", path.basename(chunkUri)], err, 32);
|
|
744
749
|
}
|
|
745
750
|
}
|
|
746
751
|
appending?.forEach(item => item.order += order);
|
|
@@ -823,19 +828,18 @@ async function checkData(item, name, result, validate) {
|
|
|
823
828
|
if (typeof callback === 'function') {
|
|
824
829
|
try {
|
|
825
830
|
let output;
|
|
826
|
-
|
|
827
|
-
if (callback["__cjs__" /* INTERNAL.CJS */]) {
|
|
831
|
+
if (callback["__cjs__"]) {
|
|
828
832
|
output = await callback(result, item);
|
|
829
833
|
}
|
|
830
834
|
else {
|
|
831
|
-
output = await callback.apply(Document.enabled("node.process.inline"
|
|
835
|
+
output = await callback.apply(Document.enabled("node.process.inline") ? process : null, Document.enabled("node.require.inline") ? [result, item, require] : [result, item]);
|
|
832
836
|
}
|
|
833
837
|
if (validate(output)) {
|
|
834
838
|
return output;
|
|
835
839
|
}
|
|
836
840
|
}
|
|
837
841
|
catch (err) {
|
|
838
|
-
this.writeFail(["Unable to parse inline method"
|
|
842
|
+
this.writeFail(["Unable to parse inline method", name], err);
|
|
839
843
|
}
|
|
840
844
|
}
|
|
841
845
|
}
|
|
@@ -866,7 +870,6 @@ const getEndIndex = (match) => match.index + match[0].length;
|
|
|
866
870
|
const getRelativeURL = (file) => joinPath(file.moveTo, file.pathname, file.inlineFilename || file.filename) + (!file.static ? restoreSearchParams(file.url?.search) : '');
|
|
867
871
|
const errorHtml = ({ tagName, tagIndex = -1 }) => (0, types_1.errorMessage)('html', 'Location did not resolve', tagName.toLowerCase() + (tagIndex >= 0 ? ': ' + tagIndex : ''));
|
|
868
872
|
const errorDataSource = (value, hint) => (0, types_1.errorMessage)('data-source', value, hint);
|
|
869
|
-
// @ts-ignore
|
|
870
873
|
class ChromeDocument extends Document {
|
|
871
874
|
constructor() {
|
|
872
875
|
super(...arguments);
|
|
@@ -946,7 +949,7 @@ class ChromeDocument extends Document {
|
|
|
946
949
|
const { Db: db, htmlFile, assets } = instance;
|
|
947
950
|
const outHtml = htmlFile && !isIgnored(htmlFile, true);
|
|
948
951
|
if (db && await db.commit()) {
|
|
949
|
-
db.writeTimeElapsed('DB', ["Transactions were committed"
|
|
952
|
+
db.writeTimeElapsed('DB', ["Transactions were committed", db.moduleName], processing.startTime, { ...Document.LOG_STYLE_SUCCESS, type: 65536 });
|
|
950
953
|
}
|
|
951
954
|
if (instance.dataSource.length === 0 && outHtml) {
|
|
952
955
|
const incremental = htmlFile.incremental ?? this.incremental;
|
|
@@ -989,7 +992,7 @@ class ChromeDocument extends Document {
|
|
|
989
992
|
}
|
|
990
993
|
case 'exists':
|
|
991
994
|
if (hint || isHtmlOnly()) {
|
|
992
|
-
this.formatMessage(4
|
|
995
|
+
this.formatMessage(4, 'HTML', ['No changes detected', 'incremental: ' + incremental], hint, { ...Document.LOG_STYLE_NOTICE, messageBgColor: 'bgWhite', messageColor: 'black' });
|
|
993
996
|
return super.finalize.call(this, instance);
|
|
994
997
|
}
|
|
995
998
|
break;
|
|
@@ -1031,7 +1034,7 @@ class ChromeDocument extends Document {
|
|
|
1031
1034
|
continue;
|
|
1032
1035
|
}
|
|
1033
1036
|
if (isWatched.call(instance, item)) {
|
|
1034
|
-
item.flags |= 8
|
|
1037
|
+
item.flags |= 8;
|
|
1035
1038
|
}
|
|
1036
1039
|
items.add(item);
|
|
1037
1040
|
const next = related.get(item);
|
|
@@ -1065,16 +1068,16 @@ class ChromeDocument extends Document {
|
|
|
1065
1068
|
this.delete(value);
|
|
1066
1069
|
}
|
|
1067
1070
|
else {
|
|
1068
|
-
instance.writeFail(["Unable to move file"
|
|
1071
|
+
instance.writeFail(["Unable to move file", instance.moduleName], (0, types_1.errorMessage)('production', path.join(this.baseDirectory, value)), { fatal: true });
|
|
1069
1072
|
}
|
|
1070
1073
|
}
|
|
1071
1074
|
}
|
|
1072
1075
|
else {
|
|
1073
|
-
instance.writeFail(["Unable to write directory"
|
|
1076
|
+
instance.writeFail(["Unable to write directory", instance.moduleName], (0, types_1.errorMessage)('production', 'Access denied', productionRelease));
|
|
1074
1077
|
}
|
|
1075
1078
|
}
|
|
1076
1079
|
else {
|
|
1077
|
-
instance.writeFail(["Unable to read directory"
|
|
1080
|
+
instance.writeFail(["Unable to read directory", instance.moduleName], (0, types_1.errorMessage)('production', 'Invalid directory', productionRelease), 32);
|
|
1078
1081
|
}
|
|
1079
1082
|
}
|
|
1080
1083
|
static sanitizeAssets(assets, exclusions = []) {
|
|
@@ -1394,7 +1397,7 @@ class ChromeDocument extends Document {
|
|
|
1394
1397
|
await instance.tryFile(buffer, { format: to, filename: file.filename, etag: file.etag }, (err, result, ext) => {
|
|
1395
1398
|
if (err) {
|
|
1396
1399
|
setFormat();
|
|
1397
|
-
this.writeFail("Unable to compress file"
|
|
1400
|
+
this.writeFail("Unable to compress file", err, 8);
|
|
1398
1401
|
}
|
|
1399
1402
|
else if (result) {
|
|
1400
1403
|
if (ext) {
|
|
@@ -1408,7 +1411,7 @@ class ChromeDocument extends Document {
|
|
|
1408
1411
|
host.replace(file, output);
|
|
1409
1412
|
}
|
|
1410
1413
|
else {
|
|
1411
|
-
this.writeFail("Unable to write file"
|
|
1414
|
+
this.writeFail("Unable to write file", error, 32);
|
|
1412
1415
|
}
|
|
1413
1416
|
});
|
|
1414
1417
|
}
|
|
@@ -1602,14 +1605,14 @@ class ChromeDocument extends Document {
|
|
|
1602
1605
|
replaceContent(source, statement, mimeType) {
|
|
1603
1606
|
switch (mimeType) {
|
|
1604
1607
|
case 'text/css': {
|
|
1605
|
-
const match =
|
|
1608
|
+
const match = REGEXP_REPLACECSS.exec((typeof statement === 'string' ? statement : statement[0]).trim());
|
|
1606
1609
|
if (match) {
|
|
1607
1610
|
const layer = match[1];
|
|
1608
1611
|
const supports = match[3]?.trim();
|
|
1609
1612
|
const query = match[4].trim();
|
|
1610
1613
|
if (layer || supports || query) {
|
|
1611
1614
|
const newline = (0, util_1.getNewline)(source);
|
|
1612
|
-
let result = supports ? `@supports (${
|
|
1615
|
+
let result = supports ? `@supports (${supports}) {` + newline : '';
|
|
1613
1616
|
if (query) {
|
|
1614
1617
|
result += `@media ${query} {` + newline;
|
|
1615
1618
|
}
|
|
@@ -1718,7 +1721,7 @@ class ChromeDocument extends Document {
|
|
|
1718
1721
|
item.sourceUTF8 = output;
|
|
1719
1722
|
}
|
|
1720
1723
|
catch (err) {
|
|
1721
|
-
host.writeFail(["Unable to write file"
|
|
1724
|
+
host.writeFail(["Unable to write file", path.basename(item.localUri)], err, 32);
|
|
1722
1725
|
}
|
|
1723
1726
|
}
|
|
1724
1727
|
}
|
|
@@ -1920,7 +1923,7 @@ class ChromeDocument extends Document {
|
|
|
1920
1923
|
host.removeAsset(item);
|
|
1921
1924
|
}
|
|
1922
1925
|
catch (err) {
|
|
1923
|
-
this.writeFail(["Unable to read file"
|
|
1926
|
+
this.writeFail(["Unable to read file", item.filename], err, { type: 32, startTime });
|
|
1924
1927
|
return false;
|
|
1925
1928
|
}
|
|
1926
1929
|
}
|
|
@@ -2103,7 +2106,7 @@ class ChromeDocument extends Document {
|
|
|
2103
2106
|
const { moduleName, config } = this;
|
|
2104
2107
|
const htmlFile = this.htmlFile;
|
|
2105
2108
|
const localUri = htmlFile.localUri;
|
|
2106
|
-
this.formatMessage(4
|
|
2109
|
+
this.formatMessage(4, 'HTML', ['Rewriting content...', path.dirname(localUri)]);
|
|
2107
2110
|
let source = host.getUTF8String(htmlFile, localUri), output;
|
|
2108
2111
|
const domBase = new dom_1.DomWriter(moduleName, source, this.elements, { normalize: config.normalizeHtmlOutput, stripComments: config.stripCommentsAndCDATA, ignoreTagGroup: config.ignoreServerCodeBlocks, escapeEntities: config.escapeReservedCharacters });
|
|
2109
2112
|
if (config.useUnsafeHtmlReplace) {
|
|
@@ -2129,7 +2132,7 @@ class ChromeDocument extends Document {
|
|
|
2129
2132
|
const domElement = new dom_1.HtmlElement(moduleName, element, item.attributes);
|
|
2130
2133
|
domElement.remove = true;
|
|
2131
2134
|
if (!domBase.write(domElement)) {
|
|
2132
|
-
this.writeFail('Unable to exclude HTML element', errorHtml(element), 4
|
|
2135
|
+
this.writeFail('Unable to exclude HTML element', errorHtml(element), 4);
|
|
2133
2136
|
}
|
|
2134
2137
|
}
|
|
2135
2138
|
}
|
|
@@ -2169,7 +2172,7 @@ class ChromeDocument extends Document {
|
|
|
2169
2172
|
domBase.errors.forEach(err => this.addLog(types_1.STATUS_TYPE.WARN, 'dom-writer -> ' + err.message, timeStamp));
|
|
2170
2173
|
}
|
|
2171
2174
|
if (domBase.failCount > 0) {
|
|
2172
|
-
this.writeFail(['Unable to update document', moduleName], (0, types_1.errorMessage)('html', 'DOM rewrite failed', domBase.failCount + ' errors'), { type: 4
|
|
2175
|
+
this.writeFail(['Unable to update document', moduleName], (0, types_1.errorMessage)('html', 'DOM rewrite failed', domBase.failCount + ' errors'), { type: 4, startTime });
|
|
2173
2176
|
}
|
|
2174
2177
|
else {
|
|
2175
2178
|
this.writeTimeProcess('html', `dom-writer (${domBase.modifyCount} modified) -> ` + path.basename(localUri), startTime);
|
|
@@ -2180,7 +2183,7 @@ class ChromeDocument extends Document {
|
|
|
2180
2183
|
for (const name in data) {
|
|
2181
2184
|
message.push(name + `(${data[name]})`);
|
|
2182
2185
|
}
|
|
2183
|
-
this.formatMessage(65536
|
|
2186
|
+
this.formatMessage(65536, 'DB', ['Cache statistics', cacheMiss.length + ' missed'], message.join(' - '), { ...Document.LOG_STYLE_NOTICE, hintBold: true });
|
|
2184
2187
|
}
|
|
2185
2188
|
}
|
|
2186
2189
|
htmlFile.modified = true;
|
|
@@ -2296,7 +2299,7 @@ class ChromeDocument extends Document {
|
|
|
2296
2299
|
}
|
|
2297
2300
|
}
|
|
2298
2301
|
if (!domBase.write(domElement)) {
|
|
2299
|
-
this.writeFail(inlineContent ? 'Inline tag replacement' : 'Element attribute replacement', errorHtml(element), { type: 4
|
|
2302
|
+
this.writeFail(inlineContent ? 'Inline tag replacement' : 'Element attribute replacement', errorHtml(element), { type: 4, startTime });
|
|
2300
2303
|
delete item.inlineUrlCloud;
|
|
2301
2304
|
}
|
|
2302
2305
|
else if (inlineContent) {
|
|
@@ -2320,7 +2323,7 @@ class ChromeDocument extends Document {
|
|
|
2320
2323
|
if (item.removeEmpty || item.type === 'display') {
|
|
2321
2324
|
(element || (element = new dom_1.HtmlElement(moduleName, item.element))).remove = true;
|
|
2322
2325
|
if (!domBase.write(element)) {
|
|
2323
|
-
this.writeFail('Unable to remove element', errorHtml(item.element), { type: 4
|
|
2326
|
+
this.writeFail('Unable to remove element', errorHtml(item.element), { type: 4, startTime });
|
|
2324
2327
|
}
|
|
2325
2328
|
}
|
|
2326
2329
|
};
|
|
@@ -2328,7 +2331,7 @@ class ChromeDocument extends Document {
|
|
|
2328
2331
|
removeElement(item);
|
|
2329
2332
|
const pkg = getPackageName(err);
|
|
2330
2333
|
if (!(pkg && this.checkPackage(err, pkg))) {
|
|
2331
|
-
this.writeFail(["Invalid credentials"
|
|
2334
|
+
this.writeFail(["Invalid credentials", item.source], err);
|
|
2332
2335
|
}
|
|
2333
2336
|
};
|
|
2334
2337
|
const checkObject = (item, data) => {
|
|
@@ -2358,7 +2361,7 @@ class ChromeDocument extends Document {
|
|
|
2358
2361
|
}
|
|
2359
2362
|
catch (err) {
|
|
2360
2363
|
this.abort(item.source);
|
|
2361
|
-
this.checkPackage(err, pkg, ["Unable to filter results"
|
|
2364
|
+
this.checkPackage(err, pkg, ["Unable to filter results", item.source]);
|
|
2362
2365
|
}
|
|
2363
2366
|
}
|
|
2364
2367
|
}
|
|
@@ -2381,7 +2384,7 @@ class ChromeDocument extends Document {
|
|
|
2381
2384
|
(batchMap[key] || (batchMap[key] = [])).push(item);
|
|
2382
2385
|
}
|
|
2383
2386
|
else {
|
|
2384
|
-
errorCredential(item, (0, types_1.errorValue)("Cloud module not installed"
|
|
2387
|
+
errorCredential(item, (0, types_1.errorValue)("Cloud module not installed", service));
|
|
2385
2388
|
}
|
|
2386
2389
|
break;
|
|
2387
2390
|
}
|
|
@@ -2414,7 +2417,7 @@ class ChromeDocument extends Document {
|
|
|
2414
2417
|
}
|
|
2415
2418
|
}
|
|
2416
2419
|
else {
|
|
2417
|
-
errorCredential(item, (0, types_1.errorValue)(db ? "Database provider not found"
|
|
2420
|
+
errorCredential(item, (0, types_1.errorValue)(db ? "Database provider not found" : "Db module not installed", type));
|
|
2418
2421
|
}
|
|
2419
2422
|
break;
|
|
2420
2423
|
}
|
|
@@ -2431,7 +2434,7 @@ class ChromeDocument extends Document {
|
|
|
2431
2434
|
const errorClient = (item, reason) => {
|
|
2432
2435
|
removeElement(item);
|
|
2433
2436
|
if (reason) {
|
|
2434
|
-
this.writeFail(["Unable to configure client"
|
|
2437
|
+
this.writeFail(["Unable to configure client", item.source], reason);
|
|
2435
2438
|
}
|
|
2436
2439
|
reject();
|
|
2437
2440
|
};
|
|
@@ -2473,7 +2476,7 @@ class ChromeDocument extends Document {
|
|
|
2473
2476
|
}
|
|
2474
2477
|
catch (err) {
|
|
2475
2478
|
this.abort(type);
|
|
2476
|
-
this.writeFail(["Unable to read file"
|
|
2479
|
+
this.writeFail(["Unable to read file", path.basename(location)], err, { type: 32, startTime });
|
|
2477
2480
|
errorRemove(current);
|
|
2478
2481
|
return;
|
|
2479
2482
|
}
|
|
@@ -2509,7 +2512,7 @@ class ChromeDocument extends Document {
|
|
|
2509
2512
|
}
|
|
2510
2513
|
catch (err) {
|
|
2511
2514
|
this.abort(type);
|
|
2512
|
-
this.writeFail(["Unable to download file"
|
|
2515
|
+
this.writeFail(["Unable to download file", target], err, { type: 1024, startTime });
|
|
2513
2516
|
errorRemove(current);
|
|
2514
2517
|
return;
|
|
2515
2518
|
}
|
|
@@ -2538,7 +2541,7 @@ class ChromeDocument extends Document {
|
|
|
2538
2541
|
}
|
|
2539
2542
|
catch (err) {
|
|
2540
2543
|
this.abort(type);
|
|
2541
|
-
this.writeFail(["Unable to read file"
|
|
2544
|
+
this.writeFail(["Unable to read file", path.basename(pathname)], err, { type: 32, startTime });
|
|
2542
2545
|
errorRemove(current);
|
|
2543
2546
|
return;
|
|
2544
2547
|
}
|
|
@@ -2552,7 +2555,7 @@ class ChromeDocument extends Document {
|
|
|
2552
2555
|
}
|
|
2553
2556
|
catch (err) {
|
|
2554
2557
|
this.abort(type);
|
|
2555
|
-
this.writeFail(['Unable to parse data source', format], err, { type: 4
|
|
2558
|
+
this.writeFail(['Unable to parse data source', format], err, { type: 4, startTime });
|
|
2556
2559
|
errorRemove(current);
|
|
2557
2560
|
return;
|
|
2558
2561
|
}
|
|
@@ -2630,13 +2633,12 @@ class ChromeDocument extends Document {
|
|
|
2630
2633
|
if (params && this.settingsOf(type, 'coerce') === true) {
|
|
2631
2634
|
(0, types_1.coerceObject)(params);
|
|
2632
2635
|
}
|
|
2633
|
-
|
|
2634
|
-
if (getData["__cjs__" /* INTERNAL.CJS */]) {
|
|
2636
|
+
if (getData["__cjs__"]) {
|
|
2635
2637
|
data = await getData(params);
|
|
2636
2638
|
}
|
|
2637
2639
|
else {
|
|
2638
|
-
const thisArg = Document.enabled("node.process.inline"
|
|
2639
|
-
const inline = Document.enabled("node.require.inline"
|
|
2640
|
+
const thisArg = Document.enabled("node.process.inline") ? process : null;
|
|
2641
|
+
const inline = Document.enabled("node.require.inline");
|
|
2640
2642
|
const args = [params];
|
|
2641
2643
|
if (getData.toString().startsWith('async')) {
|
|
2642
2644
|
if (inline) {
|
|
@@ -2658,7 +2660,7 @@ class ChromeDocument extends Document {
|
|
|
2658
2660
|
}
|
|
2659
2661
|
catch (err) {
|
|
2660
2662
|
this.abort(type);
|
|
2661
|
-
this.writeFail(['Unable to retrieve data source', hint], err, { type: 4
|
|
2663
|
+
this.writeFail(['Unable to retrieve data source', hint], err, { type: 4, startTime });
|
|
2662
2664
|
errorRemove(current);
|
|
2663
2665
|
return;
|
|
2664
2666
|
}
|
|
@@ -2744,12 +2746,12 @@ class ChromeDocument extends Document {
|
|
|
2744
2746
|
}
|
|
2745
2747
|
}
|
|
2746
2748
|
else {
|
|
2747
|
-
throw (0, types_1.errorMessage)(type, "File not found"
|
|
2749
|
+
throw (0, types_1.errorMessage)(type, "File not found", query);
|
|
2748
2750
|
}
|
|
2749
2751
|
}
|
|
2750
2752
|
catch (err) {
|
|
2751
2753
|
this.abort(type);
|
|
2752
|
-
this.writeFail(["Unable to read file"
|
|
2754
|
+
this.writeFail(["Unable to read file", pathname ? path.basename(pathname) : query], err, { startTime });
|
|
2753
2755
|
errorRemove(current);
|
|
2754
2756
|
return;
|
|
2755
2757
|
}
|
|
@@ -2786,7 +2788,7 @@ class ChromeDocument extends Document {
|
|
|
2786
2788
|
this.abort(type);
|
|
2787
2789
|
}
|
|
2788
2790
|
if (err) {
|
|
2789
|
-
this.writeFail(["Unable to execute query"
|
|
2791
|
+
this.writeFail(["Unable to execute query", message || "Unknown"], err, { type: 65536, startTime });
|
|
2790
2792
|
}
|
|
2791
2793
|
return this.aborted;
|
|
2792
2794
|
};
|
|
@@ -2800,7 +2802,7 @@ class ChromeDocument extends Document {
|
|
|
2800
2802
|
}
|
|
2801
2803
|
break;
|
|
2802
2804
|
}
|
|
2803
|
-
errorRemove(current, errorDataSource('Not found', type || "Unknown"
|
|
2805
|
+
errorRemove(current, errorDataSource('Not found', type || "Unknown"));
|
|
2804
2806
|
return;
|
|
2805
2807
|
}
|
|
2806
2808
|
if (this.aborted) {
|
|
@@ -2864,7 +2866,7 @@ class ChromeDocument extends Document {
|
|
|
2864
2866
|
setCacheData.call(this, item, item.value, pathname, cacheData, true);
|
|
2865
2867
|
}
|
|
2866
2868
|
catch (err) {
|
|
2867
|
-
this.writeFail(["Unable to read file"
|
|
2869
|
+
this.writeFail(["Unable to read file", path.basename(pathname)], err, { type: 32, startTime });
|
|
2868
2870
|
errors = true;
|
|
2869
2871
|
}
|
|
2870
2872
|
}
|
|
@@ -2907,7 +2909,7 @@ class ChromeDocument extends Document {
|
|
|
2907
2909
|
const literal = segment.trim();
|
|
2908
2910
|
if (literal[0] === '`' && literal[literal.length - 1] === '`') {
|
|
2909
2911
|
if (!this.hasEval('function')) {
|
|
2910
|
-
errors = (0, types_1.errorMessage)('eval', "Unsupported access"
|
|
2912
|
+
errors = (0, types_1.errorMessage)('eval', "Unsupported access", 'function');
|
|
2911
2913
|
continue;
|
|
2912
2914
|
}
|
|
2913
2915
|
try {
|
|
@@ -3123,34 +3125,34 @@ class ChromeDocument extends Document {
|
|
|
3123
3125
|
default:
|
|
3124
3126
|
removeElement(item, domElement);
|
|
3125
3127
|
if (length === 1) {
|
|
3126
|
-
reject(errorDataSource('Invalid action', item.type || "Unknown"
|
|
3128
|
+
reject(errorDataSource('Invalid action', item.type || "Unknown"));
|
|
3127
3129
|
return;
|
|
3128
3130
|
}
|
|
3129
3131
|
break invalid;
|
|
3130
3132
|
}
|
|
3131
3133
|
if (!domBase.write(domElement) || errors) {
|
|
3132
|
-
this.writeFail(item.type === 'display' ? domElement.remove ? errors ? 'Element was removed with errors' : 'Unable to remove element' : 'Unable to determine display conditional' : 'Unable to replace ' + item.type, errors instanceof Error ? errors : errorHtml(element), { type: 4
|
|
3134
|
+
this.writeFail(item.type === 'display' ? domElement.remove ? errors ? 'Element was removed with errors' : 'Unable to remove element' : 'Unable to determine display conditional' : 'Unable to replace ' + item.type, errors instanceof Error ? errors : errorHtml(element), { type: 4, startTime });
|
|
3133
3135
|
}
|
|
3134
3136
|
}
|
|
3135
3137
|
}
|
|
3136
3138
|
else {
|
|
3137
3139
|
if (!empty && item.type !== 'display' || item.transactionFail) {
|
|
3138
|
-
const emptyResponse = (value, service = item.source) => errorDataSource(service + ' -> Empty', value || "Unknown"
|
|
3140
|
+
const emptyResponse = (value, service = item.source) => errorDataSource(service + ' -> Empty', value || "Unknown");
|
|
3139
3141
|
switch (item.source) {
|
|
3140
3142
|
case 'cloud': {
|
|
3141
3143
|
const { service, table, id, query } = item;
|
|
3142
3144
|
const queryString = (table ? 'table=' + table : '') + (id || query ? (table ? ';' : '') + (id ? 'id=' + id : 'query=' + asString(query)) : '');
|
|
3143
|
-
(cloud || this).formatFail(64
|
|
3145
|
+
(cloud || this).formatFail(64, service, ["Unable to execute query", queryString], emptyResponse(queryString, service), { ...Cloud.LOG_CLOUD_FAIL, startTime });
|
|
3144
3146
|
break;
|
|
3145
3147
|
}
|
|
3146
3148
|
case 'uri': {
|
|
3147
3149
|
const { uri, format = uri && path.extname(uri).substring(1) } = item;
|
|
3148
|
-
this.formatFail(4
|
|
3150
|
+
this.formatFail(4, format || 'URI', ['No records were found', uri], emptyResponse(uri), { startTime });
|
|
3149
3151
|
break;
|
|
3150
3152
|
}
|
|
3151
3153
|
case 'local': {
|
|
3152
3154
|
const { pathname, format = pathname && path.extname(pathname).substring(1) } = item;
|
|
3153
|
-
this.formatFail(4
|
|
3155
|
+
this.formatFail(4, format || 'LOCAL', ['No records were found', pathname], emptyResponse(pathname), { startTime });
|
|
3154
3156
|
break;
|
|
3155
3157
|
}
|
|
3156
3158
|
case 'export': {
|
|
@@ -3159,7 +3161,7 @@ class ChromeDocument extends Document {
|
|
|
3159
3161
|
if (typeof target === 'function') {
|
|
3160
3162
|
target = target.name;
|
|
3161
3163
|
}
|
|
3162
|
-
this.formatFail(4
|
|
3164
|
+
this.formatFail(4, 'EXPORT', ['No records were retrieved', target], emptyResponse(target), { startTime });
|
|
3163
3165
|
break;
|
|
3164
3166
|
}
|
|
3165
3167
|
}
|
|
@@ -3211,7 +3213,7 @@ class ChromeDocument extends Document {
|
|
|
3211
3213
|
throw (0, types_1.errorMessage)('hash', 'Source not found', item.filename);
|
|
3212
3214
|
}
|
|
3213
3215
|
catch (err) {
|
|
3214
|
-
this.writeFail(["Unable to read file"
|
|
3216
|
+
this.writeFail(["Unable to read file", item.filename], err, { type: 32, startTime });
|
|
3215
3217
|
}
|
|
3216
3218
|
default:
|
|
3217
3219
|
if (algorithm) {
|
|
@@ -3238,7 +3240,7 @@ class ChromeDocument extends Document {
|
|
|
3238
3240
|
const parseSelector = (value) => {
|
|
3239
3241
|
const items = [];
|
|
3240
3242
|
const revised = value.replace(useUnsafeCssReplace ? REGEXP_NTHCHILD_UNSAFE : REGEXP_NTHCHILD, (...capture) => {
|
|
3241
|
-
return '`%' + (items.push('\\(' + getStringSome() + (capture[1] === '-' ? '\\x2d' : '\\x2b?') + (capture[2] || '[01]?') + (capture[3] === '0' ? !capture[1] && !capture[2] && !capture[4] && !capture[5] ? '[+-]?0[nN]?' : '0' : '[nN]') + getStringSome() + (capture[5] ? (capture[4] === '-' ? '\\x2d' : '\\x2b') + getStringSome() + capture[5] : `(?:[+-]${getStringSome()}0)?`) + getStringSome() + '\\)') - 1) + '`';
|
|
3243
|
+
return '`%' + (items.push('\\(' + getStringSome() + (capture[1] === '-' ? '\\x2d' : '\\x2b?') + (capture[2] || '[01]?') + (capture[3] === '0' ? !capture[1] && !capture[2] && !capture[4] && !capture[5] ? '[+-]?0[nN]?' : '0' : '[nN]') + getStringSome() + (capture[5] ? (capture[4] === '-' ? '\\x2d' : '\\x2b') + getStringSome() + capture[5] : `(?:[+-]${getStringSome()}0)?`) + (capture[6] ? getStringMany() + '[oO][fF]' + getStringMany() + capture[6].trim() : '') + getStringSome() + '\\)') - 1) + '`';
|
|
3242
3244
|
});
|
|
3243
3245
|
let selector = '';
|
|
3244
3246
|
for (let i = 0, length = revised.length, casing = false, attr = false, quote = false; i < length; i++) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-r/chrome",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.3",
|
|
4
4
|
"description": "Chrome document constructor for E-mc.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"publishConfig": {
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
},
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
11
|
-
"url": "https://github.com/anpham6/pi-r.git",
|
|
11
|
+
"url": "git+https://github.com/anpham6/pi-r.git",
|
|
12
12
|
"directory": "src/module/chrome"
|
|
13
13
|
},
|
|
14
14
|
"keywords": [
|
|
@@ -20,9 +20,9 @@
|
|
|
20
20
|
"license": "MIT",
|
|
21
21
|
"homepage": "https://github.com/anpham6/pi-r#readme",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@e-mc/cloud": "^0.6.
|
|
24
|
-
"@e-mc/core": "^0.6.
|
|
25
|
-
"@e-mc/document": "^0.6.
|
|
26
|
-
"@e-mc/types": "^0.6.
|
|
23
|
+
"@e-mc/cloud": "^0.6.2",
|
|
24
|
+
"@e-mc/core": "^0.6.2",
|
|
25
|
+
"@e-mc/document": "^0.6.2",
|
|
26
|
+
"@e-mc/types": "^0.6.2"
|
|
27
27
|
}
|
|
28
28
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -91,12 +91,12 @@ export interface IChromeDocument<T extends IFileManager<U>, U extends DocumentAs
|
|
|
91
91
|
formatMap?: ObjectMap<FormatUri>;
|
|
92
92
|
setElementSrc(asset: U, element: IXmlElement, value: string): void;
|
|
93
93
|
findDataValue(name: string): Undef<string>;
|
|
94
|
-
setInlinedAttributes(processing: FinalizeProcessing<T>): void;
|
|
95
|
-
applyTransforms(processing: FinalizeProcessing<T>): Promise<void>;
|
|
96
|
-
rewriteHtml(processing: FinalizeProcessing<T>): Promise<void>;
|
|
97
|
-
setElementAttributes(processing: FinalizeProcessing<T>, domBase: IDomWriter): Promise<void>;
|
|
98
|
-
applyDataSource(processing: FinalizeProcessing<T>, domBase: IDomWriter): Promise<void>;
|
|
99
|
-
setProductionAttributes(processing: FinalizeProcessing<T>): void;
|
|
94
|
+
setInlinedAttributes(processing: FinalizeProcessing<T, U>): void;
|
|
95
|
+
applyTransforms(processing: FinalizeProcessing<T, U>): Promise<void>;
|
|
96
|
+
rewriteHtml(processing: FinalizeProcessing<T, U>): Promise<void>;
|
|
97
|
+
setElementAttributes(processing: FinalizeProcessing<T, U>, domBase: IDomWriter): Promise<void>;
|
|
98
|
+
applyDataSource(processing: FinalizeProcessing<T, U>, domBase: IDomWriter): Promise<void>;
|
|
99
|
+
setProductionAttributes(processing: FinalizeProcessing<T, U>): void;
|
|
100
100
|
removeUnusedStyles(source: string, options?: UserConfig): Undef<string>;
|
|
101
101
|
removeServerRoot(value: string): string;
|
|
102
102
|
replaceContent(source: string, match: RegExpExecArray | string, mimeType?: string): Undef<string>;
|
|
@@ -116,4 +116,4 @@ export interface ChromeDocumentConstructor<T extends IFileManager<U>, U extends
|
|
|
116
116
|
INTERNAL_SERVERROOT: string;
|
|
117
117
|
readonly prototype: IChromeDocument<T, U>;
|
|
118
118
|
new(module?: DocumentModule, ...args: unknown[]): IChromeDocument<T, U>;
|
|
119
|
-
}
|
|
119
|
+
}
|