@teamscale/javascript-instrumenter 0.0.1-beta.9 → 0.1.0-beta.2

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.
@@ -4,6 +4,30 @@ import { Optional } from 'typescript-optional';
4
4
  */
5
5
  export declare abstract class SourceMapReference {
6
6
  }
7
+ type BaseBundle = {
8
+ content: string;
9
+ codeArguments: string[];
10
+ };
11
+ /**
12
+ * A standard JavaScript bundle. Produced, for example, with bundlers
13
+ * like Webpack or Vite.
14
+ */
15
+ export type StandardBundle = BaseBundle & {
16
+ type: 'javascript';
17
+ };
18
+ /**
19
+ * A Google Web-Toolkit Js bundle file.
20
+ */
21
+ export type GwtBundle = BaseBundle & {
22
+ type: 'gwt';
23
+ functionName: string;
24
+ fragmentId: string;
25
+ codeAsArrayArgument: boolean;
26
+ };
27
+ /**
28
+ * A bundle to be handled by the instrumenter.
29
+ */
30
+ export type Bundle = BaseBundle & (StandardBundle | GwtBundle);
7
31
  /**
8
32
  * One element of an instrumentation task.
9
33
  * It corresponds to instrumenting a single file.
@@ -26,11 +50,9 @@ export declare class TaskElement {
26
50
  * receive the coverage information.
27
51
  */
28
52
  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);
53
+ /** The URL specifying the address the collector is reachable at. */
54
+ readonly url: string;
55
+ constructor(specifier: string);
34
56
  }
35
57
  /**
36
58
  * Patterns that define which parts of a given bundle to instrument or not.
@@ -47,17 +69,40 @@ export declare class OriginSourcePattern {
47
69
  * An exclude is stronger than an include.
48
70
  */
49
71
  private readonly exclude;
50
- constructor(include: string | undefined, exclude: string | undefined);
72
+ constructor(include: string[] | undefined, exclude: string[] | undefined);
51
73
  /**
52
- * Does the given pattern require to include the given set of files?
74
+ * Does the given pattern require to include the given file?
53
75
  *
54
- * @param originFiles - The file set to decide for include or exclude.
76
+ * For example, a JavaScript bundle is compiled from several (origin) source files.
77
+ * If one of the files in the bundle is needed, then the full bundle is needed, that is,
78
+ * this function is required to return `true`.
55
79
  *
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.
80
+ * @param originFile - The file to decide for include or exclude.
81
+ *
82
+ * @returns `false` if (1) the given file is supposed to be excluded,
83
+ * or (2) `true` if the given file is supposed to be included.
84
+ */
85
+ isIncluded(originFile: string): boolean;
86
+ /**
87
+ * Variant of `isIncluded` working on a list of files to check.
88
+ * (Primarily, used for testing.)
58
89
  */
59
90
  isAnyIncluded(originFiles: string[]): boolean;
60
91
  }
92
+ /**
93
+ * Pattern describing files (bundles) to not instrument.
94
+ */
95
+ export declare class FileExcludePattern {
96
+ /**
97
+ * Glob pattern describing a set of files to be excluded in the instrumentation process.
98
+ */
99
+ private readonly exclude;
100
+ constructor(exclude: string[] | undefined);
101
+ /**
102
+ * Return `true` if the given `filePath` is matched by any of the patterns in `exclude`.
103
+ */
104
+ isExcluded(filePath: string): boolean;
105
+ }
61
106
  /**
62
107
  * The actual instrumentation task.
63
108
  */
