@teamscale/javascript-instrumenter 1.0.0-beta.5 → 1.0.0-beta.7
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 +0 -25
- package/dist/package.json +22 -28
- package/dist/src/App.d.ts +0 -36
- package/dist/src/App.d.ts.map +1 -1
- package/dist/src/App.js +4 -54
- package/dist/src/instrumenter/FileSystem.d.ts +0 -28
- package/dist/src/instrumenter/FileSystem.d.ts.map +1 -1
- package/dist/src/instrumenter/FileSystem.js +2 -32
- package/dist/src/instrumenter/Instrumenter.d.ts +2 -69
- package/dist/src/instrumenter/Instrumenter.d.ts.map +1 -1
- package/dist/src/instrumenter/Instrumenter.js +11 -94
- package/dist/src/instrumenter/InstrumenterConfig.d.ts +1 -9
- package/dist/src/instrumenter/InstrumenterConfig.d.ts.map +1 -1
- package/dist/src/instrumenter/InstrumenterConfig.js +22 -6
- package/dist/src/instrumenter/RelativeCollectorPatternParser.d.ts +1 -3
- package/dist/src/instrumenter/RelativeCollectorPatternParser.d.ts.map +1 -1
- package/dist/src/instrumenter/RelativeCollectorPatternParser.js +9 -9
- package/dist/src/instrumenter/RelativeCollectorPatternParser.test.js +12 -7
- package/dist/src/instrumenter/Task.d.ts +0 -144
- package/dist/src/instrumenter/Task.d.ts.map +1 -1
- package/dist/src/instrumenter/Task.js +29 -110
- package/dist/src/instrumenter/TaskBuilder.d.ts +0 -50
- package/dist/src/instrumenter/TaskBuilder.d.ts.map +1 -1
- package/dist/src/instrumenter/TaskBuilder.js +12 -59
- package/dist/src/instrumenter/WebToolkit.d.ts +0 -27
- package/dist/src/instrumenter/WebToolkit.d.ts.map +1 -1
- package/dist/src/instrumenter/WebToolkit.js +0 -27
- package/dist/src/main.js +3 -1
- package/dist/src/vaccine/types.d.ts +0 -37
- package/dist/src/vaccine/types.d.ts.map +1 -1
- package/dist/vaccine.js +1 -1
- package/package.json +13 -13
package/README.md
CHANGED
|
@@ -14,28 +14,3 @@ in the [Teamscale Documentation](https://docs.teamscale.com/howto/setting-up-pro
|
|
|
14
14
|
The Instrumenter instruments a given (set of) JavaScript file(s) such that (1) coverage
|
|
15
15
|
information is produced and (2) forwarded to the Collector.
|
|
16
16
|
|
|
17
|
-
## Building
|
|
18
|
-
|
|
19
|
-
The Instrumenter is written in TypeScript/JavaScript. For building and running it,
|
|
20
|
-
NodeJs (>= v16) and pnpm are needed as prerequisites.
|
|
21
|
-
|
|
22
|
-
```
|
|
23
|
-
pnpm clean
|
|
24
|
-
pnpm install
|
|
25
|
-
pnpm build
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
## Workflow Integration
|
|
29
|
-
|
|
30
|
-
There are several options to run the Instrumenter. For example, via `pnpm` by running
|
|
31
|
-
|
|
32
|
-
```
|
|
33
|
-
pnpm instrumenter
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
or via `npx` by running
|
|
37
|
-
|
|
38
|
-
```
|
|
39
|
-
npx @teamscale/javascript-instrumenter
|
|
40
|
-
```
|
|
41
|
-
|
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teamscale/javascript-instrumenter",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.7",
|
|
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",
|
|
@@ -14,53 +14,47 @@
|
|
|
14
14
|
"build": "tsc --project tsconfig.json && pnpm buildVaccine",
|
|
15
15
|
"buildVaccine": "node esbuild.mjs",
|
|
16
16
|
"instrumenter": "node dist/src/main.js",
|
|
17
|
-
"test": "
|
|
17
|
+
"test": "node --import tsx --test test/**/*.test.ts"
|
|
18
18
|
},
|
|
19
19
|
"files": [
|
|
20
20
|
"dist/**/*"
|
|
21
21
|
],
|
|
22
22
|
"devDependencies": {
|
|
23
|
-
"@babel/core": "^7.
|
|
24
|
-
"@babel/plugin-transform-modules-commonjs": "^7.
|
|
25
|
-
"@babel/preset-env": "^7.
|
|
26
|
-
"@types/async": "^3.2.
|
|
27
|
-
"@types/babel__generator": "^7.
|
|
28
|
-
"@types/babel__traverse": "^7.
|
|
23
|
+
"@babel/core": "^7.28.5",
|
|
24
|
+
"@babel/plugin-transform-modules-commonjs": "^7.27.1",
|
|
25
|
+
"@babel/preset-env": "^7.28.5",
|
|
26
|
+
"@types/async": "^3.2.25",
|
|
27
|
+
"@types/babel__generator": "^7.27.0",
|
|
28
|
+
"@types/babel__traverse": "^7.28.0",
|
|
29
29
|
"@types/bunyan": "^1.8.11",
|
|
30
30
|
"@types/convert-source-map": "^2.0.3",
|
|
31
|
-
"@types/
|
|
32
|
-
"@types/
|
|
33
|
-
"
|
|
34
|
-
"@types/ws": "^8.5.14",
|
|
35
|
-
"@types/uuid": "^10.0.0",
|
|
36
|
-
"babel-jest": "^29.7.0",
|
|
37
|
-
"esbuild": "^0.25.0",
|
|
31
|
+
"@types/node": "^22.18.12",
|
|
32
|
+
"@types/ws": "^8.18.1",
|
|
33
|
+
"esbuild": "^0.25.11",
|
|
38
34
|
"esbuild-plugin-inline-worker": "^0.1.1",
|
|
39
|
-
"jest": "^29.7.0",
|
|
40
35
|
"rimraf": "^6.0.1",
|
|
41
|
-
"ts-jest": "^29.2.5",
|
|
42
|
-
"ts-node": "^10.9.2",
|
|
43
36
|
"tslib": "^2.8.1",
|
|
44
|
-
"
|
|
37
|
+
"tsx": "^4.19.2",
|
|
38
|
+
"typescript": "^5.8.3"
|
|
45
39
|
},
|
|
46
40
|
"dependencies": {
|
|
41
|
+
"@babel/generator": "^7.28.5",
|
|
42
|
+
"@babel/parser": "^7.28.5",
|
|
43
|
+
"@babel/traverse": "^7.28.5",
|
|
44
|
+
"@babel/types": "^7.28.5",
|
|
47
45
|
"@cqse/commons": "workspace:../cqse-commons",
|
|
48
46
|
"@teamscale/lib-instrument": "workspace:../lib-instrument",
|
|
49
|
-
"@
|
|
50
|
-
"@babel/parser": "^7.26.8",
|
|
51
|
-
"@babel/traverse": "^7.26.8",
|
|
52
|
-
"@babel/types": "^7.26.8",
|
|
53
|
-
"@types/micromatch": "^4.0.9",
|
|
47
|
+
"@types/micromatch": "^4.0.10",
|
|
54
48
|
"async": "^3.2.6",
|
|
55
49
|
"bunyan": "^1.8.15",
|
|
56
50
|
"convert-source-map": "^2.0.0",
|
|
57
|
-
"foreground-child": "^3.3.
|
|
58
|
-
"glob": "^11.0.1",
|
|
51
|
+
"foreground-child": "^3.3.1",
|
|
59
52
|
"micromatch": "4.0.8",
|
|
60
53
|
"mkdirp": "^3.0.1",
|
|
61
|
-
"source-map": "0.7.
|
|
54
|
+
"source-map": "0.7.6",
|
|
55
|
+
"tinyglobby": "^0.2.15",
|
|
62
56
|
"unload": "^2.4.1",
|
|
63
|
-
"uuid": "^
|
|
57
|
+
"uuid": "^13.0.0",
|
|
64
58
|
"web-worker": "^1.5.0"
|
|
65
59
|
},
|
|
66
60
|
"publishConfig": {
|
package/dist/src/App.d.ts
CHANGED
|
@@ -1,52 +1,16 @@
|
|
|
1
1
|
import { TaskResult } from './instrumenter/Task';
|
|
2
2
|
import Logger from 'bunyan';
|
|
3
3
|
import { InstrumenterOptions } from './instrumenter/InstrumenterConfig';
|
|
4
|
-
/**
|
|
5
|
-
* Entry points of the instrumenter, including command line argument parsing.
|
|
6
|
-
*/
|
|
7
4
|
export declare class App {
|
|
8
|
-
/**
|
|
9
|
-
* Main function of the instrumenter.
|
|
10
|
-
* Parses the command line options and the instrumentation accordingly.
|
|
11
|
-
*/
|
|
12
5
|
static run(): Promise<TaskResult>;
|
|
13
|
-
/**
|
|
14
|
-
* Runs the application with for the given command line arguments. Visible for testing.
|
|
15
|
-
*/
|
|
16
6
|
static runForArgv(argv: string[]): Promise<TaskResult>;
|
|
17
|
-
/**
|
|
18
|
-
* Parses the command-line arguments.
|
|
19
|
-
*
|
|
20
|
-
* @param args - Optional. For testing. If given, uses this as the arguments to parse and does not exit the process on errors.
|
|
21
|
-
* If not given, uses the NodeJS process's arguments and exits on errors.
|
|
22
|
-
* @param beforeArgumentCheckCallback - To be executed before the arguments are checked for validity.
|
|
23
|
-
*/
|
|
24
7
|
static parseCommandLine(args?: string[], beforeArgumentCheckCallback?: (options: InstrumenterOptions) => void): InstrumenterOptions;
|
|
25
|
-
/**
|
|
26
|
-
* Sometimes we get inputs from shell environments where the strings are
|
|
27
|
-
* still quoted. We remove those here.
|
|
28
|
-
*/
|
|
29
8
|
static postprocessConfig(config: InstrumenterOptions): void;
|
|
30
|
-
/**
|
|
31
|
-
* Construct the logger.
|
|
32
|
-
*/
|
|
33
9
|
private static buildLogger;
|
|
34
|
-
/**
|
|
35
|
-
* A logger for testing.
|
|
36
|
-
*/
|
|
37
10
|
private static buildDummyLogger;
|
|
38
|
-
/**
|
|
39
|
-
* The instrumenter can also be started by providing the configuration dictionary explicitly.
|
|
40
|
-
*
|
|
41
|
-
* @param config - The dictionary with all configuration arguments.
|
|
42
|
-
* @param logger - The logger to use.
|
|
43
|
-
*/
|
|
44
11
|
static runForConfigArguments(config: InstrumenterOptions, logger?: Logger): Promise<TaskResult>;
|
|
45
12
|
private static createInstrumentationTask;
|
|
46
13
|
private static createInstrumenter;
|
|
47
|
-
/**
|
|
48
|
-
* Processes the task result and produces console outputs, and possibly a process exit with a corresponding code.
|
|
49
|
-
*/
|
|
50
14
|
private static finalizeAppRunWithConsoleOutputs;
|
|
51
15
|
}
|
|
52
16
|
//# sourceMappingURL=App.d.ts.map
|
package/dist/src/App.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"App.d.ts","sourceRoot":"","sources":["../../src/App.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAYtE,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B,OAAO,EAA4C,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;
|
|
1
|
+
{"version":3,"file":"App.d.ts","sourceRoot":"","sources":["../../src/App.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAYtE,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B,OAAO,EAA4C,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AAMlH,qBAAa,GAAG;WAKK,GAAG,IAAI,OAAO,CAAC,UAAU,CAAC;WAO1B,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,UAAU,CAAC;WAkCrD,gBAAgB,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,EAAE,2BAA2B,CAAC,EAAE,CAAC,OAAO,EAAE,mBAAmB,KAAK,IAAI,GAAG,mBAAmB;WAU5H,iBAAiB,CAAC,MAAM,EAAE,mBAAmB,GAAG,IAAI;IA2ClE,OAAO,CAAC,MAAM,CAAC,WAAW;IAkC1B,OAAO,CAAC,MAAM,CAAC,gBAAgB;WAUjB,qBAAqB,CAAC,MAAM,EAAE,mBAAmB,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;IAqCtG,OAAO,CAAC,MAAM,CAAC,yBAAyB;IAIxC,OAAO,CAAC,MAAM,CAAC,kBAAkB;mBAiBZ,gCAAgC;CAmDrD"}
|
package/dist/src/App.js
CHANGED
|
@@ -47,20 +47,10 @@ const mkdirp_1 = require("mkdirp");
|
|
|
47
47
|
const bunyan_1 = __importDefault(require("bunyan"));
|
|
48
48
|
const InstrumenterConfig_1 = require("./instrumenter/InstrumenterConfig");
|
|
49
49
|
const process = __importStar(require("node:process"));
|
|
50
|
-
/**
|
|
51
|
-
* Entry points of the instrumenter, including command line argument parsing.
|
|
52
|
-
*/
|
|
53
50
|
class App {
|
|
54
|
-
/**
|
|
55
|
-
* Main function of the instrumenter.
|
|
56
|
-
* Parses the command line options and the instrumentation accordingly.
|
|
57
|
-
*/
|
|
58
51
|
static async run() {
|
|
59
52
|
return this.runForArgv(process.argv);
|
|
60
53
|
}
|
|
61
|
-
/**
|
|
62
|
-
* Runs the application with for the given command line arguments. Visible for testing.
|
|
63
|
-
*/
|
|
64
54
|
static async runForArgv(argv) {
|
|
65
55
|
const config = this.parseCommandLine(argv.slice(2), options => {
|
|
66
56
|
if (options.collectorOptionsList) {
|
|
@@ -75,29 +65,16 @@ class App {
|
|
|
75
65
|
process.exit(0);
|
|
76
66
|
}
|
|
77
67
|
});
|
|
78
|
-
// Build the logger
|
|
79
68
|
const logger = this.buildLogger(config);
|
|
80
69
|
logger.trace('Retrieved arguments', process.argv);
|
|
81
70
|
logger.trace('Translated arguments to config', config);
|
|
82
|
-
// Run the instrumenter with the given configuration.
|
|
83
71
|
return this.runForConfigArguments(config, logger);
|
|
84
72
|
}
|
|
85
|
-
/**
|
|
86
|
-
* Parses the command-line arguments.
|
|
87
|
-
*
|
|
88
|
-
* @param args - Optional. For testing. If given, uses this as the arguments to parse and does not exit the process on errors.
|
|
89
|
-
* If not given, uses the NodeJS process's arguments and exits on errors.
|
|
90
|
-
* @param beforeArgumentCheckCallback - To be executed before the arguments are checked for validity.
|
|
91
|
-
*/
|
|
92
73
|
static parseCommandLine(args, beforeArgumentCheckCallback) {
|
|
93
74
|
const configParameters = (0, InstrumenterConfig_1.buildInstrumenterConfigurationParameters)();
|
|
94
75
|
const appInfos = { about: package_json_1.description, version: package_json_1.version, name: package_json_1.name };
|
|
95
76
|
return (0, commons_1.processCommandLine)(configParameters, appInfos, args, beforeArgumentCheckCallback);
|
|
96
77
|
}
|
|
97
|
-
/**
|
|
98
|
-
* Sometimes we get inputs from shell environments where the strings are
|
|
99
|
-
* still quoted. We remove those here.
|
|
100
|
-
*/
|
|
101
78
|
static postprocessConfig(config) {
|
|
102
79
|
function unquoteString(originalString) {
|
|
103
80
|
if (originalString === undefined) {
|
|
@@ -126,33 +103,25 @@ class App {
|
|
|
126
103
|
}
|
|
127
104
|
for (const [property, value] of Object.entries(config)) {
|
|
128
105
|
if (value === undefined) {
|
|
129
|
-
// In case the value is 'undefined' we can ignore this.
|
|
130
106
|
}
|
|
131
107
|
else if (typeof value === 'string') {
|
|
132
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
133
108
|
config[property] = unquoteString(value);
|
|
134
109
|
}
|
|
135
110
|
else if (Array.isArray(value)) {
|
|
136
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
137
111
|
config[property] = unquoteStringElements(value);
|
|
138
112
|
}
|
|
139
113
|
}
|
|
140
114
|
}
|
|
141
|
-
/**
|
|
142
|
-
* Construct the logger.
|
|
143
|
-
*/
|
|
144
115
|
static buildLogger(config) {
|
|
145
|
-
var _a;
|
|
146
116
|
const logfilePath = 'logs/instrumenter.log';
|
|
147
117
|
mkdirp_1.mkdirp.sync(path.dirname(logfilePath));
|
|
148
|
-
const logLevel =
|
|
118
|
+
const logLevel = config.logLevel ?? 'info';
|
|
149
119
|
return bunyan_1.default.createLogger({
|
|
150
120
|
name: 'Instrumenter',
|
|
151
121
|
streams: [
|
|
152
122
|
{
|
|
153
123
|
level: logLevel,
|
|
154
124
|
stream: {
|
|
155
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
156
125
|
write: (rec) => {
|
|
157
126
|
console.log('[%s] %s: %s', rec.time.toISOString(), bunyan_1.default.nameFromLevel[rec.level], rec.msg);
|
|
158
127
|
}
|
|
@@ -166,18 +135,9 @@ class App {
|
|
|
166
135
|
]
|
|
167
136
|
});
|
|
168
137
|
}
|
|
169
|
-
/**
|
|
170
|
-
* A logger for testing.
|
|
171
|
-
*/
|
|
172
138
|
static buildDummyLogger() {
|
|
173
139
|
return bunyan_1.default.createLogger({ name: 'Instrumenter' });
|
|
174
140
|
}
|
|
175
|
-
/**
|
|
176
|
-
* The instrumenter can also be started by providing the configuration dictionary explicitly.
|
|
177
|
-
*
|
|
178
|
-
* @param config - The dictionary with all configuration arguments.
|
|
179
|
-
* @param logger - The logger to use.
|
|
180
|
-
*/
|
|
181
141
|
static runForConfigArguments(config, logger) {
|
|
182
142
|
this.postprocessConfig(config);
|
|
183
143
|
if (config.collectorConfigFile) {
|
|
@@ -194,7 +154,6 @@ class App {
|
|
|
194
154
|
}
|
|
195
155
|
if (config.collectorConfigFileContent) {
|
|
196
156
|
try {
|
|
197
|
-
// We parse the collector config file once, to see if it is valid.
|
|
198
157
|
const collectorParameters = (0, commons_1.buildReconfigurableCollectorParameters)();
|
|
199
158
|
const { options } = (0, commons_1.parseConfigFile)(config.collectorConfigFileContent, collectorParameters);
|
|
200
159
|
if (!(0, commons_1.checkArguments)(collectorParameters, options)) {
|
|
@@ -207,17 +166,13 @@ class App {
|
|
|
207
166
|
}
|
|
208
167
|
const task = this.createInstrumentationTask(config);
|
|
209
168
|
commons_1.Contract.require(task.elements.length > 0, 'The instrumentation task must not be empty.');
|
|
210
|
-
const instrumentationResult = this.createInstrumenter(logger
|
|
169
|
+
const instrumentationResult = this.createInstrumenter(logger ?? this.buildDummyLogger(), task.collector, task.targetBucket).instrument(task);
|
|
211
170
|
return App.finalizeAppRunWithConsoleOutputs(instrumentationResult);
|
|
212
171
|
}
|
|
213
172
|
static createInstrumentationTask(config) {
|
|
214
173
|
return new TaskBuilder_1.TaskBuilder().addFromConfig(config).build();
|
|
215
174
|
}
|
|
216
175
|
static createInstrumenter(logger, collector, targetBucket) {
|
|
217
|
-
// We have to deal with two different `__dirname` versions,
|
|
218
|
-
// which depends on whether we run from within the IDE or from
|
|
219
|
-
// the command line:
|
|
220
|
-
// dist/src/ OR src/
|
|
221
176
|
const pathVariant1 = path.join(__dirname, '../vaccine.js');
|
|
222
177
|
const pathVariant2 = path.join(__dirname, '../dist/vaccine.js');
|
|
223
178
|
if ((0, fs_1.existsSync)(pathVariant1)) {
|
|
@@ -227,11 +182,7 @@ class App {
|
|
|
227
182
|
return new Instrumenter_1.IstanbulInstrumenter(pathVariant2, logger, collector, targetBucket);
|
|
228
183
|
}
|
|
229
184
|
}
|
|
230
|
-
/**
|
|
231
|
-
* Processes the task result and produces console outputs, and possibly a process exit with a corresponding code.
|
|
232
|
-
*/
|
|
233
185
|
static async finalizeAppRunWithConsoleOutputs(resultPromise) {
|
|
234
|
-
var _a, _b;
|
|
235
186
|
try {
|
|
236
187
|
const result = await resultPromise;
|
|
237
188
|
console.log('Instrumentation finished.');
|
|
@@ -242,8 +193,8 @@ class App {
|
|
|
242
193
|
console.log(`\tUnsupported: ${result.unsupported}`);
|
|
243
194
|
console.log(`\tWith warning: ${result.warnings}`);
|
|
244
195
|
console.log(`\tFailed: ${result.failed}`);
|
|
245
|
-
if (
|
|
246
|
-
const stats =
|
|
196
|
+
if (result.task?.originSourcePattern.patternsSpecified()) {
|
|
197
|
+
const stats = result.task?.originSourcePattern.retrieveMatchingFiles();
|
|
247
198
|
console.log(`\tSource origin matches`);
|
|
248
199
|
console.log(`\t\tInclude patterns: [${stats.includePatterns}]`);
|
|
249
200
|
console.log(`\t\tExclude patterns: [${stats.excludePatterns}]`);
|
|
@@ -267,7 +218,6 @@ class App {
|
|
|
267
218
|
}
|
|
268
219
|
catch (reason) {
|
|
269
220
|
if (reason instanceof commons_1.InvalidConfigurationException) {
|
|
270
|
-
// Do not print the stack trace for invalid configuration parameters from the user.
|
|
271
221
|
console.error(`Failed: ${reason.message}`);
|
|
272
222
|
}
|
|
273
223
|
else {
|
|
@@ -1,38 +1,10 @@
|
|
|
1
1
|
import { RawSourceMap } from 'source-map';
|
|
2
|
-
/**
|
|
3
|
-
* Does the given `path` point to an existing file?
|
|
4
|
-
*/
|
|
5
2
|
export declare function isExistingFile(path: string): boolean;
|
|
6
|
-
/**
|
|
7
|
-
* Does the given `path` point to an existing directory?
|
|
8
|
-
*/
|
|
9
3
|
export declare function isExistingDirectory(path: string): boolean;
|
|
10
|
-
/**
|
|
11
|
-
* Ensure that the given directory `path` exists.
|
|
12
|
-
*/
|
|
13
4
|
export declare function ensureExistingDirectory(path: string): void;
|
|
14
|
-
/**
|
|
15
|
-
* Given a root folder find a folder with a given name.
|
|
16
|
-
*/
|
|
17
5
|
export declare function findSubFolders(startFromFolder: string, folderName: string): string[];
|
|
18
|
-
/**
|
|
19
|
-
* Is the given directory empty?
|
|
20
|
-
*/
|
|
21
6
|
export declare function isDirectoryEmpty(path: string): boolean;
|
|
22
|
-
/**
|
|
23
|
-
* Expand a given Glob pattern to a list of files.
|
|
24
|
-
*
|
|
25
|
-
* @param toExpand - The Glob pattern.
|
|
26
|
-
*/
|
|
27
7
|
export declare function expandToFileSet(toExpand: string): string[];
|
|
28
|
-
/**
|
|
29
|
-
* Read a source map from a source map file.
|
|
30
|
-
*
|
|
31
|
-
* @param mapFilePath
|
|
32
|
-
*/
|
|
33
8
|
export declare function sourceMapFromMapFile(mapFilePath: string): RawSourceMap | undefined;
|
|
34
|
-
/**
|
|
35
|
-
* Ensure that the given name works as a file or folder name.
|
|
36
|
-
*/
|
|
37
9
|
export declare function replaceNonFilesystemCharacters(name: string): string;
|
|
38
10
|
//# sourceMappingURL=FileSystem.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FileSystem.d.ts","sourceRoot":"","sources":["../../../src/instrumenter/FileSystem.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"FileSystem.d.ts","sourceRoot":"","sources":["../../../src/instrumenter/FileSystem.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAM1C,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEpD;AAKD,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEzD;AAKD,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAU1D;AAKD,wBAAgB,cAAc,CAAC,eAAe,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,EAAE,CAgBpF;AAKD,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEtD;AAOD,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,CAc1D;AAOD,wBAAgB,oBAAoB,CAAC,WAAW,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS,CAGlF;AAKD,wBAAgB,8BAA8B,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAKnE"}
|
|
@@ -48,22 +48,13 @@ const commons_1 = require("@cqse/commons");
|
|
|
48
48
|
const fs = __importStar(require("fs"));
|
|
49
49
|
const mkdirp = __importStar(require("mkdirp"));
|
|
50
50
|
const path_1 = __importDefault(require("path"));
|
|
51
|
-
const
|
|
52
|
-
/**
|
|
53
|
-
* Does the given `path` point to an existing file?
|
|
54
|
-
*/
|
|
51
|
+
const tinyglobby_1 = require("tinyglobby");
|
|
55
52
|
function isExistingFile(path) {
|
|
56
53
|
return fs.existsSync(path) && fs.lstatSync(path).isFile();
|
|
57
54
|
}
|
|
58
|
-
/**
|
|
59
|
-
* Does the given `path` point to an existing directory?
|
|
60
|
-
*/
|
|
61
55
|
function isExistingDirectory(path) {
|
|
62
56
|
return fs.existsSync(path) && fs.lstatSync(path).isDirectory();
|
|
63
57
|
}
|
|
64
|
-
/**
|
|
65
|
-
* Ensure that the given directory `path` exists.
|
|
66
|
-
*/
|
|
67
58
|
function ensureExistingDirectory(path) {
|
|
68
59
|
if (!fs.existsSync(path)) {
|
|
69
60
|
mkdirp.sync(path);
|
|
@@ -72,9 +63,6 @@ function ensureExistingDirectory(path) {
|
|
|
72
63
|
throw new commons_1.InvalidConfigurationException(`The specified path '${path}' does not point to an existing directory!`);
|
|
73
64
|
}
|
|
74
65
|
}
|
|
75
|
-
/**
|
|
76
|
-
* Given a root folder find a folder with a given name.
|
|
77
|
-
*/
|
|
78
66
|
function findSubFolders(startFromFolder, folderName) {
|
|
79
67
|
const matches = [];
|
|
80
68
|
const entries = fs.readdirSync(startFromFolder, { withFileTypes: true });
|
|
@@ -90,17 +78,9 @@ function findSubFolders(startFromFolder, folderName) {
|
|
|
90
78
|
}
|
|
91
79
|
return matches;
|
|
92
80
|
}
|
|
93
|
-
/**
|
|
94
|
-
* Is the given directory empty?
|
|
95
|
-
*/
|
|
96
81
|
function isDirectoryEmpty(path) {
|
|
97
82
|
return !isExistingDirectory(path) || fs.readdirSync(path).length > 0;
|
|
98
83
|
}
|
|
99
|
-
/**
|
|
100
|
-
* Expand a given Glob pattern to a list of files.
|
|
101
|
-
*
|
|
102
|
-
* @param toExpand - The Glob pattern.
|
|
103
|
-
*/
|
|
104
84
|
function expandToFileSet(toExpand) {
|
|
105
85
|
let globPattern = toExpand;
|
|
106
86
|
if (fs.existsSync(toExpand)) {
|
|
@@ -112,23 +92,13 @@ function expandToFileSet(toExpand) {
|
|
|
112
92
|
globPattern = `${toExpand}${path_1.default.sep}**`;
|
|
113
93
|
}
|
|
114
94
|
}
|
|
115
|
-
return
|
|
95
|
+
return (0, tinyglobby_1.globSync)(globPattern, { onlyFiles: true });
|
|
116
96
|
}
|
|
117
|
-
/**
|
|
118
|
-
* Read a source map from a source map file.
|
|
119
|
-
*
|
|
120
|
-
* @param mapFilePath
|
|
121
|
-
*/
|
|
122
97
|
function sourceMapFromMapFile(mapFilePath) {
|
|
123
98
|
const content = fs.readFileSync(mapFilePath, 'utf8');
|
|
124
99
|
return JSON.parse(content);
|
|
125
100
|
}
|
|
126
|
-
/**
|
|
127
|
-
* Ensure that the given name works as a file or folder name.
|
|
128
|
-
*/
|
|
129
101
|
function replaceNonFilesystemCharacters(name) {
|
|
130
|
-
// Replace undesired characters by underscore chars.
|
|
131
102
|
const result = name.replace(/[^a-zA-Z0-9_\-.\\/]/g, '_');
|
|
132
|
-
// Remove repeated underscores (_) from `result.
|
|
133
103
|
return result.replace(/_+/g, '_');
|
|
134
104
|
}
|
|
@@ -1,92 +1,25 @@
|
|
|
1
1
|
import { FileExcludePattern, InstrumentationTask, OriginSourcePattern, SourceMapReference, TaskElement, TaskResult } from './Task';
|
|
2
|
-
import { RawSourceMap
|
|
2
|
+
import { RawSourceMap } from 'source-map';
|
|
3
3
|
import Logger from 'bunyan';
|
|
4
|
-
import { CollectorSpecifier, CoverageBucketSpecifier } from '
|
|
4
|
+
import { CollectorSpecifier, CoverageBucketSpecifier } from '../vaccine/types';
|
|
5
5
|
export declare const IS_INSTRUMENTED_TOKEN = "$IS_JS_PROFILER_INSTRUMENTED=true";
|
|
6
|
-
/**
|
|
7
|
-
* An instrumenter that can conduct a {@code InstrumentationTask}.
|
|
8
|
-
*/
|
|
9
6
|
export interface IInstrumenter {
|
|
10
|
-
/**
|
|
11
|
-
* Perform the given instrumentation task.
|
|
12
|
-
*
|
|
13
|
-
* @param task - The instrumentation task to conduct.
|
|
14
|
-
*/
|
|
15
7
|
instrument(task: InstrumentationTask): Promise<TaskResult>;
|
|
16
8
|
}
|
|
17
|
-
/**
|
|
18
|
-
* An instrumenter based on the IstanbulJs instrumentation and coverage framework.
|
|
19
|
-
*/
|
|
20
9
|
export declare class IstanbulInstrumenter implements IInstrumenter {
|
|
21
|
-
/**
|
|
22
|
-
* The vaccine to inject. The vaccine is a JavaScript
|
|
23
|
-
* file with the code to forward the coverage information
|
|
24
|
-
* produced by the Istanbul instrumentation.
|
|
25
|
-
*/
|
|
26
10
|
private readonly vaccineSource;
|
|
27
|
-
/**
|
|
28
|
-
* The logger instance to log to.
|
|
29
|
-
*/
|
|
30
11
|
private logger;
|
|
31
12
|
constructor(vaccineFilePath: string, logger: Logger, collector: CollectorSpecifier, targetBucket: CoverageBucketSpecifier);
|
|
32
|
-
/**
|
|
33
|
-
* {@inheritDoc #IInstrumenter.instrument}
|
|
34
|
-
*/
|
|
35
13
|
instrument(task: InstrumentationTask): Promise<TaskResult>;
|
|
36
|
-
/**
|
|
37
|
-
* Perform the instrumentation for one given task element (file to instrument).
|
|
38
|
-
*
|
|
39
|
-
* @param collector - The collector to send the coverage information to.
|
|
40
|
-
* @param taskElement - The task element to perform the instrumentation for.
|
|
41
|
-
* @param excludeBundles - A exclude pattern to restrict which bundles should be instrumented
|
|
42
|
-
* @param sourcePattern - A pattern to restrict the instrumentation to only a fraction of the task element.
|
|
43
|
-
* @param dumpOriginsFile - A file path where all origins from the source map should be dumped in json format, or undefined if no origins should be dumped
|
|
44
|
-
*/
|
|
45
14
|
instrumentOne(taskElement: TaskElement, excludeBundles: FileExcludePattern, sourcePattern: OriginSourcePattern, dumpOriginsFile: string | undefined): Promise<TaskResult>;
|
|
46
15
|
private instrumentBundle;
|
|
47
16
|
private writeBundleFile;
|
|
48
|
-
/**
|
|
49
|
-
* Loads the vaccine from the vaccine file and adjusts some template parameters.
|
|
50
|
-
*
|
|
51
|
-
* @param filePath - The path to the vaccine file.
|
|
52
|
-
* @param collector - The collector to send coverage information to.
|
|
53
|
-
* @param targetBucket - The bucket within the collector to put the coverage into.
|
|
54
|
-
*/
|
|
55
17
|
private loadVaccine;
|
|
56
|
-
/**
|
|
57
|
-
* @returns whether the given file is supported for instrumentation.
|
|
58
|
-
*/
|
|
59
18
|
private isFileTypeSupported;
|
|
60
|
-
/**
|
|
61
|
-
* Determine the list of configurations to try conducting the
|
|
62
|
-
* given task element.
|
|
63
|
-
*/
|
|
64
19
|
private configurationAlternativesFor;
|
|
65
|
-
/** Deletes the file if it exists, such that it is now ready to be appended. */
|
|
66
20
|
private clearFile;
|
|
67
|
-
/** Write the contents of the given object into the given file, if provided. */
|
|
68
21
|
private dumpToJson;
|
|
69
22
|
}
|
|
70
|
-
/**
|
|
71
|
-
* Extract the sourcemap from the given source code.
|
|
72
|
-
*
|
|
73
|
-
* @param instrumentedSource - The source code.
|
|
74
|
-
* @param instrumentedSourceFileName - The file name to assume for the file name.
|
|
75
|
-
*/
|
|
76
|
-
export declare function loadSourceMap(instrumentedSource: string, instrumentedSourceFileName: string): Promise<SourceMapConsumer | undefined>;
|
|
77
|
-
/**
|
|
78
|
-
* Given a source code file, load the corresponding sourcemap.
|
|
79
|
-
*
|
|
80
|
-
* @param inputSource - The source code that might contain sourcemap comments.
|
|
81
|
-
* @param taskFile - The name of the file the `inputSource` is from.
|
|
82
|
-
* @param externalSourceMapFile - An external source map file to consider.
|
|
83
|
-
*/
|
|
84
23
|
export declare function loadInputSourceMap(inputSource: string, taskFile: string, externalSourceMapFile?: SourceMapReference): RawSourceMap | undefined;
|
|
85
|
-
/**
|
|
86
|
-
* Extract a sourcemap for a given code comment.
|
|
87
|
-
*
|
|
88
|
-
* @param sourcecode - The source code that is scanned for source map comments.
|
|
89
|
-
* @param sourceFilePath - The file name the code was loaded from.
|
|
90
|
-
*/
|
|
91
24
|
export declare function sourceMapFromCodeComment(sourcecode: string, sourceFilePath: string): RawSourceMap | undefined;
|
|
92
25
|
//# sourceMappingURL=Instrumenter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Instrumenter.d.ts","sourceRoot":"","sources":["../../../src/instrumenter/Instrumenter.ts"],"names":[],"mappings":"AAAA,OAAO,EAEN,kBAAkB,EAElB,mBAAmB,EACnB,mBAAmB,EAEnB,kBAAkB,EAElB,WAAW,EACX,UAAU,EACV,MAAM,QAAQ,CAAC;AAEhB,OAAO,EAAE,YAAY,EAAE,
|
|
1
|
+
{"version":3,"file":"Instrumenter.d.ts","sourceRoot":"","sources":["../../../src/instrumenter/Instrumenter.ts"],"names":[],"mappings":"AAAA,OAAO,EAEN,kBAAkB,EAElB,mBAAmB,EACnB,mBAAmB,EAEnB,kBAAkB,EAElB,WAAW,EACX,UAAU,EACV,MAAM,QAAQ,CAAC;AAEhB,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAM1C,OAAO,MAAM,MAAM,QAAQ,CAAC;AAO5B,OAAO,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAE/E,eAAO,MAAM,qBAAqB,sCAAsC,CAAC;AAKzE,MAAM,WAAW,aAAa;IAM7B,UAAU,CAAC,IAAI,EAAE,mBAAmB,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;CAC3D;AA6BD,qBAAa,oBAAqB,YAAW,aAAa;IAMzD,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAS;IAKvC,OAAO,CAAC,MAAM,CAAS;gBAEX,eAAe,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,kBAAkB,EAAE,YAAY,EAAE,uBAAuB;IAanH,UAAU,CAAC,IAAI,EAAE,mBAAmB,GAAG,OAAO,CAAC,UAAU,CAAC;IAmC1D,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;IAiCvB,OAAO,CAAC,WAAW;IAWnB,OAAO,CAAC,mBAAmB;IAa3B,OAAO,CAAC,4BAA4B;IAkBpC,OAAO,CAAC,SAAS;IAWjB,OAAO,CAAC,UAAU;CAYlB;AA6BD,wBAAgB,kBAAkB,CACjC,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,MAAM,EAChB,qBAAqB,CAAC,EAAE,kBAAkB,GACxC,YAAY,GAAG,SAAS,CAU1B;AAQD,wBAAgB,wBAAwB,CAAC,UAAU,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS,CAwC7G"}
|