@teamscale/javascript-instrumenter 0.0.1-beta.5 → 0.0.1-beta.51

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.
@@ -26,11 +26,9 @@ export declare class TaskElement {
26
26
  * receive the coverage information.
27
27
  */
28
28
  export declare class CollectorSpecifier {
29
- /** Hostname the collector is running on */
30
- readonly host: string;
31
- /** Port on the host the collector listens to */
32
- readonly port: number;
33
- constructor(collector: string);
29
+ /** The URL specifying the address the collector is reachable at. */
30
+ readonly url: string;
31
+ constructor(specifier: string);
34
32
  }
35
33
  /**
36
34
  * Patterns that define which parts of a given bundle to instrument or not.
@@ -47,17 +45,35 @@ export declare class OriginSourcePattern {
47
45
  * An exclude is stronger than an include.
48
46
  */
49
47
  private readonly exclude;
50
- constructor(include: string | undefined, exclude: string | undefined);
48
+ constructor(include: string[] | undefined, exclude: string[] | undefined);
51
49
  /**
52
50
  * Does the given pattern require to include the given set of files?
53
51
  *
52
+ * For example, a JavaScript bundle is compiled from several (origin) source files.
53
+ * If one of the files in the bundle is needed, then the full bundle is needed, that is,
54
+ * this function is required to return `true`.
55
+ *
54
56
  * @param originFiles - The file set to decide for include or exclude.
55
57
  *
56
- * @returns `true` if (1) all of the given files are supposed to be excluded,
57
- * or (2) if one of the files is supposed to be included.
58
+ * @returns `false` if (1) all given files are supposed to be excluded,
59
+ * or (2) `true` if at least one of the files is supposed to be included.
58
60
  */
59
61
  isAnyIncluded(originFiles: string[]): boolean;
60
62
  }
63
+ /**
64
+ * Pattern describing files (bundles) to not instrument.
65
+ */
66
+ export declare class FileExcludePattern {
67
+ /**
68
+ * Glob pattern describing a set of files to be excluded in the instrumentation process.
69
+ */
70
+ private readonly exclude;
71
+ constructor(exclude: string[] | undefined);
72
+ /**
73
+ * Return `true` if the given `filePath` is matched by any of the patterns in `exclude`.
74
+ */
75
+ isExcluded(filePath: string): boolean;
76
+ }
61
77
  /**
62
78
  * The actual instrumentation task.
63
79
  */