@@ -75,7 +120,16 @@ export declare class InstrumentationTask {
75
120
  * based on the original file names the code was transpiled from.
76
121
  */
77
122
  readonly originSourcePattern: OriginSourcePattern;
78
- constructor(collector: CollectorSpecifier, elements: TaskElement[], originSourcePattern: OriginSourcePattern);
123
+ /**
124
+ * A pattern describing the set of files to not instrument but to output
125
+ * without adding instrumentations.
126
+ */
127
+ readonly excludeFilesPattern: FileExcludePattern;
128
+ /**
129
+ * File to write the file-origin-mapping to.
130
+ */
131
+ readonly dumpOriginsFile: string | undefined;
132
+ constructor(collector: CollectorSpecifier, elements: TaskElement[], excludeFilesPattern: FileExcludePattern, originSourcePattern: OriginSourcePattern, dumpOriginsFile: string | undefined);
79
133
  /**
80
134
  * @returns the elements of the task.
81
135
  */
@@ -87,6 +141,8 @@ export declare class InstrumentationTask {
87
141
  export declare class TaskResult {
88
142
  /** Number of task elements that were performed (instrumented) */
89
143
  readonly translated: number;
144
+ /** Number of task elements that were excluded because of corresponding include/exclude patterns. */
145
+ readonly excluded: number;
90
146
  /** Number of instrumentations that were taken from a cache */
91
147
  readonly translatedFromCache: number;
92
148
  /** Number of skips due to a present instrumentation */
@@ -97,7 +153,7 @@ export declare class TaskResult {
97
153
  readonly failed: number;
98
154
  /** Number of warnings that were produced during the instrumentation process */
99
155
  readonly warnings: number;
100
- constructor(translated: number, translatedFromCache: number, alreadyInstrumented: number, unsupported: number, failed: number, warnings: number);
156
+ constructor(translated: number, excluded: number, translatedFromCache: number, alreadyInstrumented: number, unsupported: number, failed: number, warnings: number);
101
157
  /**
102
158
  * Returns the sum of the present task results and the given one.
103
159
  *
@@ -129,4 +185,5 @@ export declare class SourceMapFileReference extends SourceMapReference {
129
185
  readonly sourceMapFilePath: string;
130
186
  constructor(sourceMapFilePath: string);
131
187
  }
188
+ export {};
132
189
  //# sourceMappingURL=Task.d.ts.map
@@ -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,QAAQ,EAAE,MAAM,CAAC;IAEjC,2BAA2B;IAC3B,SAAgB,MAAM,EAAE,MAAM,CAAC;IAE/B,gEAAgE;IAChE,SAAgB,qBAAqB,EAAE,QAAQ,CAAC,kBAAkB,CAAC,CAAC;gBAExD,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,iBAAiB,CAAC,EAAE,kBAAkB;IAMpF;;OAEG;IACI,SAAS,IAAI,OAAO;CAK3B;AAED;;;GAGG;AACH,qBAAa,kBAAkB;IAC9B,2CAA2C;IAC3C,SAAgB,IAAI,EAAE,MAAM,CAAC;IAE7B,gDAAgD;IAChD,SAAgB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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"));
26
10
  /**
27
11
  * An abstract source map type.
28
12
  */
@@ -54,10 +38,17 @@ exports.TaskElement = TaskElement;
54
38
  * receive the coverage information.
55
39
  */
56
40
  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]);
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
+ }
61
52
  }
62
53
  }
63
54
  exports.CollectorSpecifier = CollectorSpecifier;
@@ -70,41 +61,107 @@ exports.CollectorSpecifier = CollectorSpecifier;
70
61
  */
