@e-mc/document 0.13.10 → 0.14.0

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/index.js CHANGED
@@ -1,16 +1,17 @@
1
1
  "use strict";
2
- const path = require("node:path");
3
- const fs = require("node:fs");
4
- const pm = require("picomatch");
5
- const yaml = require("js-yaml");
6
- const chalk = require("chalk");
7
- const node_util_1 = require("node:util");
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 transform_1 = require("@e-mc/document/transform");
12
- const parse_1 = require("@e-mc/document/parse");
13
- const util_1 = require("@e-mc/document/util");
2
+
3
+ const path = require('node:path');
4
+ const fs = require('node:fs');
5
+ const pm = require('picomatch');
6
+ const chalk = require('chalk');
7
+ const { toUSVString } = require('node:util');
8
+ const { load } = require('js-yaml');
9
+ const { IMPORT_MAP, asExt, asFunction, cloneObject, coerceObject, createAbortError, errorMessage, errorValue, escapePattern, formatSize, getEncoding, hasGlob, hashKey, importESM, incrementUUID, isArray, isEmpty, isError, isFunction, isObject, isPlainObject, isString, parseExpires, requireESM } = require('@e-mc/types');
10
+ const { Client } = require('@e-mc/core');
11
+ const Db = require('@e-mc/db');
12
+ const { SourceMap, TransformSeries } = require('@e-mc/document/transform');
13
+ const { XmlWriter } = require('@e-mc/document/parse');
14
+ const { PATTERN_PARENTHESIS, appendSuffix, concatString, getHashData, getIndent, getModuleName, getNewline, spliceString } = require('@e-mc/document/util');
14
15
  const kDocument = Symbol.for('document:constructor');
15
16
  const CACHE_PACKAGE = new Map();
16
17
  const CACHE_CONFIG = new Map();
@@ -38,7 +39,7 @@ function deleteTransform(map, key, timeout) {
38
39
  }
39
40
  function getSourceMappingURL(value, css) {
40
41
  if (value.includes(' ')) {
41
- value = encodeURIComponent((0, node_util_1.toUSVString)(value));
42
+ value = encodeURIComponent(toUSVString(value));
42
43
  }
43
44
  return css ? `\n/*# sourceMappingURL=${value} */\n` : `\n//# sourceMappingURL=${value}\n`;
44
45
  }
@@ -47,21 +48,21 @@ function normalizeDir(value, check) {
47
48
  if (check) {
48
49
  value = toPosix(value).toLowerCase();
49
50
  }
50
- return value.endsWith(sep) ? value : value + sep;
51
+ return value.at(-1) === sep ? value : value + sep;
51
52
  }
52
53
  function cloneConfigItems(items) {
53
54
  const [a, b, c] = items;
54
- return [a, (typeof b === 'object' ? (0, types_1.cloneObject)(b, true) : b), typeof c === 'object' ? (0, types_1.cloneObject)(c, true) : c];
55
+ return [a, (typeof b === 'object' ? cloneObject(b, true) : b), typeof c === 'object' ? cloneObject(c, true) : c];
55
56
  }
56
57
  const isExcluded = (type, name, config, cacheData) => !(config?.hasType(type, name) || cacheData?.override === true);
57
58
  const wrapCount = (value) => chalk.grey('(') + value + chalk.grey(')');
58
59
  const fixHint = (warningCount, errorCount, value) => warningCount > 0 || errorCount > 0 ? ':' + value : '';
