supercov 4.30.1 → 4.30.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "supercov",
3
- "version": "4.30.1",
3
+ "version": "4.30.2",
4
4
  "description": "Coverage, security and code quality for coding agents",
5
5
  "keywords": [
6
6
  "coverage",
@@ -126,14 +126,14 @@
126
126
  "test:windows-tls": "node scripts/windows-tls-test.mjs"
127
127
  },
128
128
  "optionalDependencies": {
129
- "@supercov/cli-darwin-arm64": "4.30.1",
130
- "@supercov/cli-darwin-x64": "4.30.1",
131
- "@supercov/cli-linux-arm64-gnu": "4.30.1",
132
- "@supercov/cli-linux-arm64-musl": "4.30.1",
133
- "@supercov/cli-linux-x64-gnu": "4.30.1",
134
- "@supercov/cli-linux-x64-musl": "4.30.1",
135
- "@supercov/cli-win32-arm64": "4.30.1",
136
- "@supercov/cli-win32-x64": "4.30.1"
129
+ "@supercov/cli-darwin-arm64": "4.30.2",
130
+ "@supercov/cli-darwin-x64": "4.30.2",
131
+ "@supercov/cli-linux-arm64-gnu": "4.30.2",
132
+ "@supercov/cli-linux-arm64-musl": "4.30.2",
133
+ "@supercov/cli-linux-x64-gnu": "4.30.2",
134
+ "@supercov/cli-linux-x64-musl": "4.30.2",
135
+ "@supercov/cli-win32-arm64": "4.30.2",
136
+ "@supercov/cli-win32-x64": "4.30.2"
137
137
  },
138
138
  "peerDependencies": {
139
139
  "@playwright/test": ">=1.55.0",
@@ -25,6 +25,16 @@ if ((process.env.NODE_OPTIONS ?? "").split(/\s+/).filter((option) => option ===
25
25
  !process.execArgv.includes("--enable-source-maps") &&
26
26
  typeof Module.setSourceMapsSupport === "function")
27
27
  Module.setSourceMapsSupport(true, { nodeModules: false, generatedCode: true });
28
+ // `node --check` with source maps on fails on any file with an inline map
29
+ // ("TypeError: WeakRef: invalid target", Node 24), and every instrumented
30
+ // copy has one: a site's `node --check assets/scripts/landing.js` failed its
31
+ // test command. A syntax check runs nothing that a stack trace could name.
32
+ if (process.execArgv.includes("--check") || process.execArgv.includes("-c")) {
33
+ if (typeof Module.setSourceMapsSupport === "function")
34
+ Module.setSourceMapsSupport(false);
35
+ else
36
+ process.setSourceMapsEnabled?.(false);
37
+ }
28
38
  // Before anything else loads: every module after this compiles from the
29
39
  // code the run's earlier processes left (atomic.mjs says why). Not in npm's
30
40
  // own process (`npm run`, `npx`, `npm exec`), which runs none of the
@@ -155,6 +165,182 @@ virtualMachine.createContext = function createContextWithRuntime(...parameters)
155
165
  }
156
166
  return context;
157
167
  };
