@tapjs/processinfo 3.1.3 → 3.1.4

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.
Files changed (48) hide show
  1. package/dist/commonjs/find-source-map-safe.d.ts +1 -2
  2. package/dist/commonjs/find-source-map-safe.d.ts.map +1 -1
  3. package/dist/commonjs/find-source-map-safe.js +4 -4
  4. package/dist/commonjs/find-source-map-safe.js.map +1 -1
  5. package/dist/commonjs/line-lengths.d.ts.map +1 -1
  6. package/dist/commonjs/line-lengths.js +0 -2
  7. package/dist/commonjs/line-lengths.js.map +1 -1
  8. package/dist/commonjs/lookup-sources.d.ts +6 -0
  9. package/dist/commonjs/lookup-sources.d.ts.map +1 -0
  10. package/dist/commonjs/lookup-sources.js +57 -0
  11. package/dist/commonjs/lookup-sources.js.map +1 -0
  12. package/dist/commonjs/register-coverage.d.ts.map +1 -1
  13. package/dist/commonjs/register-coverage.js +15 -8
  14. package/dist/commonjs/register-coverage.js.map +1 -1
  15. package/dist/commonjs/register-process-end.d.ts.map +1 -1
  16. package/dist/commonjs/register-process-end.js +1 -3
  17. package/dist/commonjs/register-process-end.js.map +1 -1
  18. package/dist/commonjs/set-sources.d.ts +2 -1
  19. package/dist/commonjs/set-sources.d.ts.map +1 -1
  20. package/dist/commonjs/set-sources.js +11 -10
  21. package/dist/commonjs/set-sources.js.map +1 -1
  22. package/dist/esm/find-source-map-safe.d.ts +1 -2
  23. package/dist/esm/find-source-map-safe.d.ts.map +1 -1
  24. package/dist/esm/find-source-map-safe.js +4 -4
  25. package/dist/esm/find-source-map-safe.js.map +1 -1
  26. package/dist/esm/hooks.d.mts.map +1 -1
  27. package/dist/esm/hooks.mjs +28 -6
  28. package/dist/esm/hooks.mjs.map +1 -1
  29. package/dist/esm/import.mjs +4 -1
  30. package/dist/esm/import.mjs.map +1 -1
  31. package/dist/esm/line-lengths.d.ts.map +1 -1
  32. package/dist/esm/line-lengths.js +0 -2
  33. package/dist/esm/line-lengths.js.map +1 -1
  34. package/dist/esm/lookup-sources.d.ts +6 -0
  35. package/dist/esm/lookup-sources.d.ts.map +1 -0
  36. package/dist/esm/lookup-sources.js +50 -0
  37. package/dist/esm/lookup-sources.js.map +1 -0
  38. package/dist/esm/register-coverage.d.ts.map +1 -1
  39. package/dist/esm/register-coverage.js +15 -8
  40. package/dist/esm/register-coverage.js.map +1 -1
  41. package/dist/esm/register-process-end.d.ts.map +1 -1
  42. package/dist/esm/register-process-end.js +1 -3
  43. package/dist/esm/register-process-end.js.map +1 -1
  44. package/dist/esm/set-sources.d.ts +2 -1
  45. package/dist/esm/set-sources.d.ts.map +1 -1
  46. package/dist/esm/set-sources.js +11 -10
  47. package/dist/esm/set-sources.js.map +1 -1
  48. package/package.json +3 -2
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import { SourceMap } from 'module';
3
- export declare const findSourceMapSafe: (s: string | URL) => SourceMap | undefined;
2
+ export declare const findSourceMapSafe: (s: string | URL) => false | undefined | SourceMap;
4
3
  //# sourceMappingURL=find-source-map-safe.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"find-source-map-safe.d.ts","sourceRoot":"","sources":["../../src/find-source-map-safe.ts"],"names":[],"mappings":";AAAA,OAAO,EAAiB,SAAS,EAAE,MAAM,QAAQ,CAAA;AAKjD,eAAO,MAAM,iBAAiB,MAAO,MAAM,GAAG,GAAG,0BAehD,CAAA"}
