@e-mc/document 0.13.6 → 0.13.8

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,6 +1,6 @@
1
1
  # @e-mc/document
2
2
 
3
- * NodeJS 18.20.5 LTS
3
+ * NodeJS 18.20 LTS
4
4
  * ES2022
5
5
 
6
6
  ## General Usage
@@ -9,7 +9,7 @@
9
9
 
10
10
  ## Interface
11
11
 
12
- * [View Source](https://www.unpkg.com/@e-mc/types@0.13.6/lib/index.d.ts)
12
+ * [View Source](https://www.unpkg.com/@e-mc/types@0.13.8/lib/index.d.ts)
13
13
 
14
14
  ```typescript
15
15
  import type { DataSource, ViewEngine } from "./squared";
@@ -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.13.6/lib/squared.d.ts
189
- - https://www.unpkg.com/@e-mc/types@0.13.6/lib/asset.d.ts
190
- - https://www.unpkg.com/@e-mc/types@0.13.6/lib/core.d.ts
191
- - https://www.unpkg.com/@e-mc/types@0.13.6/lib/document.d.ts
192
- - https://www.unpkg.com/@e-mc/types@0.13.6/lib/filemanager.d.ts
193
- - https://www.unpkg.com/@e-mc/types@0.13.6/lib/logger.d.ts
194
- - https://www.unpkg.com/@e-mc/types@0.13.6/lib/settings.d.ts
195
- - https://www.unpkg.com/@e-mc/types@0.13.6/lib/watch.d.ts
188
+ - https://www.unpkg.com/@e-mc/types@0.13.8/lib/squared.d.ts
189
+ - https://www.unpkg.com/@e-mc/types@0.13.8/lib/asset.d.ts
190
+ - https://www.unpkg.com/@e-mc/types@0.13.8/lib/core.d.ts
191
+ - https://www.unpkg.com/@e-mc/types@0.13.8/lib/document.d.ts
192
+ - https://www.unpkg.com/@e-mc/types@0.13.8/lib/filemanager.d.ts
193
+ - https://www.unpkg.com/@e-mc/types@0.13.8/lib/logger.d.ts
194
+ - https://www.unpkg.com/@e-mc/types@0.13.8/lib/settings.d.ts
195
+ - https://www.unpkg.com/@e-mc/types@0.13.8/lib/watch.d.ts
196
196
 
197
197
  ## LICENSE
198
198
 
package/index.js CHANGED
@@ -12,21 +12,28 @@ 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
14
  const kDocument = Symbol.for('document:constructor');
15
- const CACHE_PACKAGE = {};
15
+ const CACHE_PACKAGE = new Map();
16
16
  const CACHE_CONFIG = new Map();
17
- const CACHE_TEMPLATE = {};
17
+ const CACHE_TEMPLATE = new Map();
18
18
  const CACHE_VIEWENGINE = new Map();
19
- const CACHE_EXTERNAL = {};
20
- const CACHE_ETAG = {};
21
- const CACHE_CODE = {};
22
- const CACHE_HASH = {};
23
- const CACHE_PICOMATCH = new Map();
19
+ let CACHE_ETAG;
20
+ let CACHE_CODE;
21
+ let CACHE_HASH;
22
+ let CACHE_EXTERNAL;
23
+ let CACHE_PICOMATCH;
24
24
  let CACHE_TOTAL = 0;
25
+ function initCache() {
26
+ CACHE_ETAG = Object.create(null);
27
+ CACHE_CODE = Object.create(null);
28
+ CACHE_HASH = Object.create(null);
29
+ CACHE_PICOMATCH = Object.create(null);
30
+ CACHE_EXTERNAL = Object.create(null);
31
+ }
25
32
  function deleteTransform(map, key, timeout) {
26
33
  if (timeout) {
27
34
  clearTimeout(timeout);
28
35
  }
29
- delete map[key];
36
+ map.delete(key);
30
37
  --CACHE_TOTAL;
31
38
  }
32
39
  function getSourceMappingURL(value, css) {
@@ -83,13 +90,13 @@ class TransformCache {
83
90
  return data;
84
91
  }
85
92
  get(stored) {
86
- const location = stored.format[this.formatKey];
93
+ const location = stored.format.get(this.formatKey);
87
94
  if (typeof location === 'string') {
88
95
  try {
89
96
  return JSON.parse(fs.readFileSync(location, this.encoding));
90
97
  }
91
98
  catch {
92
- delete stored.format[this.formatKey];
99
+ stored.format.delete(this.formatKey);
93
100
  fs.unlink(location, () => { });
94
101
  return;
95
102
  }
@@ -99,46 +106,48 @@ class TransformCache {
99
106
  save(type, code, formatData) {
100
107
  const lastAccessed = Date.now();
101
108
  const config = this.config;
109
+ const create = () => new Map([[this.formatKey, this.set(type, formatData)]]);
110
+ const update = (stored) => {
111
+ stored.format.set(this.formatKey, this.set(type, formatData));
112
+ stored.lastAccessed = lastAccessed;
113
+ };
102
114
  if (this.formatType === 1) {
103
115
  const { uri, etag } = this.cacheData;
104
116
  const etagMap = CACHE_ETAG[config.moduleName];
105
- const stored = etagMap[uri];
117
+ const stored = etagMap.get(uri);
106
118
  if (stored) {
107
- if (stored.etag === etag) {
108
- stored.format[this.formatKey] = this.set(type, formatData);
109
- stored.lastAccessed = lastAccessed;
119
+ if (stored.hashKey === etag) {
120
+ update(stored);
110
121
  return;
111
122
  }
112
123
  deleteTransform(etagMap, uri, stored.timeout);
113
124
  }
114
- etagMap[uri] = { lastAccessed, etag, timeout: config.renewSession(etagMap, uri), format: { [this.formatKey]: this.set(type, formatData) } };
125
+ etagMap.set(uri, { lastAccessed, timeout: config.renewSession(etagMap, uri), format: create(), hashKey: etag });
115
126
  ++CACHE_TOTAL;
116
127
  }
117
128
  else if (this.formatType === 2) {
118
129
  const hashMap = CACHE_HASH[config.moduleName];
119
130
  const key = this.hashKey;
120
- const stored = hashMap[key];
131
+ const stored = hashMap.get(key);
121
132
  if (stored) {
122
- stored.format[this.formatKey] = this.set(type, formatData);
123
- stored.lastAccessed = lastAccessed;
133
+ update(stored);
124
134
  return;
125
135
  }
126
- hashMap[key] = { lastAccessed, timeout: config.renewSession(hashMap, key), format: { [this.formatKey]: this.set(type, formatData) } };
136
+ hashMap.set(key, { lastAccessed, timeout: config.renewSession(hashMap, key), format: create() });
127
137
  ++CACHE_TOTAL;
128
138
  }
129
139
  else {
130
140
  const uri = this.cacheData.uri;
131
141
  const codeMap = CACHE_CODE[config.moduleName];
132
- const stored = codeMap[uri];
142
+ const stored = codeMap.get(uri);
133
143
  if (stored) {
134
- if (stored.code === code) {
135
- stored.format[this.formatKey] = this.set(type, formatData);
136
- stored.lastAccessed = lastAccessed;
144
+ if (stored.hashKey === code) {
145
+ update(stored);
137
146
  return;
138
147
  }
139
148
  deleteTransform(codeMap, uri, stored.timeout);
140
149
  }
141
- codeMap[uri] = { lastAccessed, code, timeout: config.renewSession(codeMap, uri), format: { [this.formatKey]: this.set(type, formatData) } };
150
+ codeMap.set(uri, { lastAccessed, timeout: config.renewSession(codeMap, uri), format: create(), hashKey: code });
142
151
  ++CACHE_TOTAL;
143
152
  }
144
153
  }
@@ -174,7 +183,7 @@ class TransformConfig {
174
183
  algorithm = options;
175
184
  enabled = true;
176
185
  }
177
- else if ((0, types_1.isPlainObject)(options)) {
186
+ else if ((0, types_1.isObject)(options)) {
178
187
  ({ enabled = true, algorithm, etag, expires, renew, limit, include, exclude } = options);
179
188
  }
180
189
  if (!enabled) {
@@ -268,19 +277,17 @@ class TransformConfig {
268
277
  }
269
278
  renewSession(map, key) {
270
279
  if (this.expires > 0) {
271
- return setTimeout(() => {
272
- deleteTransform(map, key);
273
- }, this.expires);
280
+ return setTimeout(() => deleteTransform(map, key), this.expires);
274
281
  }
275
282
  return null;
276
283
  }
277
284
  useETag(cache, etag, uri) {
278
- const etagMap = CACHE_ETAG[this.moduleName] ||= {};
279
- const stored = etagMap[uri];
285
+ const etagMap = CACHE_ETAG[this.moduleName] ||= new Map();
286
+ const stored = etagMap.get(uri);
280
287
  cache.formatType = 1;
281
288
  if (stored) {
282
289
  let result;
283
- if (stored.etag !== etag) {
290
+ if (stored.hashKey !== etag) {
284
291
  deleteTransform(etagMap, uri, stored.timeout);
285
292
  }
286
293
  else if (result = cache.get(stored)) {
@@ -293,8 +300,8 @@ class TransformConfig {
293
300
  useHash(cache, code) {
294
301
  let key;
295
302
  if (this.withinLimit(code, cache.encoding) && (key = core_1.Client.asHash(code, this.algorithm, { encoding: cache.encoding }))) {
296
- const hashMap = CACHE_HASH[this.moduleName] ||= {};
297
- const stored = hashMap[key];
303
+ const hashMap = CACHE_HASH[this.moduleName] ||= new Map();
304
+ const stored = hashMap.get(key);
298
305
  let result;
299
306
  cache.formatType ||= 2;
300
307
  cache.hashKey = key;
@@ -307,12 +314,12 @@ class TransformConfig {
307
314
  }
308
315
  useUri(cache, code, uri) {
309
316
  if (this.withinLimit(code, cache.encoding)) {
310
- const codeMap = CACHE_CODE[this.moduleName] ||= {};
311
- const stored = codeMap[uri];
317
+ const codeMap = CACHE_CODE[this.moduleName] ||= new Map();
318
+ const stored = codeMap.get(uri);
312
319
  cache.formatType ||= 3;
313
320
  if (stored) {
314
321
  let result;
315
- if (stored.code !== code) {
322
+ if (stored.hashKey !== code) {
316
323
  deleteTransform(codeMap, uri, stored.timeout);
317
324
  }
318
325
  else if (result = cache.get(stored)) {
@@ -339,20 +346,19 @@ class Document extends core_1.Client {
339
346
  for (const cache of [CACHE_ETAG, CACHE_CODE, CACHE_HASH]) {
340
347
  for (const name in cache) {
341
348
  const map = cache[name];
342
- for (const key in map) {
343
- deleteTransform(map, key, map[key].timeout);
349
+ for (const [key, data] of map) {
350
+ deleteTransform(map, key, data.timeout);
344
351
  ++result;
345
352
  }
346
- delete cache[name];
347
353
  }
348
354
  }
349
- for (const cache of [CACHE_PACKAGE, CACHE_EXTERNAL, CACHE_TEMPLATE]) {
350
- for (const name in cache) {
351
- delete cache[name];
352
- }
355
+ initCache();
356
+ for (const item of CACHE_TEMPLATE.values()) {
357
+ item.clear();
353
358
  }
359
+ CACHE_PACKAGE.clear();
360
+ CACHE_TEMPLATE.clear();
354
361
  CACHE_VIEWENGINE.clear();
355
- CACHE_PICOMATCH.clear();
356
362
  CACHE_TOTAL = 0;
357
363
  }
358
364
  else if (percent > 0) {
@@ -360,16 +366,16 @@ class Document extends core_1.Client {
360
366
  for (const cache of [CACHE_ETAG, CACHE_CODE, CACHE_HASH]) {
361
367
  for (const name in cache) {
362
368
  const map = cache[name];
363
- for (const key in map) {
364
- stored.push([map, key]);
369
+ for (const [key, data] of map) {
370
+ stored.push([map, key, data]);
365
371
  }
366
372
  }
367
373
  }
368
- stored.sort(([a1, a2], [b1, b2]) => a1[a2].lastAccessed - b1[b2].lastAccessed);
374
+ stored.sort((a, b) => a[2].lastAccessed - b[2].lastAccessed);
369
375
  result = Math.floor(stored.length * percent);
370
376
  for (let i = 0; i < result; ++i) {
371
- const [map, key] = stored[i];
372
- deleteTransform(map, key, map[key].timeout);
377
+ const [map, key, data] = stored[i];
378
+ deleteTransform(map, key, data.timeout);
373
379
  }
374
380
  CACHE_TOTAL = stored.length - result;
375
381
  }
@@ -645,10 +651,7 @@ class Document extends core_1.Client {
645
651
  items.push(item);
646
652
  }
647
653
  else if ((0, types_1.hasGlob)(pattern)) {
648
- let isMatch = CACHE_PICOMATCH.get(pattern);
649
- if (!isMatch) {
650
- CACHE_PICOMATCH.set(pattern, isMatch = pm(pattern, { matchBase: true }));
651
- }
654
+ const isMatch = CACHE_PICOMATCH[pattern] ||= pm(pattern, { matchBase: true });
652
655
  if (isMatch(baseUrl)) {
653
656
  items.push(item);
654
657
  }
@@ -758,13 +761,13 @@ class Document extends core_1.Client {
758
761
  const cache = CACHE_CONFIG.get(data);
759
762
  cacheKey = type ? `${name}::${type}` : name;
760
763
  if (cache) {
761
- const items = cache[username]?.[name];
764
+ const items = cache[username]?.[cacheKey];
762
765
  if (items) {
763
766
  return cloneConfigItems(items);
764
767
  }
765
768
  }
766
769
  else {
767
- CACHE_CONFIG.set(data, {});
770
+ CACHE_CONFIG.set(data, Object.create(null));
768
771
  }
769
772
  }
770
773
  for (const plugin in data) {
@@ -776,7 +779,7 @@ class Document extends core_1.Client {
776
779
  if (options || output) {
777
780
  const result = [plugin, options, output, true];
778
781
  if (cacheKey) {
779
- const cache = CACHE_CONFIG.get(data)[username] ||= {};
782
+ const cache = CACHE_CONFIG.get(data)[username] ||= Object.create(null);
780
783
  cache[cacheKey] = cloneConfigItems(result);
781
784
  }
782
785
  return result;
@@ -1065,7 +1068,12 @@ class Document extends core_1.Client {
1065
1068
  case 'xml':
1066
1069
  return new (require('fast-xml-parser').XMLParser)(options).parse(source);
1067
1070
  case 'toml':
1068
- return require('toml').parse(source);
1071
+ try {
1072
+ return require('smol-toml').parse(source, options);
1073
+ }
1074
+ catch {
1075
+ return require('toml').parse(source);
1076
+ }
1069
1077
  default:
1070
1078
  return JSON.parse(source);
1071
1079
  }
@@ -1118,7 +1126,7 @@ class Document extends core_1.Client {
1118
1126
  this.writeFail(["Unable to load configuration", from], (0, types_1.errorMessage)('view-engine', from, "Unknown"));
1119
1127
  return null;
1120
1128
  }
1121
- if (data.length === 0 && !target.outputEmpty) {
1129
+ if (!target.outputEmpty && !(0, types_1.isArray)(data)) {
1122
1130
  return '';
1123
1131
  }
1124
1132
  try {
@@ -1138,15 +1146,19 @@ class Document extends core_1.Client {
1138
1146
  (0, types_1.coerceObject)(output, stored);
1139
1147
  }
1140
1148
  }
1149
+ let cache = CACHE_TEMPLATE.get(target.name);
1150
+ if (!cache) {
1151
+ cache = new Map();
1152
+ CACHE_TEMPLATE.set(target.name, cache);
1153
+ }
1141
1154
  const username = this.host?.username || '';
1142
- const cache = CACHE_TEMPLATE[target.name] ||= {};
1143
1155
  const cacheKey = (username ? username + ':' : '') + (0, types_1.hashKey)(template + (compile ? core_1.Client.asString(compile) : ''));
1144
1156
  let result = '', valid = false, expires = typeof target.expires === 'string' ? (0, types_1.parseExpires)(target.expires) : target.expires, render;
1145
1157
  if (expires !== 0) {
1146
- render = cache[cacheKey];
1158
+ render = cache.get(cacheKey);
1147
1159
  }
1148
- else if (username && cacheKey in cache) {
1149
- delete cache[cacheKey];
1160
+ else if (username && cache.has(cacheKey)) {
1161
+ cache.delete(cacheKey);
1150
1162
  }
1151
1163
  if (!render) {
1152
1164
  if ((0, types_1.isArray)(compile)) {
@@ -1156,7 +1168,7 @@ class Document extends core_1.Client {
1156
1168
  render = typeof context.compileSync === 'function' ? context.compileSync(template, compile) : await context.compile(template, compile);
1157
1169
  }
1158
1170
  if (expires !== 0) {
1159
- cache[cacheKey] = render;
1171
+ cache.set(cacheKey, render);
1160
1172
  if (this.hasPermission('memory')) {
1161
1173
  expires = typeof expires === 'number' && expires !== Infinity ? Math.min(expires, core_1.Client.MAX_TIMEOUT) : 0;
1162
1174
  }
@@ -1164,14 +1176,14 @@ class Document extends core_1.Client {
1164
1176
  expires = 60000;
1165
1177
  }
1166
1178
  if (expires > 0) {
1167
- setTimeout(() => delete cache[cacheKey], expires);
1179
+ setTimeout(() => cache.delete(cacheKey), expires);
1168
1180
  }
1169
1181
  }
1170
1182
  }
1171
1183
  const writeRow = async (row) => {
1172
1184
  const content = await render.call(context, row);
1173
1185
  if (content != null) {
1174
- result += content;
1186
+ result += typeof content === 'string' ? content : JSON.stringify(content);
1175
1187
  valid = true;
1176
1188
  }
1177
1189
  };
@@ -1204,8 +1216,9 @@ class Document extends core_1.Client {
1204
1216
  return null;
1205
1217
  }
1206
1218
  async transform(type, code, format, options = {}) {
1207
- let transform = this.settings.transform, data;
1208
- if (!(0, types_1.isObject)(transform) || !(0, types_1.isObject)(data = transform[type])) {
1219
+ let transform = this.settings.transform;
1220
+ const data = transform?.[type];
1221
+ if (!(0, types_1.isObject)(data)) {
1209
1222
  return;
1210
1223
  }
1211
1224
  if (typeof format === 'string') {
@@ -1218,13 +1231,13 @@ class Document extends core_1.Client {
1218
1231
  if (cacheData) {
1219
1232
  const cacheDir = this.hasPermission('memory.user') || this.cacheDir || this.hasPermission('memory');
1220
1233
  if (cacheDir && !CACHE_EXTERNAL[excludeKey = this.moduleName + '_' + type + '_' + format] && config.valid(type, format)) {
1221
- const { uri, etag } = cacheData;
1234
+ const uri = cacheData.uri;
1222
1235
  const encoding = (0, types_1.getEncoding)(cacheData.encoding);
1223
1236
  const hashOpts = core_1.Client.asString(options.external) + core_1.Client.asString(options.metadata);
1224
1237
  cache = new TransformCache(config, cacheData, cacheDir, encoding, (username ? username + ':' : '') + type + '_' + format + '_' + encoding + (hashOpts ? '_' + (0, types_1.hashKey)(hashOpts) : ''));
1225
1238
  let result, cacheName;
1226
- if (config.etag && etag && uri) {
1227
- [result, cacheName] = config.useETag(cache, etag, uri);
1239
+ if (config.etag && cacheData.etag && uri) {
1240
+ [result, cacheName] = config.useETag(cache, cacheData.etag, uri);
1228
1241
  }
1229
1242
  if (!result) {
1230
1243
  if (config.algorithm) {
@@ -1235,14 +1248,12 @@ class Document extends core_1.Client {
1235
1248
  }
1236
1249
  }
1237
1250
  if (result) {
1238
- result.log?.forEach(log => {
1239
- this.addLog(log);
1240
- });
1251
+ result.log?.forEach(log => this.addLog(log));
1241
1252
  this.formatMessage(4, type, [joinString(cacheName, format.filter(value => value).join(' | '), options.filename), 'cache'], uri, { ...core_1.Client.LOG_STYLE_NOTICE, hintBold: true });
1242
1253
  return result;
1243
1254
  }
1244
1255
  }
1245
- delete options.cacheData;
1256
+ options.cacheData = undefined;
1246
1257
  }
1247
1258
  const imports = transform.imports ||= {};
1248
1259
  const series = new transform_1.TransformSeries(type, code, options);
@@ -1371,7 +1382,7 @@ class Document extends core_1.Client {
1371
1382
  }
1372
1383
  }
1373
1384
  else {
1374
- let transformer = CACHE_PACKAGE[target + username];
1385
+ let transformer = CACHE_PACKAGE.get(target + username);
1375
1386
  if (!transformer) {
1376
1387
  try {
1377
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];
@@ -1408,7 +1419,7 @@ class Document extends core_1.Client {
1408
1419
  throw (0, types_1.errorMessage)(plugin, "Invalid function", pkg || name);
1409
1420
  }
1410
1421
  if (pkg) {
1411
- CACHE_PACKAGE[target + username] = transformer;
1422
+ CACHE_PACKAGE.set(target + username, transformer);
1412
1423
  }
1413
1424
  }
1414
1425
  catch (err) {
@@ -1525,4 +1536,5 @@ class Document extends core_1.Client {
1525
1536
  return this.assets.some(item => item.watch);
1526
1537
  }
1527
1538
  }
1539
+ initCache();
1528
1540
  module.exports = Document;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e-mc/document",
3
- "version": "0.13.6",
3
+ "version": "0.13.8",
4
4
  "description": "Document constructor for E-mc.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -19,9 +19,9 @@
19
19
  "license": "BSD-3-Clause",
20
20
  "homepage": "https://github.com/anpham6/e-mc#readme",
21
21
  "dependencies": {
22
- "@e-mc/core": "0.13.6",
23
- "@e-mc/db": "0.13.6",
24
- "@e-mc/types": "0.13.6",
22
+ "@e-mc/core": "0.13.8",
23
+ "@e-mc/db": "0.13.8",
24
+ "@e-mc/types": "0.13.8",
25
25
  "chalk": "4.1.2",
26
26
  "domhandler": "^5.0.3",
27
27
  "domutils": "^3.2.2",
package/parse/dom.js CHANGED
@@ -169,9 +169,9 @@ class DomWriter extends index_1.XmlWriter {
169
169
  const textContent = trailing.reduce((a, b) => a + b.textContent, '');
170
170
  offsetMap = index_1.XmlWriter.getTagOffset(textContent, { ignoreCase: this.ignoreCaseTagName, ignoreTagName: this.ignoreTagName, parser: this.parser });
171
171
  source = source.substring(0, match.index) + textContent + source.substring(match.index);
172
- trailing.forEach(item => {
172
+ for (const item of trailing) {
173
173
  delete item.textContent;
174
- });
174
+ }
175
175
  }
176
176
  }
177
177
  }
package/parse/index.js CHANGED
@@ -499,9 +499,9 @@ class XmlWriter {
499
499
  }
500
500
  }
501
501
  ignoreFlag(...values) {
502
- values.forEach(value => {
502
+ for (const value of values) {
503
503
  this._ignoreFlag |= value;
504
- });
504
+ }
505
505
  }
506
506
  getInvalidArea() {
507
507
  if ((this._ignoreFlag & IGNORE_FLAG.INTERIOR) === 0 && this._hasInvalidContent) {
@@ -820,9 +820,9 @@ class XmlWriter {
820
820
  const revised = this.decrement(node);
821
821
  if (revised.includes(node)) {
822
822
  if (tagName in this._tagCount) {
823
- revised.forEach(item => {
823
+ for (const item of revised) {
824
824
  updateTagName(item, tagName);
825
- });
825
+ }
826
826
  this.indexTag(tagName);
827
827
  this.increment(revised);
828
828
  }
@@ -22,6 +22,19 @@ function toJSON(data) {
22
22
  catch {
23
23
  }
24
24
  }
25
+ function parseModuleArgs(startDir, packageName, version) {
26
+ if ((0, types_1.isObject)(startDir)) {
27
+ ({ startDir, packageName, version } = startDir);
28
+ }
29
+ if (!startDir && packageName && version && version !== 'latest') {
30
+ try {
31
+ startDir = path.dirname(require.resolve(packageName));
32
+ }
33
+ catch {
34
+ }
35
+ }
36
+ return [startDir, packageName, version];
37
+ }
25
38
  class Out {
26
39
  sourceFiles;
27
40
  ignoreCache;
@@ -127,9 +140,7 @@ class TransformSeries extends core_1.Module {
127
140
  return baseConfig;
128
141
  }
129
142
  upgrade(context, startDir, packageName, version) {
130
- if ((0, types_1.isObject)(startDir)) {
131
- ({ startDir, packageName, version } = startDir);
132
- }
143
+ [startDir, packageName, version] = parseModuleArgs(startDir, packageName, version);
133
144
  try {
134
145
  const pathname = startDir && this.findModule(startDir, packageName, version || this.version) || packageName;
135
146
  if (pathname) {
@@ -141,9 +152,7 @@ class TransformSeries extends core_1.Module {
141
152
  return context;
142
153
  }
143
154
  async upgradeESM(context, startDir, packageName, version) {
144
- if ((0, types_1.isObject)(startDir)) {
145
- ({ startDir, packageName, version } = startDir);
146
- }
155
+ [startDir, packageName, version] = parseModuleArgs(startDir, packageName, version);
147
156
  try {
148
157
  const pathname = startDir && this.findModule(startDir, packageName, version || this.version);
149
158
  let result;
package/util.js CHANGED
@@ -187,7 +187,7 @@ function trimQuote(value) {
187
187
  value = value.trim();
188
188
  const first = value[0];
189
189
  const last = value.at(-1);
190
- return first === last && (first === '"' || first === "'") ? value.substring(1, value.length - 1).trim() : value;
190
+ return first === last && (first === '"' || first === "'") ? value.slice(1, -1).trim() : value;
191
191
  }
192
192
  function wrapQuote(value, quote = '"') {
193
193
  return quote + value.replace(new RegExp(`(?<!\\\\)${quote}`, 'g'), `\\${quote}`) + quote;