@teamscale/javascript-instrumenter 0.0.1-beta.22 → 0.0.1-beta.25
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 +10 -4
- package/dist/src/App.js +5 -1
- package/dist/src/instrumenter/Cleaner.d.ts +9 -0
- package/dist/src/instrumenter/Cleaner.d.ts.map +1 -0
- package/dist/src/instrumenter/Cleaner.js +46 -0
- package/dist/src/instrumenter/FileSystem.js +5 -1
- package/dist/src/instrumenter/Instrumenter.d.ts +6 -3
- package/dist/src/instrumenter/Instrumenter.d.ts.map +1 -1
- package/dist/src/instrumenter/Instrumenter.js +56 -19
- package/dist/src/instrumenter/Task.d.ts +1 -0
- package/dist/src/instrumenter/Task.d.ts.map +1 -1
- package/dist/src/instrumenter/Task.js +13 -4
- package/dist/src/instrumenter/TaskBuilder.js +5 -1
- package/dist/src/main.js +0 -0
- package/dist/vaccine.js +1 -1
- package/package.json +10 -4
- package/CHANGELOG.md +0 -11
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.25",
|
|
4
4
|
"description": "Istanbul-based coverage instrumenter with coverage forwarding via WebSockets",
|
|
5
5
|
"main": "dist/src/main.js",
|
|
6
6
|
"bin": "dist/src/main.js",
|
|
@@ -12,8 +12,10 @@
|
|
|
12
12
|
"url": "https://github.com/cqse/teamscale-javascript-profiler.git"
|
|
13
13
|
},
|
|
14
14
|
"scripts": {
|
|
15
|
+
"prepublishOnly": "yarn clean && yarn build",
|
|
15
16
|
"clean": "rimraf dist tsconfig.tsbuildinfo",
|
|
16
|
-
"build": "tsc --project tsconfig.json &&
|
|
17
|
+
"build": "tsc --project tsconfig.json && yarn buildVaccine",
|
|
18
|
+
"buildVaccine": "node esbuild.mjs",
|
|
17
19
|
"instrumenter": "node dist/src/main.js",
|
|
18
20
|
"test": "yarn build && NODE_OPTIONS='--experimental-vm-modules' jest --forceExit --coverage --silent=true --detectOpenHandles"
|
|
19
21
|
},
|
|
@@ -21,7 +23,7 @@
|
|
|
21
23
|
"dist/**/*"
|
|
22
24
|
],
|
|
23
25
|
"devDependencies": {
|
|
24
|
-
"@babel/core": "^7.
|
|
26
|
+
"@babel/core": "^7.17.5",
|
|
25
27
|
"@babel/plugin-transform-modules-commonjs": "^7.15.4",
|
|
26
28
|
"@babel/preset-env": "^7.14.1",
|
|
27
29
|
"@types/async": "^3.2.6",
|
|
@@ -44,6 +46,10 @@
|
|
|
44
46
|
"typescript": "^4.4.3"
|
|
45
47
|
},
|
|
46
48
|
"dependencies": {
|
|
49
|
+
"@babel/generator": "^7.17.3",
|
|
50
|
+
"@babel/parser": "^7.17.3",
|
|
51
|
+
"@babel/traverse": "^7.17.3",
|
|
52
|
+
"@babel/types": "^7.17.0",
|
|
47
53
|
"@cqse/commons": "^0.0.1-beta.1",
|
|
48
54
|
"@types/micromatch": "^4.0.2",
|
|
49
55
|
"argparse": "^2.0.1",
|
|
@@ -55,7 +61,7 @@
|
|
|
55
61
|
"micromatch": "4.0.4",
|
|
56
62
|
"mkdirp": "^1.0.4",
|
|
57
63
|
"nyc": "^15.1.0",
|
|
58
|
-
"source-map": "0.
|
|
64
|
+
"source-map": "0.7.3",
|
|
59
65
|
"typescript-optional": "^2.0.1",
|
|
60
66
|
"unload": "^2.2.0",
|
|
61
67
|
"web-worker": "^1.0.0",
|
package/dist/src/App.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { SourceLocation } from '@babel/types';
|
|
2
|
+
/**
|
|
3
|
+
* Remove IstanbulJs instrumentations based on the given
|
|
4
|
+
* hook `makeCoverable`.
|
|
5
|
+
*
|
|
6
|
+
* An instrumentation is removed if the hook `makeCoverable` returns `false`.
|
|
7
|
+
*/
|
|
8
|
+
export declare function cleanSourceCode(code: string, esModules: boolean, makeCoverable: (location: SourceLocation) => boolean): string;
|
|
9
|
+
//# sourceMappingURL=Cleaner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Cleaner.d.ts","sourceRoot":"","sources":["../../../src/instrumenter/Cleaner.ts"],"names":[],"mappings":"AAGA,OAAO,EAON,cAAc,EACd,MAAM,cAAc,CAAC;AAEtB;;;;;GAKG;AACH,wBAAgB,eAAe,CAC9B,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,OAAO,EAClB,aAAa,EAAE,CAAC,QAAQ,EAAE,cAAc,KAAK,OAAO,GAClD,MAAM,CAYR"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.cleanSourceCode = void 0;
|
|
7
|
+
const parser_1 = require("@babel/parser");
|
|
8
|
+
const generator_1 = __importDefault(require("@babel/generator"));
|
|
9
|
+
const traverse_1 = __importDefault(require("@babel/traverse"));
|
|
10
|
+
const types_1 = require("@babel/types");
|
|
11
|
+
/**
|
|
12
|
+
* Remove IstanbulJs instrumentations based on the given
|
|
13
|
+
* hook `makeCoverable`.
|
|
14
|
+
*
|
|
15
|
+
* An instrumentation is removed if the hook `makeCoverable` returns `false`.
|
|
16
|
+
*/
|
|
17
|
+
function cleanSourceCode(code, esModules, makeCoverable) {
|
|
18
|
+
const ast = (0, parser_1.parse)(code, { sourceType: esModules ? 'module' : 'script' });
|
|
19
|
+
(0, traverse_1.default)(ast, {
|
|
20
|
+
ExpressionStatement(path) {
|
|
21
|
+
if (isCoverageIncrementNode(path)) {
|
|
22
|
+
if (path.node.loc && !makeCoverable(path.node.loc)) {
|
|
23
|
+
path.remove();
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
return (0, generator_1.default)(ast, {}, code).code;
|
|
29
|
+
}
|
|
30
|
+
exports.cleanSourceCode = cleanSourceCode;
|
|
31
|
+
/**
|
|
32
|
+
* Checks if the given `path.node` to a statement like `cov_104fq7oo4i().f[0]++;`
|
|
33
|
+
*/
|
|
34
|
+
function isCoverageIncrementNode(path) {
|
|
35
|
+
const expr = path.node.expression;
|
|
36
|
+
if (!(0, types_1.isUpdateExpression)(expr)) {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
return (expr.operator === '++' &&
|
|
40
|
+
(0, types_1.isMemberExpression)(expr.argument) &&
|
|
41
|
+
(0, types_1.isMemberExpression)(expr.argument.object) &&
|
|
42
|
+
(0, types_1.isCallExpression)(expr.argument.object.object) &&
|
|
43
|
+
(0, types_1.isIdentifier)(expr.argument.object.object.callee) &&
|
|
44
|
+
expr.argument.object.object.callee.name.startsWith('cov_') &&
|
|
45
|
+
(0, types_1.isNumericLiteral)(expr.argument.property));
|
|
46
|
+
}
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -38,7 +38,9 @@ export declare class IstanbulInstrumenter implements IInstrumenter {
|
|
|
38
38
|
* @param taskElement - The task element to perform the instrumentation for.
|
|
39
39
|
* @param sourcePattern - A pattern to restrict the instrumentation to only a fraction of the task element.
|
|
40
40
|
*/
|
|
41
|
-
instrumentOne(collector: CollectorSpecifier, taskElement: TaskElement, sourcePattern: OriginSourcePattern): TaskResult
|
|
41
|
+
instrumentOne(collector: CollectorSpecifier, taskElement: TaskElement, sourcePattern: OriginSourcePattern): Promise<TaskResult>;
|
|
42
|
+
private removeUnwantedInstrumentation;
|
|
43
|
+
private loadSourceMap;
|
|
42
44
|
/**
|
|
43
45
|
* Loads the vaccine from the vaccine file and adjusts some template parameters.
|
|
44
46
|
*
|
|
@@ -64,10 +66,11 @@ export declare class IstanbulInstrumenter implements IInstrumenter {
|
|
|
64
66
|
*/
|
|
65
67
|
private configurationAlternativesFor;
|
|
66
68
|
/**
|
|
67
|
-
* Given a source code file
|
|
69
|
+
* Given a source code file, load the corresponding sourcemap.
|
|
68
70
|
*
|
|
69
71
|
* @param inputSource - The source code that might contain sourcemap comments.
|
|
70
|
-
* @param
|
|
72
|
+
* @param taskFile - The name of the file the `inputSource` is from.
|
|
73
|
+
* @param externalSourceMapFile - An external source map file to consider.
|
|
71
74
|
*/
|
|
72
75
|
private loadInputSourceMap;
|
|
73
76
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Instrumenter.d.ts","sourceRoot":"","sources":["../../../src/instrumenter/Instrumenter.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,kBAAkB,EAClB,mBAAmB,EACnB,mBAAmB,
|
|
1
|
+
{"version":3,"file":"Instrumenter.d.ts","sourceRoot":"","sources":["../../../src/instrumenter/Instrumenter.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,kBAAkB,EAClB,mBAAmB,EACnB,mBAAmB,EAGnB,WAAW,EACX,UAAU,EACV,MAAM,QAAQ,CAAC;AAOhB,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAIjC,eAAO,MAAM,qBAAqB,8CAA8C,CAAC;AAEjF;;GAEG;AACH,MAAM,WAAW,aAAa;IAC7B;;;;OAIG;IACH,UAAU,CAAC,IAAI,EAAE,mBAAmB,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;CAC3D;AAED;;GAEG;AACH,qBAAa,oBAAqB,YAAW,aAAa;IACzD;;;;OAIG;IACH,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAS;IAEzC;;OAEG;IACH,OAAO,CAAC,MAAM,CAAS;gBAEX,eAAe,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IASnD;;OAEG;IACG,UAAU,CAAC,IAAI,EAAE,mBAAmB,GAAG,OAAO,CAAC,UAAU,CAAC;IAehE;;;;;;OAMG;IACG,aAAa,CAClB,SAAS,EAAE,kBAAkB,EAC7B,WAAW,EAAE,WAAW,EACxB,aAAa,EAAE,mBAAmB,GAChC,OAAO,CAAC,UAAU,CAAC;YAqGR,6BAA6B;YA6B7B,aAAa;IAe3B;;;;OAIG;IACH,OAAO,CAAC,WAAW;IASnB;;;;;;;OAOG;IACH,OAAO,CAAC,gCAAgC;IAQxC;;OAEG;IACH,OAAO,CAAC,mBAAmB;IAK3B;;;OAGG;IACH,OAAO,CAAC,4BAA4B;IAcpC;;;;;;OAMG;IACH,OAAO,CAAC,kBAAkB;CAe1B"}
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -22,10 +26,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
22
26
|
exports.IstanbulInstrumenter = exports.IS_INSTRUMENTED_TOKEN = void 0;
|
|
23
27
|
const Task_1 = require("./Task");
|
|
24
28
|
const commons_1 = require("@cqse/commons");
|
|
29
|
+
const source_map_1 = require("source-map");
|
|
25
30
|
const istanbul = __importStar(require("istanbul-lib-instrument"));
|
|
26
31
|
const fs = __importStar(require("fs"));
|
|
27
32
|
const path = __importStar(require("path"));
|
|
28
33
|
const convertSourceMap = __importStar(require("convert-source-map"));
|
|
34
|
+
const Cleaner_1 = require("./Cleaner");
|
|
35
|
+
const typescript_optional_1 = require("typescript-optional");
|
|
29
36
|
exports.IS_INSTRUMENTED_TOKEN = '/** $IS_JS_PROFILER_INSTRUMENTED=true **/';
|
|
30
37
|
/**
|
|
31
38
|
* An instrumenter based on the IstanbulJs instrumentation and coverage framework.
|
|
@@ -39,14 +46,12 @@ class IstanbulInstrumenter {
|
|
|
39
46
|
/**
|
|
40
47
|
* {@inheritDoc #IInstrumenter.instrument}
|
|
41
48
|
*/
|
|
42
|
-
instrument(task) {
|
|
49
|
+
async instrument(task) {
|
|
43
50
|
fs.existsSync(this.vaccineFilePath);
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
.reduce((prev, current) => current.withIncrement(prev), Task_1.TaskResult.neutral());
|
|
49
|
-
return Promise.resolve(result);
|
|
51
|
+
const resolved = await Promise.all(task.elements.map((taskElement) => {
|
|
52
|
+
return this.instrumentOne(task.collector, taskElement, task.originSourcePattern);
|
|
53
|
+
}));
|
|
54
|
+
return resolved.reduce((aggregatedResult, taskResult) => aggregatedResult.withIncrement(taskResult), Task_1.TaskResult.neutral());
|
|
50
55
|
}
|
|
51
56
|
/**
|
|
52
57
|
* Perform the instrumentation for one given task element (file to instrument).
|
|
@@ -55,7 +60,7 @@ class IstanbulInstrumenter {
|
|
|
55
60
|
* @param taskElement - The task element to perform the instrumentation for.
|
|
56
61
|
* @param sourcePattern - A pattern to restrict the instrumentation to only a fraction of the task element.
|
|
57
62
|
*/
|
|
58
|
-
instrumentOne(collector, taskElement, sourcePattern) {
|
|
63
|
+
async instrumentOne(collector, taskElement, sourcePattern) {
|
|
59
64
|
var _a, _b;
|
|
60
65
|
const inputFileSource = fs.readFileSync(taskElement.fromFile, 'utf8');
|
|
61
66
|
// We skip files that we have already instrumented
|
|
@@ -77,15 +82,17 @@ class IstanbulInstrumenter {
|
|
|
77
82
|
// alternative configurations of the instrumenter.
|
|
78
83
|
const configurationAlternatives = this.configurationAlternativesFor(taskElement);
|
|
79
84
|
for (let i = 0; i < configurationAlternatives.length; i++) {
|
|
85
|
+
const configurationAlternative = configurationAlternatives[i];
|
|
80
86
|
let inputSourceMap;
|
|
81
87
|
try {
|
|
82
|
-
const instrumenter = istanbul.createInstrumenter(
|
|
83
|
-
inputSourceMap = this.loadInputSourceMap(inputFileSource, taskElement);
|
|
88
|
+
const instrumenter = istanbul.createInstrumenter(configurationAlternative);
|
|
89
|
+
inputSourceMap = this.loadInputSourceMap(inputFileSource, taskElement.fromFile, taskElement.externalSourceMapFile);
|
|
84
90
|
// Based on the source maps of the file to instrument, we can now
|
|
85
91
|
// decide if we should NOT write an instrumented version of it
|
|
86
92
|
// and use the original code instead and write it to the target path.
|
|
87
93
|
//
|
|
88
|
-
|
|
94
|
+
const originSourceFiles = (_a = inputSourceMap === null || inputSourceMap === void 0 ? void 0 : inputSourceMap.sources) !== null && _a !== void 0 ? _a : [];
|
|
95
|
+
if (this.shouldExcludeFromInstrumentation(sourcePattern, taskElement.fromFile, originSourceFiles)) {
|
|
89
96
|
fs.writeFileSync(taskElement.toFile, inputFileSource);
|
|
90
97
|
return new Task_1.TaskResult(0, 1, 0, 0, 0, 0, 0);
|
|
91
98
|
}
|
|
@@ -95,6 +102,9 @@ class IstanbulInstrumenter {
|
|
|
95
102
|
.replace(/return actualCoverage/g, 'return makeCoverageInterceptor(actualCoverage)')
|
|
96
103
|
.replace(/new Function\("return this"\)\(\)/g, "typeof window === 'object' ? window : this");
|
|
97
104
|
this.logger.debug('Instrumentation source maps to:', (_b = instrumenter.lastSourceMap()) === null || _b === void 0 ? void 0 : _b.sources);
|
|
105
|
+
// In case of a bundle, the initial instrumentation step might have added
|
|
106
|
+
// too much and undesired instrumentations. Remove them now.
|
|
107
|
+
instrumentedSource = await this.removeUnwantedInstrumentation(taskElement, instrumentedSource, configurationAlternative, sourcePattern);
|
|
98
108
|
// The process also can result in a new source map that we will append in the result.
|
|
99
109
|
//
|
|
100
110
|
// `lastSourceMap` === Sourcemap for the last file that was instrumented.
|
|
@@ -119,13 +129,39 @@ class IstanbulInstrumenter {
|
|
|
119
129
|
fs.writeFileSync(taskElement.toFile, `${exports.IS_INSTRUMENTED_TOKEN} ${vaccineSource} ${instrumentedSource} \n${finalSourceMap}`);
|
|
120
130
|
return new Task_1.TaskResult(1, 0, 0, 0, 0, 0, 0);
|
|
121
131
|
}
|
|
132
|
+
async removeUnwantedInstrumentation(taskElement, instrumentedSource, configurationAlternative, sourcePattern) {
|
|
133
|
+
// Read the source map from the instrumented file
|
|
134
|
+
const instrumentedSourceMapConsumer = await this.loadSourceMap(instrumentedSource, taskElement.fromFile);
|
|
135
|
+
// Without a source map, excludes/includes do not work.
|
|
136
|
+
if (!instrumentedSourceMapConsumer) {
|
|
137
|
+
return instrumentedSource;
|
|
138
|
+
}
|
|
139
|
+
// Remove the unwanted instrumentation
|
|
140
|
+
return (0, Cleaner_1.cleanSourceCode)(instrumentedSource, configurationAlternative.esModules, location => {
|
|
141
|
+
const originalPosition = instrumentedSourceMapConsumer.originalPositionFor({
|
|
142
|
+
line: location.start.line,
|
|
143
|
+
column: location.start.column
|
|
144
|
+
});
|
|
145
|
+
if (!originalPosition.source) {
|
|
146
|
+
return true;
|
|
147
|
+
}
|
|
148
|
+
return sourcePattern.isAnyIncluded([originalPosition.source]);
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
async loadSourceMap(instrumentedSource, instrumentedSourceFileName) {
|
|
152
|
+
const instrumentedSourceMap = this.loadInputSourceMap(instrumentedSource, instrumentedSourceFileName, typescript_optional_1.Optional.empty());
|
|
153
|
+
if (instrumentedSourceMap) {
|
|
154
|
+
return await new source_map_1.SourceMapConsumer(instrumentedSourceMap);
|
|
155
|
+
}
|
|
156
|
+
return undefined;
|
|
157
|
+
}
|
|
122
158
|
/**
|
|
123
159
|
* Loads the vaccine from the vaccine file and adjusts some template parameters.
|
|
124
160
|
*
|
|
125
161
|
* @param collector - The collector to send coverage information to.
|
|
126
162
|
*/
|
|
127
163
|
loadVaccine(collector) {
|
|
128
|
-
// We first replace
|
|
164
|
+
// We first replace parameters in the file with the
|
|
129
165
|
// actual values, for example, the collector to send the coverage information to.
|
|
130
166
|
return fs
|
|
131
167
|
.readFileSync(this.vaccineFilePath, 'utf8')
|
|
@@ -166,21 +202,22 @@ class IstanbulInstrumenter {
|
|
|
166
202
|
];
|
|
167
203
|
}
|
|
168
204
|
/**
|
|
169
|
-
* Given a source code file
|
|
205
|
+
* Given a source code file, load the corresponding sourcemap.
|
|
170
206
|
*
|
|
171
207
|
* @param inputSource - The source code that might contain sourcemap comments.
|
|
172
|
-
* @param
|
|
208
|
+
* @param taskFile - The name of the file the `inputSource` is from.
|
|
209
|
+
* @param externalSourceMapFile - An external source map file to consider.
|
|
173
210
|
*/
|
|
174
|
-
loadInputSourceMap(
|
|
175
|
-
if (
|
|
176
|
-
const sourceMapOrigin =
|
|
211
|
+
loadInputSourceMap(inputSourceCode, taskFile, externalSourceMapFile) {
|
|
212
|
+
if (externalSourceMapFile.isPresent()) {
|
|
213
|
+
const sourceMapOrigin = externalSourceMapFile.get();
|
|
177
214
|
if (!(sourceMapOrigin instanceof Task_1.SourceMapFileReference)) {
|
|
178
215
|
throw new commons_1.IllegalArgumentException('Type of source map not yet supported!');
|
|
179
216
|
}
|
|
180
217
|
return sourceMapFromMapFile(sourceMapOrigin.sourceMapFilePath);
|
|
181
218
|
}
|
|
182
219
|
else {
|
|
183
|
-
return sourceMapFromCodeComment(
|
|
220
|
+
return sourceMapFromCodeComment(inputSourceCode, taskFile);
|
|
184
221
|
}
|
|
185
222
|
}
|
|
186
223
|
}
|
|
@@ -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;CAK3B;AAED;;;GAGG;AACH,qBAAa,kBAAkB;IAC9B,2CAA2C;IAC3C,SAAgB,IAAI,EAAE,MAAM,CAAC;IAE7B,gDAAgD;IAChD,SAAgB,IAAI,EAAE,MAAM,CAAC;gBAEjB,SAAS,EAAE,MAAM;CAK7B;AAED;;;;;;GAMG;AAC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AAU;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"}
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -91,6 +95,9 @@ class OriginSourcePattern {
|
|
|
91
95
|
*/
|
|
92
96
|
isAnyIncluded(originFiles) {
|
|
93
97
|
var _a;
|
|
98
|
+
if (originFiles.length === 0) {
|
|
99
|
+
return true;
|
|
100
|
+
}
|
|
94
101
|
const normalizedOriginFiles = originFiles.map(OriginSourcePattern.normalizePath);
|
|
95
102
|
if (this.exclude) {
|
|
96
103
|
const matchedToExclude = matching.match(normalizedOriginFiles, this.exclude);
|
|
@@ -114,9 +121,11 @@ class OriginSourcePattern {
|
|
|
114
121
|
return OriginSourcePattern.removeTrailingCurrentWorkingDir(toNormalize);
|
|
115
122
|
}
|
|
116
123
|
static removeTrailingCurrentWorkingDir(removeFrom) {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
124
|
+
return OriginSourcePattern.removePrefix('webpack:///', OriginSourcePattern.removePrefix('.' + path_1.default.sep, removeFrom));
|
|
125
|
+
}
|
|
126
|
+
static removePrefix(prefix, removeFrom) {
|
|
127
|
+
if (removeFrom.startsWith(prefix)) {
|
|
128
|
+
return removeFrom.substring(prefix.length);
|
|
120
129
|
}
|
|
121
130
|
return removeFrom;
|
|
122
131
|
}
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
package/dist/src/main.js
CHANGED
|
File without changes
|
package/dist/vaccine.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{var
|
|
1
|
+
(()=>{var R=Object.create;var h=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var $=Object.getOwnPropertyNames;var I=Object.getPrototypeOf,A=Object.prototype.hasOwnProperty;var j=e=>h(e,"__esModule",{value:!0});var v=(e,n)=>()=>(n||e((n={exports:{}}).exports,n),n.exports);var L=(e,n,t)=>{if(n&&typeof n=="object"||typeof n=="function")for(let o of $(n))!A.call(e,o)&&o!=="default"&&h(e,o,{get:()=>n[o],enumerable:!(t=y(n,o))||t.enumerable});return e},b=e=>L(j(h(e!=null?R(I(e)):{},"default",e&&e.__esModule&&"default"in e?{get:()=>e.default,enumerable:!0}:{value:e,enumerable:!0})),e);var E=v((K,C)=>{C.exports=!1});var W=v(()=>{});function f(e){let n=new Blob([e],{type:"text/javascript"}),t=URL.createObjectURL(n),o=new Worker(t);return URL.revokeObjectURL(t),o}function p(){return f('var i=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(){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)}};var p=20,f=1e3,c=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)}},n=class{constructor(e){this.socket=e,this.cachedCoveredPositions=new Map,this.numberOfCachedPositions=0,this.flushCountdown=new c(f,()=>this.flush())}add(e){let t=e.split(":");if(t.length!==3)return;let[r,d,u]=t,o=this.cachedCoveredPositions.get(r);o||(o=new Set,this.cachedCoveredPositions.set(r,o)),o.add(`${d}:${u}`),this.numberOfCachedPositions+=1,this.flushCountdown.restartCountdown(),this.numberOfCachedPositions>=p&&this.flush()}flush(){this.numberOfCachedPositions!==0&&(this.flushCountdown.stopCountdown(),this.cachedCoveredPositions.forEach((e,t)=>{this.socket.send(`${"c"} ${t} ${Array.from(e).join(" ")}`)}),this.cachedCoveredPositions=new Map,this.numberOfCachedPositions=0)}};console.log("Starting coverage forwarding worker.");var h=new i("ws://$REPORT_TO_HOST:$REPORT_TO_PORT/socket"),a=new n(h);onmessage=s=>{let e=s.data;e.startsWith("s")?h.send(e):e==="unload"?a.flush():a.add(e)};\n')}function u(){return c()}function k(){return typeof window!="undefined"}function c(){return window}function m(e,n){let t=u()[e];return t||(t=n,u()[e]=t),t}var D="s",S=class{constructor(n,t){this.coverageObj=n;this.path=t}get(n,t,o){let r=n[t];return r!==Object(r)?r:w(this.coverageObj,r,[...this.path,t])}set(n,t,o){let r=[...this.path,t];if(r[0]===D){let i=this.coverageObj.hash,s=this.coverageObj.statementMap[r[1]].start;u()._$Bc(i,s.line,s.column)}return!0}};function w(e,n,t){return new Proxy(n,new S(e,t))}var M=b(E());function H(e){if(!(typeof WorkerGlobalScope=="function"&&self instanceof WorkerGlobalScope)){if(typeof window.addEventListener!="function")return;window.addEventListener("beforeunload",function(){e()},!0),window.addEventListener("unload",function(){e()},!0)}}var O={add:H};var T=b(W()),B=M.default?T.default:O,d=new Set,x=!1;function G(){x||(x=!0,B.add(U))}function P(e){if(G(),typeof e!="function")throw new Error("Listener is no function");d.add(e);var n={remove:function(){return d.delete(e)},run:function(){return d.delete(e),e()}};return n}function U(){var e=[];return d.forEach(function(n){e.push(n()),d.delete(n)}),Promise.all(e)}var l;(function(t){t.MESSAGE_TYPE_SOURCEMAP="s",t.MESSAGE_TYPE_COVERAGE="c"})(l||(l={}));var _=m("__TS_AGENT",{});function g(){return _._$BcWorker}function N(e){return _._$BcWorker=e,e}u().makeCoverageInterceptor=function(e){let n=e.hash;if(!g()){let t=N(new p);(function(){let r=function(i){let s=c()[i];c()[i]=function(...a){if(t.postMessage("unload"),s)return s.apply(this,a)},k()&&Object.defineProperty(c(),i,{get:function(){return s},set:function(a){s=a}})};r("onunload"),r("onbeforeunload"),P(()=>t.postMessage("unload"))})()}return function(){let o=m("sentMaps",new Set);e.inputSourceMap&&(o.has(e.path)||(g().postMessage(`${l.MESSAGE_TYPE_SOURCEMAP} ${n}:${JSON.stringify(e.inputSourceMap)}`),o.add(e.path)))}(),function(){let o=new Set;u()._$Bc=(r,i,s)=>{let a=`${r}:${i}:${s}`;o.has(a)||(g().postMessage(a),o.add(a))}}(),w(e,e,[])};})();
|
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.25",
|
|
4
4
|
"description": "Istanbul-based coverage instrumenter with coverage forwarding via WebSockets",
|
|
5
5
|
"main": "dist/src/main.js",
|
|
6
6
|
"bin": "dist/src/main.js",
|
|
@@ -12,8 +12,10 @@
|
|
|
12
12
|
"url": "https://github.com/cqse/teamscale-javascript-profiler.git"
|
|
13
13
|
},
|
|
14
14
|
"scripts": {
|
|
15
|
+
"prepublishOnly": "yarn clean && yarn build",
|
|
15
16
|
"clean": "rimraf dist tsconfig.tsbuildinfo",
|
|
16
|
-
"build": "tsc --project tsconfig.json &&
|
|
17
|
+
"build": "tsc --project tsconfig.json && yarn buildVaccine",
|
|
18
|
+
"buildVaccine": "node esbuild.mjs",
|
|
17
19
|
"instrumenter": "node dist/src/main.js",
|
|
18
20
|
"test": "yarn build && NODE_OPTIONS='--experimental-vm-modules' jest --forceExit --coverage --silent=true --detectOpenHandles"
|
|
19
21
|
},
|
|
@@ -21,7 +23,7 @@
|
|
|
21
23
|
"dist/**/*"
|
|
22
24
|
],
|
|
23
25
|
"devDependencies": {
|
|
24
|
-
"@babel/core": "^7.
|
|
26
|
+
"@babel/core": "^7.17.5",
|
|
25
27
|
"@babel/plugin-transform-modules-commonjs": "^7.15.4",
|
|
26
28
|
"@babel/preset-env": "^7.14.1",
|
|
27
29
|
"@types/async": "^3.2.6",
|
|
@@ -44,6 +46,10 @@
|
|
|
44
46
|
"typescript": "^4.4.3"
|
|
45
47
|
},
|
|
46
48
|
"dependencies": {
|
|
49
|
+
"@babel/generator": "^7.17.3",
|
|
50
|
+
"@babel/parser": "^7.17.3",
|
|
51
|
+
"@babel/traverse": "^7.17.3",
|
|
52
|
+
"@babel/types": "^7.17.0",
|
|
47
53
|
"@cqse/commons": "^0.0.1-beta.1",
|
|
48
54
|
"@types/micromatch": "^4.0.2",
|
|
49
55
|
"argparse": "^2.0.1",
|
|
@@ -55,7 +61,7 @@
|
|
|
55
61
|
"micromatch": "4.0.4",
|
|
56
62
|
"mkdirp": "^1.0.4",
|
|
57
63
|
"nyc": "^15.1.0",
|
|
58
|
-
"source-map": "0.
|
|
64
|
+
"source-map": "0.7.3",
|
|
59
65
|
"typescript-optional": "^2.0.1",
|
|
60
66
|
"unload": "^2.2.0",
|
|
61
67
|
"web-worker": "^1.0.0",
|
package/CHANGELOG.md
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
We use [Semantic Versioning](https://semver.org/).
|
|
2
|
-
|
|
3
|
-
# New Release
|
|
4
|
-
|
|
5
|
-
# 0.0.1-beta.21
|
|
6
|
-
|
|
7
|
-
- [fix] Include/exclude pattern and the paths to match were not normalized
|
|
8
|
-
|
|
9
|
-
# 0.0.1-beta.20
|
|
10
|
-
|
|
11
|
-
- [feature] Automatic release now for NPM packages and Docker images
|