1
+ {"version":3,"file":"find-source-map-safe.d.ts","sourceRoot":"","sources":["../../src/find-source-map-safe.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,SAAS,EAAE,MAAM,QAAQ,CAAA;AAKjD,eAAO,MAAM,iBAAiB,MACzB,MAAM,GAAG,GAAG,KACd,KAAK,GAAG,SAAS,GAAG,SAetB,CAAA"}
@@ -11,16 +11,16 @@ const findSourceMapSafe = (s) => {
11
11
  const c = sourceMaps.get(mod);
12
12
  if (c)
13
13
  return c;
14
- // this can throw in some cases in node 19
14
+ // this can throw in some cases, eg if the sourcemap file is missing
15
15
  try {
16
16
  const sm = (0, module_1.findSourceMap)(mod);
17
17
  if (sm)
18
18
  sourceMaps.set(mod, sm);
19
19
  return sm;
20
- /* c8 ignore start */
21
20
  }
22
- catch { }
23
- /* c8 ignore stop */
21
+ catch {
22
+ return false;
23
+ }
24
24
  };
25
25
  exports.findSourceMapSafe = findSourceMapSafe;
26
26
  //# sourceMappingURL=find-source-map-safe.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"find-source-map-safe.js","sourceRoot":"","sources":["../../src/find-source-map-safe.ts"],"names":[],"mappings":";;;AAAA,mCAAiD;AACjD,qDAA4C;AAE5C,MAAM,UAAU,GAAG,IAAI,GAAG,EAAqB,CAAA;AAExC,MAAM,iBAAiB,GAAG,CAAC,CAAe,EAAE,EAAE;IACnD,gEAAgE;IAChE,mEAAmE;IACnE,MAAM,GAAG,GAAG,IAAA,0BAAS,EAAC,CAAC,CAAC,CAAA;IACxB,MAAM,CAAC,GAAG,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;IAC7B,IAAI,CAAC;QAAE,OAAO,CAAC,CAAA;IAEf,0CAA0C;IAC1C,IAAI;QACF,MAAM,EAAE,GAAG,IAAA,sBAAa,EAAC,GAAG,CAAC,CAAA;QAC7B,IAAI,EAAE;YAAE,UAAU,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,CAAC,CAAA;QAC/B,OAAO,EAAE,CAAA;QACT,qBAAqB;KACtB;IAAC,MAAM,GAAE;IACV,oBAAoB;AACtB,CAAC,CAAA;AAfY,QAAA,iBAAiB,qBAe7B","sourcesContent":["import { findSourceMap, SourceMap } from 'module'\nimport { pathToURL } from './path-to-url.js'\n\nconst sourceMaps = new Map<string, SourceMap>()\n\nexport const findSourceMapSafe = (s: string | URL) => {\n // Have to look up by URL, because the ?tapmock param will be in\n // the internal key used by node, as those are \"different\" modules.\n const mod = pathToURL(s)\n const c = sourceMaps.get(mod)\n if (c) return c\n\n // this can throw in some cases in node 19\n try {\n const sm = findSourceMap(mod)\n if (sm) sourceMaps.set(mod, sm)\n return sm\n /* c8 ignore start */\n } catch {}\n /* c8 ignore stop */\n}\n"]}
1
+ {"version":3,"file":"find-source-map-safe.js","sourceRoot":"","sources":["../../src/find-source-map-safe.ts"],"names":[],"mappings":";;;AAAA,mCAAiD;AACjD,qDAA4C;AAE5C,MAAM,UAAU,GAAG,IAAI,GAAG,EAAqB,CAAA;AAExC,MAAM,iBAAiB,GAAG,CAC/B,CAAe,EACgB,EAAE;IACjC,gEAAgE;IAChE,mEAAmE;IACnE,MAAM,GAAG,GAAG,IAAA,0BAAS,EAAC,CAAC,CAAC,CAAA;IACxB,MAAM,CAAC,GAAG,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;IAC7B,IAAI,CAAC;QAAE,OAAO,CAAC,CAAA;IAEf,oEAAoE;IACpE,IAAI;QACF,MAAM,EAAE,GAAG,IAAA,sBAAa,EAAC,GAAG,CAAC,CAAA;QAC7B,IAAI,EAAE;YAAE,UAAU,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,CAAC,CAAA;QAC/B,OAAO,EAAE,CAAA;KACV;IAAC,MAAM;QACN,OAAO,KAAK,CAAA;KACb;AACH,CAAC,CAAA;AAjBY,QAAA,iBAAiB,qBAiB7B","sourcesContent":["import { findSourceMap, SourceMap } from 'module'\nimport { pathToURL } from './path-to-url.js'\n\nconst sourceMaps = new Map<string, SourceMap>()\n\nexport const findSourceMapSafe = (\n s: string | URL\n): false | undefined | SourceMap => {\n // Have to look up by URL, because the ?tapmock param will be in\n // the internal key used by node, as those are \"different\" modules.\n const mod = pathToURL(s)\n const c = sourceMaps.get(mod)\n if (c) return c\n\n // this can throw in some cases, eg if the sourcemap file is missing\n try {\n const sm = findSourceMap(mod)\n if (sm) sourceMaps.set(mod, sm)\n return sm\n } catch {\n return false\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"line-lengths.d.ts","sourceRoot":"","sources":["../../src/line-lengths.ts"],"names":[],"mappings":";AAYA,eAAO,MAAM,eAAe,aAChB,MAAM,YACN,MAAM,GAAG,MAAM,SAiB1B,CAAA;AAED,eAAO,MAAM,cAAc,aAAc,MAAM,yBAG9C,CAAA"}
1
+ {"version":3,"file":"line-lengths.d.ts","sourceRoot":"","sources":["../../src/line-lengths.ts"],"names":[],"mappings":";AAYA,eAAO,MAAM,eAAe,aAChB,MAAM,YACN,MAAM,GAAG,MAAM,SAe1B,CAAA;AAED,eAAO,MAAM,cAAc,aAAc,MAAM,yBAG9C,CAAA"}
@@ -22,11 +22,9 @@ const saveLineLengths = (filename, content) => {
22
22
  if (cache.has(filename) || !last?.startsWith(sourceMapComment))
23
23
  return;
24
24
  const ll = content
25
- .replace(/[\n\u2028\u2029]$/, '')
26
25
  .split(/\n|\u2028|\u2029/)
27
26
  .map(l => l.length);
28
27
  cache.set(filename, ll);
29
- cache.set(filename, ll);
30
28
  };
31
29
  exports.saveLineLengths = saveLineLengths;
32
30
  const getLineLengths = (filename) => {
@@ -1 +1 @@
1
- {"version":3,"file":"line-lengths.js","sourceRoot":"","sources":["../../src/line-lengths.ts"],"names":[],"mappings":";AAAA,wEAAwE;;;AAExE,6BAAmC;AAEnC,MAAM,IAAI,GAAG,MAAM,CAAC,GAAG,CAAC,qCAAqC,CAAC,CAAA;AAC9D,MAAM,CAAC,GAAG,MAET,CAAA;AACD,MAAM,KAAK,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,IAAI,GAAG,EAAoB,CAAA;AACpD,CAAC,CAAC,IAAI,CAAC,GAAG,KAAK,CAAA;AAEf,MAAM,gBAAgB,GAAG,uBAAuB,CAAA;AACzC,MAAM,eAAe,GAAG,CAC7B,QAAgB,EAChB,OAAyB,EACzB,EAAE;IACF,IAAI,OAAO,KAAK,SAAS;QAAE,OAAM;IACjC,IAAI,OAAO,OAAO,KAAK,QAAQ;QAAE,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,CAAA;IAC1D,IAAI,QAAQ,CAAC,UAAU,CAAC,SAAS,CAAC;QAAE,QAAQ,GAAG,IAAA,mBAAa,EAAC,QAAQ,CAAC,CAAA;IACtE,mCAAmC;IACnC,sEAAsE;IACtE,uDAAuD;IACvD,MAAM,IAAI,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,CAAA;IAChD,IAAI,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,UAAU,CAAC,gBAAgB,CAAC;QAAE,OAAM;IACtE,MAAM,EAAE,GAAG,OAAO;SACf,OAAO,CAAC,mBAAmB,EAAE,EAAE,CAAC;SAChC,KAAK,CAAC,kBAAkB,CAAC;SACzB,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAA;IACrB,KAAK,CAAC,GAAG,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAA;IAEvB,KAAK,CAAC,GAAG,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAA;AACzB,CAAC,CAAA;AAnBY,QAAA,eAAe,mBAmB3B;AAEM,MAAM,cAAc,GAAG,CAAC,QAAgB,EAAE,EAAE;IACjD,IAAI,QAAQ,CAAC,UAAU,CAAC,SAAS,CAAC;QAAE,QAAQ,GAAG,IAAA,mBAAa,EAAC,QAAQ,CAAC,CAAA;IACtE,OAAO,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;AAC5B,CAAC,CAAA;AAHY,QAAA,cAAc,kBAG1B","sourcesContent":["// TODO: Refactor once https://github.com/nodejs/node/issues/48460 fixed\n\nimport { fileURLToPath } from 'url'\n\nconst kLLC = Symbol.for('@tapjs/processinfo lineLength cache')\nconst g = global as {\n [kLLC]?: Map<string, number[]>\n}\nconst cache = g[kLLC] || new Map<string, number[]>()\ng[kLLC] = cache\n\nconst sourceMapComment = '//# sourceMappingURL='\nexport const saveLineLengths = (\n filename: string,\n content?: string | Buffer\n) => {\n if (content === undefined) return\n if (typeof content === 'object') content = String(content)\n if (filename.startsWith('file://')) filename = fileURLToPath(filename)\n // no need if it's not sourcemapped\n // don't cache an empty array, though, because ts-node files will show\n // up first as source, and then as their built content.\n const last = content.trimEnd().split('\\n').pop()\n if (cache.has(filename) || !last?.startsWith(sourceMapComment)) return\n const ll = content\n .replace(/[\\n\\u2028\\u2029]$/, '')\n .split(/\\n|\\u2028|\\u2029/)\n .map(l => l.length)\n cache.set(filename, ll)\n\n cache.set(filename, ll)\n}\n\nexport const getLineLengths = (filename: string) => {\n if (filename.startsWith('file://')) filename = fileURLToPath(filename)\n return cache.get(filename)\n}\n"]}
1
+ {"version":3,"file":"line-lengths.js","sourceRoot":"","sources":["../../src/line-lengths.ts"],"names":[],"mappings":";AAAA,wEAAwE;;;AAExE,6BAAmC;AAEnC,MAAM,IAAI,GAAG,MAAM,CAAC,GAAG,CAAC,qCAAqC,CAAC,CAAA;AAC9D,MAAM,CAAC,GAAG,MAET,CAAA;AACD,MAAM,KAAK,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,IAAI,GAAG,EAAoB,CAAA;AACpD,CAAC,CAAC,IAAI,CAAC,GAAG,KAAK,CAAA;AAEf,MAAM,gBAAgB,GAAG,uBAAuB,CAAA;AACzC,MAAM,eAAe,GAAG,CAC7B,QAAgB,EAChB,OAAyB,EACzB,EAAE;IACF,IAAI,OAAO,KAAK,SAAS;QAAE,OAAM;IACjC,IAAI,OAAO,OAAO,KAAK,QAAQ;QAAE,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,CAAA;IAC1D,IAAI,QAAQ,CAAC,UAAU,CAAC,SAAS,CAAC;QAAE,QAAQ,GAAG,IAAA,mBAAa,EAAC,QAAQ,CAAC,CAAA;IACtE,mCAAmC;IACnC,sEAAsE;IACtE,uDAAuD;IACvD,MAAM,IAAI,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,CAAA;IAChD,IAAI,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,UAAU,CAAC,gBAAgB,CAAC;QAAE,OAAM;IACtE,MAAM,EAAE,GAAG,OAAO;SACf,KAAK,CAAC,kBAAkB,CAAC;SACzB,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAA;IAErB,KAAK,CAAC,GAAG,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAA;AACzB,CAAC,CAAA;AAjBY,QAAA,eAAe,mBAiB3B;AAEM,MAAM,cAAc,GAAG,CAAC,QAAgB,EAAE,EAAE;IACjD,IAAI,QAAQ,CAAC,UAAU,CAAC,SAAS,CAAC;QAAE,QAAQ,GAAG,IAAA,mBAAa,EAAC,QAAQ,CAAC,CAAA;IACtE,OAAO,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;AAC5B,CAAC,CAAA;AAHY,QAAA,cAAc,kBAG1B","sourcesContent":["// TODO: Refactor once https://github.com/nodejs/node/issues/48460 fixed\n\nimport { fileURLToPath } from 'url'\n\nconst kLLC = Symbol.for('@tapjs/processinfo lineLength cache')\nconst g = global as {\n [kLLC]?: Map<string, number[]>\n}\nconst cache = g[kLLC] || new Map<string, number[]>()\ng[kLLC] = cache\n\nconst sourceMapComment = '//# sourceMappingURL='\nexport const saveLineLengths = (\n filename: string,\n content?: string | Buffer\n) => {\n if (content === undefined) return\n if (typeof content === 'object') content = String(content)\n if (filename.startsWith('file://')) filename = fileURLToPath(filename)\n // no need if it's not sourcemapped\n // don't cache an empty array, though, because ts-node files will show\n // up first as source, and then as their built content.\n const last = content.trimEnd().split('\\n').pop()\n if (cache.has(filename) || !last?.startsWith(sourceMapComment)) return\n const ll = content\n .split(/\\n|\\u2028|\\u2029/)\n .map(l => l.length)\n\n cache.set(filename, ll)\n}\n\nexport const getLineLengths = (filename: string) => {\n if (filename.startsWith('file://')) filename = fileURLToPath(filename)\n return cache.get(filename)\n}\n"]}
@@ -0,0 +1,6 @@
1
+ export declare const sourcesCache: Map<string, string[]>;
2
+ export declare const loadPendingSourceMaps: () => void;
3
+ export declare const lookupSources: (url: string) => string[] | undefined;
4
+ export declare const getSources: () => Map<string, string[]>;
5
+ export declare const likelyHasSourceMap: (url: string) => void;
6
+ //# sourceMappingURL=lookup-sources.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lookup-sources.d.ts","sourceRoot":"","sources":["../../src/lookup-sources.ts"],"names":[],"mappings":"AAqBA,eAAO,MAAM,YAAY,uBAA8B,CAAA;AAEvD,eAAO,MAAM,qBAAqB,YAgBjC,CAAA;AAED,eAAO,MAAM,aAAa,QAAS,MAAM,yBAA0B,CAAA;AAEnE,eAAO,MAAM,UAAU,6BAGtB,CAAA;AAED,eAAO,MAAM,kBAAkB,QAAS,MAAM,SAG7C,CAAA"}
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ // For some reason that is very mysterious as of the time of writing this,
3
+ // node sporadically will in rare cases hang and fail to gracefully exit if
4
+ // a sufficiently large number of findSourceMap calls are made during the
5
+ // process exit event.
6
+ //
7
+ // However, we cannot look up source maps until *after* the module load
8
+ // event is completely finished and the module is about to be executed,
9
+ // because that is when the source map is added to node's cache.
10
+ //
11
+ // To work around this, every time a module is loaded, we attempt to
12
+ // determine whether it likely has the magic sourceMappingURL comment.
13
+ // If so, then we put it in a list, and at each message, attempt to load
14
+ // the sources for all modules in the list. Then, on process exit, if
15
+ // there's anything still pending that likely has a source map, we only
16
+ // have to look up at most one module (ie, if the last module loaded had a
17
+ // source map), which seems to not trigger the hang.
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ exports.likelyHasSourceMap = exports.getSources = exports.lookupSources = exports.loadPendingSourceMaps = exports.sourcesCache = void 0;
20
+ const find_source_map_safe_js_1 = require("./find-source-map-safe.js");
21
+ // the list of modules that likely have source maps
22
+ const maybeSM = new Set();
23
+ exports.sourcesCache = new Map();
24
+ const loadPendingSourceMaps = () => {
25
+ for (const url of maybeSM) {
26
+ const sm = (0, find_source_map_safe_js_1.findSourceMapSafe)(url);
27
+ if (sm === false) {
28
+ // can only happen if node found the SM comment, and tried to load it,
29
+ // but got an error creating the sourcemap, because it's invalid or
30
+ // the file is not present. No need to keep trying.
31
+ maybeSM.delete(url);
32
+ }
33
+ else {
34
+ const sources = sm?.payload?.sources;
35
+ if (sources) {
36
+ exports.sourcesCache.set(url, sources);
37
+ maybeSM.delete(url);
38
+ }
39
+ }
40
+ }
41
+ };
42
+ exports.loadPendingSourceMaps = loadPendingSourceMaps;
43
+ const lookupSources = (url) => (0, exports.getSources)().get(url);
44
+ exports.lookupSources = lookupSources;
45
+ const getSources = () => {
46
+ if (maybeSM.size)
47
+ (0, exports.loadPendingSourceMaps)();
48
+ return exports.sourcesCache;
49
+ };
50
+ exports.getSources = getSources;
51
+ const likelyHasSourceMap = (url) => {
52
+ if (!exports.sourcesCache.has(url))
53
+ maybeSM.add(url);
54
+ (0, exports.loadPendingSourceMaps)();
55
+ };
56
+ exports.likelyHasSourceMap = likelyHasSourceMap;
57
+ //# sourceMappingURL=lookup-sources.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lookup-sources.js","sourceRoot":"","sources":["../../src/lookup-sources.ts"],"names":[],"mappings":";AAAA,0EAA0E;AAC1E,2EAA2E;AAC3E,yEAAyE;AACzE,sBAAsB;AACtB,EAAE;AACF,uEAAuE;AACvE,uEAAuE;AACvE,gEAAgE;AAChE,EAAE;AACF,oEAAoE;AACpE,sEAAsE;AACtE,wEAAwE;AACxE,qEAAqE;AACrE,uEAAuE;AACvE,0EAA0E;AAC1E,oDAAoD;;;AAEpD,uEAA6D;AAE7D,mDAAmD;AACnD,MAAM,OAAO,GAAG,IAAI,GAAG,EAAU,CAAA;AACpB,QAAA,YAAY,GAAG,IAAI,GAAG,EAAoB,CAAA;AAEhD,MAAM,qBAAqB,GAAG,GAAG,EAAE;IACxC,KAAK,MAAM,GAAG,IAAI,OAAO,EAAE;QACzB,MAAM,EAAE,GAAG,IAAA,2CAAiB,EAAC,GAAG,CAAC,CAAA;QACjC,IAAI,EAAE,KAAK,KAAK,EAAE;YAChB,sEAAsE;YACtE,mEAAmE;YACnE,mDAAmD;YACnD,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;SACpB;aAAM;YACL,MAAM,OAAO,GAAG,EAAE,EAAE,OAAO,EAAE,OAAO,CAAA;YACpC,IAAI,OAAO,EAAE;gBACX,oBAAY,CAAC,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,CAAA;gBAC9B,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;aACpB;SACF;KACF;AACH,CAAC,CAAA;AAhBY,QAAA,qBAAqB,yBAgBjC;AAEM,MAAM,aAAa,GAAG,CAAC,GAAW,EAAE,EAAE,CAAC,IAAA,kBAAU,GAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;AAAtD,QAAA,aAAa,iBAAyC;AAE5D,MAAM,UAAU,GAAG,GAAG,EAAE;IAC7B,IAAI,OAAO,CAAC,IAAI;QAAE,IAAA,6BAAqB,GAAE,CAAA;IACzC,OAAO,oBAAY,CAAA;AACrB,CAAC,CAAA;AAHY,QAAA,UAAU,cAGtB;AAEM,MAAM,kBAAkB,GAAG,CAAC,GAAW,EAAE,EAAE;IAChD,IAAI,CAAC,oBAAY,CAAC,GAAG,CAAC,GAAG,CAAC;QAAE,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;IAC5C,IAAA,6BAAqB,GAAE,CAAA;AACzB,CAAC,CAAA;AAHY,QAAA,kBAAkB,sBAG9B","sourcesContent":["// For some reason that is very mysterious as of the time of writing this,\n// node sporadically will in rare cases hang and fail to gracefully exit if\n// a sufficiently large number of findSourceMap calls are made during the\n// process exit event.\n//\n// However, we cannot look up source maps until *after* the module load\n// event is completely finished and the module is about to be executed,\n// because that is when the source map is added to node's cache.\n//\n// To work around this, every time a module is loaded, we attempt to\n// determine whether it likely has the magic sourceMappingURL comment.\n// If so, then we put it in a list, and at each message, attempt to load\n// the sources for all modules in the list. Then, on process exit, if\n// there's anything still pending that likely has a source map, we only\n// have to look up at most one module (ie, if the last module loaded had a\n// source map), which seems to not trigger the hang.\n\nimport { findSourceMapSafe } from './find-source-map-safe.js'\n\n// the list of modules that likely have source maps\nconst maybeSM = new Set<string>()\nexport const sourcesCache = new Map<string, string[]>()\n\nexport const loadPendingSourceMaps = () => {\n for (const url of maybeSM) {\n const sm = findSourceMapSafe(url)\n if (sm === false) {\n // can only happen if node found the SM comment, and tried to load it,\n // but got an error creating the sourcemap, because it's invalid or\n // the file is not present. No need to keep trying.\n maybeSM.delete(url)\n } else {\n const sources = sm?.payload?.sources\n if (sources) {\n sourcesCache.set(url, sources)\n maybeSM.delete(url)\n }\n }\n }\n}\n\nexport const lookupSources = (url: string) => getSources().get(url)\n\nexport const getSources = () => {\n if (maybeSM.size) loadPendingSourceMaps()\n return sourcesCache\n}\n\nexport const likelyHasSourceMap = (url: string) => {\n if (!sourcesCache.has(url)) maybeSM.add(url)\n loadPendingSourceMaps()\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"register-coverage.d.ts","sourceRoot":"","sources":["../../src/register-coverage.ts"],"names":[],"mappings":";AAKA,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;AAOxC,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAA;AAE5D,eAAO,IAAI,OAAO,EAAE,OAAO,GAAG,SAAqB,CAAA;AA+DnD,eAAO,MAAM,QAAQ,YAYpB,CAAA;AAGD,eAAO,MAAM,oBAAoB,QAC1B,MAAM,eACE,mBAAmB,SA2DjC,CAAA"}
1
+ {"version":3,"file":"register-coverage.d.ts","sourceRoot":"","sources":["../../src/register-coverage.ts"],"names":[],"mappings":";AAKA,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;AAQxC,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAA;AAE5D,eAAO,IAAI,OAAO,EAAE,OAAO,GAAG,SAAqB,CAAA;AA6DnD,eAAO,MAAM,QAAQ,YAYpB,CAAA;AAGD,eAAO,MAAM,oBAAoB,QAC1B,MAAM,eACE,mBAAmB,SAmEjC,CAAA"}
@@ -12,6 +12,7 @@ const node_url_1 = require("node:url");
12
12
  const find_source_map_safe_js_1 = require("./find-source-map-safe.js");
13
13
  const get_exclude_js_1 = require("./get-exclude.js");
14
14
  const line_lengths_js_1 = require("./line-lengths.js");
15
+ const lookup_sources_js_1 = require("./lookup-sources.js");
15
16
  exports.SESSION = undefined;
16
17
  // This is a \n delimited list of files to show coverage for
17
18
  // If not set, or empty, then coverage is included for all files
@@ -33,12 +34,10 @@ const uncoveredFiles = cxEnv
33
34
  const exclude = p.env._TAPJS_PROCESSINFO_COV_EXCLUDE_
34
35
  ? (0, get_exclude_js_1.getExclude)('_TAPJS_PROCESSINFO_COV_EXCLUDE_', false)
35
36
  : undefined;
36
- const fileCovered = (f, s, files = []) => {
37
+ const fileCovered = (f, sources = [], files = []) => {
37
38
  const testFiles = [f];
38
- if (s) {
39
- for (const src of s.sources || []) {
40
- testFiles.push((0, node_path_1.resolve)(src.startsWith('file://') ? (0, node_url_1.fileURLToPath)(src) : src));
41
- }
39
+ for (const src of sources || []) {
40
+ testFiles.push((0, node_path_1.resolve)(src.startsWith('file://') ? (0, node_url_1.fileURLToPath)(src) : src));
42
41
  }
43
42
  // never include coverage if the file is fully ignored.
44
43
  if (!testFiles.some(f => files.includes(f)))
@@ -107,14 +106,22 @@ const coverageOnProcessEnd = (cwd, processInfo) => {
107
106
  // see if it has a source map
108
107
  // need to look up via the url, not the file path, because mocks
109
108
  // attach a tapmock search param, which is in node's internal key.
110
- const s = (0, find_source_map_safe_js_1.findSourceMapSafe)(obj.url);
111
- if (!fileCovered(f, s?.payload, processInfo.files)) {
109
+ const sources = (0, lookup_sources_js_1.lookupSources)(obj.url);
110
+ if (!fileCovered(f, sources, processInfo.files)) {
112
111
  return false;
113
112
  }
113
+ // Most of the time this will be cached at the time of recording, but
114
+ // if it's the last module loaded, or transpiled in-place by ts-node,
115
+ // the sourcemap won't be pre-loaded and will have to be looked up.
116
+ const s = (0, find_source_map_safe_js_1.findSourceMapSafe)(obj.url);
114
117
  const { payload } = s || { payload: null };
115
118
  if (payload) {
116
119
  sourceMapCache[obj.url] = Object.assign(Object.create(null), {
117
- lineLengths: (0, line_lengths_js_1.getLineLengths)(f),
120
+ /* c8 ignore start */
121
+ // node's SourceMap objects provide this as of 20.5.0
122
+ //@ts-ignore
123
+ lineLengths: s?.lineLengths || (0, line_lengths_js_1.getLineLengths)(f),
124
+ /* c8 ignore stop */
118
125
  data: payload,
119
126
  });
120
127
  }
@@ -1 +1 @@
1
- {"version":3,"file":"register-coverage.js","sourceRoot":"","sources":["../../src/register-coverage.ts"],"names":[],"mappings":";;;AAAA,sDAAsD;AACtD,8DAA8D;AAC9D,MAAM,CAAC,GAAG,OAAO,CAAA;AACjB,MAAM,OAAO,GAAG,CAAC,CAAC,GAAG,CAAC,4BAA4B,KAAK,GAAG,CAAA;AAC1D,qCAAkD;AAClD,mDAAwC;AAExC,yCAAmC;AACnC,uCAAwC;AACxC,uEAA6D;AAC7D,qDAA6C;AAC7C,uDAAkD;AAGvC,QAAA,OAAO,GAAwB,SAAS,CAAA;AAEnD,4DAA4D;AAC5D,gEAAgE;AAChE,mEAAmE;AACnE,8DAA8D;AAC9D,MAAM,KAAK,GAAG,CAAC,CAAC,GAAG,CAAC,6BAA6B,IAAI,EAAE,CAAA;AACvD,MAAM,YAAY,GAAa,KAAK;KACjC,IAAI,EAAE;KACN,KAAK,CAAC,IAAI,CAAC;KACX,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;AAEnB,uDAAuD;AACvD,oDAAoD;AACpD,qDAAqD;AACrD,MAAM,KAAK,GAAG,CAAC,CAAC,GAAG,CAAC,qCAAqC,IAAI,EAAE,CAAA;AAC/D,MAAM,cAAc,GAAa,KAAK;KACnC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know to collect at the end of the process\nconst p = process\nconst enabled = p.env._TAPJS_PROCESSINFO_COVERAGE_ !== '0'\nimport { mkdirSync, writeFileSync } from 'node:fs'\nimport { Session } from 'node:inspector'\nimport { SourceMapPayload } from 'node:module'\nimport { resolve } from 'node:path'\nimport { fileURLToPath } from 'node:url'\nimport { findSourceMapSafe } from './find-source-map-safe.js'\nimport { getExclude } from './get-exclude.js'\nimport { getLineLengths } from './line-lengths.js'\nimport { ProcessInfoNodeData } from './process-info-node.js'\n\nexport let SESSION: Session | undefined = undefined\n\n// This is a \\n delimited list of files to show coverage for\n// If not set, or empty, then coverage is included for all files\n// that pass the exclusion RegExp filter. If included in this list,\n// then coverage will be recorded, even if it matches exclude.\nconst cfEnv = p.env._TAPJS_PROCESSINFO_COV_FILES_ || ''\nconst coveredFiles: string[] = cfEnv\n .trim()\n .split('\\n')\n .filter(f => !!f)\n\n// NB: coverage exclusion is in addition to processinfo\n// exclusion. Only show coverage for a file we care\n// about at least somewhat, but coverage is a subset.\nconst cxEnv = p.env._TAPJS_PROCESSINFO_COV_EXCLUDE_FILES_ || ''\nconst uncoveredFiles: string[] = cxEnv\n .trim()\n .split('\\n')\n .filter(f => !!f)\n\nconst exclude = p.env._TAPJS_PROCESSINFO_COV_EXCLUDE_\n ? getExclude('_TAPJS_PROCESSINFO_COV_EXCLUDE_', false)\n : undefined\n\nconst fileCovered = (\n f: string,\n s?: SourceMapPayload,\n files: string[] = []\n) => {\n const testFiles = [f]\n if (s) {\n for (const src of s.sources || []) {\n testFiles.push(\n resolve(src.startsWith('file://') ? fileURLToPath(src) : src)\n )\n }\n }\n\n // never include coverage if the file is fully ignored.\n if (!testFiles.some(f => files.includes(f))) return false\n\n // if at least one of them are explicitly covered, then include it,\n // otherwise omit if we explicitly listed\n if (coveredFiles.length) {\n return testFiles.some(f => coveredFiles.includes(f))\n }\n\n // if any of the filenames are explicitly excluded, no coverage\n // otherwise, it is covered\n return !testFiles.some(\n f => uncoveredFiles.includes(f) || exclude?.test(f)\n )\n}\n\n// C8 can't see that this function runs, best theory is that it\n// collides with what it's doing with the coverage it's collecting\n// This ignore can possibly be removed once this is being tested\n// with a version of tap that uses this library, but it might just\n// be an unresolveable bootstrap problem.\n// The test does verify that it ran, because otherwise, there would\n// be no coverage, and it verifies that it gets the expected coverage.\n/* c8 ignore start */\nexport const register = () => {\n if (!enabled) return\n p.env._TAPJS_PROCESSINFO_COVERAGE_ = '1'\n\n SESSION = new Session()\n SESSION.connect()\n SESSION.post('Profiler.enable')\n SESSION.post('Runtime.enable')\n SESSION.post('Profiler.startPreciseCoverage', {\n callCount: true,\n detailed: true,\n })\n}\n/* c8 ignore stop */\n\nexport const coverageOnProcessEnd = (\n cwd: string,\n processInfo: ProcessInfoNodeData\n) => {\n // Similar to the coverage tracking bootstrap problem above, c8\n // doesn't see that this function runs, even though it DOES see\n // that the function defined below runs, which is weird.\n /* c8 ignore start */\n if (!SESSION) return\n const session = SESSION\n\n const f = `${cwd}/.tap/coverage/${processInfo.uuid}.json`\n mkdirSync(`${cwd}/.tap/coverage`, { recursive: true })\n\n session.post('Profiler.takePreciseCoverage', (er, cov) => {\n session.post('Profiler.stopPreciseCoverage')\n /* c8 ignore stop */\n\n // something very strange and bad happened\n /* c8 ignore start */\n if (er) {\n throw er\n }\n /* c8 ignore stop */\n\n // Create a source-map-cache that c8 uses in report generation\n const sourceMapCache: {\n [k: string]: {\n lineLengths: number[]\n data: SourceMapPayload\n }\n } = {}\n Object.assign(cov, {\n 'source-map-cache': sourceMapCache,\n })\n\n cov.result = cov.result.filter(obj => {\n if (!/^file:/.test(obj.url)) {\n return false\n }\n const f = fileURLToPath(obj.url)\n // see if it has a source map\n // need to look up via the url, not the file path, because mocks\n // attach a tapmock search param, which is in node's internal key.\n const s = findSourceMapSafe(obj.url)\n if (!fileCovered(f, s?.payload, processInfo.files)) {\n return false\n }\n const { payload } = s || { payload: null }\n if (payload) {\n sourceMapCache[obj.url] = Object.assign(Object.create(null), {\n lineLengths: getLineLengths(f),\n data: payload,\n })\n }\n return true\n })\n\n writeFileSync(f, JSON.stringify(cov, null, 2) + '\\n', 'utf8')\n /* c8 ignore start */\n })\n}\n/* c8 ignore stop */\n"]}
1
+ {"version":3,"file":"register-coverage.js","sourceRoot":"","sources":["../../src/register-coverage.ts"],"names":[],"mappings":";;;AAAA,sDAAsD;AACtD,8DAA8D;AAC9D,MAAM,CAAC,GAAG,OAAO,CAAA;AACjB,MAAM,OAAO,GAAG,CAAC,CAAC,GAAG,CAAC,4BAA4B,KAAK,GAAG,CAAA;AAC1D,qCAAkD;AAClD,mDAAwC;AAExC,yCAAmC;AACnC,uCAAwC;AACxC,uEAA6D;AAC7D,qDAA6C;AAC7C,uDAAkD;AAClD,2DAAmD;AAGxC,QAAA,OAAO,GAAwB,SAAS,CAAA;AAEnD,4DAA4D;AAC5D,gEAAgE;AAChE,mEAAmE;AACnE,8DAA8D;AAC9D,MAAM,KAAK,GAAG,CAAC,CAAC,GAAG,CAAC,6BAA6B,IAAI,EAAE,CAAA;AACvD,MAAM,YAAY,GAAa,KAAK;KACjC,IAAI,EAAE;KACN,KAAK,CAAC,IAAI,CAAC;KACX,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;AAEnB,uDAAuD;AACvD,oDAAoD;AACpD,qDAAqD;AACrD,MAAM,KAAK,GAAG,CAAC,CAAC,GAAG,CAAC,qCAAqC,IAAI,EAAE,CAAA;AAC/D,MAAM,cAAc,GAAa,KAAK;KACnC,IAAI,EAAE;KACN,KAAK,CAAC,IAAI,CAAC;KACX,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;AAEnB,MAAM,OAAO,GAAG,CAAC,CAAC,GAAG,CAAC,+BAA+B;IACnD,CAAC,CAAC,IAAA,2BAAU,EAAC,iCAAiC,EAAE,KAAK,CAAC;IACtD,CAAC,CAAC,SAAS,CAAA;AAEb,MAAM,WAAW,GAAG,CAClB,CAA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AAC,CAAA;YAChC,6BAA6B;YAC7B,gEAAgE;YAChE,kEAAkE;YAClE,MAAM,OAAO,GAAG,IAAA,iCAAa,EAAC,GAAG,CAAC,GAAG,CAAC,CAAA;YACtC,IAAI,CAAC,WAAW,CAAC,CAAC,EAAE,OAAO,EAAE,WAAW,CAAC,KAAK,CAAC,EAAE;gBAC/C,OAAO,KAAK,CAAA;aACb;YACD,qEAAqE;YACrE,qEAAqE;YACrE,mEAAmE;YACnE,MAAM,CAAC,GAAG,IAAA,2CAAiB,EAAC,GAAG,CAAC,GAAG,CAAC,CAAA;YACpC,MAAM,EAAE,OAAO,EAAE,GAAG,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,CAAA;YAC1C,IAAI,OAAO,EAAE;gBACX,cAAc,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE;oBAC3D,qBAAqB;oBACrB,qDAAqD;oBACrD,YAAY;oBACZ,WAAW,EAAE,CAAC,EAAE,WAAW,IAAI,IAAA,gCAAc,EAAC,CAAC,CAAC;oBAChD,oBAAoB;oBACpB,IAAI,EAAE,OAAO;iBACd,CAAC,CAAA;aACH;YACD,OAAO,IAAI,CAAA;QACb,CAAC,CAAC,CAAA;QAEF,IAAA,uBAAa,EAAC,CAAC,EAAE,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC,GAAG,IAAI,EAAE,MAAM,CAAC,CAAA;QAC7D,qBAAqB;IACvB,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA;AArEY,QAAA,oBAAoB,wBAqEhC;AACD,oBAAoB","sourcesContent":["// start tracking coverage, unless disabled explicltly\n// export so that we know to collect at the end of the process\nconst p = process\nconst enabled = p.env._TAPJS_PROCESSINFO_COVERAGE_ !== '0'\nimport { mkdirSync, writeFileSync } from 'node:fs'\nimport { Session } from 'node:inspector'\nimport { SourceMapPayload } from 'node:module'\nimport { resolve } from 'node:path'\nimport { fileURLToPath } from 'node:url'\nimport { findSourceMapSafe } from './find-source-map-safe.js'\nimport { getExclude } from './get-exclude.js'\nimport { getLineLengths } from './line-lengths.js'\nimport { lookupSources } from './lookup-sources.js'\nimport { ProcessInfoNodeData } from './process-info-node.js'\n\nexport let SESSION: Session | undefined = undefined\n\n// This is a \\n delimited list of files to show coverage for\n// If not set, or empty, then coverage is included for all files\n// that pass the exclusion RegExp filter. If included in this list,\n// then coverage will be recorded, even if it matches exclude.\nconst cfEnv = p.env._TAPJS_PROCESSINFO_COV_FILES_ || ''\nconst coveredFiles: string[] = cfEnv\n .trim()\n .split('\\n')\n .filter(f => !!f)\n\n// NB: coverage exclusion is in addition to processinfo\n// exclusion. Only show coverage for a file we care\n// about at least somewhat, but coverage is a subset.\nconst cxEnv = p.env._TAPJS_PROCESSINFO_COV_EXCLUDE_FILES_ || ''\nconst uncoveredFiles: string[] = cxEnv\n .trim()\n .split('\\n')\n .filter(f => !!f)\n\nconst exclude = p.env._TAPJS_PROCESSINFO_COV_EXCLUDE_\n ? getExclude('_TAPJS_PROCESSINFO_COV_EXCLUDE_', false)\n : undefined\n\nconst fileCovered = (\n f: string,\n sources: string[] = [],\n files: string[] = []\n) => {\n const testFiles = [f]\n for (const src of sources || []) {\n testFiles.push(\n resolve(src.startsWith('file://') ? fileURLToPath(src) : src)\n )\n }\n\n // never include coverage if the file is fully ignored.\n if (!testFiles.some(f => files.includes(f))) return false\n\n // if at least one of them are explicitly covered, then include it,\n // otherwise omit if we explicitly listed\n if (coveredFiles.length) {\n return testFiles.some(f => coveredFiles.includes(f))\n }\n\n // if any of the filenames are explicitly excluded, no coverage\n // otherwise, it is covered\n return !testFiles.some(\n f => uncoveredFiles.includes(f) || exclude?.test(f)\n )\n}\n\n// C8 can't see that this function runs, best theory is that it\n// collides with what it's doing with the coverage it's collecting\n// This ignore can possibly be removed once this is being tested\n// with a version of tap that uses this library, but it might just\n// be an unresolveable bootstrap problem.\n// The test does verify that it ran, because otherwise, there would\n// be no coverage, and it verifies that it gets the expected coverage.\n/* c8 ignore start */\nexport const register = () => {\n if (!enabled) return\n p.env._TAPJS_PROCESSINFO_COVERAGE_ = '1'\n\n SESSION = new Session()\n SESSION.connect()\n SESSION.post('Profiler.enable')\n SESSION.post('Runtime.enable')\n SESSION.post('Profiler.startPreciseCoverage', {\n callCount: true,\n detailed: true,\n })\n}\n/* c8 ignore stop */\n\nexport const coverageOnProcessEnd = (\n cwd: string,\n processInfo: ProcessInfoNodeData\n) => {\n // Similar to the coverage tracking bootstrap problem above, c8\n // doesn't see that this function runs, even though it DOES see\n // that the function defined below runs, which is weird.\n /* c8 ignore start */\n if (!SESSION) return\n const session = SESSION\n\n const f = `${cwd}/.tap/coverage/${processInfo.uuid}.json`\n mkdirSync(`${cwd}/.tap/coverage`, { recursive: true })\n\n session.post('Profiler.takePreciseCoverage', (er, cov) => {\n session.post('Profiler.stopPreciseCoverage')\n /* c8 ignore stop */\n\n // something very strange and bad happened\n /* c8 ignore start */\n if (er) {\n throw er\n }\n /* c8 ignore stop */\n\n // Create a source-map-cache that c8 uses in report generation\n const sourceMapCache: {\n [k: string]: {\n lineLengths: number[]\n data: SourceMapPayload\n }\n } = {}\n Object.assign(cov, {\n 'source-map-cache': sourceMapCache,\n })\n\n cov.result = cov.result.filter(obj => {\n if (!/^file:/.test(obj.url)) {\n return false\n }\n const f = fileURLToPath(obj.url)\n // see if it has a source map\n // need to look up via the url, not the file path, because mocks\n // attach a tapmock search param, which is in node's internal key.\n const sources = lookupSources(obj.url)\n if (!fileCovered(f, sources, processInfo.files)) {\n return false\n }\n // Most of the time this will be cached at the time of recording, but\n // if it's the last module loaded, or transpiled in-place by ts-node,\n // the sourcemap won't be pre-loaded and will have to be looked up.\n const s = findSourceMapSafe(obj.url)\n const { payload } = s || { payload: null }\n if (payload) {\n sourceMapCache[obj.url] = Object.assign(Object.create(null), {\n /* c8 ignore start */\n // node's SourceMap objects provide this as of 20.5.0\n //@ts-ignore\n lineLengths: s?.lineLengths || getLineLengths(f),\n /* c8 ignore stop */\n data: payload,\n })\n }\n return true\n })\n\n writeFileSync(f, JSON.stringify(cov, null, 2) + '\\n', 'utf8')\n /* c8 ignore start */\n })\n}\n/* c8 ignore stop */\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"register-process-end.d.ts","sourceRoot":"","sources":["../../src/register-process-end.ts"],"names":[],"mappings":"AAaA,eAAO,MAAM,QAAQ,YA4BpB,CAAA"}
1
+ {"version":3,"file":"register-process-end.d.ts","sourceRoot":"","sources":["../../src/register-process-end.ts"],"names":[],"mappings":"AAaA,eAAO,MAAM,QAAQ,YA0BpB,CAAA"}
@@ -21,9 +21,7 @@ const register = () => {
21
21
  // try to find the actual sources of the files we loaded
22
22
  // This can't be done up front, because the sourcemap isn't
23
23
  // present during the load phase, since it's in the contents.
24
- for (const file of processInfo.files) {
25
- (0, set_sources_js_1.setSources)(file);
26
- }
24
+ (0, set_sources_js_1.setSources)(processInfo);
27
25
  processInfo.runtime = runtime[0] * 1e3 + runtime[1] / 1e6;
28
26
  const globalsAdded = Object.keys(global).filter(k => !globals.has(k));
29
27
  if (globalsAdded.length) {
@@ -1 +1 @@
1
- {"version":3,"file":"register-process-end.js","sourceRoot":"","sources":["../../src/register-process-end.ts"],"names":[],"mappings":";;;AAAA,6CAAoC;AACpC,+DAAsD;AAEtD,2BAA6C;AAC7C,iEAA6D;AAC7D,qDAA6C;AAE7C,MAAM,IAAI,GAAG,OAAO,CAAA;AAEpB,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,uBAAuB,IAAI,IAAI,CAAC,GAAG,EAAE,CAAA;AAC1D,IAAI,CAAC,GAAG,CAAC,uBAAuB,GAAG,GAAG,CAAA;AACtC,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAA;AAErC,MAAM,QAAQ,GAAG,GAAG,EAAE;IAC3B,IAAA,oBAAM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AAW,CAAC,CAAA;IACxC,CAAC,EACD,EAAE,UAAU,EAAE,IAAI,EAAE,CACrB,CAAA;AACH,CAAC,CAAA;AA5BY,QAAA,QAAQ,YA4BpB","sourcesContent":["import { onExit } from 'signal-exit'\nimport { getProcessInfo } from './get-process-info.js'\n\nimport { mkdirSync, writeFileSync } from 'fs'\nimport { coverageOnProcessEnd } from './register-coverage.js'\nimport { setSources } from './set-sources.js'\n\nconst proc = process\n\nconst cwd = proc.env._TAPJS_PROCESSINFO_CWD_ || proc.cwd()\nproc.env._TAPJS_PROCESSINFO_CWD_ = cwd\nconst globals = new Set(Object.keys(global))\n\nexport const register = () => {\n onExit(\n (code, signal) => {\n const processInfo = getProcessInfo()\n processInfo.code = code\n processInfo.signal = signal\n const runtime = proc.hrtime(processInfo.hrstart)\n delete processInfo.hrstart\n processInfo.files = [...new Set(processInfo.files)]\n // try to find the actual sources of the files we loaded\n // This can't be done up front, because the sourcemap isn't\n // present during the load phase, since it's in the contents.\n for (const file of processInfo.files) {\n setSources(file)\n }\n processInfo.runtime = runtime[0] * 1e3 + runtime[1] / 1e6\n const globalsAdded = Object.keys(global).filter(k => !globals.has(k))\n if (globalsAdded.length) {\n processInfo.globalsAdded = globalsAdded\n }\n\n const f = `${cwd}/.tap/processinfo/${processInfo.uuid}.json`\n mkdirSync(`${cwd}/.tap/processinfo`, { recursive: true })\n writeFileSync(f, JSON.stringify(processInfo, null, 2) + '\\n', 'utf8')\n coverageOnProcessEnd(cwd, processInfo)\n },\n { alwaysLast: true }\n )\n}\n"]}
1
+ {"version":3,"file":"register-process-end.js","sourceRoot":"","sources":["../../src/register-process-end.ts"],"names":[],"mappings":";;;AAAA,6CAAoC;AACpC,+DAAsD;AAEtD,2BAA6C;AAC7C,iEAA6D;AAC7D,qDAA6C;AAE7C,MAAM,IAAI,GAAG,OAAO,CAAA;AAEpB,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,uBAAuB,IAAI,IAAI,CAAC,GAAG,EAAE,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AC,CAAC,EAAE,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE,IAAI,EAAE,CAAC,CAAC,GAAG,IAAI,EAAE,MAAM,CAAC,CAAA;QACrE,IAAA,2CAAoB,EAAC,GAAG,EAAE,WAAW,CAAC,CAAA;IACxC,CAAC,EACD,EAAE,UAAU,EAAE,IAAI,EAAE,CACrB,CAAA;AACH,CAAC,CAAA;AA1BY,QAAA,QAAQ,YA0BpB","sourcesContent":["import { onExit } from 'signal-exit'\nimport { getProcessInfo } from './get-process-info.js'\n\nimport { mkdirSync, writeFileSync } from 'fs'\nimport { coverageOnProcessEnd } from './register-coverage.js'\nimport { setSources } from './set-sources.js'\n\nconst proc = process\n\nconst cwd = proc.env._TAPJS_PROCESSINFO_CWD_ || proc.cwd()\nproc.env._TAPJS_PROCESSINFO_CWD_ = cwd\nconst globals = new Set(Object.keys(global))\n\nexport const register = () => {\n onExit(\n (code, signal) => {\n const processInfo = getProcessInfo()\n processInfo.code = code\n processInfo.signal = signal\n const runtime = proc.hrtime(processInfo.hrstart)\n delete processInfo.hrstart\n processInfo.files = [...new Set(processInfo.files)]\n // try to find the actual sources of the files we loaded\n // This can't be done up front, because the sourcemap isn't\n // present during the load phase, since it's in the contents.\n setSources(processInfo)\n processInfo.runtime = runtime[0] * 1e3 + runtime[1] / 1e6\n const globalsAdded = Object.keys(global).filter(k => !globals.has(k))\n if (globalsAdded.length) {\n processInfo.globalsAdded = globalsAdded\n }\n\n const f = `${cwd}/.tap/processinfo/${processInfo.uuid}.json`\n mkdirSync(`${cwd}/.tap/processinfo`, { recursive: true })\n writeFileSync(f, JSON.stringify(processInfo, null, 2) + '\\n', 'utf8')\n coverageOnProcessEnd(cwd, processInfo)\n },\n { alwaysLast: true }\n )\n}\n"]}
@@ -1,2 +1,3 @@
1
- export declare const setSources: (file: string) => void;
1
+ import { ProcessInfoNodeData } from './index.js';
2
+ export declare const setSources: (pi: ProcessInfoNodeData) => void;
2
3
  //# sourceMappingURL=set-sources.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"set-sources.d.ts","sourceRoot":"","sources":["../../src/set-sources.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,UAAU,SAAU,MAAM,SAOtC,CAAA"}
1
+ {"version":3,"file":"set-sources.d.ts","sourceRoot":"","sources":["../../src/set-sources.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAShD,eAAO,MAAM,UAAU,OAAQ,mBAAmB,SAQjD,CAAA"}
@@ -1,20 +1,21 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.setSources = void 0;
4
- const find_source_map_safe_js_1 = require("./find-source-map-safe.js");
5
- const get_process_info_js_1 = require("./get-process-info.js");
4
+ const url_1 = require("url");
5
+ const lookup_sources_js_1 = require("./lookup-sources.js");
6
6
  const url_to_path_js_1 = require("./url-to-path.js");
7
+ let sourcesCache;
7
8
  // set the processInfo.sources for a given file, but don't clobber
8
9
  // if called multiple times, or create duplicate entries.
9
10
  // Should only be called *after* the file in question has been loaded.
10
- const setSources = (file) => {
11
- const sm = (0, find_source_map_safe_js_1.findSourceMapSafe)(file);
12
- if (!sm)
13
- return;
14
- const pi = (0, get_process_info_js_1.getProcessInfo)();
15
- const s = pi.sources[file] || [];
16
- s.push(...sm.payload.sources.map(s => (0, url_to_path_js_1.urlToPath)(s)));
17
- pi.sources[file] = [...new Set(s)];
11
+ const setSources = (pi) => {
12
+ sourcesCache ??= (0, lookup_sources_js_1.getSources)();
13
+ for (const [url, sources] of sourcesCache.entries()) {
14
+ const file = (0, url_1.fileURLToPath)(url);
15
+ const s = pi.sources[file] || [];
16
+ s.push(...sources.map(s => (0, url_to_path_js_1.urlToPath)(s)));
17
+ pi.sources[file] = [...new Set(s)];
18
+ }
18
19
  };
19
20
  exports.setSources = setSources;
20
21
  //# sourceMappingURL=set-sources.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"set-sources.js","sourceRoot":"","sources":["../../src/set-sources.ts"],"names":[],"mappings":";;;AAAA,uEAA6D;AAC7D,+DAAsD;AACtD,qDAA4C;AAE5C,kEAAkE;AAClE,yDAAyD;AACzD,sEAAsE;AAC/D,MAAM,UAAU,GAAG,CAAC,IAAY,EAAE,EAAE;IACzC,MAAM,EAAE,GAAG,IAAA,2CAAiB,EAAC,IAAI,CAAC,CAAA;IAClC,IAAI,CAAC,EAAE;QAAE,OAAM;IACf,MAAM,EAAE,GAAG,IAAA,oCAAc,GAAE,CAAA;IAC3B,MAAM,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,CAAA;IAChC,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,IAAA,0BAAS,EAAC,CAAC,CAAC,CAAC,CAAC,CAAA;IACpD,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,CAAA;AACpC,CAAC,CAAA;AAPY,QAAA,UAAU,cAOtB","sourcesContent":["import { findSourceMapSafe } from './find-source-map-safe.js'\nimport { getProcessInfo } from './get-process-info.js'\nimport { urlToPath } from './url-to-path.js'\n\n// set the processInfo.sources for a given file, but don't clobber\n// if called multiple times, or create duplicate entries.\n// Should only be called *after* the file in question has been loaded.\nexport const setSources = (file: string) => {\n const sm = findSourceMapSafe(file)\n if (!sm) return\n const pi = getProcessInfo()\n const s = pi.sources[file] || []\n s.push(...sm.payload.sources.map(s => urlToPath(s)))\n pi.sources[file] = [...new Set(s)]\n}\n"]}
1
+ {"version":3,"file":"set-sources.js","sourceRoot":"","sources":["../../src/set-sources.ts"],"names":[],"mappings":";;;AAAA,6BAAmC;AAEnC,2DAAgD;AAChD,qDAA4C;AAE5C,IAAI,YAAmC,CAAA;AAEvC,kEAAkE;AAClE,yDAAyD;AACzD,sEAAsE;AAC/D,MAAM,UAAU,GAAG,CAAC,EAAuB,EAAE,EAAE;IACpD,YAAY,KAAK,IAAA,8BAAU,GAAE,CAAA;IAC7B,KAAK,MAAM,CAAC,GAAG,EAAE,OAAO,CAAC,IAAI,YAAY,CAAC,OAAO,EAAE,EAAE;QACnD,MAAM,IAAI,GAAG,IAAA,mBAAa,EAAC,GAAG,CAAC,CAAA;QAC/B,MAAM,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,CAAA;QAChC,CAAC,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,IAAA,0BAAS,EAAC,CAAC,CAAC,CAAC,CAAC,CAAA;QACzC,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,CAAA;KACnC;AACH,CAAC,CAAA;AARY,QAAA,UAAU,cAQtB","sourcesContent":["import { fileURLToPath } from 'url'\nimport { ProcessInfoNodeData } from './index.js'\nimport { getSources } from './lookup-sources.js'\nimport { urlToPath } from './url-to-path.js'\n\nlet sourcesCache: Map<string, string[]>\n\n// set the processInfo.sources for a given file, but don't clobber\n// if called multiple times, or create duplicate entries.\n// Should only be called *after* the file in question has been loaded.\nexport const setSources = (pi: ProcessInfoNodeData) => {\n sourcesCache ??= getSources()\n for (const [url, sources] of sourcesCache.entries()) {\n const file = fileURLToPath(url)\n const s = pi.sources[file] || []\n s.push(...sources.map(s => urlToPath(s)))\n pi.sources[file] = [...new Set(s)]\n }\n}\n"]}
@@ -1,4 +1,3 @@
1
- /// <reference types="node" resolution-mode="require"/>
2
1
  import { SourceMap } from 'module';
3
- export declare const findSourceMapSafe: (s: string | URL) => SourceMap | undefined;
2
+ export declare const findSourceMapSafe: (s: string | URL) => false | undefined | SourceMap;
4
3
  //# sourceMappingURL=find-source-map-safe.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"find-source-map-safe.d.ts","sourceRoot":"","sources":["../../src/find-source-map-safe.ts"],"names":[],"mappings":";AAAA,OAAO,EAAiB,SAAS,EAAE,MAAM,QAAQ,CAAA;AAKjD,eAAO,MAAM,iBAAiB,MAAO,MAAM,GAAG,GAAG,0BAehD,CAAA"}
1
+ {"version":3,"file":"find-source-map-safe.d.ts","sourceRoot":"","sources":["../../src/find-source-map-safe.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,SAAS,EAAE,MAAM,QAAQ,CAAA;AAKjD,eAAO,MAAM,iBAAiB,MACzB,MAAM,GAAG,GAAG,KACd,KAAK,GAAG,SAAS,GAAG,SAetB,CAAA"}
@@ -8,15 +8,15 @@ export const findSourceMapSafe = (s) => {
8
8
  const c = sourceMaps.get(mod);
9
9
  if (c)
10
10
  return c;
11
- // this can throw in some cases in node 19
11
+ // this can throw in some cases, eg if the sourcemap file is missing
12
12
  try {
13
13
  const sm = findSourceMap(mod);
14
14
  if (sm)
15
15
  sourceMaps.set(mod, sm);
16
16
  return sm;
17
- /* c8 ignore start */
18
17
  }
19
- catch { }
20
- /* c8 ignore stop */
18
+ catch {
19
+ return false;
20
+ }
21
21
  };
22
22
  //# sourceMappingURL=find-source-map-safe.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"find-source-map-safe.js","sourceRoot":"","sources":["../../src/find-source-map-safe.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAa,MAAM,QAAQ,CAAA;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAE5C,MAAM,UAAU,GAAG,IAAI,GAAG,EAAqB,CAAA;AAE/C,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,CAAe,EAAE,EAAE;IACnD,gEAAgE;IAChE,mEAAmE;IACnE,MAAM,GAAG,GAAG,SAAS,CAAC,CAAC,CAAC,CAAA;IACxB,MAAM,CAAC,GAAG,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;IAC7B,IAAI,CAAC;QAAE,OAAO,CAAC,CAAA;IAEf,0CAA0C;IAC1C,IAAI;QACF,MAAM,EAAE,GAAG,aAAa,CAAC,GAAG,CAAC,CAAA;QAC7B,IAAI,EAAE;YAAE,UAAU,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,CAAC,CAAA;QAC/B,OAAO,EAAE,CAAA;QACT,qBAAqB;KACtB;IAAC,MAAM,GAAE;IACV,oBAAoB;AACtB,CAAC,CAAA","sourcesContent":["import { findSourceMap, SourceMap } from 'module'\nimport { pathToURL } from './path-to-url.js'\n\nconst sourceMaps = new Map<string, SourceMap>()\n\nexport const findSourceMapSafe = (s: string | URL) => {\n // Have to look up by URL, because the ?tapmock param will be in\n // the internal key used by node, as those are \"different\" modules.\n const mod = pathToURL(s)\n const c = sourceMaps.get(mod)\n if (c) return c\n\n // this can throw in some cases in node 19\n try {\n const sm = findSourceMap(mod)\n if (sm) sourceMaps.set(mod, sm)\n return sm\n /* c8 ignore start */\n } catch {}\n /* c8 ignore stop */\n}\n"]}
1
+ {"version":3,"file":"find-source-map-safe.js","sourceRoot":"","sources":["../../src/find-source-map-safe.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAa,MAAM,QAAQ,CAAA;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAE5C,MAAM,UAAU,GAAG,IAAI,GAAG,EAAqB,CAAA;AAE/C,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAC/B,CAAe,EACgB,EAAE;IACjC,gEAAgE;IAChE,mEAAmE;IACnE,MAAM,GAAG,GAAG,SAAS,CAAC,CAAC,CAAC,CAAA;IACxB,MAAM,CAAC,GAAG,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;IAC7B,IAAI,CAAC;QAAE,OAAO,CAAC,CAAA;IAEf,oEAAoE;IACpE,IAAI;QACF,MAAM,EAAE,GAAG,aAAa,CAAC,GAAG,CAAC,CAAA;QAC7B,IAAI,EAAE;YAAE,UAAU,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,CAAC,CAAA;QAC/B,OAAO,EAAE,CAAA;KACV;IAAC,MAAM;QACN,OAAO,KAAK,CAAA;KACb;AACH,CAAC,CAAA","sourcesContent":["import { findSourceMap, SourceMap } from 'module'\nimport { pathToURL } from './path-to-url.js'\n\nconst sourceMaps = new Map<string, SourceMap>()\n\nexport const findSourceMapSafe = (\n s: string | URL\n): false | undefined | SourceMap => {\n // Have to look up by URL, because the ?tapmock param will be in\n // the internal key used by node, as those are \"different\" modules.\n const mod = pathToURL(s)\n const c = sourceMaps.get(mod)\n if (c) return c\n\n // this can throw in some cases, eg if the sourcemap file is missing\n try {\n const sm = findSourceMap(mod)\n if (sm) sourceMaps.set(mod, sm)\n return sm\n } catch {\n return false\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"hooks.d.mts","sourceRoot":"","sources":["../../src/hooks.mts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AActD,eAAO,MAAM,aAAa,YAAa;IAAE,IAAI,CAAC,EAAE,WAAW,CAAA;CAAE,WAwB5D,CAAA;AAED,eAAO,MAAM,UAAU;UAAsB,WAAW;UAEvD,CAAA;AAsBD,eAAO,MAAM,IAAI,QACV,MAAM,WACF,GAAG,YACF,QAAQ,iBAyBnB,CAAA;AAGD,eAAO,MAAM,KAAK,YAGjB,CAAA"}
1
+ {"version":3,"file":"hooks.d.mts","sourceRoot":"","sources":["../../src/hooks.mts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AAiBtD,eAAO,MAAM,aAAa,YAAa;IAAE,IAAI,CAAC,EAAE,WAAW,CAAA;CAAE,WA0B5D,CAAA;AAED,eAAO,MAAM,UAAU;UAAsB,WAAW;UAEvD,CAAA;AAyCD,eAAO,MAAM,IAAI,QACV,MAAM,WACF,GAAG,YACF,QAAQ,iBA2BnB,CAAA;AAGD,eAAO,MAAM,KAAK,YAGjB,CAAA"}
@@ -1,4 +1,5 @@
1
1
  // hooks used by loader-legacy.mjs and loader.mjs
2
+ import { readFile } from 'node:fs/promises';
2
3
  import { parse } from 'node:path';
3
4
  import { fileURLToPath } from 'node:url';
4
5
  import { getExclude } from './get-exclude.js';
@@ -6,8 +7,11 @@ import { getImportMetaURL } from './get-import-meta-url.js';
6
7
  import { fakeMains } from './get-main.js';
7
8
  import { getProcessInfo as _getProcessInfo, reset as processInfoReset, } from './get-process-info.js';
8
9
  import { saveLineLengths } from './line-lengths.js';
10
+ import { likelyHasSourceMap } from './lookup-sources.js';
9
11
  let getProcessInfo = _getProcessInfo;
10
12
  let PORT = undefined;
13
+ const exclude = getExclude('_TAPJS_PROCESSINFO_EXCLUDE_', false);
14
+ const smMagicComment = /\/[*\/]#\s+sourceMappingURL=[^\s]+/;
11
15
  export const globalPreload = (context) => {
12
16
  // this will be something like path/to/dist/esm/lib/esm.mjs
13
17
  // but we need path/to/dist/commonjs/cjs.js
@@ -21,13 +25,15 @@ if (typeof port !== 'undefined') {
21
25
  const require = createRequire(${JSON.stringify(base)})
22
26
  const { getProcessInfo } = require('./get-process-info.js')
23
27
  const { saveLineLengths } = require('./line-lengths.js')
28
+ const { likelyHasSourceMap } = require('./lookup-sources.js')
24
29
  // must be called eagerly here.
25
30
  // this does all the registration as well.
26
31
  const processInfo = getProcessInfo()
27
32
  port.onmessage = (e) => {
28
- const { filename, content } = e.data
33
+ const { filename, content, url } = e.data
29
34
  processInfo.files.push(filename)
30
35
  saveLineLengths(filename, content)
36
+ if (url) likelyHasSourceMap(url)
31
37
  }
32
38
  port.unref()
33
39
  }
@@ -36,8 +42,7 @@ if (typeof port !== 'undefined') {
36
42
  export const initialize = ({ port }) => {
37
43
  PORT = port;
38
44
  };
39
- const exclude = getExclude('_TAPJS_PROCESSINFO_EXCLUDE_', false);
40
- const record = async (url, content) => {
45
+ const record = async (url, content, originSource) => {
41
46
  const filename = url.startsWith('file://') ? fileURLToPath(url) : url;
42
47
  if (exclude.test(filename)) {
43
48
  return;
@@ -45,13 +50,28 @@ const record = async (url, content) => {
45
50
  if (fakeMains.includes(filename)) {
46
51
  return;
47
52
  }
53
+ let maybeSM = false;
54
+ if (originSource !== content ||
55
+ (content === undefined && url.startsWith('file://'))) {
56
+ // try to read the file, fall back to the content we have, or ''
57
+ // if any source maps anywhere, flag it as possibly having one
58
+ originSource ??=
59
+ (await readFile(filename, 'utf8').catch(() => content)) ?? '';
60
+ }
61
+ maybeSM = smMagicComment.test(originSource);
48
62
  if (PORT) {
49
- PORT.postMessage({ filename, content });
63
+ PORT.postMessage({
64
+ filename,
65
+ content,
66
+ ...(maybeSM && { url }),
67
+ });
50
68
  }
51
69
  else {
52
70
  // call lazily so we don't double-register
53
71
  getProcessInfo().files.push(filename);
54
72
  saveLineLengths(filename, content);
73
+ if (maybeSM)
74
+ likelyHasSourceMap(url);
55
75
  }
56
76
  };
57
77
  export const load = async (url, context, nextLoad) => {
@@ -73,9 +93,11 @@ export const load = async (url, context, nextLoad) => {
73
93
  };
74
94
  }
75
95
  }
76
- // we actually need the transpiled
96
+ // get line lengths from final source
97
+ // if origin source doesn't match, check for possible source map
98
+ const originSource = context.source;
77
99
  const ret = await nextLoad(url, context);
78
- await record(url, ret.source);
100
+ await record(url, ret.source, originSource);
79
101
  return ret;
80
102
  };
81
103
  // just for testing purposes
@@ -1 +1 @@
1
- {"version":3,"file":"hooks.mjs","sourceRoot":"","sources":["../../src/hooks.mts"],"names":[],"mappings":"AAAA,iDAAiD;AAEjD,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAA;AACjC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAExC,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAA;AAC3D,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AACzC,OAAO,EACL,cAAc,IAAI,eAAe,EACjC,KAAK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AAC,CAAA;QACrC,eAAe,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAA;KACnC;AACH,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,IAAI,GAAG,KAAK,EACvB,GAAW,EACX,OAAY,EACZ,QAAkB,EAClB,EAAE;IACF,IAAI,GAAG,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE;QAC7B,MAAM,QAAQ,GAAG,aAAa,CAAC,GAAG,CAAC,CAAA;QACnC,MAAM,EAAE,GAAG,EAAE,GAAG,KAAK,CAAC,QAAQ,CAAC,CAAA;QAC/B,+DAA+D;QAC/D,gEAAgE;QAChE,kEAAkE;QAClE,2BAA2B;QAC3B,qEAAqE;QACrE,aAAa;QACb,IAAI,CAAC,GAAG,EAAE;YACR,MAAM,MAAM,CAAC,GAAG,CAAC,CAAA;YACjB,OAAO;gBACL,GAAG,OAAO;gBACV,MAAM,EAAE,UAAU;gBAClB,YAAY,EAAE,IAAI;aACnB,CAAA;SACF;KACF;IAED,kCAAkC;IAClC,MAAM,GAAG,GAAG,MAAM,QAAQ,CAAC,GAAG,EAAE,OAAO,CAAC,CAAA;IACxC,MAAM,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;IAC7B,OAAO,GAAG,CAAA;AACZ,CAAC,CAAA;AAED,4BAA4B;AAC5B,MAAM,CAAC,MAAM,KAAK,GAAG,GAAG,EAAE;IACxB,IAAI,GAAG,SAAS,CAAA;IAChB,cAAc,GAAG,gBAAgB,EAAE,CAAC,cAAc,CAAA;AACpD,CAAC,CAAA","sourcesContent":["// hooks used by loader-legacy.mjs and loader.mjs\n\nimport { parse } from 'node:path'\nimport { fileURLToPath } from 'node:url'\nimport type { MessagePort } from 'node:worker_threads'\nimport { getExclude } from './get-exclude.js'\nimport { getImportMetaURL } from './get-import-meta-url.js'\nimport { fakeMains } from './get-main.js'\nimport {\n getProcessInfo as _getProcessInfo,\n reset as processInfoReset,\n} from './get-process-info.js'\nimport { saveLineLengths } from './line-lengths.js'\n\nlet getProcessInfo = _getProcessInfo\n\nlet PORT: undefined | MessagePort = undefined\n\nexport const globalPreload = (context: { port?: MessagePort }) => {\n // this will be something like path/to/dist/esm/lib/esm.mjs\n // but we need path/to/dist/commonjs/cjs.js\n const base = getImportMetaURL('../commonjs/[global preload].js')\n const { port } = context || {}\n PORT = port\n return `\nif (typeof port !== 'undefined') {\n const { createRequire } = getBuiltin('module')\n const { fileURLToPath } = getBuiltin('url')\n const require = createRequire(${JSON.stringify(base)})\n const { getProcessInfo } = require('./get-process-info.js')\n const { saveLineLengths } = require('./line-lengths.js')\n // must be called eagerly here.\n // this does all the registration as well.\n const processInfo = getProcessInfo()\n port.onmessage = (e) => {\n const { filename, content } = e.data\n processInfo.files.push(filename)\n saveLineLengths(filename, content)\n }\n port.unref()\n}\n`\n}\n\nexport const initialize = ({ port }: { port: MessagePort }) => {\n PORT = port\n}\n\nconst exclude = getExclude('_TAPJS_PROCESSINFO_EXCLUDE_', false)\n\nconst record = async (url: string, content?: string) => {\n const filename = url.startsWith('file://') ? fileURLToPath(url) : url\n if (exclude.test(filename)) {\n return\n }\n if (fakeMains.includes(filename)) {\n return\n }\n\n if (PORT) {\n PORT.postMessage({ filename, content })\n } else {\n // call lazily so we don't double-register\n getProcessInfo().files.push(filename)\n saveLineLengths(filename, content)\n }\n}\n\nexport const load = async (\n url: string,\n context: any,\n nextLoad: Function\n) => {\n if (url.startsWith('file://')) {\n const filename = fileURLToPath(url)\n const { ext } = parse(filename)\n // Package bins will sometimes have an extensionless bin script\n // instead of just naming their extensioned file and letting npm\n // symlink it for them. Don't blow up when this happens, just tell\n // node that it's commonjs.\n // TODO: should we just let this fail? It fails *without* the loader,\n // after all.\n if (!ext) {\n await record(url)\n return {\n ...context,\n format: 'commonjs',\n shortCircuit: true,\n }\n }\n }\n\n // we actually need the transpiled\n const ret = await nextLoad(url, context)\n await record(url, ret.source)\n return ret\n}\n\n// just for testing purposes\nexport const reset = () => {\n PORT = undefined\n getProcessIn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F,IAAI,GAAG,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE;QAC7B,MAAM,QAAQ,GAAG,aAAa,CAAC,GAAG,CAAC,CAAA;QACnC,MAAM,EAAE,GAAG,EAAE,GAAG,KAAK,CAAC,QAAQ,CAAC,CAAA;QAC/B,+DAA+D;QAC/D,gEAAgE;QAChE,kEAAkE;QAClE,2BAA2B;QAC3B,qEAAqE;QACrE,aAAa;QACb,IAAI,CAAC,GAAG,EAAE;YACR,MAAM,MAAM,CAAC,GAAG,CAAC,CAAA;YACjB,OAAO;gBACL,GAAG,OAAO;gBACV,MAAM,EAAE,UAAU;gBAClB,YAAY,EAAE,IAAI;aACnB,CAAA;SACF;KACF;IAED,qCAAqC;IACrC,gEAAgE;IAChE,MAAM,YAAY,GAAG,OAAO,CAAC,MAAM,CAAA;IACnC,MAAM,GAAG,GAAG,MAAM,QAAQ,CAAC,GAAG,EAAE,OAAO,CAAC,CAAA;IACxC,MAAM,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,MAAM,EAAE,YAAY,CAAC,CAAA;IAC3C,OAAO,GAAG,CAAA;AACZ,CAAC,CAAA;AAED,4BAA4B;AAC5B,MAAM,CAAC,MAAM,KAAK,GAAG,GAAG,EAAE;IACxB,IAAI,GAAG,SAAS,CAAA;IAChB,cAAc,GAAG,gBAAgB,EAAE,CAAC,cAAc,CAAA;AACpD,CAAC,CAAA","sourcesContent":["// hooks used by loader-legacy.mjs and loader.mjs\n\nimport { readFile } from 'node:fs/promises'\nimport { parse } from 'node:path'\nimport { fileURLToPath } from 'node:url'\nimport type { MessagePort } from 'node:worker_threads'\nimport { getExclude } from './get-exclude.js'\nimport { getImportMetaURL } from './get-import-meta-url.js'\nimport { fakeMains } from './get-main.js'\nimport {\n getProcessInfo as _getProcessInfo,\n reset as processInfoReset,\n} from './get-process-info.js'\nimport { saveLineLengths } from './line-lengths.js'\nimport { likelyHasSourceMap } from './lookup-sources.js'\n\nlet getProcessInfo = _getProcessInfo\nlet PORT: undefined | MessagePort = undefined\n\nconst exclude = getExclude('_TAPJS_PROCESSINFO_EXCLUDE_', false)\nconst smMagicComment = /\\/[*\\/]#\\s+sourceMappingURL=[^\\s]+/\n\nexport const globalPreload = (context: { port?: MessagePort }) => {\n // this will be something like path/to/dist/esm/lib/esm.mjs\n // but we need path/to/dist/commonjs/cjs.js\n const base = getImportMetaURL('../commonjs/[global preload].js')\n const { port } = context || {}\n PORT = port\n return `\nif (typeof port !== 'undefined') {\n const { createRequire } = getBuiltin('module')\n const { fileURLToPath } = getBuiltin('url')\n const require = createRequire(${JSON.stringify(base)})\n const { getProcessInfo } = require('./get-process-info.js')\n const { saveLineLengths } = require('./line-lengths.js')\n const { likelyHasSourceMap } = require('./lookup-sources.js')\n // must be called eagerly here.\n // this does all the registration as well.\n const processInfo = getProcessInfo()\n port.onmessage = (e) => {\n const { filename, content, url } = e.data\n processInfo.files.push(filename)\n saveLineLengths(filename, content)\n if (url) likelyHasSourceMap(url)\n }\n port.unref()\n}\n`\n}\n\nexport const initialize = ({ port }: { port: MessagePort }) => {\n PORT = port\n}\n\nconst record = async (\n url: string,\n content?: string,\n originSource?: string\n) => {\n const filename = url.startsWith('file://') ? fileURLToPath(url) : url\n if (exclude.test(filename)) {\n return\n }\n if (fakeMains.includes(filename)) {\n return\n }\n\n let maybeSM = false\n if (\n originSource !== content ||\n (content === undefined && url.startsWith('file://'))\n ) {\n // try to read the file, fall back to the content we have, or ''\n // if any source maps anywhere, flag it as possibly having one\n originSource ??=\n (await readFile(filename, 'utf8').catch(() => content)) ?? ''\n }\n maybeSM = smMagicComment.test(originSource as string)\n\n if (PORT) {\n PORT.postMessage({\n filename,\n content,\n ...(maybeSM && { url }),\n })\n } else {\n // call lazily so we don't double-register\n getProcessInfo().files.push(filename)\n saveLineLengths(filename, content)\n if (maybeSM) likelyHasSourceMap(url)\n }\n}\n\nexport const load = async (\n url: string,\n context: any,\n nextLoad: Function\n) => {\n if (url.startsWith('file://')) {\n const filename = fileURLToPath(url)\n const { ext } = parse(filename)\n // Package bins will sometimes have an extensionless bin script\n // instead of just naming their extensioned file and letting npm\n // symlink it for them. Don't blow up when this happens, just tell\n // node that it's commonjs.\n // TODO: should we just let this fail? It fails *without* the loader,\n // after all.\n if (!ext) {\n await record(url)\n return {\n ...context,\n format: 'commonjs',\n shortCircuit: true,\n }\n }\n }\n\n // get line lengths from final source\n // if origin source doesn't match, check for possible source map\n const originSource = context.source\n const ret = await nextLoad(url, context)\n await record(url, ret.source, originSource)\n return ret\n}\n\n// just for testing purposes\nexport const reset = () => {\n PORT = undefined\n getProcessInfo = processInfoReset().getProcessInfo\n}\n"]}
@@ -6,13 +6,16 @@ import { MessageChannel } from 'node:worker_threads';
6
6
  import { getProcessInfo } from './get-process-info.js';
7
7
  import { saveLineLengths } from './line-lengths.js';
8
8
  import { getImportMetaURL } from './get-import-meta-url.js';
9
+ import { likelyHasSourceMap } from './lookup-sources.js';
9
10
  const { port1, port2 } = new MessageChannel();
10
11
  // must be called eagerly here.
11
12
  // this does all the registration as well.
12
13
  const processInfo = getProcessInfo();
13
- port1.on('message', ({ filename, content }) => {
14
+ port1.on('message', ({ filename, content, url }) => {
14
15
  processInfo.files.push(filename);
15
16
  saveLineLengths(filename, content);
17
+ if (url)
18
+ likelyHasSourceMap(url);
16
19
  });
17
20
  port1.unref();
18
21
  port2.unref();
@@ -1 +1 @@
1
- {"version":3,"file":"import.mjs","sourceRoot":"","sources":["../../src/import.mts"],"names":[],"mappings":"AAAA,iCAAiC;AACjC,wEAAwE;AACxE,4DAA4D;AAC5D,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AACtC,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAA;AAE3D,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,IAAI,cAAc,EAAE,CAAA;AAE7C,+BAA+B;AAC/B,0CAA0C;AAC1C,MAAM,WAAW,GAAG,cAAc,EAAE,CAAA;AACpC,KAAK,CAAC,EAAE,CAAC,SAAS,EAAE,CAAC,EAAE,QAAQ,EAAE,OAAO,EAAE,EAAE,EAAE;IAC5C,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;IAChC,eAAe,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAA;AACpC,CAAC,CAAC,CAAA;AAEF,KAAK,CAAC,KAAK,EAAE,CAAA;AACb,KAAK,CAAC,KAAK,EAAE,CAAA;AAEb,QAAQ,CAAC,gBAAgB,CAAC,cAAc,CAAC,EAAE;IACzC,SAAS,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG;IAC1B,IAAI,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE;IACrB,YAAY,EAAE,CAAC,KAAK,CAAC;CACtB,CAAC,CAAA","sourcesContent":["//@ts-ignore - added in node 20.6\n// this is the argument for --import, which does the initial main-thread\n// work, and then registers the loader without globalPreload\nimport { register } from 'node:module'\nimport { MessageChannel } from 'node:worker_threads'\nimport { getProcessInfo } from './get-process-info.js'\nimport { saveLineLengths } from './line-lengths.js'\nimport { getImportMetaURL } from './get-import-meta-url.js'\n\nconst { port1, port2 } = new MessageChannel()\n\n// must be called eagerly here.\n// this does all the registration as well.\nconst processInfo = getProcessInfo()\nport1.on('message', ({ filename, content }) => {\n processInfo.files.push(filename)\n saveLineLengths(filename, content)\n})\n\nport1.unref()\nport2.unref()\n\nregister(getImportMetaURL(`./loader.mjs`), {\n parentURL: import.meta.url,\n data: { port: port2 },\n transferList: [port2],\n})\n"]}
1
+ {"version":3,"file":"import.mjs","sourceRoot":"","sources":["../../src/import.mts"],"names":[],"mappings":"AAAA,iCAAiC;AACjC,wEAAwE;AACxE,4DAA4D;AAC5D,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AACtC,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAA;AAC3D,OAAO,EAAC,kBAAkB,EAAC,MAAM,qBAAqB,CAAA;AAEtD,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,IAAI,cAAc,EAAE,CAAA;AAE7C,+BAA+B;AAC/B,0CAA0C;AAC1C,MAAM,WAAW,GAAG,cAAc,EAAE,CAAA;AACpC,KAAK,CAAC,EAAE,CAAC,SAAS,EAAE,CAAC,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,EAAE,EAAE,EAAE;IACjD,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;IAChC,eAAe,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAA;IAClC,IAAI,GAAG;QAAE,kBAAkB,CAAC,GAAG,CAAC,CAAA;AAClC,CAAC,CAAC,CAAA;AAEF,KAAK,CAAC,KAAK,EAAE,CAAA;AACb,KAAK,CAAC,KAAK,EAAE,CAAA;AAEb,QAAQ,CAAC,gBAAgB,CAAC,cAAc,CAAC,EAAE;IACzC,SAAS,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG;IAC1B,IAAI,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE;IACrB,YAAY,EAAE,CAAC,KAAK,CAAC;CACtB,CAAC,CAAA","sourcesContent":["//@ts-ignore - added in node 20.6\n// this is the argument for --import, which does the initial main-thread\n// work, and then registers the loader without globalPreload\nimport { register } from 'node:module'\nimport { MessageChannel } from 'node:worker_threads'\nimport { getProcessInfo } from './get-process-info.js'\nimport { saveLineLengths } from './line-lengths.js'\nimport { getImportMetaURL } from './get-import-meta-url.js'\nimport {likelyHasSourceMap} from './lookup-sources.js'\n\nconst { port1, port2 } = new MessageChannel()\n\n// must be called eagerly here.\n// this does all the registration as well.\nconst processInfo = getProcessInfo()\nport1.on('message', ({ filename, content, url }) => {\n processInfo.files.push(filename)\n saveLineLengths(filename, content)\n if (url) likelyHasSourceMap(url)\n})\n\nport1.unref()\nport2.unref()\n\nregister(getImportMetaURL(`./loader.mjs`), {\n parentURL: import.meta.url,\n data: { port: port2 },\n transferList: [port2],\n})\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"line-lengths.d.ts","sourceRoot":"","sources":["../../src/line-lengths.ts"],"names":[],"mappings":";AAYA,eAAO,MAAM,eAAe,aAChB,MAAM,YACN,MAAM,GAAG,MAAM,SAiB1B,CAAA;AAED,eAAO,MAAM,cAAc,aAAc,MAAM,yBAG9C,CAAA"}
1
+ {"version":3,"file":"line-lengths.d.ts","sourceRoot":"","sources":["../../src/line-lengths.ts"],"names":[],"mappings":";AAYA,eAAO,MAAM,eAAe,aAChB,MAAM,YACN,MAAM,GAAG,MAAM,SAe1B,CAAA;AAED,eAAO,MAAM,cAAc,aAAc,MAAM,yBAG9C,CAAA"}
@@ -19,11 +19,9 @@ export const saveLineLengths = (filename, content) => {
19
19
  if (cache.has(filename) || !last?.startsWith(sourceMapComment))
20
20
  return;
21
21
  const ll = content
22
- .replace(/[\n\u2028\u2029]$/, '')
23
22
  .split(/\n|\u2028|\u2029/)
24
23
  .map(l => l.length);
25
24
  cache.set(filename, ll);
26
- cache.set(filename, ll);
27
25
  };
28
26
  export const getLineLengths = (filename) => {
29
27
  if (filename.startsWith('file://'))
@@ -1 +1 @@
1
- {"version":3,"file":"line-lengths.js","sourceRoot":"","sources":["../../src/line-lengths.ts"],"names":[],"mappings":"AAAA,wEAAwE;AAExE,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAA;AAEnC,MAAM,IAAI,GAAG,MAAM,CAAC,GAAG,CAAC,qCAAqC,CAAC,CAAA;AAC9D,MAAM,CAAC,GAAG,MAET,CAAA;AACD,MAAM,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,QAAQ,CAAC,CAAA;AAC5B,CAAC,CAAA","sourcesContent":["// TODO: Refactor once https://github.com/nodejs/node/issues/48460 fixed\n\nimport { fileURLToPath } from 'url'\n\nconst kLLC = Symbol.for('@tapjs/processinfo lineLength cache')\nconst g = global as {\n [kLLC]?: Map<string, number[]>\n}\nconst cache = g[kLLC] || new Map<string, number[]>()\ng[kLLC] = cache\n\nconst sourceMapComment = '//# sourceMappingURL='\nexport const saveLineLengths = (\n filename: string,\n content?: string | Buffer\n) => {\n if (content === undefined) return\n if (typeof content === 'object') content = String(content)\n if (filename.startsWith('file://')) filename = fileURLToPath(filename)\n // no need if it's not sourcemapped\n // don't cache an empty array, though, because ts-node files will show\n // up first as source, and then as their built content.\n const last = content.trimEnd().split('\\n').pop()\n if (cache.has(filename) || !last?.startsWith(sourceMapComment)) return\n const ll = content\n .replace(/[\\n\\u2028\\u2029]$/, '')\n .split(/\\n|\\u2028|\\u2029/)\n .map(l => l.length)\n cache.set(filename, ll)\n\n cache.set(filename, ll)\n}\n\nexport const getLineLengths = (filename: string) => {\n if (filename.startsWith('file://')) filename = fileURLToPath(filename)\n return cache.get(filename)\n}\n"]}
1
+ {"version":3,"file":"line-lengths.js","sourceRoot":"","sources":["../../src/line-lengths.ts"],"names":[],"mappings":"AAAA,wEAAwE;AAExE,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAA;AAEnC,MAAM,IAAI,GAAG,MAAM,CAAC,GAAG,CAAC,qCAAqC,CAAC,CAAA;AAC9D,MAAM,CAAC,GAAG,MAET,CAAA;AACD,MAAM,KAAK,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,IAAI,GAAG,EAAoB,CAAA;AACpD,CAAC,CAAC,IAAI,CAAC,GAAG,KAAK,CAAA;AAEf,MAAM,gBAAgB,GAAG,uBAAuB,CAAA;AAChD,MAAM,CAAC,MAAM,eAAe,GAAG,CAC7B,QAAgB,EAChB,OAAyB,EACzB,EAAE;IACF,IAAI,OAAO,KAAK,SAAS;QAAE,OAAM;IACjC,IAAI,OAAO,OAAO,KAAK,QAAQ;QAAE,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,CAAA;IAC1D,IAAI,QAAQ,CAAC,UAAU,CAAC,SAAS,CAAC;QAAE,QAAQ,GAAG,aAAa,CAAC,QAAQ,CAAC,CAAA;IACtE,mCAAmC;IACnC,sEAAsE;IACtE,uDAAuD;IACvD,MAAM,IAAI,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,CAAA;IAChD,IAAI,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,UAAU,CAAC,gBAAgB,CAAC;QAAE,OAAM;IACtE,MAAM,EAAE,GAAG,OAAO;SACf,KAAK,CAAC,kBAAkB,CAAC;SACzB,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAA;IAErB,KAAK,CAAC,GAAG,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAA;AACzB,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,QAAgB,EAAE,EAAE;IACjD,IAAI,QAAQ,CAAC,UAAU,CAAC,SAAS,CAAC;QAAE,QAAQ,GAAG,aAAa,CAAC,QAAQ,CAAC,CAAA;IACtE,OAAO,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;AAC5B,CAAC,CAAA","sourcesContent":["// TODO: Refactor once https://github.com/nodejs/node/issues/48460 fixed\n\nimport { fileURLToPath } from 'url'\n\nconst kLLC = Symbol.for('@tapjs/processinfo lineLength cache')\nconst g = global as {\n [kLLC]?: Map<string, number[]>\n}\nconst cache = g[kLLC] || new Map<string, number[]>()\ng[kLLC] = cache\n\nconst sourceMapComment = '//# sourceMappingURL='\nexport const saveLineLengths = (\n filename: string,\n content?: string | Buffer\n) => {\n if (content === undefined) return\n if (typeof content === 'object') content = String(content)\n if (filename.startsWith('file://')) filename = fileURLToPath(filename)\n // no need if it's not sourcemapped\n // don't cache an empty array, though, because ts-node files will show\n // up first as source, and then as their built content.\n const last = content.trimEnd().split('\\n').pop()\n if (cache.has(filename) || !last?.startsWith(sourceMapComment)) return\n const ll = content\n .split(/\\n|\\u2028|\\u2029/)\n .map(l => l.length)\n\n cache.set(filename, ll)\n}\n\nexport const getLineLengths = (filename: string) => {\n if (filename.startsWith('file://')) filename = fileURLToPath(filename)\n return cache.get(filename)\n}\n"]}
@@ -0,0 +1,6 @@
1
+ export declare const sourcesCache: Map<string, string[]>;
2
+ export declare const loadPendingSourceMaps: () => void;
3
+ export declare const lookupSources: (url: string) => string[] | undefined;
4
+ export declare const getSources: () => Map<string, string[]>;
5
+ export declare const likelyHasSourceMap: (url: string) => void;
6
+ //# sourceMappingURL=lookup-sources.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lookup-sources.d.ts","sourceRoot":"","sources":["../../src/lookup-sources.ts"],"names":[],"mappings":"AAqBA,eAAO,MAAM,YAAY,uBAA8B,CAAA;AAEvD,eAAO,MAAM,qBAAqB,YAgBjC,CAAA;AAED,eAAO,MAAM,aAAa,QAAS,MAAM,yBAA0B,CAAA;AAEnE,eAAO,MAAM,UAAU,6BAGtB,CAAA;AAED,eAAO,MAAM,kBAAkB,QAAS,MAAM,SAG7C,CAAA"}
@@ -0,0 +1,50 @@
1
+ // For some reason that is very mysterious as of the time of writing this,
2
+ // node sporadically will in rare cases hang and fail to gracefully exit if
3
+ // a sufficiently large number of findSourceMap calls are made during the
4
+ // process exit event.
5
+ //
6
+ // However, we cannot look up source maps until *after* the module load
7
+ // event is completely finished and the module is about to be executed,
8
+ // because that is when the source map is added to node's cache.
9
+ //
10
+ // To work around this, every time a module is loaded, we attempt to
11
+ // determine whether it likely has the magic sourceMappingURL comment.
12
+ // If so, then we put it in a list, and at each message, attempt to load
13
+ // the sources for all modules in the list. Then, on process exit, if
14
+ // there's anything still pending that likely has a source map, we only
15
+ // have to look up at most one module (ie, if the last module loaded had a
16
+ // source map), which seems to not trigger the hang.
17
+ import { findSourceMapSafe } from './find-source-map-safe.js';
18
+ // the list of modules that likely have source maps
19
+ const maybeSM = new Set();
20
+ export const sourcesCache = new Map();
21
+ export const loadPendingSourceMaps = () => {
22
+ for (const url of maybeSM) {
23
+ const sm = findSourceMapSafe(url);
24
+ if (sm === false) {
25
+ // can only happen if node found the SM comment, and tried to load it,
26
+ // but got an error creating the sourcemap, because it's invalid or
27
+ // the file is not present. No need to keep trying.
28
+ maybeSM.delete(url);
29
+ }
30
+ else {
31
+ const sources = sm?.payload?.sources;
32
+ if (sources) {
33
+ sourcesCache.set(url, sources);
34
+ maybeSM.delete(url);
35
+ }
36
+ }
37
+ }
38
+ };
39
+ export const lookupSources = (url) => getSources().get(url);
40
+ export const getSources = () => {
41
+ if (maybeSM.size)
42
+ loadPendingSourceMaps();
43
+ return sourcesCache;
44
+ };
45
+ export const likelyHasSourceMap = (url) => {
46
+ if (!sourcesCache.has(url))
47
+ maybeSM.add(url);
48
+ loadPendingSourceMaps();
49
+ };
50
+ //# sourceMappingURL=lookup-sources.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lookup-sources.js","sourceRoot":"","sources":["../../src/lookup-sources.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,2EAA2E;AAC3E,yEAAyE;AACzE,sBAAsB;AACtB,EAAE;AACF,uEAAuE;AACvE,uEAAuE;AACvE,gEAAgE;AAChE,EAAE;AACF,oEAAoE;AACpE,sEAAsE;AACtE,wEAAwE;AACxE,qEAAqE;AACrE,uEAAuE;AACvE,0EAA0E;AAC1E,oDAAoD;AAEpD,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAA;AAE7D,mDAAmD;AACnD,MAAM,OAAO,GAAG,IAAI,GAAG,EAAU,CAAA;AACjC,MAAM,CAAC,MAAM,YAAY,GAAG,IAAI,GAAG,EAAoB,CAAA;AAEvD,MAAM,CAAC,MAAM,qBAAqB,GAAG,GAAG,EAAE;IACxC,KAAK,MAAM,GAAG,IAAI,OAAO,EAAE;QACzB,MAAM,EAAE,GAAG,iBAAiB,CAAC,GAAG,CAAC,CAAA;QACjC,IAAI,EAAE,KAAK,KAAK,EAAE;YAChB,sEAAsE;YACtE,mEAAmE;YACnE,mDAAmD;YACnD,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;SACpB;aAAM;YACL,MAAM,OAAO,GAAG,EAAE,EAAE,OAAO,EAAE,OAAO,CAAA;YACpC,IAAI,OAAO,EAAE;gBACX,YAAY,CAAC,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,CAAA;gBAC9B,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;aACpB;SACF;KACF;AACH,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,GAAW,EAAE,EAAE,CAAC,UAAU,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;AAEnE,MAAM,CAAC,MAAM,UAAU,GAAG,GAAG,EAAE;IAC7B,IAAI,OAAO,CAAC,IAAI;QAAE,qBAAqB,EAAE,CAAA;IACzC,OAAO,YAAY,CAAA;AACrB,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,GAAW,EAAE,EAAE;IAChD,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,GAAG,CAAC;QAAE,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;IAC5C,qBAAqB,EAAE,CAAA;AACzB,CAAC,CAAA","sourcesContent":["// For some reason that is very mysterious as of the time of writing this,\n// node sporadically will in rare cases hang and fail to gracefully exit if\n// a sufficiently large number of findSourceMap calls are made during the\n// process exit event.\n//\n// However, we cannot look up source maps until *after* the module load\n// event is completely finished and the module is about to be executed,\n// because that is when the source map is added to node's cache.\n//\n// To work around this, every time a module is loaded, we attempt to\n// determine whether it likely has the magic sourceMappingURL comment.\n// If so, then we put it in a list, and at each message, attempt to load\n// the sources for all modules in the list. Then, on process exit, if\n// there's anything still pending that likely has a source map, we only\n// have to look up at most one module (ie, if the last module loaded had a\n// source map), which seems to not trigger the hang.\n\nimport { findSourceMapSafe } from './find-source-map-safe.js'\n\n// the list of modules that likely have source maps\nconst maybeSM = new Set<string>()\nexport const sourcesCache = new Map<string, string[]>()\n\nexport const loadPendingSourceMaps = () => {\n for (const url of maybeSM) {\n const sm = findSourceMapSafe(url)\n if (sm === false) {\n // can only happen if node found the SM comment, and tried to load it,\n // but got an error creating the sourcemap, because it's invalid or\n // the file is not present. No need to keep trying.\n maybeSM.delete(url)\n } else {\n const sources = sm?.payload?.sources\n if (sources) {\n sourcesCache.set(url, sources)\n maybeSM.delete(url)\n }\n }\n }\n}\n\nexport const lookupSources = (url: string) => getSources().get(url)\n\nexport const getSources = () => {\n if (maybeSM.size) loadPendingSourceMaps()\n return sourcesCache\n}\n\nexport const likelyHasSourceMap = (url: string) => {\n if (!sourcesCache.has(url)) maybeSM.add(url)\n loadPendingSourceMaps()\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"register-coverage.d.ts","sourceRoot":"","sources":["../../src/register-coverage.ts"],"names":[],"mappings":";AAKA,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;AAOxC,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAA;AAE5D,eAAO,IAAI,OAAO,EAAE,OAAO,GAAG,SAAqB,CAAA;AA+DnD,eAAO,MAAM,QAAQ,YAYpB,CAAA;AAGD,eAAO,MAAM,oBAAoB,QAC1B,MAAM,eACE,mBAAmB,SA2DjC,CAAA"}
1
+ {"version":3,"file":"register-coverage.d.ts","sourceRoot":"","sources":["../../src/register-coverage.ts"],"names":[],"mappings":";AAKA,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;AAQxC,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAA;AAE5D,eAAO,IAAI,OAAO,EAAE,OAAO,GAAG,SAAqB,CAAA;AA6DnD,eAAO,MAAM,QAAQ,YAYpB,CAAA;AAGD,eAAO,MAAM,oBAAoB,QAC1B,MAAM,eACE,mBAAmB,SAmEjC,CAAA"}
@@ -9,6 +9,7 @@ import { fileURLToPath } from 'node:url';
9
9
  import { findSourceMapSafe } from './find-source-map-safe.js';
10
10
  import { getExclude } from './get-exclude.js';
11
11
  import { getLineLengths } from './line-lengths.js';
12
+ import { lookupSources } from './lookup-sources.js';
12
13
  export let SESSION = undefined;
13
14
  // This is a \n delimited list of files to show coverage for
14
15
  // If not set, or empty, then coverage is included for all files
@@ -30,12 +31,10 @@ const uncoveredFiles = cxEnv
30
31
  const exclude = p.env._TAPJS_PROCESSINFO_COV_EXCLUDE_
31
32
  ? getExclude('_TAPJS_PROCESSINFO_COV_EXCLUDE_', false)
32
33
  : undefined;
33
- const fileCovered = (f, s, files = []) => {
34
+ const fileCovered = (f, sources = [], files = []) => {
34
35
  const testFiles = [f];
35
- if (s) {
36
- for (const src of s.sources || []) {
37
- testFiles.push(resolve(src.startsWith('file://') ? fileURLToPath(src) : src));
38
- }
36
+ for (const src of sources || []) {
37
+ testFiles.push(resolve(src.startsWith('file://') ? fileURLToPath(src) : src));
39
38
  }
40
39
  // never include coverage if the file is fully ignored.
41
40
  if (!testFiles.some(f => files.includes(f)))
@@ -103,14 +102,22 @@ export const coverageOnProcessEnd = (cwd, processInfo) => {
103
102
  // see if it has a source map
104
103
  // need to look up via the url, not the file path, because mocks
105
104
  // attach a tapmock search param, which is in node's internal key.
106
- const s = findSourceMapSafe(obj.url);
107
- if (!fileCovered(f, s?.payload, processInfo.files)) {
105
+ const sources = lookupSources(obj.url);
106
+ if (!fileCovered(f, sources, processInfo.files)) {
108
107
  return false;
109
108
  }
109
+ // Most of the time this will be cached at the time of recording, but
110
+ // if it's the last module loaded, or transpiled in-place by ts-node,
111
+ // the sourcemap won't be pre-loaded and will have to be looked up.
112
+ const s = findSourceMapSafe(obj.url);
110
113
  const { payload } = s || { payload: null };
111
114
  if (payload) {
112
115
  sourceMapCache[obj.url] = Object.assign(Object.create(null), {
113
- lineLengths: getLineLengths(f),
116
+ /* c8 ignore start */
117
+ // node's SourceMap objects provide this as of 20.5.0
118
+ //@ts-ignore
119
+ lineLengths: s?.lineLengths || getLineLengths(f),
120
+ /* c8 ignore stop */
114
121
  data: payload,
115
122
  });
116
123
  }
@@ -1 +1 @@
1
- {"version":3,"file":"register-coverage.js","sourceRoot":"","sources":["../../src/register-coverage.ts"],"names":[],"mappings":"AAAA,sDAAsD;AACtD,8DAA8D;AAC9D,MAAM,CAAC,GAAG,OAAO,CAAA;AACjB,MAAM,OAAO,GAAG,CAAC,CAAC,GAAG,CAAC,4BAA4B,KAAK,GAAG,CAAA;AAC1D,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAClD,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;AAExC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AACxC,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAA;AAC7D,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAGlD,MAAM,CAAC,IAAI,OAAO,GAAwB,SAAS,CAAA;AAEnD,4DAA4D;AAC5D,gEAAgE;AAChE,mEAAmE;AACnE,8DAA8D;AAC9D,MAAM,KAAK,GAAG,CAAC,CAAC,GAAG,CAAC,6BAA6B,IAAI,EAAE,CAAA;AACvD,MAAM,YAAY,GAAa,KAAK;KACjC,IAAI,EAAE;KACN,KAAK,CAAC,IAAI,CAAC;KACX,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;AAEnB,uDAAuD;AACvD,oDAAoD;AACpD,qDAAqD;AACrD,MAAM,KAAK,GAAG,CAAC,CAAC,GAAG,CAAC,qC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cAAc,GAKhB,EAAE,CAAA;QACN,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE;YACjB,kBAAkB,EAAE,cAAc;SACnC,CAAC,CAAA;QAEF,GAAG,CAAC,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE;YACnC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE;gBAC3B,OAAO,KAAK,CAAA;aACb;YACD,MAAM,CAAC,GAAG,aAAa,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;YAChC,6BAA6B;YAC7B,gEAAgE;YAChE,kEAAkE;YAClE,MAAM,CAAC,GAAG,iBAAiB,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;YACpC,IAAI,CAAC,WAAW,CAAC,CAAC,EAAE,CAAC,EAAE,OAAO,EAAE,WAAW,CAAC,KAAK,CAAC,EAAE;gBAClD,OAAO,KAAK,CAAA;aACb;YACD,MAAM,EAAE,OAAO,EAAE,GAAG,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,CAAA;YAC1C,IAAI,OAAO,EAAE;gBACX,cAAc,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE;oBAC3D,WAAW,EAAE,cAAc,CAAC,CAAC,CAAC;oBAC9B,IAAI,EAAE,OAAO;iBACd,CAAC,CAAA;aACH;YACD,OAAO,IAAI,CAAA;QACb,CAAC,CAAC,CAAA;QAEF,aAAa,CAAC,CAAC,EAAE,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC,GAAG,IAAI,EAAE,MAAM,CAAC,CAAA;QAC7D,qBAAqB;IACvB,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA;AACD,oBAAoB","sourcesContent":["// start tracking coverage, unless disabled explicltly\n// export so that we know to collect at the end of the process\nconst p = process\nconst enabled = p.env._TAPJS_PROCESSINFO_COVERAGE_ !== '0'\nimport { mkdirSync, writeFileSync } from 'node:fs'\nimport { Session } from 'node:inspector'\nimport { SourceMapPayload } from 'node:module'\nimport { resolve } from 'node:path'\nimport { fileURLToPath } from 'node:url'\nimport { findSourceMapSafe } from './find-source-map-safe.js'\nimport { getExclude } from './get-exclude.js'\nimport { getLineLengths } from './line-lengths.js'\nimport { ProcessInfoNodeData } from './process-info-node.js'\n\nexport let SESSION: Session | undefined = undefined\n\n// This is a \\n delimited list of files to show coverage for\n// If not set, or empty, then coverage is included for all files\n// that pass the exclusion RegExp filter. If included in this list,\n// then coverage will be recorded, even if it matches exclude.\nconst cfEnv = p.env._TAPJS_PROCESSINFO_COV_FILES_ || ''\nconst coveredFiles: string[] = cfEnv\n .trim()\n .split('\\n')\n .filter(f => !!f)\n\n// NB: coverage exclusion is in addition to processinfo\n// exclusion. Only show coverage for a file we care\n// about at least somewhat, but coverage is a subset.\nconst cxEnv = p.env._TAPJS_PROCESSINFO_COV_EXCLUDE_FILES_ || ''\nconst uncoveredFiles: string[] = cxEnv\n .trim()\n .split('\\n')\n .filter(f => !!f)\n\nconst exclude = p.env._TAPJS_PROCESSINFO_COV_EXCLUDE_\n ? getExclude('_TAPJS_PROCESSINFO_COV_EXCLUDE_', false)\n : undefined\n\nconst fileCovered = (\n f: string,\n s?: SourceMapPayload,\n files: string[] = []\n) => {\n const testFiles = [f]\n if (s) {\n for (const src of s.sources || []) {\n testFiles.push(\n resolve(src.startsWith('file://') ? fileURLToPath(src) : src)\n )\n }\n }\n\n // never include coverage if the file is fully ignored.\n if (!testFiles.some(f => files.includes(f))) return false\n\n // if at least one of them are explicitly covered, then include it,\n // otherwise omit if we explicitly listed\n if (coveredFiles.length) {\n return testFiles.some(f => coveredFiles.includes(f))\n }\n\n // if any of the filenames are explicitly excluded, no coverage\n // otherwise, it is covered\n return !testFiles.some(\n f => uncoveredFiles.includes(f) || exclude?.test(f)\n )\n}\n\n// C8 can't see that this function runs, best theory is that it\n// collides with what it's doing with the coverage it's collecting\n// This ignore can possibly be removed once this is being tested\n// with a version of tap that uses this library, but it might just\n// be an unresolveable bootstrap problem.\n// The test does verify that it ran, because otherwise, there would\n// be no coverage, and it verifies that it gets the expected coverage.\n/* c8 ignore start */\nexport const register = () => {\n if (!enabled) return\n p.env._TAPJS_PROCESSINFO_COVERAGE_ = '1'\n\n SESSION = new Session()\n SESSION.connect()\n SESSION.post('Profiler.enable')\n SESSION.post('Runtime.enable')\n SESSION.post('Profiler.startPreciseCoverage', {\n callCount: true,\n detailed: true,\n })\n}\n/* c8 ignore stop */\n\nexport const coverageOnProcessEnd = (\n cwd: string,\n processInfo: ProcessInfoNodeData\n) => {\n // Similar to the coverage tracking bootstrap problem above, c8\n // doesn't see that this function runs, even though it DOES see\n // that the function defined below runs, which is weird.\n /* c8 ignore start */\n if (!SESSION) return\n const session = SESSION\n\n const f = `${cwd}/.tap/coverage/${processInfo.uuid}.json`\n mkdirSync(`${cwd}/.tap/coverage`, { recursive: true })\n\n session.post('Profiler.takePreciseCoverage', (er, cov) => {\n session.post('Profiler.stopPreciseCoverage')\n /* c8 ignore stop */\n\n // something very strange and bad happened\n /* c8 ignore start */\n if (er) {\n throw er\n }\n /* c8 ignore stop */\n\n // Create a source-map-cache that c8 uses in report generation\n const sourceMapCache: {\n [k: string]: {\n lineLengths: number[]\n data: SourceMapPayload\n }\n } = {}\n Object.assign(cov, {\n 'source-map-cache': sourceMapCache,\n })\n\n cov.result = cov.result.filter(obj => {\n if (!/^file:/.test(obj.url)) {\n return false\n }\n const f = fileURLToPath(obj.url)\n // see if it has a source map\n // need to look up via the url, not the file path, because mocks\n // attach a tapmock search param, which is in node's internal key.\n const s = findSourceMapSafe(obj.url)\n if (!fileCovered(f, s?.payload, processInfo.files)) {\n return false\n }\n const { payload } = s || { payload: null }\n if (payload) {\n sourceMapCache[obj.url] = Object.assign(Object.create(null), {\n lineLengths: getLineLengths(f),\n data: payload,\n })\n }\n return true\n })\n\n writeFileSync(f, JSON.stringify(cov, null, 2) + '\\n', 'utf8')\n /* c8 ignore start */\n })\n}\n/* c8 ignore stop */\n"]}
1
+ {"version":3,"file":"register-coverage.js","sourceRoot":"","sources":["../../src/register-coverage.ts"],"names":[],"mappings":"AAAA,sDAAsD;AACtD,8DAA8D;AAC9D,MAAM,CAAC,GAAG,OAAO,CAAA;AACjB,MAAM,OAAO,GAAG,CAAC,CAAC,GAAG,CAAC,4BAA4B,KAAK,GAAG,CAAA;AAC1D,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAClD,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;AAExC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AACxC,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAA;AAC7D,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAGnD,MAAM,CAAC,IAAI,OAAO,GAAwB,SAAS,CAAA;AAEnD,4DAA4D;AAC5D,gEAAgE;AAChE,mEAAmE;AACnE,8DAA8D;AAC9D,MAAM,KAAK,GAAG,CAAC,CAAC,GAAG,CAAC,6BAA6B,IAAI,EAAE,CAAA;AACvD,MAAM,YAAY,GAAa,KAAK;KACjC,IAAI,EAAE;KACN,KAAK,CAAC,IAAI,CAAC;KACX,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;AAEnB,uDAAuD;AACvD,oDAAoD;AACpD,qDAAqD;AACrD,MAAM,KAAK,GAAG,CAAC,CAAC,GAAG,CAAC,qCAAqC,IAAI,EAAE,CAAA;AAC/D,MAAM,cAAc,GAAa,KAAK;KACnC,IAAI,EAAE;KACN,KAA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ourcesContent":["// start tracking coverage, unless disabled explicltly\n// export so that we know to collect at the end of the process\nconst p = process\nconst enabled = p.env._TAPJS_PROCESSINFO_COVERAGE_ !== '0'\nimport { mkdirSync, writeFileSync } from 'node:fs'\nimport { Session } from 'node:inspector'\nimport { SourceMapPayload } from 'node:module'\nimport { resolve } from 'node:path'\nimport { fileURLToPath } from 'node:url'\nimport { findSourceMapSafe } from './find-source-map-safe.js'\nimport { getExclude } from './get-exclude.js'\nimport { getLineLengths } from './line-lengths.js'\nimport { lookupSources } from './lookup-sources.js'\nimport { ProcessInfoNodeData } from './process-info-node.js'\n\nexport let SESSION: Session | undefined = undefined\n\n// This is a \\n delimited list of files to show coverage for\n// If not set, or empty, then coverage is included for all files\n// that pass the exclusion RegExp filter. If included in this list,\n// then coverage will be recorded, even if it matches exclude.\nconst cfEnv = p.env._TAPJS_PROCESSINFO_COV_FILES_ || ''\nconst coveredFiles: string[] = cfEnv\n .trim()\n .split('\\n')\n .filter(f => !!f)\n\n// NB: coverage exclusion is in addition to processinfo\n// exclusion. Only show coverage for a file we care\n// about at least somewhat, but coverage is a subset.\nconst cxEnv = p.env._TAPJS_PROCESSINFO_COV_EXCLUDE_FILES_ || ''\nconst uncoveredFiles: string[] = cxEnv\n .trim()\n .split('\\n')\n .filter(f => !!f)\n\nconst exclude = p.env._TAPJS_PROCESSINFO_COV_EXCLUDE_\n ? getExclude('_TAPJS_PROCESSINFO_COV_EXCLUDE_', false)\n : undefined\n\nconst fileCovered = (\n f: string,\n sources: string[] = [],\n files: string[] = []\n) => {\n const testFiles = [f]\n for (const src of sources || []) {\n testFiles.push(\n resolve(src.startsWith('file://') ? fileURLToPath(src) : src)\n )\n }\n\n // never include coverage if the file is fully ignored.\n if (!testFiles.some(f => files.includes(f))) return false\n\n // if at least one of them are explicitly covered, then include it,\n // otherwise omit if we explicitly listed\n if (coveredFiles.length) {\n return testFiles.some(f => coveredFiles.includes(f))\n }\n\n // if any of the filenames are explicitly excluded, no coverage\n // otherwise, it is covered\n return !testFiles.some(\n f => uncoveredFiles.includes(f) || exclude?.test(f)\n )\n}\n\n// C8 can't see that this function runs, best theory is that it\n// collides with what it's doing with the coverage it's collecting\n// This ignore can possibly be removed once this is being tested\n// with a version of tap that uses this library, but it might just\n// be an unresolveable bootstrap problem.\n// The test does verify that it ran, because otherwise, there would\n// be no coverage, and it verifies that it gets the expected coverage.\n/* c8 ignore start */\nexport const register = () => {\n if (!enabled) return\n p.env._TAPJS_PROCESSINFO_COVERAGE_ = '1'\n\n SESSION = new Session()\n SESSION.connect()\n SESSION.post('Profiler.enable')\n SESSION.post('Runtime.enable')\n SESSION.post('Profiler.startPreciseCoverage', {\n callCount: true,\n detailed: true,\n })\n}\n/* c8 ignore stop */\n\nexport const coverageOnProcessEnd = (\n cwd: string,\n processInfo: ProcessInfoNodeData\n) => {\n // Similar to the coverage tracking bootstrap problem above, c8\n // doesn't see that this function runs, even though it DOES see\n // that the function defined below runs, which is weird.\n /* c8 ignore start */\n if (!SESSION) return\n const session = SESSION\n\n const f = `${cwd}/.tap/coverage/${processInfo.uuid}.json`\n mkdirSync(`${cwd}/.tap/coverage`, { recursive: true })\n\n session.post('Profiler.takePreciseCoverage', (er, cov) => {\n session.post('Profiler.stopPreciseCoverage')\n /* c8 ignore stop */\n\n // something very strange and bad happened\n /* c8 ignore start */\n if (er) {\n throw er\n }\n /* c8 ignore stop */\n\n // Create a source-map-cache that c8 uses in report generation\n const sourceMapCache: {\n [k: string]: {\n lineLengths: number[]\n data: SourceMapPayload\n }\n } = {}\n Object.assign(cov, {\n 'source-map-cache': sourceMapCache,\n })\n\n cov.result = cov.result.filter(obj => {\n if (!/^file:/.test(obj.url)) {\n return false\n }\n const f = fileURLToPath(obj.url)\n // see if it has a source map\n // need to look up via the url, not the file path, because mocks\n // attach a tapmock search param, which is in node's internal key.\n const sources = lookupSources(obj.url)\n if (!fileCovered(f, sources, processInfo.files)) {\n return false\n }\n // Most of the time this will be cached at the time of recording, but\n // if it's the last module loaded, or transpiled in-place by ts-node,\n // the sourcemap won't be pre-loaded and will have to be looked up.\n const s = findSourceMapSafe(obj.url)\n const { payload } = s || { payload: null }\n if (payload) {\n sourceMapCache[obj.url] = Object.assign(Object.create(null), {\n /* c8 ignore start */\n // node's SourceMap objects provide this as of 20.5.0\n //@ts-ignore\n lineLengths: s?.lineLengths || getLineLengths(f),\n /* c8 ignore stop */\n data: payload,\n })\n }\n return true\n })\n\n writeFileSync(f, JSON.stringify(cov, null, 2) + '\\n', 'utf8')\n /* c8 ignore start */\n })\n}\n/* c8 ignore stop */\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"register-process-end.d.ts","sourceRoot":"","sources":["../../src/register-process-end.ts"],"names":[],"mappings":"AAaA,eAAO,MAAM,QAAQ,YA4BpB,CAAA"}
1
+ {"version":3,"file":"register-process-end.d.ts","sourceRoot":"","sources":["../../src/register-process-end.ts"],"names":[],"mappings":"AAaA,eAAO,MAAM,QAAQ,YA0BpB,CAAA"}
@@ -18,9 +18,7 @@ export const register = () => {
18
18
  // try to find the actual sources of the files we loaded
19
19
  // This can't be done up front, because the sourcemap isn't
20
20
  // present during the load phase, since it's in the contents.
21
- for (const file of processInfo.files) {
22
- setSources(file);
23
- }
21
+ setSources(processInfo);
24
22
  processInfo.runtime = runtime[0] * 1e3 + runtime[1] / 1e6;
25
23
  const globalsAdded = Object.keys(global).filter(k => !globals.has(k));
26
24
  if (globalsAdded.length) {
@@ -1 +1 @@
1
- {"version":3,"file":"register-process-end.js","sourceRoot":"","sources":["../../src/register-process-end.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAEtD,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,IAAI,CAAA;AAC7C,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAA;AAC7D,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CA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,CAAC,GAAG,GAAG,GAAG,qBAAqB,WAAW,CAAC,IAAI,OAAO,CAAA;QAC5D,SAAS,CAAC,GAAG,GAAG,mBAAmB,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAA;QACzD,aAAa,CAAC,CAAC,EAAE,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE,IAAI,EAAE,CAAC,CAAC,GAAG,IAAI,EAAE,MAAM,CAAC,CAAA;QACrE,oBAAoB,CAAC,GAAG,EAAE,WAAW,CAAC,CAAA;IACxC,CAAC,EACD,EAAE,UAAU,EAAE,IAAI,EAAE,CACrB,CAAA;AACH,CAAC,CAAA","sourcesContent":["import { onExit } from 'signal-exit'\nimport { getProcessInfo } from './get-process-info.js'\n\nimport { mkdirSync, writeFileSync } from 'fs'\nimport { coverageOnProcessEnd } from './register-coverage.js'\nimport { setSources } from './set-sources.js'\n\nconst proc = process\n\nconst cwd = proc.env._TAPJS_PROCESSINFO_CWD_ || proc.cwd()\nproc.env._TAPJS_PROCESSINFO_CWD_ = cwd\nconst globals = new Set(Object.keys(global))\n\nexport const register = () => {\n onExit(\n (code, signal) => {\n const processInfo = getProcessInfo()\n processInfo.code = code\n processInfo.signal = signal\n const runtime = proc.hrtime(processInfo.hrstart)\n delete processInfo.hrstart\n processInfo.files = [...new Set(processInfo.files)]\n // try to find the actual sources of the files we loaded\n // This can't be done up front, because the sourcemap isn't\n // present during the load phase, since it's in the contents.\n for (const file of processInfo.files) {\n setSources(file)\n }\n processInfo.runtime = runtime[0] * 1e3 + runtime[1] / 1e6\n const globalsAdded = Object.keys(global).filter(k => !globals.has(k))\n if (globalsAdded.length) {\n processInfo.globalsAdded = globalsAdded\n }\n\n const f = `${cwd}/.tap/processinfo/${processInfo.uuid}.json`\n mkdirSync(`${cwd}/.tap/processinfo`, { recursive: true })\n writeFileSync(f, JSON.stringify(processInfo, null, 2) + '\\n', 'utf8')\n coverageOnProcessEnd(cwd, processInfo)\n },\n { alwaysLast: true }\n )\n}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C,CAAC,CAAC,GAAG,GAAG,CAAA;QACzD,MAAM,YAAY,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAA;QACrE,IAAI,YAAY,CAAC,MAAM,EAAE;YACvB,WAAW,CAAC,YAAY,GAAG,YAAY,CAAA;SACxC;QAED,MAAM,CAAC,GAAG,GAAG,GAAG,qBAAqB,WAAW,CAAC,IAAI,OAAO,CAAA;QAC5D,SAAS,CAAC,GAAG,GAAG,mBAAmB,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAA;QACzD,aAAa,CAAC,CAAC,EAAE,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE,IAAI,EAAE,CAAC,CAAC,GAAG,IAAI,EAAE,MAAM,CAAC,CAAA;QACrE,oBAAoB,CAAC,GAAG,EAAE,WAAW,CAAC,CAAA;IACxC,CAAC,EACD,EAAE,UAAU,EAAE,IAAI,EAAE,CACrB,CAAA;AACH,CAAC,CAAA","sourcesContent":["import { onExit } from 'signal-exit'\nimport { getProcessInfo } from './get-process-info.js'\n\nimport { mkdirSync, writeFileSync } from 'fs'\nimport { coverageOnProcessEnd } from './register-coverage.js'\nimport { setSources } from './set-sources.js'\n\nconst proc = process\n\nconst cwd = proc.env._TAPJS_PROCESSINFO_CWD_ || proc.cwd()\nproc.env._TAPJS_PROCESSINFO_CWD_ = cwd\nconst globals = new Set(Object.keys(global))\n\nexport const register = () => {\n onExit(\n (code, signal) => {\n const processInfo = getProcessInfo()\n processInfo.code = code\n processInfo.signal = signal\n const runtime = proc.hrtime(processInfo.hrstart)\n delete processInfo.hrstart\n processInfo.files = [...new Set(processInfo.files)]\n // try to find the actual sources of the files we loaded\n // This can't be done up front, because the sourcemap isn't\n // present during the load phase, since it's in the contents.\n setSources(processInfo)\n processInfo.runtime = runtime[0] * 1e3 + runtime[1] / 1e6\n const globalsAdded = Object.keys(global).filter(k => !globals.has(k))\n if (globalsAdded.length) {\n processInfo.globalsAdded = globalsAdded\n }\n\n const f = `${cwd}/.tap/processinfo/${processInfo.uuid}.json`\n mkdirSync(`${cwd}/.tap/processinfo`, { recursive: true })\n writeFileSync(f, JSON.stringify(processInfo, null, 2) + '\\n', 'utf8')\n coverageOnProcessEnd(cwd, processInfo)\n },\n { alwaysLast: true }\n )\n}\n"]}
@@ -1,2 +1,3 @@
1
- export declare const setSources: (file: string) => void;
1
+ import { ProcessInfoNodeData } from './index.js';
2
+ export declare const setSources: (pi: ProcessInfoNodeData) => void;
2
3
  //# sourceMappingURL=set-sources.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"set-sources.d.ts","sourceRoot":"","sources":["../../src/set-sources.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,UAAU,SAAU,MAAM,SAOtC,CAAA"}
1
+ {"version":3,"file":"set-sources.d.ts","sourceRoot":"","sources":["../../src/set-sources.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAShD,eAAO,MAAM,UAAU,OAAQ,mBAAmB,SAQjD,CAAA"}
@@ -1,16 +1,17 @@
1
- import { findSourceMapSafe } from './find-source-map-safe.js';
2
- import { getProcessInfo } from './get-process-info.js';
1
+ import { fileURLToPath } from 'url';
2
+ import { getSources } from './lookup-sources.js';
3
3
  import { urlToPath } from './url-to-path.js';
4
+ let sourcesCache;
4
5
  // set the processInfo.sources for a given file, but don't clobber
5
6
  // if called multiple times, or create duplicate entries.
6
7
  // Should only be called *after* the file in question has been loaded.
7
- export const setSources = (file) => {
8
- const sm = findSourceMapSafe(file);
9
- if (!sm)
10
- return;
11
- const pi = getProcessInfo();
12
- const s = pi.sources[file] || [];
13
- s.push(...sm.payload.sources.map(s => urlToPath(s)));
14
- pi.sources[file] = [...new Set(s)];
8
+ export const setSources = (pi) => {
9
+ sourcesCache ??= getSources();
10
+ for (const [url, sources] of sourcesCache.entries()) {
11
+ const file = fileURLToPath(url);
12
+ const s = pi.sources[file] || [];
13
+ s.push(...sources.map(s => urlToPath(s)));
14
+ pi.sources[file] = [...new Set(s)];
15
+ }
15
16
  };
16
17
  //# sourceMappingURL=set-sources.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"set-sources.js","sourceRoot":"","sources":["../../src/set-sources.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAA;AAC7D,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AACtD,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAE5C,kEAAkE;AAClE,yDAAyD;AACzD,sEAAsE;AACtE,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,IAAY,EAAE,EAAE;IACzC,MAAM,EAAE,GAAG,iBAAiB,CAAC,IAAI,CAAC,CAAA;IAClC,IAAI,CAAC,EAAE;QAAE,OAAM;IACf,MAAM,EAAE,GAAG,cAAc,EAAE,CAAA;IAC3B,MAAM,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,CAAA;IAChC,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;IACpD,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,CAAA;AACpC,CAAC,CAAA","sourcesContent":["import { findSourceMapSafe } from './find-source-map-safe.js'\nimport { getProcessInfo } from './get-process-info.js'\nimport { urlToPath } from './url-to-path.js'\n\n// set the processInfo.sources for a given file, but don't clobber\n// if called multiple times, or create duplicate entries.\n// Should only be called *after* the file in question has been loaded.\nexport const setSources = (file: string) => {\n const sm = findSourceMapSafe(file)\n if (!sm) return\n const pi = getProcessInfo()\n const s = pi.sources[file] || []\n s.push(...sm.payload.sources.map(s => urlToPath(s)))\n pi.sources[file] = [...new Set(s)]\n}\n"]}
1
+ {"version":3,"file":"set-sources.js","sourceRoot":"","sources":["../../src/set-sources.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAA;AAEnC,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAE5C,IAAI,YAAmC,CAAA;AAEvC,kEAAkE;AAClE,yDAAyD;AACzD,sEAAsE;AACtE,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,EAAuB,EAAE,EAAE;IACpD,YAAY,KAAK,UAAU,EAAE,CAAA;IAC7B,KAAK,MAAM,CAAC,GAAG,EAAE,OAAO,CAAC,IAAI,YAAY,CAAC,OAAO,EAAE,EAAE;QACnD,MAAM,IAAI,GAAG,aAAa,CAAC,GAAG,CAAC,CAAA;QAC/B,MAAM,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,CAAA;QAChC,CAAC,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;QACzC,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,CAAA;KACnC;AACH,CAAC,CAAA","sourcesContent":["import { fileURLToPath } from 'url'\nimport { ProcessInfoNodeData } from './index.js'\nimport { getSources } from './lookup-sources.js'\nimport { urlToPath } from './url-to-path.js'\n\nlet sourcesCache: Map<string, string[]>\n\n// set the processInfo.sources for a given file, but don't clobber\n// if called multiple times, or create duplicate entries.\n// Should only be called *after* the file in question has been loaded.\nexport const setSources = (pi: ProcessInfoNodeData) => {\n sourcesCache ??= getSources()\n for (const [url, sources] of sourcesCache.entries()) {\n const file = fileURLToPath(url)\n const s = pi.sources[file] || []\n s.push(...sources.map(s => urlToPath(s)))\n pi.sources[file] = [...new Set(s)]\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tapjs/processinfo",
3
- "version": "3.1.3",
3
+ "version": "3.1.4",
4
4
  "files": [
5
5
  "dist"
6
6
  ],
@@ -9,6 +9,7 @@
9
9
  "types": "./dist/commonjs/index.d.ts",
10
10
  "tshy": {
11
11
  "main": true,
12
+ "selfLink": false,
12
13
  "exports": {
13
14
  ".": "./src/index.ts",
14
15
  "./loader": "./src/loader-legacy.mts",
@@ -50,7 +51,7 @@
50
51
  "test": "c8 tap",
51
52
  "snap": "c8 tap",
52
53
  "format": "prettier --write . --loglevel warn",
53
- "typedoc": "typedoc --tsconfig .tshy/esm.json ./lib/*.*ts"
54
+ "typedoc": "typedoc --tsconfig .tshy/esm.json ./src/*.ts ./src/*.mts"
54
55
  },
55
56
  "tap": {
56
57
  "coverage": false,