@teamscale/javascript-instrumenter 1.0.0-beta.6 → 1.0.0-beta.7
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/README.md +0 -25
- package/dist/package.json +22 -28
- package/dist/src/App.d.ts +0 -36
- package/dist/src/App.d.ts.map +1 -1
- package/dist/src/App.js +4 -54
- package/dist/src/instrumenter/FileSystem.d.ts +0 -28
- package/dist/src/instrumenter/FileSystem.d.ts.map +1 -1
- package/dist/src/instrumenter/FileSystem.js +2 -32
- package/dist/src/instrumenter/Instrumenter.d.ts +2 -69
- package/dist/src/instrumenter/Instrumenter.d.ts.map +1 -1
- package/dist/src/instrumenter/Instrumenter.js +10 -94
- package/dist/src/instrumenter/InstrumenterConfig.d.ts +0 -9
- package/dist/src/instrumenter/InstrumenterConfig.d.ts.map +1 -1
- package/dist/src/instrumenter/InstrumenterConfig.js +0 -6
- package/dist/src/instrumenter/RelativeCollectorPatternParser.d.ts +1 -3
- package/dist/src/instrumenter/RelativeCollectorPatternParser.d.ts.map +1 -1
- package/dist/src/instrumenter/RelativeCollectorPatternParser.js +9 -9
- package/dist/src/instrumenter/RelativeCollectorPatternParser.test.js +12 -7
- package/dist/src/instrumenter/Task.d.ts +0 -144
- package/dist/src/instrumenter/Task.d.ts.map +1 -1
- package/dist/src/instrumenter/Task.js +29 -110
- package/dist/src/instrumenter/TaskBuilder.d.ts +0 -50
- package/dist/src/instrumenter/TaskBuilder.d.ts.map +1 -1
- package/dist/src/instrumenter/TaskBuilder.js +12 -59
- package/dist/src/instrumenter/WebToolkit.d.ts +0 -27
- package/dist/src/instrumenter/WebToolkit.d.ts.map +1 -1
- package/dist/src/instrumenter/WebToolkit.js +0 -27
- package/dist/src/main.js +3 -1
- package/dist/src/vaccine/types.d.ts +0 -37
- package/dist/src/vaccine/types.d.ts.map +1 -1
- package/dist/vaccine.js +1 -1
- package/package.json +13 -13
|
@@ -8,52 +8,32 @@ exports.createCollectorSpecifier = createCollectorSpecifier;
|
|
|
8
8
|
const commons_1 = require("@cqse/commons");
|
|
9
9
|
const micromatch_1 = __importDefault(require("micromatch"));
|
|
10
10
|
const RelativeCollectorPatternParser_1 = require("./RelativeCollectorPatternParser");
|
|
11
|
-
/**
|
|
12
|
-
* An abstract source map type.
|
|
13
|
-
*/
|
|
14
11
|
class SourceMapReference {
|
|
15
12
|
}
|
|
16
13
|
exports.SourceMapReference = SourceMapReference;
|
|
17
|
-
/**
|
|
18
|
-
* One element of an instrumentation task.
|
|
19
|
-
* It corresponds to instrumenting a single file.
|
|
20
|
-
*/
|
|
21
14
|
class TaskElement {
|
|
15
|
+
fromFile;
|
|
16
|
+
toFile;
|
|
17
|
+
externalSourceMapFile;
|
|
22
18
|
constructor(fromFile, toFile, externalSourceMap) {
|
|
23
19
|
this.fromFile = commons_1.Contract.requireDefined(fromFile);
|
|
24
20
|
this.toFile = commons_1.Contract.requireDefined(toFile);
|
|
25
21
|
this.externalSourceMapFile = externalSourceMap;
|
|
26
22
|
}
|
|
27
|
-
/**
|
|
28
|
-
* Is it an in-place instrumentation task?
|
|
29
|
-
*/
|
|
30
23
|
isInPlace() {
|
|
31
|
-
// We assume that different file names link to different files on the storage
|
|
32
|
-
// and abstract from the fact that it might be a symlink.
|
|
33
24
|
return this.fromFile === this.toFile;
|
|
34
25
|
}
|
|
35
26
|
}
|
|
36
27
|
exports.TaskElement = TaskElement;
|
|
37
|
-
/**
|
|
38
|
-
* Given a command-line URL and an optional relative pattern, create a specifier for how the vaccine can
|
|
39
|
-
* locate the connector.
|
|
40
|
-
*
|
|
41
|
-
* If a relative pattern is given, it is preferred, since the command-line interface always provides a URL
|
|
42
|
-
* (the default URL in case the user didn't explicitly specify one).
|
|
43
|
-
*/
|
|
44
28
|
function createCollectorSpecifier(commandLineUrl, relativePattern) {
|
|
45
29
|
if (relativePattern !== undefined) {
|
|
46
30
|
return RelativeCollectorPatternParser_1.RelativeCollectorPatternParser.parse(relativePattern);
|
|
47
31
|
}
|
|
48
32
|
return parseCommandLineUrl(commandLineUrl);
|
|
49
33
|
}
|
|
50
|
-
/**
|
|
51
|
-
* Parses, validates and normalizes the given URL that the user provided on the command-line.
|
|
52
|
-
*/
|
|
53
34
|
function parseCommandLineUrl(commandLineUrl) {
|
|
54
35
|
let url;
|
|
55
36
|
if (commandLineUrl.indexOf('://') > 0) {
|
|
56
|
-
// A trailing slash will be removed
|
|
57
37
|
url = commandLineUrl.replace(/\/$/, '');
|
|
58
38
|
}
|
|
59
39
|
else {
|
|
@@ -67,22 +47,17 @@ function parseCommandLineUrl(commandLineUrl) {
|
|
|
67
47
|
url,
|
|
68
48
|
};
|
|
69
49
|
}
|
|
70
|
-
/**
|
|
71
|
-
* Configuration used to match paths with `micromatch`.
|
|
72
|
-
*/
|
|
73
50
|
const MATCHER_OPTIONS = {
|
|
74
51
|
basename: false,
|
|
75
52
|
lookbehinds: true,
|
|
76
53
|
noglobstar: false
|
|
77
54
|
};
|
|
78
|
-
/**
|
|
79
|
-
* Patterns that define which parts of a given bundle to instrument or not.
|
|
80
|
-
*
|
|
81
|
-
* The patterns describe a set of filenames that can be found in the origin,
|
|
82
|
-
* that is, before conducting all the transpilation steps. The source maps
|
|
83
|
-
* are used to determine the original file names.
|
|
84
|
-
*/
|
|
85
55
|
class OriginSourcePattern {
|
|
56
|
+
include;
|
|
57
|
+
exclude;
|
|
58
|
+
includeMatches;
|
|
59
|
+
excludeMatches;
|
|
60
|
+
neitherExcludedNorIncluded;
|
|
86
61
|
constructor(include, exclude) {
|
|
87
62
|
this.include = normalizePatterns(include);
|
|
88
63
|
this.exclude = normalizePatterns(exclude);
|
|
@@ -90,18 +65,6 @@ class OriginSourcePattern {
|
|
|
90
65
|
this.excludeMatches = new Set();
|
|
91
66
|
this.neitherExcludedNorIncluded = new Set();
|
|
92
67
|
}
|
|
93
|
-
/**
|
|
94
|
-
* Does the given pattern require to include the given file?
|
|
95
|
-
*
|
|
96
|
-
* For example, a JavaScript bundle is compiled from several (origin) source files.
|
|
97
|
-
* If one of the files in the bundle is needed, then the full bundle is needed, that is,
|
|
98
|
-
* this function is required to return `true`.
|
|
99
|
-
*
|
|
100
|
-
* @param originFile - The file to decide for include or exclude.
|
|
101
|
-
*
|
|
102
|
-
* @returns `false` if (1) the given file is supposed to be excluded,
|
|
103
|
-
* or (2) `true` if the given file is supposed to be included.
|
|
104
|
-
*/
|
|
105
68
|
isIncluded(originFile) {
|
|
106
69
|
if (originFile.length === 0) {
|
|
107
70
|
return true;
|
|
@@ -127,55 +90,33 @@ class OriginSourcePattern {
|
|
|
127
90
|
this.neitherExcludedNorIncluded.add(normalizedOriginFile);
|
|
128
91
|
return true;
|
|
129
92
|
}
|
|
130
|
-
/**
|
|
131
|
-
* Variant of `isIncluded` working on a list of files to check.
|
|
132
|
-
* (Primarily, used for testing.)
|
|
133
|
-
*/
|
|
134
93
|
isAnyIncluded(originFiles) {
|
|
135
94
|
return originFiles.find(value => this.isIncluded(value)) !== undefined;
|
|
136
95
|
}
|
|
137
|
-
/**
|
|
138
|
-
* Retrieve the file names that have been matching the different patterns.
|
|
139
|
-
*/
|
|
140
96
|
retrieveMatchingFiles() {
|
|
141
|
-
var _a, _b;
|
|
142
97
|
return {
|
|
143
|
-
includePatterns:
|
|
144
|
-
excludePatterns:
|
|
98
|
+
includePatterns: this.include ?? [],
|
|
99
|
+
excludePatterns: this.exclude ?? [],
|
|
145
100
|
excludeMatches: [...this.excludeMatches],
|
|
146
101
|
includeMatches: [...this.includeMatches],
|
|
147
102
|
neitherExcludedNorIncluded: [...this.neitherExcludedNorIncluded]
|
|
148
103
|
};
|
|
149
104
|
}
|
|
150
|
-
/**
|
|
151
|
-
* Returns if include/exclude patterns are specified.
|
|
152
|
-
*/
|
|
153
105
|
patternsSpecified() {
|
|
154
106
|
return this.include !== undefined || this.exclude !== undefined;
|
|
155
107
|
}
|
|
156
108
|
}
|
|
157
109
|
exports.OriginSourcePattern = OriginSourcePattern;
|
|
158
|
-
/**
|
|
159
|
-
* Pattern describing files (bundles) to not instrument.
|
|
160
|
-
*/
|
|
161
110
|
class FileExcludePattern {
|
|
111
|
+
exclude;
|
|
162
112
|
constructor(exclude) {
|
|
163
|
-
|
|
164
|
-
this.exclude = (_a = normalizePatterns(exclude)) !== null && _a !== void 0 ? _a : [];
|
|
113
|
+
this.exclude = normalizePatterns(exclude) ?? [];
|
|
165
114
|
}
|
|
166
|
-
/**
|
|
167
|
-
* Return `true` if the given `filePath` is matched by any of the patterns in `exclude`.
|
|
168
|
-
*/
|
|
169
115
|
isExcluded(filePath) {
|
|
170
116
|
return micromatch_1.default.isMatch(normalizePath(filePath), this.exclude);
|
|
171
117
|
}
|
|
172
118
|
}
|
|
173
119
|
exports.FileExcludePattern = FileExcludePattern;
|
|
174
|
-
/**
|
|
175
|
-
* Normalizes all patterns (normally either include or exclude patterns), and returns all
|
|
176
|
-
* valid normalized patterns. Returns undefined if the patterns list is undefined, or all
|
|
177
|
-
* items inside the list are undefined.
|
|
178
|
-
*/
|
|
179
120
|
function normalizePatterns(patterns) {
|
|
180
121
|
if (patterns === undefined || patterns.length === 0) {
|
|
181
122
|
return undefined;
|
|
@@ -192,16 +133,11 @@ function normalizeGlobPattern(pattern) {
|
|
|
192
133
|
if (!pattern) {
|
|
193
134
|
return pattern;
|
|
194
135
|
}
|
|
195
|
-
// This should be in line with the logic in `normalizePath`.
|
|
196
136
|
return removeTrailingDirectoryTraversals(removeTrailingCurrentWorkingDir(pattern));
|
|
197
137
|
}
|
|
198
138
|
function normalizePath(toNormalize) {
|
|
199
|
-
// This should be in line with the logic in `normalizeGlobPattern`.
|
|
200
139
|
return removeTrailingDirectoryTraversals(removeTrailingCurrentWorkingDir(toNormalize.replace(/\\/g, '/')));
|
|
201
140
|
}
|
|
202
|
-
/**
|
|
203
|
-
* `micromatch` cannot deal with leading `../`, so we remove those.
|
|
204
|
-
*/
|
|
205
141
|
function removeTrailingDirectoryTraversals(toNormalize) {
|
|
206
142
|
let result = toNormalize;
|
|
207
143
|
while (result.startsWith("../")) {
|
|
@@ -218,10 +154,14 @@ function removePrefix(prefix, removeFrom) {
|
|
|
218
154
|
}
|
|
219
155
|
return removeFrom;
|
|
220
156
|
}
|
|
221
|
-
/**
|
|
222
|
-
* The actual instrumentation task.
|
|
223
|
-
*/
|
|
224
157
|
class InstrumentationTask {
|
|
158
|
+
collector;
|
|
159
|
+
targetBucket;
|
|
160
|
+
_elements;
|
|
161
|
+
originSourcePattern;
|
|
162
|
+
excludeFilesPattern;
|
|
163
|
+
dumpOriginsFile;
|
|
164
|
+
dumpMatchedOriginsFile;
|
|
225
165
|
constructor(collector, targetBucket, elements, excludeFilesPattern, originSourcePattern, dumpOriginsFile, dumpMatchedOriginsFile) {
|
|
226
166
|
this.collector = commons_1.Contract.requireDefined(collector);
|
|
227
167
|
this.targetBucket = commons_1.Contract.requireDefined(targetBucket);
|
|
@@ -231,20 +171,20 @@ class InstrumentationTask {
|
|
|
231
171
|
this.dumpOriginsFile = dumpOriginsFile;
|
|
232
172
|
this.dumpMatchedOriginsFile = dumpMatchedOriginsFile;
|
|
233
173
|
}
|
|
234
|
-
/**
|
|
235
|
-
* @returns the elements of the task.
|
|
236
|
-
*/
|
|
237
174
|
get elements() {
|
|
238
|
-
// Ensure immutability of this object by returning a copy
|
|
239
|
-
// of the list of immutable objects.
|
|
240
175
|
return this._elements.slice();
|
|
241
176
|
}
|
|
242
177
|
}
|
|
243
178
|
exports.InstrumentationTask = InstrumentationTask;
|
|
244
|
-
/**
|
|
245
|
-
* A summary of executing the instrumentation task.
|
|
246
|
-
*/
|
|
247
179
|
class TaskResult {
|
|
180
|
+
translated;
|
|
181
|
+
excluded;
|
|
182
|
+
translatedFromCache;
|
|
183
|
+
alreadyInstrumented;
|
|
184
|
+
unsupported;
|
|
185
|
+
failed;
|
|
186
|
+
warnings;
|
|
187
|
+
task;
|
|
248
188
|
constructor(translated, excluded, translatedFromCache, alreadyInstrumented, unsupported, failed, warnings, task) {
|
|
249
189
|
commons_1.Contract.require(translated > -1);
|
|
250
190
|
commons_1.Contract.require(excluded > -1);
|
|
@@ -262,45 +202,24 @@ class TaskResult {
|
|
|
262
202
|
this.warnings = warnings;
|
|
263
203
|
this.task = task;
|
|
264
204
|
}
|
|
265
|
-
/**
|
|
266
|
-
* Returns the sum of the present task results and the given one.
|
|
267
|
-
*
|
|
268
|
-
* @param incBy - The task result to add (as delta).
|
|
269
|
-
*/
|
|
270
205
|
withIncrement(incBy) {
|
|
271
|
-
|
|
272
|
-
return new TaskResult(this.translated + incBy.translated, this.excluded + incBy.excluded, this.translatedFromCache + incBy.translatedFromCache, this.alreadyInstrumented + incBy.alreadyInstrumented, this.unsupported + incBy.unsupported, this.failed + incBy.failed, this.warnings + incBy.warnings, (_a = this.task) !== null && _a !== void 0 ? _a : incBy.task);
|
|
206
|
+
return new TaskResult(this.translated + incBy.translated, this.excluded + incBy.excluded, this.translatedFromCache + incBy.translatedFromCache, this.alreadyInstrumented + incBy.alreadyInstrumented, this.unsupported + incBy.unsupported, this.failed + incBy.failed, this.warnings + incBy.warnings, this.task ?? incBy.task);
|
|
273
207
|
}
|
|
274
|
-
/**
|
|
275
|
-
* @returns the neutral task element (adding it with {@code withIncrement} does not change the result).
|
|
276
|
-
*/
|
|
277
208
|
static neutral(task) {
|
|
278
209
|
return new TaskResult(0, 0, 0, 0, 0, 0, 0, task);
|
|
279
210
|
}
|
|
280
|
-
/**
|
|
281
|
-
* @returns a task result signaling one error.
|
|
282
|
-
*
|
|
283
|
-
* @param e - The error to add.
|
|
284
|
-
*/
|
|
285
211
|
static error(e) {
|
|
286
212
|
console.error(e);
|
|
287
213
|
return new TaskResult(0, 0, 0, 0, 0, 1, 0);
|
|
288
214
|
}
|
|
289
|
-
/**
|
|
290
|
-
* @returns a task result signaling one warning.
|
|
291
|
-
*
|
|
292
|
-
* @param msg - The warning message to add.
|
|
293
|
-
*/
|
|
294
215
|
static warning(msg) {
|
|
295
216
|
console.warn(msg);
|
|
296
217
|
return new TaskResult(0, 0, 0, 0, 0, 0, 1);
|
|
297
218
|
}
|
|
298
219
|
}
|
|
299
220
|
exports.TaskResult = TaskResult;
|
|
300
|
-
/**
|
|
301
|
-
* A source map in an external file.
|
|
302
|
-
*/
|
|
303
221
|
class SourceMapFileReference extends SourceMapReference {
|
|
222
|
+
sourceMapFilePath;
|
|
304
223
|
constructor(sourceMapFilePath) {
|
|
305
224
|
super();
|
|
306
225
|
this.sourceMapFilePath = sourceMapFilePath;
|
|
@@ -1,75 +1,25 @@
|
|
|
1
1
|
import { InstrumentationTask, SourceMapReference } from './Task';
|
|
2
2
|
import { InstrumenterOptions } from './InstrumenterConfig';
|
|
3
|
-
/**
|
|
4
|
-
* A builder for an instrumentation task.
|
|
5
|
-
*/
|
|
6
3
|
export declare class TaskBuilder {
|
|
7
|
-
/** The elements of the instrumentation task. */
|
|
8
4
|
private readonly elements;
|
|
9
|
-
/** The collector to send the coverage to. */
|
|
10
5
|
private collector;
|
|
11
|
-
/** Origin include patterns. */
|
|
12
6
|
private originSourceIncludePatterns;
|
|
13
|
-
/** Origin exclude patters. */
|
|
14
7
|
private originSourceExcludePatterns;
|
|
15
|
-
/** Bundle exclude patters. */
|
|
16
8
|
private bundleFileExcludePatterns;
|
|
17
|
-
/**
|
|
18
|
-
* File path where all origins from the source map should be dumped in JSON format,
|
|
19
|
-
* or undefined if no origins should be dumped */
|
|
20
9
|
private dumpOriginsFile;
|
|
21
|
-
/**
|
|
22
|
-
* File path where the matched origin file names are stored as JSON,
|
|
23
|
-
* `undefined` if this information should not be dumped.
|
|
24
|
-
*/
|
|
25
10
|
private dumpMatchedOriginsFile;
|
|
26
|
-
/**
|
|
27
|
-
* The bucket within the collector the coverage is supposed to be sent to.
|
|
28
|
-
*/
|
|
29
11
|
private targetBucket;
|
|
30
|
-
/**
|
|
31
|
-
* The automatically generated unique app id to use.
|
|
32
|
-
*/
|
|
33
12
|
private appId;
|
|
34
13
|
constructor();
|
|
35
|
-
/** Set the collector specification based on the command-line arguments. */
|
|
36
14
|
setCollectorFromCommandLine(commandLineUrl: string, relativePattern?: string): this;
|
|
37
|
-
/** Set the coverage bucket to be used within the collector. */
|
|
38
15
|
setCollectorTargetBucket(configId: string | undefined, commit: string, configOptions?: string, appName?: string): this;
|
|
39
|
-
/** Set the origin include pattern. If multiple patterns are present, concatenates them via the OR operator. */
|
|
40
16
|
setOriginSourceIncludePatterns(patterns: string[] | undefined): this;
|
|
41
|
-
/** Set the origin exclude pattern(s). If multiple patterns are present, concatenates them via the OR operator. */
|
|
42
17
|
setOriginSourceExcludePatterns(patterns: string[] | undefined): this;
|
|
43
|
-
/** Sets the file bundle exclude pattern. If multiple patterns are present, concatenates them via the OR operator. */
|
|
44
18
|
setBundleExcludePatterns(patterns: string[] | undefined): this;
|
|
45
|
-
/** Add a task element */
|
|
46
19
|
addElement(fromFilePath: string, toFilePath: string, fromFileSourceMap?: SourceMapReference): this;
|
|
47
|
-
/**
|
|
48
|
-
* Add the task details based on a configuration (command line arguments).
|
|
49
|
-
*
|
|
50
|
-
* @param config - The configuration based on that the task is built.
|
|
51
|
-
*/
|
|
52
20
|
addFromConfig(config: InstrumenterOptions): this;
|
|
53
|
-
/**
|
|
54
|
-
* Adds instrumentation tasks based on a given pattern `inputs` describing the set of
|
|
55
|
-
* input files and produces the output files in the specified output folder `target.
|
|
56
|
-
*
|
|
57
|
-
* @param inputs - Glob pattern describing set of input files
|
|
58
|
-
* @param target - Target folder
|
|
59
|
-
* @param sourceMapInfo - Source map file for all the input files.
|
|
60
|
-
*/
|
|
61
21
|
private addInstrumentationTasksFromPatternWithTarget;
|
|
62
|
-
/**
|
|
63
|
-
* Adds in-place instrumentation tasks for the set of files described
|
|
64
|
-
* by the `inputs` pattern.
|
|
65
|
-
*
|
|
66
|
-
* @param inputs - Glob pattern.
|
|
67
|
-
* @param sourceMapInfo - Source map for the files described by the pattern.
|
|
68
|
-
*/
|
|
69
22
|
private addInPlaceTasksFromPattern;
|
|
70
|
-
/**
|
|
71
|
-
* Build the instrumentation task.
|
|
72
|
-
*/
|
|
73
23
|
build(): InstrumentationTask;
|
|
74
24
|
}
|
|
75
25
|
//# sourceMappingURL=TaskBuilder.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TaskBuilder.d.ts","sourceRoot":"","sources":["../../../src/instrumenter/TaskBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EAEN,mBAAmB,EAGnB,kBAAkB,EAGlB,MAAM,QAAQ,CAAC;AAYhB,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"TaskBuilder.d.ts","sourceRoot":"","sources":["../../../src/instrumenter/TaskBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EAEN,mBAAmB,EAGnB,kBAAkB,EAGlB,MAAM,QAAQ,CAAC;AAYhB,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAuB3D,qBAAa,WAAW;IAEvB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAgB;IAGzC,OAAO,CAAC,SAAS,CAA4B;IAG7C,OAAO,CAAC,2BAA2B,CAAuB;IAG1D,OAAO,CAAC,2BAA2B,CAAuB;IAG1D,OAAO,CAAC,yBAAyB,CAAuB;IAKxD,OAAO,CAAC,eAAe,CAAqB;IAM5C,OAAO,CAAC,sBAAsB,CAAqB;IAKnD,OAAO,CAAC,YAAY,CAAiC;IAKrD,OAAO,CAAC,KAAK,CAAS;;IAUtB,2BAA2B,CAAC,cAAc,EAAE,MAAM,EAAE,eAAe,CAAC,EAAE,MAAM,GAAG,IAAI;IAOnF,wBAAwB,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,aAAa,CAAC,EAAE,MAAM,EACtF,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI;IAQ9B,8BAA8B,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,SAAS,GAAG,IAAI;IAMpE,8BAA8B,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,SAAS,GAAG,IAAI;IAMpE,wBAAwB,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,SAAS,GAAG,IAAI;IAM9D,UAAU,CAAC,YAAY,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,iBAAiB,CAAC,EAAE,kBAAkB,GAAG,IAAI;IAUlG,aAAa,CAAC,MAAM,EAAE,mBAAmB,GAAG,IAAI;IA+ChD,OAAO,CAAC,4CAA4C;IAuCpD,OAAO,CAAC,0BAA0B;IAY3B,KAAK,IAAI,mBAAmB;CAWnC"}
|
|
@@ -40,12 +40,6 @@ const fs = __importStar(require("fs"));
|
|
|
40
40
|
const path = __importStar(require("path"));
|
|
41
41
|
const FileSystem_1 = require("./FileSystem");
|
|
42
42
|
const uuid_1 = require("uuid");
|
|
43
|
-
/**
|
|
44
|
-
* Load a source map object from the given file (path).
|
|
45
|
-
* Exception if the specified file does not exist.
|
|
46
|
-
*
|
|
47
|
-
* @param sourceMapPath - The path to the source map file.
|
|
48
|
-
*/
|
|
49
43
|
function loadSourceMap(sourceMapPath) {
|
|
50
44
|
if (sourceMapPath) {
|
|
51
45
|
if (!fs.existsSync(sourceMapPath)) {
|
|
@@ -55,58 +49,52 @@ function loadSourceMap(sourceMapPath) {
|
|
|
55
49
|
}
|
|
56
50
|
return undefined;
|
|
57
51
|
}
|
|
58
|
-
/**
|
|
59
|
-
* A builder for an instrumentation task.
|
|
60
|
-
*/
|
|
61
52
|
class TaskBuilder {
|
|
53
|
+
elements;
|
|
54
|
+
collector;
|
|
55
|
+
originSourceIncludePatterns;
|
|
56
|
+
originSourceExcludePatterns;
|
|
57
|
+
bundleFileExcludePatterns;
|
|
58
|
+
dumpOriginsFile;
|
|
59
|
+
dumpMatchedOriginsFile;
|
|
60
|
+
targetBucket;
|
|
61
|
+
appId;
|
|
62
62
|
constructor() {
|
|
63
63
|
this.appId = (0, uuid_1.v4)();
|
|
64
64
|
this.elements = [];
|
|
65
65
|
this.collector = null;
|
|
66
66
|
this.targetBucket = null;
|
|
67
67
|
}
|
|
68
|
-
/** Set the collector specification based on the command-line arguments. */
|
|
69
68
|
setCollectorFromCommandLine(commandLineUrl, relativePattern) {
|
|
70
69
|
commons_1.Contract.requireNonEmpty(commandLineUrl, "The collector URL must not be empty");
|
|
71
70
|
this.collector = (0, Task_1.createCollectorSpecifier)(commandLineUrl, relativePattern);
|
|
72
71
|
return this;
|
|
73
72
|
}
|
|
74
|
-
/** Set the coverage bucket to be used within the collector. */
|
|
75
73
|
setCollectorTargetBucket(configId, commit, configOptions, appName) {
|
|
76
74
|
commons_1.Contract.requireNonEmpty(commit, "The commit must not be empty");
|
|
77
75
|
this.appId = generateAppId(appName);
|
|
78
76
|
this.targetBucket = { appId: this.appId, configId, commit, configOptions };
|
|
79
77
|
return this;
|
|
80
78
|
}
|
|
81
|
-
/** Set the origin include pattern. If multiple patterns are present, concatenates them via the OR operator. */
|
|
82
79
|
setOriginSourceIncludePatterns(patterns) {
|
|
83
80
|
this.originSourceIncludePatterns = patterns;
|
|
84
81
|
return this;
|
|
85
82
|
}
|
|
86
|
-
/** Set the origin exclude pattern(s). If multiple patterns are present, concatenates them via the OR operator. */
|
|
87
83
|
setOriginSourceExcludePatterns(patterns) {
|
|
88
84
|
this.originSourceExcludePatterns = patterns;
|
|
89
85
|
return this;
|
|
90
86
|
}
|
|
91
|
-
/** Sets the file bundle exclude pattern. If multiple patterns are present, concatenates them via the OR operator. */
|
|
92
87
|
setBundleExcludePatterns(patterns) {
|
|
93
88
|
this.bundleFileExcludePatterns = patterns;
|
|
94
89
|
return this;
|
|
95
90
|
}
|
|
96
|
-
/** Add a task element */
|
|
97
91
|
addElement(fromFilePath, toFilePath, fromFileSourceMap) {
|
|
98
92
|
this.elements.push(new Task_1.TaskElement(fromFilePath, toFilePath, fromFileSourceMap));
|
|
99
93
|
return this;
|
|
100
94
|
}
|
|
101
|
-
/**
|
|
102
|
-
* Add the task details based on a configuration (command line arguments).
|
|
103
|
-
*
|
|
104
|
-
* @param config - The configuration based on that the task is built.
|
|
105
|
-
*/
|
|
106
95
|
addFromConfig(config) {
|
|
107
|
-
|
|
108
|
-
const
|
|
109
|
-
const inPlace = (_b = config.inPlace) !== null && _b !== void 0 ? _b : false;
|
|
96
|
+
const inputs = (config.input ?? []);
|
|
97
|
+
const inPlace = config.inPlace ?? false;
|
|
110
98
|
const target = config.to;
|
|
111
99
|
const sourceMap = config.sourceMap;
|
|
112
100
|
this.dumpOriginsFile = config.dumpOriginsTo;
|
|
@@ -115,12 +103,8 @@ class TaskBuilder {
|
|
|
115
103
|
this.setOriginSourceIncludePatterns(config.includeOrigin);
|
|
116
104
|
this.setOriginSourceExcludePatterns(config.excludeOrigin);
|
|
117
105
|
this.setBundleExcludePatterns(config.excludeBundle);
|
|
118
|
-
this.setCollectorTargetBucket(config.configId,
|
|
119
|
-
// Handle an explicitly specified source map
|
|
106
|
+
this.setCollectorTargetBucket(config.configId, config.commit ?? 'HEAD', config.collectorConfigFileContent, config.appName);
|
|
120
107
|
const sourceMapInfo = loadSourceMap(sourceMap);
|
|
121
|
-
// If an in-place instrumentation is needed,
|
|
122
|
-
// the task has to be built differently and different invariants
|
|
123
|
-
// have to be satisfied by the passed configuration.
|
|
124
108
|
if (inPlace) {
|
|
125
109
|
if (target) {
|
|
126
110
|
throw new commons_1.InvalidConfigurationException('No target path must be specified in case an in-place instrumentation is enabled.');
|
|
@@ -128,7 +112,6 @@ class TaskBuilder {
|
|
|
128
112
|
this.addInPlaceTasksFromPattern(inputs, sourceMapInfo);
|
|
129
113
|
}
|
|
130
114
|
else if (!inPlace) {
|
|
131
|
-
// A target directory must be specified
|
|
132
115
|
if (!target) {
|
|
133
116
|
throw new commons_1.InvalidConfigurationException('A target path must be specified using `--to`.');
|
|
134
117
|
}
|
|
@@ -136,14 +119,6 @@ class TaskBuilder {
|
|
|
136
119
|
}
|
|
137
120
|
return this;
|
|
138
121
|
}
|
|
139
|
-
/**
|
|
140
|
-
* Adds instrumentation tasks based on a given pattern `inputs` describing the set of
|
|
141
|
-
* input files and produces the output files in the specified output folder `target.
|
|
142
|
-
*
|
|
143
|
-
* @param inputs - Glob pattern describing set of input files
|
|
144
|
-
* @param target - Target folder
|
|
145
|
-
* @param sourceMapInfo - Source map file for all the input files.
|
|
146
|
-
*/
|
|
147
122
|
addInstrumentationTasksFromPatternWithTarget(inputs, target, sourceMapInfo) {
|
|
148
123
|
(0, FileSystem_1.ensureExistingDirectory)(target);
|
|
149
124
|
for (const input of inputs) {
|
|
@@ -173,13 +148,6 @@ class TaskBuilder {
|
|
|
173
148
|
}
|
|
174
149
|
}
|
|
175
150
|
}
|
|
176
|
-
/**
|
|
177
|
-
* Adds in-place instrumentation tasks for the set of files described
|
|
178
|
-
* by the `inputs` pattern.
|
|
179
|
-
*
|
|
180
|
-
* @param inputs - Glob pattern.
|
|
181
|
-
* @param sourceMapInfo - Source map for the files described by the pattern.
|
|
182
|
-
*/
|
|
183
151
|
addInPlaceTasksFromPattern(inputs, sourceMapInfo) {
|
|
184
152
|
inputs
|
|
185
153
|
.map(input => expandAndCheck(input))
|
|
@@ -188,17 +156,11 @@ class TaskBuilder {
|
|
|
188
156
|
}, [])
|
|
189
157
|
.forEach(filePath => this.addElement(filePath, filePath, sourceMapInfo));
|
|
190
158
|
}
|
|
191
|
-
/**
|
|
192
|
-
* Build the instrumentation task.
|
|
193
|
-
*/
|
|
194
159
|
build() {
|
|
195
160
|
return new Task_1.InstrumentationTask(commons_1.Contract.requireDefined(this.collector), commons_1.Contract.requireDefined(this.targetBucket), this.elements, new Task_1.FileExcludePattern(this.bundleFileExcludePatterns), new Task_1.OriginSourcePattern(this.originSourceIncludePatterns, this.originSourceExcludePatterns), this.dumpOriginsFile, this.dumpMatchedOriginsFile);
|
|
196
161
|
}
|
|
197
162
|
}
|
|
198
163
|
exports.TaskBuilder = TaskBuilder;
|
|
199
|
-
/**
|
|
200
|
-
* Generates an application ID, if an `appName` is given, with a user-friendly prefix.
|
|
201
|
-
*/
|
|
202
164
|
function generateAppId(appName) {
|
|
203
165
|
const result = (0, uuid_1.v4)();
|
|
204
166
|
if (appName) {
|
|
@@ -207,18 +169,9 @@ function generateAppId(appName) {
|
|
|
207
169
|
}
|
|
208
170
|
return result;
|
|
209
171
|
}
|
|
210
|
-
/**
|
|
211
|
-
* Does the given string look like a RegExp or Glob pattern?
|
|
212
|
-
*/
|
|
213
172
|
function isPattern(text) {
|
|
214
173
|
return text.includes('*') || text.includes('+') || text.includes('?') || text.includes('|');
|
|
215
174
|
}
|
|
216
|
-
/**
|
|
217
|
-
* Expand the given Glob pattern and check if files matched.
|
|
218
|
-
* Raises an exception is the result is empty.
|
|
219
|
-
*
|
|
220
|
-
* @param pattern - The Glob pattern used for matching.
|
|
221
|
-
*/
|
|
222
175
|
function expandAndCheck(pattern) {
|
|
223
176
|
const result = (0, FileSystem_1.expandToFileSet)(pattern);
|
|
224
177
|
if (result.length === 0) {
|
|
@@ -1,40 +1,13 @@
|
|
|
1
1
|
import { Bundle, GwtBundle } from './Task';
|
|
2
2
|
import { RawSourceMap } from 'source-map';
|
|
3
|
-
/**
|
|
4
|
-
* Information on a GWT function call, typically with code to be evaluated as arguments.
|
|
5
|
-
*/
|
|
6
3
|
export type GwtCallInfos = {
|
|
7
4
|
codeArguments: string[];
|
|
8
5
|
functionName: string;
|
|
9
6
|
codeAsArrayArgument: boolean;
|
|
10
7
|
};
|
|
11
|
-
/**
|
|
12
|
-
* There are different places where a 'symbolMaps' folder can be:
|
|
13
|
-
* (1) within the `WEB-INF` folder (`WEB-INF/deploy/<module-name>/symbolMaps`)
|
|
14
|
-
* or (2) it can be a sibling of the parent `deferredjs` folder.
|
|
15
|
-
*
|
|
16
|
-
* @param taskFile - Path to the JS bundle file to start searching from.
|
|
17
|
-
*/
|
|
18
8
|
export declare function determineSymbolMapsDir(taskFile: string): string[];
|
|
19
|
-
/**
|
|
20
|
-
* Extract the GWT function calls from the GWT bundle. These function calls
|
|
21
|
-
* do have the actual application code as arguments.
|
|
22
|
-
*
|
|
23
|
-
* Examples of `bundleContent` (without the double quotes):
|
|
24
|
-
* "showcase.onScriptDownloaded(["var $wnd = ..... __gwtModuleFunction.__moduleStartupDone($gwt.permProps);\n//# sourceURL=showcase-0.js\n"]);"
|
|
25
|
-
* "$wnd.showcase.runAsyncCallback3("function bc(a){Wb((Ze(),Xe),a) ..... nZ5b(El)(3);\n//# sourceURL=showcase-3.js\n")
|
|
26
|
-
*/
|
|
27
9
|
export declare function extractGwtCallInfos(bundleContent: string): GwtCallInfos | null;
|
|
28
|
-
/**
|
|
29
|
-
* Load the source map for the given GWT bundle.
|
|
30
|
-
*/
|
|
31
10
|
export declare function loadInputSourceMapsGwt(taskFile: string, bundleFile: GwtBundle): Array<RawSourceMap | undefined>;
|
|
32
|
-
/**
|
|
33
|
-
* Determine the ID of the given GWT bundle file.
|
|
34
|
-
*/
|
|
35
11
|
export declare function determineGwtFileUid(filename: string): string | undefined;
|
|
36
|
-
/**
|
|
37
|
-
* Is the given bundle a GWT bundle?
|
|
38
|
-
*/
|
|
39
12
|
export declare function isGwtBundle(bundle: Bundle): bundle is GwtBundle;
|
|
40
13
|
//# sourceMappingURL=WebToolkit.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WebToolkit.d.ts","sourceRoot":"","sources":["../../../src/instrumenter/WebToolkit.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"WebToolkit.d.ts","sourceRoot":"","sources":["../../../src/instrumenter/WebToolkit.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAK1C,MAAM,MAAM,YAAY,GAAG;IAAE,aAAa,EAAE,MAAM,EAAE,CAAC;IAAC,YAAY,EAAE,MAAM,CAAC;IAAC,mBAAmB,EAAE,OAAO,CAAA;CAAE,CAAC;AAS3G,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,CAqBjE;AA0BD,wBAAgB,mBAAmB,CAAC,aAAa,EAAE,MAAM,GAAG,YAAY,GAAG,IAAI,CA+B9E;AAKD,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,GAAG,KAAK,CAAC,YAAY,GAAG,SAAS,CAAC,CAgC/G;AAKD,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAOxE;AAKD,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,IAAI,SAAS,CAE/D"}
|
|
@@ -13,13 +13,6 @@ const FileSystem_1 = require("./FileSystem");
|
|
|
13
13
|
const types_1 = require("@babel/types");
|
|
14
14
|
const parser_1 = require("@babel/parser");
|
|
15
15
|
const commons_1 = require("@cqse/commons");
|
|
16
|
-
/**
|
|
17
|
-
* There are different places where a 'symbolMaps' folder can be:
|
|
18
|
-
* (1) within the `WEB-INF` folder (`WEB-INF/deploy/<module-name>/symbolMaps`)
|
|
19
|
-
* or (2) it can be a sibling of the parent `deferredjs` folder.
|
|
20
|
-
*
|
|
21
|
-
* @param taskFile - Path to the JS bundle file to start searching from.
|
|
22
|
-
*/
|
|
23
16
|
function determineSymbolMapsDir(taskFile) {
|
|
24
17
|
const symbolMapDirs = [];
|
|
25
18
|
let webInfDir = null;
|
|
@@ -55,14 +48,6 @@ function extractQualifiedFunctionName(call) {
|
|
|
55
48
|
}
|
|
56
49
|
throw new commons_1.IllegalArgumentException('Type of callee not yet supported.');
|
|
57
50
|
}
|
|
58
|
-
/**
|
|
59
|
-
* Extract the GWT function calls from the GWT bundle. These function calls
|
|
60
|
-
* do have the actual application code as arguments.
|
|
61
|
-
*
|
|
62
|
-
* Examples of `bundleContent` (without the double quotes):
|
|
63
|
-
* "showcase.onScriptDownloaded(["var $wnd = ..... __gwtModuleFunction.__moduleStartupDone($gwt.permProps);\n//# sourceURL=showcase-0.js\n"]);"
|
|
64
|
-
* "$wnd.showcase.runAsyncCallback3("function bc(a){Wb((Ze(),Xe),a) ..... nZ5b(El)(3);\n//# sourceURL=showcase-3.js\n")
|
|
65
|
-
*/
|
|
66
51
|
function extractGwtCallInfos(bundleContent) {
|
|
67
52
|
const ast = (0, parser_1.parse)(bundleContent);
|
|
68
53
|
if (ast.program.body.length === 0) {
|
|
@@ -95,13 +80,7 @@ function extractGwtCallInfos(bundleContent) {
|
|
|
95
80
|
}
|
|
96
81
|
return null;
|
|
97
82
|
}
|
|
98
|
-
/**
|
|
99
|
-
* Load the source map for the given GWT bundle.
|
|
100
|
-
*/
|
|
101
83
|
function loadInputSourceMapsGwt(taskFile, bundleFile) {
|
|
102
|
-
// taskFile:
|
|
103
|
-
// war/stockwatcher/E2C1FB09E006E0A2420123D036967150.cache.js
|
|
104
|
-
// war/showcase/deferredjs/28F63AD125178AAAB80993C11635D26F/5.cache.js
|
|
105
84
|
const mapDirs = determineSymbolMapsDir(taskFile);
|
|
106
85
|
const fileNumberMatcher = /sourceURL=(.*)-(\d+).js(\\n)*\s*$/;
|
|
107
86
|
const mapModules = bundleFile.codeArguments.map(code => {
|
|
@@ -127,9 +106,6 @@ function loadInputSourceMapsGwt(taskFile, bundleFile) {
|
|
|
127
106
|
return undefined;
|
|
128
107
|
});
|
|
129
108
|
}
|
|
130
|
-
/**
|
|
131
|
-
* Determine the ID of the given GWT bundle file.
|
|
132
|
-
*/
|
|
133
109
|
function determineGwtFileUid(filename) {
|
|
134
110
|
const fileUidMatcher = /.*([0-9A-Fa-f]{32}).*/;
|
|
135
111
|
const uidMatches = fileUidMatcher.exec(filename);
|
|
@@ -138,9 +114,6 @@ function determineGwtFileUid(filename) {
|
|
|
138
114
|
}
|
|
139
115
|
return uidMatches[1];
|
|
140
116
|
}
|
|
141
|
-
/**
|
|
142
|
-
* Is the given bundle a GWT bundle?
|
|
143
|
-
*/
|
|
144
117
|
function isGwtBundle(bundle) {
|
|
145
118
|
return bundle.type === 'gwt';
|
|
146
119
|
}
|
package/dist/src/main.js
CHANGED
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
"use strict";
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
const App_1 = require("./App");
|
|
5
|
-
// Main function of the instrumenter
|
|
6
5
|
App_1.App.run().catch(reason => {
|
|
7
6
|
console.error(reason);
|
|
7
|
+
if (process.exitCode === 0 || process.exitCode === undefined) {
|
|
8
|
+
process.exitCode = 1;
|
|
9
|
+
}
|
|
8
10
|
});
|