59
60
  const compareValue = (value) => value.replace(/["'()]/g, '').trim();
60
- const toPath = (uri, hostname) => path.resolve(hostname[1], uri.substring(normalizeDir(hostname[0]).length).split('?')[0]);
61
+ const toPath = (uri, hostname) => path.resolve(hostname[1], uri.slice(normalizeDir(hostname[0]).length).split('?')[0]);
61
62
  const toBase64 = (value) => 'data:application/json;base64,' + Buffer.from(value).toString('base64');
62
- const toPosix = (value) => core_1.Client.PLATFORM_WIN32 ? value.trim().replace(/(?:^\\|\\+)/g, '/') : value;
63
+ const toPosix = (value) => Client.PLATFORM_WIN32 ? value.trim().replace(/(?:^\\|\\+)/g, '/') : value;
63
64
  const joinString = (name, ...values) => (name ? name + ': ' : '') + values.reduce((a, b) => b ? a + (a ? ' -> ' : '') + b : a, '');
64
- const truncateString = (value, width) => value.length > width ? value.substring(0, width - 3) + '...' : value.padStart(width);
65
+ const truncateString = (value, width) => value.length > width ? value.slice(0, width - 3) + '...' : value.padStart(width);
65
66
  class TransformCache {
66
67
  config;
67
68
  cacheData;
@@ -79,9 +80,9 @@ class TransformCache {
79
80
  }
80
81
  set(type, data) {
81
82
  let pathname;
82
- if (typeof this.cacheDir === 'string' && core_1.Client.createDir(pathname = path.join(this.cacheDir, 'transform', type))) {
83
+ if (typeof this.cacheDir === 'string' && Client.createDir(pathname = path.join(this.cacheDir, 'transform', type))) {
83
84
  try {
84
- fs.writeFileSync(pathname = path.join(pathname, (0, types_1.incrementUUID)()), JSON.stringify(data));
85
+ fs.writeFileSync(pathname = path.join(pathname, incrementUUID()), JSON.stringify(data));
85
86
  return pathname;
86
87
  }
87
88
  catch {
@@ -183,7 +184,7 @@ class TransformConfig {
183
184
  algorithm = options;
184
185
  enabled = true;
185
186
  }
186
- else if ((0, types_1.isObject)(options)) {
187
+ else if (options) {
187
188
  ({ enabled = true, algorithm, etag, expires, renew, limit, include, exclude } = options);
188
189
  }
189
190
  if (!enabled) {
@@ -207,32 +208,28 @@ class TransformConfig {
207
208
  if (typeof etag === 'boolean') {
208
209
  this.etag = etag;
209
210
  }
210
- if (expires && (expires = (0, types_1.parseExpires)(expires)) >= 0) {
211
- this.expires = Math.min(expires, core_1.Client.MAX_TIMEOUT);
211
+ if (expires && (expires = parseExpires(expires)) >= 0) {
212
+ this.expires = Math.min(expires, Client.MAX_TIMEOUT);
212
213
  }
213
214
  if (renew) {
214
215
  this.renew = true;
215
216
  }
216
- if ((0, types_1.isPlainObject)(include)) {
217
- for (const type in include) {
218
- const item = include[type];
219
- if (item === '*') {
220
- this.include[type] = true;
221
- }
222
- else if ((0, types_1.isArray)(item)) {
223
- this.include[type] = item;
224
- }
217
+ for (const type in include) {
218
+ const item = include[type];
219
+ if (item === '*') {
220
+ this.include[type] = true;
221
+ }
222
+ else if (isArray(item)) {
223
+ this.include[type] = item;
225
224
  }
226
225
  }
227
- if ((0, types_1.isPlainObject)(exclude)) {
228
- for (const type in exclude) {
229
- const item = exclude[type];
230
- if (item === '*') {
231
- this.exclude[type] = true;
232
- }
233
- else if ((0, types_1.isArray)(item)) {
234
- this.exclude[type] = item;
235
- }
226
+ for (const type in exclude) {
227
+ const item = exclude[type];
228
+ if (item === '*') {
229
+ this.exclude[type] = true;
230
+ }
231
+ else if (isArray(item)) {
232
+ this.exclude[type] = item;
236
233
  }
237
234
  }
238
235
  if (limit !== undefined) {
@@ -241,7 +238,7 @@ class TransformConfig {
241
238
  if (parseFloat(limit) === 0) {
242
239
  value = 0;
243
240
  }
244
- else if ((value = (0, types_1.formatSize)(limit)) === 0) {
241
+ else if ((value = formatSize(limit)) === 0) {
245
242
  return;
246
243
  }
247
244
  }
@@ -299,7 +296,7 @@ class TransformConfig {
299
296
  }
300
297
  useHash(cache, code) {
301
298
  let key;
302
- if (this.withinLimit(code, cache.encoding) && (key = core_1.Client.asHash(code, this.algorithm, { encoding: cache.encoding }))) {
299
+ if (this.withinLimit(code, cache.encoding) && (key = Client.asHash(code, this.algorithm, { encoding: cache.encoding }))) {
303
300
  const hashMap = CACHE_HASH[this.moduleName] ||= new Map();
304
301
  const stored = hashMap.get(key);
305
302
  let result;
@@ -335,7 +332,7 @@ class TransformConfig {
335
332
  return limit === Infinity || limit > 0 && Buffer.byteLength(code, encoding) <= limit;
336
333
  }
337
334
  }
338
- class Document extends core_1.Client {
335
+ class Document extends Client {
339
336
  static [kDocument] = true;
340
337
  static async purgeMemory(percent = 1, limit = 0, parent) {
341
338
  if (limit > 0 && CACHE_TOTAL < limit) {
@@ -384,14 +381,11 @@ class Document extends core_1.Client {
384
381
  static async finalize(instance) {
385
382
  for (const ext of instance.extensions) {
386
383
  if (instance.aborted) {
387
- return (0, types_1.createAbortError)(true);
384
+ return createAbortError(true);
388
385
  }
389
386
  try {
390
387
  const args = [instance];
391
- if ((0, types_1.isFunction)(ext, true)) {
392
- args.push(__dirname);
393
- }
394
- else if (core_1.Client.enabled("node.require.inline")) {
388
+ if (!isFunction(ext, true) && Client.enabled("node.require.inline")) {
395
389
  args.push(require);
396
390
  }
397
391
  await ext.apply(this, args);
@@ -429,16 +423,16 @@ class Document extends core_1.Client {
429
423
  sourceMappingURL += '.map';
430
424
  }
431
425
  if (hash) {
432
- const [algorithm, length] = (0, util_1.getHashData)(hash);
426
+ const [algorithm, length] = getHashData(hash);
433
427
  if (algorithm) {
434
428
  const value = this.asHash(output, algorithm);
435
429
  if (value) {
436
- sourceMappingURL = (0, util_1.appendSuffix)(sourceMappingURL, length ? value.substring(0, length) : value);
430
+ sourceMappingURL = appendSuffix(sourceMappingURL, length ? value.slice(0, length) : value);
437
431
  }
438
432
  }
439
433
  }
440
434
  }
441
- let code = data.code.replace(transform_1.SourceMap.SOURCE_MAPPING_URL, (...capture) => {
435
+ let code = data.code.replace(SourceMap.SOURCE_MAPPING_URL, (...capture) => {
442
436
  flags |= 1;
443
437
  if (capture[2] && capture[5]) {
444
438
  css = true;
@@ -469,10 +463,19 @@ class Document extends core_1.Client {
469
463
  }
470
464
  }
471
465
  static createSourceMap(code, uri, remove) {
472
- return new transform_1.SourceMap(code, uri, remove);
466
+ return new SourceMap(code, uri, remove);
473
467
  }
474
- static updateGradle(source, namespaces, value, options) {
475
- const local = /^([\w.]+)(?:\((.+)\)|\s*(=)?\s*(".+"|'.+'|\(.+\)||\[.+\]|\S+))$/s.exec(value = value.trim());
468
+ static updateGradle(source, namespaces, values, options) {
469
+ let value;
470
+ if (Array.isArray(values)) {
471
+ values = values.slice(0);
472
+ value = values.pop().trim();
473
+ }
474
+ else {
475
+ value = values.trim();
476
+ values = [];
477
+ }
478
+ const local = /^([\w.]+)(?:\((.+)\)|\s*(=)?\s*(".+"|'.+'|\(.+\)||\[.+\]|\S+))$/s.exec(value);
476
479
  if (!local) {
477
480
  return source;
478
481
  }
@@ -485,28 +488,44 @@ class Document extends core_1.Client {
485
488
  }
486
489
  const replacement = addendum ? value + ' ' + addendum : value;
487
490
  const length = namespaces.length;
488
- let ident, lastIndex = 0, i = 0;
491
+ let ident, lastMatch = null, lastIndex = 0, i = 0;
489
492
  while (i < length) {
490
- const pattern = new RegExp(`([\\t ]*)${(0, types_1.escapePattern)(namespaces[i])}\\s*\\{` + parse_1.XmlWriter.PATTERN_TRAILINGSPACE);
493
+ const item = namespaces[i];
494
+ const pattern = new RegExp(`([\\t ]*)${item instanceof RegExp ? item.source : escapePattern(item)}\\s*\\{[ \\t]*(?:\\r?\\n)*`);
491
495
  pattern.lastIndex = lastIndex;
492
- const match = pattern.exec(source);
493
- if (!match) {
494
- break;
496
+ if (lastMatch = pattern.exec(source)) {
497
+ if (i > 0 && !ident && lastMatch[1]) {
498
+ ident = lastMatch[1];
499
+ }
500
+ lastIndex = lastMatch.index + lastMatch[0].length;
495
501
  }
496
- if (i > 0 && !ident && match[1]) {
497
- ident = match[1];
502
+ else {
503
+ break;
498
504
  }
499
- lastIndex = match.index + match[0].length;
500
505
  ++i;
501
506
  }
502
- const newline = (0, util_1.getNewline)(source);
503
- ident ||= (0, util_1.getIndent)(source);
504
- if (i === length) {
505
- const pattern = new RegExp(`\\b(${(0, types_1.escapePattern)(local[1])}` + (local[2] ? `\\(${util_1.PATTERN_PARENTHESIS}\\)` : '\\b' + (local[3] ? '\\s*=\\s*' : '\\s*') + `("[^"]+"|'[^']+'|\\(${util_1.PATTERN_PARENTHESIS}\\)|\\S+)?`) + ')' + (addendum ? '[^\\r\\n]*' : '[^\\w\\r\\n]*'), 'g');
507
+ const newline = getNewline(source);
508
+ ident ||= getIndent(source);
509
+ if (lastMatch) {
510
+ if (lastMatch[2]) {
511
+ let block = lastMatch[0];
512
+ for (let j = 0; j < values.length; ++j) {
513
+ const group = lastMatch[j + 2];
514
+ if (group) {
515
+ block = block.replace(group, values[j]);
516
+ }
517
+ else {
518
+ return source;
519
+ }
520
+ }
521
+ source = spliceString(source, lastMatch.index, lastMatch.index + lastMatch[0].length, block);
522
+ lastIndex = lastMatch.index + block.length;
523
+ }
524
+ const pattern = new RegExp(`\\b(${escapePattern(local[1])}` + (local[2] ? `\\(${PATTERN_PARENTHESIS}\\)` : '\\b' + (local[3] ? '\\s*=\\s*' : '\\s*') + `("[^"]+"|'[^']+'|\\(${PATTERN_PARENTHESIS}\\)|\\S+)?`) + ')' + (addendum ? '[^\\r\\n]*' : '[^\\w\\r\\n]*'), 'g');
506
525
  pattern.lastIndex = lastIndex;
507
- let match;
526
+ let match, found = false;
508
527
  while (match = pattern.exec(source)) {
509
- const preceding = source.substring(lastIndex, match.index);
528
+ const preceding = source.slice(lastIndex, match.index);
510
529
  let opening = 0, closing = 0;
511
530
  for (let j = 0, q = preceding.length; j < q; ++j) {
512
531
  switch (preceding[j]) {
@@ -519,15 +538,16 @@ class Document extends core_1.Client {
519
538
  }
520
539
  }
521
540
  if (opening === closing) {
541
+ found = true;
522
542
  if (!multiple || local[2] && local[1].includes('.') || match[2] && local[4] && compareValue(match[2]) === compareValue(local[4])) {
523
- return upgrade && match[1] !== value ? parse_1.XmlWriter.replaceMatch(match, source, replacement, pattern) : source;
543
+ return upgrade && match[1] !== value ? XmlWriter.replaceMatch(match, source, replacement, pattern) : source;
524
544
  }
525
545
  lastIndex = match.index + match[0].length;
526
546
  }
527
547
  }
528
- return (0, util_1.spliceString)(source, lastIndex, lastIndex, ident.repeat(length) + replacement + newline);
548
+ return found && updateOnly ? source : spliceString(source, lastIndex, lastIndex, ident.repeat(length) + replacement + newline);
529
549
  }
530
- if (updateOnly) {
550
+ if (updateOnly || namespaces.some(item => item instanceof RegExp)) {
531
551
  return source;
532
552
  }
533
553
  const j = i;
@@ -540,7 +560,7 @@ class Document extends core_1.Client {
540
560
  trailing += ident.repeat(i) + '}' + newline;
541
561
  }
542
562
  const content = leading + ident.repeat(length) + replacement + newline + trailing;
543
- return lastIndex > 0 ? (0, util_1.spliceString)(source, lastIndex, lastIndex, content) : source.trimEnd() + newline + newline + content;
563
+ return lastIndex > 0 ? spliceString(source, lastIndex, lastIndex, content) : source.trimEnd() + newline + newline + content;
544
564
  }
545
565
  static generateLintTable(messages, options) {
546
566
  const { leadingText, trailingText, pathname, filename, ruleWidth = 30, messageWidth = 60 } = options;
@@ -624,9 +644,8 @@ class Document extends core_1.Client {
624
644
  }
625
645
  restart() { }
626
646
  init(assets, config) {
627
- let ignoreModules, ignoreExtensions;
647
+ let baseUrl, ignoreModules, ignoreExtensions;
628
648
  if (config) {
629
- let baseUrl;
630
649
  ({ baseUrl, ignoreModules, ignoreExtensions } = config);
631
650
  const users = this.getUserSettings();
632
651
  if (Array.isArray(users?.extensions)) {
@@ -646,11 +665,11 @@ class Document extends core_1.Client {
646
665
  const items = [];
647
666
  for (const pattern in pages) {
648
667
  const item = pages[pattern];
649
- if ((0, types_1.isObject)(item)) {
668
+ if (isObject(item)) {
650
669
  if (pattern === baseUrl) {
651
670
  items.push(item);
652
671
  }
653
- else if ((0, types_1.hasGlob)(pattern)) {
672
+ else if (hasGlob(pattern)) {
654
673
  const isMatch = CACHE_PICOMATCH[pattern] ||= pm(pattern, { matchBase: true });
655
674
  if (isMatch(baseUrl)) {
656
675
  items.push(item);
@@ -669,7 +688,7 @@ class Document extends core_1.Client {
669
688
  if (mimeMap) {
670
689
  for (const item of assets) {
671
690
  const merge = item.mimeType && mimeMap[item.mimeType];
672
- if ((0, types_1.isObject)(merge)) {
691
+ if (isObject(merge)) {
673
692
  Object.assign(item, merge);
674
693
  }
675
694
  }
@@ -685,12 +704,12 @@ class Document extends core_1.Client {
685
704
  let instance = null;
686
705
  if (handler && handler !== "@e-mc/db") {
687
706
  try {
688
- const Module = (0, types_1.requireESM)(handler);
689
- if (core_1.Client.constructorOf(Module, 'clientdb')) {
707
+ const Module = requireESM(handler);
708
+ if (Client.constructorOf(Module, 'clientdb')) {
690
709
  instance = new Module(db, database);
691
710
  }
692
711
  else {
693
- throw (0, types_1.errorMessage)(this.moduleName, "Not a Db constructor", handler);
712
+ throw errorMessage(this.moduleName, "Not a Db constructor", handler);
694
713
  }
695
714
  }
696
715
  catch (err) {
@@ -698,7 +717,7 @@ class Document extends core_1.Client {
698
717
  }
699
718
  }
700
719
  else {
701
- instance = new db_1(db, database);
720
+ instance = new Db(db, database);
702
721
  }
703
722
  if (instance) {
704
723
  const host = this.host;
@@ -721,11 +740,11 @@ class Document extends core_1.Client {
721
740
  }
722
741
  else {
723
742
  const extensions = this._extensions;
724
- if ((0, types_1.isArray)(extensions)) {
743
+ if (isArray(extensions)) {
725
744
  if (typeof ignoreExtensions === 'string') {
726
745
  this._extensions = extensions.filter(value => value !== ignoreExtensions);
727
746
  }
728
- else if ((0, types_1.isArray)(ignoreExtensions)) {
747
+ else if (isArray(ignoreExtensions)) {
729
748
  this._extensions = extensions.filter(value => !ignoreExtensions.includes(value));
730
749
  }
731
750
  }
@@ -734,10 +753,10 @@ class Document extends core_1.Client {
734
753
  return this;
735
754
  }
736
755
  abort(name, reason) {
737
- if (this.aborted || (0, types_1.isString)(name) && this.settingsOf(name, 'abort') !== true) {
756
+ if (this.aborted || isString(name) && this.settingsOf(name, 'abort') !== true) {
738
757
  return;
739
758
  }
740
- if (name instanceof Error) {
759
+ if (isError(name)) {
741
760
  reason ||= name;
742
761
  }
743
762
  super.abort(reason);
@@ -807,7 +826,7 @@ class Document extends core_1.Client {
807
826
  }
808
827
  this.#addConfigError("\"output\" can only be a plain object");
809
828
  }
810
- else if ((0, types_1.isPlainObject)(result)) {
829
+ else if (isPlainObject(result)) {
811
830
  return this.#getConfigObject(data, name, result, false);
812
831
  }
813
832
  else if (path.isAbsolute(value)) {
@@ -854,28 +873,28 @@ class Document extends core_1.Client {
854
873
  let result, pkgName;
855
874
  try {
856
875
  if (value.startsWith('npm:')) {
857
- if (!core_1.Client.enabled("node.require.npm")) {
876
+ if (!Client.enabled("node.require.npm")) {
858
877
  return null;
859
878
  }
860
- pkgName = value.substring(4);
861
- result = options?.default ? (0, types_1.requireESM)(pkgName, options.url) : require(pkgName);
879
+ pkgName = value.slice(4);
880
+ result = options?.default ? requireESM(pkgName, options.url) : require(pkgName);
862
881
  if (typeof result === 'function') {
863
- return Object.defineProperty(result, "__cjs__", { value: true });
882
+ return Object.defineProperty(result, "__cjs__", { value: true, writable: false, enumerable: false });
864
883
  }
865
884
  return result;
866
885
  }
867
- const source = this.readFile(value, { ownPermissionOnly: true, absolutePath: this.hasEval('absolute'), requireExt: true, encoding: (0, types_1.getEncoding)(encoding), cache }) || value;
886
+ const source = this.readFile(value, { ownPermissionOnly: true, absolutePath: this.hasEval('absolute'), requireExt: true, encoding: getEncoding(encoding), cache }) || value;
868
887
  if (typeof source !== 'string') {
869
888
  result = source;
870
889
  }
871
- else if (!(result = (0, types_1.asFunction)(source))) {
890
+ else if (!(result = asFunction(source))) {
872
891
  try {
873
- result = this.tryParse(source, path.extname(value).substring(1));
892
+ result = this.tryParse(source, asExt(value));
874
893
  }
875
894
  catch {
876
895
  }
877
896
  }
878
- if ((0, types_1.isObject)(result) || (0, types_1.isFunction)(result, true) || typeof result === 'function' && this.hasEval('function')) {
897
+ if (isObject(result) || isFunction(result, true) || typeof result === 'function' && this.hasEval('function')) {
879
898
  return result;
880
899
  }
881
900
  }
@@ -905,11 +924,11 @@ class Document extends core_1.Client {
905
924
  }
906
925
  findSourceScope(uri, imports) {
907
926
  const scopes = imports.scopes;
908
- if ((0, types_1.isPlainObject)(scopes)) {
927
+ if (isPlainObject(scopes)) {
909
928
  const qualified = [];
910
929
  for (const qualifier in scopes) {
911
930
  const item = scopes[qualifier];
912
- if (uri.includes(qualifier) && (0, types_1.isPlainObject)(item)) {
931
+ if (uri.includes(qualifier) && isPlainObject(item)) {
913
932
  qualified.push([qualifier, item]);
914
933
  }
915
934
  }
@@ -918,23 +937,23 @@ class Document extends core_1.Client {
918
937
  return [];
919
938
  }
920
939
  findSourceRoot(uri, imports = this.imports) {
921
- if (!(0, types_1.isPlainObject)(imports)) {
940
+ if (!isPlainObject(imports)) {
922
941
  return;
923
942
  }
924
943
  const importsStrict = this.getUserSettings()?.imports_strict ?? this.settings.imports_strict;
925
- const scopes = (importsStrict ? this.findSourceScope(uri, imports) : []).concat([imports]);
926
- const protocol = core_1.Client.isURL(uri);
927
- let result;
944
+ const scopes = (importsStrict ? this.findSourceScope(uri, imports) : []).concat([isPlainObject(imports.imports) ? imports.imports : imports]);
945
+ const integrity = isPlainObject(imports.integrity) ? imports.integrity : undefined;
946
+ const protocol = Client.isURL(uri);
947
+ let result = '', target;
928
948
  for (const scope of scopes) {
929
949
  for (const url in scope) {
930
- if (uri === url && (0, types_1.isString)(result = scope[url])) {
931
- if (importsStrict) {
932
- if (core_1.Client.isPath(result) && !(protocol ? url : toPosix(url)).endsWith('/')) {
933
- return toPosix(result);
934
- }
935
- continue;
950
+ if (uri === url && isString(target = scope[url])) {
951
+ if (!importsStrict) {
952
+ return target;
953
+ }
954
+ if (Client.isPath(target) && !(protocol ? url : toPosix(url)).endsWith('/') && this.#checkIntegrity(integrity, url, target)) {
955
+ return toPosix(target);
936
956
  }
937
- return result;
938
957
  }
939
958
  }
940
959
  }
@@ -944,11 +963,11 @@ class Document extends core_1.Client {
944
963
  for (const scope of scopes) {
945
964
  for (const url in scope) {
946
965
  const local = protocol ? url : toPosix(url);
947
- if (local.endsWith('/') && remote.startsWith(local) && (result = scope[url]) && result.endsWith('/')) {
966
+ if (local.endsWith('/') && remote.startsWith(local) && isString(target = scope[url]) && target.endsWith('/')) {
948
967
  if (protocol) {
949
- found.push([url, result]);
968
+ found.push([url, target]);
950
969
  }
951
- else if (core_1.Client.isPath(result = path.join(result, remote.substring(local.length)))) {
970
+ else if (Client.isPath(result = path.join(target, remote.slice(local.length))) && this.#checkIntegrity(integrity, url, target)) {
952
971
  return toPosix(result);
953
972
  }
954
973
  }
@@ -959,13 +978,13 @@ class Document extends core_1.Client {
959
978
  for (const scope of scopes) {
960
979
  for (const url in scope) {
961
980
  const local = normalizeDir(url);
962
- if ((normalizeDir(uri) === local || core_1.Client.PLATFORM_WIN32 && normalizeDir(uri, true) === local.toLowerCase()) && (0, types_1.isString)(result = scope[url])) {
963
- return result;
981
+ if ((normalizeDir(uri) === local || Client.PLATFORM_WIN32 && normalizeDir(uri, true) === local.toLowerCase()) && isString(target = scope[url])) {
982
+ return target;
964
983
  }
965
984
  }
966
985
  for (const url in scope) {
967
- if (uri.startsWith(normalizeDir(url)) && (0, types_1.isString)(result = scope[url])) {
968
- found.push([url, result]);
986
+ if (uri.startsWith(normalizeDir(url)) && isString(target = scope[url])) {
987
+ found.push([url, target]);
969
988
  }
970
989
  }
971
990
  }
@@ -974,7 +993,7 @@ class Document extends core_1.Client {
974
993
  found.sort((a, b) => b[0].length - a[0].length);
975
994
  if (importsStrict) {
976
995
  for (const url of found) {
977
- if (core_1.Client.isPath(result = toPath(uri, url))) {
996
+ if (Client.isPath(result = toPath(uri, url)) && this.#checkIntegrity(integrity, url[1], result)) {
978
997
  break;
979
998
  }
980
999
  result = '';
@@ -998,31 +1017,31 @@ class Document extends core_1.Client {
998
1017
  }
999
1018
  else if (Object.keys(imports).length > 0) {
1000
1019
  const bundleId = file.bundleId;
1001
- const assets = !(0, types_1.isEmpty)(bundleId) ? this.assets.filter(item => item.bundleId === bundleId).sort((a, b) => a.bundleIndex - b.bundleIndex) : [file];
1020
+ const assets = !isEmpty(bundleId) ? this.assets.filter(item => item.bundleId === bundleId).sort((a, b) => a.bundleIndex - b.bundleIndex) : [file];
1002
1021
  if (!Array.isArray(bundleContent) || bundleContent.length !== assets.length - 1) {
1003
1022
  bundleContent = undefined;
1004
1023
  }
1005
1024
  for (const item of assets) {
1006
1025
  const localFile = !item.exported && item.uri ? this.findSourceRoot(item.uri, imports) : undefined;
1007
- if (localFile && core_1.Client.isPath(localFile) && !item.trailingContent) {
1026
+ if (localFile && Client.isPath(localFile) && !item.trailingContent) {
1008
1027
  sourceFile.push([localFile]);
1009
1028
  }
1010
1029
  else {
1030
+ const localUri = item.localUri;
1011
1031
  let source;
1012
- if (item.bundleIndex === 0) {
1013
- const localUri = item.localUri;
1032
+ if (item.bundleIndex === 0 && localUri) {
1014
1033
  try {
1015
1034
  source = fs.readFileSync(localUri, file.encoding ||= 'utf8');
1016
- if (this.resolveUri && (0, types_1.isArray)(file.trailingContent)) {
1035
+ if (this.resolveUri && isArray(file.trailingContent)) {
1017
1036
  let trailing;
1018
- [source, trailing] = this.resolveUri(file, source, (0, util_1.concatString)(file.trailingContent));
1037
+ [source, trailing] = this.resolveUri(file, source, concatString(file.trailingContent));
1019
1038
  if (trailing) {
1020
1039
  source += trailing;
1021
1040
  }
1022
1041
  }
1023
1042
  }
1024
1043
  catch (err) {
1025
- this.writeFail(["Unable to read file", localUri && path.basename(localUri)], err, 32);
1044
+ this.writeFail(["Unable to read file", path.basename(localUri)], err, 32);
1026
1045
  }
1027
1046
  }
1028
1047
  else if (bundleContent) {
@@ -1064,26 +1083,21 @@ class Document extends core_1.Client {
1064
1083
  switch (format.toLowerCase()) {
1065
1084
  case 'yml':
1066
1085
  case 'yaml':
1067
- return yaml.load(source, options);
1086
+ return load(source, options);
1068
1087
  case 'json5':
1069
1088
  return require('json5').parse(source);
1070
1089
  case 'xml':
1071
1090
  return new (require('fast-xml-parser').XMLParser)(options).parse(source);
1072
1091
  case 'toml':
1073
- try {
1074
- return require('smol-toml').parse(source, options);
1075
- }
1076
- catch {
1077
- return require('toml').parse(source);
1078
- }
1092
+ return require('toml').parse(source);
1079
1093
  default:
1080
1094
  return JSON.parse(source);
1081
1095
  }
1082
1096
  }
1083
1097
  catch (err) {
1084
- const name = (0, util_1.getModuleName)(err);
1098
+ const name = getModuleName(err);
1085
1099
  if (name) {
1086
- this.checkPackage(err, (0, util_1.getModuleName)(err), "Unknown");
1100
+ this.checkPackage(err, getModuleName(err), "Unknown");
1087
1101
  }
1088
1102
  throw err;
1089
1103
  }
@@ -1096,7 +1110,7 @@ class Document extends core_1.Client {
1096
1110
  }
1097
1111
  settingsOf(name, option) {
1098
1112
  const options = this.settings.options?.[name];
1099
- if ((0, types_1.isObject)(options)) {
1113
+ if (isObject(options)) {
1100
1114
  return options[option];
1101
1115
  }
1102
1116
  }
@@ -1105,12 +1119,12 @@ class Document extends core_1.Client {
1105
1119
  if (typeof viewEngine === 'string') {
1106
1120
  target = this.settings.view_engine?.[viewEngine];
1107
1121
  const userConfig = this.getUserSettings()?.view_engine?.[viewEngine];
1108
- if ((0, types_1.isPlainObject)(userConfig)) {
1122
+ if (isObject(userConfig)) {
1109
1123
  if (CACHE_VIEWENGINE.has(userConfig)) {
1110
1124
  target = CACHE_VIEWENGINE.get(userConfig);
1111
1125
  }
1112
- else if ((0, types_1.isPlainObject)(target)) {
1113
- target = (0, types_1.cloneObject)(userConfig, { target: { ...target }, deep: true, preserve: true, structured: true });
1126
+ else if (isObject(target)) {
1127
+ target = cloneObject(userConfig, { target: { ...target }, deep: true, preserve: true, structured: true });
1114
1128
  CACHE_VIEWENGINE.set(userConfig, target);
1115
1129
  }
1116
1130
  else {
@@ -1122,13 +1136,13 @@ class Document extends core_1.Client {
1122
1136
  else {
1123
1137
  target = viewEngine;
1124
1138
  }
1125
- if (!((0, types_1.isPlainObject)(target) && (0, types_1.isString)(target.name))) {
1139
+ if (!(isObject(target) && isString(target.name))) {
1126
1140
  this.abort('view_engine');
1127
1141
  const from = typeof viewEngine === 'string' ? viewEngine : this.moduleName;
1128
- this.writeFail(["Unable to load configuration", from], (0, types_1.errorMessage)('view-engine', from, "Unknown"));
1142
+ this.writeFail(["Unable to load configuration", from], errorMessage('view-engine', from, "Unknown"));
1129
1143
  return null;
1130
1144
  }
1131
- if (!target.outputEmpty && !(0, types_1.isArray)(data)) {
1145
+ if (!target.outputEmpty && !isArray(data)) {
1132
1146
  return '';
1133
1147
  }
1134
1148
  try {
@@ -1137,15 +1151,15 @@ class Document extends core_1.Client {
1137
1151
  context = require(target.name);
1138
1152
  }
1139
1153
  catch {
1140
- context = await (0, types_1.importESM)(target.name);
1154
+ context = await importESM(target.name);
1141
1155
  }
1142
1156
  const { compile, output } = target.options || {};
1143
1157
  if (this.settingsOf('view_engine', 'coerce') === true) {
1144
1158
  if (compile) {
1145
- (0, types_1.coerceObject)(compile, stored);
1159
+ coerceObject(compile, stored);
1146
1160
  }
1147
1161
  if (output) {
1148
- (0, types_1.coerceObject)(output, stored);
1162
+ coerceObject(output, stored);
1149
1163
  }
1150
1164
  }
1151
1165
  let cache = CACHE_TEMPLATE.get(target.name);
@@ -1154,8 +1168,8 @@ class Document extends core_1.Client {
1154
1168
  CACHE_TEMPLATE.set(target.name, cache);
1155
1169
  }
1156
1170
  const username = this.host?.username || '';
1157
- const cacheKey = (username ? username + ':' : '') + (0, types_1.hashKey)(template + (compile ? core_1.Client.asString(compile) : ''));
1158
- let result = '', valid = false, expires = typeof target.expires === 'string' ? (0, types_1.parseExpires)(target.expires) : target.expires, render;
1171
+ const cacheKey = (username ? username + ':' : '') + hashKey(template + (compile ? Client.asString(compile) : ''));
1172
+ let result = '', valid = false, expires = typeof target.expires === 'string' ? parseExpires(target.expires) : target.expires, render;
1159
1173
  if (expires !== 0) {
1160
1174
  render = cache.get(cacheKey);
1161
1175
  }
@@ -1163,7 +1177,7 @@ class Document extends core_1.Client {
1163
1177
  cache.delete(cacheKey);
1164
1178
  }
1165
1179
  if (!render) {
1166
- if ((0, types_1.isArray)(compile)) {
1180
+ if (isArray(compile)) {
1167
1181
  render = typeof context.compileSync === 'function' ? context.compileSync(template, ...compile) : await context.compile(template, ...compile);
1168
1182
  }
1169
1183
  else {
@@ -1172,7 +1186,7 @@ class Document extends core_1.Client {
1172
1186
  if (expires !== 0) {
1173
1187
  cache.set(cacheKey, render);
1174
1188
  if (this.hasPermission('memory')) {
1175
- expires = typeof expires === 'number' && expires !== Infinity ? Math.min(expires, core_1.Client.MAX_TIMEOUT) : 0;
1189
+ expires = typeof expires === 'number' && expires !== Infinity ? Math.min(expires, Client.MAX_TIMEOUT) : 0;
1176
1190
  }
1177
1191
  else {
1178
1192
  expires = 60000;
@@ -1192,14 +1206,14 @@ class Document extends core_1.Client {
1192
1206
  const singleRow = !!target.singleRow;
1193
1207
  for (let i = 0, j = 0; i < data.length; ++i) {
1194
1208
  let row = data[i];
1195
- if ((0, types_1.isPlainObject)(row)) {
1209
+ if (isPlainObject(row)) {
1196
1210
  row.__index__ ??= ++j;
1197
1211
  if (output) {
1198
1212
  row = { ...output, ...row };
1199
1213
  }
1200
1214
  }
1201
- else if (!(0, types_1.isObject)(row)) {
1202
- this.addLog(3, joinString('view engine', target.name, core_1.Client.asString(row) || "Unknown"), { source: `row #${i + 1}` });
1215
+ else if (!isObject(row)) {
1216
+ this.addLog(3, joinString('view engine', target.name, Client.asString(row) || "Unknown"), { source: `row #${i + 1}` });
1203
1217
  continue;
1204
1218
  }
1205
1219
  if (!singleRow) {
@@ -1220,7 +1234,7 @@ class Document extends core_1.Client {
1220
1234
  async transform(type, code, format, options = {}) {
1221
1235
  let transform = this.settings.transform;
1222
1236
  const data = transform?.[type];
1223
- if (!(0, types_1.isObject)(data)) {
1237
+ if (!isObject(data)) {
1224
1238
  return;
1225
1239
  }
1226
1240
  if (typeof format === 'string') {
@@ -1234,9 +1248,9 @@ class Document extends core_1.Client {
1234
1248
  const cacheDir = this.hasPermission('memory.user') || this.cacheDir || this.hasPermission('memory');
1235
1249
  if (cacheDir && !CACHE_EXTERNAL[excludeKey = this.moduleName + '_' + type + '_' + format] && config.valid(type, format)) {
1236
1250
  const uri = cacheData.uri;
1237
- const encoding = (0, types_1.getEncoding)(cacheData.encoding);
1238
- const hashOpts = core_1.Client.asString(options.external) + core_1.Client.asString(options.metadata);
1239
- cache = new TransformCache(config, cacheData, cacheDir, encoding, (username ? username + ':' : '') + type + '_' + format + '_' + encoding + (hashOpts ? '_' + (0, types_1.hashKey)(hashOpts) : ''));
1251
+ const encoding = getEncoding(cacheData.encoding);
1252
+ const hashOpts = Client.asString(options.external) + Client.asString(options.metadata);
1253
+ cache = new TransformCache(config, cacheData, cacheDir, encoding, (username ? username + ':' : '') + type + '_' + format + '_' + encoding + (hashOpts ? '_' + hashKey(hashOpts) : ''));
1240
1254
  let result, cacheName;
1241
1255
  if (config.etag && cacheData.etag && uri) {
1242
1256
  [result, cacheName] = config.useETag(cache, cacheData.etag, uri);
@@ -1251,18 +1265,18 @@ class Document extends core_1.Client {
1251
1265
  }
1252
1266
  if (result) {
1253
1267
  result.log?.forEach(log => this.addLog(log));
1254
- this.formatMessage(4, type, [joinString(cacheName, format.filter(value => value).join(' | '), options.filename), 'cache'], uri, { ...core_1.Client.LOG_STYLE_NOTICE, hintBold: true });
1268
+ this.formatMessage(4, type, [joinString(cacheName, format.filter(value => value).join(' | '), options.filename), 'cache'], uri, { ...Client.LOG_STYLE_NOTICE, hintBold: true });
1255
1269
  return result;
1256
1270
  }
1257
1271
  }
1258
1272
  options.cacheData = undefined;
1259
1273
  }
1260
1274
  const imports = transform.imports ||= {};
1261
- const series = new transform_1.TransformSeries(type, code, options);
1275
+ const series = new TransformSeries(type, code, options);
1262
1276
  series.init(this, __dirname);
1263
1277
  let valid = false, excluded = false, userData, userImports, ignoreCache = false, storedLog, sourceFiles;
1264
- if (username && (0, types_1.isObject)(transform = this.getUserSettings()?.transform)) {
1265
- if ((0, types_1.isObject)(transform[type])) {
1278
+ if (username && isObject(transform = this.getUserSettings()?.transform)) {
1279
+ if (isObject(transform[type])) {
1266
1280
  userData = transform[type];
1267
1281
  }
1268
1282
  userImports = transform.imports;
@@ -1282,7 +1296,7 @@ class Document extends core_1.Client {
1282
1296
  if (!plugin || a === plugin) {
1283
1297
  if (b) {
1284
1298
  if (baseConfig) {
1285
- (0, types_1.cloneObject)(b, { target: baseConfig, deep: true, preserve: true });
1299
+ cloneObject(b, { target: baseConfig, deep: true, preserve: true });
1286
1300
  }
1287
1301
  else {
1288
1302
  baseConfig = b;
@@ -1290,7 +1304,7 @@ class Document extends core_1.Client {
1290
1304
  }
1291
1305
  if (c) {
1292
1306
  if (outputConfig) {
1293
- (0, types_1.cloneObject)(c, { target: outputConfig, deep: true, preserve: true });
1307
+ cloneObject(c, { target: outputConfig, deep: true, preserve: true });
1294
1308
  }
1295
1309
  else {
1296
1310
  outputConfig = c;
@@ -1317,10 +1331,10 @@ class Document extends core_1.Client {
1317
1331
  }
1318
1332
  const out = series.out;
1319
1333
  let bypassLog = false, failed = false;
1320
- if (typeof value !== 'string' || (0, types_1.isArray)(out.sourceFiles) && (this.hasPermission('fs') || process.permission) && out.sourceFiles.some(item => !this.canRead(item, { ownPermissionOnly: true }))) {
1334
+ if (typeof value !== 'string' || isArray(out.sourceFiles) && (this.hasPermission('fs') || process.permission) && out.sourceFiles.some(item => !this.canRead(item, { ownPermissionOnly: true }))) {
1321
1335
  failed = true;
1322
1336
  ignoreCache = true;
1323
- this.writeFail(["Unable to transform document", plugin], (0, types_1.errorMessage)(plugin, name, typeof value === 'string' ? "Unsupported access" : "Empty"), { type: 4, startTime });
1337
+ this.writeFail(["Unable to transform document", plugin], errorMessage(plugin, name, typeof value === 'string' ? "Unsupported access" : "Empty"), { type: 4, startTime });
1324
1338
  }
1325
1339
  else if (source !== value) {
1326
1340
  series.code = value;
@@ -1328,16 +1342,16 @@ class Document extends core_1.Client {
1328
1342
  if (out.ignoreCache && isExcluded(type, name, config, cacheData)) {
1329
1343
  ignoreCache = true;
1330
1344
  }
1331
- if ((0, types_1.isArray)(out.sourceFiles)) {
1345
+ if (isArray(out.sourceFiles)) {
1332
1346
  sourceFiles = sourceFiles ? sourceFiles.concat(out.sourceFiles.filter(item => !sourceFiles.includes(item))) : out.sourceFiles.slice(0);
1333
1347
  }
1334
1348
  }
1335
- if ((0, types_1.isArray)(out.logAppend)) {
1349
+ if (isArray(out.logAppend)) {
1336
1350
  out.logAppend.forEach(log => this.addLog(log));
1337
1351
  storedLog = (storedLog || []).concat(out.logAppend);
1338
1352
  bypassLog = true;
1339
1353
  }
1340
- if ((0, types_1.isArray)(out.logQueued)) {
1354
+ if (isArray(out.logQueued)) {
1341
1355
  out.logQueued.forEach(log => this.writeLog(log, true));
1342
1356
  storedLog = (storedLog || []).concat(out.logQueued);
1343
1357
  bypassLog = true;
@@ -1354,17 +1368,17 @@ class Document extends core_1.Client {
1354
1368
  context = require(plugin);
1355
1369
  }
1356
1370
  catch {
1357
- context = await (0, types_1.importESM)(plugin);
1371
+ context = await importESM(plugin);
1358
1372
  }
1359
1373
  series.packageName = plugin;
1360
1374
  if (typeof baseConfig === 'function') {
1361
1375
  series.baseConfig = outputConfig;
1362
- if ((0, types_1.isFunction)(baseConfig, true)) {
1376
+ if (isFunction(baseConfig, true)) {
1363
1377
  next(await baseConfig(context, source, series));
1364
1378
  }
1365
1379
  else {
1366
- const thisArg = core_1.Client.enabled("node.process.inline") ? process : null;
1367
- const inlineArg = core_1.Client.enabled("node.require.inline");
1380
+ const thisArg = Client.enabled("node.process.inline") ? process : null;
1381
+ const inlineArg = Client.enabled("node.require.inline");
1368
1382
  const args = [context, source, series];
1369
1383
  if (baseConfig.toString().startsWith('async')) {
1370
1384
  if (inlineArg) {
@@ -1387,7 +1401,7 @@ class Document extends core_1.Client {
1387
1401
  let transformer = CACHE_PACKAGE.get(target + username);
1388
1402
  if (!transformer) {
1389
1403
  try {
1390
- let pkg = this.resolveDir('package', plugin + '.js') || this.resolveDir('package', plugin + '.cjs') || this.resolveDir('package', plugin + '.mjs') || userImports?.[plugin] || imports[plugin] || types_1.IMPORT_MAP[plugin];
1404
+ let pkg = this.resolveDir('package', plugin + '.js') || this.resolveDir('package', plugin + '.cjs') || this.resolveDir('package', plugin + '.mjs') || userImports?.[plugin] || imports[plugin] || IMPORT_MAP[plugin];
1391
1405
  if (pkg) {
1392
1406
  const match = /^(@?\S+)[@:](\d+(?:\.\d+(?:[.-]\S+)?)?|[a-z]+)$/.exec(pkg);
1393
1407
  if (match) {
@@ -1396,7 +1410,7 @@ class Document extends core_1.Client {
1396
1410
  }
1397
1411
  const ext = path.extname(pkg);
1398
1412
  if (ext === '.mjs') {
1399
- transformer = await (0, types_1.importESM)(pkg, false, true);
1413
+ transformer = await importESM(pkg, false, true);
1400
1414
  }
1401
1415
  else if (ext === '.cjs') {
1402
1416
  transformer = require(pkg);
@@ -1406,7 +1420,7 @@ class Document extends core_1.Client {
1406
1420
  transformer = require(pkg);
1407
1421
  }
1408
1422
  catch {
1409
- transformer = await (0, types_1.importESM)(pkg, false, true);
1423
+ transformer = await importESM(pkg, false, true);
1410
1424
  }
1411
1425
  }
1412
1426
  }
@@ -1414,11 +1428,11 @@ class Document extends core_1.Client {
1414
1428
  transformer = context;
1415
1429
  context = null;
1416
1430
  }
1417
- if ((0, types_1.isObject)(transformer)) {
1418
- transformer = typeof transformer[name] === 'function' ? transformer[name] : typeof transformer[name.replaceAll('-', '_')] === 'function' ? transformer[name.replaceAll('-', '_')] : transformer.default;
1431
+ if (isObject(transformer)) {
1432
+ transformer = typeof transformer[name] === 'function' ? transformer[name] : typeof transformer[name.replace(/-/g, '_')] === 'function' ? transformer[name.replace(/-/g, '_')] : transformer.default;
1419
1433
  }
1420
1434
  if (typeof transformer !== 'function') {
1421
- throw (0, types_1.errorMessage)(plugin, "Invalid function", pkg || name);
1435
+ throw errorMessage(plugin, "Invalid function", pkg || name);
1422
1436
  }
1423
1437
  if (pkg) {
1424
1438
  CACHE_PACKAGE.set(target + username, transformer);
@@ -1436,7 +1450,7 @@ class Document extends core_1.Client {
1436
1450
  }
1437
1451
  catch (err) {
1438
1452
  abortTransform();
1439
- this.checkPackage(err, (0, util_1.getModuleName)(err), ["Unable to transform document", target], { type: 4, startTime });
1453
+ this.checkPackage(err, getModuleName(err), ["Unable to transform document", target], { type: 4, startTime });
1440
1454
  if (i < length - 1) {
1441
1455
  series.reset();
1442
1456
  }
@@ -1445,10 +1459,10 @@ class Document extends core_1.Client {
1445
1459
  else if (name) {
1446
1460
  abortTransform();
1447
1461
  if (plugin) {
1448
- this.writeFail("Unable to load configuration", (0, types_1.errorMessage)(plugin, name, "Invalid config"), 4);
1462
+ this.writeFail("Unable to load configuration", errorMessage(plugin, name, "Invalid config"), 4);
1449
1463
  }
1450
1464
  else {
1451
- this.writeFail("Format method was not found", (0, types_1.errorValue)(name, "Unknown"), 4);
1465
+ this.writeFail("Format method was not found", errorValue(name, "Unknown"), 4);
1452
1466
  }
1453
1467
  }
1454
1468
  }
@@ -1468,7 +1482,7 @@ class Document extends core_1.Client {
1468
1482
  if (sourceMap.map && sourceMap.code === output.code) {
1469
1483
  output.map = sourceMap.map;
1470
1484
  }
1471
- if ((0, types_1.isArray)(series.supplementChunks)) {
1485
+ if (isArray(series.supplementChunks)) {
1472
1486
  output.chunks = series.supplementChunks.map(item => ({ code: item.code, map: output.map && item.sourceMap?.map, entryPoint: item.entryPoint, filename: item.filename }));
1473
1487
  }
1474
1488
  if (sourceFiles) {
@@ -1479,11 +1493,28 @@ class Document extends core_1.Client {
1479
1493
  }
1480
1494
  return output;
1481
1495
  }
1496
+ #checkIntegrity(metadata, url, localUri) {
1497
+ const integrity = metadata?.[url];
1498
+ if (!isString(integrity)) {
1499
+ return true;
1500
+ }
1501
+ try {
1502
+ const match = /^(sha(?:256|384|512))-(.+)$/i.exec(integrity);
1503
+ if (match && hashKey(fs.readFileSync(localUri), match[1], 'base64') === match[2]) {
1504
+ return true;
1505
+ }
1506
+ this.addLog(3, joinString('checksum', url, integrity), 'imports', path.basename(localUri));
1507
+ }
1508
+ catch (err) {
1509
+ this.writeFail(["Unable to read file", path.basename(localUri)], err, 32);
1510
+ }
1511
+ return false;
1512
+ }
1482
1513
  #getConfigObject(data, name, target, cache) {
1483
1514
  if (this.settingsOf('transform', 'coerce') === true) {
1484
- (0, types_1.coerceObject)(target, cache);
1515
+ coerceObject(target, cache);
1485
1516
  }
1486
- return (0, types_1.cloneObject)(data[name] = target, true);
1517
+ return cloneObject(data[name] = target, true);
1487
1518
  }
1488
1519
  #addConfigError(...message) {
1489
1520
  this.addLog(2, joinString('config', ...message));
@@ -1515,17 +1546,17 @@ class Document extends core_1.Client {
1515
1546
  return [];
1516
1547
  }
1517
1548
  set imports(value) {
1518
- if (!(0, types_1.isPlainObject)(value)) {
1519
- this._imports = null;
1520
- return;
1521
- }
1522
- let imports = this._imports;
1523
- if (imports) {
1524
- this._imports = Object.assign(imports, value);
1549
+ if (isPlainObject(value)) {
1550
+ if (this._imports) {
1551
+ this._imports = Object.assign(this._imports, value);
1552
+ }
1553
+ else {
1554
+ const imports = this.getUserSettings()?.imports || this.module.imports;
1555
+ this._imports = Object.assign({}, isPlainObject(imports) ? imports : undefined, value);
1556
+ }
1525
1557
  }
1526
1558
  else {
1527
- imports = this.getUserSettings()?.imports || this.module.imports;
1528
- this._imports = Object.assign(this._imports || {}, (0, types_1.isPlainObject)(imports) ? imports : undefined, value);
1559
+ this._imports = null;
1529
1560
  }
1530
1561
  }
1531
1562
  get imports() {
@@ -1539,4 +1570,5 @@ class Document extends core_1.Client {
1539
1570
  }
1540
1571
  }
1541
1572
  initCache();
1573
+
1542
1574
  module.exports = Document;