@tapjs/processinfo 3.1.4 → 3.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commonjs/canonical-source.d.ts +3 -0
- package/dist/commonjs/canonical-source.d.ts.map +1 -0
- package/dist/commonjs/canonical-source.js +38 -0
- package/dist/commonjs/canonical-source.js.map +1 -0
- package/dist/commonjs/find-source-map-safe.d.ts.map +1 -1
- package/dist/commonjs/find-source-map-safe.js +3 -0
- package/dist/commonjs/find-source-map-safe.js.map +1 -1
- package/dist/commonjs/line-lengths.d.ts.map +1 -1
- package/dist/commonjs/line-lengths.js +1 -3
- package/dist/commonjs/line-lengths.js.map +1 -1
- package/dist/commonjs/lookup-sources.d.ts +2 -2
- package/dist/commonjs/lookup-sources.d.ts.map +1 -1
- package/dist/commonjs/lookup-sources.js +10 -3
- package/dist/commonjs/lookup-sources.js.map +1 -1
- package/dist/commonjs/register-coverage.d.ts.map +1 -1
- package/dist/commonjs/register-coverage.js +10 -4
- package/dist/commonjs/register-coverage.js.map +1 -1
- package/dist/esm/canonical-source.d.ts +3 -0
- package/dist/esm/canonical-source.d.ts.map +1 -0
- package/dist/esm/canonical-source.js +33 -0
- package/dist/esm/canonical-source.js.map +1 -0
- package/dist/esm/find-source-map-safe.d.ts.map +1 -1
- package/dist/esm/find-source-map-safe.js +3 -0
- package/dist/esm/find-source-map-safe.js.map +1 -1
- package/dist/esm/import.mjs +1 -1
- package/dist/esm/import.mjs.map +1 -1
- package/dist/esm/line-lengths.d.ts.map +1 -1
- package/dist/esm/line-lengths.js +1 -3
- package/dist/esm/line-lengths.js.map +1 -1
- package/dist/esm/lookup-sources.d.ts +2 -2
- package/dist/esm/lookup-sources.d.ts.map +1 -1
- package/dist/esm/lookup-sources.js +10 -3
- package/dist/esm/lookup-sources.js.map +1 -1
- package/dist/esm/register-coverage.d.ts.map +1 -1
- package/dist/esm/register-coverage.js +10 -4
- package/dist/esm/register-coverage.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"canonical-source.d.ts","sourceRoot":"","sources":["../../src/canonical-source.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,eAAe,MAAO,MAAM,KAAG,MAY3C,CAAA;AAED,eAAO,MAAM,aAAa,MAAO,MAAM,KAAG,MAUzC,CAAA"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// The sources reported in sourcemaps can be fickle,
|
|
3
|
+
// and istanbul's reporting doesn't handle it so well.
|
|
4
|
+
// So, we canonicalize all entries in sources to a file://
|
|
5
|
+
// url with consistent capitalization.
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.canonicalPath = exports.canonicalSource = void 0;
|
|
8
|
+
const path_1 = require("path");
|
|
9
|
+
const url_1 = require("url");
|
|
10
|
+
const cwd = process.cwd();
|
|
11
|
+
const canonicalSource = (s) => {
|
|
12
|
+
// convert to a path
|
|
13
|
+
if (s.startsWith('file://')) {
|
|
14
|
+
const u = new URL(s);
|
|
15
|
+
const hash = u.hash;
|
|
16
|
+
const search = u.search;
|
|
17
|
+
return String((0, url_1.pathToFileURL)((0, exports.canonicalPath)((0, url_1.fileURLToPath)(s)))) +
|
|
18
|
+
hash + search;
|
|
19
|
+
}
|
|
20
|
+
// re-resolve it relative to the cwd
|
|
21
|
+
// back to a file: url
|
|
22
|
+
return String((0, url_1.pathToFileURL)((0, exports.canonicalPath)(s)));
|
|
23
|
+
};
|
|
24
|
+
exports.canonicalSource = canonicalSource;
|
|
25
|
+
const canonicalPath = (s) => {
|
|
26
|
+
const rel = (0, path_1.relative)(cwd, s);
|
|
27
|
+
s = (0, path_1.resolve)(cwd, rel);
|
|
28
|
+
// capitalize drive letters
|
|
29
|
+
if (/^[a-z]:/.test(s))
|
|
30
|
+
s = s.charAt(0).toUpperCase() + s.substring(1);
|
|
31
|
+
// capitalize UNC paths
|
|
32
|
+
if (s.startsWith('\\\\')) {
|
|
33
|
+
s = s.replace(/\\\\[^\\]+\\[^\\]+\\/, _0 => _0.toUpperCase());
|
|
34
|
+
}
|
|
35
|
+
return s;
|
|
36
|
+
};
|
|
37
|
+
exports.canonicalPath = canonicalPath;
|
|
38
|
+
//# sourceMappingURL=canonical-source.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"canonical-source.js","sourceRoot":"","sources":["../../src/canonical-source.ts"],"names":[],"mappings":";AAAA,oDAAoD;AACpD,sDAAsD;AACtD,0DAA0D;AAC1D,sCAAsC;;;AAEtC,+BAAwC;AACxC,6BAAkD;AAClD,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE,CAAA;AAElB,MAAM,eAAe,GAAG,CAAC,CAAS,EAAU,EAAE;IACnD,oBAAoB;IACpB,IAAI,CAAC,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE;QAC3B,MAAM,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,CAAC,CAAA;QACpB,MAAM,IAAI,GAAG,CAAC,CAAC,IAAI,CAAA;QACnB,MAAM,MAAM,GAAG,CAAC,CAAC,MAAM,CAAA;QACvB,OAAO,MAAM,CAAC,IAAA,mBAAa,EAAC,IAAA,qBAAa,EAAC,IAAA,mBAAa,EAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YAC3D,IAAI,GAAG,MAAM,CAAA;KAChB;IACD,oCAAoC;IACpC,sBAAsB;IACtB,OAAO,MAAM,CAAC,IAAA,mBAAa,EAAC,IAAA,qBAAa,EAAC,CAAC,CAAC,CAAC,CAAC,CAAA;AAChD,CAAC,CAAA;AAZY,QAAA,eAAe,mBAY3B;AAEM,MAAM,aAAa,GAAG,CAAC,CAAS,EAAU,EAAE;IACjD,MAAM,GAAG,GAAG,IAAA,eAAQ,EAAC,GAAG,EAAE,CAAC,CAAC,CAAA;IAC5B,CAAC,GAAG,IAAA,cAAO,EAAC,GAAG,EAAE,GAAG,CAAC,CAAA;IACrB,2BAA2B;IAC3B,IAAI,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;QAAE,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAA;IACrE,uBAAuB;IACvB,IAAI,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE;QACxB,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,sBAAsB,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,WAAW,EAAE,CAAC,CAAA;KAC9D;IACD,OAAO,CAAC,CAAA;AACV,CAAC,CAAA;AAVY,QAAA,aAAa,iBAUzB","sourcesContent":["// The sources reported in sourcemaps can be fickle,\n// and istanbul's reporting doesn't handle it so well.\n// So, we canonicalize all entries in sources to a file://\n// url with consistent capitalization.\n\nimport { relative, resolve } from 'path'\nimport { fileURLToPath, pathToFileURL } from 'url'\nconst cwd = process.cwd()\n\nexport const canonicalSource = (s: string): string => {\n // convert to a path\n if (s.startsWith('file://')) {\n const u = new URL(s)\n const hash = u.hash\n const search = u.search\n return String(pathToFileURL(canonicalPath(fileURLToPath(s)))) +\n hash + search\n }\n // re-resolve it relative to the cwd\n // back to a file: url\n return String(pathToFileURL(canonicalPath(s)))\n}\n\nexport const canonicalPath = (s: string): string => {\n const rel = relative(cwd, s)\n s = resolve(cwd, rel)\n // capitalize drive letters\n if (/^[a-z]:/.test(s)) s = s.charAt(0).toUpperCase() + s.substring(1)\n // capitalize UNC paths\n if (s.startsWith('\\\\\\\\')) {\n s = s.replace(/\\\\\\\\[^\\\\]+\\\\[^\\\\]+\\\\/, _0 => _0.toUpperCase())\n }\n return s\n}\n"]}
|
|
@@ -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,MACzB,MAAM,GAAG,GAAG,KACd,KAAK,GAAG,SAAS,GAAG,
|
|
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,SAkBtB,CAAA"}
|
|
@@ -17,10 +17,13 @@ const findSourceMapSafe = (s) => {
|
|
|
17
17
|
if (sm)
|
|
18
18
|
sourceMaps.set(mod, sm);
|
|
19
19
|
return sm;
|
|
20
|
+
// only throws on node 20
|
|
21
|
+
/* c8 ignore start */
|
|
20
22
|
}
|
|
21
23
|
catch {
|
|
22
24
|
return false;
|
|
23
25
|
}
|
|
26
|
+
/* c8 ignore stop */
|
|
24
27
|
};
|
|
25
28
|
exports.findSourceMapSafe = findSourceMapSafe;
|
|
26
29
|
//# 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,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;
|
|
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;QACT,yBAAyB;QACzB,qBAAqB;KACtB;IAAC,MAAM;QACN,OAAO,KAAK,CAAA;KACb;IACD,oBAAoB;AACtB,CAAC,CAAA;AApBY,QAAA,iBAAiB,qBAoB7B","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 // only throws on node 20\n /* c8 ignore start */\n } catch {\n return false\n }\n /* c8 ignore stop */\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,
|
|
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,SAa1B,CAAA;AAED,eAAO,MAAM,cAAc,aAAc,MAAM,yBAG9C,CAAA"}
|
|
@@ -21,9 +21,7 @@ const saveLineLengths = (filename, content) => {
|
|
|
21
21
|
const last = content.trimEnd().split('\n').pop();
|
|
22
22
|
if (cache.has(filename) || !last?.startsWith(sourceMapComment))
|
|
23
23
|
return;
|
|
24
|
-
const ll = content
|
|
25
|
-
.split(/\n|\u2028|\u2029/)
|
|
26
|
-
.map(l => l.length);
|
|
24
|
+
const ll = content.split(/\n|\u2028|\u2029/).map(l => l.length);
|
|
27
25
|
cache.set(filename, ll);
|
|
28
26
|
};
|
|
29
27
|
exports.saveLineLengths = saveLineLengths;
|
|
@@ -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,O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AO,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,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAA;IAE/D,KAAK,CAAC,GAAG,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAA;AACzB,CAAC,CAAA;AAfY,QAAA,eAAe,mBAe3B;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.split(/\\n|\\u2028|\\u2029/).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"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export declare const sourcesCache: Map<string, string[]>;
|
|
2
2
|
export declare const loadPendingSourceMaps: () => void;
|
|
3
|
-
export declare const lookupSources: (url: string) => string[] | undefined;
|
|
4
|
-
export declare const getSources: () => Map<string, string[]>;
|
|
3
|
+
export declare const lookupSources: (url: string, processEnd?: boolean) => string[] | undefined;
|
|
4
|
+
export declare const getSources: (processEnd?: boolean) => Map<string, string[]>;
|
|
5
5
|
export declare const likelyHasSourceMap: (url: string) => void;
|
|
6
6
|
//# sourceMappingURL=lookup-sources.d.ts.map
|
|
@@ -1 +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,
|
|
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,YAmBjC,CAAA;AAED,eAAO,MAAM,aAAa,QAAS,MAAM,eAAe,OAAO,yBAC9B,CAAA;AAGjC,eAAO,MAAM,UAAU,gBAAgB,OAAO,0BAM7C,CAAA;AAED,eAAO,MAAM,kBAAkB,QAAS,MAAM,SAG7C,CAAA"}
|
|
@@ -24,6 +24,8 @@ exports.sourcesCache = new Map();
|
|
|
24
24
|
const loadPendingSourceMaps = () => {
|
|
25
25
|
for (const url of maybeSM) {
|
|
26
26
|
const sm = (0, find_source_map_safe_js_1.findSourceMapSafe)(url);
|
|
27
|
+
// only possible on node 19+
|
|
28
|
+
/* c8 ignore start */
|
|
27
29
|
if (sm === false) {
|
|
28
30
|
// can only happen if node found the SM comment, and tried to load it,
|
|
29
31
|
// but got an error creating the sourcemap, because it's invalid or
|
|
@@ -31,6 +33,7 @@ const loadPendingSourceMaps = () => {
|
|
|
31
33
|
maybeSM.delete(url);
|
|
32
34
|
}
|
|
33
35
|
else {
|
|
36
|
+
/* c8 ignore stop */
|
|
34
37
|
const sources = sm?.payload?.sources;
|
|
35
38
|
if (sources) {
|
|
36
39
|
exports.sourcesCache.set(url, sources);
|
|
@@ -40,11 +43,15 @@ const loadPendingSourceMaps = () => {
|
|
|
40
43
|
}
|
|
41
44
|
};
|
|
42
45
|
exports.loadPendingSourceMaps = loadPendingSourceMaps;
|
|
43
|
-
const lookupSources = (url) => (0, exports.getSources)().get(url);
|
|
46
|
+
const lookupSources = (url, processEnd) => (0, exports.getSources)(processEnd).get(url);
|
|
44
47
|
exports.lookupSources = lookupSources;
|
|
45
|
-
|
|
46
|
-
|
|
48
|
+
let didFinalLookupAttempt = false;
|
|
49
|
+
const getSources = (processEnd = false) => {
|
|
50
|
+
if (maybeSM.size && (!processEnd || !didFinalLookupAttempt)) {
|
|
51
|
+
if (processEnd)
|
|
52
|
+
didFinalLookupAttempt = true;
|
|
47
53
|
(0, exports.loadPendingSourceMaps)();
|
|
54
|
+
}
|
|
48
55
|
return exports.sourcesCache;
|
|
49
56
|
};
|
|
50
57
|
exports.getSources = getSources;
|
|
@@ -1 +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,GA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mD;YACnD,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;SACpB;aAAM;YACL,oBAAoB;YACpB,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;AAnBY,QAAA,qBAAqB,yBAmBjC;AAEM,MAAM,aAAa,GAAG,CAAC,GAAW,EAAE,UAAoB,EAAE,EAAE,CACjE,IAAA,kBAAU,EAAC,UAAU,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;AADpB,QAAA,aAAa,iBACO;AAEjC,IAAI,qBAAqB,GAAG,KAAK,CAAA;AAC1B,MAAM,UAAU,GAAG,CAAC,aAAsB,KAAK,EAAE,EAAE;IACxD,IAAI,OAAO,CAAC,IAAI,IAAI,CAAC,CAAC,UAAU,IAAI,CAAC,qBAAqB,CAAC,EAAE;QAC3D,IAAI,UAAU;YAAE,qBAAqB,GAAG,IAAI,CAAA;QAC5C,IAAA,6BAAqB,GAAE,CAAA;KACxB;IACD,OAAO,oBAAY,CAAA;AACrB,CAAC,CAAA;AANY,QAAA,UAAU,cAMtB;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 // only possible on node 19+\n /* c8 ignore start */\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 /* c8 ignore stop */\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, processEnd?: boolean) =>\n getSources(processEnd).get(url)\n\nlet didFinalLookupAttempt = false\nexport const getSources = (processEnd: boolean = false) => {\n if (maybeSM.size && (!processEnd || !didFinalLookupAttempt)) {\n if (processEnd) didFinalLookupAttempt = true\n loadPendingSourceMaps()\n }\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;
|
|
1
|
+
{"version":3,"file":"register-coverage.d.ts","sourceRoot":"","sources":["../../src/register-coverage.ts"],"names":[],"mappings":";AAKA,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;AASxC,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,SAuEjC,CAAA"}
|
|
@@ -9,6 +9,7 @@ const node_fs_1 = require("node:fs");
|
|
|
9
9
|
const node_inspector_1 = require("node:inspector");
|
|
10
10
|
const node_path_1 = require("node:path");
|
|
11
11
|
const node_url_1 = require("node:url");
|
|
12
|
+
const canonical_source_js_1 = require("./canonical-source.js");
|
|
12
13
|
const find_source_map_safe_js_1 = require("./find-source-map-safe.js");
|
|
13
14
|
const get_exclude_js_1 = require("./get-exclude.js");
|
|
14
15
|
const line_lengths_js_1 = require("./line-lengths.js");
|
|
@@ -33,15 +34,16 @@ const uncoveredFiles = cxEnv
|
|
|
33
34
|
.filter(f => !!f);
|
|
34
35
|
const exclude = p.env._TAPJS_PROCESSINFO_COV_EXCLUDE_
|
|
35
36
|
? (0, get_exclude_js_1.getExclude)('_TAPJS_PROCESSINFO_COV_EXCLUDE_', false)
|
|
36
|
-
:
|
|
37
|
+
: /[\\\/]node_modules[\\\/]/;
|
|
37
38
|
const fileCovered = (f, sources = [], files = []) => {
|
|
38
39
|
const testFiles = [f];
|
|
39
40
|
for (const src of sources || []) {
|
|
40
41
|
testFiles.push((0, node_path_1.resolve)(src.startsWith('file://') ? (0, node_url_1.fileURLToPath)(src) : src));
|
|
41
42
|
}
|
|
42
43
|
// never include coverage if the file is fully ignored.
|
|
43
|
-
if (!testFiles.some(f => files.includes(f)))
|
|
44
|
+
if (!testFiles.some(f => files.includes(f))) {
|
|
44
45
|
return false;
|
|
46
|
+
}
|
|
45
47
|
// if at least one of them are explicitly covered, then include it,
|
|
46
48
|
// otherwise omit if we explicitly listed
|
|
47
49
|
if (coveredFiles.length) {
|
|
@@ -102,11 +104,12 @@ const coverageOnProcessEnd = (cwd, processInfo) => {
|
|
|
102
104
|
if (!/^file:/.test(obj.url)) {
|
|
103
105
|
return false;
|
|
104
106
|
}
|
|
107
|
+
obj.url = (0, canonical_source_js_1.canonicalSource)(obj.url);
|
|
105
108
|
const f = (0, node_url_1.fileURLToPath)(obj.url);
|
|
106
109
|
// see if it has a source map
|
|
107
110
|
// need to look up via the url, not the file path, because mocks
|
|
108
111
|
// attach a tapmock search param, which is in node's internal key.
|
|
109
|
-
const sources = (0, lookup_sources_js_1.lookupSources)(obj.url);
|
|
112
|
+
const sources = (0, lookup_sources_js_1.lookupSources)(obj.url, true);
|
|
110
113
|
if (!fileCovered(f, sources, processInfo.files)) {
|
|
111
114
|
return false;
|
|
112
115
|
}
|
|
@@ -122,7 +125,10 @@ const coverageOnProcessEnd = (cwd, processInfo) => {
|
|
|
122
125
|
//@ts-ignore
|
|
123
126
|
lineLengths: s?.lineLengths || (0, line_lengths_js_1.getLineLengths)(f),
|
|
124
127
|
/* c8 ignore stop */
|
|
125
|
-
data:
|
|
128
|
+
data: {
|
|
129
|
+
...payload,
|
|
130
|
+
sources: payload.sources?.map(s => (0, canonical_source_js_1.canonicalSource)(s)),
|
|
131
|
+
},
|
|
126
132
|
});
|
|
127
133
|
}
|
|
128
134
|
return true;
|
|
@@ -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;AAClD,2DAAmD;AAGxC,QAAA,OAAO,GAAwB,SAAS,CAAA;AAEnD,4DAA4D;AAC5D,gEAAgE;AAChE,mEAAmE;AACnE,8DAA8D;AAC9D,MAAM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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
|
+
{"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,+DAAuD;AACvD,uEAA6D;AAC7D,qDAA6C;AAC7C,uDAAkD;AAClD,2DAAmD;AAGxC,QAAA,OAAO,GAAwB,SAAS,CAA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AAE,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;wBACJ,GAAG,OAAO;wBACV,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,IAAA,qCAAe,EAAC,CAAC,CAAC,CAAC;qBACvD;iBACF,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;AAzEY,QAAA,oBAAoB,wBAyEhC;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 { canonicalSource } from './canonical-source.js'\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 : /[\\\\\\/]node_modules[\\\\\\/]/\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))) {\n return false\n }\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 obj.url = canonicalSource(obj.url)\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, true)\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: {\n ...payload,\n sources: payload.sources?.map(s => canonicalSource(s)),\n },\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"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"canonical-source.d.ts","sourceRoot":"","sources":["../../src/canonical-source.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,eAAe,MAAO,MAAM,KAAG,MAY3C,CAAA;AAED,eAAO,MAAM,aAAa,MAAO,MAAM,KAAG,MAUzC,CAAA"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// The sources reported in sourcemaps can be fickle,
|
|
2
|
+
// and istanbul's reporting doesn't handle it so well.
|
|
3
|
+
// So, we canonicalize all entries in sources to a file://
|
|
4
|
+
// url with consistent capitalization.
|
|
5
|
+
import { relative, resolve } from 'path';
|
|
6
|
+
import { fileURLToPath, pathToFileURL } from 'url';
|
|
7
|
+
const cwd = process.cwd();
|
|
8
|
+
export const canonicalSource = (s) => {
|
|
9
|
+
// convert to a path
|
|
10
|
+
if (s.startsWith('file://')) {
|
|
11
|
+
const u = new URL(s);
|
|
12
|
+
const hash = u.hash;
|
|
13
|
+
const search = u.search;
|
|
14
|
+
return String(pathToFileURL(canonicalPath(fileURLToPath(s)))) +
|
|
15
|
+
hash + search;
|
|
16
|
+
}
|
|
17
|
+
// re-resolve it relative to the cwd
|
|
18
|
+
// back to a file: url
|
|
19
|
+
return String(pathToFileURL(canonicalPath(s)));
|
|
20
|
+
};
|
|
21
|
+
export const canonicalPath = (s) => {
|
|
22
|
+
const rel = relative(cwd, s);
|
|
23
|
+
s = resolve(cwd, rel);
|
|
24
|
+
// capitalize drive letters
|
|
25
|
+
if (/^[a-z]:/.test(s))
|
|
26
|
+
s = s.charAt(0).toUpperCase() + s.substring(1);
|
|
27
|
+
// capitalize UNC paths
|
|
28
|
+
if (s.startsWith('\\\\')) {
|
|
29
|
+
s = s.replace(/\\\\[^\\]+\\[^\\]+\\/, _0 => _0.toUpperCase());
|
|
30
|
+
}
|
|
31
|
+
return s;
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=canonical-source.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"canonical-source.js","sourceRoot":"","sources":["../../src/canonical-source.ts"],"names":[],"mappings":"AAAA,oDAAoD;AACpD,sDAAsD;AACtD,0DAA0D;AAC1D,sCAAsC;AAEtC,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AACxC,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,KAAK,CAAA;AAClD,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE,CAAA;AAEzB,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,CAAS,EAAU,EAAE;IACnD,oBAAoB;IACpB,IAAI,CAAC,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE;QAC3B,MAAM,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,CAAC,CAAA;QACpB,MAAM,IAAI,GAAG,CAAC,CAAC,IAAI,CAAA;QACnB,MAAM,MAAM,GAAG,CAAC,CAAC,MAAM,CAAA;QACvB,OAAO,MAAM,CAAC,aAAa,CAAC,aAAa,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YAC3D,IAAI,GAAG,MAAM,CAAA;KAChB;IACD,oCAAoC;IACpC,sBAAsB;IACtB,OAAO,MAAM,CAAC,aAAa,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;AAChD,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,CAAS,EAAU,EAAE;IACjD,MAAM,GAAG,GAAG,QAAQ,CAAC,GAAG,EAAE,CAAC,CAAC,CAAA;IAC5B,CAAC,GAAG,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,CAAA;IACrB,2BAA2B;IAC3B,IAAI,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;QAAE,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAA;IACrE,uBAAuB;IACvB,IAAI,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE;QACxB,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,sBAAsB,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,WAAW,EAAE,CAAC,CAAA;KAC9D;IACD,OAAO,CAAC,CAAA;AACV,CAAC,CAAA","sourcesContent":["// The sources reported in sourcemaps can be fickle,\n// and istanbul's reporting doesn't handle it so well.\n// So, we canonicalize all entries in sources to a file://\n// url with consistent capitalization.\n\nimport { relative, resolve } from 'path'\nimport { fileURLToPath, pathToFileURL } from 'url'\nconst cwd = process.cwd()\n\nexport const canonicalSource = (s: string): string => {\n // convert to a path\n if (s.startsWith('file://')) {\n const u = new URL(s)\n const hash = u.hash\n const search = u.search\n return String(pathToFileURL(canonicalPath(fileURLToPath(s)))) +\n hash + search\n }\n // re-resolve it relative to the cwd\n // back to a file: url\n return String(pathToFileURL(canonicalPath(s)))\n}\n\nexport const canonicalPath = (s: string): string => {\n const rel = relative(cwd, s)\n s = resolve(cwd, rel)\n // capitalize drive letters\n if (/^[a-z]:/.test(s)) s = s.charAt(0).toUpperCase() + s.substring(1)\n // capitalize UNC paths\n if (s.startsWith('\\\\\\\\')) {\n s = s.replace(/\\\\\\\\[^\\\\]+\\\\[^\\\\]+\\\\/, _0 => _0.toUpperCase())\n }\n return s\n}\n"]}
|
|
@@ -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,MACzB,MAAM,GAAG,GAAG,KACd,KAAK,GAAG,SAAS,GAAG,
|
|
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,SAkBtB,CAAA"}
|
|
@@ -14,9 +14,12 @@ export const findSourceMapSafe = (s) => {
|
|
|
14
14
|
if (sm)
|
|
15
15
|
sourceMaps.set(mod, sm);
|
|
16
16
|
return sm;
|
|
17
|
+
// only throws on node 20
|
|
18
|
+
/* c8 ignore start */
|
|
17
19
|
}
|
|
18
20
|
catch {
|
|
19
21
|
return false;
|
|
20
22
|
}
|
|
23
|
+
/* c8 ignore stop */
|
|
21
24
|
};
|
|
22
25
|
//# 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,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;
|
|
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;QACT,yBAAyB;QACzB,qBAAqB;KACtB;IAAC,MAAM;QACN,OAAO,KAAK,CAAA;KACb;IACD,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 = (\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 // only throws on node 20\n /* c8 ignore start */\n } catch {\n return false\n }\n /* c8 ignore stop */\n}\n"]}
|
package/dist/esm/import.mjs
CHANGED
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
// work, and then registers the loader without globalPreload
|
|
4
4
|
import { register } from 'node:module';
|
|
5
5
|
import { MessageChannel } from 'node:worker_threads';
|
|
6
|
+
import { getImportMetaURL } from './get-import-meta-url.js';
|
|
6
7
|
import { getProcessInfo } from './get-process-info.js';
|
|
7
8
|
import { saveLineLengths } from './line-lengths.js';
|
|
8
|
-
import { getImportMetaURL } from './get-import-meta-url.js';
|
|
9
9
|
import { likelyHasSourceMap } from './lookup-sources.js';
|
|
10
10
|
const { port1, port2 } = new MessageChannel();
|
|
11
11
|
// must be called eagerly here.
|
package/dist/esm/import.mjs.map
CHANGED
|
@@ -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,
|
|
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,gBAAgB,EAAE,MAAM,0BAA0B,CAAA;AAC3D,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AAExD,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 { getImportMetaURL } from './get-import-meta-url.js'\nimport { getProcessInfo } from './get-process-info.js'\nimport { saveLineLengths } from './line-lengths.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,
|
|
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,SAa1B,CAAA;AAED,eAAO,MAAM,cAAc,aAAc,MAAM,yBAG9C,CAAA"}
|
package/dist/esm/line-lengths.js
CHANGED
|
@@ -18,9 +18,7 @@ export const saveLineLengths = (filename, content) => {
|
|
|
18
18
|
const last = content.trimEnd().split('\n').pop();
|
|
19
19
|
if (cache.has(filename) || !last?.startsWith(sourceMapComment))
|
|
20
20
|
return;
|
|
21
|
-
const ll = content
|
|
22
|
-
.split(/\n|\u2028|\u2029/)
|
|
23
|
-
.map(l => l.length);
|
|
21
|
+
const ll = content.split(/\n|\u2028|\u2029/).map(l => l.length);
|
|
24
22
|
cache.set(filename, ll);
|
|
25
23
|
};
|
|
26
24
|
export const getLineLengths = (filename) => {
|
|
@@ -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,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,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IAAI,CAAC,IAAI,EAAE,UAAU,CAAC,gBAAgB,CAAC;QAAE,OAAM;IACtE,MAAM,EAAE,GAAG,OAAO,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAA;IAE/D,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.split(/\\n|\\u2028|\\u2029/).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"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export declare const sourcesCache: Map<string, string[]>;
|
|
2
2
|
export declare const loadPendingSourceMaps: () => void;
|
|
3
|
-
export declare const lookupSources: (url: string) => string[] | undefined;
|
|
4
|
-
export declare const getSources: () => Map<string, string[]>;
|
|
3
|
+
export declare const lookupSources: (url: string, processEnd?: boolean) => string[] | undefined;
|
|
4
|
+
export declare const getSources: (processEnd?: boolean) => Map<string, string[]>;
|
|
5
5
|
export declare const likelyHasSourceMap: (url: string) => void;
|
|
6
6
|
//# sourceMappingURL=lookup-sources.d.ts.map
|
|
@@ -1 +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,
|
|
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,YAmBjC,CAAA;AAED,eAAO,MAAM,aAAa,QAAS,MAAM,eAAe,OAAO,yBAC9B,CAAA;AAGjC,eAAO,MAAM,UAAU,gBAAgB,OAAO,0BAM7C,CAAA;AAED,eAAO,MAAM,kBAAkB,QAAS,MAAM,SAG7C,CAAA"}
|
|
@@ -21,6 +21,8 @@ export const sourcesCache = new Map();
|
|
|
21
21
|
export const loadPendingSourceMaps = () => {
|
|
22
22
|
for (const url of maybeSM) {
|
|
23
23
|
const sm = findSourceMapSafe(url);
|
|
24
|
+
// only possible on node 19+
|
|
25
|
+
/* c8 ignore start */
|
|
24
26
|
if (sm === false) {
|
|
25
27
|
// can only happen if node found the SM comment, and tried to load it,
|
|
26
28
|
// but got an error creating the sourcemap, because it's invalid or
|
|
@@ -28,6 +30,7 @@ export const loadPendingSourceMaps = () => {
|
|
|
28
30
|
maybeSM.delete(url);
|
|
29
31
|
}
|
|
30
32
|
else {
|
|
33
|
+
/* c8 ignore stop */
|
|
31
34
|
const sources = sm?.payload?.sources;
|
|
32
35
|
if (sources) {
|
|
33
36
|
sourcesCache.set(url, sources);
|
|
@@ -36,10 +39,14 @@ export const loadPendingSourceMaps = () => {
|
|
|
36
39
|
}
|
|
37
40
|
}
|
|
38
41
|
};
|
|
39
|
-
export const lookupSources = (url) => getSources().get(url);
|
|
40
|
-
|
|
41
|
-
|
|
42
|
+
export const lookupSources = (url, processEnd) => getSources(processEnd).get(url);
|
|
43
|
+
let didFinalLookupAttempt = false;
|
|
44
|
+
export const getSources = (processEnd = false) => {
|
|
45
|
+
if (maybeSM.size && (!processEnd || !didFinalLookupAttempt)) {
|
|
46
|
+
if (processEnd)
|
|
47
|
+
didFinalLookupAttempt = true;
|
|
42
48
|
loadPendingSourceMaps();
|
|
49
|
+
}
|
|
43
50
|
return sourcesCache;
|
|
44
51
|
};
|
|
45
52
|
export const likelyHasSourceMap = (url) => {
|
|
@@ -1 +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;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AM,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,UAAoB,EAAE,EAAE,CACjE,UAAU,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;AAEjC,IAAI,qBAAqB,GAAG,KAAK,CAAA;AACjC,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,aAAsB,KAAK,EAAE,EAAE;IACxD,IAAI,OAAO,CAAC,IAAI,IAAI,CAAC,CAAC,UAAU,IAAI,CAAC,qBAAqB,CAAC,EAAE;QAC3D,IAAI,UAAU;YAAE,qBAAqB,GAAG,IAAI,CAAA;QAC5C,qBAAqB,EAAE,CAAA;KACxB;IACD,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 // only possible on node 19+\n /* c8 ignore start */\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 /* c8 ignore stop */\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, processEnd?: boolean) =>\n getSources(processEnd).get(url)\n\nlet didFinalLookupAttempt = false\nexport const getSources = (processEnd: boolean = false) => {\n if (maybeSM.size && (!processEnd || !didFinalLookupAttempt)) {\n if (processEnd) didFinalLookupAttempt = true\n loadPendingSourceMaps()\n }\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;
|
|
1
|
+
{"version":3,"file":"register-coverage.d.ts","sourceRoot":"","sources":["../../src/register-coverage.ts"],"names":[],"mappings":";AAKA,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;AASxC,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,SAuEjC,CAAA"}
|
|
@@ -6,6 +6,7 @@ import { mkdirSync, writeFileSync } from 'node:fs';
|
|
|
6
6
|
import { Session } from 'node:inspector';
|
|
7
7
|
import { resolve } from 'node:path';
|
|
8
8
|
import { fileURLToPath } from 'node:url';
|
|
9
|
+
import { canonicalSource } from './canonical-source.js';
|
|
9
10
|
import { findSourceMapSafe } from './find-source-map-safe.js';
|
|
10
11
|
import { getExclude } from './get-exclude.js';
|
|
11
12
|
import { getLineLengths } from './line-lengths.js';
|
|
@@ -30,15 +31,16 @@ const uncoveredFiles = cxEnv
|
|
|
30
31
|
.filter(f => !!f);
|
|
31
32
|
const exclude = p.env._TAPJS_PROCESSINFO_COV_EXCLUDE_
|
|
32
33
|
? getExclude('_TAPJS_PROCESSINFO_COV_EXCLUDE_', false)
|
|
33
|
-
:
|
|
34
|
+
: /[\\\/]node_modules[\\\/]/;
|
|
34
35
|
const fileCovered = (f, sources = [], files = []) => {
|
|
35
36
|
const testFiles = [f];
|
|
36
37
|
for (const src of sources || []) {
|
|
37
38
|
testFiles.push(resolve(src.startsWith('file://') ? fileURLToPath(src) : src));
|
|
38
39
|
}
|
|
39
40
|
// never include coverage if the file is fully ignored.
|
|
40
|
-
if (!testFiles.some(f => files.includes(f)))
|
|
41
|
+
if (!testFiles.some(f => files.includes(f))) {
|
|
41
42
|
return false;
|
|
43
|
+
}
|
|
42
44
|
// if at least one of them are explicitly covered, then include it,
|
|
43
45
|
// otherwise omit if we explicitly listed
|
|
44
46
|
if (coveredFiles.length) {
|
|
@@ -98,11 +100,12 @@ export const coverageOnProcessEnd = (cwd, processInfo) => {
|
|
|
98
100
|
if (!/^file:/.test(obj.url)) {
|
|
99
101
|
return false;
|
|
100
102
|
}
|
|
103
|
+
obj.url = canonicalSource(obj.url);
|
|
101
104
|
const f = fileURLToPath(obj.url);
|
|
102
105
|
// see if it has a source map
|
|
103
106
|
// need to look up via the url, not the file path, because mocks
|
|
104
107
|
// attach a tapmock search param, which is in node's internal key.
|
|
105
|
-
const sources = lookupSources(obj.url);
|
|
108
|
+
const sources = lookupSources(obj.url, true);
|
|
106
109
|
if (!fileCovered(f, sources, processInfo.files)) {
|
|
107
110
|
return false;
|
|
108
111
|
}
|
|
@@ -118,7 +121,10 @@ export const coverageOnProcessEnd = (cwd, processInfo) => {
|
|
|
118
121
|
//@ts-ignore
|
|
119
122
|
lineLengths: s?.lineLengths || getLineLengths(f),
|
|
120
123
|
/* c8 ignore stop */
|
|
121
|
-
data:
|
|
124
|
+
data: {
|
|
125
|
+
...payload,
|
|
126
|
+
sources: payload.sources?.map(s => canonicalSource(s)),
|
|
127
|
+
},
|
|
122
128
|
});
|
|
123
129
|
}
|
|
124
130
|
return true;
|
|
@@ -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;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,GAA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AE,CAAC,EAAE,WAAW,IAAI,cAAc,CAAC,CAAC,CAAC;oBAChD,oBAAoB;oBACpB,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 { 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
|
+
{"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,eAAe,EAAE,MAAM,uBAAuB,CAAA;AACvD,OAAO,EAAE,iBAAiB,EAAE,MAAM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,OAAO,KAAK,CAAA;aACb;YACD,qEAAqE;YACrE,qEAAqE;YACrE,mEAAmE;YACnE,MAAM,CAAC,GAAG,iBAAiB,CAAC,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,cAAc,CAAC,CAAC,CAAC;oBAChD,oBAAoB;oBACpB,IAAI,EAAE;wBACJ,GAAG,OAAO;wBACV,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;qBACvD;iBACF,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 { canonicalSource } from './canonical-source.js'\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 : /[\\\\\\/]node_modules[\\\\\\/]/\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))) {\n return false\n }\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 obj.url = canonicalSource(obj.url)\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, true)\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: {\n ...payload,\n sources: payload.sources?.map(s => canonicalSource(s)),\n },\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"]}
|