@teamscale/javascript-instrumenter 0.0.1-beta.50 → 0.0.1-beta.52
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/package.json +1 -1
- package/dist/src/instrumenter/Instrumenter.d.ts +1 -0
- package/dist/src/instrumenter/Instrumenter.d.ts.map +1 -1
- package/dist/src/instrumenter/Instrumenter.js +17 -9
- package/dist/src/instrumenter/Postprocessor.d.ts.map +1 -1
- package/dist/src/instrumenter/Postprocessor.js +29 -2
- package/dist/src/instrumenter/Task.d.ts.map +1 -1
- package/dist/src/instrumenter/Task.js +2 -3
- package/dist/vaccine.js +1 -1
- package/package.json +1 -1
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teamscale/javascript-instrumenter",
|
|
3
|
-
"version": "0.0.1-beta.
|
|
3
|
+
"version": "0.0.1-beta.52",
|
|
4
4
|
"description": "JavaScript coverage instrumenter with coverage forwarding to a collector process",
|
|
5
5
|
"main": "dist/src/main.js",
|
|
6
6
|
"bin": "dist/src/main.js",
|
|
@@ -38,6 +38,7 @@ export declare class IstanbulInstrumenter implements IInstrumenter {
|
|
|
38
38
|
*
|
|
39
39
|
* @param collector - The collector to send the coverage information to.
|
|
40
40
|
* @param taskElement - The task element to perform the instrumentation for.
|
|
41
|
+
* @param excludeBundles - A exclude pattern to restrict which bundles should be instrumented
|
|
41
42
|
* @param sourcePattern - A pattern to restrict the instrumentation to only a fraction of the task element.
|
|
42
43
|
* @param dumpOriginsFile - A file path where all origins from the source map should be dumped in json format, or undefined if no origins should be dumped
|
|
43
44
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Instrumenter.d.ts","sourceRoot":"","sources":["../../../src/instrumenter/Instrumenter.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,kBAAkB,
|
|
1
|
+
{"version":3,"file":"Instrumenter.d.ts","sourceRoot":"","sources":["../../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B,aAAa,CAClC,kBAAkB,EAAE,MAAM,EAC1B,0BAA0B,EAAE,MAAM,GAChC,OAAO,CAAC,iBAAiB,GAAG,SAAS,CAAC,CAUxC;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CACjC,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,MAAM,EAChB,qBAAqB,EAAE,QAAQ,CAAC,kBAAkB,CAAC,GACjD,YAAY,GAAG,SAAS,CAU1B;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,CAAC,UAAU,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS,CAsC7G;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,WAAW,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS,CAGlF"}
|
|
@@ -70,30 +70,34 @@ class IstanbulInstrumenter {
|
|
|
70
70
|
*
|
|
71
71
|
* @param collector - The collector to send the coverage information to.
|
|
72
72
|
* @param taskElement - The task element to perform the instrumentation for.
|
|
73
|
+
* @param excludeBundles - A exclude pattern to restrict which bundles should be instrumented
|
|
73
74
|
* @param sourcePattern - A pattern to restrict the instrumentation to only a fraction of the task element.
|
|
74
75
|
* @param dumpOriginsFile - A file path where all origins from the source map should be dumped in json format, or undefined if no origins should be dumped
|
|
75
76
|
*/
|
|
76
77
|
async instrumentOne(collector, taskElement, excludeBundles, sourcePattern, dumpOriginsFile) {
|
|
77
78
|
var _a, _b;
|
|
78
|
-
const inputFileSource = fs.readFileSync(taskElement.fromFile, 'utf8');
|
|
79
|
-
// We skip files that we have already instrumented
|
|
80
|
-
if (inputFileSource.startsWith(exports.IS_INSTRUMENTED_TOKEN)) {
|
|
81
|
-
if (!taskElement.isInPlace()) {
|
|
82
|
-
writeToFile(taskElement.toFile, inputFileSource);
|
|
83
|
-
}
|
|
84
|
-
return new Task_1.TaskResult(0, 0, 0, 1, 0, 0, 0);
|
|
85
|
-
}
|
|
86
79
|
// Not all file types are supported by the instrumenter
|
|
87
80
|
if (!this.isFileTypeSupported(taskElement.fromFile)) {
|
|
81
|
+
if (!taskElement.isInPlace()) {
|
|
82
|
+
copyToFile(taskElement.toFile, taskElement.fromFile);
|
|
83
|
+
}
|
|
88
84
|
return new Task_1.TaskResult(0, 0, 0, 0, 1, 0, 0);
|
|
89
85
|
}
|
|
90
86
|
// We might want to skip the instrumentation of the file
|
|
91
87
|
if (excludeBundles.isExcluded(taskElement.fromFile)) {
|
|
92
88
|
if (!taskElement.isInPlace()) {
|
|
93
|
-
|
|
89
|
+
copyToFile(taskElement.toFile, taskElement.fromFile);
|
|
94
90
|
}
|
|
95
91
|
return new Task_1.TaskResult(0, 1, 0, 0, 0, 0, 0);
|
|
96
92
|
}
|
|
93
|
+
const inputFileSource = fs.readFileSync(taskElement.fromFile, 'utf8');
|
|
94
|
+
// We skip files that we have already instrumented
|
|
95
|
+
if (inputFileSource.startsWith(exports.IS_INSTRUMENTED_TOKEN)) {
|
|
96
|
+
if (!taskElement.isInPlace()) {
|
|
97
|
+
writeToFile(taskElement.toFile, inputFileSource);
|
|
98
|
+
}
|
|
99
|
+
return new Task_1.TaskResult(0, 0, 0, 1, 0, 0, 0);
|
|
100
|
+
}
|
|
97
101
|
// Report progress
|
|
98
102
|
this.logger.info(`Instrumenting "${path.basename(taskElement.fromFile)}"`);
|
|
99
103
|
let finalSourceMap;
|
|
@@ -326,3 +330,7 @@ function writeToFile(filePath, fileContent) {
|
|
|
326
330
|
mkdirp.sync(path.dirname(filePath));
|
|
327
331
|
fs.writeFileSync(filePath, fileContent);
|
|
328
332
|
}
|
|
333
|
+
function copyToFile(targetFilePath, sourceFilePath) {
|
|
334
|
+
mkdirp.sync(path.dirname(targetFilePath));
|
|
335
|
+
fs.copyFileSync(sourceFilePath, targetFilePath);
|
|
336
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Postprocessor.d.ts","sourceRoot":"","sources":["../../../src/instrumenter/Postprocessor.ts"],"names":[],"mappings":"AAGA,OAAO,EAQN,cAAc,
|
|
1
|
+
{"version":3,"file":"Postprocessor.d.ts","sourceRoot":"","sources":["../../../src/instrumenter/Postprocessor.ts"],"names":[],"mappings":"AAGA,OAAO,EAQN,cAAc,EASd,MAAM,cAAc,CAAC;AAqKtB;;;;;GAKG;AACH,wBAAgB,eAAe,CAC9B,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,OAAO,EAClB,aAAa,EAAE,CAAC,QAAQ,EAAE,cAAc,KAAK,OAAO,GAClD,MAAM,CAaR"}
|
|
@@ -10,6 +10,34 @@ const traverse_1 = __importDefault(require("@babel/traverse"));
|
|
|
10
10
|
const types_1 = require("@babel/types");
|
|
11
11
|
const commons_1 = require("@cqse/commons");
|
|
12
12
|
const COVERAGE_OBJ_FUNCTION_NAME_PREFIX = 'cov_';
|
|
13
|
+
/**
|
|
14
|
+
* Generator for identifiers that are unique across files to instrument.
|
|
15
|
+
* Relevant in case no Ecmascript modules are used.
|
|
16
|
+
*
|
|
17
|
+
* We assume that the files to be executed in a browser can
|
|
18
|
+
* stem from different runs of the instrumenter. We have to decrease
|
|
19
|
+
* the probability of colliding identifiers.
|
|
20
|
+
*/
|
|
21
|
+
const fileIdSeqGenerator = (() => {
|
|
22
|
+
const instrumenterRunId = process.pid;
|
|
23
|
+
let fileIdSeq = 0;
|
|
24
|
+
return {
|
|
25
|
+
next: () => {
|
|
26
|
+
fileIdSeq++;
|
|
27
|
+
let num;
|
|
28
|
+
if (fileIdSeq < 10000) {
|
|
29
|
+
num = instrumenterRunId * 10000 + fileIdSeq;
|
|
30
|
+
}
|
|
31
|
+
else if (fileIdSeq < 100000) {
|
|
32
|
+
num = instrumenterRunId * 100000 + fileIdSeq;
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
throw new Error(`Not more that 100k files supported to be instrumented in one run.`);
|
|
36
|
+
}
|
|
37
|
+
return num.toString(36);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
})();
|
|
13
41
|
function getIstanbulCoverageFunctionDeclarationName(node) {
|
|
14
42
|
var _a;
|
|
15
43
|
if (!(0, types_1.isFunctionDeclaration)(node)) {
|
|
@@ -25,7 +53,6 @@ function getIstanbulCoverageFunctionDeclarationName(node) {
|
|
|
25
53
|
}
|
|
26
54
|
function createFileIdMappingHandler() {
|
|
27
55
|
const fileIdMap = new Map();
|
|
28
|
-
let fileIdSeq = 0;
|
|
29
56
|
return {
|
|
30
57
|
enterPath(path) {
|
|
31
58
|
var _a;
|
|
@@ -40,7 +67,7 @@ function createFileIdMappingHandler() {
|
|
|
40
67
|
const declarator = declaration.declarations[0];
|
|
41
68
|
if ((0, types_1.isIdentifier)(declarator.id) && declarator.id.name === 'hash') {
|
|
42
69
|
// We take note of the hash that is stored within the `cov_*' function.
|
|
43
|
-
const fileIdVarName = `_$
|
|
70
|
+
const fileIdVarName = `_$f${fileIdSeqGenerator.next()}`;
|
|
44
71
|
const fileId = declarator.init.value;
|
|
45
72
|
fileIdMap.set(coverageFunctionName, fileIdVarName);
|
|
46
73
|
grandParentPath.insertBefore(newStringConstDeclarationNode(fileIdVarName, fileId));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Task.d.ts","sourceRoot":"","sources":["../../../src/instrumenter/Task.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAK/C;;GAEG;AACH,8BAAsB,kBAAkB;CAAG;AAE3C;;;GAGG;AACH,qBAAa,WAAW;IACvB,sBAAsB;IACtB,SAAgB,QAAQ,EAAE,MAAM,CAAC;IAEjC,2BAA2B;IAC3B,SAAgB,MAAM,EAAE,MAAM,CAAC;IAE/B,gEAAgE;IAChE,SAAgB,qBAAqB,EAAE,QAAQ,CAAC,kBAAkB,CAAC,CAAC;gBAExD,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,iBAAiB,CAAC,EAAE,kBAAkB;IAMpF;;OAEG;IACI,SAAS,IAAI,OAAO;CAK3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EpC,6DAA6D;IAC7D,SAAgB,MAAM,EAAE,MAAM,CAAC;IAE/B,+EAA+E;IAC/E,SAAgB,QAAQ,EAAE,MAAM,CAAC;gBAGhC,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,EAChB,mBAAmB,EAAE,MAAM,EAC3B,mBAAmB,EAAE,MAAM,EAC3B,WAAW,EAAE,MAAM,EACnB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM;IAkBjB;;;;OAIG;IACI,aAAa,CAAC,KAAK,EAAE,UAAU,GAAG,UAAU;IAYnD;;OAEG;WACW,OAAO,IAAI,UAAU;IAInC;;;;OAIG;WACW,KAAK,CAAC,CAAC,EAAE,KAAK,GAAG,UAAU;IAKzC;;;;OAIG;WACW,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU;CAI9C;AAED;;GAEG;AACH,qBAAa,sBAAuB,SAAQ,kBAAkB;IAC7D,2CAA2C;IAC3C,SAAgB,iBAAiB,EAAE,MAAM,CAAC;gBAE9B,iBAAiB,EAAE,MAAM;CAIrC"}
|
|
@@ -89,8 +89,7 @@ class OriginSourcePattern {
|
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
91
|
if (this.include) {
|
|
92
|
-
|
|
93
|
-
return matchedToInclude.length > 0;
|
|
92
|
+
return micromatch_1.default.some(normalizedOriginFiles, this.include || ['**']);
|
|
94
93
|
}
|
|
95
94
|
return true;
|
|
96
95
|
}
|
|
@@ -108,7 +107,7 @@ class FileExcludePattern {
|
|
|
108
107
|
* Return `true` if the given `filePath` is matched by any of the patterns in `exclude`.
|
|
109
108
|
*/
|
|
110
109
|
isExcluded(filePath) {
|
|
111
|
-
return
|
|
110
|
+
return micromatch_1.default.isMatch(normalizePath(filePath), this.exclude);
|
|
112
111
|
}
|
|
113
112
|
}
|
|
114
113
|
exports.FileExcludePattern = FileExcludePattern;
|
package/dist/vaccine.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{function
|
|
1
|
+
(()=>{function d(e){let n=new Blob([e],{type:"text/javascript"}),t=URL.createObjectURL(n),s=new Worker(t);return URL.revokeObjectURL(t),s}function h(){return d('var r=class{constructor(e){this.cachedMessages=[];this.url=e,this.socket=this.createSocket()}createSocket(){let e=new WebSocket(this.url);return e.onopen=()=>this.onopen(),e.onclose=()=>this.onclose(),e}onclose(){this.socket=this.createSocket()}onopen(){console.log("Connection to Coverage Collector established."),this.cachedMessages.forEach(e=>this.socket.send(e)),this.cachedMessages=[]}send(e){this.socket.readyState===WebSocket.OPEN?this.socket.send(e):(this.cachedMessages.push(e),this.cachedMessages.length%500===0&&console.log(`More than ${this.cachedMessages.length} messages are queued to be sent.`))}};var C=20,m=1e3,d=class{constructor(e,t){this.milliseconds=e;this.onCountedToZero=t;this.timerHandle=null}restartCountdown(){this.stopCountdown(),this.timerHandle=self.setTimeout(()=>{this.stopCountdown(),this.onCountedToZero()},this.milliseconds)}stopCountdown(){this.timerHandle!==null&&(self.clearTimeout(this.timerHandle),this.timerHandle=null)}},a=class{constructor(e){this.socket=e,this.cachedCoveredRanges=new Map,this.numberOfCachedPositions=0,this.flushCountdown=new d(m,()=>this.flush())}addRange(e,t){if(!t.start.line||!t.end.line)return;let o=this.cachedCoveredRanges.get(e);o||(o=new Set,this.cachedCoveredRanges.set(e,o)),o.add(t),this.numberOfCachedPositions+=1,this.flushCountdown.restartCountdown(),this.numberOfCachedPositions>=C&&this.flush()}flush(){this.numberOfCachedPositions!==0&&(this.flushCountdown.stopCountdown(),this.cachedCoveredRanges.forEach((e,t)=>{let o=Array.from(e).map(n=>`${n.start.line}:${n.start.column}:${n.end.line}:${n.end.column}`);this.socket.send(`${"c"} ${t} ${o.join(" ")}`),e.clear()}),this.cachedCoveredRanges.clear(),this.numberOfCachedPositions=0)}};console.log("Starting coverage forwarding worker.");var u=new r("$REPORT_TO_URL/socket"),h=new a(u),f=new Map;onmessage=s=>{if(Array.isArray(s.data))p(s.data);else{let e=s.data;if(e.startsWith("s"))u.send(e);else if(e.startsWith("i")){let t=JSON.parse(e.substring(2));f.set(t.hash,t),console.info(`Received coverage mapping information for "${t.hash}".`)}else e==="unload"?h.flush():console.error(`No handler for message: ${e}`)}};function p(s){var n;let e=s[0],t=s[1],o=f.get(e);if(!o){console.log(`No coverage mapping information for ${e} available!`);return}for(let[c,i]of t.branches.entries()){let l=(n=o.branchMap[c])==null?void 0:n.locations[i];l&&h.addRange(e,l)}for(let c of t.statements){let i=o.statementMap[c];i&&h.addRange(e,i)}}\n')}function c(){return g()}function g(){return window}function p(e,n){let t=c()[e];return t||(t=n,c()[e]=t),t}var l;(function(r){r.MESSAGE_TYPE_SOURCEMAP="s",r.MESSAGE_TYPE_COVERAGE="c",r.ISTANBUL_COV_OBJECT="i",r.UNRESOLVED_CODE_ENTITY="u"})(l||(l={}));function v(e,n){let t=new Map;function s(i){let o=t.get(i);return o||(o={branches:new Map,statements:new Set},t.set(i,o),o)}function r(i,o,w){s(i).branches.set(o,w)}function u(i,o){s(i).statements.add(o)}function a(){n(t),t.clear()}return setInterval(()=>a(),e),{putBranchCoverage:r,putStatementCoverage:u,flush:a}}var C=p("__TS_AGENT",{});function f(){return C._$BcWorker}function S(e){return C._$BcWorker=e,e}var m=v(250,e=>{for(let n of e.entries())f().postMessage(n)});c()._$stmtCov=m.putStatementCoverage;c()._$brCov=m.putBranchCoverage;var b=new Set;c()._$registerCoverageObject=function(e){let n=e.hash;if(b.has(n)){console.log(`Coverage interceptor added twice for ${n}. This seems to be a bug in the instrumentation.`);return}else b.add(n);if(!f()){let t=S(new h);(function(){let r=()=>{m.flush(),t.postMessage("unload")},u=function(i,o){!o||o.addEventListener(i,r,{capture:!0})},a=g();u("blur",a),u("unload",a),u("visibilitychange",a),u("beforeunload",a)})()}(function(){f().postMessage(`${l.ISTANBUL_COV_OBJECT} ${JSON.stringify(e)}`);let s=p("sentMaps",new Set);e.inputSourceMap&&(s.has(e.path)||(f().postMessage(`${l.MESSAGE_TYPE_SOURCEMAP} ${n}:${JSON.stringify(e.inputSourceMap)}`),s.add(e.path)))})()};})();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teamscale/javascript-instrumenter",
|
|
3
|
-
"version": "0.0.1-beta.
|
|
3
|
+
"version": "0.0.1-beta.52",
|
|
4
4
|
"description": "JavaScript coverage instrumenter with coverage forwarding to a collector process",
|
|
5
5
|
"main": "dist/src/main.js",
|
|
6
6
|
"bin": "dist/src/main.js",
|