monocart-reporter 2.8.0 → 2.8.2

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/lib/cli.js CHANGED
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env node
1
+ #!/usr/bin/env node
2
2
 
3
3
  const fs = require('fs');
4
4
  const path = require('path');
@@ -7,6 +7,7 @@ const https = require('https');
7
7
  const net = require('net');
8
8
  const os = require('os');
9
9
  const { pathToFileURL } = require('url');
10
+ const { register } = require('module');
10
11
  const EC = require('eight-colors');
11
12
  const KSR = require('koa-static-resolver');
12
13
  const Koa = require('koa');
@@ -190,6 +191,37 @@ const findUpConfig = (customConfigFile) => {
190
191
  // default config not found
191
192
  };
192
193
 
194
+ const checkRegisterFeature = () => {
195
+ const nv = process.versions.node;
196
+
197
+ // "module.register" added in Node.js: v20.6.0
198
+ // if (Util.cmpVersion(nv, '20.6.0') >= 0) {
199
+ // return true;
200
+ // }
201
+ // but also added in: v18.19.0
202
+ const requiredNV = '18.19.0';
203
+ if (Util.cmpVersion(nv, requiredNV) < 0) {
204
+ Util.logInfo(`The current Node.js version "${nv}" does NOT support "module.register", it requires "${requiredNV}" or higher.`);
205
+ return false;
206
+ }
207
+
208
+ // could be < 20.6.0 but just ignore it, please using latest minor version
209
+
210
+ return true;
211
+ };
212
+
213
+ const initTSPreload = () => {
214
+
215
+ const supportRegister = checkRegisterFeature();
216
+ if (!supportRegister) {
217
+ return;
218
+ }
219
+
220
+ register('./hooks.js', pathToFileURL(__filename));
221
+
222
+ };
223
+
224
+ // eslint-disable-next-line complexity
193
225
  const resolveConfigOptions = async (configPath) => {
194
226
  // json format
195
227
  const ext = path.extname(configPath);
@@ -197,6 +229,10 @@ const resolveConfigOptions = async (configPath) => {
197
229
  return JSON.parse(Util.readFileSync(configPath));
198
230
  }
199
231
 
232
+ if (ext === '.ts') {
233
+ initTSPreload();
234
+ }
235
+
200
236
  let configOptions;
201
237
  let err;
202
238
  try {
package/lib/hooks.js ADDED
@@ -0,0 +1,37 @@
1
+
2
+ const EC = require('eight-colors');
3
+
4
+ const extensionsRegex = /\.ts$|\.mts$|\.cts$/;
5
+
6
+ async function load(url, context, nextLoad) {
7
+
8
+ if (extensionsRegex.test(url) && !url.includes('/node_modules/')) {
9
+
10
+ const { transformSync } = await import('amaro').catch((e) => {
11
+ // console.log(e.message || e);
12
+ EC.logRed('The "amaro" module is required for loading ".ts" file, please run "npm i amaro"');
13
+ });
14
+
15
+ // Use format 'module' so it returns the source as-is, without stripping the types.
16
+ // Format 'commonjs' would not return the source for historical reasons.
17
+ const { source } = await nextLoad(url, {
18
+ ... context,
19
+ format: 'module'
20
+ });
21
+ if (source === null) {
22
+ throw new Error('Source code cannot be null or undefined');
23
+ }
24
+ const { code } = transformSync(source.toString(), {
25
+ mode: 'strip-only'
26
+ });
27
+ return {
28
+ format: 'module',
29
+ source: code
30
+ };
31
+ }
32
+ return nextLoad(url, context);
33
+ }
34
+
35
+ module.exports = {
36
+ load
37
+ };
package/lib/merge-data.js CHANGED
@@ -258,9 +258,9 @@ const mergeDataList = async (dataList, options) => {
258
258
 
259
259
  const artifacts = await mergeArtifacts(artifactsList, options);
260
260
 
261
- // base on first one
261
+ // base on first one, do not change dataList (need for onData)
262
262
  const mergedData = {
263
- ... dataList.shift()
263
+ ... dataList[0]
264
264
  };
265
265
 
266
266
  // merge new options