@teamscale/javascript-instrumenter 1.0.0-beta.7 → 1.0.5

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.
Files changed (36) hide show
  1. package/dist/main.mjs +216 -0
  2. package/package.json +18 -9
  3. package/dist/package.json +0 -63
  4. package/dist/src/App.d.ts +0 -16
  5. package/dist/src/App.d.ts.map +0 -1
  6. package/dist/src/App.js +0 -233
  7. package/dist/src/instrumenter/FileSystem.d.ts +0 -10
  8. package/dist/src/instrumenter/FileSystem.d.ts.map +0 -1
  9. package/dist/src/instrumenter/FileSystem.js +0 -104
  10. package/dist/src/instrumenter/Instrumenter.d.ts +0 -25
  11. package/dist/src/instrumenter/Instrumenter.d.ts.map +0 -1
  12. package/dist/src/instrumenter/Instrumenter.js +0 -292
  13. package/dist/src/instrumenter/InstrumenterConfig.d.ts +0 -28
  14. package/dist/src/instrumenter/InstrumenterConfig.d.ts.map +0 -1
  15. package/dist/src/instrumenter/InstrumenterConfig.js +0 -159
  16. package/dist/src/instrumenter/RelativeCollectorPatternParser.d.ts +0 -6
  17. package/dist/src/instrumenter/RelativeCollectorPatternParser.d.ts.map +0 -1
  18. package/dist/src/instrumenter/RelativeCollectorPatternParser.js +0 -53
  19. package/dist/src/instrumenter/RelativeCollectorPatternParser.test.d.ts +0 -2
  20. package/dist/src/instrumenter/RelativeCollectorPatternParser.test.d.ts.map +0 -1
  21. package/dist/src/instrumenter/RelativeCollectorPatternParser.test.js +0 -33
  22. package/dist/src/instrumenter/Task.d.ts +0 -80
  23. package/dist/src/instrumenter/Task.d.ts.map +0 -1
  24. package/dist/src/instrumenter/Task.js +0 -228
  25. package/dist/src/instrumenter/TaskBuilder.d.ts +0 -25
  26. package/dist/src/instrumenter/TaskBuilder.d.ts.map +0 -1
  27. package/dist/src/instrumenter/TaskBuilder.js +0 -181
  28. package/dist/src/instrumenter/WebToolkit.d.ts +0 -13
  29. package/dist/src/instrumenter/WebToolkit.d.ts.map +0 -1
  30. package/dist/src/instrumenter/WebToolkit.js +0 -119
  31. package/dist/src/main.d.ts +0 -3
  32. package/dist/src/main.d.ts.map +0 -1
  33. package/dist/src/main.js +0 -10
  34. package/dist/src/vaccine/types.d.ts +0 -28
  35. package/dist/src/vaccine/types.d.ts.map +0 -1
  36. package/dist/src/vaccine/types.js +0 -2
