@teamscale/javascript-instrumenter 0.1.0-beta.5 → 0.1.0-beta.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teamscale/javascript-instrumenter",
3
- "version": "0.1.0-beta.5",
3
+ "version": "0.1.0-beta.6",
4
4
  "description": "JavaScript coverage instrumenter with coverage forwarding to a collector process",
5
5
  "main": "dist/src/main.js",
6
6
  "bin": "dist/src/main.js",
@@ -38,7 +38,7 @@
38
38
  "@types/node": "^20.11.19",
39
39
  "@types/ws": "^8.5.10",
40
40
  "babel-jest": "^29.7.0",
41
- "esbuild": "^0.20.0",
41
+ "esbuild": "^0.20.1",
42
42
  "esbuild-plugin-inline-worker": "^0.1.1",
43
43
  "jest": "^29.7.0",
44
44
  "rimraf": "^5.0.5",
@@ -48,7 +48,7 @@
48
48
  "typescript": "^5.3.3"
49
49
  },
50
50
  "dependencies": {
51
- "@cqse/commons": "0.1.0-beta.4",
51
+ "@cqse/commons": "0.1.0-beta.5",
52
52
  "@teamscale/lib-instrument": "workspace:../lib-instrument",
53
53
  "@babel/generator": "^7.23.6",
54
54
  "@babel/parser": "^7.23.9",
@@ -1 +1 @@
1
- {"version":3,"file":"App.d.ts","sourceRoot":"","sources":["../../src/App.ts"],"names":[],"mappings":"AACA,OAAO,EAA0C,UAAU,EAAC,MAAM,qBAAqB,CAAC;AAGxF,OAAO,EAAE,uBAAuB,EAAe,MAAM,4BAA4B,CAAC;AAKlF,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B;;GAEG;AACH,qBAAa,GAAG;IACf;;;OAGG;WACiB,GAAG,IAAI,OAAO,CAAC,UAAU,CAAC;IAe9C;;;OAGG;WACW,iBAAiB,CAAC,MAAM,EAAE,uBAAuB,GAAG,IAAI;IAwCtE;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,WAAW;IA4C1B;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,WAAW;IA+B1B;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,gBAAgB;IAI/B;;;;;OAKG;WACW,qBAAqB,CAAC,MAAM,EAAE,uBAAuB,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;IAS1G,OAAO,CAAC,MAAM,CAAC,yBAAyB;IAIxC,OAAO,CAAC,MAAM,CAAC,kBAAkB;CAajC"}
1
+ {"version":3,"file":"App.d.ts","sourceRoot":"","sources":["../../src/App.ts"],"names":[],"mappings":"AACA,OAAO,EAAuB,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAGtE,OAAO,EAAE,uBAAuB,EAAe,MAAM,4BAA4B,CAAC;AAKlF,OAAO,MAAM,MAAM,QAAQ,CAAC;AAG5B;;GAEG;AACH,qBAAa,GAAG;IACf;;;OAGG;WACiB,GAAG,IAAI,OAAO,CAAC,UAAU,CAAC;IAe9C;;;OAGG;WACW,iBAAiB,CAAC,MAAM,EAAE,uBAAuB,GAAG,IAAI;IAwCtE;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,WAAW;IA0D1B;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,WAAW;IA+B1B;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,gBAAgB;IAI/B;;;;;OAKG;WACW,qBAAqB,CAAC,MAAM,EAAE,uBAAuB,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;IAS1G,OAAO,CAAC,MAAM,CAAC,yBAAyB;IAIxC,OAAO,CAAC,MAAM,CAAC,kBAAkB;CAajC"}
package/dist/src/App.js CHANGED
@@ -51,8 +51,8 @@ class App {
51
51
  const config = parser.parse_args();
52
52
  // Build the logger
53
53
  const logger = this.buildLogger(config);
54
- logger.debug('Retrieved arguments', process.argv);
55
- logger.debug('Translated arguments to config', config);
54
+ logger.trace('Retrieved arguments', process.argv);
55
+ logger.trace('Translated arguments to config', config);
56
56
  // Run the instrumenter with the given configuration.
57
57
  return this.runForConfigArguments(config, logger);
58
58
  }
@@ -123,6 +123,19 @@ class App {
123
123
  help: 'The collector (`host:port` or `wss://host:port/` or `ws://host:port/`) to send coverage information to.',
124
124
  default: 'ws://localhost:54678'
125
125
  });
