@e-mc/document 0.13.9 → 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 = require(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)) {
@@ -846,34 +865,36 @@ class Document extends core_1.Client {
846
865
  let encoding, cache;
847
866
  if (typeof options === 'boolean') {
848
867
  cache = options;
868
+ options = undefined;
849
869
  }
850
- else if ((0, types_1.isObject)(options)) {
870
+ else if (options) {
851
871
  ({ encoding, cache } = options);
852
872
  }
853
873
  let result, pkgName;
854
874
  try {
855
875
  if (value.startsWith('npm:')) {
856
- if (!core_1.Client.enabled("node.require.npm")) {
876
+ if (!Client.enabled("node.require.npm")) {
857
877
  return null;
858
878
  }
859
- result = require(pkgName = value.substring(4));
879
+ pkgName = value.slice(4);
880
+ result = options?.default ? requireESM(pkgName, options.url) : require(pkgName);
860
881
  if (typeof result === 'function') {
861
- return Object.defineProperty(result, "__cjs__", { value: true });
882
+ return Object.defineProperty(result, "__cjs__", { value: true, writable: false, enumerable: false });
862
883
  }
863
884
  return result;
864
885
  }
865
- 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;
866
887
  if (typeof source !== 'string') {
867
888
  result = source;
868
889
  }
869
- else if (!(result = (0, types_1.asFunction)(source))) {
890
+ else if (!(result = asFunction(source))) {
870
891
  try {
871
- result = this.tryParse(source, path.extname(value).substring(1));
892
+ result = this.tryParse(source, asExt(value));
872
893
  }
873
894
  catch {
874
895
  }
875
896
  }
876
- 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')) {
877
898
  return result;
878
899
  }
879
900
  }
@@ -903,11 +924,11 @@ class Document extends core_1.Client {
903
924
  }
904
925
  findSourceScope(uri, imports) {
905
926
  const scopes = imports.scopes;
906
- if ((0, types_1.isPlainObject)(scopes)) {
927
+ if (isPlainObject(scopes)) {
907
928
  const qualified = [];
908
929
  for (const qualifier in scopes) {
909
930
  const item = scopes[qualifier];
910
- if (uri.includes(qualifier) && (0, types_1.isPlainObject)(item)) {
931
+ if (uri.includes(qualifier) && isPlainObject(item)) {
911
932
  qualified.push([qualifier, item]);
912
933
  }
913
934
  }
@@ -916,23 +937,23 @@ class Document extends core_1.Client {
916
937
  return [];
917
938
  }
918
939
  findSourceRoot(uri, imports = this.imports) {
919
- if (!(0, types_1.isPlainObject)(imports)) {
940
+ if (!isPlainObject(imports)) {
920
941
  return;
921
942
  }
922
943
  const importsStrict = this.getUserSettings()?.imports_strict ?? this.settings.imports_strict;
923
- const scopes = (importsStrict ? this.findSourceScope(uri, imports) : []).concat([imports]);
924
- const protocol = core_1.Client.isURL(uri);
925
- 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;
926
948
  for (const scope of scopes) {
927
949
  for (const url in scope) {
928
- if (uri === url && (0, types_1.isString)(result = scope[url])) {
929
- if (importsStrict) {
930
- if (core_1.Client.isPath(result) && !(protocol ? url : toPosix(url)).endsWith('/')) {
931
- return toPosix(result);
932
- }
933
- 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);
934
956
  }
935
- return result;
936
957
  }
937
958
  }
938
959
  }
@@ -942,11 +963,11 @@ class Document extends core_1.Client {
942
963
  for (const scope of scopes) {
943
964
  for (const url in scope) {
944
965
  const local = protocol ? url : toPosix(url);
945
- if (local.endsWith('/') && remote.startsWith(local) && (result = scope[url]) && result.endsWith('/')) {
966
+ if (local.endsWith('/') && remote.startsWith(local) && isString(target = scope[url]) && target.endsWith('/')) {
946
967
  if (protocol) {
947
- found.push([url, result]);
968
+ found.push([url, target]);
948
969
  }
949
- 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)) {
950
971
  return toPosix(result);
951
972
  }
952
973
  }
@@ -957,13 +978,13 @@ class Document extends core_1.Client {
957
978
  for (const scope of scopes) {
958
979
  for (const url in scope) {
959
980
  const local = normalizeDir(url);
960
- if ((normalizeDir(uri) === local || core_1.Client.PLATFORM_WIN32 && normalizeDir(uri, true) === local.toLowerCase()) && (0, types_1.isString)(result = scope[url])) {
961
- return result;
981
+ if ((normalizeDir(uri) === local || Client.PLATFORM_WIN32 && normalizeDir(uri, true) === local.toLowerCase()) && isString(target = scope[url])) {
982
+ return target;
962
983
  }
963
984
  }
964
985
  for (const url in scope) {
965
- if (uri.startsWith(normalizeDir(url)) && (0, types_1.isString)(result = scope[url])) {
966
- found.push([url, result]);
986
+ if (uri.startsWith(normalizeDir(url)) && isString(target = scope[url])) {
987
+ found.push([url, target]);
967
988
  }
968
989
  }
969
990
  }
@@ -972,7 +993,7 @@ class Document extends core_1.Client {
972
993
  found.sort((a, b) => b[0].length - a[0].length);
973
994
  if (importsStrict) {
974
995
  for (const url of found) {
975
- if (core_1.Client.isPath(result = toPath(uri, url))) {
996
+ if (Client.isPath(result = toPath(uri, url)) && this.#checkIntegrity(integrity, url[1], result)) {
976
997
  break;
977
998
  }
978
999
  result = '';
@@ -996,31 +1017,31 @@ class Document extends core_1.Client {
996
1017
  }
997
1018
  else if (Object.keys(imports).length > 0) {
998
1019
  const bundleId = file.bundleId;
999
- 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];
1000
1021
  if (!Array.isArray(bundleContent) || bundleContent.length !== assets.length - 1) {
1001
1022
  bundleContent = undefined;
1002
1023
  }
1003
1024
  for (const item of assets) {
1004
1025
  const localFile = !item.exported && item.uri ? this.findSourceRoot(item.uri, imports) : undefined;
1005
- if (localFile && core_1.Client.isPath(localFile) && !item.trailingContent) {
1026
+ if (localFile && Client.isPath(localFile) && !item.trailingContent) {
1006
1027
  sourceFile.push([localFile]);
1007
1028
  }
1008
1029
  else {
1030
+ const localUri = item.localUri;
1009
1031
  let source;
1010
- if (item.bundleIndex === 0) {
1011
- const localUri = item.localUri;
1032
+ if (item.bundleIndex === 0 && localUri) {
1012
1033
  try {
1013
1034
  source = fs.readFileSync(localUri, file.encoding ||= 'utf8');
1014
- if (this.resolveUri && (0, types_1.isArray)(file.trailingContent)) {
1035
+ if (this.resolveUri && isArray(file.trailingContent)) {
1015
1036
  let trailing;
1016
- [source, trailing] = this.resolveUri(file, source, (0, util_1.concatString)(file.trailingContent));
1037
+ [source, trailing] = this.resolveUri(file, source, concatString(file.trailingContent));
1017
1038
  if (trailing) {
1018
1039
  source += trailing;
1019
1040
  }
1020
1041
  }
1021
1042
  }
1022
1043
  catch (err) {
1023
- this.writeFail(["Unable to read file", localUri && path.basename(localUri)], err, 32);
1044
+ this.writeFail(["Unable to read file", path.basename(localUri)], err, 32);
1024
1045
  }
1025
1046
  }
1026
1047
  else if (bundleContent) {
@@ -1062,26 +1083,21 @@ class Document extends core_1.Client {
1062
1083
  switch (format.toLowerCase()) {
1063
1084
  case 'yml':
1064
1085
  case 'yaml':
1065
- return yaml.load(source, options);
1086
+ return load(source, options);
1066
1087
  case 'json5':
1067
1088
  return require('json5').parse(source);
1068
1089
  case 'xml':
1069
1090
  return new (require('fast-xml-parser').XMLParser)(options).parse(source);
1070
1091
  case 'toml':
1071
- try {
1072
- return require('smol-toml').parse(source, options);
1073
- }
1074
- catch {
1075
- return require('toml').parse(source);
1076
- }
1092
+ return require('toml').parse(source);
1077
1093
  default:
1078
1094
  return JSON.parse(source);
1079
1095
  }
1080
1096
  }
1081
1097
  catch (err) {
1082
- const name = (0, util_1.getModuleName)(err);
1098
+ const name = getModuleName(err);
1083
1099
  if (name) {
1084
- this.checkPackage(err, (0, util_1.getModuleName)(err), "Unknown");
1100
+ this.checkPackage(err, getModuleName(err), "Unknown");
1085
1101
  }
1086
1102
  throw err;
1087
1103
  }
@@ -1094,7 +1110,7 @@ class Document extends core_1.Client {
1094
1110
  }
1095
1111
  settingsOf(name, option) {
1096
1112
  const options = this.settings.options?.[name];
1097
- if ((0, types_1.isObject)(options)) {
1113
+ if (isObject(options)) {
1098
1114
  return options[option];
1099
1115
  }
1100
1116
  }
@@ -1103,12 +1119,12 @@ class Document extends core_1.Client {
1103
1119
  if (typeof viewEngine === 'string') {
1104
1120
  target = this.settings.view_engine?.[viewEngine];
1105
1121
  const userConfig = this.getUserSettings()?.view_engine?.[viewEngine];
1106
- if ((0, types_1.isPlainObject)(userConfig)) {
1122
+ if (isObject(userConfig)) {
1107
1123
  if (CACHE_VIEWENGINE.has(userConfig)) {
1108
1124
  target = CACHE_VIEWENGINE.get(userConfig);
1109
1125
  }
1110
- else if ((0, types_1.isPlainObject)(target)) {
1111
- 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 });
1112
1128
  CACHE_VIEWENGINE.set(userConfig, target);
1113
1129
  }
1114
1130
  else {
@@ -1120,13 +1136,13 @@ class Document extends core_1.Client {
1120
1136
  else {
1121
1137
  target = viewEngine;
1122
1138
  }
1123
- if (!((0, types_1.isPlainObject)(target) && (0, types_1.isString)(target.name))) {
1139
+ if (!(isObject(target) && isString(target.name))) {
1124
1140
  this.abort('view_engine');
1125
1141
  const from = typeof viewEngine === 'string' ? viewEngine : this.moduleName;
1126
- 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"));
1127
1143
  return null;
1128
1144
  }
1129
- if (!target.outputEmpty && !(0, types_1.isArray)(data)) {
1145
+ if (!target.outputEmpty && !isArray(data)) {
1130
1146
  return '';
1131
1147
  }
1132
1148
  try {
@@ -1135,15 +1151,15 @@ class Document extends core_1.Client {
1135
1151
  context = require(target.name);
1136
1152
  }
1137
1153
  catch {
1138
- context = await (0, types_1.importESM)(target.name);
1154
+ context = await importESM(target.name);
1139
1155
  }
1140
1156
  const { compile, output } = target.options || {};
1141
1157
  if (this.settingsOf('view_engine', 'coerce') === true) {
1142
1158
  if (compile) {
1143
- (0, types_1.coerceObject)(compile, stored);
1159
+ coerceObject(compile, stored);
1144
1160
  }
1145
1161
  if (output) {
1146
- (0, types_1.coerceObject)(output, stored);
1162
+ coerceObject(output, stored);
1147
1163
  }
1148
1164
  }
1149
1165
  let cache = CACHE_TEMPLATE.get(target.name);
@@ -1152,8 +1168,8 @@ class Document extends core_1.Client {
1152
1168
  CACHE_TEMPLATE.set(target.name, cache);
1153
1169
  }
1154
1170
  const username = this.host?.username || '';
1155
- const cacheKey = (username ? username + ':' : '') + (0, types_1.hashKey)(template + (compile ? core_1.Client.asString(compile) : ''));
1156
- 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;
1157
1173
  if (expires !== 0) {
1158
1174
  render = cache.get(cacheKey);
1159
1175
  }
@@ -1161,7 +1177,7 @@ class Document extends core_1.Client {
1161
1177
  cache.delete(cacheKey);
1162
1178
  }
1163
1179
  if (!render) {
1164
- if ((0, types_1.isArray)(compile)) {
1180
+ if (isArray(compile)) {
1165
1181
  render = typeof context.compileSync === 'function' ? context.compileSync(template, ...compile) : await context.compile(template, ...compile);
1166
1182
  }
1167
1183
  else {
@@ -1170,7 +1186,7 @@ class Document extends core_1.Client {
1170
1186
  if (expires !== 0) {
1171
1187
  cache.set(cacheKey, render);
1172
1188
  if (this.hasPermission('memory')) {
1173
- 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;
1174
1190
  }
1175
1191
  else {
1176
1192
  expires = 60000;
@@ -1190,14 +1206,14 @@ class Document extends core_1.Client {
1190
1206
  const singleRow = !!target.singleRow;
1191
1207
  for (let i = 0, j = 0; i < data.length; ++i) {
1192
1208
  let row = data[i];
1193
- if ((0, types_1.isPlainObject)(row)) {
1209
+ if (isPlainObject(row)) {
1194
1210
  row.__index__ ??= ++j;
1195
1211
  if (output) {
1196
1212
  row = { ...output, ...row };
1197
1213
  }
1198
1214
  }
1199
- else if (!(0, types_1.isObject)(row)) {
1200
- 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}` });
1201
1217
  continue;
1202
1218
  }
1203
1219
  if (!singleRow) {
@@ -1218,7 +1234,7 @@ class Document extends core_1.Client {
1218
1234
  async transform(type, code, format, options = {}) {
1219
1235
  let transform = this.settings.transform;
1220
1236
  const data = transform?.[type];
1221
- if (!(0, types_1.isObject)(data)) {
1237
+ if (!isObject(data)) {
1222
1238
  return;
1223
1239
  }
1224
1240
  if (typeof format === 'string') {
@@ -1232,9 +1248,9 @@ class Document extends core_1.Client {
1232
1248
  const cacheDir = this.hasPermission('memory.user') || this.cacheDir || this.hasPermission('memory');
1233
1249
  if (cacheDir && !CACHE_EXTERNAL[excludeKey = this.moduleName + '_' + type + '_' + format] && config.valid(type, format)) {
1234
1250
  const uri = cacheData.uri;
1235
- const encoding = (0, types_1.getEncoding)(cacheData.encoding);
1236
- const hashOpts = core_1.Client.asString(options.external) + core_1.Client.asString(options.metadata);
1237
- 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) : ''));
1238
1254
  let result, cacheName;
1239
1255
  if (config.etag && cacheData.etag && uri) {
1240
1256
  [result, cacheName] = config.useETag(cache, cacheData.etag, uri);
@@ -1249,18 +1265,18 @@ class Document extends core_1.Client {
1249
1265
  }
1250
1266
  if (result) {
1251
1267
  result.log?.forEach(log => this.addLog(log));
1252
- 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 });
1253
1269
  return result;
1254
1270
  }
1255
1271
  }
1256
1272
  options.cacheData = undefined;
1257
1273
  }
1258
1274
  const imports = transform.imports ||= {};
1259
- const series = new transform_1.TransformSeries(type, code, options);
1275
+ const series = new TransformSeries(type, code, options);
1260
1276
  series.init(this, __dirname);
1261
1277
  let valid = false, excluded = false, userData, userImports, ignoreCache = false, storedLog, sourceFiles;
1262
- if (username && (0, types_1.isObject)(transform = this.getUserSettings()?.transform)) {
1263
- if ((0, types_1.isObject)(transform[type])) {
1278
+ if (username && isObject(transform = this.getUserSettings()?.transform)) {
1279
+ if (isObject(transform[type])) {
1264
1280
  userData = transform[type];
1265
1281
  }
1266
1282
  userImports = transform.imports;
@@ -1280,7 +1296,7 @@ class Document extends core_1.Client {
1280
1296
  if (!plugin || a === plugin) {
1281
1297
  if (b) {
1282
1298
  if (baseConfig) {
1283
- (0, types_1.cloneObject)(b, { target: baseConfig, deep: true, preserve: true });
1299
+ cloneObject(b, { target: baseConfig, deep: true, preserve: true });
1284
1300
  }
1285
1301
  else {
1286
1302
  baseConfig = b;
@@ -1288,7 +1304,7 @@ class Document extends core_1.Client {
1288
1304
  }
1289
1305
  if (c) {
1290
1306
  if (outputConfig) {
1291
- (0, types_1.cloneObject)(c, { target: outputConfig, deep: true, preserve: true });
1307
+ cloneObject(c, { target: outputConfig, deep: true, preserve: true });
1292
1308
  }
1293
1309
  else {
1294
1310
  outputConfig = c;
@@ -1315,10 +1331,10 @@ class Document extends core_1.Client {
1315
1331
  }
1316
1332
  const out = series.out;
1317
1333
  let bypassLog = false, failed = false;
1318
- 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 }))) {
1319
1335
  failed = true;
1320
1336
  ignoreCache = true;
1321
- 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 });
1322
1338
  }
1323
1339
  else if (source !== value) {
1324
1340
  series.code = value;
@@ -1326,16 +1342,16 @@ class Document extends core_1.Client {
1326
1342
  if (out.ignoreCache && isExcluded(type, name, config, cacheData)) {
1327
1343
  ignoreCache = true;
1328
1344
  }
1329
- if ((0, types_1.isArray)(out.sourceFiles)) {
1345
+ if (isArray(out.sourceFiles)) {
1330
1346
  sourceFiles = sourceFiles ? sourceFiles.concat(out.sourceFiles.filter(item => !sourceFiles.includes(item))) : out.sourceFiles.slice(0);
1331
1347
  }
1332
1348
  }
1333
- if ((0, types_1.isArray)(out.logAppend)) {
1349
+ if (isArray(out.logAppend)) {
1334
1350
  out.logAppend.forEach(log => this.addLog(log));
1335
1351
  storedLog = (storedLog || []).concat(out.logAppend);
1336
1352
  bypassLog = true;
1337
1353
  }
1338
- if ((0, types_1.isArray)(out.logQueued)) {
1354
+ if (isArray(out.logQueued)) {
1339
1355
  out.logQueued.forEach(log => this.writeLog(log, true));
1340
1356
  storedLog = (storedLog || []).concat(out.logQueued);
1341
1357
  bypassLog = true;
@@ -1352,17 +1368,17 @@ class Document extends core_1.Client {
1352
1368
  context = require(plugin);
1353
1369
  }
1354
1370
  catch {
1355
- context = await (0, types_1.importESM)(plugin);
1371
+ context = await importESM(plugin);
1356
1372
  }
1357
1373
  series.packageName = plugin;
1358
1374
  if (typeof baseConfig === 'function') {
1359
1375
  series.baseConfig = outputConfig;
1360
- if ((0, types_1.isFunction)(baseConfig, true)) {
1376
+ if (isFunction(baseConfig, true)) {
1361
1377
  next(await baseConfig(context, source, series));
1362
1378
  }
1363
1379
  else {
1364
- const thisArg = core_1.Client.enabled("node.process.inline") ? process : null;
1365
- 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");
1366
1382
  const args = [context, source, series];
1367
1383
  if (baseConfig.toString().startsWith('async')) {
1368
1384
  if (inlineArg) {
@@ -1385,7 +1401,7 @@ class Document extends core_1.Client {
1385
1401
  let transformer = CACHE_PACKAGE.get(target + username);
1386
1402
  if (!transformer) {
1387
1403
  try {
1388
- 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];
1389
1405
  if (pkg) {
1390
1406
  const match = /^(@?\S+)[@:](\d+(?:\.\d+(?:[.-]\S+)?)?|[a-z]+)$/.exec(pkg);
1391
1407
  if (match) {
@@ -1394,7 +1410,7 @@ class Document extends core_1.Client {
1394
1410
  }
1395
1411
  const ext = path.extname(pkg);
1396
1412
  if (ext === '.mjs') {
1397
- transformer = await (0, types_1.importESM)(pkg, false, true);
1413
+ transformer = await importESM(pkg, false, true);
1398
1414
  }
1399
1415
  else if (ext === '.cjs') {
1400
1416
  transformer = require(pkg);
@@ -1404,7 +1420,7 @@ class Document extends core_1.Client {
1404
1420
  transformer = require(pkg);
1405
1421
  }
1406
1422
  catch {
1407
- transformer = await (0, types_1.importESM)(pkg, false, true);
1423
+ transformer = await importESM(pkg, false, true);
1408
1424
  }
1409
1425
  }
1410
1426
  }
@@ -1412,11 +1428,11 @@ class Document extends core_1.Client {
1412
1428
  transformer = context;
1413
1429
  context = null;
1414
1430
  }
1415
- if ((0, types_1.isObject)(transformer)) {
1416
- 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;
1417
1433
  }
1418
1434
  if (typeof transformer !== 'function') {
1419
- throw (0, types_1.errorMessage)(plugin, "Invalid function", pkg || name);
1435
+ throw errorMessage(plugin, "Invalid function", pkg || name);
1420
1436
  }
1421
1437
  if (pkg) {
1422
1438
  CACHE_PACKAGE.set(target + username, transformer);
@@ -1434,7 +1450,7 @@ class Document extends core_1.Client {
1434
1450
  }
1435
1451
  catch (err) {
1436
1452
  abortTransform();
1437
- 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 });
1438
1454
  if (i < length - 1) {
1439
1455
  series.reset();
1440
1456
  }
@@ -1443,10 +1459,10 @@ class Document extends core_1.Client {
1443
1459
  else if (name) {
1444
1460
  abortTransform();
1445
1461
  if (plugin) {
1446
- 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);
1447
1463
  }
1448
1464
  else {
1449
- 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);
1450
1466
  }
1451
1467
  }
1452
1468
  }
@@ -1466,7 +1482,7 @@ class Document extends core_1.Client {
1466
1482
  if (sourceMap.map && sourceMap.code === output.code) {
1467
1483
  output.map = sourceMap.map;
1468
1484
  }
1469
- if ((0, types_1.isArray)(series.supplementChunks)) {
1485
+ if (isArray(series.supplementChunks)) {
1470
1486
  output.chunks = series.supplementChunks.map(item => ({ code: item.code, map: output.map && item.sourceMap?.map, entryPoint: item.entryPoint, filename: item.filename }));
1471
1487
  }
1472
1488
  if (sourceFiles) {
@@ -1477,11 +1493,28 @@ class Document extends core_1.Client {
1477
1493
  }
1478
1494
  return output;
1479
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
+ }
1480
1513
  #getConfigObject(data, name, target, cache) {
1481
1514
  if (this.settingsOf('transform', 'coerce') === true) {
1482
- (0, types_1.coerceObject)(target, cache);
1515
+ coerceObject(target, cache);
1483
1516
  }
1484
- return (0, types_1.cloneObject)(data[name] = target, true);
1517
+ return cloneObject(data[name] = target, true);
1485
1518
  }
1486
1519
  #addConfigError(...message) {
1487
1520
  this.addLog(2, joinString('config', ...message));
@@ -1513,17 +1546,17 @@ class Document extends core_1.Client {
1513
1546
  return [];
1514
1547
  }
1515
1548
  set imports(value) {
1516
- if (!(0, types_1.isPlainObject)(value)) {
1517
- this._imports = null;
1518
- return;
1519
- }
1520
- let imports = this._imports;
1521
- if (imports) {
1522
- 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
+ }
1523
1557
  }
1524
1558
  else {
1525
- imports = this.getUserSettings()?.imports || this.module.imports;
1526
- this._imports = Object.assign(this._imports || {}, (0, types_1.isPlainObject)(imports) ? imports : undefined, value);
1559
+ this._imports = null;
1527
1560
  }
1528
1561
  }
1529
1562
  get imports() {
@@ -1537,4 +1570,5 @@ class Document extends core_1.Client {
1537
1570
  }
1538
1571
  }
1539
1572
  initCache();
1573
+
1540
1574
  module.exports = Document;