@teamscale/javascript-instrumenter 0.0.1-beta.45 → 0.0.1-beta.48
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 +2 -2
- package/dist/src/App.d.ts +5 -0
- package/dist/src/App.d.ts.map +1 -1
- package/dist/src/App.js +44 -1
- package/dist/src/instrumenter/Instrumenter.d.ts +2 -2
- package/dist/src/instrumenter/Instrumenter.d.ts.map +1 -1
- package/dist/src/instrumenter/Instrumenter.js +9 -2
- package/dist/src/instrumenter/Task.d.ts +23 -11
- package/dist/src/instrumenter/Task.d.ts.map +1 -1
- package/dist/src/instrumenter/Task.js +54 -37
- package/dist/src/instrumenter/TaskBuilder.d.ts +9 -4
- package/dist/src/instrumenter/TaskBuilder.d.ts.map +1 -1
- package/dist/src/instrumenter/TaskBuilder.js +11 -6
- package/package.json +2 -2
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.48",
|
|
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",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"@babel/parser": "^7.18.5",
|
|
52
52
|
"@babel/traverse": "^7.18.6",
|
|
53
53
|
"@babel/types": "^7.18.4",
|
|
54
|
-
"@cqse/commons": "^0.0.1-beta.
|
|
54
|
+
"@cqse/commons": "^0.0.1-beta.45",
|
|
55
55
|
"@types/micromatch": "^4.0.2",
|
|
56
56
|
"argparse": "^2.0.1",
|
|
57
57
|
"async": "^3.2.4",
|
package/dist/src/App.d.ts
CHANGED
|
@@ -10,6 +10,11 @@ export declare class App {
|
|
|
10
10
|
* Parses the command line options and the instrumentation accordingly.
|
|
11
11
|
*/
|
|
12
12
|
static run(): Promise<TaskResult>;
|
|
13
|
+
/**
|
|
14
|
+
* Sometimes we get inputs from shell environments where the strings are
|
|
15
|
+
* still quoted. We remove those here.
|
|
16
|
+
*/
|
|
17
|
+
static postprocessConfig(config: ConfigurationParameters): void;
|
|
13
18
|
/**
|
|
14
19
|
* Build the command line argument parser.
|
|
15
20
|
*/
|
package/dist/src/App.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"App.d.ts","sourceRoot":"","sources":["../../src/App.ts"],"names":[],"mappings":"AACA,OAAO,EAAuB,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAGtE,OAAO,EAAE,uBAAuB,EAAe,MAAM,4BAA4B,CAAC;AAKlF,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B;;GAEG;AACH,qBAAa,GAAG;IACf;;;OAGG;WACiB,GAAG,IAAI,OAAO,CAAC,UAAU,CAAC;IAa9C;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,WAAW;
|
|
1
|
+
{"version":3,"file":"App.d.ts","sourceRoot":"","sources":["../../src/App.ts"],"names":[],"mappings":"AACA,OAAO,EAAuB,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAGtE,OAAO,EAAE,uBAAuB,EAAe,MAAM,4BAA4B,CAAC;AAKlF,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B;;GAEG;AACH,qBAAa,GAAG;IACf;;;OAGG;WACiB,GAAG,IAAI,OAAO,CAAC,UAAU,CAAC;IAa9C;;;OAGG;WACW,iBAAiB,CAAC,MAAM,EAAE,uBAAuB,GAAG,IAAI;IAoCtE;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,WAAW;IAyC1B;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,WAAW;IA8B1B;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,gBAAgB;IAI/B;;;;;OAKG;WACW,qBAAqB,CAAC,MAAM,EAAE,uBAAuB,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;IAS1G,OAAO,CAAC,MAAM,CAAC,yBAAyB;IAIxC,OAAO,CAAC,MAAM,CAAC,kBAAkB;CAajC"}
|
package/dist/src/App.js
CHANGED
|
@@ -54,6 +54,44 @@ class App {
|
|
|
54
54
|
// Run the instrumenter with the given configuration.
|
|
55
55
|
return this.runForConfigArguments(config, logger);
|
|
56
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* Sometimes we get inputs from shell environments where the strings are
|
|
59
|
+
* still quoted. We remove those here.
|
|
60
|
+
*/
|
|
61
|
+
static postprocessConfig(config) {
|
|
62
|
+
function unquoteString(originalString) {
|
|
63
|
+
if (originalString === undefined) {
|
|
64
|
+
return originalString;
|
|
65
|
+
}
|
|
66
|
+
return originalString.replace(/^["'](.+(?=["']$))["']$/, '$1');
|
|
67
|
+
}
|
|
68
|
+
function unquoteStringElements(originalArray) {
|
|
69
|
+
if (originalArray === undefined) {
|
|
70
|
+
return undefined;
|
|
71
|
+
}
|
|
72
|
+
return originalArray.map(s => {
|
|
73
|
+
if (typeof s === 'string') {
|
|
74
|
+
return unquoteString(s);
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
return s;
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
for (const [property, value] of Object.entries(config)) {
|
|
82
|
+
if (value === undefined) {
|
|
83
|
+
// In case the value is 'undefined' we can ignore this.
|
|
84
|
+
}
|
|
85
|
+
else if (typeof value === 'string') {
|
|
86
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
87
|
+
config[property] = unquoteString(value);
|
|
88
|
+
}
|
|
89
|
+
else if (Array.isArray(value)) {
|
|
90
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
91
|
+
config[property] = unquoteStringElements(value);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
57
95
|
/**
|
|
58
96
|
* Build the command line argument parser.
|
|
59
97
|
*/
|
|
@@ -71,7 +109,7 @@ class App {
|
|
|
71
109
|
help: 'Path (directory or file name) to write the instrumented version to.'
|
|
72
110
|
});
|
|
73
111
|
parser.add_argument('-s', '--source-map', {
|
|
74
|
-
help: 'External location of source-map files to consider.'
|
|
112
|
+
help: 'External location of source-map files to consider.',
|
|
75
113
|
});
|
|
76
114
|
parser.add_argument('-c', '--collector', {
|
|
77
115
|
help: 'The collector (`host:port` or `wss://host:port/` or `ws://host:port/`) to send coverage information to.',
|
|
@@ -85,6 +123,10 @@ class App {
|
|
|
85
123
|
nargs: '*',
|
|
86
124
|
help: 'Glob pattern(s) of files in the source origin to produce coverage for. Multiple patterns can be separated by space.'
|
|
87
125
|
});
|
|
126
|
+
parser.add_argument('-e', '--exclude-bundle', {
|
|
127
|
+
nargs: '*',
|
|
128
|
+
help: 'Glob pattern(s) of input (bundle) files to keep unchanged (to not instrument).'
|
|
129
|
+
});
|
|
88
130
|
parser.add_argument('-p', '--dump-origins-to', {
|
|
89
131
|
help: 'Optional location specifying where to dump possible origins from the source map as a json file'
|
|
90
132
|
});
|
|
@@ -130,6 +172,7 @@ class App {
|
|
|
130
172
|
* @param logger - The logger to use.
|
|
131
173
|
*/
|
|
132
174
|
static runForConfigArguments(config, logger) {
|
|
175
|
+
this.postprocessConfig(config);
|
|
133
176
|
const task = this.createInstrumentationTask(config);
|
|
134
177
|
commons_1.Contract.require(task.elements.length > 0, 'The instrumentation task must not be empty.');
|
|
135
178
|
return this.createInstrumenter(logger !== null && logger !== void 0 ? logger : this.buildDummyLogger()).instrument(task);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CollectorSpecifier, InstrumentationTask, OriginSourcePattern, SourceMapReference, TaskElement, TaskResult } from './Task';
|
|
1
|
+
import { CollectorSpecifier, FileExcludePattern, InstrumentationTask, OriginSourcePattern, SourceMapReference, TaskElement, TaskResult } from './Task';
|
|
2
2
|
import { RawSourceMap, SourceMapConsumer } from 'source-map';
|
|
3
3
|
import { Optional } from 'typescript-optional';
|
|
4
4
|
import Logger from 'bunyan';
|
|
@@ -41,7 +41,7 @@ export declare class IstanbulInstrumenter implements IInstrumenter {
|
|
|
41
41
|
* @param sourcePattern - A pattern to restrict the instrumentation to only a fraction of the task element.
|
|
42
42
|
* @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
43
|
*/
|
|
44
|
-
instrumentOne(collector: CollectorSpecifier, taskElement: TaskElement, sourcePattern: OriginSourcePattern, dumpOriginsFile: string | undefined): Promise<TaskResult>;
|
|
44
|
+
instrumentOne(collector: CollectorSpecifier, taskElement: TaskElement, excludeBundles: FileExcludePattern, sourcePattern: OriginSourcePattern, dumpOriginsFile: string | undefined): Promise<TaskResult>;
|
|
45
45
|
private removeUnwantedInstrumentation;
|
|
46
46
|
/**
|
|
47
47
|
* Loads the vaccine from the vaccine file and adjusts some template parameters.
|
|
@@ -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":["../../../src/instrumenter/Instrumenter.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,kBAAkB,EAAE,kBAAkB,EACtC,mBAAmB,EACnB,mBAAmB,EAEnB,kBAAkB,EAClB,WAAW,EACX,UAAU,EACV,MAAM,QAAQ,CAAC;AAEhB,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAO7D,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,MAAM,MAAM,QAAQ,CAAC;AAG5B,eAAO,MAAM,qBAAqB,8CAA8C,CAAC;AAEjF;;GAEG;AACH,MAAM,WAAW,aAAa;IAC7B;;;;OAIG;IACH,UAAU,CAAC,IAAI,EAAE,mBAAmB,GAAG,OAAO,CAAC,UAAU,CA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AGlF"}
|
|
@@ -57,7 +57,7 @@ class IstanbulInstrumenter {
|
|
|
57
57
|
// not overuse memory (NodeJS has only limited mem to use).
|
|
58
58
|
return async_1.default
|
|
59
59
|
.mapLimit(task.elements, 1, async (taskElement) => {
|
|
60
|
-
return await this.instrumentOne(task.collector, taskElement, task.originSourcePattern, task.dumpOriginsFile);
|
|
60
|
+
return await this.instrumentOne(task.collector, taskElement, task.excludeFilesPattern, task.originSourcePattern, task.dumpOriginsFile);
|
|
61
61
|
})
|
|
62
62
|
.then(results => {
|
|
63
63
|
return results.reduce((prev, curr) => {
|
|
@@ -73,7 +73,7 @@ class IstanbulInstrumenter {
|
|
|
73
73
|
* @param sourcePattern - A pattern to restrict the instrumentation to only a fraction of the task element.
|
|
74
74
|
* @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
75
|
*/
|
|
76
|
-
async instrumentOne(collector, taskElement, sourcePattern, dumpOriginsFile) {
|
|
76
|
+
async instrumentOne(collector, taskElement, excludeBundles, sourcePattern, dumpOriginsFile) {
|
|
77
77
|
var _a, _b;
|
|
78
78
|
const inputFileSource = fs.readFileSync(taskElement.fromFile, 'utf8');
|
|
79
79
|
// We skip files that we have already instrumented
|
|
@@ -83,6 +83,13 @@ class IstanbulInstrumenter {
|
|
|
83
83
|
}
|
|
84
84
|
return new Task_1.TaskResult(0, 0, 0, 1, 0, 0, 0);
|
|
85
85
|
}
|
|
86
|
+
// We might want to skip the instrumentation of the file
|
|
87
|
+
if (excludeBundles.isExcluded(taskElement.fromFile)) {
|
|
88
|
+
if (!taskElement.isInPlace()) {
|
|
89
|
+
writeToFile(taskElement.toFile, inputFileSource);
|
|
90
|
+
}
|
|
91
|
+
return new Task_1.TaskResult(0, 1, 0, 0, 0, 0, 0);
|
|
92
|
+
}
|
|
86
93
|
// Not all file types are supported by the instrumenter
|
|
87
94
|
if (!this.isFileTypeSupported(taskElement.fromFile)) {
|
|
88
95
|
return new Task_1.TaskResult(0, 0, 0, 0, 1, 0, 0);
|
|
@@ -46,12 +46,6 @@ export declare class OriginSourcePattern {
|
|
|
46
46
|
*/
|
|
47
47
|
private readonly exclude;
|
|
48
48
|
constructor(include: string[] | undefined, exclude: string[] | undefined);
|
|
49
|
-
/**
|
|
50
|
-
* Normalizes all patterns (normally either include or exclude patterns), and returns all
|
|
51
|
-
* valid normalized patterns. Returns undefined if the patterns list is undefined, or all
|
|
52
|
-
* items inside the list are undefined.
|
|
53
|
-
*/
|
|
54
|
-
private normalizePatterns;
|
|
55
49
|
/**
|
|
56
50
|
* Does the given pattern require to include the given set of files?
|
|
57
51
|
*
|
|
@@ -65,10 +59,20 @@ export declare class OriginSourcePattern {
|
|
|
65
59
|
* or (2) `true` if at least one of the files is supposed to be included.
|
|
66
60
|
*/
|
|
67
61
|
isAnyIncluded(originFiles: string[]): boolean;
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Pattern describing files (bundles) to not instrument.
|
|
65
|
+
*/
|
|
66
|
+
export declare class FileExcludePattern {
|
|
67
|
+
/**
|
|
68
|
+
* Glob pattern describing a set of files to be excluded in the instrumentation process.
|
|
69
|
+
*/
|
|
70
|
+
private readonly exclude;
|
|
71
|
+
constructor(exclude: string[] | undefined);
|
|
72
|
+
/**
|
|
73
|
+
* Return `true` if the given `filePath` is matched by any of the patterns in `exclude`.
|
|
74
|
+
*/
|
|
75
|
+
isExcluded(filePath: string): boolean;
|
|
72
76
|
}
|
|
73
77
|
/**
|
|
74
78
|
* The actual instrumentation task.
|
|
@@ -87,8 +91,16 @@ export declare class InstrumentationTask {
|
|
|
87
91
|
* based on the original file names the code was transpiled from.
|
|
88
92
|
*/
|
|
89
93
|
readonly originSourcePattern: OriginSourcePattern;
|
|
94
|
+
/**
|
|
95
|
+
* A pattern describing the set of files to not instrument but to output
|
|
96
|
+
* without adding instrumentations.
|
|
97
|
+
*/
|
|
98
|
+
readonly excludeFilesPattern: FileExcludePattern;
|
|
99
|
+
/**
|
|
100
|
+
* File to write the file-origin-mapping to.
|
|
101
|
+
*/
|
|
90
102
|
readonly dumpOriginsFile: string | undefined;
|
|
91
|
-
constructor(collector: CollectorSpecifier, elements: TaskElement[], originSourcePattern: OriginSourcePattern, dumpOriginsFile: string | undefined);
|
|
103
|
+
constructor(collector: CollectorSpecifier, elements: TaskElement[], excludeFilesPattern: FileExcludePattern, originSourcePattern: OriginSourcePattern, dumpOriginsFile: string | undefined);
|
|
92
104
|
/**
|
|
93
105
|
* @returns the elements of the task.
|
|
94
106
|
*/
|
|
@@ -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,oEAAoE;IACpE,SAAgB,GAAG,EAAE,MAAM,CAAC;gBAEhB,SAAS,EAAE,MAAM;CAW7B;AAED;;;;;;GAMG;AACH,qBAAa,mBAAmB;IAC/B,mGAAmG;IACnG,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAuB;IAE/C;;;OAGG;IACH,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAuB;gBAEnC,OAAO,EAAE,MAAM,EAAE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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"}
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.SourceMapFileReference = exports.TaskResult = exports.InstrumentationTask = exports.OriginSourcePattern = exports.CollectorSpecifier = exports.TaskElement = exports.SourceMapReference = void 0;
|
|
6
|
+
exports.SourceMapFileReference = exports.TaskResult = exports.InstrumentationTask = exports.FileExcludePattern = exports.OriginSourcePattern = exports.CollectorSpecifier = exports.TaskElement = exports.SourceMapReference = void 0;
|
|
7
7
|
const typescript_optional_1 = require("typescript-optional");
|
|
8
8
|
const commons_1 = require("@cqse/commons");
|
|
9
9
|
const micromatch_1 = __importDefault(require("micromatch"));
|
|
@@ -62,25 +62,8 @@ exports.CollectorSpecifier = CollectorSpecifier;
|
|
|
62
62
|
*/
|
|
63
63
|
class OriginSourcePattern {
|
|
64
64
|
constructor(include, exclude) {
|
|
65
|
-
this.include =
|
|
66
|
-
this.exclude =
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Normalizes all patterns (normally either include or exclude patterns), and returns all
|
|
70
|
-
* valid normalized patterns. Returns undefined if the patterns list is undefined, or all
|
|
71
|
-
* items inside the list are undefined.
|
|
72
|
-
*/
|
|
73
|
-
normalizePatterns(patterns) {
|
|
74
|
-
if (patterns === undefined || patterns.length === 0) {
|
|
75
|
-
return undefined;
|
|
76
|
-
}
|
|
77
|
-
const normalizedPatterns = patterns
|
|
78
|
-
.map(pattern => OriginSourcePattern.normalizeGlobPattern(pattern))
|
|
79
|
-
.filter(pattern => pattern !== undefined);
|
|
80
|
-
if (patterns.length === 0) {
|
|
81
|
-
return undefined;
|
|
82
|
-
}
|
|
83
|
-
return normalizedPatterns;
|
|
65
|
+
this.include = normalizePatterns(include);
|
|
66
|
+
this.exclude = normalizePatterns(exclude);
|
|
84
67
|
}
|
|
85
68
|
/**
|
|
86
69
|
* Does the given pattern require to include the given set of files?
|
|
@@ -98,7 +81,7 @@ class OriginSourcePattern {
|
|
|
98
81
|
if (originFiles.length === 0) {
|
|
99
82
|
return true;
|
|
100
83
|
}
|
|
101
|
-
const normalizedOriginFiles = originFiles.map(
|
|
84
|
+
const normalizedOriginFiles = originFiles.map(normalizePath);
|
|
102
85
|
if (this.exclude) {
|
|
103
86
|
const matchedToExclude = (0, micromatch_1.default)(normalizedOriginFiles, this.exclude);
|
|
104
87
|
if (originFiles.length === matchedToExclude.length) {
|
|
@@ -111,32 +94,66 @@ class OriginSourcePattern {
|
|
|
111
94
|
}
|
|
112
95
|
return true;
|
|
113
96
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
97
|
+
}
|
|
98
|
+
exports.OriginSourcePattern = OriginSourcePattern;
|
|
99
|
+
/**
|
|
100
|
+
* Pattern describing files (bundles) to not instrument.
|
|
101
|
+
*/
|
|
102
|
+
class FileExcludePattern {
|
|
103
|
+
constructor(exclude) {
|
|
104
|
+
var _a;
|
|
105
|
+
this.exclude = (_a = normalizePatterns(exclude)) !== null && _a !== void 0 ? _a : [];
|
|
119
106
|
}
|
|
120
|
-
|
|
121
|
-
|
|
107
|
+
/**
|
|
108
|
+
* Return `true` if the given `filePath` is matched by any of the patterns in `exclude`.
|
|
109
|
+
*/
|
|
110
|
+
isExcluded(filePath) {
|
|
111
|
+
return (0, micromatch_1.default)([filePath], this.exclude).length === 1;
|
|
122
112
|
}
|
|
123
|
-
|
|
124
|
-
|
|
113
|
+
}
|
|
114
|
+
exports.FileExcludePattern = FileExcludePattern;
|
|
115
|
+
/**
|
|
116
|
+
* Normalizes all patterns (normally either include or exclude patterns), and returns all
|
|
117
|
+
* valid normalized patterns. Returns undefined if the patterns list is undefined, or all
|
|
118
|
+
* items inside the list are undefined.
|
|
119
|
+
*/
|
|
120
|
+
function normalizePatterns(patterns) {
|
|
121
|
+
if (patterns === undefined || patterns.length === 0) {
|
|
122
|
+
return undefined;
|
|
125
123
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
return
|
|
124
|
+
const normalizedPatterns = patterns
|
|
125
|
+
.map(pattern => normalizeGlobPattern(pattern))
|
|
126
|
+
.filter(pattern => pattern !== undefined);
|
|
127
|
+
if (patterns.length === 0) {
|
|
128
|
+
return undefined;
|
|
131
129
|
}
|
|
130
|
+
return normalizedPatterns;
|
|
131
|
+
}
|
|
132
|
+
function normalizeGlobPattern(pattern) {
|
|
133
|
+
if (!pattern) {
|
|
134
|
+
return pattern;
|
|
135
|
+
}
|
|
136
|
+
return removeTrailingCurrentWorkingDir(pattern);
|
|
137
|
+
}
|
|
138
|
+
function normalizePath(toNormalize) {
|
|
139
|
+
return removeTrailingCurrentWorkingDir(toNormalize);
|
|
140
|
+
}
|
|
141
|
+
function removeTrailingCurrentWorkingDir(removeFrom) {
|
|
142
|
+
return removePrefix('webpack:///', removePrefix('.' + path_1.default.sep, removeFrom));
|
|
143
|
+
}
|
|
144
|
+
function removePrefix(prefix, removeFrom) {
|
|
145
|
+
if (removeFrom.startsWith(prefix)) {
|
|
146
|
+
return removeFrom.substring(prefix.length);
|
|
147
|
+
}
|
|
148
|
+
return removeFrom;
|
|
132
149
|
}
|
|
133
|
-
exports.OriginSourcePattern = OriginSourcePattern;
|
|
134
150
|
/**
|
|
135
151
|
* The actual instrumentation task.
|
|
136
152
|
*/
|
|
137
153
|
class InstrumentationTask {
|
|
138
|
-
constructor(collector, elements, originSourcePattern, dumpOriginsFile) {
|
|
154
|
+
constructor(collector, elements, excludeFilesPattern, originSourcePattern, dumpOriginsFile) {
|
|
139
155
|
this.collector = commons_1.Contract.requireDefined(collector);
|
|
156
|
+
this.excludeFilesPattern = commons_1.Contract.requireDefined(excludeFilesPattern);
|
|
140
157
|
this.originSourcePattern = commons_1.Contract.requireDefined(originSourcePattern);
|
|
141
158
|
this._elements = commons_1.Contract.requireDefined(elements).slice();
|
|
142
159
|
this.dumpOriginsFile = dumpOriginsFile;
|
|
@@ -9,6 +9,7 @@ export declare type ConfigurationParameters = {
|
|
|
9
9
|
collector: string;
|
|
10
10
|
include_origin?: string[];
|
|
11
11
|
exclude_origin?: string[];
|
|
12
|
+
exclude_bundle?: string[];
|
|
12
13
|
dump_origins_to?: string;
|
|
13
14
|
};
|
|
14
15
|
/**
|
|
@@ -19,19 +20,23 @@ export declare class TaskBuilder {
|
|
|
19
20
|
private readonly elements;
|
|
20
21
|
/** The collector to send the coverage to. */
|
|
21
22
|
private collector;
|
|
22
|
-
/**
|
|
23
|
+
/** Origin include patterns. */
|
|
23
24
|
private originSourceIncludePatterns;
|
|
24
|
-
/**
|
|
25
|
+
/** Origin exclude patters. */
|
|
25
26
|
private originSourceExcludePatterns;
|
|
27
|
+
/** Bundle exclude patters. */
|
|
28
|
+
private bundleFileExcludePatterns;
|
|
26
29
|
/** File path where all origins from the source map should be dumped in json format, or undefined if no origins should be dumped */
|
|
27
30
|
private dumpOriginsFile;
|
|
28
31
|
constructor();
|
|
29
32
|
/** Set the collector by extracting the information from a given string */
|
|
30
33
|
setCollectorFromString(collectorSpecification: string): this;
|
|
31
|
-
/** Set the include pattern. If multiple patterns are present, concatenates them via the OR operator. */
|
|
34
|
+
/** Set the origin include pattern. If multiple patterns are present, concatenates them via the OR operator. */
|
|
32
35
|
setOriginSourceIncludePatterns(patterns: string[] | undefined): this;
|
|
33
|
-
/** Set the exclude pattern(s). If multiple patterns are present, concatenates them via the OR operator. */
|
|
36
|
+
/** Set the origin exclude pattern(s). If multiple patterns are present, concatenates them via the OR operator. */
|
|
34
37
|
setOriginSourceExcludePatterns(patterns: string[] | undefined): this;
|
|
38
|
+
/** Sets the file bundle exclude pattern. If multiple patterns are present, concatenates them via the OR operator. */
|
|
39
|
+
setBundleExcludePatterns(patterns: string[] | undefined): this;
|
|
35
40
|
/** Add a task element */
|
|
36
41
|
addElement(fromFilePath: string, toFilePath: string, fromFileSourceMap?: SourceMapReference): this;
|
|
37
42
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TaskBuilder.d.ts","sourceRoot":"","sources":["../../../src/instrumenter/TaskBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EAEN,mBAAmB,EAGnB,kBAAkB,EAElB,MAAM,QAAQ,CAAC;AAMhB,2DAA2D;AAC3D,oBAAY,uBAAuB,GAAG;IACrC,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAElB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,EAAE,CAAC,EAAE,MAAM,CAAC;IAEZ,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAElB,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAE1B,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAE1B,eAAe,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC;AAkBF;;GAEG;AACH,qBAAa,WAAW;IACvB,gDAAgD;IAChD,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAgB;IAEzC,6CAA6C;IAC7C,OAAO,CAAC,SAAS,CAA4B;IAE7C
|
|
1
|
+
{"version":3,"file":"TaskBuilder.d.ts","sourceRoot":"","sources":["../../../src/instrumenter/TaskBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EAEN,mBAAmB,EAGnB,kBAAkB,EAElB,MAAM,QAAQ,CAAC;AAMhB,2DAA2D;AAC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aAAa,CAAC,MAAM,EAAE,uBAAuB,GAAG,IAAI;IAoCpD;;;;;;;OAOG;IACH,OAAO,CAAC,4CAA4C;IAgCpD;;;;;;OAMG;IACH,OAAO,CAAC,0BAA0B;IASlC;;OAEG;IACI,KAAK,IAAI,mBAAmB;CASnC"}
|
|
@@ -58,16 +58,21 @@ class TaskBuilder {
|
|
|
58
58
|
this.collector = new Task_1.CollectorSpecifier(collectorSpecification);
|
|
59
59
|
return this;
|
|
60
60
|
}
|
|
61
|
-
/** Set the include pattern. If multiple patterns are present, concatenates them via the OR operator. */
|
|
61
|
+
/** Set the origin include pattern. If multiple patterns are present, concatenates them via the OR operator. */
|
|
62
62
|
setOriginSourceIncludePatterns(patterns) {
|
|
63
63
|
this.originSourceIncludePatterns = patterns;
|
|
64
64
|
return this;
|
|
65
65
|
}
|
|
66
|
-
/** Set the exclude pattern(s). If multiple patterns are present, concatenates them via the OR operator. */
|
|
66
|
+
/** Set the origin exclude pattern(s). If multiple patterns are present, concatenates them via the OR operator. */
|
|
67
67
|
setOriginSourceExcludePatterns(patterns) {
|
|
68
68
|
this.originSourceExcludePatterns = patterns;
|
|
69
69
|
return this;
|
|
70
70
|
}
|
|
71
|
+
/** Sets the file bundle exclude pattern. If multiple patterns are present, concatenates them via the OR operator. */
|
|
72
|
+
setBundleExcludePatterns(patterns) {
|
|
73
|
+
this.bundleFileExcludePatterns = patterns;
|
|
74
|
+
return this;
|
|
75
|
+
}
|
|
71
76
|
/** Add a task element */
|
|
72
77
|
addElement(fromFilePath, toFilePath, fromFileSourceMap) {
|
|
73
78
|
this.elements.push(new Task_1.TaskElement(fromFilePath, toFilePath, fromFileSourceMap));
|
|
@@ -88,9 +93,10 @@ class TaskBuilder {
|
|
|
88
93
|
this.setCollectorFromString(config.collector);
|
|
89
94
|
this.setOriginSourceIncludePatterns(config.include_origin);
|
|
90
95
|
this.setOriginSourceExcludePatterns(config.exclude_origin);
|
|
96
|
+
this.setBundleExcludePatterns(config.exclude_bundle);
|
|
91
97
|
// Handle an explicitly specified source map
|
|
92
98
|
const sourceMapInfo = loadSourceMap(sourceMap);
|
|
93
|
-
//
|
|
99
|
+
// If an in place instrumentation is needed
|
|
94
100
|
// the task has to be built differently and different invariants
|
|
95
101
|
// have to be satisfied by the passed configuration.
|
|
96
102
|
if (inPlace) {
|
|
@@ -164,8 +170,7 @@ class TaskBuilder {
|
|
|
164
170
|
* Build the instrumentation task.
|
|
165
171
|
*/
|
|
166
172
|
build() {
|
|
167
|
-
|
|
168
|
-
return new Task_1.InstrumentationTask(commons_1.Contract.requireDefined(this.collector), this.elements, pattern, this.dumpOriginsFile);
|
|
173
|
+
return new Task_1.InstrumentationTask(commons_1.Contract.requireDefined(this.collector), this.elements, new Task_1.FileExcludePattern(this.bundleFileExcludePatterns), new Task_1.OriginSourcePattern(this.originSourceIncludePatterns, this.originSourceExcludePatterns), this.dumpOriginsFile);
|
|
169
174
|
}
|
|
170
175
|
}
|
|
171
176
|
exports.TaskBuilder = TaskBuilder;
|
|
@@ -176,7 +181,7 @@ function isPattern(text) {
|
|
|
176
181
|
return text.includes('*') || text.includes('+') || text.includes('?') || text.includes('|');
|
|
177
182
|
}
|
|
178
183
|
/**
|
|
179
|
-
* Expand the given Glob pattern and check
|
|
184
|
+
* Expand the given Glob pattern and check if files matched.
|
|
180
185
|
* Raises an exception is the result is empty.
|
|
181
186
|
*
|
|
182
187
|
* @param pattern - The Glob pattern used for matching.
|
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.48",
|
|
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",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"@babel/parser": "^7.18.5",
|
|
52
52
|
"@babel/traverse": "^7.18.6",
|
|
53
53
|
"@babel/types": "^7.18.4",
|
|
54
|
-
"@cqse/commons": "^0.0.1-beta.
|
|
54
|
+
"@cqse/commons": "^0.0.1-beta.45",
|
|
55
55
|
"@types/micromatch": "^4.0.2",
|
|
56
56
|
"argparse": "^2.0.1",
|
|
57
57
|
"async": "^3.2.4",
|