Skip to content

Commit fb2981d

Browse files
clydinalan-agius4
authored andcommitted
fix(@angular-devkit/build-angular): use istanbul-lib-instrument directly for karma code coverage
The `istanbul-lib-instrument` package provides the required functionality needed to instrument code for test coverage within the context of the Angular CLI. Since the build pipeline already contains a customized babel preset, this package can be integrated directly into the pipeline. This reduces the number of dependencies required for `@angular-devkit/build-angular` including the deprecated `inflight` package.
1 parent e3b8b78 commit fb2981d

File tree

7 files changed

+96
-78
lines changed

7 files changed

+96
-78
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@
122122
"ansi-colors": "4.1.3",
123123
"autoprefixer": "10.4.19",
124124
"babel-loader": "9.1.3",
125-
"babel-plugin-istanbul": "6.1.1",
126125
"browser-sync": "3.0.2",
127126
"browserslist": "^4.21.5",
128127
"buffer": "6.0.3",
@@ -144,6 +143,7 @@
144143
"https-proxy-agent": "7.0.4",
145144
"husky": "9.0.11",
146145
"ini": "4.1.3",
146+
"istanbul-lib-instrument": "6.0.2",
147147
"jasmine": "^5.0.0",
148148
"jasmine-core": "~5.1.0",
149149
"jasmine-spec-reporter": "~7.0.0",