168
+ // A test can read a measured file as text instead of importing it: to check
169
+ // what it says, or to run it in a `vm` sandbox of its own, as a browser
170
+ // script's test does without a browser. The instrumented copy then changed
171
+ // the test's result: a test that parsed the script's first line failed on
172
+ // the runtime loader there, and a script run in a fresh context failed on
173
+ // "Cannot read properties of undefined (reading 'mcdcBegin')". A test file
174
+ // (`*.test.*`, `*.spec.*`, or one under test/, tests/, __tests__/, spec/ or
175
+ // e2e/) reads a measured file as its author wrote it. Everything else reads
176
+ // the copy: a server of the project's own, a bundler, a helper, so a browser
177
+ // is served what Supercov measures. Supercov's own browser fixtures serve
178
+ // public/app.js from a server.mjs that reads it with fs. Code run in a `vm`
179
+ // context that is a measured file, as written or as the copy, runs as the
180
+ // copy with the process's runtime there, so a sandboxed script is measured.
181
+ installProjectSourceText();
182
+ function installProjectSourceText() {
183
+ const workspace = fileURLToPath(new URL("../../", import.meta.url));
184
+ let authored;
185
+ try {
186
+ authored = new Set(JSON.parse(readFileSync(new URL("./authored-sources.json", import.meta.url), "utf8")));
187
+ }
188
+ catch {
189
+ return;
190
+ }
191
+ if (authored.size === 0)
192
+ return;
193
+ const authoredRoot = fileURLToPath(new URL("./.authored/", import.meta.url));
194
+ const changedRoot = fileURLToPath(new URL("./.changed/", import.meta.url));
195
+ const roots = [...new Set([workspace, (() => {
196
+ try {
197
+ return realpathSync(workspace);
198
+ }
199
+ catch {
200
+ return workspace;
201
+ }
202
+ })()])];
203
+ const local = (file) => {
204
+ let absolute;
205
+ try {
206
+ absolute = resolve(file instanceof URL ? fileURLToPath(file) : file);
207
+ }
208
+ catch {
209
+ return undefined;
210
+ }
211
+ for (const root of roots) {
212
+ const inside = relative(root, absolute);
213
+ if (inside !== ".." && !inside.startsWith(`..${sep}`) && !isAbsolute(inside))
214
+ return inside.split(sep).join("/");
215
+ }
216
+ return undefined;
217
+ };
218
+ const { readFileSync: readSync, readFile: readCallback, existsSync: exists } = fs;
219
+ const { readFile: readPromise } = fs.promises;
220
+ // The text a tool of the command wrote to the file, or what its author wrote.
221
+ const authoredText = (file) => {
222
+ const changed = resolve(changedRoot, file);
223
+ return exists(changed) ? changed : resolve(authoredRoot, file);
224
+ };
225
+ const testFile = (file) => /(?:^|\/)(?:tests?|__tests__|specs?|e2e)\//.test(file) ||
226
+ /[._-](?:test|spec)\.[cm]?[jt]sx?$/.test(file);
227
+ // Whether the first project frame above `above` is a test file's.
228
+ const readByTest = (above) => {
229
+ const holder = {};
230
+ const limit = Error.stackTraceLimit;
231
+ try {
232
+ Error.stackTraceLimit = 8;
233
+ Error.captureStackTrace(holder, above);
234
+ }
235
+ finally {
236
+ Error.stackTraceLimit = limit;
237
+ }
238
+ for (const line of String(holder.stack).split("\n").slice(1)) {
239
+ const frame = /\(?((?:file:\/\/)?[^\s()]+?):\d+:\d+\)?$/.exec(line.trim())?.[1];
240
+ if (frame === undefined || frame.startsWith("node:"))
241
+ continue;
242
+ const caller = frame.startsWith("file:") ? fileURLToPath(frame) : frame;
243
+ const inside = local(caller);
244
+ // Supercov's own wrappers of the same read sit in between.
245
+ if (inside?.split("/").includes(".supercov"))
246
+ continue;
247
+ if (inside === undefined || inside.split("/").includes("node_modules"))
248
+ return false;
249
+ return testFile(inside);
250
+ }
251
+ return false;
252
+ };
253
+ const asAuthored = (target, above) => {
254
+ if (typeof target !== "string" && !(target instanceof URL))
255
+ return target;
256
+ const inside = local(target);
257
+ return inside !== undefined && authored.has(inside) && readByTest(above)
258
+ ? authoredText(inside)
259
+ : target;
260
+ };
261
+ fs.readFileSync = function readFileSync(target, ...rest) {
262
+ return Reflect.apply(readSync, this, [asAuthored(target, readFileSync), ...rest]);
263
+ };
264
+ fs.readFile = function readFile(target, ...rest) {
265
+ return Reflect.apply(readCallback, this, [asAuthored(target, readFile), ...rest]);
266
+ };
267
+ fs.promises.readFile = function readFile(target, ...rest) {
268
+ return Reflect.apply(readPromise, this, [asAuthored(target, readFile), ...rest]);
269
+ };
270
+ // Measured files by their authored text, read the first time a `vm` call
271
+ // is given text as long as one of them.
272
+ let byText;
273
+ const lengths = new Set();
274
+ for (const file of authored) {
275
+ try {
276
+ lengths.add(fs.statSync(authoredText(file)).size);
277
+ }
278
+ catch { }
279
+ }
280
+ // The copy to run for `code`: itself when it is already instrumented.
281
+ const copyOf = (code) => {
282
+ if (typeof code !== "string")
283
+ return undefined;
284
+ if (code.includes("__SUPERCOV_DIRECT_RUNTIME__"))
285
+ return code;
286
+ if (!lengths.has(Buffer.byteLength(code)))
287
+ return undefined;
288
+ if (byText === undefined) {
289
+ byText = new Map();
290
+ for (const file of authored) {
291
+ try {
292
+ byText.set(String(Reflect.apply(readSync, fs, [authoredText(file), "utf8"])), resolve(roots[0], file));
293
+ }
294
+ catch { }
295
+ }
296
+ }
297
+ const copy = byText.get(code);
298
+ if (copy === undefined)
299
+ return undefined;
300
+ try {
301
+ const instrumented = String(Reflect.apply(readSync, fs, [copy, "utf8"]));
302
+ return instrumented.includes("__SUPERCOV_DIRECT_RUNTIME__") ? instrumented : undefined;
303
+ }
304
+ catch {
305
+ return undefined;
306
+ }
307
+ };
308
+ const withRuntime = (context) => {
309
+ if (context === null || (typeof context !== "object" && typeof context !== "function"))
310
+ return;
311
+ if (Object.prototype.hasOwnProperty.call(context, "__SUPERCOV_DIRECT_RUNTIME__"))
312
+ return;
313
+ try {
314
+ Object.defineProperty(context, "__SUPERCOV_DIRECT_RUNTIME__", {
315
+ configurable: true,
316
+ enumerable: false,
317
+ get: () => globalThis.__SUPERCOV_DIRECT_RUNTIME__ ?? process.__SUPERCOV_DIRECT_RUNTIME__,
318
+ set(value) {
319
+ Object.defineProperty(context, "__SUPERCOV_DIRECT_RUNTIME__", {
320
+ configurable: true, enumerable: false, writable: true, value,
321
+ });
322
+ },
323
+ });
324
+ }
325
+ catch { }
326
+ };
327
+ const { runInContext, runInNewContext } = virtualMachine;
328
+ virtualMachine.runInContext = function runInContextMeasured(code, context, ...rest) {
329
+ const copy = copyOf(code);
330
+ if (copy === undefined)
331
+ return Reflect.apply(runInContext, this, [code, context, ...rest]);
332
+ withRuntime(context);
333
+ return Reflect.apply(runInContext, this, [copy, context, ...rest]);
334
+ };
335
+ virtualMachine.runInNewContext = function runInNewContextMeasured(code, context, ...rest) {
336
+ const copy = copyOf(code);
337
+ if (copy === undefined)
338
+ return Reflect.apply(runInNewContext, this, [code, context, ...rest]);
339
+ const sandbox = context ?? {};
340
+ withRuntime(sandbox);
341
+ return Reflect.apply(runInNewContext, this, [copy, sandbox, ...rest]);
342
+ };
343
+ }
158
344
  // Workers are independent Node processes and an explicit `execArgv: []`
159
345
  // otherwise strips the preload that supplies the isolated runtime. Preserve
160
346
  // every user option while adding exactly one Supercov import.