Skip to content

Commit ec42935

Browse files
committed
feat(@angular/build): move istanbul-lib-instrument to optional peer dependency
Move `istanbul-lib-instrument` from dependencies to optional peer dependencies. This helps reduce the transitive dependency count for new projects. BREAKING CHANGE: `istanbul-lib-instrument` is now an optional peer dependency. Projects using karma with code coverage enabled will need to ensure that istanbul-lib-instrument is installed. Note: `ng update` will automatically add this dependency during the update process.
1 parent 7fbc715 commit ec42935

File tree

4 files changed

+24
-8
lines changed

4 files changed

+24
-8
lines changed

packages/angular/build/package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
"browserslist": "^4.26.0",
3030
"esbuild": "0.27.3",
3131
"https-proxy-agent": "8.0.0",
32-
"istanbul-lib-instrument": "6.0.3",
3332
"jsonc-parser": "3.3.1",
3433
"listr2": "10.2.1",
3534
"magic-string": "0.30.21",
@@ -51,6 +50,7 @@
5150
"devDependencies": {
5251
"@angular-devkit/core": "workspace:*",
5352
"@angular/ssr": "workspace:*",
53+
"istanbul-lib-instrument": "6.0.3",
5454
"jsdom": "29.0.1",
5555
"less": "4.6.4",
5656
"ng-packagr": "22.0.0-next.1",
@@ -67,6 +67,7 @@
6767
"@angular/platform-server": "0.0.0-ANGULAR-FW-PEER-DEP",
6868
"@angular/service-worker": "0.0.0-ANGULAR-FW-PEER-DEP",
6969
"@angular/ssr": "^0.0.0-PLACEHOLDER",
70+
"istanbul-lib-instrument": "^6.0.0",
7071
"karma": "^6.4.0",
7172
"less": "^4.2.0",
7273
"ng-packagr": "0.0.0-NG-PACKAGR-PEER-DEP",
@@ -95,6 +96,9 @@
9596
"@angular/ssr": {
9697
"optional": true
9798
},
99+
"istanbul-lib-instrument": {
100+
"optional": true
101+
},
98102
"karma": {
99103
"optional": true
100104
},

packages/angular/build/src/tools/babel/plugins/add-code-coverage.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,17 @@
77
*/
88

99
import { NodePath, PluginObj, types } from '@babel/core';
10-
import { Visitor, programVisitor } from 'istanbul-lib-instrument';
10+
import type { Visitor } from 'istanbul-lib-instrument';
1111
import assert from 'node:assert';
1212

1313
/**
1414
* A babel plugin factory function for adding istanbul instrumentation.
1515
*
1616
* @returns A babel plugin object instance.
1717
*/
18-
export default function (): PluginObj {
18+
export default function (
19+
programVisitor: typeof import('istanbul-lib-instrument').programVisitor,
20+
): PluginObj {
1921
const visitors = new WeakMap<NodePath, Visitor>();
2022

2123
return {

packages/angular/build/src/tools/esbuild/javascript-transformer-worker.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,18 @@ async function transformWithBabel(
6666
const plugins: PluginItem[] = [];
6767

6868
if (options.instrumentForCoverage) {
69-
const { default: coveragePlugin } = await import('../babel/plugins/add-code-coverage.js');
70-
plugins.push(coveragePlugin);
69+
try {
70+
const { programVisitor } = await import('istanbul-lib-instrument');
71+
const { default: coveragePluginFactory } = await import(
72+
'../babel/plugins/add-code-coverage.js'
73+
);
74+
plugins.push(coveragePluginFactory(programVisitor));
75+
} catch {
76+
throw new Error(
77+
"The 'istanbul-lib-instrument' package is required for code coverage but was not found. " +
78+
'Please install it.',
79+
);
80+
}
7181
}
7282

7383
if (shouldLink) {

pnpm-lock.yaml

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)