packages/angular_devkit/build_angular/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,6 @@ ts_library(
161161
"@npm//ansi-colors",
162162
"@npm//autoprefixer",
163163
"@npm//babel-loader",
164-
"@npm//babel-plugin-istanbul",
165164
"@npm//browserslist",
166165
"@npm//copy-webpack-plugin",
167166
"@npm//critters",
@@ -171,6 +170,7 @@ ts_library(
171170
"@npm//fast-glob",
172171
"@npm//http-proxy-middleware",
173172
"@npm//https-proxy-agent",
173+
"@npm//istanbul-lib-instrument",
174174
"@npm//jsonc-parser",
175175
"@npm//karma",
176176
"@npm//karma-source-map-support",

packages/angular_devkit/build_angular/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
"ansi-colors": "4.1.3",
2727
"autoprefixer": "10.4.19",
2828
"babel-loader": "9.1.3",
29-
"babel-plugin-istanbul": "6.1.1",
3029
"browserslist": "^4.21.5",
3130
"copy-webpack-plugin": "12.0.2",
3231
"critters": "0.0.22",
@@ -35,6 +34,7 @@
3534
"fast-glob": "3.3.2",
3635
"http-proxy-middleware": "3.0.0",
3736
"https-proxy-agent": "7.0.4",
37+
"istanbul-lib-instrument": "6.0.2",
3838
"jsonc-parser": "3.2.1",
3939
"karma-source-map-support": "1.4.0",
4040
"less": "4.2.0",
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.dev/license
7+
*/
8+
9+
import { NodePath, PluginObj, types } from '@babel/core';
10+
import { Visitor, programVisitor } from 'istanbul-lib-instrument';
11+
import assert from 'node:assert';
12+
13+
/**
14+
* A babel plugin factory function for adding istanbul instrumentation.
15+
*
16+
* @returns A babel plugin object instance.
17+
*/
18+
export default function (): PluginObj {
19+
const visitors = new WeakMap<NodePath, Visitor>();
20+
21+
return {
22+
visitor: {
23+
Program: {
24+
enter(path, state) {
25+
const visitor = programVisitor(types, state.filename, {
26+
// Babel returns a Converter object from the `convert-source-map` package
27+
inputSourceMap: (state.file.inputMap as undefined | { toObject(): object })?.toObject(),
28+
});
29+
visitors.set(path, visitor);
30+
31+
visitor.enter(path);
32+
},
33+
exit(path) {
34+
const visitor = visitors.get(path);
35+
assert(visitor, 'Instrumentation visitor should always be present for program path.');
36+
37+
visitor.exit(path);
38+
visitors.delete(path);
39+
},
40+
},
41+
},
42+
};
43+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.dev/license
7+
*/
8+
9+
declare module 'istanbul-lib-instrument' {
10+
export interface Visitor {
11+
enter(path: import('@babel/core').NodePath<types.Program>): void;
12+
exit(path: import('@babel/core').NodePath<types.Program>): void;
13+
}
14+
15+
export function programVisitor(
16+
types: typeof import('@babel/core').types,
17+
filePath?: string,
18+
options?: { inputSourceMap?: object | null },
19+
): Visitor;
20+
}

packages/angular_devkit/build_angular/src/tools/babel/presets/application.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -265,13 +265,7 @@ export default function (api: unknown, options: ApplicationPresetOptions) {
265265
}
266266

267267
if (options.instrumentCode) {
268-
plugins.push([
269-
require('babel-plugin-istanbul').default,
270-
{
271-
inputSourceMap: options.instrumentCode.inputSourceMap ?? false,
272-
cwd: options.instrumentCode.includedBasePath,
273-
},
274-
]);
268+
plugins.push(require('../plugins/add-code-coverage').default);
275269
}
276270

277271
if (needRuntimeTransform) {

yarn.lock

Lines changed: 29 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ __metadata:
8484
ansi-colors: "npm:4.1.3"
8585
autoprefixer: "npm:10.4.19"
8686
babel-loader: "npm:9.1.3"
87-
babel-plugin-istanbul: "npm:6.1.1"
8887
browserslist: "npm:^4.21.5"
8988
copy-webpack-plugin: "npm:12.0.2"
9089
critters: "npm:0.0.22"
@@ -94,6 +93,7 @@ __metadata:
9493
fast-glob: "npm:3.3.2"
9594
http-proxy-middleware: "npm:3.0.0"
9695
https-proxy-agent: "npm:7.0.4"
96+
istanbul-lib-instrument: "npm:6.0.2"
9797
jsonc-parser: "npm:3.2.1"
9898
karma-source-map-support: "npm:1.4.0"
9999
less: "npm:4.2.0"
@@ -689,7 +689,6 @@ __metadata:
689689
ansi-colors: "npm:4.1.3"
690690
autoprefixer: "npm:10.4.19"
691691
babel-loader: "npm:9.1.3"
692-
babel-plugin-istanbul: "npm:6.1.1"
693692
browser-sync: "npm:3.0.2"
694693
browserslist: "npm:^4.21.5"
695694
buffer: "npm:6.0.3"
@@ -711,6 +710,7 @@ __metadata:
711710
https-proxy-agent: "npm:7.0.4"
712711
husky: "npm:9.0.11"
713712
ini: "npm:4.1.3"
713+
istanbul-lib-instrument: "npm:6.0.2"
714714
jasmine: "npm:^5.0.0"
715715
jasmine-core: "npm:~5.1.0"
716716
jasmine-spec-reporter: "npm:~7.0.0"
@@ -1019,7 +1019,7 @@ __metadata:
10191019
languageName: node
10201020
linkType: hard
10211021

1022-
"@babel/core@npm:7.24.7, @babel/core@npm:^7.12.3, @babel/core@npm:^7.16.0":
1022+
"@babel/core@npm:7.24.7, @babel/core@npm:^7.12.3, @babel/core@npm:^7.16.0, @babel/core@npm:^7.23.9":
10231023
version: 7.24.7
10241024
resolution: "@babel/core@npm:7.24.7"
10251025
dependencies:
@@ -1322,7 +1322,7 @@ __metadata:
13221322
languageName: node
13231323
linkType: hard
13241324

1325-
"@babel/parser@npm:^7.1.0, @babel/parser@npm:^7.14.7, @babel/parser@npm:^7.20.7, @babel/parser@npm:^7.24.7":
1325+
"@babel/parser@npm:^7.1.0, @babel/parser@npm:^7.14.7, @babel/parser@npm:^7.20.7, @babel/parser@npm:^7.23.9, @babel/parser@npm:^7.24.7":
13261326
version: 7.24.7
13271327
resolution: "@babel/parser@npm:7.24.7"
13281328
bin:
@@ -3297,20 +3297,7 @@ __metadata:
32973297
languageName: node
32983298
linkType: hard
32993299

3300-
"@istanbuljs/load-nyc-config@npm:^1.0.0":
3301-
version: 1.1.0
3302-
resolution: "@istanbuljs/load-nyc-config@npm:1.1.0"
3303-
dependencies:
3304-
camelcase: "npm:^5.3.1"
3305-
find-up: "npm:^4.1.0"
3306-
get-package-type: "npm:^0.1.0"
3307-
js-yaml: "npm:^3.13.1"
3308-
resolve-from: "npm:^5.0.0"
3309-
checksum: 10c0/dd2a8b094887da5a1a2339543a4933d06db2e63cbbc2e288eb6431bd832065df0c099d091b6a67436e71b7d6bf85f01ce7c15f9253b4cbebcc3b9a496165ba42
3310-
languageName: node
3311-
linkType: hard
3312-
3313-
"@istanbuljs/schema@npm:^0.1.2":
3300+
"@istanbuljs/schema@npm:^0.1.2, @istanbuljs/schema@npm:^0.1.3":
33143301
version: 0.1.3
33153302
resolution: "@istanbuljs/schema@npm:0.1.3"
33163303
checksum: 10c0/61c5286771676c9ca3eb2bd8a7310a9c063fb6e0e9712225c8471c582d157392c88f5353581c8c9adbe0dff98892317d2fdfc56c3499aa42e0194405206a963a
@@ -7237,7 +7224,14 @@ __metadata:
72377224
languageName: node
72387225
linkType: hard
72397226

7240-
"argparse@npm:^1.0.7, argparse@npm:~1.0.9":
7227+
"argparse@npm:^2.0.1":
7228+
version: 2.0.1
7229+
resolution: "argparse@npm:2.0.1"
7230+
checksum: 10c0/c5640c2d89045371c7cedd6a70212a04e360fd34d6edeae32f6952c63949e3525ea77dbec0289d8213a99bbaeab5abfa860b5c12cf88a2e6cf8106e90dd27a7e
7231+
languageName: node
7232+
linkType: hard
7233+
7234+
"argparse@npm:~1.0.9":
72417235
version: 1.0.10
72427236
resolution: "argparse@npm:1.0.10"
72437237
dependencies:
@@ -7246,13 +7240,6 @@ __metadata:
72467240
languageName: node
72477241
linkType: hard
72487242

7249-
"argparse@npm:^2.0.1":
7250-
version: 2.0.1
7251-
resolution: "argparse@npm:2.0.1"
7252-
checksum: 10c0/c5640c2d89045371c7cedd6a70212a04e360fd34d6edeae32f6952c63949e3525ea77dbec0289d8213a99bbaeab5abfa860b5c12cf88a2e6cf8106e90dd27a7e
7253-
languageName: node
7254-
linkType: hard
7255-
72567243
"array-back@npm:^3.0.1, array-back@npm:^3.1.0":
72577244
version: 3.1.0
72587245
resolution: "array-back@npm:3.1.0"
@@ -7537,19 +7524,6 @@ __metadata:
75377524
languageName: node
75387525
linkType: hard
75397526

7540-
"babel-plugin-istanbul@npm:6.1.1":
7541-
version: 6.1.1
7542-
resolution: "babel-plugin-istanbul@npm:6.1.1"
7543-
dependencies:
7544-
"@babel/helper-plugin-utils": "npm:^7.0.0"
7545-
"@istanbuljs/load-nyc-config": "npm:^1.0.0"
7546-
"@istanbuljs/schema": "npm:^0.1.2"
7547-
istanbul-lib-instrument: "npm:^5.0.4"
7548-
test-exclude: "npm:^6.0.0"
7549-
checksum: 10c0/1075657feb705e00fd9463b329921856d3775d9867c5054b449317d39153f8fbcebd3e02ebf00432824e647faff3683a9ca0a941325ef1afe9b3c4dd51b24beb
7550-
languageName: node
7551-
linkType: hard
7552-
75537527
"babel-plugin-polyfill-corejs2@npm:^0.4.10":
75547528
version: 0.4.11
75557529
resolution: "babel-plugin-polyfill-corejs2@npm:0.4.11"
@@ -8054,7 +8028,7 @@ __metadata:
80548028
languageName: node
80558029
linkType: hard
80568030

8057-
"camelcase@npm:^5.0.0, camelcase@npm:^5.3.1":
8031+
"camelcase@npm:^5.0.0":
80588032
version: 5.3.1
80598033
resolution: "camelcase@npm:5.3.1"
80608034
checksum: 10c0/92ff9b443bfe8abb15f2b1513ca182d16126359ad4f955ebc83dc4ddcc4ef3fdd2c078bc223f2673dc223488e75c99b16cc4d056624374b799e6a1555cf61b23
@@ -10084,7 +10058,7 @@ __metadata:
1008410058
languageName: node
1008510059
linkType: hard
1008610060

10087-
"esprima@npm:^4.0.0, esprima@npm:^4.0.1":
10061+
"esprima@npm:^4.0.1":
1008810062
version: 4.0.1
1008910063
resolution: "esprima@npm:4.0.1"
1009010064
bin:
@@ -10795,13 +10769,6 @@ __metadata:
1079510769
languageName: node
1079610770
linkType: hard
1079710771

10798-
"get-package-type@npm:^0.1.0":
10799-
version: 0.1.0
10800-
resolution: "get-package-type@npm:0.1.0"
10801-
checksum: 10c0/e34cdf447fdf1902a1f6d5af737eaadf606d2ee3518287abde8910e04159368c268568174b2e71102b87b26c2020486f126bfca9c4fb1ceb986ff99b52ecd1be
10802-
languageName: node
10803-
linkType: hard
10804-
1080510772
"get-stream@npm:^5.1.0":
1080610773
version: 5.2.0
1080710774
resolution: "get-stream@npm:5.2.0"
@@ -12149,7 +12116,20 @@ __metadata:
1214912116
languageName: node
1215012117
linkType: hard
1215112118

12152-
"istanbul-lib-instrument@npm:^5.0.4, istanbul-lib-instrument@npm:^5.1.0":
12119+
"istanbul-lib-instrument@npm:6.0.2":
12120+
version: 6.0.2
12121+
resolution: "istanbul-lib-instrument@npm:6.0.2"
12122+
dependencies:
12123+
"@babel/core": "npm:^7.23.9"
12124+
"@babel/parser": "npm:^7.23.9"
12125+
"@istanbuljs/schema": "npm:^0.1.3"
12126+
istanbul-lib-coverage: "npm:^3.2.0"
12127+
semver: "npm:^7.5.4"
12128+
checksum: 10c0/405c6ac037bf8c7ee7495980b0cd5544b2c53078c10534d0c9ceeb92a9ea7dcf8510f58ccfce31336458a8fa6ccef27b570bbb602abaa8c1650f5496a807477c
12129+
languageName: node
12130+
linkType: hard
12131+
12132+
"istanbul-lib-instrument@npm:^5.1.0":
1215312133
version: 5.2.1
1215412134
resolution: "istanbul-lib-instrument@npm:5.2.1"
1215512135
dependencies:
@@ -12331,18 +12311,6 @@ __metadata:
1233112311
languageName: node
1233212312
linkType: hard
1233312313

12334-
"js-yaml@npm:^3.13.1":
12335-
version: 3.14.1
12336-
resolution: "js-yaml@npm:3.14.1"
12337-
dependencies:
12338-
argparse: "npm:^1.0.7"
12339-
esprima: "npm:^4.0.0"
12340-
bin:
12341-
js-yaml: bin/js-yaml.js
12342-
checksum: 10c0/6746baaaeac312c4db8e75fa22331d9a04cccb7792d126ed8ce6a0bbcfef0cedaddd0c5098fade53db067c09fe00aa1c957674b4765610a8b06a5a189e46433b
12343-
languageName: node
12344-
linkType: hard
12345-
1234612314
"jsbn@npm:1.1.0":
1234712315
version: 1.1.0
1234812316
resolution: "jsbn@npm:1.1.0"
@@ -15933,13 +15901,6 @@ __metadata:
1593315901
languageName: node
1593415902
linkType: hard
1593515903

15936-
"resolve-from@npm:^5.0.0":
15937-
version: 5.0.0
15938-
resolution: "resolve-from@npm:5.0.0"
15939-
checksum: 10c0/b21cb7f1fb746de8107b9febab60095187781137fd803e6a59a76d421444b1531b641bba5857f5dc011974d8a5c635d61cec49e6bd3b7fc20e01f0fafc4efbf2
15940-
languageName: node
15941-
linkType: hard
15942-
1594315904
"resolve-path@npm:^1.4.0":
1594415905
version: 1.4.0
1594515906
resolution: "resolve-path@npm:1.4.0"

0 commit comments

Comments
 (0)