@teamscale/javascript-instrumenter 0.0.1-alpha.20 → 0.0.1-beta.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.
- package/README.md +28 -12
- package/dist/package.json +17 -15
- package/dist/src/App.d.ts +1 -0
- package/dist/src/App.d.ts.map +1 -0
- package/dist/src/App.js +71 -41
- package/dist/src/instrumenter/FileSystem.d.ts +1 -0
- package/dist/src/instrumenter/FileSystem.d.ts.map +1 -0
- package/dist/src/instrumenter/FileSystem.js +44 -18
- package/dist/src/instrumenter/Instrumenter.d.ts +9 -2
- package/dist/src/instrumenter/Instrumenter.d.ts.map +1 -0
- package/dist/src/instrumenter/Instrumenter.js +99 -47
- package/dist/src/instrumenter/Task.d.ts +3 -2
- package/dist/src/instrumenter/Task.d.ts.map +1 -0
- package/dist/src/instrumenter/Task.js +52 -23
- package/dist/src/instrumenter/TaskBuilder.d.ts +18 -0
- package/dist/src/instrumenter/TaskBuilder.d.ts.map +1 -0
- package/dist/src/instrumenter/TaskBuilder.js +111 -50
- package/dist/src/main.d.ts +1 -0
- package/dist/src/main.d.ts.map +1 -0
- package/dist/src/main.js +4 -2
- package/dist/vaccine.js +216 -571
- package/package.json +13 -15
- package/dist/src/ConfigurationParameters.d.ts +0 -11
- package/dist/src/ConfigurationParameters.js +0 -1
- package/dist/vaccine.js.map +0 -1
|
@@ -1,20 +1,57 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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;
|
|
20
|
+
};
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
exports.TaskBuilder = void 0;
|
|
23
|
+
const Task_1 = require("./Task");
|
|
24
|
+
const commons_1 = require("@cqse/commons");
|
|
25
|
+
const fs = __importStar(require("fs"));
|
|
26
|
+
const path = __importStar(require("path"));
|
|
27
|
+
const FileSystem_1 = require("./FileSystem");
|
|
28
|
+
/**
|
|
29
|
+
* Load a source map object from the given file (path).
|
|
30
|
+
* Exception if the specified file does not exist.
|
|
31
|
+
*
|
|
32
|
+
* @param sourceMapPath - The path to the source map file.
|
|
33
|
+
*/
|
|
34
|
+
function loadSourceMap(sourceMapPath) {
|
|
35
|
+
if (sourceMapPath) {
|
|
36
|
+
if (!fs.existsSync(sourceMapPath)) {
|
|
37
|
+
throw new commons_1.InvalidConfigurationException(`The specified source map file '${sourceMapPath}' was not found.`);
|
|
38
|
+
}
|
|
39
|
+
return new Task_1.SourceMapFileReference(sourceMapPath);
|
|
40
|
+
}
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
6
43
|
/**
|
|
7
44
|
* A builder for an instrumentation task.
|
|
8
45
|
*/
|
|
9
|
-
|
|
46
|
+
class TaskBuilder {
|
|
10
47
|
constructor() {
|
|
11
48
|
this.elements = [];
|
|
12
49
|
this.collector = null;
|
|
13
50
|
}
|
|
14
51
|
/** Set the collector by extracting the information from a given string */
|
|
15
52
|
setCollectorFromString(collectorSpecification) {
|
|
16
|
-
Contract.requireNonEmpty(collectorSpecification);
|
|
17
|
-
this.collector = new CollectorSpecifier(collectorSpecification);
|
|
53
|
+
commons_1.Contract.requireNonEmpty(collectorSpecification);
|
|
54
|
+
this.collector = new Task_1.CollectorSpecifier(collectorSpecification);
|
|
18
55
|
return this;
|
|
19
56
|
}
|
|
20
57
|
/** Set the include pattern */
|
|
@@ -29,7 +66,7 @@ export class TaskBuilder {
|
|
|
29
66
|
}
|
|
30
67
|
/** Add a task element */
|
|
31
68
|
addElement(fromFilePath, toFilePath, fromFileSourceMap) {
|
|
32
|
-
this.elements.push(new TaskElement(fromFilePath, toFilePath, fromFileSourceMap));
|
|
69
|
+
this.elements.push(new Task_1.TaskElement(fromFilePath, toFilePath, fromFileSourceMap));
|
|
33
70
|
return this;
|
|
34
71
|
}
|
|
35
72
|
/**
|
|
@@ -47,74 +84,98 @@ export class TaskBuilder {
|
|
|
47
84
|
this.setOriginSourceIncludePattern(config.include_origin);
|
|
48
85
|
this.setOriginSourceExcludePattern(config.exclude_origin);
|
|
49
86
|
// Handle an explicitly specified source map
|
|
50
|
-
|
|
51
|
-
if (sourceMap) {
|
|
52
|
-
if (!fs.existsSync(sourceMap)) {
|
|
53
|
-
throw new InvalidConfigurationException(`The specified source map file '${sourceMap}' was not found.`);
|
|
54
|
-
}
|
|
55
|
-
sourceMapInfo = new SourceMapFileReference(sourceMap);
|
|
56
|
-
}
|
|
87
|
+
const sourceMapInfo = loadSourceMap(sourceMap);
|
|
57
88
|
// Depending on whether or not an in place instrumentation is needed
|
|
58
89
|
// the task has to be built differently and different invariants
|
|
59
90
|
// have to be satisfied by the passed configuration.
|
|
60
91
|
if (inPlace) {
|
|
61
92
|
if (target) {
|
|
62
|
-
throw new InvalidConfigurationException('No target path must be specified in case an in-place instrumentation is enabled.');
|
|
93
|
+
throw new commons_1.InvalidConfigurationException('No target path must be specified in case an in-place instrumentation is enabled.');
|
|
63
94
|
}
|
|
64
|
-
inputs
|
|
65
|
-
.map(input => expandToFileSet(input))
|
|
66
|
-
.reduce((prev, curr) => {
|
|
67
|
-
return curr.concat(prev);
|
|
68
|
-
}, [])
|
|
69
|
-
.forEach(filePath => this.addElement(filePath, filePath, sourceMapInfo));
|
|
95
|
+
this.addInPlaceTasksFromPattern(inputs, sourceMapInfo);
|
|
70
96
|
}
|
|
71
97
|
else if (!inPlace) {
|
|
72
98
|
// A target directory must be specified
|
|
73
99
|
if (!target) {
|
|
74
|
-
throw new InvalidConfigurationException('A target path must be specified using `--to`.');
|
|
100
|
+
throw new commons_1.InvalidConfigurationException('A target path must be specified using `--to`.');
|
|
75
101
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
102
|
+
this.addInstrumentationTasksFromPatternWithTarget(inputs, target, sourceMapInfo);
|
|
103
|
+
}
|
|
104
|
+
return this;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Adds instrumentation tasks based on a given pattern `inputs` describing the set of
|
|
108
|
+
* input files and produces the output files in the specified output folder `target.
|
|
109
|
+
*
|
|
110
|
+
* @param inputs - Glob pattern describing set of input files
|
|
111
|
+
* @param target - Target folder
|
|
112
|
+
* @param sourceMapInfo - Source map file for all the input files.
|
|
113
|
+
*/
|
|
114
|
+
addInstrumentationTasksFromPatternWithTarget(inputs, target, sourceMapInfo) {
|
|
115
|
+
(0, FileSystem_1.ensureExistingDirectory)(target);
|
|
116
|
+
for (const input of inputs) {
|
|
117
|
+
if ((0, FileSystem_1.isExistingFile)(input)) {
|
|
118
|
+
if ((0, FileSystem_1.isExistingDirectory)(target) || target.endsWith(path.sep)) {
|
|
119
|
+
this.addElement(input, path.join(target, path.basename(input)), sourceMapInfo);
|
|
86
120
|
}
|
|
87
|
-
else
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
}
|
|
96
|
-
else {
|
|
97
|
-
inputFiles.forEach(f => this.addElement(f, path.join(target, path.relative(input, path.basename(f))), sourceMapInfo));
|
|
98
|
-
}
|
|
121
|
+
else {
|
|
122
|
+
this.addElement(input, target, sourceMapInfo);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
else if ((0, FileSystem_1.isExistingDirectory)(input) || isPattern(input)) {
|
|
126
|
+
const inputFiles = inputs.flatMap(input => (0, FileSystem_1.expandToFileSet)(input));
|
|
127
|
+
if (isPattern(input)) {
|
|
128
|
+
inputFiles.forEach(f => this.addElement(f, path.join(target, path.basename(f)), sourceMapInfo));
|
|
99
129
|
}
|
|
100
130
|
else {
|
|
101
|
-
|
|
131
|
+
inputFiles.forEach(f => this.addElement(f, path.join(target, path.relative(input, path.basename(f))), sourceMapInfo));
|
|
102
132
|
}
|
|
103
133
|
}
|
|
134
|
+
else {
|
|
135
|
+
throw new commons_1.InvalidConfigurationException(`The specified input '${input}' was not found.`);
|
|
136
|
+
}
|
|
104
137
|
}
|
|
105
|
-
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Adds in-place instrumentation tasks for the set of files described
|
|
141
|
+
* by the `inputs` pattern.
|
|
142
|
+
*
|
|
143
|
+
* @param inputs - Glob pattern.
|
|
144
|
+
* @param sourceMapInfo - Source map for the files described by the pattern.
|
|
145
|
+
*/
|
|
146
|
+
addInPlaceTasksFromPattern(inputs, sourceMapInfo) {
|
|
147
|
+
inputs
|
|
148
|
+
.map(input => expandAndCheck(input))
|
|
149
|
+
.reduce((prev, curr) => {
|
|
150
|
+
return curr.concat(prev);
|
|
151
|
+
}, [])
|
|
152
|
+
.forEach(filePath => this.addElement(filePath, filePath, sourceMapInfo));
|
|
106
153
|
}
|
|
107
154
|
/**
|
|
108
155
|
* Build the instrumentation task.
|
|
109
156
|
*/
|
|
110
157
|
build() {
|
|
111
|
-
const pattern = new OriginSourcePattern(this.originSourceIncludePattern, this.originSourceExcludePattern);
|
|
112
|
-
return new InstrumentationTask(Contract.requireDefined(this.collector), this.elements, pattern);
|
|
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);
|
|
113
160
|
}
|
|
114
161
|
}
|
|
162
|
+
exports.TaskBuilder = TaskBuilder;
|
|
115
163
|
/**
|
|
116
164
|
* Does the given string look like a RegExp or Glob pattern?
|
|
117
165
|
*/
|
|
118
166
|
function isPattern(text) {
|
|
119
167
|
return text.includes('*') || text.includes('+') || text.includes('?') || text.includes('|');
|
|
120
168
|
}
|
|
169
|
+
/**
|
|
170
|
+
* Expand the given Glob pattern and check whether or not files matched.
|
|
171
|
+
* Raises an exception is the result is empty.
|
|
172
|
+
*
|
|
173
|
+
* @param pattern - The Glob pattern used for matching.
|
|
174
|
+
*/
|
|
175
|
+
function expandAndCheck(pattern) {
|
|
176
|
+
const result = (0, FileSystem_1.expandToFileSet)(pattern);
|
|
177
|
+
if (result.length === 0) {
|
|
178
|
+
throw new commons_1.InvalidConfigurationException(`No files to instrument found. \n\tWorking directory: '${process.cwd()}'\n\tPattern: '${pattern}'`);
|
|
179
|
+
}
|
|
180
|
+
return result;
|
|
181
|
+
}
|
package/dist/src/main.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../../src/main.ts"],"names":[],"mappings":""}
|
package/dist/src/main.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
const App_1 = require("./App");
|
|
3
5
|
// Run the instrumenter and print the results to the console.
|
|
4
|
-
App.run()
|
|
6
|
+
App_1.App.run()
|
|
5
7
|
.then(result => {
|
|
6
8
|
console.log('Instrumentation finished.');
|
|
7
9
|
console.log(`\tInstrumented: ${result.translated}`);
|