71
62
  class OriginSourcePattern {
72
63
  constructor(include, exclude) {
73
- this.include = include;
74
- this.exclude = exclude;
64
+ this.include = normalizePatterns(include);
65
+ this.exclude = normalizePatterns(exclude);
75
66
  }
76
67
  /**
77
- * Does the given pattern require to include the given set of files?
68
+ * Does the given pattern require to include the given file?
78
69
  *
79
- * @param originFiles - The file set to decide for include or exclude.
70
+ * For example, a JavaScript bundle is compiled from several (origin) source files.
71
+ * If one of the files in the bundle is needed, then the full bundle is needed, that is,
72
+ * this function is required to return `true`.
80
73
  *
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.
74
+ * @param originFile - The file to decide for include or exclude.
75
+ *
76
+ * @returns `false` if (1) the given file is supposed to be excluded,
77
+ * or (2) `true` if the given file is supposed to be included.
83
78
  */
84
- isAnyIncluded(originFiles) {
85
- var _a;
79
+ isIncluded(originFile) {
80
+ if (originFile.length === 0) {
81
+ return true;
82
+ }
83
+ const normalizedOriginFile = normalizePath(originFile);
86
84
  if (this.exclude) {
87
- const matchedToExclude = matching.match(originFiles, this.exclude);
88
- if (originFiles.length === matchedToExclude.length) {
85
+ const matchedToExclude = (0, micromatch_1.default)([normalizedOriginFile], this.exclude);
86
+ if (matchedToExclude.length === 1) {
89
87
  return false;
90
88
  }
91
89
  }
92
90
  if (this.include) {
93
- const matchedToInclude = matching.match(originFiles, (_a = this.include) !== null && _a !== void 0 ? _a : '**');
94
- return matchedToInclude.length > 0;
91
+ return micromatch_1.default.some([normalizedOriginFile], this.include || ['**']);
95
92
  }
96
93
  return true;
97
94
  }
95
+ /**
96
+ * Variant of `isIncluded` working on a list of files to check.
97
+ * (Primarily, used for testing.)
98
+ */
99
+ isAnyIncluded(originFiles) {
100
+ return originFiles.find(value => this.isIncluded(value)) !== undefined;
101
+ }
98
102
  }
99
103
  exports.OriginSourcePattern = OriginSourcePattern;
104
+ /**
105
+ * Pattern describing files (bundles) to not instrument.
106
+ */
107
+ class FileExcludePattern {
108
+ constructor(exclude) {
109
+ var _a;
110
+ this.exclude = (_a = normalizePatterns(exclude)) !== null && _a !== void 0 ? _a : [];
111
+ }
112
+ /**
113
+ * Return `true` if the given `filePath` is matched by any of the patterns in `exclude`.
114
+ */
115
+ isExcluded(filePath) {
116
+ return micromatch_1.default.isMatch(normalizePath(filePath), this.exclude);
117
+ }
118
+ }
119
+ exports.FileExcludePattern = FileExcludePattern;
120
+ /**
121
+ * Normalizes all patterns (normally either include or exclude patterns), and returns all
122
+ * valid normalized patterns. Returns undefined if the patterns list is undefined, or all
123
+ * items inside the list are undefined.
124
+ */
125
+ function normalizePatterns(patterns) {
126
+ if (patterns === undefined || patterns.length === 0) {
127
+ return undefined;
128
+ }
129
+ const normalizedPatterns = patterns
130
+ .map(pattern => normalizeGlobPattern(pattern))
131
+ .filter(pattern => pattern !== undefined);
132
+ if (patterns.length === 0) {
133
+ return undefined;
134
+ }
135
+ return normalizedPatterns;
136
+ }
137
+ function normalizeGlobPattern(pattern) {
138
+ if (!pattern) {
139
+ return pattern;
140
+ }
141
+ return removeTrailingCurrentWorkingDir(pattern);
142
+ }
143
+ function normalizePath(toNormalize) {
144
+ return removeTrailingCurrentWorkingDir(toNormalize.replace(/\\/g, '/'));
145
+ }
146
+ function removeTrailingCurrentWorkingDir(removeFrom) {
147
+ return removePrefix('webpack:///', removePrefix('./', removeFrom));
148
+ }
149
+ function removePrefix(prefix, removeFrom) {
150
+ if (removeFrom.startsWith(prefix)) {
151
+ return removeFrom.substring(prefix.length);
152
+ }
153
+ return removeFrom;
154
+ }
100
155
  /**
101
156
  * The actual instrumentation task.
102
157
  */
103
158
  class InstrumentationTask {
104
- constructor(collector, elements, originSourcePattern) {
159
+ constructor(collector, elements, excludeFilesPattern, originSourcePattern, dumpOriginsFile) {
105
160
  this.collector = commons_1.Contract.requireDefined(collector);
161
+ this.excludeFilesPattern = commons_1.Contract.requireDefined(excludeFilesPattern);
106
162
  this.originSourcePattern = commons_1.Contract.requireDefined(originSourcePattern);
107
163
  this._elements = commons_1.Contract.requireDefined(elements).slice();
164
+ this.dumpOriginsFile = dumpOriginsFile;
108
165
  }
109
166
  /**
110
167
  * @returns the elements of the task.
@@ -120,14 +177,16 @@ exports.InstrumentationTask = InstrumentationTask;
120
177
  * A summary of executing the instrumentation task.
121
178
  */
122
179
  class TaskResult {
123
- constructor(translated, translatedFromCache, alreadyInstrumented, unsupported, failed, warnings) {
180
+ constructor(translated, excluded, translatedFromCache, alreadyInstrumented, unsupported, failed, warnings) {
124
181
  commons_1.Contract.require(translated > -1);
182
+ commons_1.Contract.require(excluded > -1);
125
183
  commons_1.Contract.require(translatedFromCache > -1);
126
184
  commons_1.Contract.require(alreadyInstrumented > -1);
127
185
  commons_1.Contract.require(unsupported > -1);
128
186
  commons_1.Contract.require(failed > -1);
129
187
  commons_1.Contract.require(warnings > -1);
130
188
  this.translated = translated;
189
+ this.excluded = excluded;
131
190
  this.translatedFromCache = translatedFromCache;
132
191
  this.alreadyInstrumented = alreadyInstrumented;
133
192
  this.unsupported = unsupported;
@@ -140,13 +199,13 @@ class TaskResult {
140
199
  * @param incBy - The task result to add (as delta).
141
200
  */
142
201
  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);
202
+ 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
203
  }
145
204
  /**
146
205
  * @returns the neutral task element (adding it with {@code withIncrement} does not change the result).
147
206
  */
148
207
  static neutral() {
149
- return new TaskResult(0, 0, 0, 0, 0, 0);
208
+ return new TaskResult(0, 0, 0, 0, 0, 0, 0);
150
209
  }
151
210
  /**
152
211
  * @returns a task result signaling one error.
@@ -155,7 +214,7 @@ class TaskResult {
155
214
  */
156
215
  static error(e) {
157
216
  console.error(e);
158
- return new TaskResult(0, 0, 0, 0, 1, 0);
217
+ return new TaskResult(0, 0, 0, 0, 0, 1, 0);
159
218
  }
160
219
  /**
161
220
  * @returns a task result signaling one warning.
@@ -164,7 +223,7 @@ class TaskResult {
164
223
  */
165
224
  static warning(msg) {
166
225
  console.warn(msg);
167
- return new TaskResult(0, 0, 0, 0, 0, 1);
226
+ return new TaskResult(0, 0, 0, 0, 0, 0, 1);
168
227
  }
169
228
  }
170
229
  exports.TaskResult = TaskResult;
@@ -1,14 +1,16 @@
1
1
  import { InstrumentationTask, SourceMapReference } from './Task';
2
2
  /** The parameters the instrumenter can be configured by */
3
- export declare type ConfigurationParameters = {
3
+ export type ConfigurationParameters = {
4
4
  inputs?: string[];
5
5
  in_place?: boolean;
6
6
  debug?: boolean;
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;I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- 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.
@@ -0,0 +1,40 @@
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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WebToolkit.d.ts","sourceRoot":"","sources":["../../../src/instrumenter/WebToolkit.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;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"}