@teamscale/javascript-instrumenter 1.0.0-beta.6 → 1.0.4
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/main.mjs +216 -0
- package/dist/vaccine.js +1 -1
- package/package.json +28 -19
- package/dist/package.json +0 -69
- package/dist/src/App.d.ts +0 -52
- package/dist/src/App.d.ts.map +0 -1
- package/dist/src/App.js +0 -283
- package/dist/src/instrumenter/FileSystem.d.ts +0 -38
- package/dist/src/instrumenter/FileSystem.d.ts.map +0 -1
- package/dist/src/instrumenter/FileSystem.js +0 -134
- package/dist/src/instrumenter/Instrumenter.d.ts +0 -92
- package/dist/src/instrumenter/Instrumenter.d.ts.map +0 -1
- package/dist/src/instrumenter/Instrumenter.js +0 -376
- package/dist/src/instrumenter/InstrumenterConfig.d.ts +0 -37
- package/dist/src/instrumenter/InstrumenterConfig.d.ts.map +0 -1
- package/dist/src/instrumenter/InstrumenterConfig.js +0 -165
- package/dist/src/instrumenter/RelativeCollectorPatternParser.d.ts +0 -8
- package/dist/src/instrumenter/RelativeCollectorPatternParser.d.ts.map +0 -1
- package/dist/src/instrumenter/RelativeCollectorPatternParser.js +0 -53
- package/dist/src/instrumenter/RelativeCollectorPatternParser.test.d.ts +0 -2
- package/dist/src/instrumenter/RelativeCollectorPatternParser.test.d.ts.map +0 -1
- package/dist/src/instrumenter/RelativeCollectorPatternParser.test.js +0 -28
- package/dist/src/instrumenter/Task.d.ts +0 -224
- package/dist/src/instrumenter/Task.d.ts.map +0 -1
- package/dist/src/instrumenter/Task.js +0 -309
- package/dist/src/instrumenter/TaskBuilder.d.ts +0 -75
- package/dist/src/instrumenter/TaskBuilder.d.ts.map +0 -1
- package/dist/src/instrumenter/TaskBuilder.js +0 -228
- package/dist/src/instrumenter/WebToolkit.d.ts +0 -40
- package/dist/src/instrumenter/WebToolkit.d.ts.map +0 -1
- package/dist/src/instrumenter/WebToolkit.js +0 -146
- package/dist/src/main.d.ts +0 -3
- package/dist/src/main.d.ts.map +0 -1
- package/dist/src/main.js +0 -8
- package/dist/src/vaccine/types.d.ts +0 -65
- package/dist/src/vaccine/types.d.ts.map +0 -1
- package/dist/src/vaccine/types.js +0 -2
|
@@ -1,309 +0,0 @@
|
|
|
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.SourceMapFileReference = exports.TaskResult = exports.InstrumentationTask = exports.FileExcludePattern = exports.OriginSourcePattern = exports.TaskElement = exports.SourceMapReference = void 0;
|
|
7
|
-
exports.createCollectorSpecifier = createCollectorSpecifier;
|
|
8
|
-
const commons_1 = require("@cqse/commons");
|
|
9
|
-
const micromatch_1 = __importDefault(require("micromatch"));
|
|
10
|
-
const RelativeCollectorPatternParser_1 = require("./RelativeCollectorPatternParser");
|
|
11
|
-
/**
|
|
12
|
-
* An abstract source map type.
|
|
13
|
-
*/
|
|
14
|
-
class SourceMapReference {
|
|
15
|
-
}
|
|
16
|
-
exports.SourceMapReference = SourceMapReference;
|
|
17
|
-
/**
|
|
18
|
-
* One element of an instrumentation task.
|
|
19
|
-
* It corresponds to instrumenting a single file.
|
|
20
|
-
*/
|
|
21
|
-
class TaskElement {
|
|
22
|
-
constructor(fromFile, toFile, externalSourceMap) {
|
|
23
|
-
this.fromFile = commons_1.Contract.requireDefined(fromFile);
|
|
24
|
-
this.toFile = commons_1.Contract.requireDefined(toFile);
|
|
25
|
-
this.externalSourceMapFile = externalSourceMap;
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Is it an in-place instrumentation task?
|
|
29
|
-
*/
|
|
30
|
-
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
|
-
return this.fromFile === this.toFile;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
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
|
-
function createCollectorSpecifier(commandLineUrl, relativePattern) {
|
|
45
|
-
if (relativePattern !== undefined) {
|
|
46
|
-
return RelativeCollectorPatternParser_1.RelativeCollectorPatternParser.parse(relativePattern);
|
|
47
|
-
}
|
|
48
|
-
return parseCommandLineUrl(commandLineUrl);
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Parses, validates and normalizes the given URL that the user provided on the command-line.
|
|
52
|
-
*/
|
|
53
|
-
function parseCommandLineUrl(commandLineUrl) {
|
|
54
|
-
let url;
|
|
55
|
-
if (commandLineUrl.indexOf('://') > 0) {
|
|
56
|
-
// A trailing slash will be removed
|
|
57
|
-
url = commandLineUrl.replace(/\/$/, '');
|
|
58
|
-
}
|
|
59
|
-
else {
|
|
60
|
-
commons_1.Contract.requireStringPattern(commandLineUrl, '.+:[0-9]+', 'Invalid collector pattern used!');
|
|
61
|
-
const host = commandLineUrl.split(':')[0];
|
|
62
|
-
const port = Number.parseInt(commandLineUrl.split(':')[1]);
|
|
63
|
-
url = `ws://${host}:${port}`;
|
|
64
|
-
}
|
|
65
|
-
return {
|
|
66
|
-
type: "url",
|
|
67
|
-
url,
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Configuration used to match paths with `micromatch`.
|
|
72
|
-
*/
|
|
73
|
-
const MATCHER_OPTIONS = {
|
|
74
|
-
basename: false,
|
|
75
|
-
lookbehinds: true,
|
|
76
|
-
noglobstar: false
|
|
77
|
-
};
|
|
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
|
-
class OriginSourcePattern {
|
|
86
|
-
constructor(include, exclude) {
|
|
87
|
-
this.include = normalizePatterns(include);
|
|
88
|
-
this.exclude = normalizePatterns(exclude);
|
|
89
|
-
this.includeMatches = new Set();
|
|
90
|
-
this.excludeMatches = new Set();
|
|
91
|
-
this.neitherExcludedNorIncluded = new Set();
|
|
92
|
-
}
|
|
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
|
-
isIncluded(originFile) {
|
|
106
|
-
if (originFile.length === 0) {
|
|
107
|
-
return true;
|
|
108
|
-
}
|
|
109
|
-
const normalizedOriginFile = normalizePath(originFile);
|
|
110
|
-
if (this.exclude) {
|
|
111
|
-
const matchedToExclude = (0, micromatch_1.default)([normalizedOriginFile], this.exclude, MATCHER_OPTIONS);
|
|
112
|
-
if (matchedToExclude.length === 1) {
|
|
113
|
-
this.excludeMatches.add(normalizedOriginFile);
|
|
114
|
-
return false;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
if (this.include) {
|
|
118
|
-
const result = micromatch_1.default.some([normalizedOriginFile], this.include, MATCHER_OPTIONS);
|
|
119
|
-
if (result) {
|
|
120
|
-
this.includeMatches.add(normalizedOriginFile);
|
|
121
|
-
}
|
|
122
|
-
else {
|
|
123
|
-
this.neitherExcludedNorIncluded.add(normalizedOriginFile);
|
|
124
|
-
}
|
|
125
|
-
return result;
|
|
126
|
-
}
|
|
127
|
-
this.neitherExcludedNorIncluded.add(normalizedOriginFile);
|
|
128
|
-
return true;
|
|
129
|
-
}
|
|
130
|
-
/**
|
|
131
|
-
* Variant of `isIncluded` working on a list of files to check.
|
|
132
|
-
* (Primarily, used for testing.)
|
|
133
|
-
*/
|
|
134
|
-
isAnyIncluded(originFiles) {
|
|
135
|
-
return originFiles.find(value => this.isIncluded(value)) !== undefined;
|
|
136
|
-
}
|
|
137
|
-
/**
|
|
138
|
-
* Retrieve the file names that have been matching the different patterns.
|
|
139
|
-
*/
|
|
140
|
-
retrieveMatchingFiles() {
|
|
141
|
-
var _a, _b;
|
|
142
|
-
return {
|
|
143
|
-
includePatterns: (_a = this.include) !== null && _a !== void 0 ? _a : [],
|
|
144
|
-
excludePatterns: (_b = this.exclude) !== null && _b !== void 0 ? _b : [],
|
|
145
|
-
excludeMatches: [...this.excludeMatches],
|
|
146
|
-
includeMatches: [...this.includeMatches],
|
|
147
|
-
neitherExcludedNorIncluded: [...this.neitherExcludedNorIncluded]
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
/**
|
|
151
|
-
* Returns if include/exclude patterns are specified.
|
|
152
|
-
*/
|
|
153
|
-
patternsSpecified() {
|
|
154
|
-
return this.include !== undefined || this.exclude !== undefined;
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
exports.OriginSourcePattern = OriginSourcePattern;
|
|
158
|
-
/**
|
|
159
|
-
* Pattern describing files (bundles) to not instrument.
|
|
160
|
-
*/
|
|
161
|
-
class FileExcludePattern {
|
|
162
|
-
constructor(exclude) {
|
|
163
|
-
var _a;
|
|
164
|
-
this.exclude = (_a = normalizePatterns(exclude)) !== null && _a !== void 0 ? _a : [];
|
|
165
|
-
}
|
|
166
|
-
/**
|
|
167
|
-
* Return `true` if the given `filePath` is matched by any of the patterns in `exclude`.
|
|
168
|
-
*/
|
|
169
|
-
isExcluded(filePath) {
|
|
170
|
-
return micromatch_1.default.isMatch(normalizePath(filePath), this.exclude);
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
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
|
-
function normalizePatterns(patterns) {
|
|
180
|
-
if (patterns === undefined || patterns.length === 0) {
|
|
181
|
-
return undefined;
|
|
182
|
-
}
|
|
183
|
-
const normalizedPatterns = patterns
|
|
184
|
-
.map(pattern => normalizeGlobPattern(pattern))
|
|
185
|
-
.filter(pattern => pattern !== undefined);
|
|
186
|
-
if (patterns.length === 0) {
|
|
187
|
-
return undefined;
|
|
188
|
-
}
|
|
189
|
-
return normalizedPatterns;
|
|
190
|
-
}
|
|
191
|
-
function normalizeGlobPattern(pattern) {
|
|
192
|
-
if (!pattern) {
|
|
193
|
-
return pattern;
|
|
194
|
-
}
|
|
195
|
-
// This should be in line with the logic in `normalizePath`.
|
|
196
|
-
return removeTrailingDirectoryTraversals(removeTrailingCurrentWorkingDir(pattern));
|
|
197
|
-
}
|
|
198
|
-
function normalizePath(toNormalize) {
|
|
199
|
-
// This should be in line with the logic in `normalizeGlobPattern`.
|
|
200
|
-
return removeTrailingDirectoryTraversals(removeTrailingCurrentWorkingDir(toNormalize.replace(/\\/g, '/')));
|
|
201
|
-
}
|
|
202
|
-
/**
|
|
203
|
-
* `micromatch` cannot deal with leading `../`, so we remove those.
|
|
204
|
-
*/
|
|
205
|
-
function removeTrailingDirectoryTraversals(toNormalize) {
|
|
206
|
-
let result = toNormalize;
|
|
207
|
-
while (result.startsWith("../")) {
|
|
208
|
-
result = result.substring(3);
|
|
209
|
-
}
|
|
210
|
-
return result;
|
|
211
|
-
}
|
|
212
|
-
function removeTrailingCurrentWorkingDir(removeFrom) {
|
|
213
|
-
return removePrefix('webpack:///', removePrefix('./', removeFrom));
|
|
214
|
-
}
|
|
215
|
-
function removePrefix(prefix, removeFrom) {
|
|
216
|
-
if (removeFrom.startsWith(prefix)) {
|
|
217
|
-
return removeFrom.substring(prefix.length);
|
|
218
|
-
}
|
|
219
|
-
return removeFrom;
|
|
220
|
-
}
|
|
221
|
-
/**
|
|
222
|
-
* The actual instrumentation task.
|
|
223
|
-
*/
|
|
224
|
-
class InstrumentationTask {
|
|
225
|
-
constructor(collector, targetBucket, elements, excludeFilesPattern, originSourcePattern, dumpOriginsFile, dumpMatchedOriginsFile) {
|
|
226
|
-
this.collector = commons_1.Contract.requireDefined(collector);
|
|
227
|
-
this.targetBucket = commons_1.Contract.requireDefined(targetBucket);
|
|
228
|
-
this.excludeFilesPattern = commons_1.Contract.requireDefined(excludeFilesPattern);
|
|
229
|
-
this.originSourcePattern = commons_1.Contract.requireDefined(originSourcePattern);
|
|
230
|
-
this._elements = commons_1.Contract.requireDefined(elements).slice();
|
|
231
|
-
this.dumpOriginsFile = dumpOriginsFile;
|
|
232
|
-
this.dumpMatchedOriginsFile = dumpMatchedOriginsFile;
|
|
233
|
-
}
|
|
234
|
-
/**
|
|
235
|
-
* @returns the elements of the task.
|
|
236
|
-
*/
|
|
237
|
-
get elements() {
|
|
238
|
-
// Ensure immutability of this object by returning a copy
|
|
239
|
-
// of the list of immutable objects.
|
|
240
|
-
return this._elements.slice();
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
exports.InstrumentationTask = InstrumentationTask;
|
|
244
|
-
/**
|
|
245
|
-
* A summary of executing the instrumentation task.
|
|
246
|
-
*/
|
|
247
|
-
class TaskResult {
|
|
248
|
-
constructor(translated, excluded, translatedFromCache, alreadyInstrumented, unsupported, failed, warnings, task) {
|
|
249
|
-
commons_1.Contract.require(translated > -1);
|
|
250
|
-
commons_1.Contract.require(excluded > -1);
|
|
251
|
-
commons_1.Contract.require(translatedFromCache > -1);
|
|
252
|
-
commons_1.Contract.require(alreadyInstrumented > -1);
|
|
253
|
-
commons_1.Contract.require(unsupported > -1);
|
|
254
|
-
commons_1.Contract.require(failed > -1);
|
|
255
|
-
commons_1.Contract.require(warnings > -1);
|
|
256
|
-
this.translated = translated;
|
|
257
|
-
this.excluded = excluded;
|
|
258
|
-
this.translatedFromCache = translatedFromCache;
|
|
259
|
-
this.alreadyInstrumented = alreadyInstrumented;
|
|
260
|
-
this.unsupported = unsupported;
|
|
261
|
-
this.failed = failed;
|
|
262
|
-
this.warnings = warnings;
|
|
263
|
-
this.task = task;
|
|
264
|
-
}
|
|
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
|
-
withIncrement(incBy) {
|
|
271
|
-
var _a;
|
|
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);
|
|
273
|
-
}
|
|
274
|
-
/**
|
|
275
|
-
* @returns the neutral task element (adding it with {@code withIncrement} does not change the result).
|
|
276
|
-
*/
|
|
277
|
-
static neutral(task) {
|
|
278
|
-
return new TaskResult(0, 0, 0, 0, 0, 0, 0, task);
|
|
279
|
-
}
|
|
280
|
-
/**
|
|
281
|
-
* @returns a task result signaling one error.
|
|
282
|
-
*
|
|
283
|
-
* @param e - The error to add.
|
|
284
|
-
*/
|
|
285
|
-
static error(e) {
|
|
286
|
-
console.error(e);
|
|
287
|
-
return new TaskResult(0, 0, 0, 0, 0, 1, 0);
|
|
288
|
-
}
|
|
289
|
-
/**
|
|
290
|
-
* @returns a task result signaling one warning.
|
|
291
|
-
*
|
|
292
|
-
* @param msg - The warning message to add.
|
|
293
|
-
*/
|
|
294
|
-
static warning(msg) {
|
|
295
|
-
console.warn(msg);
|
|
296
|
-
return new TaskResult(0, 0, 0, 0, 0, 0, 1);
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
exports.TaskResult = TaskResult;
|
|
300
|
-
/**
|
|
301
|
-
* A source map in an external file.
|
|
302
|
-
*/
|
|
303
|
-
class SourceMapFileReference extends SourceMapReference {
|
|
304
|
-
constructor(sourceMapFilePath) {
|
|
305
|
-
super();
|
|
306
|
-
this.sourceMapFilePath = sourceMapFilePath;
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
exports.SourceMapFileReference = SourceMapFileReference;
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { InstrumentationTask, SourceMapReference } from './Task';
|
|
2
|
-
import { InstrumenterOptions } from './InstrumenterConfig';
|
|
3
|
-
/**
|
|
4
|
-
* A builder for an instrumentation task.
|
|
5
|
-
*/
|
|
6
|
-
export declare class TaskBuilder {
|
|
7
|
-
/** The elements of the instrumentation task. */
|
|
8
|
-
private readonly elements;
|
|
9
|
-
/** The collector to send the coverage to. */
|
|
10
|
-
private collector;
|
|
11
|
-
/** Origin include patterns. */
|
|
12
|
-
private originSourceIncludePatterns;
|
|
13
|
-
/** Origin exclude patters. */
|
|
14
|
-
private originSourceExcludePatterns;
|
|
15
|
-
/** Bundle exclude patters. */
|
|
16
|
-
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
|
-
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
|
-
private dumpMatchedOriginsFile;
|
|
26
|
-
/**
|
|
27
|
-
* The bucket within the collector the coverage is supposed to be sent to.
|
|
28
|
-
*/
|
|
29
|
-
private targetBucket;
|
|
30
|
-
/**
|
|
31
|
-
* The automatically generated unique app id to use.
|
|
32
|
-
*/
|
|
33
|
-
private appId;
|
|
34
|
-
constructor();
|
|
35
|
-
/** Set the collector specification based on the command-line arguments. */
|
|
36
|
-
setCollectorFromCommandLine(commandLineUrl: string, relativePattern?: string): this;
|
|
37
|
-
/** Set the coverage bucket to be used within the collector. */
|
|
38
|
-
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
|
-
setOriginSourceIncludePatterns(patterns: string[] | undefined): this;
|
|
41
|
-
/** Set the origin exclude pattern(s). If multiple patterns are present, concatenates them via the OR operator. */
|
|
42
|
-
setOriginSourceExcludePatterns(patterns: string[] | undefined): this;
|
|
43
|
-
/** Sets the file bundle exclude pattern. If multiple patterns are present, concatenates them via the OR operator. */
|
|
44
|
-
setBundleExcludePatterns(patterns: string[] | undefined): this;
|
|
45
|
-
/** Add a task element */
|
|
46
|
-
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
|
-
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
|
-
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
|
-
private addInPlaceTasksFromPattern;
|
|
70
|
-
/**
|
|
71
|
-
* Build the instrumentation task.
|
|
72
|
-
*/
|
|
73
|
-
build(): InstrumentationTask;
|
|
74
|
-
}
|
|
75
|
-
//# sourceMappingURL=TaskBuilder.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
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;AAoB3D;;GAEG;AACH,qBAAa,WAAW;IACvB,gDAAgD;IAChD,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAgB;IAEzC,6CAA6C;IAC7C,OAAO,CAAC,SAAS,CAA4B;IAE7C,+BAA+B;IAC/B,OAAO,CAAC,2BAA2B,CAAuB;IAE1D,8BAA8B;IAC9B,OAAO,CAAC,2BAA2B,CAAuB;IAE1D,8BAA8B;IAC9B,OAAO,CAAC,yBAAyB,CAAuB;IAExD;;qDAEiD;IACjD,OAAO,CAAC,eAAe,CAAqB;IAE5C;;;OAGG;IACH,OAAO,CAAC,sBAAsB,CAAqB;IAEnD;;OAEG;IACH,OAAO,CAAC,YAAY,CAAiC;IAErD;;OAEG;IACH,OAAO,CAAC,KAAK,CAAS;;IAStB,2EAA2E;IAC3E,2BAA2B,CAAC,cAAc,EAAE,MAAM,EAAE,eAAe,CAAC,EAAE,MAAM,GAAG,IAAI;IAMnF,+DAA+D;IAC/D,wBAAwB,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,aAAa,CAAC,EAAE,MAAM,EACtF,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI;IAO9B,gHAAgH;IAChH,8BAA8B,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,SAAS,GAAG,IAAI;IAKpE,kHAAkH;IAClH,8BAA8B,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,SAAS,GAAG,IAAI;IAKpE,qHAAqH;IACrH,wBAAwB,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,SAAS,GAAG,IAAI;IAK9D,yBAAyB;IACzB,UAAU,CAAC,YAAY,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,iBAAiB,CAAC,EAAE,kBAAkB,GAAG,IAAI;IAKlG;;;;OAIG;IACH,aAAa,CAAC,MAAM,EAAE,mBAAmB,GAAG,IAAI;IAuChD;;;;;;;OAOG;IACH,OAAO,CAAC,4CAA4C;IAgCpD;;;;;;OAMG;IACH,OAAO,CAAC,0BAA0B;IASlC;;OAEG;IACI,KAAK,IAAI,mBAAmB;CAWnC"}
|
|
@@ -1,228 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
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);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.TaskBuilder = void 0;
|
|
37
|
-
const Task_1 = require("./Task");
|
|
38
|
-
const commons_1 = require("@cqse/commons");
|
|
39
|
-
const fs = __importStar(require("fs"));
|
|
40
|
-
const path = __importStar(require("path"));
|
|
41
|
-
const FileSystem_1 = require("./FileSystem");
|
|
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
|
-
function loadSourceMap(sourceMapPath) {
|
|
50
|
-
if (sourceMapPath) {
|
|
51
|
-
if (!fs.existsSync(sourceMapPath)) {
|
|
52
|
-
throw new commons_1.InvalidConfigurationException(`The specified source map file '${sourceMapPath}' was not found.`);
|
|
53
|
-
}
|
|
54
|
-
return new Task_1.SourceMapFileReference(sourceMapPath);
|
|
55
|
-
}
|
|
56
|
-
return undefined;
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* A builder for an instrumentation task.
|
|
60
|
-
*/
|
|
61
|
-
class TaskBuilder {
|
|
62
|
-
constructor() {
|
|
63
|
-
this.appId = (0, uuid_1.v4)();
|
|
64
|
-
this.elements = [];
|
|
65
|
-
this.collector = null;
|
|
66
|
-
this.targetBucket = null;
|
|
67
|
-
}
|
|
68
|
-
/** Set the collector specification based on the command-line arguments. */
|
|
69
|
-
setCollectorFromCommandLine(commandLineUrl, relativePattern) {
|
|
70
|
-
commons_1.Contract.requireNonEmpty(commandLineUrl, "The collector URL must not be empty");
|
|
71
|
-
this.collector = (0, Task_1.createCollectorSpecifier)(commandLineUrl, relativePattern);
|
|
72
|
-
return this;
|
|
73
|
-
}
|
|
74
|
-
/** Set the coverage bucket to be used within the collector. */
|
|
75
|
-
setCollectorTargetBucket(configId, commit, configOptions, appName) {
|
|
76
|
-
commons_1.Contract.requireNonEmpty(commit, "The commit must not be empty");
|
|
77
|
-
this.appId = generateAppId(appName);
|
|
78
|
-
this.targetBucket = { appId: this.appId, configId, commit, configOptions };
|
|
79
|
-
return this;
|
|
80
|
-
}
|
|
81
|
-
/** Set the origin include pattern. If multiple patterns are present, concatenates them via the OR operator. */
|
|
82
|
-
setOriginSourceIncludePatterns(patterns) {
|
|
83
|
-
this.originSourceIncludePatterns = patterns;
|
|
84
|
-
return this;
|
|
85
|
-
}
|
|
86
|
-
/** Set the origin exclude pattern(s). If multiple patterns are present, concatenates them via the OR operator. */
|
|
87
|
-
setOriginSourceExcludePatterns(patterns) {
|
|
88
|
-
this.originSourceExcludePatterns = patterns;
|
|
89
|
-
return this;
|
|
90
|
-
}
|
|
91
|
-
/** Sets the file bundle exclude pattern. If multiple patterns are present, concatenates them via the OR operator. */
|
|
92
|
-
setBundleExcludePatterns(patterns) {
|
|
93
|
-
this.bundleFileExcludePatterns = patterns;
|
|
94
|
-
return this;
|
|
95
|
-
}
|
|
96
|
-
/** Add a task element */
|
|
97
|
-
addElement(fromFilePath, toFilePath, fromFileSourceMap) {
|
|
98
|
-
this.elements.push(new Task_1.TaskElement(fromFilePath, toFilePath, fromFileSourceMap));
|
|
99
|
-
return this;
|
|
100
|
-
}
|
|
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
|
-
addFromConfig(config) {
|
|
107
|
-
var _a, _b, _c;
|
|
108
|
-
const inputs = ((_a = config.input) !== null && _a !== void 0 ? _a : []);
|
|
109
|
-
const inPlace = (_b = config.inPlace) !== null && _b !== void 0 ? _b : false;
|
|
110
|
-
const target = config.to;
|
|
111
|
-
const sourceMap = config.sourceMap;
|
|
112
|
-
this.dumpOriginsFile = config.dumpOriginsTo;
|
|
113
|
-
this.dumpMatchedOriginsFile = config.dumpOriginMatchesTo;
|
|
114
|
-
this.setCollectorFromCommandLine(config.collector, config.relativeCollector);
|
|
115
|
-
this.setOriginSourceIncludePatterns(config.includeOrigin);
|
|
116
|
-
this.setOriginSourceExcludePatterns(config.excludeOrigin);
|
|
117
|
-
this.setBundleExcludePatterns(config.excludeBundle);
|
|
118
|
-
this.setCollectorTargetBucket(config.configId, (_c = config.commit) !== null && _c !== void 0 ? _c : 'HEAD', config.collectorConfigFileContent, config.appName);
|
|
119
|
-
// Handle an explicitly specified source map
|
|
120
|
-
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
|
-
if (inPlace) {
|
|
125
|
-
if (target) {
|
|
126
|
-
throw new commons_1.InvalidConfigurationException('No target path must be specified in case an in-place instrumentation is enabled.');
|
|
127
|
-
}
|
|
128
|
-
this.addInPlaceTasksFromPattern(inputs, sourceMapInfo);
|
|
129
|
-
}
|
|
130
|
-
else if (!inPlace) {
|
|
131
|
-
// A target directory must be specified
|
|
132
|
-
if (!target) {
|
|
133
|
-
throw new commons_1.InvalidConfigurationException('A target path must be specified using `--to`.');
|
|
134
|
-
}
|
|
135
|
-
this.addInstrumentationTasksFromPatternWithTarget(inputs, target, sourceMapInfo);
|
|
136
|
-
}
|
|
137
|
-
return this;
|
|
138
|
-
}
|
|
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
|
-
addInstrumentationTasksFromPatternWithTarget(inputs, target, sourceMapInfo) {
|
|
148
|
-
(0, FileSystem_1.ensureExistingDirectory)(target);
|
|
149
|
-
for (const input of inputs) {
|
|
150
|
-
if ((0, FileSystem_1.isExistingFile)(input)) {
|
|
151
|
-
if ((0, FileSystem_1.isExistingDirectory)(target) || target.endsWith(path.sep)) {
|
|
152
|
-
this.addElement(input, path.join(target, path.basename(input)), sourceMapInfo);
|
|
153
|
-
}
|
|
154
|
-
else {
|
|
155
|
-
this.addElement(input, target, sourceMapInfo);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
else if ((0, FileSystem_1.isExistingDirectory)(input) || isPattern(input)) {
|
|
159
|
-
const inputFiles = inputs.flatMap(input => (0, FileSystem_1.expandToFileSet)(input));
|
|
160
|
-
if (isPattern(input)) {
|
|
161
|
-
inputFiles.forEach(f => this.addElement(f, path.join(target, path.basename(f)), sourceMapInfo));
|
|
162
|
-
}
|
|
163
|
-
else {
|
|
164
|
-
inputFiles.forEach(f => {
|
|
165
|
-
const pathRelativeToInputDir = path.relative(input, f);
|
|
166
|
-
const targetFileName = path.join(target, pathRelativeToInputDir);
|
|
167
|
-
this.addElement(f, targetFileName, sourceMapInfo);
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
else {
|
|
172
|
-
throw new commons_1.InvalidConfigurationException(`The specified input '${input}' was not found.`);
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
}
|
|
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
|
-
addInPlaceTasksFromPattern(inputs, sourceMapInfo) {
|
|
184
|
-
inputs
|
|
185
|
-
.map(input => expandAndCheck(input))
|
|
186
|
-
.reduce((prev, curr) => {
|
|
187
|
-
return curr.concat(prev);
|
|
188
|
-
}, [])
|
|
189
|
-
.forEach(filePath => this.addElement(filePath, filePath, sourceMapInfo));
|
|
190
|
-
}
|
|
191
|
-
/**
|
|
192
|
-
* Build the instrumentation task.
|
|
193
|
-
*/
|
|
194
|
-
build() {
|
|
195
|
-
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
|
-
}
|
|
197
|
-
}
|
|
198
|
-
exports.TaskBuilder = TaskBuilder;
|
|
199
|
-
/**
|
|
200
|
-
* Generates an application ID, if an `appName` is given, with a user-friendly prefix.
|
|
201
|
-
*/
|
|
202
|
-
function generateAppId(appName) {
|
|
203
|
-
const result = (0, uuid_1.v4)();
|
|
204
|
-
if (appName) {
|
|
205
|
-
const appPrefix = (0, FileSystem_1.replaceNonFilesystemCharacters)(appName).toLowerCase();
|
|
206
|
-
return `${appPrefix}-${result.substring(0, 10)}`;
|
|
207
|
-
}
|
|
208
|
-
return result;
|
|
209
|
-
}
|
|
210
|
-
/**
|
|
211
|
-
* Does the given string look like a RegExp or Glob pattern?
|
|
212
|
-
*/
|
|
213
|
-
function isPattern(text) {
|
|
214
|
-
return text.includes('*') || text.includes('+') || text.includes('?') || text.includes('|');
|
|
215
|
-
}
|
|
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
|
-
function expandAndCheck(pattern) {
|
|
223
|
-
const result = (0, FileSystem_1.expandToFileSet)(pattern);
|
|
224
|
-
if (result.length === 0) {
|
|
225
|
-
throw new commons_1.InvalidConfigurationException(`No files to instrument found. \n\tWorking directory: '${process.cwd()}'\n\tPattern: '${pattern}'`);
|
|
226
|
-
}
|
|
227
|
-
return result;
|
|
228
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { Bundle, GwtBundle } from './Task';
|
|
2
|
-
import { RawSourceMap } from 'source-map';
|
|
3
|
-
/**
|
|
4
|
-
* Information on a GWT function call, typically with code to be evaluated as arguments.
|
|
5
|
-
*/
|
|
6
|
-
export type GwtCallInfos = {
|
|
7
|
-
codeArguments: string[];
|
|
8
|
-
functionName: string;
|
|
9
|
-
codeAsArrayArgument: boolean;
|
|
10
|
-
};
|
|
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
|
-
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
|
-
export declare function extractGwtCallInfos(bundleContent: string): GwtCallInfos | null;
|
|
28
|
-
/**
|
|
29
|
-
* Load the source map for the given GWT bundle.
|
|
30
|
-
*/
|
|
31
|
-
export declare function loadInputSourceMapsGwt(taskFile: string, bundleFile: GwtBundle): Array<RawSourceMap | undefined>;
|
|
32
|
-
/**
|
|
33
|
-
* Determine the ID of the given GWT bundle file.
|
|
34
|
-
*/
|
|
35
|
-
export declare function determineGwtFileUid(filename: string): string | undefined;
|
|
36
|
-
/**
|
|
37
|
-
* Is the given bundle a GWT bundle?
|
|
38
|
-
*/
|
|
39
|
-
export declare function isGwtBundle(bundle: Bundle): bundle is GwtBundle;
|
|
40
|
-
//# sourceMappingURL=WebToolkit.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
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;AAE1C;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG;IAAE,aAAa,EAAE,MAAM,EAAE,CAAC;IAAC,YAAY,EAAE,MAAM,CAAC;IAAC,mBAAmB,EAAE,OAAO,CAAA;CAAE,CAAC;AAE3G;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,CAqBjE;AAkBD;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,aAAa,EAAE,MAAM,GAAG,YAAY,GAAG,IAAI,CA+B9E;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,GAAG,KAAK,CAAC,YAAY,GAAG,SAAS,CAAC,CAgC/G;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAOxE;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,IAAI,SAAS,CAE/D"}
|