@e-mc/document 0.11.8 → 0.12.1

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/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # @e-mc/document
2
2
 
3
- * NodeJS 16 LTS
4
- * ES2021
3
+ * NodeJS 18
4
+ * ES2022
5
5
 
6
6
  ## General Usage
7
7
 
@@ -9,7 +9,7 @@
9
9
 
10
10
  ## Interface
11
11
 
12
- * [View Source](https://www.unpkg.com/@e-mc/types@0.11.8/lib/index.d.ts)
12
+ * [View Source](https://www.unpkg.com/@e-mc/types@0.12.1/lib/index.d.ts)
13
13
 
14
14
  ```typescript
15
15
  import type { DataSource, ViewEngine } from "./squared";
@@ -61,7 +61,7 @@ interface IDocument extends IClient<IFileManager, DocumentModule, TransformCallb
61
61
  cloudUpload?(state: IScopeOrigin<IFileManager, ICloud>, file: ExternalAsset, url: string, active: boolean): Promise<boolean>;
62
62
  cloudFinalize?(state: IScopeOrigin<IFileManager, ICloud>): Promise<unknown[]>;
63
63
  watchInit?(watch: IFileGroup<ExternalAsset>, assets: ExternalAsset[], sanitize?: boolean): WatchInitResult | undefined;
64
- watchModified?(watch: IFileGroup<ExternalAsset>, assets?: ExternalAsset[]): PostFinalizeCallback;
64
+ watchModified?(watch: IFileGroup<ExternalAsset>, assets?: ExternalAsset[], recursive?: [string, string[]][]): PostFinalizeCallback;
65
65
  set dataSource(value: DataSource[]);
66
66
  get dataSource(): DataSource[];
67
67
  set imports(value);
@@ -185,14 +185,14 @@ NOTE: **@e-mc/document** is an abstract base class and cannot be instantiated. *
185
185
 
186
186
  ## References
187
187
 
188
- - https://www.unpkg.com/@e-mc/types@0.11.8/lib/squared.d.ts
189
- - https://www.unpkg.com/@e-mc/types@0.11.8/lib/asset.d.ts
190
- - https://www.unpkg.com/@e-mc/types@0.11.8/lib/core.d.ts
191
- - https://www.unpkg.com/@e-mc/types@0.11.8/lib/document.d.ts
192
- - https://www.unpkg.com/@e-mc/types@0.11.8/lib/filemanager.d.ts
193
- - https://www.unpkg.com/@e-mc/types@0.11.8/lib/logger.d.ts
194
- - https://www.unpkg.com/@e-mc/types@0.11.8/lib/settings.d.ts
195
- - https://www.unpkg.com/@e-mc/types@0.11.8/lib/watch.d.ts
188
+ - https://www.unpkg.com/@e-mc/types@0.12.1/lib/squared.d.ts
189
+ - https://www.unpkg.com/@e-mc/types@0.12.1/lib/asset.d.ts
190
+ - https://www.unpkg.com/@e-mc/types@0.12.1/lib/core.d.ts
191
+ - https://www.unpkg.com/@e-mc/types@0.12.1/lib/document.d.ts
192
+ - https://www.unpkg.com/@e-mc/types@0.12.1/lib/filemanager.d.ts
193
+ - https://www.unpkg.com/@e-mc/types@0.12.1/lib/logger.d.ts
194
+ - https://www.unpkg.com/@e-mc/types@0.12.1/lib/settings.d.ts
195
+ - https://www.unpkg.com/@e-mc/types@0.12.1/lib/watch.d.ts
196
196
 
197
197
  ## LICENSE
198
198
 
package/index.js CHANGED
@@ -11,6 +11,7 @@ const db_1 = require("@e-mc/db");
11
11
  const transform_1 = require("@e-mc/document/transform");
12
12
  const parse_1 = require("@e-mc/document/parse");
13
13
  const util_1 = require("@e-mc/document/util");
14
+ const kDocument = Symbol.for('document:constructor');
14
15
  const CACHE_PACKAGE = {};
15
16
  const CACHE_TEMPLATE = {};
16
17
  const CACHE_EXTERNAL = {};
@@ -57,16 +58,20 @@ const toBase64 = (value) => 'data:application/json;base64,' + Buffer.from(value)
57
58
  const toPosix = (value) => core_1.Client.PLATFORM_WIN32 ? value.trim().replace(/(?:^\\|\\+)/g, '/') : value;
58
59
  const joinString = (name, ...values) => (name ? name + ': ' : '') + values.reduce((a, b) => b ? a + (a ? ' -> ' : '') + b : a, '');
59
60
  const truncateString = (value, width) => value.length > width ? value.substring(0, width - 3) + '...' : value.padStart(width);
60
- const isFunction = (value) => typeof value === 'function';
61
61
  class TransformCache {
62
+ config;
63
+ cacheData;
64
+ cacheDir;
65
+ encoding;
66
+ formatKey;
67
+ formatType = 0;
68
+ hashKey = '';
62
69
  constructor(config, cacheData, cacheDir, encoding, formatKey) {
63
70
  this.config = config;
64
71
  this.cacheData = cacheData;
65
72
  this.cacheDir = cacheDir;
66
73
  this.encoding = encoding;
67
74
  this.formatKey = formatKey;
68
- this.formatType = 0;
69
- this.hashKey = '';
70
75
  }
71
76
  set(type, data) {
72
77
  let pathname;
@@ -151,15 +156,16 @@ class TransformCache {
151
156
  }
152
157
  }
153
158
  class TransformConfig {
159
+ moduleName;
160
+ algorithm = undefined;
161
+ etag = false;
162
+ expires = 0;
163
+ renew = false;
164
+ limit = Infinity;
165
+ exclude = {};
166
+ include = {};
154
167
  constructor(moduleName) {
155
168
  this.moduleName = moduleName;
156
- this.algorithm = undefined;
157
- this.etag = false;
158
- this.expires = 0;
159
- this.renew = false;
160
- this.limit = Infinity;
161
- this.exclude = {};
162
- this.include = {};
163
169
  }
164
170
  init(options) {
165
171
  let enabled = false, algorithm, etag, expires, renew, limit, include, exclude;
@@ -326,6 +332,7 @@ class TransformConfig {
326
332
  }
327
333
  }
328
334
  class Document extends core_1.Client {
335
+ static [kDocument] = true;
329
336
  static async purgeMemory(percent = 1, limit = 0, parent) {
330
337
  if (limit > 0 && CACHE_TOTAL < limit) {
331
338
  return 0;
@@ -377,7 +384,7 @@ class Document extends core_1.Client {
377
384
  }
378
385
  try {
379
386
  const args = [instance];
380
- if (ext["__cjs__"]) {
387
+ if ((0, types_1.isFunction)(ext, true)) {
381
388
  args.push(__dirname);
382
389
  }
383
390
  else if (core_1.Client.enabled("node.require.inline")) {
@@ -427,7 +434,7 @@ class Document extends core_1.Client {
427
434
  }
428
435
  }
429
436
  }
430
- let code = data.code.replace(transform_1.SourceMap.RE_SOURCE_MAPPING_URL, (...capture) => {
437
+ let code = data.code.replace(transform_1.SourceMap.SOURCE_MAPPING_URL, (...capture) => {
431
438
  flags |= 1;
432
439
  if (capture[2] && capture[5]) {
433
440
  css = true;
@@ -598,14 +605,14 @@ class Document extends core_1.Client {
598
605
  }
599
606
  return result;
600
607
  }
608
+ Db = null;
609
+ _assets = null;
610
+ _dataSource = null;
611
+ _transformConfig = null;
612
+ _mimeMap = null;
613
+ _imports = null;
601
614
  constructor(data) {
602
615
  super(data);
603
- this.Db = null;
604
- this._assets = null;
605
- this._dataSource = null;
606
- this._transformConfig = null;
607
- this._mimeMap = null;
608
- this._imports = null;
609
616
  const transform = this.settingsOf('transform', 'cache');
610
617
  if (transform !== undefined) {
611
618
  this.customize({ transform });
@@ -678,9 +685,9 @@ class Document extends core_1.Client {
678
685
  let instance;
679
686
  if (handler && handler !== "@e-mc/db") {
680
687
  try {
681
- const Handler = require(handler);
682
- if (isFunction(Handler) && Handler.prototype instanceof core_1.ClientDb) {
683
- instance = new Handler(db, database);
688
+ const Module = require(handler);
689
+ if (core_1.Client.constructorOf(Module, 'clientdb')) {
690
+ instance = new Module(db, database);
684
691
  }
685
692
  else {
686
693
  throw (0, types_1.errorMessage)(this.moduleName, "Not a Db constructor", handler);
@@ -710,7 +717,7 @@ class Document extends core_1.Client {
710
717
  if (!ignoreExtensions) {
711
718
  return this;
712
719
  }
713
- if (ignoreExtensions === true || ignoreExtensions === this.moduleName || (0, types_1.isArray)(ignoreExtensions) && ignoreExtensions.includes(this.moduleName)) {
720
+ if (ignoreExtensions === true || ignoreExtensions === this.moduleName || Array.isArray(ignoreExtensions) && ignoreExtensions.includes(this.moduleName)) {
714
721
  this._extensions = [];
715
722
  }
716
723
  else {
@@ -730,7 +737,10 @@ class Document extends core_1.Client {
730
737
  if (this.aborted || (0, types_1.isString)(name) && this.settingsOf(name, 'abort') !== true) {
731
738
  return;
732
739
  }
733
- super.abort(reason || (name instanceof Error ? name : undefined));
740
+ if (name instanceof Error) {
741
+ reason ||= name;
742
+ }
743
+ super.abort(reason);
734
744
  }
735
745
  customize(options) {
736
746
  const transform = options.transform;
@@ -793,25 +803,24 @@ class Document extends core_1.Client {
793
803
  }
794
804
  resolveDir(name, ...paths) {
795
805
  let baseDir = this.settings.directory?.[name];
796
- if (!baseDir) {
797
- return;
798
- }
799
- try {
800
- baseDir = path.resolve(baseDir);
801
- const username = this.host?.username;
802
- let result;
803
- if (username) {
804
- const leading = path.join(baseDir, 'users', username);
805
- if (fs.existsSync(result = path.join(leading, ...paths))) {
806
+ if (baseDir) {
807
+ try {
808
+ baseDir = path.resolve(baseDir);
809
+ const username = this.host?.username;
810
+ let result;
811
+ if (username) {
812
+ const leading = path.join(baseDir, 'users', username);
813
+ if (fs.existsSync(result = path.join(leading, ...paths))) {
814
+ return result;
815
+ }
816
+ }
817
+ if (fs.existsSync(result = path.join(baseDir, ...paths))) {
806
818
  return result;
807
819
  }
808
820
  }
809
- if (fs.existsSync(result = path.join(baseDir, ...paths))) {
810
- return result;
821
+ catch {
811
822
  }
812
823
  }
813
- catch {
814
- }
815
824
  }
816
825
  asSourceFile(value, options) {
817
826
  let encoding, cache;
@@ -854,7 +863,7 @@ class Document extends core_1.Client {
854
863
  catch {
855
864
  }
856
865
  }
857
- if ((0, types_1.isObject)(result) || typeof result === 'function' && (result["__cjs__"] || this.hasEval('function'))) {
866
+ if ((0, types_1.isObject)(result) || (0, types_1.isFunction)(result, true) || typeof result === 'function' && this.hasEval('function')) {
858
867
  return result;
859
868
  }
860
869
  }
@@ -864,8 +873,8 @@ class Document extends core_1.Client {
864
873
  return null;
865
874
  }
866
875
  findVersion(name, fallback = '') {
867
- let result;
868
876
  const versions = this.module.versions;
877
+ let result;
869
878
  if (versions) {
870
879
  if (Array.isArray(name)) {
871
880
  for (const value of name) {
@@ -989,7 +998,7 @@ class Document extends core_1.Client {
989
998
  if (item.bundleIndex === 0) {
990
999
  const localUri = item.localUri;
991
1000
  try {
992
- source = fs.readFileSync(localUri, file.encoding ||= 'utf-8');
1001
+ source = fs.readFileSync(localUri, file.encoding ||= 'utf8');
993
1002
  if (this.resolveUri && (0, types_1.isArray)(file.trailingContent)) {
994
1003
  let trailing;
995
1004
  [source, trailing] = this.resolveUri(file, source, (0, util_1.concatString)(file.trailingContent));
@@ -1013,7 +1022,7 @@ class Document extends core_1.Client {
1013
1022
  }
1014
1023
  }
1015
1024
  }
1016
- if (sourceFile.length > 0 && (sourceFile[0] && (mainFile = sourceFile[0][0]) || !invalid) && (!this.hasOwnPermission() || !sourceFile.some(item => item[0] && !this.canRead(item[0])))) {
1025
+ if (sourceFile.length > 0 && (sourceFile[0] && (mainFile = sourceFile[0][0]) || !invalid) && (!this.hasPermission('fs') && !process.permission || !sourceFile.some(item => item[0] && !this.canRead(item[0])))) {
1017
1026
  return { code, sourceFile: !invalid ? sourceFile : undefined, sourcesRelativeTo: mainFile && path.dirname(mainFile) };
1018
1027
  }
1019
1028
  };
@@ -1090,20 +1099,18 @@ class Document extends core_1.Client {
1090
1099
  else {
1091
1100
  target = viewEngine;
1092
1101
  }
1093
- if (!((0, types_1.isPlainObject)(target) && target.name)) {
1102
+ if (!(0, types_1.isPlainObject)(target) || !(0, types_1.isString)(target.name)) {
1094
1103
  this.abort('view_engine');
1095
1104
  const from = typeof viewEngine === 'string' ? viewEngine : this.moduleName;
1096
1105
  this.writeFail(["Unable to load configuration", from], (0, types_1.errorMessage)('view-engine', from, "Unknown"));
1097
1106
  return null;
1098
1107
  }
1099
- const length = data.length;
1100
- if (length === 0 && !target.outputEmpty) {
1108
+ if (data.length === 0 && !target.outputEmpty) {
1101
1109
  return '';
1102
1110
  }
1103
1111
  try {
1104
1112
  const context = require(target.name);
1105
- let { singleRow, expires, options = {} } = target;
1106
- const { compile, output } = options;
1113
+ const { compile, output } = target.options || {};
1107
1114
  if (this.settingsOf('view_engine', 'coerce') === true) {
1108
1115
  if (compile) {
1109
1116
  (0, types_1.coerceObject)(compile, stored);
@@ -1112,13 +1119,10 @@ class Document extends core_1.Client {
1112
1119
  (0, types_1.coerceObject)(output, stored);
1113
1120
  }
1114
1121
  }
1115
- if (typeof expires === 'string') {
1116
- expires = (0, types_1.parseExpires)(expires);
1117
- }
1118
1122
  const username = this.host?.username || '';
1119
1123
  const cache = CACHE_TEMPLATE[target.name] ||= {};
1120
1124
  const cacheKey = (username ? username + ':' : '') + (0, types_1.hashKey)(template + (compile ? core_1.Client.asString(compile) : ''));
1121
- let result = '', render, valid = false;
1125
+ let result = '', valid = false, expires = typeof target.expires === 'string' ? (0, types_1.parseExpires)(target.expires) : target.expires, render;
1122
1126
  if (expires !== 0) {
1123
1127
  render = cache[cacheKey];
1124
1128
  }
@@ -1126,10 +1130,15 @@ class Document extends core_1.Client {
1126
1130
  delete cache[cacheKey];
1127
1131
  }
1128
1132
  if (!render) {
1129
- render = await context.compile(template, compile);
1133
+ if ((0, types_1.isArray)(compile)) {
1134
+ render = typeof context.compileSync === 'function' ? context.compileSync(template, ...compile) : await context.compile(template, ...compile);
1135
+ }
1136
+ else {
1137
+ render = typeof context.compileSync === 'function' ? context.compileSync(template, compile) : await context.compile(template, compile);
1138
+ }
1130
1139
  if (expires !== 0) {
1131
1140
  cache[cacheKey] = render;
1132
- if (core_1.Client.enabled("memory.settings.users", username)) {
1141
+ if (this.hasPermission('memory')) {
1133
1142
  expires = typeof expires === 'number' && expires !== Infinity ? Math.min(expires, core_1.Client.MAX_TIMEOUT) : 0;
1134
1143
  }
1135
1144
  else {
@@ -1147,7 +1156,8 @@ class Document extends core_1.Client {
1147
1156
  valid = true;
1148
1157
  }
1149
1158
  };
1150
- for (let i = 0, j = 0; i < length; ++i) {
1159
+ const singleRow = !!target.singleRow;
1160
+ for (let i = 0, j = 0; i < data.length; ++i) {
1151
1161
  let row = data[i];
1152
1162
  if ((0, types_1.isPlainObject)(row)) {
1153
1163
  row.__index__ ??= ++j;
@@ -1156,7 +1166,7 @@ class Document extends core_1.Client {
1156
1166
  }
1157
1167
  }
1158
1168
  else if (!(0, types_1.isObject)(row)) {
1159
- this.addLog(types_1.STATUS_TYPE.WARN, joinString('view engine', target.name, `row #${i + 1}`, core_1.Client.asString(row) || "Unknown"));
1169
+ this.addLog(types_1.STATUS_TYPE.WARN, joinString('view engine', target.name, core_1.Client.asString(row) || "Unknown"), { source: `row #${i + 1}` });
1160
1170
  continue;
1161
1171
  }
1162
1172
  if (!singleRow) {
@@ -1176,16 +1186,18 @@ class Document extends core_1.Client {
1176
1186
  }
1177
1187
  async transform(type, code, format, options = {}) {
1178
1188
  let transform = this.settings.transform, data;
1179
- if (!(transform && (0, types_1.isObject)(data = transform[type]))) {
1189
+ if (!(0, types_1.isObject)(transform) || !(0, types_1.isObject)(data = transform[type])) {
1180
1190
  return;
1181
1191
  }
1182
- format = typeof format === 'string' ? format.trim().split(/\s*\+\s*/) : format.map(item => typeof item === 'string' ? item.trim() : '');
1192
+ if (typeof format === 'string') {
1193
+ format = format.trim().split(/\s*\+\s*/);
1194
+ }
1183
1195
  const username = this.host?.username || '';
1184
1196
  const config = this._transformConfig;
1185
1197
  const cacheData = config && options.cacheData;
1186
1198
  let cache = null, excludeKey;
1187
1199
  if (cacheData) {
1188
- const cacheDir = username && core_1.Client.enabled("memory.settings.users", username) ? true : this.cacheDir || core_1.Client.enabled("memory.settings.users");
1200
+ const cacheDir = this.hasPermission('memory.user') || this.cacheDir || this.hasPermission('memory');
1189
1201
  if (cacheDir && !CACHE_EXTERNAL[excludeKey = this.moduleName + '_' + type + '_' + format] && config.valid(type, format)) {
1190
1202
  const { uri, etag } = cacheData;
1191
1203
  const encoding = (0, types_1.getEncoding)(cacheData.encoding);
@@ -1218,9 +1230,8 @@ class Document extends core_1.Client {
1218
1230
  series.init(this, __dirname);
1219
1231
  let valid = false, excluded = false, userData, userImports, ignoreCache = false, storedLog, sourceFiles;
1220
1232
  if (username && (0, types_1.isObject)(transform = this.getUserSettings()?.transform)) {
1221
- userData = transform[type];
1222
- if (!(0, types_1.isObject)(userData)) {
1223
- userData = undefined;
1233
+ if ((0, types_1.isObject)(transform[type])) {
1234
+ userData = transform[type];
1224
1235
  }
1225
1236
  userImports = transform.imports;
1226
1237
  }
@@ -1233,9 +1244,6 @@ class Document extends core_1.Client {
1233
1244
  break;
1234
1245
  }
1235
1246
  const name = format[i];
1236
- if (!name) {
1237
- continue;
1238
- }
1239
1247
  let [plugin, baseConfig, outputConfig, baseSettings] = this.findConfig(data, name, type);
1240
1248
  if (userData) {
1241
1249
  const [a, b, c, d] = this.findConfig(userData, name, type);
@@ -1277,7 +1285,7 @@ class Document extends core_1.Client {
1277
1285
  }
1278
1286
  const out = series.out;
1279
1287
  let bypassLog = false, failed = false;
1280
- if (typeof value !== 'string' || (0, types_1.isArray)(out.sourceFiles) && this.hasOwnPermission() && out.sourceFiles.some(item => !this.canRead(item, { ownPermissionOnly: true }))) {
1288
+ if (typeof value !== 'string' || (0, types_1.isArray)(out.sourceFiles) && (this.hasPermission('fs') || process.permission) && out.sourceFiles.some(item => !this.canRead(item, { ownPermissionOnly: true }))) {
1281
1289
  failed = true;
1282
1290
  ignoreCache = true;
1283
1291
  this.writeFail(["Unable to transform document", plugin], (0, types_1.errorMessage)(plugin, name, typeof value === 'string' ? "Unsupported access" : "Empty"), { type: 4, startTime });
@@ -1332,7 +1340,7 @@ class Document extends core_1.Client {
1332
1340
  series.packageName = plugin;
1333
1341
  if (typeof baseConfig === 'function') {
1334
1342
  series.baseConfig = outputConfig;
1335
- if (baseConfig["__cjs__"]) {
1343
+ if ((0, types_1.isFunction)(baseConfig, true)) {
1336
1344
  next(await baseConfig(context, source, series));
1337
1345
  }
1338
1346
  else {
@@ -1385,7 +1393,7 @@ class Document extends core_1.Client {
1385
1393
  }
1386
1394
  else {
1387
1395
  transformer = context;
1388
- context = this;
1396
+ context = null;
1389
1397
  }
1390
1398
  if ((0, types_1.isObject)(transformer) && typeof transformer.default === 'function') {
1391
1399
  transformer = transformer.default;
@@ -1404,7 +1412,7 @@ class Document extends core_1.Client {
1404
1412
  }
1405
1413
  }
1406
1414
  series.baseConfig = baseConfig;
1407
- next(await transformer(context, source, series));
1415
+ next(await transformer(context || this, source, series));
1408
1416
  }
1409
1417
  }
1410
1418
  catch (err) {
@@ -1415,7 +1423,7 @@ class Document extends core_1.Client {
1415
1423
  }
1416
1424
  }
1417
1425
  }
1418
- else {
1426
+ else if (name) {
1419
1427
  abortTransform();
1420
1428
  if (plugin) {
1421
1429
  this.writeFail("Unable to load configuration", (0, types_1.errorMessage)(plugin, name, "Invalid config"), 4);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/document",
3
- "version": "0.11.8",
3
+ "version": "0.12.1",
4
4
  "description": "Document constructor for E-mc.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -20,13 +20,13 @@
20
20
  "license": "BSD-3-Clause",
21
21
  "homepage": "https://github.com/anpham6/e-mc#readme",
22
22
  "dependencies": {
23
- "@e-mc/core": "0.11.8",
24
- "@e-mc/db": "0.11.8",
25
- "@e-mc/types": "0.11.8",
23
+ "@e-mc/core": "0.12.1",
24
+ "@e-mc/db": "0.12.1",
25
+ "@e-mc/types": "0.12.1",
26
26
  "chalk": "4.1.2",
27
- "domhandler": "^5.0.3",
28
- "domutils": "^3.2.2",
29
- "htmlparser2": "^9.1.0",
27
+ "domhandler": "*",
28
+ "domutils": "*",
29
+ "htmlparser2": "^10.0.0",
30
30
  "js-yaml": "^4.1.0",
31
31
  "picomatch": "^4.0.2"
32
32
  }
package/parse/dom.js CHANGED
@@ -20,10 +20,10 @@ class DomWriter extends index_1.XmlWriter {
20
20
  }
21
21
  return !TAG_VOID.includes(tagName);
22
22
  }
23
- static normalize(source, newline, ignoreChar = '', escapeEntities) {
24
- let ignoreTagGroup;
25
- if ((0, types_1.isObject)(newline)) {
26
- ({ newline, ignoreChar = '', ignoreTagGroup, escapeEntities } = newline);
23
+ static normalize(source, options) {
24
+ let newline, ignoreChar = '', ignoreTagGroup, escapeEntities;
25
+ if (options) {
26
+ ({ newline, ignoreTagGroup, escapeEntities, ignoreChar = '' } = options);
27
27
  }
28
28
  for (const tag of REGEXP_VOID) {
29
29
  source = source.replace(tag, (...capture) => index_1.XmlWriter.getNewlineString(capture[1], capture[2], newline));
@@ -101,20 +101,14 @@ class DomWriter extends index_1.XmlWriter {
101
101
  static getElementsByTagName(tagName, nodes, recurse, limit) {
102
102
  return domutils.getElementsByTagName(tagName, nodes, recurse, limit);
103
103
  }
104
- constructor(documentName, source, elements, options, escapeEntities, parser) {
105
- let normalize, stripComments, ignoreTagGroup;
106
- if ((0, types_1.isObject)(options)) {
107
- ({ normalize, escapeEntities, stripComments, ignoreTagGroup, parser } = options);
108
- }
109
- else {
110
- options = { normalize: options, escapeEntities, parser };
111
- }
112
- parser ||= { ...PARSER_OPTIONS };
104
+ documentElement = null;
105
+ ignoreTagName = "title|style|script";
106
+ initOpts;
107
+ rootName = "html";
108
+ ignoreCaseTagName = true;
109
+ constructor(documentName, source, elements, options = {}) {
110
+ const { normalize, escapeEntities, stripComments, ignoreTagGroup, parser = { ...PARSER_OPTIONS } } = options;
113
111
  super(documentName, source, elements, { parser });
114
- this.documentElement = null;
115
- this.ignoreTagName = "title|style|script";
116
- this.rootName = "html";
117
- this.ignoreCaseTagName = true;
118
112
  const items = [];
119
113
  let outerXml = '', documentElement, offsetMap, startIndex = -1;
120
114
  for (const item of elements) {
@@ -226,10 +220,10 @@ class DomWriter extends index_1.XmlWriter {
226
220
  }
227
221
  exports.DomWriter = DomWriter;
228
222
  class HtmlElement extends index_1.XmlElement {
223
+ _documentType = "HTML";
229
224
  constructor(documentName, node, attributes, options = {}) {
230
225
  options.parser ||= { ...PARSER_OPTIONS };
231
226
  super(documentName, node, attributes, { ...options, tagVoid: TAG_VOID.includes(node.tagName) });
232
- this._documentType = "HTML";
233
227
  }
234
228
  getTagOffset(source) {
235
229
  switch (this.node.append?.tagName || this.tagName) {
package/parse/index.js CHANGED
@@ -107,6 +107,9 @@ const isCount = (value) => typeof value === 'number' && value > 0 && value !== I
107
107
  const hasId = (id, source, startIndex, endIndex) => source.substring(startIndex, endIndex).indexOf(id) !== -1;
108
108
  const escapeTagName = (value) => value.replace(/[-.]/g, capture => capture === '-' ? '\\x2d' : '\\' + capture);
109
109
  class XmlWriter {
110
+ documentName;
111
+ _source;
112
+ elements;
110
113
  static get PATTERN_ATTRNAME() {
111
114
  return PATTERN_ATTRNAME;
112
115
  }
@@ -129,12 +132,16 @@ class XmlWriter {
129
132
  return PATTERN_TRAILINGSPACE;
130
133
  }
131
134
  static replaceMatch(match, source, content = '', options) {
135
+ let pattern;
132
136
  if (typeof content === 'number') {
133
137
  content = match[content] || '';
134
138
  }
139
+ else if (content instanceof RegExp) {
140
+ pattern = content;
141
+ content = '';
142
+ }
135
143
  let index = match.index, leading = index > 0 ? source.substring(0, index) : '', trailing = source.substring(index + match[0].length);
136
144
  if (options) {
137
- let pattern;
138
145
  if ((0, types_1.isPlainObject)(options)) {
139
146
  if (options.trimLeading) {
140
147
  const length = leading.length;
@@ -144,14 +151,14 @@ class XmlWriter {
144
151
  if (options.trimTrailing) {
145
152
  trailing = trailing.trimStart();
146
153
  }
147
- pattern = options.pattern;
154
+ pattern ||= options.pattern;
148
155
  }
149
156
  else {
150
157
  pattern = options;
151
158
  }
152
- if (pattern) {
153
- pattern.lastIndex = index + content.length;
154
- }
159
+ }
160
+ if (pattern) {
161
+ pattern.lastIndex = index + content.length;
155
162
  }
156
163
  return leading + content + trailing;
157
164
  }
@@ -397,16 +404,17 @@ class XmlWriter {
397
404
  while (match = pattern.exec(source)) {
398
405
  if (stripXml) {
399
406
  source = this.replaceMatch(match, source, '', { pattern, trimLeading: true });
400
- continue;
401
407
  }
402
- const type = match[1] && 'comment' || match[2] && 'cdata' || 'node';
403
- const startIndex = match.index;
404
- let endIndex = startIndex + match[0].length;
405
- if (type !== 'node') {
406
- result.push({ type, outerXml: match[0], startIndex, endIndex: endIndex - 1 });
407
- }
408
- else if ((endIndex = findCloseIndex(source, match[3], endIndex, ignoreCase)[0]) !== -1) {
409
- result.push({ type, outerXml: source.substring(startIndex, endIndex + 1), startIndex, endIndex });
408
+ else {
409
+ const type = match[1] && 'comment' || match[2] && 'cdata' || 'node';
410
+ const startIndex = match.index;
411
+ let endIndex = startIndex + match[0].length;
412
+ if (type !== 'node') {
413
+ result.push({ type, outerXml: match[0], startIndex, endIndex: endIndex - 1 });
414
+ }
415
+ else if ((endIndex = findCloseIndex(source, match[3], endIndex, ignoreCase)[0]) !== -1) {
416
+ result.push({ type, outerXml: source.substring(startIndex, endIndex + 1), startIndex, endIndex });
417
+ }
410
418
  }
411
419
  }
412
420
  if (stripXml) {
@@ -450,25 +458,26 @@ class XmlWriter {
450
458
  static isSpace(ch) {
451
459
  return ch === ' ' || ch === '\n' || ch === '\t' || ch === '\f' || ch === '\r' || ch === '\v';
452
460
  }
453
- constructor(documentName, source, elements, options) {
461
+ modifyCount = 0;
462
+ failCount = 0;
463
+ errors = [];
464
+ newline = '\n';
465
+ ignoreTagName = '';
466
+ ignoreTagGroup = undefined;
467
+ parser;
468
+ ignoreCaseTagName = false;
469
+ rootName = '';
470
+ _tagCount = Object.create(null);
471
+ _hasInvalidContent = true;
472
+ _ignoreFlag = 0;
473
+ _appendCount = 0;
474
+ _invalidContent = null;
475
+ #patternIgnore = null;
476
+ #writeStartIndex = -1;
477
+ constructor(documentName, _source, elements, options) {
454
478
  this.documentName = documentName;
479
+ this._source = _source;
455
480
  this.elements = elements;
456
- this.modifyCount = 0;
457
- this.failCount = 0;
458
- this.errors = [];
459
- this.newline = '\n';
460
- this.ignoreTagName = '';
461
- this.ignoreTagGroup = undefined;
462
- this.ignoreCaseTagName = false;
463
- this.rootName = '';
464
- this._tagCount = Object.create(null);
465
- this._hasInvalidContent = true;
466
- this._ignoreFlag = 0;
467
- this._appendCount = 0;
468
- this._invalidContent = null;
469
- this._patternIgnore = null;
470
- this._writeStartIndex = -1;
471
- this._source = source;
472
481
  this.parser = options?.parser;
473
482
  }
474
483
  init(offsetMap) {
@@ -496,7 +505,7 @@ class XmlWriter {
496
505
  }
497
506
  getInvalidArea() {
498
507
  if ((this._ignoreFlag & IGNORE_FLAG.INTERIOR) === 0 && this._hasInvalidContent) {
499
- const startIndex = this._writeStartIndex;
508
+ const startIndex = this.#writeStartIndex;
500
509
  if (isIndex(startIndex) && this._invalidContent && !this._invalidContent.some(item => item.startIndex >= startIndex)) {
501
510
  return this._invalidContent;
502
511
  }
@@ -626,12 +635,12 @@ class XmlWriter {
626
635
  this.renameTag(node, element.tagName);
627
636
  }
628
637
  this.update(node, outerXml, append, element.tagOffset);
629
- if (element.innerXml && !element.remove && (element.hasModifiedContent() || this.patternIgnore?.test(element.tagName))) {
638
+ if (element.innerXml && !element.remove && (element.hasModifiedContent() || this.#patternIgnore?.test(element.tagName))) {
630
639
  this._hasInvalidContent = true;
631
- this._writeStartIndex = -1;
640
+ this.#writeStartIndex = -1;
632
641
  }
633
642
  else {
634
- this._writeStartIndex = node.startIndex;
643
+ this.#writeStartIndex = node.startIndex;
635
644
  }
636
645
  element.reset();
637
646
  return true;
@@ -943,7 +952,7 @@ class XmlWriter {
943
952
  value = value.substring(1);
944
953
  }
945
954
  this.ignoreTagName = tagName + value;
946
- this._patternIgnore = null;
955
+ this.#patternIgnore = null;
947
956
  }
948
957
  resetPosition(startIndex = -1) {
949
958
  const rootName = this.rootName;
@@ -1044,7 +1053,7 @@ class XmlWriter {
1044
1053
  return XmlWriter.getNameOfId(this.documentName);
1045
1054
  }
1046
1055
  get patternIgnore() {
1047
- return this.ignoreTagName ? this._patternIgnore ||= new RegExp(`^(?:${this.ignoreTagName})$`, this.ignoreCaseTagName ? 'i' : '') : null;
1056
+ return this.ignoreTagName ? this.#patternIgnore ||= new RegExp(`^(?:${this.ignoreTagName})$`, this.ignoreCaseTagName ? 'i' : '') : null;
1048
1057
  }
1049
1058
  set source(value) {
1050
1059
  if (value !== this._source) {
@@ -1061,6 +1070,8 @@ class XmlWriter {
1061
1070
  }
1062
1071
  exports.XmlWriter = XmlWriter;
1063
1072
  class XmlElement {
1073
+ documentName;
1074
+ node;
1064
1075
  static writeAttributes(attrs, escapeEntities) {
1065
1076
  let result = '';
1066
1077
  for (const [key, value] of attrs) {
@@ -1075,24 +1086,24 @@ class XmlElement {
1075
1086
  }
1076
1087
  return result;
1077
1088
  }
1078
- constructor(documentName, node, attributes, tagVoid, parser) {
1089
+ newline = '\n';
1090
+ parser;
1091
+ _modified = true;
1092
+ _tagName = '';
1093
+ _nameOfId;
1094
+ _innerXml = '';
1095
+ _remove = false;
1096
+ _tagVoid = null;
1097
+ _prevTagName = null;
1098
+ _prevInnerXml = null;
1099
+ _append = undefined;
1100
+ _tagOffset = undefined;
1101
+ _ignoreCase;
1102
+ _documentType = '';
1103
+ _attributes = new Map();
1104
+ constructor(documentName, node, attributes, { parser, tagVoid } = {}) {
1079
1105
  this.documentName = documentName;
1080
1106
  this.node = node;
1081
- this.newline = '\n';
1082
- this._modified = true;
1083
- this._tagName = '';
1084
- this._innerXml = '';
1085
- this._remove = false;
1086
- this._tagVoid = null;
1087
- this._prevTagName = null;
1088
- this._prevInnerXml = null;
1089
- this._append = undefined;
1090
- this._tagOffset = undefined;
1091
- this._documentType = '';
1092
- this._attributes = new Map();
1093
- if ((0, types_1.isObject)(tagVoid)) {
1094
- ({ tagVoid, parser } = tagVoid);
1095
- }
1096
1107
  if (parser) {
1097
1108
  this.parser = parser;
1098
1109
  }
@@ -150,6 +150,7 @@ export interface XmlWriterConstructor {
150
150
  readonly PATTERN_QUOTEVALUE: string;
151
151
  readonly PATTERN_COMMENT: string;
152
152
  readonly PATTERN_TRAILINGSPACE: string;
153
+ replaceMatch(match: RegExpMatchArray, source: string, pattern: RegExp): string;
153
154
  replaceMatch(match: RegExpMatchArray, source: string, content: number | string, options: ReplaceMatchOptions): string;
154
155
  replaceMatch(match: RegExpMatchArray, source: string, content?: number | string, pattern?: RegExp): string;
155
156
  escapeXmlString(value: string, ampersand?: boolean): string;
@@ -168,8 +169,8 @@ export interface XmlWriterConstructor {
168
169
  getCommentsAndCDATA(source: string, tagPattern?: string | string[] | [string | undefined, string[] | undefined], ignoreCase?: boolean, stripXml?: boolean): SourceContent[];
169
170
  isEqual(node: XmlTagNode, other: XmlTagNode, ignoreCase: boolean): boolean;
170
171
  isEqual(node: XmlTagNode, other: XmlTagNode, documentName?: string, ignoreCase?: boolean): boolean;
171
- isIndex(value: number | undefined): value is number;
172
- isCount(value: number | undefined): value is number;
172
+ isIndex(value: unknown): value is number;
173
+ isCount(value: unknown): value is number;
173
174
  isSpace(ch: string): boolean;
174
175
  readonly prototype: IXmlWriter;
175
176
  new(documentName: string, source: string, elements: XmlTagNode[], options?: XmlWriterOptions): IXmlWriter;
@@ -214,7 +215,6 @@ export interface XmlElementConstructor {
214
215
  writeAttributes(attrs: AttributeMap | AttributeList, escapeEntities?: boolean): string;
215
216
  readonly prototype: IXmlElement;
216
217
  new(documentName: string, node: XmlTagNode, attributes?: PlainObject, options?: XmlElementOptions): IXmlElement;
217
- new(documentName: string, node: XmlTagNode, attributes?: PlainObject, tagVoid?: boolean, parser?: ParserOptions): IXmlElement;
218
218
  }
219
219
 
220
220
  export class IDomWriter extends IXmlWriter {
@@ -224,13 +224,11 @@ export class IDomWriter extends IXmlWriter {
224
224
 
225
225
  export interface DomWriterConstructor extends XmlWriterConstructor {
226
226
  hasInnerXml(tagName: string, ignoreCase?: boolean): boolean;
227
- normalize(source: string, options: NormalizeOptions): string;
228
- normalize(source: string, newline?: string, ignoreChar?: string, escapeEntities?: boolean): string;
227
+ normalize(source: string, options?: NormalizeOptions): string;
229
228
  getDocumentElement(source: string, parser?: ParserOptions): ParserResult;
230
229
  getElementsByTagName(tagName: string | ((name: string) => boolean), nodes: AnyNode | AnyNode[], recurse?: boolean, limit?: number): Element[];
231
230
  readonly prototype: IDomWriter;
232
231
  new(documentName: string, source: string, elements: XmlTagNode[], options?: DomWriterOptions): IDomWriter;
233
- new(documentName: string, source: string, elements: XmlTagNode[], normalize?: boolean | string, escapeEntities?: boolean, parser?: ParserOptions): IDomWriter;
234
232
  }
235
233
 
236
234
  export class IHtmlElement extends IXmlElement {}
@@ -1,18 +1,9 @@
1
1
  "use strict";
2
- var _a, _b, _c, _d;
3
2
  exports.SourceMap = exports.TransformSeries = void 0;
4
3
  const path = require("node:path");
5
4
  const types_1 = require("@e-mc/types");
6
5
  const core_1 = require("@e-mc/core");
7
- const kCode = Symbol('code');
8
- const kMap = Symbol('map');
9
- const kOut = Symbol('out');
10
- const kOptions = Symbol('options');
11
- const kSourceMap = Symbol('sourceMap');
12
- const kMetadata = Symbol('metadata');
13
- const kModulesDir = Symbol('modulesDir');
14
- const kUsername = Symbol('username');
15
- const kProductionRelease = Symbol('productionRelease');
6
+ const kTransformSeries = Symbol.for('transformseries:constructor');
16
7
  function parseMap(data, value) {
17
8
  let [mimeType, encoding] = data.split(';');
18
9
  if (!encoding && !mimeType.includes('/')) {
@@ -31,6 +22,11 @@ function toJSON(data) {
31
22
  }
32
23
  }
33
24
  class Out {
25
+ sourceFiles;
26
+ ignoreCache;
27
+ messageAppend;
28
+ logAppend;
29
+ logQueued;
34
30
  reset() {
35
31
  this.sourceFiles = undefined;
36
32
  this.ignoreCache = undefined;
@@ -40,30 +36,37 @@ class Out {
40
36
  }
41
37
  }
42
38
  class TransformSeries extends core_1.Module {
39
+ type;
40
+ static [kTransformSeries] = true;
41
+ baseConfig = {};
42
+ outputConfig = {};
43
+ supplementChunks = [];
44
+ _threadable = true;
45
+ #code;
46
+ #modulesDir = '';
47
+ #username = '';
48
+ #sourceMap;
49
+ #out;
50
+ #options;
51
+ #metadata = {};
52
+ #productionRelease;
43
53
  constructor(type, code, options) {
44
54
  super();
45
55
  this.type = type;
46
- this.baseConfig = {};
47
- this.outputConfig = {};
48
- this.supplementChunks = [];
49
- this._threadable = true;
50
- this[_a] = {};
51
- this[_b] = '';
52
- this[_c] = '';
53
- this[kCode] = code;
54
- this[kOut] = new Out();
55
- this[kOptions] = options;
56
- this[kProductionRelease] = !!options.productionRelease;
56
+ this.#code = code;
57
+ this.#out = new Out();
58
+ this.#options = options;
59
+ this.#productionRelease = !!options.productionRelease;
57
60
  if (SourceMap.isRaw(options.sourceMap)) {
58
61
  const series = new SourceMap(code);
59
62
  series.map = options.sourceMap;
60
- this[kSourceMap] = series;
63
+ this.#sourceMap = series;
61
64
  }
62
65
  else {
63
- this[kSourceMap] = options.sourceMap instanceof SourceMap ? options.sourceMap : this.createSourceMap(code);
66
+ this.#sourceMap = options.sourceMap instanceof SourceMap ? options.sourceMap : this.createSourceMap(code);
64
67
  }
65
68
  if (options.metadata) {
66
- this[kMetadata] = (0, types_1.isPlainObject)(options.metadata) ? { ...options.metadata } : options.metadata;
69
+ this.#metadata = (0, types_1.isPlainObject)(options.metadata) ? { ...options.metadata } : options.metadata;
67
70
  }
68
71
  }
69
72
  reset() {
@@ -72,21 +75,21 @@ class TransformSeries extends core_1.Module {
72
75
  this.outputConfig = {};
73
76
  this.version = '';
74
77
  this.packageName = '';
75
- this[kOut].reset();
78
+ this.#out.reset();
76
79
  }
77
80
  init(instance, dirname) {
78
- if (instance.hasOwnPermission()) {
81
+ if (instance.hasPermission('fs')) {
79
82
  this.permission = core_1.Permission.clone(instance.permission, true);
80
83
  }
81
84
  this.abortable = instance.abortable;
82
85
  this._moduleName = instance.moduleName + ':transform:' + this.type;
83
86
  if (dirname) {
84
- this[kModulesDir] = dirname;
87
+ this.#modulesDir = dirname;
85
88
  }
86
89
  const host = instance.host;
87
90
  if (host) {
88
91
  host.retain(this);
89
- this[kUsername] = host.username;
92
+ this.#username = host.username;
90
93
  }
91
94
  core_1.AbortComponent.attach(instance, this.signal);
92
95
  return this;
@@ -104,6 +107,13 @@ class TransformSeries extends core_1.Module {
104
107
  return this.options.getSourceFiles(imports);
105
108
  }
106
109
  }
110
+ getTempDir(pathname, filename, createDir) {
111
+ if (arguments.length === 0) {
112
+ pathname = this.packageName || true;
113
+ createDir = true;
114
+ }
115
+ return super.getTempDir(pathname, filename, createDir);
116
+ }
107
117
  toBaseConfig(all = true) {
108
118
  const { outputConfig, external } = this;
109
119
  const baseConfig = this.baseConfig;
@@ -163,25 +173,25 @@ class TransformSeries extends core_1.Module {
163
173
  this.host?.release(this);
164
174
  }
165
175
  set code(value) {
166
- this[kCode] = value;
176
+ this.#code = value;
167
177
  }
168
178
  get code() {
169
- return this[kCode];
179
+ return this.#code;
170
180
  }
171
181
  get sourceMap() {
172
- return this[kSourceMap];
182
+ return this.#sourceMap;
173
183
  }
174
184
  get metadata() {
175
- return this[kMetadata];
185
+ return this.#metadata;
176
186
  }
177
187
  get out() {
178
- return this[kOut];
188
+ return this.#out;
179
189
  }
180
190
  get options() {
181
- return this[kOptions];
191
+ return this.#options;
182
192
  }
183
193
  get productionRelease() {
184
- return this[kProductionRelease];
194
+ return this.#productionRelease;
185
195
  }
186
196
  get imported() {
187
197
  return !!this.options.imported;
@@ -224,7 +234,7 @@ class TransformSeries extends core_1.Module {
224
234
  }
225
235
  get packageVersion() {
226
236
  const packageName = this.packageName;
227
- return packageName ? core_1.Module.getPackageVersion(packageName, this[kModulesDir]) : '0.0.0';
237
+ return packageName ? core_1.Module.getPackageVersion(packageName, { startDir: this.#modulesDir }) : '0.0.0';
228
238
  }
229
239
  set host(value) {
230
240
  this._host = value;
@@ -233,15 +243,17 @@ class TransformSeries extends core_1.Module {
233
243
  return this._host;
234
244
  }
235
245
  get username() {
236
- return this[kUsername];
246
+ return this.#username;
237
247
  }
238
248
  }
239
249
  exports.TransformSeries = TransformSeries;
240
- _a = kMetadata, _b = kModulesDir, _c = kUsername;
241
250
  class SourceMap {
251
+ static get SOURCE_MAPPING_URL() {
252
+ return /[\r\n]*(?:(\/\/)|(\/\*))\s*[#@][ ]+sourceMappingURL=(data:[^,]+,)?(\S+)\s*(\*\/)?\r?\n?/g;
253
+ }
242
254
  static findSourceMap(code, uri) {
243
255
  if (code ||= uri && core_1.Module.readText(uri)) {
244
- const pattern = this.RE_SOURCE_MAPPING_URL;
256
+ const pattern = this.SOURCE_MAPPING_URL;
245
257
  pattern.lastIndex = 0;
246
258
  let match;
247
259
  while (match = pattern.exec(code)) {
@@ -261,7 +273,7 @@ class SourceMap {
261
273
  }
262
274
  }
263
275
  static removeSourceMappingURL(value) {
264
- const pattern = this.RE_SOURCE_MAPPING_URL;
276
+ const pattern = this.SOURCE_MAPPING_URL;
265
277
  pattern.lastIndex = 0;
266
278
  const match = pattern.exec(value);
267
279
  return match ? [value.substring(0, match.index) + value.substring(match.index + match[0].length), (match[3] || '') + match[4], match[3] && toJSON(parseMap(match[3], match[4])) || null] : [value];
@@ -269,10 +281,12 @@ class SourceMap {
269
281
  static isRaw(map) {
270
282
  return (0, types_1.isObject)(map) && (0, types_1.isString)(map.mappings);
271
283
  }
284
+ code;
285
+ output = new Map();
286
+ sourceMappingURL = '';
287
+ #map = undefined;
288
+ #start;
272
289
  constructor(code, uri, remove) {
273
- this.output = new Map();
274
- this.sourceMappingURL = '';
275
- this[_d] = undefined;
276
290
  if (typeof uri === 'boolean') {
277
291
  remove = uri;
278
292
  uri = undefined;
@@ -288,12 +302,12 @@ class SourceMap {
288
302
  if (SourceMap.isRaw(map)) {
289
303
  this.nextMap('unknown', code, map);
290
304
  }
291
- this[kCode] = code;
305
+ this.#start = code;
292
306
  this.code = code;
293
307
  }
294
308
  reset(restore) {
295
309
  if (restore) {
296
- this.code = this[kCode];
310
+ this.code = this.#start;
297
311
  }
298
312
  this.map = undefined;
299
313
  this.sourceMappingURL = '';
@@ -302,7 +316,7 @@ class SourceMap {
302
316
  nextMap(name, code, map, sourceMappingURL = '', emptySources) {
303
317
  if (!SourceMap.isRaw(map)) {
304
318
  try {
305
- map = JSON.parse(Buffer.isBuffer(map) ? map.toString('utf-8') : map.toString());
319
+ map = JSON.parse(Buffer.isBuffer(map) ? map.toString('utf8') : map.toString());
306
320
  }
307
321
  catch {
308
322
  }
@@ -310,6 +324,10 @@ class SourceMap {
310
324
  return false;
311
325
  }
312
326
  }
327
+ if (typeof sourceMappingURL === 'boolean') {
328
+ emptySources = sourceMappingURL;
329
+ sourceMappingURL = '';
330
+ }
313
331
  if (emptySources) {
314
332
  map.sources = [""];
315
333
  }
@@ -327,16 +345,14 @@ class SourceMap {
327
345
  }
328
346
  set map(value) {
329
347
  if (!value) {
330
- this[kMap] = undefined;
348
+ this.#map = undefined;
331
349
  }
332
350
  else if (SourceMap.isRaw(value)) {
333
- this[kMap] = value;
351
+ this.#map = value;
334
352
  }
335
353
  }
336
354
  get map() {
337
- return this[kMap];
355
+ return this.#map;
338
356
  }
339
357
  }
340
358
  exports.SourceMap = SourceMap;
341
- _d = kMap;
342
- SourceMap.RE_SOURCE_MAPPING_URL = /[\r\n]*(?:(\/\/)|(\/\*))\s*[#@][ ]+sourceMappingURL=(data:[^,]+,)?(\S+)\s*(\*\/)?\r?\n?/g;
package/util.d.ts CHANGED
@@ -1,13 +1,13 @@
1
1
  declare namespace util {
2
- /** @deprecated Types.IMPORT_MAP */
3
- const IMPORTS: Record<string, string | undefined>;
4
2
  const PATTERN_PARENTHESIS: string;
5
- function loadPlugins<T = unknown>(plugins: string | unknown[]): T[];
3
+ function loadPlugins<T = unknown>(plugins: string | unknown[], map?: AnyObject): T[];
6
4
  function replaceAll(source: string, valueOf: (name: string) => string, opening?: string, closing?: string): string;
7
5
  function concatString(values: string[] | string | undefined, newline?: string): string;
8
6
  function spliceString(source: string, startIndex: number, endIndex: number, content: string, pattern?: RegExp): string;
9
7
  function spliceMatch(source: string, match: RegExpExecArray, content: string, pattern?: RegExp): string;
10
8
  function splitEnclosing(value: string, pattern?: string | RegExp, options?: { trim?: boolean; start?: number; startWith?: number; count?: number } | boolean | number, opening?: string, closing?: string): string[];
9
+ function trimQuote(value: string): string;
10
+ function wrapQuote(value: string, quote?: string): string;
11
11
  function appendSuffix(filename: string, value: string, separator?: string): string;
12
12
  function getIndent(value: string, spaces?: number): string;
13
13
  function getNewline(value: string): string;
package/util.js CHANGED
@@ -1,11 +1,13 @@
1
1
  "use strict";
2
- exports.isObject = exports.IMPORTS = exports.PATTERN_PARENTHESIS = void 0;
2
+ exports.isObject = exports.PATTERN_PARENTHESIS = void 0;
3
3
  exports.loadPlugins = loadPlugins;
4
4
  exports.replaceAll = replaceAll;
5
5
  exports.concatString = concatString;
6
6
  exports.spliceString = spliceString;
7
7
  exports.spliceMatch = spliceMatch;
8
8
  exports.splitEnclosing = splitEnclosing;
9
+ exports.trimQuote = trimQuote;
10
+ exports.wrapQuote = wrapQuote;
9
11
  exports.appendSuffix = appendSuffix;
10
12
  exports.getIndent = getIndent;
11
13
  exports.getNewline = getNewline;
@@ -13,11 +15,10 @@ exports.getHashData = getHashData;
13
15
  exports.hasValue = hasValue;
14
16
  exports.getModuleName = getModuleName;
15
17
  exports.removeInternalProperties = removeInternalProperties;
16
- const path = require("path");
18
+ const path = require("node:path");
17
19
  const types_1 = require("@e-mc/types");
18
- Object.defineProperty(exports, "IMPORTS", { enumerable: true, get: function () { return types_1.IMPORT_MAP; } });
19
20
  Object.defineProperty(exports, "isObject", { enumerable: true, get: function () { return types_1.isObject; } });
20
- function loadPlugins(plugins) {
21
+ function loadPlugins(plugins, map) {
21
22
  const result = [];
22
23
  const items = (Array.isArray(plugins) ? plugins : [plugins]).map(value => {
23
24
  let name, options;
@@ -33,7 +34,11 @@ function loadPlugins(plugins) {
33
34
  else if (typeof value === 'function') {
34
35
  return [value];
35
36
  }
36
- return name ? [name, options] : null;
37
+ if (name) {
38
+ const method = map?.[name];
39
+ return [typeof method === 'function' ? method : name, options];
40
+ }
41
+ return null;
37
42
  });
38
43
  for (const plugin of items) {
39
44
  if (plugin) {
@@ -178,6 +183,15 @@ function splitEnclosing(value, pattern, options, opening = '(', closing = ')') {
178
183
  }
179
184
  return result;
180
185
  }
186
+ function trimQuote(value) {
187
+ value = value.trim();
188
+ const first = value[0];
189
+ const last = value[value.length - 1];
190
+ return first === last && (first === '"' || first === "'") ? value.substring(1, value.length - 1).trim() : value;
191
+ }
192
+ function wrapQuote(value, quote = '"') {
193
+ return quote + value.replace(new RegExp(`(?<!\\\\)${quote}`, 'g'), `\\${quote}`) + quote;
194
+ }
181
195
  function appendSuffix(filename, value, separator = '-') {
182
196
  const ext = path.extname(filename);
183
197
  return ext && value ? filename.substring(0, filename.length - ext.length) + separator + value + ext : filename;
@@ -220,7 +234,7 @@ function getModuleName(err) {
220
234
  function removeInternalProperties(value, retaining) {
221
235
  if ((0, types_1.isObject)(value)) {
222
236
  for (const prop in value) {
223
- if (Object.prototype.hasOwnProperty.call(value, prop)) {
237
+ if (Object.hasOwn(value, prop)) {
224
238
  if (retaining) {
225
239
  if (!retaining.includes(prop)) {
226
240
  delete value[prop];