@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.
- package/LICENSE +176 -0
- package/README.md +6 -56
- package/dist/package.json +45 -38
- package/dist/src/App.d.ts +6 -1
- package/dist/src/App.d.ts.map +1 -1
- package/dist/src/App.js +92 -24
- package/dist/src/instrumenter/FileSystem.d.ts +11 -0
- package/dist/src/instrumenter/FileSystem.d.ts.map +1 -1
- package/dist/src/instrumenter/FileSystem.js +37 -4
- package/dist/src/instrumenter/Instrumenter.d.ts +39 -23
- package/dist/src/instrumenter/Instrumenter.d.ts.map +1 -1
- package/dist/src/instrumenter/Instrumenter.js +214 -101
- package/dist/src/instrumenter/Task.d.ts +69 -12
- package/dist/src/instrumenter/Task.d.ts.map +1 -1
- package/dist/src/instrumenter/Task.js +101 -42
- package/dist/src/instrumenter/TaskBuilder.d.ts +19 -11
- package/dist/src/instrumenter/TaskBuilder.d.ts.map +1 -1
- package/dist/src/instrumenter/TaskBuilder.js +28 -14
- package/dist/src/instrumenter/WebToolkit.d.ts +40 -0
- package/dist/src/instrumenter/WebToolkit.d.ts.map +1 -0
- package/dist/src/instrumenter/WebToolkit.js +147 -0
- package/dist/src/main.js +1 -0
- package/dist/vaccine.js +1 -1
- package/package.json +49 -43
package/LICENSE
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
|
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@ in the Teamscale Simple Coverage Format and sent to a Teamscale instance.
|
|
|
9
9
|
The Teamscale JavaScript Profiler consists of the [Coverage Collector](https://www.npmjs.com/package/@teamscale/coverage-collector)
|
|
10
10
|
and this JavaScript Instrumenter.
|
|
11
11
|
More details on using them (in combination) can be found
|
|
12
|
-
|
|
12
|
+
in the [Teamscale Documentation](https://docs.teamscale.com/howto/recording-test-coverage-for-javascript/).
|
|
13
13
|
|
|
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.
|
|
@@ -17,34 +17,12 @@ information is produced and (2) forwarded to the Collector.
|
|
|
17
17
|
## Building
|
|
18
18
|
|
|
19
19
|
The Instrumenter is written in TypeScript/JavaScript. For building and running it,
|
|
20
|
-
NodeJs (>=
|
|
20
|
+
NodeJs (>= v16) and pnpm are needed as prerequisites.
|
|
21
21
|
|
|
22
22
|
```
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
### Preparation: Source Maps
|
|
29
|
-
|
|
30
|
-
Please make sure to enable the generation of source map files to ensure
|
|
31
|
-
that the profiled code can be mapped back to the original.
|
|
32
|
-
|
|
33
|
-
For example, when the tool Vite is used to bundle the code,
|
|
34
|
-
the generation of source map information can be enabled by setting:
|
|
35
|
-
|
|
36
|
-
```
|
|
37
|
-
build: {
|
|
38
|
-
sourcemap: true
|
|
39
|
-
}
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
or
|
|
43
|
-
|
|
44
|
-
```
|
|
45
|
-
build: {
|
|
46
|
-
sourcemap: `inline`
|
|
47
|
-
}
|
|
23
|
+
pnpm clean
|
|
24
|
+
pnpm install
|
|
25
|
+
pnpm build
|
|
48
26
|
```
|
|
49
27
|
|
|
50
28
|
## Workflow Integration
|
|
@@ -61,36 +39,8 @@ or via `npx` by running
|
|
|
61
39
|
npx @teamscale/javascript-instrumenter
|
|
62
40
|
```
|
|
63
41
|
|
|
64
|
-
### Instrumenting a Single File
|
|
65
|
-
|
|
66
|
-
Adds information for coverage tracking to a single file, either
|
|
67
|
-
in-place (by replacing the previous content), or by producing a new file.
|
|
68
|
-
|
|
69
|
-
An in-place transformation is only allowed if the given file is already
|
|
70
|
-
the result of an automatic transformation process, that is, if a source-map is available.
|
|
71
|
-
|
|
72
|
-
If the source-map is not provided as an explicit argument, either
|
|
73
|
-
the file must contain source-map information, or the source-map file
|
|
74
|
-
must be placed along with the source file in the same directory.
|
|
75
|
-
|
|
76
|
-
```
|
|
77
|
-
yarn instrumenter --inplace ./the/path/to/the/file.js
|
|
78
|
-
```
|
|
79
|
-
|
|
80
|
-
```
|
|
81
|
-
yarn instrumenter --inplace ./the/path/to/the/file.js --source-map ./the/path/to/the/source.map
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
```
|
|
85
|
-
yarn instrumenter ./the/path/to/the/file.js --to ./the/file/path/to/write/to.js
|
|
86
|
-
```
|
|
87
|
-
|
|
88
|
-
### Integration with Testing Frameworks
|
|
89
|
-
|
|
90
|
-
This is planned work: Provide a Babel plugin that provides a code transformation
|
|
91
|
-
such that coverage information is collected and this information is forwarded.
|
|
92
|
-
|
|
93
42
|
## Limitations
|
|
94
43
|
|
|
95
44
|
This tool inherits most of the limitations of IstanbulJs, including
|
|
96
45
|
a considerable performance impact.
|
|
46
|
+
|
package/dist/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teamscale/javascript-instrumenter",
|
|
3
|
-
"version": "0.0
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.1.0-beta.2",
|
|
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",
|
|
7
7
|
"types": "dist/src/main.d.ts",
|
|
@@ -12,54 +12,61 @@
|
|
|
12
12
|
"url": "https://github.com/cqse/teamscale-javascript-profiler.git"
|
|
13
13
|
},
|
|
14
14
|
"scripts": {
|
|
15
|
+
"prepublishOnly": "pnpm clean && pnpm build",
|
|
15
16
|
"clean": "rimraf dist tsconfig.tsbuildinfo",
|
|
16
|
-
"build": "tsc --project tsconfig.json &&
|
|
17
|
+
"build": "tsc --project tsconfig.json && pnpm buildVaccine",
|
|
18
|
+
"buildVaccine": "node esbuild.mjs",
|
|
17
19
|
"instrumenter": "node dist/src/main.js",
|
|
18
|
-
"test": "
|
|
20
|
+
"test": "pnpm build && NODE_OPTIONS='--experimental-vm-modules --max-old-space-size=8192' jest --forceExit --coverage --silent=true --detectOpenHandles"
|
|
19
21
|
},
|
|
20
22
|
"files": [
|
|
21
23
|
"dist/**/*"
|
|
22
24
|
],
|
|
23
25
|
"devDependencies": {
|
|
24
|
-
"@babel/core": "^7.
|
|
25
|
-
"@babel/plugin-transform-modules-commonjs": "^7.
|
|
26
|
-
"@babel/preset-env": "^7.
|
|
27
|
-
"@types/
|
|
28
|
-
"@types/
|
|
29
|
-
"@types/
|
|
30
|
-
"@types/
|
|
31
|
-
"@types/
|
|
32
|
-
"@types/
|
|
33
|
-
"@types/
|
|
34
|
-
"@types/
|
|
35
|
-
"@types/
|
|
36
|
-
"
|
|
37
|
-
"
|
|
26
|
+
"@babel/core": "^7.23.2",
|
|
27
|
+
"@babel/plugin-transform-modules-commonjs": "^7.23.0",
|
|
28
|
+
"@babel/preset-env": "^7.23.2",
|
|
29
|
+
"@types/argparse": "^2.0.12",
|
|
30
|
+
"@types/async": "^3.2.22",
|
|
31
|
+
"@types/babel__generator": "^7.6.6",
|
|
32
|
+
"@types/babel__traverse": "^7.20.3",
|
|
33
|
+
"@types/bunyan": "^1.8.10",
|
|
34
|
+
"@types/convert-source-map": "^2.0.2",
|
|
35
|
+
"@types/glob": "^8.1.0",
|
|
36
|
+
"@types/istanbul-lib-instrument": "^1.7.6",
|
|
37
|
+
"@types/jest": "^29.5.6",
|
|
38
|
+
"@types/node": "^20.8.6",
|
|
39
|
+
"@types/ws": "^8.5.7",
|
|
40
|
+
"babel-jest": "^29.7.0",
|
|
41
|
+
"esbuild": "^0.19.5",
|
|
38
42
|
"esbuild-plugin-inline-worker": "^0.1.1",
|
|
39
|
-
"jest": "^
|
|
40
|
-
"rimraf": "^
|
|
41
|
-
"ts-jest": "^
|
|
42
|
-
"ts-node": "^10.
|
|
43
|
-
"tslib": "^2.2
|
|
44
|
-
"typescript": "^
|
|
43
|
+
"jest": "^29.7.0",
|
|
44
|
+
"rimraf": "^5.0.5",
|
|
45
|
+
"ts-jest": "^29.1.1",
|
|
46
|
+
"ts-node": "^10.9.1",
|
|
47
|
+
"tslib": "^2.6.2",
|
|
48
|
+
"typescript": "^5.2.2"
|
|
45
49
|
},
|
|
46
50
|
"dependencies": {
|
|
47
|
-
"@cqse/commons": "
|
|
48
|
-
"@
|
|
51
|
+
"@cqse/commons": "0.0.1-beta.59",
|
|
52
|
+
"@teamscale/lib-instrument": "workspace:../lib-instrument",
|
|
53
|
+
"@babel/generator": "^7.23.0",
|
|
54
|
+
"@babel/parser": "^7.23.0",
|
|
55
|
+
"@babel/traverse": "^7.23.2",
|
|
56
|
+
"@babel/types": "^7.23.0",
|
|
57
|
+
"@types/micromatch": "^4.0.3",
|
|
49
58
|
"argparse": "^2.0.1",
|
|
50
|
-
"async": "^3.2.
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"micromatch": "4.0.
|
|
56
|
-
"mkdirp": "^
|
|
57
|
-
"
|
|
58
|
-
"source-map": "0.6.1",
|
|
59
|
+
"async": "^3.2.4",
|
|
60
|
+
"bunyan": "^1.8.15",
|
|
61
|
+
"convert-source-map": "^2.0.0",
|
|
62
|
+
"foreground-child": "^3.1.1",
|
|
63
|
+
"glob": "^10.3.10",
|
|
64
|
+
"micromatch": "4.0.5",
|
|
65
|
+
"mkdirp": "^3.0.1",
|
|
66
|
+
"source-map": "0.7.4",
|
|
59
67
|
"typescript-optional": "^2.0.1",
|
|
60
|
-
"unload": "^2.
|
|
61
|
-
"web-worker": "^1.
|
|
62
|
-
"winston": "^3.3.3"
|
|
68
|
+
"unload": "^2.4.1",
|
|
69
|
+
"web-worker": "^1.2.0"
|
|
63
70
|
},
|
|
64
71
|
"publishConfig": {
|
|
65
72
|
"access": "public"
|
package/dist/src/App.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { TaskResult } from './instrumenter/Task';
|
|
2
2
|
import { ConfigurationParameters } from './instrumenter/TaskBuilder';
|
|
3
|
-
import
|
|
3
|
+
import Logger from 'bunyan';
|
|
4
4
|
/**
|
|
5
5
|
* Entry points of the instrumenter, including command line argument parsing.
|
|
6
6
|
*/
|
|
@@ -10,6 +10,11 @@ export declare class App {
|
|
|
10
10
|
* Parses the command line options and the instrumentation accordingly.
|
|
11
11
|
*/
|
|
12
12
|
static run(): Promise<TaskResult>;
|
|
13
|
+
/**
|
|
14
|
+
* Sometimes we get inputs from shell environments where the strings are
|
|
15
|
+
* still quoted. We remove those here.
|
|
16
|
+
*/
|
|
17
|
+
static postprocessConfig(config: ConfigurationParameters): void;
|
|
13
18
|
/**
|
|
14
19
|
* Build the command line argument parser.
|
|
15
20
|
*/
|
package/dist/src/App.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"App.d.ts","sourceRoot":"","sources":["../../src/App.ts"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"App.d.ts","sourceRoot":"","sources":["../../src/App.ts"],"names":[],"mappings":"AACA,OAAO,EAA0C,UAAU,EAAC,MAAM,qBAAqB,CAAC;AAGxF,OAAO,EAAE,uBAAuB,EAAe,MAAM,4BAA4B,CAAC;AAKlF,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B;;GAEG;AACH,qBAAa,GAAG;IACf;;;OAGG;WACiB,GAAG,IAAI,OAAO,CAAC,UAAU,CAAC;IAe9C;;;OAGG;WACW,iBAAiB,CAAC,MAAM,EAAE,uBAAuB,GAAG,IAAI;IAwCtE;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,WAAW;IAyC1B;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,WAAW;IA+B1B;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,gBAAgB;IAI/B;;;;;OAKG;WACW,qBAAqB,CAAC,MAAM,EAAE,uBAAuB,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;IAS1G,OAAO,CAAC,MAAM,CAAC,yBAAyB;IAIxC,OAAO,CAAC,MAAM,CAAC,kBAAkB;CAajC"}
|
package/dist/src/App.js
CHANGED
|
@@ -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.
|
|
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];
|
|
@@ -29,8 +33,9 @@ const commons_1 = require("@cqse/commons");
|
|
|
29
33
|
const TaskBuilder_1 = require("./instrumenter/TaskBuilder");
|
|
30
34
|
const path = __importStar(require("path"));
|
|
31
35
|
const package_json_1 = require("../package.json");
|
|
32
|
-
const winston_1 = __importDefault(require("winston"));
|
|
33
36
|
const fs_1 = require("fs");
|
|
37
|
+
const mkdirp_1 = require("mkdirp");
|
|
38
|
+
const bunyan_1 = __importDefault(require("bunyan"));
|
|
34
39
|
/**
|
|
35
40
|
* Entry points of the instrumenter, including command line argument parsing.
|
|
36
41
|
*/
|
|
@@ -46,9 +51,55 @@ class App {
|
|
|
46
51
|
const config = parser.parse_args();
|
|
47
52
|
// Build the logger
|
|
48
53
|
const logger = this.buildLogger(config);
|
|
54
|
+
logger.debug('Retrieved arguments', process.argv);
|
|
55
|
+
logger.debug('Translated arguments to config', config);
|
|
49
56
|
// Run the instrumenter with the given configuration.
|
|
50
57
|
return this.runForConfigArguments(config, logger);
|
|
51
58
|
}
|
|
59
|
+
/**
|
|
60
|
+
* Sometimes we get inputs from shell environments where the strings are
|
|
61
|
+
* still quoted. We remove those here.
|
|
62
|
+
*/
|
|
63
|
+
static postprocessConfig(config) {
|
|
64
|
+
function unquoteString(originalString) {
|
|
65
|
+
if (originalString === undefined) {
|
|
66
|
+
return originalString;
|
|
67
|
+
}
|
|
68
|
+
const result = originalString.replace(/^["'](.+(?=["']$))["']$/, '$1');
|
|
69
|
+
if (result === originalString) {
|
|
70
|
+
return result;
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
return unquoteString(result);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
function unquoteStringElements(originalArray) {
|
|
77
|
+
if (originalArray === undefined) {
|
|
78
|
+
return undefined;
|
|
79
|
+
}
|
|
80
|
+
return originalArray.map(s => {
|
|
81
|
+
if (typeof s === 'string') {
|
|
82
|
+
return unquoteString(s);
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
return s;
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
for (const [property, value] of Object.entries(config)) {
|
|
90
|
+
if (value === undefined) {
|
|
91
|
+
// In case the value is 'undefined' we can ignore this.
|
|
92
|
+
}
|
|
93
|
+
else if (typeof value === 'string') {
|
|
94
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
95
|
+
config[property] = unquoteString(value);
|
|
96
|
+
}
|
|
97
|
+
else if (Array.isArray(value)) {
|
|
98
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
99
|
+
config[property] = unquoteStringElements(value);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
52
103
|
/**
|
|
53
104
|
* Build the command line argument parser.
|
|
54
105
|
*/
|
|
@@ -69,14 +120,23 @@ class App {
|
|
|
69
120
|
help: 'External location of source-map files to consider.'
|
|
70
121
|
});
|
|
71
122
|
parser.add_argument('-c', '--collector', {
|
|
72
|
-
help: 'The collector (host:port) to send coverage information to.',
|
|
73
|
-
default: 'localhost:54678'
|
|
123
|
+
help: 'The collector (`host:port` or `wss://host:port/` or `ws://host:port/`) to send coverage information to.',
|
|
124
|
+
default: 'ws://localhost:54678'
|
|
74
125
|
});
|
|
75
126
|
parser.add_argument('-x', '--exclude-origin', {
|
|
76
|
-
|
|
127
|
+
nargs: '*',
|
|
128
|
+
help: 'Glob pattern(s) of files in the source origin to not produce coverage for. Multiple patterns can be separated by space.'
|
|
77
129
|
});
|
|
78
130
|
parser.add_argument('-k', '--include-origin', {
|
|
79
|
-
|
|
131
|
+
nargs: '*',
|
|
132
|
+
help: 'Glob pattern(s) of files in the source origin to produce coverage for. Multiple patterns can be separated by space.'
|
|
133
|
+
});
|
|
134
|
+
parser.add_argument('-e', '--exclude-bundle', {
|
|
135
|
+
nargs: '*',
|
|
136
|
+
help: 'Glob pattern(s) of input (bundle) files to keep unchanged (to not instrument).'
|
|
137
|
+
});
|
|
138
|
+
parser.add_argument('-p', '--dump-origins-to', {
|
|
139
|
+
help: 'Optional location specifying where to dump possible origins from the source map as a json file'
|
|
80
140
|
});
|
|
81
141
|
parser.add_argument('inputs', { nargs: '+', help: 'The input file(s) to instrument.' });
|
|
82
142
|
return parser;
|
|
@@ -85,14 +145,26 @@ class App {
|
|
|
85
145
|
* Construct the logger.
|
|
86
146
|
*/
|
|
87
147
|
static buildLogger(config) {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
148
|
+
const logfilePath = 'logs/instrumenter.log';
|
|
149
|
+
mkdirp_1.mkdirp.sync(path.dirname(logfilePath));
|
|
150
|
+
const logLevel = config.debug ? 'debug' : 'error';
|
|
151
|
+
return bunyan_1.default.createLogger({
|
|
152
|
+
name: 'Instrumenter',
|
|
153
|
+
streams: [
|
|
154
|
+
{
|
|
155
|
+
level: logLevel,
|
|
156
|
+
stream: {
|
|
157
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
158
|
+
write: (rec) => {
|
|
159
|
+
console.log('[%s] %s: %s', rec.time.toISOString(), bunyan_1.default.nameFromLevel[rec.level], rec.msg);
|
|
160
|
+
}
|
|
161
|
+
},
|
|
162
|
+
type: 'raw'
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
level: logLevel,
|
|
166
|
+
path: logfilePath
|
|
167
|
+
}
|
|
96
168
|
]
|
|
97
169
|
});
|
|
98
170
|
}
|
|
@@ -100,12 +172,7 @@ class App {
|
|
|
100
172
|
* A logger for testing.
|
|
101
173
|
*/
|
|
102
174
|
static buildDummyLogger() {
|
|
103
|
-
return
|
|
104
|
-
level: 'info',
|
|
105
|
-
format: winston_1.default.format.json(),
|
|
106
|
-
defaultMeta: {},
|
|
107
|
-
transports: [new winston_1.default.transports.Console({ format: winston_1.default.format.simple(), level: 'info' })]
|
|
108
|
-
});
|
|
175
|
+
return bunyan_1.default.createLogger({ name: 'Instrumenter' });
|
|
109
176
|
}
|
|
110
177
|
/**
|
|
111
178
|
* The instrumenter can also be started by providing the configuration dictionary explicitly.
|
|
@@ -114,14 +181,15 @@ class App {
|
|
|
114
181
|
* @param logger - The logger to use.
|
|
115
182
|
*/
|
|
116
183
|
static runForConfigArguments(config, logger) {
|
|
184
|
+
this.postprocessConfig(config);
|
|
117
185
|
const task = this.createInstrumentationTask(config);
|
|
118
186
|
commons_1.Contract.require(task.elements.length > 0, 'The instrumentation task must not be empty.');
|
|
119
|
-
return this.createInstrumenter(logger !== null && logger !== void 0 ? logger : this.buildDummyLogger()).instrument(task);
|
|
187
|
+
return this.createInstrumenter(logger !== null && logger !== void 0 ? logger : this.buildDummyLogger(), task.collector).instrument(task);
|
|
120
188
|
}
|
|
121
189
|
static createInstrumentationTask(config) {
|
|
122
190
|
return new TaskBuilder_1.TaskBuilder().addFromConfig(config).build();
|
|
123
191
|
}
|
|
124
|
-
static createInstrumenter(logger) {
|
|
192
|
+
static createInstrumenter(logger, collector) {
|
|
125
193
|
// We have to deal with two different `__dirname` versions,
|
|
126
194
|
// which depends on whether we run from within the IDE or from
|
|
127
195
|
// the command line:
|
|
@@ -129,10 +197,10 @@ class App {
|
|
|
129
197
|
const pathVariant1 = path.join(__dirname, '../vaccine.js');
|
|
130
198
|
const pathVariant2 = path.join(__dirname, '../dist/vaccine.js');
|
|
131
199
|
if ((0, fs_1.existsSync)(pathVariant1)) {
|
|
132
|
-
return new Instrumenter_1.IstanbulInstrumenter(pathVariant1, logger);
|
|
200
|
+
return new Instrumenter_1.IstanbulInstrumenter(pathVariant1, logger, collector);
|
|
133
201
|
}
|
|
134
202
|
else {
|
|
135
|
-
return new Instrumenter_1.IstanbulInstrumenter(pathVariant2, logger);
|
|
203
|
+
return new Instrumenter_1.IstanbulInstrumenter(pathVariant2, logger, collector);
|
|
136
204
|
}
|
|
137
205
|
}
|
|
138
206
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { RawSourceMap } from 'source-map';
|
|
1
2
|
/**
|
|
2
3
|
* Does the given `path` point to an existing file?
|
|
3
4
|
*/
|
|
@@ -10,6 +11,10 @@ export declare function isExistingDirectory(path: string): boolean;
|
|
|
10
11
|
* Ensure that the given directory `path` exists.
|
|
11
12
|
*/
|
|
12
13
|
export declare function ensureExistingDirectory(path: string): void;
|
|
14
|
+
/**
|
|
15
|
+
* Given a root folder find a folder with a given name.
|
|
16
|
+
*/
|
|
17
|
+
export declare function findSubFolders(startFromFolder: string, folderName: string): string[];
|
|
13
18
|
/**
|
|
14
19
|
* Is the given directory empty?
|
|
15
20
|
*/
|
|
@@ -20,4 +25,10 @@ export declare function isDirectoryEmpty(path: string): boolean;
|
|
|
20
25
|
* @param toExpand - The Glob pattern.
|
|
21
26
|
*/
|
|
22
27
|
export declare function expandToFileSet(toExpand: string): string[];
|
|
28
|
+
/**
|
|
29
|
+
* Read a source map from a source map file.
|
|
30
|
+
*
|
|
31
|
+
* @param mapFilePath
|
|
32
|
+
*/
|
|
33
|
+
export declare function sourceMapFromMapFile(mapFilePath: string): RawSourceMap | undefined;
|
|
23
34
|
//# 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":"AAKA,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE1C;;GAEG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEpD;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEzD;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAU1D;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,eAAe,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,EAAE,CAgBpF;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEtD;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,CAc1D;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,WAAW,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS,CAGlF"}
|