@@ -75,7 +91,16 @@ export declare class InstrumentationTask {
75
91
  * based on the original file names the code was transpiled from.
76
92
  */
77
93
  readonly originSourcePattern: OriginSourcePattern;
78
- constructor(collector: CollectorSpecifier, elements: TaskElement[], originSourcePattern: OriginSourcePattern);
94
+ /**
95
+ * A pattern describing the set of files to not instrument but to output
96
+ * without adding instrumentations.
97
+ */
98
+ readonly excludeFilesPattern: FileExcludePattern;
99
+ /**
100
+ * File to write the file-origin-mapping to.
101
+ */
102
+ readonly dumpOriginsFile: string | undefined;
103
+ constructor(collector: CollectorSpecifier, elements: TaskElement[], excludeFilesPattern: FileExcludePattern, originSourcePattern: OriginSourcePattern, dumpOriginsFile: string | undefined);
79
104
  /**
80
105
  * @returns the elements of the task.
81
106
  */
@@ -87,6 +112,8 @@ export declare class InstrumentationTask {
87
112
  export declare class TaskResult {
88
113
  /** Number of task elements that were performed (instrumented) */
89
114
  readonly translated: number;
115
+ /** Number of task elements that were excluded because of corresponding include/exclude patterns. */
116
+ readonly excluded: number;
90
117
  /** Number of instrumentations that were taken from a cache */
91
118
  readonly translatedFromCache: number;
92
119
  /** Number of skips due to a present instrumentation */
@@ -97,7 +124,7 @@ export declare class TaskResult {
97
124
  readonly failed: number;
98
125
  /** Number of warnings that were produced during the instrumentation process */
99
126
  readonly warnings: number;
100
- constructor(translated: number, translatedFromCache: number, alreadyInstrumented: number, unsupported: number, failed: number, warnings: number);
127
+ constructor(translated: number, excluded: number, translatedFromCache: number, alreadyInstrumented: number, unsupported: number, failed: number, warnings: number);
101
128
  /**
102
129
  * Returns the sum of the present task results and the given one.
103
130
  *
@@ -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;AAI/C;;GAEG;AACH,8BAAsB,kBAAkB;CAAG;AAE3C;;;GAGG;AACH,qBAAa,WAAW;IACvB,sBAAsB;IACtB,SAAgB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,WAAW,EAAE,CAI5B;CACD;AAED;;GAEG;AACH,qBAAa,UAAU;IACtB,iEAAiE;IACjE,SAAgB,UAAU,EAAE,MAAM,CAAC;IAEnC,oGAAoG;IACpG,SAAgB,QAAQ,EAAE,MAAM,CAAC;IAEjC,8DAA8D;IAC9D,SAAgB,mBAAmB,EAAE,MAAM,CAAC;IAE5C,uDAAuD;IACvD,SAAgB,mBAAmB,EAAE,MAAM,CAAC;IAE5C,sDAAsD;IACtD,SAAgB,WAAW,EAAE,MAAM,CAAC;IAEpC,6DAA6D;IAC7D,SAAgB,MAAM,EAAE,MAAM,CAAC;IAE/B,+EAA+E;IAC/E,SAAgB,QAAQ,EAAE,MAAM,CAAC;gBAGhC,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,EAChB,mBAAmB,EAAE,MAAM,EAC3B,mBAAmB,EAAE,MAAM,EAC3B,WAAW,EAAE,MAAM,EACnB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM;IAkBjB;;;;OAIG;IACI,aAAa,CAAC,KAAK,EAAE,UAAU,GAAG,UAAU;IAYnD;;OAEG;WACW,OAAO,IAAI,UAAU;IAInC;;;;OAIG;WACW,KAAK,CAAC,CAAC,EAAE,KAAK,GAAG,UAAU;IAKzC;;;;OAIG;WACW,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU;CAI9C;AAED;;GAEG;AACH,qBAAa,sBAAuB,SAAQ,kBAAkB;IAC7D,2CAA2C;IAC3C,SAAgB,iBAAiB,EAAE,MAAM,CAAC;gBAE9B,iBAAiB,EAAE,MAAM;CAIrC"}
@@ -1,28 +1,13 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
- Object.defineProperty(o, "default", { enumerable: true, value: v });
11
- }) : function(o, v) {
12
- o["default"] = v;
13
- });
14
- var __importStar = (this && this.__importStar) || function (mod) {
15
- if (mod && mod.__esModule) return mod;
16
- var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
- __setModuleDefault(result, mod);
19
- return result;
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
20
4
  };
21
5
  Object.defineProperty(exports, "__esModule", { value: true });
22
- exports.SourceMapFileReference = exports.TaskResult = exports.InstrumentationTask = exports.OriginSourcePattern = exports.CollectorSpecifier = exports.TaskElement = exports.SourceMapReference = void 0;
6
+ exports.SourceMapFileReference = exports.TaskResult = exports.InstrumentationTask = exports.FileExcludePattern = exports.OriginSourcePattern = exports.CollectorSpecifier = exports.TaskElement = exports.SourceMapReference = void 0;
23
7
  const typescript_optional_1 = require("typescript-optional");
24
8
  const commons_1 = require("@cqse/commons");
25
- const matching = __importStar(require("micromatch"));
9
+ const micromatch_1 = __importDefault(require("micromatch"));
10
+ const path_1 = __importDefault(require("path"));
26
11
  /**
27
12
  * An abstract source map type.
28
13
  */
@@ -54,10 +39,17 @@ exports.TaskElement = TaskElement;
54
39
  * receive the coverage information.
55
40
  */
56
41
  class CollectorSpecifier {
57
- constructor(collector) {
58
- commons_1.Contract.requireStringPattern(collector, '.+:[0-9]+', 'Invalid collector pattern used!');
59
- this.host = collector.split(':')[0];
60
- this.port = Number.parseInt(collector.split(':')[1]);
42
+ constructor(specifier) {
43
+ if (specifier.indexOf('://') > 0) {
44
+ // A trailing slash will be removed
45
+ this.url = specifier.replace(/\/$/, '');
46
+ }
47
+ else {
48
+ commons_1.Contract.requireStringPattern(specifier, '.+:[0-9]+', 'Invalid collector pattern used!');
49
+ const host = specifier.split(':')[0];
50
+ const port = Number.parseInt(specifier.split(':')[1]);
51
+ this.url = `ws://${host}:${port}`;
52
+ }
61
53
  }
62
54
  }
63
55
  exports.CollectorSpecifier = CollectorSpecifier;
@@ -70,41 +62,101 @@ exports.CollectorSpecifier = CollectorSpecifier;
70
62
  */
71
63
  class OriginSourcePattern {
72
64
  constructor(include, exclude) {
73
- this.include = include;
74
- this.exclude = exclude;
65
+ this.include = normalizePatterns(include);
66
+ this.exclude = normalizePatterns(exclude);
75
67
  }
76
68
  /**
77
69
  * Does the given pattern require to include the given set of files?
78
70
  *
71
+ * For example, a JavaScript bundle is compiled from several (origin) source files.
72
+ * If one of the files in the bundle is needed, then the full bundle is needed, that is,
73
+ * this function is required to return `true`.
74
+ *
79
75
  * @param originFiles - The file set to decide for include or exclude.
80
76
  *
81
- * @returns `true` if (1) all of the given files are supposed to be excluded,
82
- * or (2) if one of the files is supposed to be included.
77
+ * @returns `false` if (1) all given files are supposed to be excluded,
78
+ * or (2) `true` if at least one of the files is supposed to be included.
83
79
  */
84
80
  isAnyIncluded(originFiles) {
85
- var _a;
81
+ if (originFiles.length === 0) {
82
+ return true;
83
+ }
84
+ const normalizedOriginFiles = originFiles.map(normalizePath);
86
85
  if (this.exclude) {
87
- const matchedToExclude = matching.match(originFiles, this.exclude);
86
+ const matchedToExclude = (0, micromatch_1.default)(normalizedOriginFiles, this.exclude);
88
87
  if (originFiles.length === matchedToExclude.length) {
89
88
  return false;
90
89
  }
91
90
  }
92
91
  if (this.include) {
93
- const matchedToInclude = matching.match(originFiles, (_a = this.include) !== null && _a !== void 0 ? _a : '**');
92
+ const matchedToInclude = (0, micromatch_1.default)(normalizedOriginFiles, this.include || ['**']);
94
93
  return matchedToInclude.length > 0;
95
94
  }
96
95
  return true;
97
96
  }
98
97
  }
99
98
  exports.OriginSourcePattern = OriginSourcePattern;
99
+ /**
100
+ * Pattern describing files (bundles) to not instrument.
101
+ */
102
+ class FileExcludePattern {
103
+ constructor(exclude) {
104
+ var _a;
105
+ this.exclude = (_a = normalizePatterns(exclude)) !== null && _a !== void 0 ? _a : [];
106
+ }
107
+ /**
108
+ * Return `true` if the given `filePath` is matched by any of the patterns in `exclude`.
109
+ */
110
+ isExcluded(filePath) {
111
+ return (0, micromatch_1.default)([filePath], this.exclude).length === 1;
112
+ }
113
+ }
114
+ exports.FileExcludePattern = FileExcludePattern;
115
+ /**
116
+ * Normalizes all patterns (normally either include or exclude patterns), and returns all
117
+ * valid normalized patterns. Returns undefined if the patterns list is undefined, or all
118
+ * items inside the list are undefined.
119
+ */
120
+ function normalizePatterns(patterns) {
121
+ if (patterns === undefined || patterns.length === 0) {
122
+ return undefined;
123
+ }
124
+ const normalizedPatterns = patterns
125
+ .map(pattern => normalizeGlobPattern(pattern))
126
+ .filter(pattern => pattern !== undefined);
127
+ if (patterns.length === 0) {
128
+ return undefined;
129
+ }
130
+ return normalizedPatterns;
131
+ }
132
+ function normalizeGlobPattern(pattern) {
133
+ if (!pattern) {
134
+ return pattern;
135
+ }
136
+ return removeTrailingCurrentWorkingDir(pattern);
137
+ }
138
+ function normalizePath(toNormalize) {
139
+ return removeTrailingCurrentWorkingDir(toNormalize);
140
+ }
141
+ function removeTrailingCurrentWorkingDir(removeFrom) {
142
+ return removePrefix('webpack:///', removePrefix('.' + path_1.default.sep, removeFrom));
143
+ }
144
+ function removePrefix(prefix, removeFrom) {
145
+ if (removeFrom.startsWith(prefix)) {
146
+ return removeFrom.substring(prefix.length);
147
+ }
148
+ return removeFrom;
149
+ }
100
150
  /**
101
151
  * The actual instrumentation task.
102
152
  */
103
153
  class InstrumentationTask {
104
- constructor(collector, elements, originSourcePattern) {
154
+ constructor(collector, elements, excludeFilesPattern, originSourcePattern, dumpOriginsFile) {
105
155
  this.collector = commons_1.Contract.requireDefined(collector);
156
+ this.excludeFilesPattern = commons_1.Contract.requireDefined(excludeFilesPattern);
106
157
  this.originSourcePattern = commons_1.Contract.requireDefined(originSourcePattern);
107
158
  this._elements = commons_1.Contract.requireDefined(elements).slice();
159
+ this.dumpOriginsFile = dumpOriginsFile;
108
160
  }
109
161
  /**
110
162
  * @returns the elements of the task.
@@ -120,14 +172,16 @@ exports.InstrumentationTask = InstrumentationTask;
120
172
  * A summary of executing the instrumentation task.
121
173
  */
122
174
  class TaskResult {
123
- constructor(translated, translatedFromCache, alreadyInstrumented, unsupported, failed, warnings) {
175
+ constructor(translated, excluded, translatedFromCache, alreadyInstrumented, unsupported, failed, warnings) {
124
176
  commons_1.Contract.require(translated > -1);
177
+ commons_1.Contract.require(excluded > -1);
125
178
  commons_1.Contract.require(translatedFromCache > -1);
126
179
  commons_1.Contract.require(alreadyInstrumented > -1);
127
180
  commons_1.Contract.require(unsupported > -1);
128
181
  commons_1.Contract.require(failed > -1);
129
182
  commons_1.Contract.require(warnings > -1);
130
183
  this.translated = translated;
184
+ this.excluded = excluded;
131
185
  this.translatedFromCache = translatedFromCache;
132
186
  this.alreadyInstrumented = alreadyInstrumented;
133
187
  this.unsupported = unsupported;
@@ -140,13 +194,13 @@ class TaskResult {
140
194
  * @param incBy - The task result to add (as delta).
141
195
  */
142
196
  withIncrement(incBy) {
143
- return new TaskResult(this.translated + incBy.translated, this.translatedFromCache + incBy.translatedFromCache, this.alreadyInstrumented + incBy.alreadyInstrumented, this.unsupported + incBy.unsupported, this.failed + incBy.failed, this.warnings + incBy.warnings);
197
+ 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);
144
198
  }
145
199
  /**
146
200
  * @returns the neutral task element (adding it with {@code withIncrement} does not change the result).
147
201
  */
148
202
  static neutral() {
149
- return new TaskResult(0, 0, 0, 0, 0, 0);
203
+ return new TaskResult(0, 0, 0, 0, 0, 0, 0);
150
204
  }
151
205
  /**
152
206
  * @returns a task result signaling one error.
@@ -155,7 +209,7 @@ class TaskResult {
155
209
  */
156
210
  static error(e) {
157
211
  console.error(e);
158
- return new TaskResult(0, 0, 0, 0, 1, 0);
212
+ return new TaskResult(0, 0, 0, 0, 0, 1, 0);
159
213
  }
160
214
  /**
161
215
  * @returns a task result signaling one warning.
@@ -164,7 +218,7 @@ class TaskResult {
164
218
  */
165
219
  static warning(msg) {
166
220
  console.warn(msg);
167
- return new TaskResult(0, 0, 0, 0, 0, 1);
221
+ return new TaskResult(0, 0, 0, 0, 0, 0, 1);
168
222
  }
169
223
  }
170
224
  exports.TaskResult = TaskResult;
@@ -7,8 +7,10 @@ export declare type ConfigurationParameters = {
7
7
  to?: string;
8
8
  source_map?: string;
9
9
  collector: string;
10
- include_origin?: string;
11
- exclude_origin?: string;
10
+ include_origin?: string[];
11
+ exclude_origin?: string[];
12
+ exclude_bundle?: string[];
13
+ dump_origins_to?: string;
12
14
  };
13
15
  /**
14
16
  * A builder for an instrumentation task.
@@ -18,17 +20,23 @@ export declare class TaskBuilder {
18
20
  private readonly elements;
19
21
  /** The collector to send the coverage to. */
20
22
  private collector;
21
- /** An include pattern. */
22
- private originSourceIncludePattern;
23
- /** An exclude pattern. */
24
- private originSourceExcludePattern;
23
+ /** Origin include patterns. */
24
+ private originSourceIncludePatterns;
25
+ /** Origin exclude patters. */
26
+ private originSourceExcludePatterns;
27
+ /** Bundle exclude patters. */
28
+ private bundleFileExcludePatterns;
29
+ /** File path where all origins from the source map should be dumped in json format, or undefined if no origins should be dumped */
30
+ private dumpOriginsFile;
25
31
  constructor();
26
32
  /** Set the collector by extracting the information from a given string */
27
33
  setCollectorFromString(collectorSpecification: string): this;
28
- /** Set the include pattern */
29
- setOriginSourceIncludePattern(pattern: string | undefined): this;
30
- /** Set the exclude patter */
31
- setOriginSourceExcludePattern(pattern: string | undefined): this;
34
+ /** Set the origin include pattern. If multiple patterns are present, concatenates them via the OR operator. */
35
+ setOriginSourceIncludePatterns(patterns: string[] | undefined): this;
36
+ /** Set the origin exclude pattern(s). If multiple patterns are present, concatenates them via the OR operator. */
37
+ setOriginSourceExcludePatterns(patterns: string[] | undefined): this;
38
+ /** Sets the file bundle exclude pattern. If multiple patterns are present, concatenates them via the OR operator. */
39
+ setBundleExcludePatterns(patterns: string[] | undefined): this;
32
40
  /** Add a task element */
33
41
  addElement(fromFilePath: string, toFilePath: string, fromFileSourceMap?: SourceMapReference): this;
34
42
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"TaskBuilder.d.ts","sourceRoot":"","sources":["../../../src/instrumenter/TaskBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EAEN,mBAAmB,EAGnB,kBAAkB,EAElB,MAAM,QAAQ,CAAC;AAMhB,2DAA2D;AAC3D,oBAAY,uBAAuB,GAAG;IACrC,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAElB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,EAAE,CAAC,EAAE,MAAM,CAAC;IAEZ,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAElB,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB,cAAc,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC;AAkBF;;GAEG;AACH,qBAAa,WAAW;IACvB,gDAAgD;IAChD,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAgB;IAEzC,6CAA6C;IAC7C,OAAO,CAAC,SAAS,CAA4B;IAE7C,0BAA0B;IAC1B,OAAO,CAAC,0BAA0B,CAAqB;IAEvD,0BAA0B;IAC1B,OAAO,CAAC,0BAA0B,CAAqB;;IAOvD,0EAA0E;IAC1E,sBAAsB,CAAC,sBAAsB,EAAE,MAAM,GAAG,IAAI;IAM5D,8BAA8B;IAC9B,6BAA6B,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI;IAKhE,6BAA6B;IAC7B,6BAA6B,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI;IAKhE,yBAAyB;IACzB,UAAU,CAAC,YAAY,E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0EAA0E;IAC1E,sBAAsB,CAAC,sBAAsB,EAAE,MAAM,GAAG,IAAI;IAM5D,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;IAoCpD;;;;;;;OAOG;IACH,OAAO,CAAC,4CAA4C;IAgCpD;;;;;;OAMG;IACH,OAAO,CAAC,0BAA0B;IASlC;;OAEG;IACI,KAAK,IAAI,mBAAmB;CASnC"}
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[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);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -54,14 +58,19 @@ class TaskBuilder {
54
58
  this.collector = new Task_1.CollectorSpecifier(collectorSpecification);
55
59
  return this;
56
60
  }
57
- /** Set the include pattern */
58
- setOriginSourceIncludePattern(pattern) {
59
- this.originSourceIncludePattern = pattern;
61
+ /** Set the origin include pattern. If multiple patterns are present, concatenates them via the OR operator. */
62
+ setOriginSourceIncludePatterns(patterns) {
63
+ this.originSourceIncludePatterns = patterns;
64
+ return this;
65
+ }
66
+ /** Set the origin exclude pattern(s). If multiple patterns are present, concatenates them via the OR operator. */
67
+ setOriginSourceExcludePatterns(patterns) {
68
+ this.originSourceExcludePatterns = patterns;
60
69
  return this;
61
70
  }
62
- /** Set the exclude patter */
63
- setOriginSourceExcludePattern(pattern) {
64
- this.originSourceExcludePattern = pattern;
71
+ /** Sets the file bundle exclude pattern. If multiple patterns are present, concatenates them via the OR operator. */
72
+ setBundleExcludePatterns(patterns) {
73
+ this.bundleFileExcludePatterns = patterns;
65
74
  return this;
66
75
  }
67
76
  /** Add a task element */
@@ -80,12 +89,14 @@ class TaskBuilder {
80
89
  const inPlace = (_b = config.in_place) !== null && _b !== void 0 ? _b : true;
81
90
  const target = config.to;
82
91
  const sourceMap = config.source_map;
92
+ this.dumpOriginsFile = config.dump_origins_to;
83
93
  this.setCollectorFromString(config.collector);
84
- this.setOriginSourceIncludePattern(config.include_origin);
85
- this.setOriginSourceExcludePattern(config.exclude_origin);
94
+ this.setOriginSourceIncludePatterns(config.include_origin);
95
+ this.setOriginSourceExcludePatterns(config.exclude_origin);
96
+ this.setBundleExcludePatterns(config.exclude_bundle);
86
97
  // Handle an explicitly specified source map
87
98
  const sourceMapInfo = loadSourceMap(sourceMap);
88
- // Depending on whether or not an in place instrumentation is needed
99
+ // If an in place instrumentation is needed
89
100
  // the task has to be built differently and different invariants
90
101
  // have to be satisfied by the passed configuration.
91
102
  if (inPlace) {
@@ -128,7 +139,11 @@ class TaskBuilder {
128
139
  inputFiles.forEach(f => this.addElement(f, path.join(target, path.basename(f)), sourceMapInfo));
129
140
  }
130
141
  else {
131
- inputFiles.forEach(f => this.addElement(f, path.join(target, path.relative(input, path.basename(f))), sourceMapInfo));
142
+ inputFiles.forEach(f => {
143
+ const pathRelativeToInputDir = path.relative(input, f);
144
+ const targetFileName = path.join(target, pathRelativeToInputDir);
145
+ this.addElement(f, targetFileName, sourceMapInfo);
146
+ });
132
147
  }
133
148
  }
134
149
  else {
@@ -155,8 +170,7 @@ class TaskBuilder {
155
170
  * Build the instrumentation task.
156
171
  */
157
172
  build() {
158
- const pattern = new Task_1.OriginSourcePattern(this.originSourceIncludePattern, this.originSourceExcludePattern);
159
- return new Task_1.InstrumentationTask(commons_1.Contract.requireDefined(this.collector), this.elements, pattern);
173
+ return new Task_1.InstrumentationTask(commons_1.Contract.requireDefined(this.collector), this.elements, new Task_1.FileExcludePattern(this.bundleFileExcludePatterns), new Task_1.OriginSourcePattern(this.originSourceIncludePatterns, this.originSourceExcludePatterns), this.dumpOriginsFile);
160
174
  }
161
175
  }
162
176
  exports.TaskBuilder = TaskBuilder;
@@ -167,7 +181,7 @@ function isPattern(text) {
167
181
  return text.includes('*') || text.includes('+') || text.includes('?') || text.includes('|');
168
182
  }
169
183
  /**
170
- * Expand the given Glob pattern and check whether or not files matched.
184
+ * Expand the given Glob pattern and check if files matched.
171
185
  * Raises an exception is the result is empty.
172
186
  *
173
187
  * @param pattern - The Glob pattern used for matching.
package/dist/src/main.js CHANGED
@@ -7,6 +7,7 @@ App_1.App.run()
7
7
  .then(result => {
8
8
  console.log('Instrumentation finished.');
9
9
  console.log(`\tInstrumented: ${result.translated}`);
10
+ console.log(`\tExcluded: ${result.excluded}`);
10
11
  console.log(`\tInstrumented from cache: ${result.translatedFromCache}`);
11
12
  console.log(`\tAlready instrumented: ${result.alreadyInstrumented}`);
12
13
  console.log(`\tUnsupported: ${result.unsupported}`);