Skip to content

Commit c49a6a3

Browse files
author
Angular Builds
committed
86e031d fix(@angular-devkit/build-angular): use istanbul-lib-instrument directly for karma code coverage
1 parent d679943 commit c49a6a3

File tree

7 files changed

+90
-16
lines changed

7 files changed

+90
-16
lines changed

package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
{
22
"name": "@angular-devkit/build-angular",
3-
"version": "18.0.4+sha-bdd168f",
3+
"version": "18.0.4+sha-86e031d",
44
"description": "Angular Webpack Build Facade",
55
"main": "src/index.js",
66
"typings": "src/index.d.ts",
77
"builders": "builders.json",
88
"dependencies": {
99
"@ampproject/remapping": "2.3.0",
10-
"@angular/build": "github:angular/angular-build-builds#bdd168f",
11-
"@angular-devkit/architect": "github:angular/angular-devkit-architect-builds#bdd168f",
12-
"@angular-devkit/build-webpack": "github:angular/angular-devkit-build-webpack-builds#bdd168f",
13-
"@angular-devkit/core": "github:angular/angular-devkit-core-builds#bdd168f",
10+
"@angular/build": "github:angular/angular-build-builds#86e031d",
11+
"@angular-devkit/architect": "github:angular/angular-devkit-architect-builds#86e031d",
12+
"@angular-devkit/build-webpack": "github:angular/angular-devkit-build-webpack-builds#86e031d",
13+
"@angular-devkit/core": "github:angular/angular-devkit-core-builds#86e031d",
1414
"@babel/core": "7.24.5",
1515
"@babel/generator": "7.24.5",
1616
"@babel/helper-annotate-as-pure": "7.22.5",
@@ -21,12 +21,11 @@
2121
"@babel/preset-env": "7.24.5",
2222
"@babel/runtime": "7.24.5",
2323
"@discoveryjs/json-ext": "0.5.7",
24-
"@ngtools/webpack": "github:angular/ngtools-webpack-builds#bdd168f",
24+
"@ngtools/webpack": "github:angular/ngtools-webpack-builds#86e031d",
2525
"@vitejs/plugin-basic-ssl": "1.1.0",
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": "11.0.0",
3231
"critters": "0.0.22",
@@ -36,6 +35,7 @@
3635
"https-proxy-agent": "7.0.4",
3736
"http-proxy-middleware": "3.0.0",
3837
"inquirer": "9.2.22",
38+
"istanbul-lib-instrument": "6.0.2",
3939
"jsonc-parser": "3.2.1",
4040
"karma-source-map-support": "1.4.0",
4141
"less": "4.2.0",
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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+
/// <reference path="../../../../../../../../../../packages/angular_devkit/build_angular/src/babel-bazel.d.ts" />
9+
/// <reference types="@angular/compiler-cli/private/babel" />
10+
import { PluginObj } from '@babel/core';
11+
/**
12+
* A babel plugin factory function for adding istanbul instrumentation.
13+
*
14+
* @returns A babel plugin object instance.
15+
*/
16+
export default function (): PluginObj;
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
"use strict";
2+
/**
3+
* @license
4+
* Copyright Google LLC All Rights Reserved.
5+
*
6+
* Use of this source code is governed by an MIT-style license that can be
7+
* found in the LICENSE file at https://angular.dev/license
8+
*/
9+
var __importDefault = (this && this.__importDefault) || function (mod) {
10+
return (mod && mod.__esModule) ? mod : { "default": mod };
11+
};
12+
Object.defineProperty(exports, "__esModule", { value: true });
13+
const core_1 = require("@babel/core");
14+
const istanbul_lib_instrument_1 = require("istanbul-lib-instrument");
15+
const node_assert_1 = __importDefault(require("node:assert"));
16+
/**
17+
* A babel plugin factory function for adding istanbul instrumentation.
18+
*
19+
* @returns A babel plugin object instance.
20+
*/
21+
function default_1() {
22+
const visitors = new WeakMap();
23+
return {
24+
visitor: {
25+
Program: {
26+
enter(path, state) {
27+
const visitor = (0, istanbul_lib_instrument_1.programVisitor)(core_1.types, state.filename, {
28+
// Babel returns a Converter object from the `convert-source-map` package
29+
inputSourceMap: state.file.inputMap?.toObject(),
30+
});
31+
visitors.set(path, visitor);
32+
visitor.enter(path);
33+
},
34+
exit(path) {
35+
const visitor = visitors.get(path);
36+
(0, node_assert_1.default)(visitor, 'Instrumentation visitor should always be present for program path.');
37+
visitor.exit(path);
38+
visitors.delete(path);
39+
},
40+
},
41+
},
42+
};
43+
}
44+
exports.default = default_1;

src/tools/babel/plugins/types.d.ts

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+
}

src/tools/babel/presets/application.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -157,13 +157,7 @@ function default_1(api, options) {
157157
]);
158158
}
159159
if (options.instrumentCode) {
160-
plugins.push([
161-
require('babel-plugin-istanbul').default,
162-
{
163-
inputSourceMap: options.instrumentCode.inputSourceMap ?? false,
164-
cwd: options.instrumentCode.includedBasePath,
165-
},
166-
]);
160+
plugins.push(require('../plugins/add-code-coverage').default);
167161
}
168162
if (needRuntimeTransform) {
169163
// Babel equivalent to TypeScript's `importHelpers` option

src/utils/normalize-cache.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
1010
exports.normalizeCacheOptions = void 0;
1111
const node_path_1 = require("node:path");
1212
/** Version placeholder is replaced during the build process with actual package version */
13-
const VERSION = '18.0.4+sha-bdd168f';
13+
const VERSION = '18.0.4+sha-86e031d';
1414
function hasCacheMetadata(value) {
1515
return (!!value &&
1616
typeof value === 'object' &&

uniqueId

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Tue Jun 18 2024 14:02:34 GMT+0000 (Coordinated Universal Time)
1+
Tue Jun 18 2024 14:18:34 GMT+0000 (Coordinated Universal Time)

0 commit comments

Comments
 (0)