126
+ parser.add_argument('--relative-collector', {
127
+ help: 'Pattern used to determine the collector URL from the application hostname.'
128
+ + ' Useful for Kubernetes deployments where the collector URL is not known at instrumentation time.'
129
+ + ' Example: `replace-in-host:app collector,scheme:wss`.'
130
+ + ' This causes the first occurrence of `app` in the application hostname to be replaced with `collector`'
131
+ + ' and the URL scheme changed to wss.'
132
+ + ' Available operations:'
133
+ + ' `replace-in-host:SEARCH REPLACE` replaces the literal term SEARCH once in the hostname with REPLACE.'
134
+ + ' `port:NUMBER` changes the port to NUMBER.'
135
+ + ' `port:keep` keeps the port of the application (instead of using the chosen scheme\'s default port).'
136
+ + ' `scheme:SCHEME` changes the URL scheme to one of ws, wss, http or https.'
137
+ + ' `path:PATH` uses the URL path PATH (instead of no path).'
138
+ });
126
139
  parser.add_argument('-x', '--exclude-origin', {
127
140
  nargs: '*',
128
141
  help: 'Glob pattern(s) of files in the source origin to not produce coverage for. Multiple patterns can be separated by space.'
@@ -1,7 +1,8 @@
1
- import { CollectorSpecifier, FileExcludePattern, InstrumentationTask, OriginSourcePattern, SourceMapReference, TaskElement, TaskResult } from './Task';
1
+ import { FileExcludePattern, InstrumentationTask, OriginSourcePattern, SourceMapReference, TaskElement, TaskResult } from './Task';
2
2
  import { RawSourceMap, SourceMapConsumer } from 'source-map';
3
3
  import { Optional } from 'typescript-optional';
4
4
  import Logger from 'bunyan';
5
+ import { CollectorSpecifier } from '@src/vaccine/types';
5
6
  export declare const IS_INSTRUMENTED_TOKEN = "$IS_JS_PROFILER_INSTRUMENTED=true";
6
7
  /**
7
8
  * An instrumenter that can conduct a {@code InstrumentationTask}.
@@ -1 +1 @@
1
- {"version":3,"file":"Instrumenter.d.ts","sourceRoot":"","sources":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,SAAS,EAAE,kBAAkB;IAUlF;;OAEG;IACG,UAAU,CAAC,IAAI,EAAE,mBAAmB,GAAG,OAAO,CAAC,UAAU,CAAC;IA2BhE;;;;;;;;OAQG;IACG,aAAa,CAClB,WAAW,EAAE,WAAW,EACxB,cAAc,EAAE,kBAAkB,EAClC,aAAa,EAAE,mBAAmB,EAClC,eAAe,EAAE,MAAM,GAAG,SAAS,GACjC,OAAO,CAAC,UAAU,CAAC;YAsER,gBAAgB;IA8C9B,OAAO,CAAC,eAAe;IA0BvB;;;;OAIG;IACH,OAAO,CAAC,WAAW;IAMnB;;OAEG;IACH,OAAO,CAAC,mBAAmB;IAS3B;;;OAGG;IACH,OAAO,CAAC,4BAA4B;IAgBpC,+EAA+E;IAC/E,OAAO,CAAC,SAAS;IAUjB,+EAA+E;IAC/E,OAAO,CAAC,UAAU;CAYlB;AAED;;;;;GAKG;AACH,wBAAsB,aAAa,CAClC,kBAAkB,EAAE,MAAM,EAC1B,0BAA0B,EAAE,MAAM,GAChC,OAAO,CAAC,iBAAiB,GAAG,SAAS,CAAC,CAUxC;AAsBD;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CACjC,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,MAAM,EAChB,qBAAqB,EAAE,QAAQ,CAAC,kBAAkB,CAAC,GACjD,YAAY,GAAG,SAAS,CAU1B;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,CAAC,UAAU,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS,CAwC7G"}
@@ -204,7 +204,7 @@ class IstanbulInstrumenter {
204
204
  loadVaccine(filePath, collector) {
205
205
  // We first replace parameters in the file with the
206
206
  // actual values, for example, the collector to send the coverage information to.
207
- return fs.readFileSync(filePath, 'utf8').replace(/\$REPORT_TO_URL/g, collector.url);
207
+ return fs.readFileSync(filePath, 'utf8').replace(/\$COLLECTOR_SPECIFIER/g, JSON.stringify(collector));
208
208
  }
209
209
  /**
210
210
  * @returns whether the given file is supported for instrumentation.
@@ -222,7 +222,7 @@ class IstanbulInstrumenter {
222
222
  * given task element.
223
223
  */
224
224
  configurationAlternativesFor(taskElement) {
225
- this.logger.debug(`Determining configuration alternatives for ${taskElement.fromFile}`);
225
+ this.logger.trace(`Determining configuration alternatives for ${taskElement.fromFile}`);
226
226
  const baseConfig = {
227
227
  isInstrumentedToken: exports.IS_INSTRUMENTED_TOKEN,
228
228
  produceSourceMap: 'external',
@@ -0,0 +1,8 @@
1
+ import { CollectorSpecifierRelative } from "@src/vaccine/types";
2
+ /** Parses a relative collector pattern. */
3
+ export declare class RelativeCollectorPatternParser {
4
+ /** Parses the given pattern. */
5
+ static parse(pattern: string): CollectorSpecifierRelative;
6
+ private static apply;
7
+ }
8
+ //# sourceMappingURL=RelativeCollectorPatternParser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RelativeCollectorPatternParser.d.ts","sourceRoot":"","sources":["../../../src/instrumenter/RelativeCollectorPatternParser.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,0BAA0B,EAAE,MAAM,oBAAoB,CAAC;AAEhE,2CAA2C;AAC3C,qBAAa,8BAA8B;IAEvC,gCAAgC;IAChC,MAAM,CAAC,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,0BAA0B;IAkBzD,OAAO,CAAC,MAAM,CAAC,KAAK;CAgCvB"}
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RelativeCollectorPatternParser = void 0;
4
+ const commons_1 = require("@cqse/commons");
5
+ /** Parses a relative collector pattern. */
6
+ class RelativeCollectorPatternParser {
7
+ /** Parses the given pattern. */
8
+ static parse(pattern) {
9
+ const parts = pattern.split(",");
10
+ const specifier = {
11
+ type: "relative"
12
+ };
13
+ for (const part of parts) {
14
+ const colonIndex = part.indexOf(":");
15
+ commons_1.Contract.require(colonIndex > -1, `Invalid relative collector pattern ${pattern}: ${part} has no colon after the operation`);
16
+ const operation = part.substring(0, colonIndex);
17
+ const value = part.substring(colonIndex + 1);
18
+ RelativeCollectorPatternParser.apply(operation, value, specifier);
19
+ }
20
+ return specifier;
21
+ }
22
+ static apply(operation, value, specifier) {
23
+ switch (operation) {
24
+ case "port":
25
+ commons_1.Contract.requireStringPattern(value, /[0-9]+|keep/, `Invalid relative collector pattern: port must be a number: ${value}`);
26
+ if (value === "keep") {
27
+ specifier.port = value;
28
+ }
29
+ else {
30
+ specifier.port = parseInt(value);
31
+ }
32
+ break;
33
+ case "replace-in-host":
34
+ commons_1.Contract.requireStringPattern(value, /[^ ]+ [^ ]*/, `Invalid relative collector pattern: replace-in-host must contain exactly one space to separate search string and replacement: ${value}`);
35
+ const parts = value.split(" ");
36
+ specifier.hostReplace = {
37
+ search: parts[0],
38
+ replace: parts[1],
39
+ };
40
+ break;
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;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=RelativeCollectorPatternParser.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RelativeCollectorPatternParser.test.d.ts","sourceRoot":"","sources":["../../../src/instrumenter/RelativeCollectorPatternParser.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const RelativeCollectorPatternParser_1 = require("./RelativeCollectorPatternParser");
4
+ describe("SubstitutionPatternParser", () => {
5
+ test('empty pattern', () => {
6
+ expect(RelativeCollectorPatternParser_1.RelativeCollectorPatternParser.parse("")).toEqual({
7
+ type: "relative",
8
+ });
9
+ });
10
+ test('keep port', () => {
11
+ expect(RelativeCollectorPatternParser_1.RelativeCollectorPatternParser.parse("")).toEqual({
12
+ type: "relative",
13
+ port: "keep",
14
+ });
15
+ });
16
+ test('all features', () => {
17
+ expect(RelativeCollectorPatternParser_1.RelativeCollectorPatternParser.parse("scheme:wss,port:1234,replace-in-host:foo bar,path:path/path")).toEqual({
18
+ type: "relative",
19
+ hostReplace: {
20
+ search: "foo",
21
+ replace: "bar",
22
+ },
23
+ path: "path/path",
24
+ port: 1234,
25
+ scheme: "wss",
26
+ });
27
+ });
28
+ });
@@ -1,4 +1,5 @@
1
1
  import { Optional } from 'typescript-optional';
2
+ import { CollectorSpecifier } from '../vaccine/types';
2
3
  /**
3
4
  * An abstract source map type.
4
5
  */
@@ -46,14 +47,13 @@ export declare class TaskElement {
46
47
  isInPlace(): boolean;
47
48
  }
48
49
  /**
49
- * Specifies the collector that is supposed to
50
- * receive the coverage information.
50
+ * Given a command-line URL and an optional relative pattern, create a specifier for how the vaccine can
51
+ * locate the connector.
52
+ *
53
+ * If a relative pattern is given, it is preferred, since the command-line interface always provides a URL
54
+ * (the default URL in case the user didn't explicitly specify one).
51
55
  */
52
- export declare class CollectorSpecifier {
53
- /** The URL specifying the address the collector is reachable at. */
54
- readonly url: string;
55
- constructor(specifier: string);
56
- }
56
+ export declare function createCollectorSpecifier(commandLineUrl: string, relativePattern?: string): CollectorSpecifier;
57
57
  /**
58
58
  * Patterns that define which parts of a given bundle to instrument or not.
59
59
  *
@@ -1 +1 @@
1
- {"version":3,"file":"Task.d.ts","sourceRoot":"","sources":["../../../src/instrumenter/Task.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAK/C;;GAEG;AACH,8BAAsB,kBAAkB;CAAG;AAE3C,KAAK,UAAU,GAAG;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,MAAM,EAAE,CAAA;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,GAAG,EAAE,MAAM,GAAG,UAAU;CAI9C;AAED;;GAEG;AACH,qBAAa,sBAAuB,SAAQ,kBAAkB;IAC7D,2CAA2C;IAC3C,SAAgB,iBAAiB,EAAE,MAAM,CAAC;gBAE9B,iBAAiB,EAAE,MAAM;CAIrC"}
@@ -3,10 +3,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.SourceMapFileReference = exports.TaskResult = exports.InstrumentationTask = exports.FileExcludePattern = exports.OriginSourcePattern = exports.CollectorSpecifier = exports.TaskElement = exports.SourceMapReference = void 0;
6
+ exports.SourceMapFileReference = exports.TaskResult = exports.InstrumentationTask = exports.FileExcludePattern = exports.OriginSourcePattern = exports.createCollectorSpecifier = exports.TaskElement = exports.SourceMapReference = void 0;
7
7
  const typescript_optional_1 = require("typescript-optional");
8
8
  const commons_1 = require("@cqse/commons");
9
9
  const micromatch_1 = __importDefault(require("micromatch"));
10
+ const RelativeCollectorPatternParser_1 = require("./RelativeCollectorPatternParser");
10
11
  /**
11
12
  * An abstract source map type.
12
13
  */
@@ -34,24 +35,39 @@ class TaskElement {
34
35
  }
35
36
  exports.TaskElement = TaskElement;
36
37
  /**
37
- * Specifies the collector that is supposed to
38
- * receive the coverage information.
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).
39
43
  */
40
- class CollectorSpecifier {
41
- constructor(specifier) {
42
- if (specifier.indexOf('://') > 0) {
43
- // A trailing slash will be removed
44
- this.url = specifier.replace(/\/$/, '');
45
- }
46
- else {
47
- commons_1.Contract.requireStringPattern(specifier, '.+:[0-9]+', 'Invalid collector pattern used!');
48
- const host = specifier.split(':')[0];
49
- const port = Number.parseInt(specifier.split(':')[1]);
50
- this.url = `ws://${host}:${port}`;
51
- }
44
+ function createCollectorSpecifier(commandLineUrl, relativePattern) {
45
+ if (relativePattern !== undefined) {
46
+ return RelativeCollectorPatternParser_1.RelativeCollectorPatternParser.parse(relativePattern);
47
+ }
48
+ return parseCommandLineUrl(commandLineUrl);
49
+ }
50
+ exports.createCollectorSpecifier = createCollectorSpecifier;
51
+ /**
52
+ * Parses, validates and normalizes the given URL that the user provided on the command-line.
53
+ */
54
+ function parseCommandLineUrl(commandLineUrl) {
55
+ let url;
56
+ if (commandLineUrl.indexOf('://') > 0) {
57
+ // A trailing slash will be removed
58
+ url = commandLineUrl.replace(/\/$/, '');
59
+ }
60
+ else {
61
+ commons_1.Contract.requireStringPattern(commandLineUrl, '.+:[0-9]+', 'Invalid collector pattern used!');
62
+ const host = commandLineUrl.split(':')[0];
63
+ const port = Number.parseInt(commandLineUrl.split(':')[1]);
64
+ url = `ws://${host}:${port}`;
52
65
  }
66
+ return {
67
+ type: "url",
68
+ url,
69
+ };
53
70
  }
54
- exports.CollectorSpecifier = CollectorSpecifier;
55
71
  /**
56
72
  * Configuration used to match paths with `micromatch`.
57
73
  */
@@ -7,6 +7,7 @@ export type ConfigurationParameters = {
7
7
  to?: string;
8
8
  source_map?: string;
9
9
  collector: string;
10
+ collector_pattern?: string;
10
11
  include_origin?: string[];
11
12
  exclude_origin?: string[];
12
13
  exclude_bundle?: string[];
@@ -37,8 +38,8 @@ export declare class TaskBuilder {
37
38
  */
38
39
  private dumpMatchedOriginsFile;
39
40
  constructor();
40
- /** Set the collector by extracting the information from a given string */
41
- setCollectorFromString(collectorSpecification: string): this;
41
+ /** Set the collector specification based on the command-line arguments. */
42
+ setCollectorFromCommandLine(commandLineUrl: string, relativePattern?: string): this;
42
43
  /** Set the origin include pattern. If multiple patterns are present, concatenates them via the OR operator. */
43
44
  setOriginSourceIncludePatterns(patterns: string[] | undefined): this;
44
45
  /** Set the origin exclude pattern(s). If multiple patterns are present, concatenates them via the OR operator. */
@@ -1 +1 @@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AEzC,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;;IAOnD,2EAA2E;IAC3E,2BAA2B,CAAC,cAAc,EAAE,MAAM,EAAE,eAAe,CAAC,EAAE,MAAM,GAAG,IAAI;IAMnF,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,uBAAuB,GAAG,IAAI;IAqCpD;;;;;;;OAOG;IACH,OAAO,CAAC,4CAA4C;IAgCpD;;;;;;OAMG;IACH,OAAO,CAAC,0BAA0B;IASlC;;OAEG;IACI,KAAK,IAAI,mBAAmB;CAUnC"}
@@ -52,10 +52,10 @@ class TaskBuilder {
52
52
  this.elements = [];
53
53
  this.collector = null;
54
54
  }
55
- /** Set the collector by extracting the information from a given string */
56
- setCollectorFromString(collectorSpecification) {
57
- commons_1.Contract.requireNonEmpty(collectorSpecification);
58
- this.collector = new Task_1.CollectorSpecifier(collectorSpecification);
55
+ /** Set the collector specification based on the command-line arguments. */
56
+ setCollectorFromCommandLine(commandLineUrl, relativePattern) {
57
+ commons_1.Contract.requireNonEmpty(commandLineUrl, "The collector URL must not be empty");
58
+ this.collector = (0, Task_1.createCollectorSpecifier)(commandLineUrl, relativePattern);
59
59
  return this;
60
60
  }
61
61
  /** Set the origin include pattern. If multiple patterns are present, concatenates them via the OR operator. */
@@ -91,7 +91,7 @@ class TaskBuilder {
91
91
  const sourceMap = config.source_map;
92
92
  this.dumpOriginsFile = config.dump_origins_to;
93
93
  this.dumpMatchedOriginsFile = config.dump_origin_matches_to;
94
- this.setCollectorFromString(config.collector);
94
+ this.setCollectorFromCommandLine(config.collector, config.collector_pattern);
95
95
  this.setOriginSourceIncludePatterns(config.include_origin);
96
96
  this.setOriginSourceExcludePatterns(config.exclude_origin);
97
97
  this.setBundleExcludePatterns(config.exclude_bundle);
@@ -0,0 +1,36 @@
1
+ /**
2
+ * The collector URL is known at build time.
3
+ */
4
+ export interface CollectorSpecifierUrl {
5
+ /** Type of collector specifier. */
6
+ type: "url";
7
+ /** The URL under which the collector can be reached at runtime. */
8
+ url: string;
9
+ }
10
+ /** Describes a one-time search and replace operation on a string. */
11
+ export interface SearchReplace {
12
+ /** Literal string to search for. */
13
+ search: string;
14
+ /** Literal replacement string. */
15
+ replace: string;
16
+ }
17
+ /**
18
+ * The collector can be reached by replacing a term in location.host and optionally changing the port.
19
+ */
20
+ export interface CollectorSpecifierRelative {
21
+ /** Type of collector specifier. */
22
+ type: "relative";
23
+ /** Literal replacement string. */
24
+ hostReplace?: SearchReplace;
25
+ /** Optional port. If no port is given, uses the protocol's default port. */
26
+ port?: number | "keep";
27
+ /** Optional URL scheme to use. If no scheme is given, uses ws. */
28
+ scheme?: string;
29
+ /** Optional path. If no path is given, uses only the hostname. */
30
+ path?: string;
31
+ }
32
+ /**
33
+ * Specifies how the vaccine can reach the collector.
34
+ */
35
+ export type CollectorSpecifier = CollectorSpecifierUrl | CollectorSpecifierRelative;
36
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/vaccine/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACrC,mCAAmC;IACnC,IAAI,EAAE,KAAK,CAAC;IACZ,mEAAmE;IACnE,GAAG,EAAE,MAAM,CAAC;CACZ;AAED,qEAAqE;AACrE,MAAM,WAAW,aAAa;IAC7B,oCAAoC;IACpC,MAAM,EAAE,MAAM,CAAC;IACf,kCAAkC;IAClC,OAAO,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,0BAA0B;IAC1C,mCAAmC;IACnC,IAAI,EAAE,UAAU,CAAC;IACjB,kCAAkC;IAClC,WAAW,CAAC,EAAE,aAAa,CAAC;IAC5B,4EAA4E;IAC5E,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACvB,kEAAkE;IAClE,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,kEAAkE;IAClE,IAAI,CAAC,EAAE,MAAM,CAAC;CACd;AAED;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG,qBAAqB,GAAG,0BAA0B,CAAA"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/dist/vaccine.js CHANGED
@@ -1 +1 @@
1
- "use strict";(()=>{function l(t){let o=new Blob([t],{type:"text/javascript"}),e=URL.createObjectURL(o),n=new Worker(e);return URL.revokeObjectURL(e),n}function d(){return l('var n=class{constructor(e){this.cachedMessages=[];this.url=e,this.socket=this.createSocket()}createSocket(){let e=new WebSocket(this.url);return e.onopen=()=>this.onopen(),e.onclose=()=>this.onclose(),e}onclose(){this.socket=this.createSocket()}onopen(){console.log("Connection to Coverage Collector established."),this.cachedMessages.forEach(e=>this.socket.send(e)),this.cachedMessages=[]}send(e){this.socket.readyState===WebSocket.OPEN?this.socket.send(e):(this.cachedMessages.push(e),this.cachedMessages.length%500===0&&console.log(`More than ${this.cachedMessages.length} messages are queued to be sent.`))}};var i=class{constructor(e,t){this.milliseconds=e;this.onCountedToZero=t;this.timerHandle=null}restartCountdown(){this.stopCountdown(),this.timerHandle=self.setTimeout(()=>{this.stopCountdown(),this.onCountedToZero()},this.milliseconds)}stopCountdown(){this.timerHandle!==null&&(self.clearTimeout(this.timerHandle),this.timerHandle=null)}};var h=20,d=1e3,l="c",r=class{constructor(e){this.socket=e,this.cachedCoveredRanges=new Map,this.numberOfCachedPositions=0,this.flushCountdown=new i(d,()=>this.flush())}addLines(e,t){let s=this.cachedCoveredRanges.get(e);s||(s=new Set,this.cachedCoveredRanges.set(e,s)),t.forEach(c=>s.add(c)),this.numberOfCachedPositions+=1,this.flushCountdown.restartCountdown(),this.numberOfCachedPositions>=h&&this.flush()}arrayToLineCov(e){let t=[];for(let s of e)t.push(`${s}`);return t.join(";")}flush(){if(this.numberOfCachedPositions===0)return;this.flushCountdown.stopCountdown();let e=[];this.cachedCoveredRanges.forEach((t,s)=>{e.push(`@${s}`),e.push(this.arrayToLineCov(t))}),this.socket.send(`${l} ${e.join(";")}`),this.cachedCoveredRanges.clear(),this.numberOfCachedPositions=0}};console.log("Starting coverage forwarding worker.");var u=new n("$REPORT_TO_URL/socket"),a=new r(u);onmessage=o=>{if(Array.isArray(o.data)){let[e,t]=o.data;a.addLines(e,t)}else o.data==="unload"?a.flush():console.error(`No handler for message: ${o.data}`)};\n')}function u(){return f()}function f(){return window}function g(t,o){let e=u()[t];return e||(e=o,u()[t]=e),e}function p(t,o){let e=new Map;function n(s){let r=e.get(s);return r||(r={lines:new Set},e.set(s,r),r)}function i(s,r,b=r){let h=n(s).lines;for(let c=r;c<=b;c++)h.add(c);h.size>255&&a()}function a(){o(e),e.clear()}return setInterval(()=>a(),t),{putLineCoverage:i,flush:a}}var v=g("__TS_AGENT",{});function C(){return v._$BcWorker}function k(t){return v._$BcWorker=t,t}var w=p(250,t=>{for(let o of t.entries())C().postMessage([o[0],Array.from(o[1].lines)])});u()._$l=w.putLineCoverage;if(!C()){let t=k(new d);(function(){let e=()=>{w.flush(),t.postMessage("unload")},n=function(a,s){s&&s.addEventListener(a,e,{capture:!0})},i=f();n("blur",i),n("unload",i),n("visibilitychange",i),n("beforeunload",i)})()}})();
1
+ "use strict";(()=>{function u(t){let o=new Blob([t],{type:"text/javascript"}),e=URL.createObjectURL(o),r=new Worker(e);return URL.revokeObjectURL(e),r}function d(){return u('var i=class{constructor(e){this.cachedMessages=[];this.url=e,this.socket=this.createSocket()}createSocket(){let e=new WebSocket(this.url);return e.onopen=()=>this.onopen(),e.onclose=()=>this.onclose(),e}onclose(){this.socket=this.createSocket()}onopen(){console.log("Connection to Coverage Collector established."),this.cachedMessages.forEach(e=>this.socket.send(e)),this.cachedMessages=[]}send(e){this.socket.readyState===WebSocket.OPEN?this.socket.send(e):(this.cachedMessages.push(e),this.cachedMessages.length%500===0&&console.log(`More than ${this.cachedMessages.length} messages are queued to be sent.`))}};var c=class{constructor(e,o){this.milliseconds=e;this.onCountedToZero=o;this.timerHandle=null}restartCountdown(){this.stopCountdown(),this.timerHandle=self.setTimeout(()=>{this.stopCountdown(),this.onCountedToZero()},this.milliseconds)}stopCountdown(){this.timerHandle!==null&&(self.clearTimeout(this.timerHandle),this.timerHandle=null)}};var m=20,C=1e3,v="c",a=class{constructor(e){this.socket=e,this.cachedCoveredRanges=new Map,this.numberOfCachedPositions=0,this.flushCountdown=new c(C,()=>this.flush())}addLines(e,o){let t=this.cachedCoveredRanges.get(e);t||(t=new Set,this.cachedCoveredRanges.set(e,t)),o.forEach(r=>t.add(r)),this.numberOfCachedPositions+=1,this.flushCountdown.restartCountdown(),this.numberOfCachedPositions>=m&&this.flush()}arrayToLineCov(e){let o=[];for(let t of e)o.push(`${t}`);return o.join(";")}flush(){if(this.numberOfCachedPositions===0)return;this.flushCountdown.stopCountdown();let e=[];this.cachedCoveredRanges.forEach((o,t)=>{e.push(`@${t}`),e.push(this.arrayToLineCov(o))}),this.socket.send(`${v} ${e.join(";")}`),this.cachedCoveredRanges.clear(),this.numberOfCachedPositions=0}};var l=class s{static resolve(e){switch(e.type){case"url":return e.url;case"relative":return s.resolveRelative(location.host,location.port,e)}}static resolveRelative(e,o,t){var u;let r=e;t.hostReplace&&(r=e.replace(t.hostReplace.search,t.hostReplace.replace));let g=(u=t.scheme)!=null?u:"ws",n;t.port===void 0?n="":t.port==="keep"?n=`:${o}`:n=`:${t.port}`;let h="";t.path&&(h=`/${t.path}`);let d=`${g}://${r}${n}${h}`;return console.debug(`Resolved collector URL ${d} from ${e}:${o}`),d}};console.log("Starting coverage forwarding worker.");var f=new i(`${l.resolve($COLLECTOR_SPECIFIER)}/socket`),p=new a(f);onmessage=s=>{if(Array.isArray(s.data)){let[e,o]=s.data;p.addLines(e,o)}else s.data==="unload"?p.flush():console.error(`No handler for message: ${s.data}`)};\n')}function l(){return f()}function f(){return window}function g(t,o){let e=l()[t];return e||(e=o,l()[t]=e),e}function p(t,o){let e=new Map;function r(s){let n=e.get(s);return n||(n={lines:new Set},e.set(s,n),n)}function i(s,n,b=n){let h=r(s).lines;for(let c=n;c<=b;c++)h.add(c);h.size>255&&a()}function a(){o(e),e.clear()}return setInterval(()=>a(),t),{putLineCoverage:i,flush:a}}var v=g("__TS_AGENT",{});function C(){return v._$BcWorker}function m(t){return v._$BcWorker=t,t}var w=p(250,t=>{for(let o of t.entries())C().postMessage([o[0],Array.from(o[1].lines)])});l()._$l=w.putLineCoverage;if(!C()){let t=m(new d);(function(){let e=()=>{w.flush(),t.postMessage("unload")},r=function(a,s){s&&s.addEventListener(a,e,{capture:!0})},i=f();r("blur",i),r("unload",i),r("visibilitychange",i),r("beforeunload",i)})()}})();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teamscale/javascript-instrumenter",
3
- "version": "0.1.0-beta.5",
3
+ "version": "0.1.0-beta.6",
4
4
  "description": "JavaScript coverage instrumenter with coverage forwarding to a collector process",
5
5
  "main": "dist/src/main.js",
6
6
  "bin": "dist/src/main.js",
@@ -30,7 +30,7 @@
30
30
  "@types/node": "^20.11.19",
31
31
  "@types/ws": "^8.5.10",
32
32
  "babel-jest": "^29.7.0",
33
- "esbuild": "^0.20.0",
33
+ "esbuild": "^0.20.1",
34
34
  "esbuild-plugin-inline-worker": "^0.1.1",
35
35
  "jest": "^29.7.0",
36
36
  "rimraf": "^5.0.5",
@@ -40,7 +40,7 @@
40
40
  "typescript": "^5.3.3"
41
41
  },
42
42
  "dependencies": {
43
- "@cqse/commons": "0.1.0-beta.4",
43
+ "@cqse/commons": "0.1.0-beta.5",
44
44
  "@babel/generator": "^7.23.6",
45
45
  "@babel/parser": "^7.23.9",
46
46
  "@babel/traverse": "^7.23.9",
@@ -58,7 +58,7 @@
58
58
  "typescript-optional": "^2.0.1",
59
59
  "unload": "^2.4.1",
60
60
  "web-worker": "^1.3.0",
61
- "@teamscale/lib-instrument": "0.1.0-beta.5"
61
+ "@teamscale/lib-instrument": "0.1.0-beta.6"
62
62
  },
63
63
  "publishConfig": {
64
64
  "access": "public"