@@ -1,292 +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
- var __importDefault = (this && this.__importDefault) || function (mod) {
36
- return (mod && mod.__esModule) ? mod : { "default": mod };
37
- };
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.IstanbulInstrumenter = exports.IS_INSTRUMENTED_TOKEN = void 0;
40
- exports.loadInputSourceMap = loadInputSourceMap;
41
- exports.sourceMapFromCodeComment = sourceMapFromCodeComment;
42
- const Task_1 = require("./Task");
43
- const commons_1 = require("@cqse/commons");
44
- const istanbul = __importStar(require("@teamscale/lib-instrument"));
45
- const fs = __importStar(require("fs"));
46
- const mkdirp = __importStar(require("mkdirp"));
47
- const path = __importStar(require("path"));
48
- const convertSourceMap = __importStar(require("convert-source-map"));
49
- const async_1 = __importDefault(require("async"));
50
- const WebToolkit_1 = require("./WebToolkit");
51
- const FileSystem_1 = require("./FileSystem");
52
- exports.IS_INSTRUMENTED_TOKEN = '$IS_JS_PROFILER_INSTRUMENTED=true';
53
- function readBundle(bundleContent, taskElement) {
54
- const baseNameMatch = /^([a-zA-Z0-9]*).cache.js/.exec(path.basename(taskElement.fromFile));
55
- const directories = path.dirname(taskElement.fromFile).split(path.sep);
56
- if (baseNameMatch && directories.length > 1) {
57
- const fragmentId = (0, WebToolkit_1.determineGwtFileUid)(taskElement.fromFile);
58
- const functionCall = /^([^(]+)\((.*)\);*\s*$/.exec(bundleContent);
59
- if (fragmentId && functionCall?.length === 3) {
60
- const callInfos = (0, WebToolkit_1.extractGwtCallInfos)(bundleContent);
61
- if (callInfos) {
62
- return {
63
- type: 'gwt',
64
- content: bundleContent,
65
- fragmentId,
66
- functionName: callInfos.functionName,
67
- codeAsArrayArgument: callInfos.codeAsArrayArgument,
68
- codeArguments: callInfos.codeArguments
69
- };
70
- }
71
- }
72
- }
73
- return { type: 'javascript', content: bundleContent, codeArguments: [bundleContent] };
74
- }
75
- class IstanbulInstrumenter {
76
- vaccineSource;
77
- logger;
78
- constructor(vaccineFilePath, logger, collector, targetBucket) {
79
- commons_1.Contract.require(fs.existsSync(vaccineFilePath), `The vaccine file to inject "${vaccineFilePath}" must exist!\nCWD:${process.cwd()}`);
80
- this.vaccineSource = this.loadVaccine(commons_1.Contract.requireNonEmpty(vaccineFilePath), collector, targetBucket);
81
- this.logger = logger;
82
- }
83
- async instrument(task) {
84
- this.clearFile(task.dumpOriginsFile);
85
- this.clearFile(task.dumpMatchedOriginsFile);
86
- const result = await async_1.default
87
- .mapLimit(task.elements, 1, async (taskElement) => {
88
- return await this.instrumentOne(taskElement, task.excludeFilesPattern, task.originSourcePattern, task.dumpOriginsFile);
89
- })
90
- .then(results => {
91
- return results.reduce((prev, curr) => {
92
- return prev.withIncrement(curr);
93
- }, Task_1.TaskResult.neutral(task));
94
- });
95
- this.dumpToJson(task.dumpMatchedOriginsFile, task.originSourcePattern.retrieveMatchingFiles());
96
- return result;
97
- }
98
- async instrumentOne(taskElement, excludeBundles, sourcePattern, dumpOriginsFile) {
99
- if (!this.isFileTypeSupported(taskElement.fromFile)) {
100
- if (!taskElement.isInPlace()) {
101
- copyToFile(taskElement.toFile, taskElement.fromFile);
102
- }
103
- return new Task_1.TaskResult(0, 0, 0, 0, 1, 0, 0);
104
- }
105
- const bundleContent = fs.readFileSync(taskElement.fromFile, 'utf8');
106
- const inputBundle = readBundle(bundleContent, taskElement);
107
- if (inputBundle.content.substring(0, Math.min(inputBundle.content.length, 100)).includes(exports.IS_INSTRUMENTED_TOKEN)) {
108
- if (!taskElement.isInPlace()) {
109
- writeToFile(taskElement.toFile, inputBundle.content);
110
- }
111
- return new Task_1.TaskResult(0, 0, 0, 1, 0, 0, 0);
112
- }
113
- if (excludeBundles.isExcluded(taskElement.fromFile)) {
114
- if (!taskElement.isInPlace()) {
115
- copyToFile(taskElement.toFile, taskElement.fromFile);
116
- }
117
- return new Task_1.TaskResult(0, 1, 0, 0, 0, 0, 0);
118
- }
119
- this.logger.info(`Instrumenting "${path.basename(taskElement.fromFile)}"`);
120
- const inputSourceMaps = loadInputSourceMaps(taskElement.fromFile, inputBundle, taskElement.externalSourceMapFile);
121
- if (inputSourceMaps.length === 0) {
122
- return Task_1.TaskResult.warning(`Failed loading input source map for ${taskElement.fromFile}.`);
123
- }
124
- const configurationAlternatives = this.configurationAlternativesFor(taskElement);
125
- for (let i = 0; i < configurationAlternatives.length; i++) {
126
- const configurationAlternative = configurationAlternatives[i];
127
- try {
128
- return await this.instrumentBundle(taskElement, inputBundle, inputSourceMaps, configurationAlternative, dumpOriginsFile, sourcePattern);
129
- }
130
- catch (e) {
131
- if (i === configurationAlternatives.length - 1) {
132
- writeToFile(taskElement.toFile, inputBundle.content);
133
- return Task_1.TaskResult.error(e);
134
- }
135
- }
136
- }
137
- return new Task_1.TaskResult(0, 0, 0, 0, 0, 1, 0);
138
- }
139
- async instrumentBundle(taskElement, inputBundle, inputSourceMaps, configurationAlternative, dumpOriginsFile, sourcePattern) {
140
- for (const inputSourceMap of inputSourceMaps.filter(map => map)) {
141
- const originSourceFiles = inputSourceMap?.sources ?? [];
142
- if (dumpOriginsFile) {
143
- this.dumpToJson(dumpOriginsFile, originSourceFiles);
144
- }
145
- }
146
- const instrumenter = istanbul.createInstrumenter(configurationAlternative);
147
- const instrumentedSources = [];
148
- for (let i = 0; i < inputBundle.codeArguments.length; i++) {
149
- const shouldInstrument = (_, originLocation) => {
150
- if (!originLocation.filename) {
151
- return false;
152
- }
153
- return sourcePattern.isIncluded(originLocation.filename);
154
- };
155
- const instrumented = await instrumenter.instrument(inputBundle.codeArguments[i], taskElement.fromFile, inputSourceMaps[i], shouldInstrument);
156
- instrumentedSources.push(instrumented);
157
- }
158
- this.writeBundleFile(taskElement.toFile, inputBundle, instrumentedSources);
159
- return new Task_1.TaskResult(1, 0, 0, 0, 0, 0, 0);
160
- }
161
- writeBundleFile(toFile, inputBundle, instrumentedSources) {
162
- if (inputBundle.type === 'gwt') {
163
- commons_1.Contract.require(instrumentedSources.length === 1, 'Assuming only one code fragment to be passed as argument.');
164
- const processedCodeString = JSON.stringify(`${this.vaccineSource} ${instrumentedSources[0]}`);
165
- if (inputBundle.codeAsArrayArgument) {
166
- writeToFile(toFile, `${exports.IS_INSTRUMENTED_TOKEN} ${inputBundle.functionName}([${processedCodeString}]);`);
167
- }
168
- else {
169
- writeToFile(toFile, `${exports.IS_INSTRUMENTED_TOKEN} ${inputBundle.functionName}(${processedCodeString});`);
170
- }
171
- }
172
- else {
173
- commons_1.Contract.require(instrumentedSources.length === 1, 'Assuming only one code fragment to be passed as argument for JavaScript bundles.');
174
- writeToFile(toFile, instrumentedSources[0]);
175
- }
176
- }
177
- loadVaccine(filePath, collector, targetBucket) {
178
- return fs.readFileSync(filePath, 'utf8')
179
- .replace(/\$COLLECTOR_SPECIFIER/g, JSON.stringify(collector))
180
- .replace(/\$BUCKET_SPECIFIER/g, Buffer.from(JSON.stringify(targetBucket)).toString('base64'));
181
- }
182
- isFileTypeSupported(fileName) {
183
- if (fileName.endsWith('.devmode.js') || fileName.endsWith('.nocache.js')) {
184
- return false;
185
- }
186
- const ext = path.extname(fileName).toLowerCase();
187
- return ext === '.js' || ext === '.mjs';
188
- }
189
- configurationAlternativesFor(taskElement) {
190
- this.logger.trace(`Determining configuration alternatives for ${taskElement.fromFile}`);
191
- const baseConfig = {
192
- isInstrumentedToken: exports.IS_INSTRUMENTED_TOKEN,
193
- produceSourceMap: 'none',
194
- codeToPrepend: this.vaccineSource,
195
- preserveComments: false,
196
- compact: false
197
- };
198
- return [
199
- { ...baseConfig, ...{ esModules: true } },
200
- { ...baseConfig, ...{ esModules: false } }
201
- ];
202
- }
203
- clearFile(filePath) {
204
- if (filePath && fs.existsSync(filePath)) {
205
- try {
206
- fs.unlinkSync(filePath);
207
- }
208
- catch (err) {
209
- this.logger.warn(`Could not clear file ${filePath}:` + err);
210
- }
211
- }
212
- }
213
- dumpToJson(targetFilePath, toDump) {
214
- if (!targetFilePath) {
215
- return;
216
- }
217
- const jsonContent = JSON.stringify(toDump, null, 2);
218
- fs.writeFile(targetFilePath, jsonContent + '\n', { flag: 'a' }, error => {
219
- if (error) {
220
- this.logger.warn(`Could not dump JSON to file ${targetFilePath}:` + error.message);
221
- }
222
- });
223
- }
224
- }
225
- exports.IstanbulInstrumenter = IstanbulInstrumenter;
226
- function loadInputSourceMaps(taskFile, bundleFile, externalSourceMapFile) {
227
- if ((0, WebToolkit_1.isGwtBundle)(bundleFile)) {
228
- return (0, WebToolkit_1.loadInputSourceMapsGwt)(taskFile, bundleFile);
229
- }
230
- else {
231
- return loadInputSourceMapsStandard(taskFile, bundleFile, externalSourceMapFile);
232
- }
233
- }
234
- function loadInputSourceMapsStandard(taskFile, bundleFile, externalSourceMapFile) {
235
- return bundleFile.codeArguments.map(code => loadInputSourceMap(code, taskFile, externalSourceMapFile));
236
- }
237
- function loadInputSourceMap(inputSource, taskFile, externalSourceMapFile) {
238
- if (externalSourceMapFile) {
239
- const sourceMapOrigin = externalSourceMapFile;
240
- if (!(sourceMapOrigin instanceof Task_1.SourceMapFileReference)) {
241
- throw new commons_1.IllegalArgumentException('Type of source map not yet supported!');
242
- }
243
- return (0, FileSystem_1.sourceMapFromMapFile)(sourceMapOrigin.sourceMapFilePath);
244
- }
245
- else {
246
- return sourceMapFromCodeComment(inputSource, taskFile);
247
- }
248
- }
249
- function sourceMapFromCodeComment(sourcecode, sourceFilePath) {
250
- const re = /\/\/[#@]\s(source(?:Mapping)?URL)=\s*(\S+)/g;
251
- let failedLoading = 0;
252
- let result;
253
- let matched;
254
- do {
255
- matched = re.exec(sourcecode);
256
- if (matched) {
257
- const sourceMapComment = matched[0];
258
- try {
259
- if (sourceMapComment.slice(0, 50).indexOf('data:application/json') > 0) {
260
- result = convertSourceMap.fromComment(sourceMapComment).toObject();
261
- }
262
- else {
263
- result = convertSourceMap
264
- .fromMapFileComment(sourceMapComment, function (filename) {
265
- return fs.readFileSync(path.resolve(path.dirname(sourceFilePath), filename), 'utf-8');
266
- })
267
- .toObject();
268
- }
269
- }
270
- catch {
271
- failedLoading++;
272
- }
273
- }
274
- } while (matched);
275
- if (result) {
276
- return result;
277
- }
278
- if (failedLoading > 0) {
279
- throw new commons_1.IllegalArgumentException('None of the referenced source map files loaded!');
280
- }
281
- else {
282
- return undefined;
283
- }
284
- }
285
- function writeToFile(filePath, fileContent) {
286
- mkdirp.sync(path.dirname(filePath));
287
- fs.writeFileSync(filePath, fileContent);
288
- }
289
- function copyToFile(targetFilePath, sourceFilePath) {
290
- mkdirp.sync(path.dirname(targetFilePath));
291
- fs.copyFileSync(sourceFilePath, targetFilePath);
292
- }
@@ -1,28 +0,0 @@
1
- import { ConfigurationParameters } from '@cqse/commons';
2
- import { LogLevelString } from 'bunyan';
3
- export type InstrumenterOptions = {
4
- version?: boolean;
5
- help?: boolean;
6
- input?: string[];
7
- inPlace?: boolean;
8
- to?: string;
9
- logLevel?: LogLevelString;
10
- configId?: string;
11
- appName?: string;
12
- commit?: string;
13
- sourceMap?: string;
14
- collector: string;
15
- relativeCollector?: string;
16
- includeOrigin?: string[];
17
- excludeOrigin?: string[];
18
- excludeBundle?: string[];
19
- dumpOriginsTo?: string;
20
- dumpOriginMatchesTo?: string;
21
- collectorConfigFile?: string;
22
- collectorConfigFileContent?: string;
23
- collectorOption?: string[];
24
- collectorOptionsList?: boolean;
25
- coverageTargetFromCollector?: boolean;
26
- };
27
- export declare function buildInstrumenterConfigurationParameters(): ConfigurationParameters;
28
- //# sourceMappingURL=InstrumenterConfig.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"InstrumenterConfig.d.ts","sourceRoot":"","sources":["../../../src/instrumenter/InstrumenterConfig.ts"],"names":[],"mappings":"AAAA,OAAO,EAEN,uBAAuB,EAGvB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC;AAQxC,MAAM,MAAM,mBAAmB,GAAG;IACjC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,QAAQ,CAAC,EAAE,cAAc,CAAC;IAC1B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IACzB,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IACzB,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IACzB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,0BAA0B,CAAC,EAAE,MAAM,CAAC;IACpC,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAC3B,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,2BAA2B,CAAC,EAAE,OAAO,CAAC;CACtC,CAAC;AA0BF,wBAAgB,wCAAwC,IAAI,uBAAuB,CA+IlF"}
@@ -1,159 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.buildInstrumenterConfigurationParameters = buildInstrumenterConfigurationParameters;
4
- const commons_1 = require("@cqse/commons");
5
- const commons_2 = require("@cqse/commons");
6
- const CONFIG_GROUP_INPUT = {
7
- order: 1,
8
- title: 'Instrumenter Input and Output'
9
- };
10
- const CONFIG_GROUP_TARGET_PARAMS = {
11
- order: 2,
12
- title: 'Coverage Target Parameters'
13
- };
14
- const CONFIG_GROUP_COVERAGE_SUBJECT = {
15
- order: 3,
16
- title: 'Coverage Subject'
17
- };
18
- const CONFIG_GROUP_DEBUGGING = {
19
- order: 4,
20
- title: 'Troubleshooting'
21
- };
22
- function buildInstrumenterConfigurationParameters() {
23
- const parameters = new commons_1.ConfigurationParameters();
24
- function addParameter(shortParameter, longParameter, type, options) {
25
- parameters.addParameter(shortParameter, longParameter, type, options);
26
- }
27
- addParameter('-i', '--input', 'string[]', {
28
- help: 'The input file(s) or folder(s) to instrument.',
29
- group: CONFIG_GROUP_INPUT
30
- });
31
- addParameter('-l', '--in-place', 'bool', {
32
- help: 'If set, the original files to instrument are replaced by their instrumented counterparts.',
33
- group: CONFIG_GROUP_INPUT
34
- });
35
- addParameter('-o', '--to', 'string', {
36
- help: 'Path (directory or file name) to write the instrumented version to.',
37
- group: CONFIG_GROUP_INPUT
38
- });
39
- addParameter('-r', '--commit', 'string', {
40
- help: 'The commit (<branch name>:<UNIX timestamp in milliseconds>) or revision (Git hash) of the code to report coverage for.',
41
- group: CONFIG_GROUP_TARGET_PARAMS
42
- });
43
- addParameter('-c', '--collector', 'string', {
44
- help: 'The collector (`host:port` or `wss://host:port/` or `ws://host:port/`) to send coverage information to.',
45
- default: 'ws://localhost:54678',
46
- group: CONFIG_GROUP_TARGET_PARAMS
47
- });
48
- addParameter('-a', '--app-name', 'string', {
49
- help: 'The name of the application to report coverage for. Will be used to make the automatically generated application ID more readable.',
50
- group: CONFIG_GROUP_TARGET_PARAMS
51
- });
52
- addParameter(undefined, '--coverage-target-from-collector', 'bool', {
53
- help: 'All coverage target (upload) parameters, for example, the target partition, shall be specified by the collector.',
54
- group: CONFIG_GROUP_TARGET_PARAMS
55
- });
56
- addParameter('-f', '--config-id', 'string', {
57
- help: 'The ID of the profiler configuration to use; this configuration is refetched from Teamscale once a minute.',
58
- group: CONFIG_GROUP_TARGET_PARAMS
59
- });
60
- addParameter('-t', '--collector-config-file', 'string', {
61
- help: 'Provide a configuration file that specifies or overwrites the configuration of the Coverage Collector.',
62
- group: CONFIG_GROUP_TARGET_PARAMS
63
- });
64
- addParameter(undefined, '--collector-option', 'string[]', {
65
- help: 'Sets a given collector configuration option. Provided as key=value pairs.',
66
- group: CONFIG_GROUP_TARGET_PARAMS
67
- });
68
- addParameter(undefined, '--collector-options-list', 'bool', {
69
- help: 'Lists the options that can be set for the collector, via a --collector-config-file or via --collector-option.',
70
- group: CONFIG_GROUP_TARGET_PARAMS
71
- });
72
- addParameter(undefined, '--source-map', 'string', {
73
- help: 'External location of source-map files to consider.',
74
- group: CONFIG_GROUP_COVERAGE_SUBJECT
75
- });
76
- addParameter(undefined, '--relative-collector', 'string', {
77
- help: 'Pattern used to determine the collector URL from the application hostname.'
78
- + ' Useful for Kubernetes deployments where the collector URL is not known at instrumentation time.'
79
- + ' Example: `replace-in-host:app collector,scheme:wss`.'
80
- + ' This causes the first occurrence of `app` in the application hostname to be replaced with `collector`'
81
- + ' and the URL scheme changed to wss.'
82
- + ' Available operations:'
83
- + ' `replace-in-host:SEARCH REPLACE` replaces the literal term SEARCH once in the hostname with REPLACE.'
84
- + ' `port:NUMBER` changes the port to NUMBER.'
85
- + ' `port:keep` keeps the port of the application (instead of using the chosen scheme\'s default port).'
86
- + ' `scheme:SCHEME` changes the URL scheme to one of ws, wss, http or https.'
87
- + ' `path:PATH` uses the URL path PATH (instead of no path).',
88
- group: CONFIG_GROUP_TARGET_PARAMS
89
- });
90
- addParameter('-x', '--exclude-origin', 'string[]', {
91
- help: 'Glob pattern(s) of files in the source origin to not produce coverage for. Multiple patterns can be separated by comma.',
92
- group: CONFIG_GROUP_INPUT
93
- });
94
- addParameter('-k', '--include-origin', 'string[]', {
95
- help: 'Glob pattern(s) of files in the source origin to produce coverage for. Multiple patterns can be separated by comma.',
96
- group: CONFIG_GROUP_INPUT
97
- });
98
- addParameter('-e', '--exclude-bundle', 'string[]', {
99
- help: 'Glob pattern(s) of input (bundle) files to keep unchanged (to not instrument).',
100
- group: CONFIG_GROUP_INPUT
101
- });
102
- addParameter('-p', '--dump-origins-to', 'string', {
103
- help: 'Path specifying where to dump source origins file names, based on the source maps, as a JSON file.',
104
- group: CONFIG_GROUP_DEBUGGING
105
- });
106
- addParameter('-m', '--dump-origin-matches-to', 'string', {
107
- help: 'Path specifying where to dump a JSON with the names of the files that have matched the origin include/exclude patterns.',
108
- group: CONFIG_GROUP_DEBUGGING
109
- });
110
- addParameter(undefined, '--log-level', 'string', {
111
- help: 'Log level', default: 'info', group: CONFIG_GROUP_DEBUGGING
112
- });
113
- parameters.addArgumentCheck(options => {
114
- if (!Array.isArray(options.input) || options.input.length === 0) {
115
- return 'The --input parameter must be provided with the list of files or folders to instrument.';
116
- }
117
- });
118
- parameters.addRequiredArgumentFor('commit');
119
- parameters.addArgumentCheck(options => {
120
- if (!(0, commons_2.isValidCommitInfo)(options.commit)) {
121
- return 'The given commit must be of the form <branch>:<UNIX timestamp in milliseconds> or a Git hash.';
122
- }
123
- });
124
- parameters.addArgumentCheck(options => {
125
- if (!options.collector && !options.relativeCollector) {
126
- return 'Either a collector URL or a relative collector URL must be specified.';
127
- }
128
- });
129
- parameters.addArgumentCheck(options => {
130
- if (options.coverageTargetFromCollector) {
131
- if (Array.isArray(options.collectorOption) && options.collectorOption.length > 0) {
132
- const optionsSet = new Set(options.collectorOption.map((value) => value.split("=")[0]));
133
- if (optionsSet.has("teamscale-partition")
134
- || optionsSet.has("teamscale-project")
135
- || optionsSet.has("teamscale-repository")
136
- || optionsSet.has("teamscale-message")) {
137
- return 'The parameter `--coverage-target-from-collector` cannot be combined ' +
138
- 'with explicitly setting upload target options in the instrumenter.';
139
- }
140
- }
141
- }
142
- else {
143
- if (!options.configId && !options.collectorConfigFile && !(Array.isArray(options.collectorOption) && options.collectorOption.length > 0)) {
144
- return 'Either a configuration ID (--config-id), a collector configuration file (--collector-config-file) ' +
145
- 'or explicit collector options (--collector-option) must be specified. You can also decide to set all ' +
146
- 'coverage upload parameters on the collector side only by setting --coverage-target-from-collector.';
147
- }
148
- }
149
- });
150
- parameters.addArgumentCheck(options => {
151
- if (options.logLevel !== undefined) {
152
- const validLevels = ["trace", "debug", "info", "warn", "error", "fatal"];
153
- if (!validLevels.includes(options.logLevel)) {
154
- return "Please provide a valid value for --log-level. One of: " + validLevels.join(", ");
155
- }
156
- }
157
- });
158
- return parameters;
159
- }
@@ -1,6 +0,0 @@
1
- import { CollectorSpecifierRelative } from "../vaccine/types";
2
- export declare class RelativeCollectorPatternParser {
3
- static parse(pattern: string): CollectorSpecifierRelative;
4
- private static apply;
5
- }
6
- //# sourceMappingURL=RelativeCollectorPatternParser.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"RelativeCollectorPatternParser.d.ts","sourceRoot":"","sources":["../../../src/instrumenter/RelativeCollectorPatternParser.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,0BAA0B,EAAE,MAAM,kBAAkB,CAAC;AAG9D,qBAAa,8BAA8B;IAGvC,MAAM,CAAC,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,0BAA0B;IAkBzD,OAAO,CAAC,MAAM,CAAC,KAAK;CAkCvB"}
@@ -1,53 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RelativeCollectorPatternParser = void 0;
4
- const commons_1 = require("@cqse/commons");
5
- class RelativeCollectorPatternParser {
6
- static parse(pattern) {
7
- const parts = pattern.split(",");
8
- const specifier = {
9
- type: "relative"
10
- };
11
- for (const part of parts) {
12
- const colonIndex = part.indexOf(":");
13
- commons_1.Contract.require(colonIndex > -1, `Invalid relative collector pattern ${pattern}: ${part} has no colon after the operation`);
14
- const operation = part.substring(0, colonIndex);
15
- const value = part.substring(colonIndex + 1);
16
- RelativeCollectorPatternParser.apply(operation, value, specifier);
17
- }
18
- return specifier;
19
- }
20
- static apply(operation, value, specifier) {
21
- switch (operation) {
22
- case "port":
23
- commons_1.Contract.requireStringPattern(value, /[0-9]+|keep/, `Invalid relative collector pattern: port must be a number: ${value}`);
24
- if (value === "keep") {
25
- specifier.port = value;
26
- }
27
- else {
28
- specifier.port = parseInt(value);
29
- }
30
- break;
31
- case "replace-in-host":
32
- {
33
- commons_1.Contract.requireStringPattern(value, /[^ ]+ [^ ]*/, `Invalid relative collector pattern: replace-in-host must contain exactly one space to separate search string and replacement: ${value}`);
34
- const parts = value.split(" ");
35
- specifier.hostReplace = {
36
- search: parts[0],
37
- replace: parts[1],
38
- };
39
- break;
40
- }
41
- case "path":
42
- specifier.path = value;
43
- break;
44
- case "scheme":
45
- commons_1.Contract.requireStringPattern(value, /ws|wss|http|https/i, `Invalid relative collector pattern: scheme must be one of ws, wss, http or https: ${value}`);
46
- specifier.scheme = value.toLowerCase();
47
- break;
48
- default:
49
- throw new commons_1.IllegalArgumentException(`Invalid relative collector pattern: unknown operation ${operation}`);
50
- }
51
- }
52
- }
53
- exports.RelativeCollectorPatternParser = RelativeCollectorPatternParser;
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=RelativeCollectorPatternParser.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"RelativeCollectorPatternParser.test.d.ts","sourceRoot":"","sources":["../../../src/instrumenter/RelativeCollectorPatternParser.test.ts"],"names":[],"mappings":""}
@@ -1,33 +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
- const node_test_1 = require("node:test");
7
- const strict_1 = __importDefault(require("node:assert/strict"));
8
- const RelativeCollectorPatternParser_1 = require("./RelativeCollectorPatternParser");
9
- (0, node_test_1.describe)("SubstitutionPatternParser", () => {
10
- (0, node_test_1.test)('empty pattern', () => {
11
- strict_1.default.deepStrictEqual(RelativeCollectorPatternParser_1.RelativeCollectorPatternParser.parse(""), {
12
- type: "relative",
13
- });
14
- });
15
- (0, node_test_1.test)('keep port', () => {
16
- strict_1.default.deepStrictEqual(RelativeCollectorPatternParser_1.RelativeCollectorPatternParser.parse(""), {
17
- type: "relative",
18
- port: "keep",
19
- });
20
- });
21
- (0, node_test_1.test)('all features', () => {
22
- strict_1.default.deepStrictEqual(RelativeCollectorPatternParser_1.RelativeCollectorPatternParser.parse("scheme:wss,port:1234,replace-in-host:foo bar,path:path/path"), {
23
- type: "relative",
24
- hostReplace: {
25
- search: "foo",
26
- replace: "bar",
27
- },
28
- path: "path/path",
29
- port: 1234,
30
- scheme: "wss",
31
- });
32
- });
33
- });
@@ -1,80 +0,0 @@
1
- import { CollectorSpecifier, CoverageBucketSpecifier } from '../vaccine/types';
2
- export declare abstract class SourceMapReference {
3
- }
4
- type BaseBundle = {
5
- content: string;
6
- codeArguments: string[];
7
- };
8
- export type StandardBundle = BaseBundle & {
9
- type: 'javascript';
10
- };
11
- export type GwtBundle = BaseBundle & {
12
- type: 'gwt';
13
- functionName: string;
14
- fragmentId: string;
15
- codeAsArrayArgument: boolean;
16
- };
17
- export type Bundle = BaseBundle & (StandardBundle | GwtBundle);
18
- export declare class TaskElement {
19
- readonly fromFile: string;
20
- readonly toFile: string;
21
- readonly externalSourceMapFile?: SourceMapReference;
22
- constructor(fromFile: string, toFile: string, externalSourceMap?: SourceMapReference);
23
- isInPlace(): boolean;
24
- }
25
- export declare function createCollectorSpecifier(commandLineUrl: string, relativePattern?: string): CollectorSpecifier;
26
- export declare class OriginSourcePattern {
27
- private readonly include;
28
- private readonly exclude;
29
- private readonly includeMatches;
30
- private readonly excludeMatches;
31
- private readonly neitherExcludedNorIncluded;
32
- constructor(include: string[] | undefined, exclude: string[] | undefined);
33
- isIncluded(originFile: string): boolean;
34
- isAnyIncluded(originFiles: string[]): boolean;
35
- retrieveMatchingFiles(): {
36
- includePatterns: string[];
37
- excludePatterns: string[];
38
- excludeMatches: string[];
39
- includeMatches: string[];
40
- neitherExcludedNorIncluded: string[];
41
- };
42
- patternsSpecified(): boolean;
43
- }
44
- export declare class FileExcludePattern {
45
- private readonly exclude;
46
- constructor(exclude: string[] | undefined);
47
- isExcluded(filePath: string): boolean;
48
- }
49
- export declare class InstrumentationTask {
50
- readonly collector: CollectorSpecifier;
51
- readonly targetBucket: CoverageBucketSpecifier;
52
- private readonly _elements;
53
- readonly originSourcePattern: OriginSourcePattern;
54
- readonly excludeFilesPattern: FileExcludePattern;
55
- readonly dumpOriginsFile: string | undefined;
56
- readonly dumpMatchedOriginsFile: string | undefined;
57
- constructor(collector: CollectorSpecifier, targetBucket: CoverageBucketSpecifier, elements: TaskElement[], excludeFilesPattern: FileExcludePattern, originSourcePattern: OriginSourcePattern, dumpOriginsFile: string | undefined, dumpMatchedOriginsFile: string | undefined);
58
- get elements(): TaskElement[];
59
- }
60
- export declare class TaskResult {
61
- readonly translated: number;
62
- readonly excluded: number;
63
- readonly translatedFromCache: number;
64
- readonly alreadyInstrumented: number;
65
- readonly unsupported: number;
66
- readonly failed: number;
67
- readonly warnings: number;
68
- readonly task?: InstrumentationTask;
69
- constructor(translated: number, excluded: number, translatedFromCache: number, alreadyInstrumented: number, unsupported: number, failed: number, warnings: number, task?: InstrumentationTask);
70
- withIncrement(incBy: TaskResult): TaskResult;
71
- static neutral(task?: InstrumentationTask): TaskResult;
72
- static error(e: Error): TaskResult;
73
- static warning(msg: string): TaskResult;
74
- }
75
- export declare class SourceMapFileReference extends SourceMapReference {
76
- readonly sourceMapFilePath: string;
77
- constructor(sourceMapFilePath: string);
78
- }
79
- export {};
80
- //# sourceMappingURL=Task.d.ts.map