-
Notifications
You must be signed in to change notification settings - Fork 1.7k
[html coverage report] Add vendored package + generate HTML report #7528
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 36 commits
731d409
4088b56
e3d52e3
4dae722
d002919
95f8d9a
f3e276f
c77eb8d
7771d9f
029bc26
9be67d5
3a55628
cc5cb6a
1856995
e646399
3047483
c8ea036
39ce891
c6f1e72
f78a224
b28430a
8c92ef9
022c6ae
a50b3b8
0b89710
50f3b4c
f3591e7
d0fba8e
3602408
006f834
f771d34
7724608
9dde2ee
7542cdc
8ed50de
f264363
b26e193
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| "@nomicfoundation/hardhat": minor | ||
| "@nomicfoundation/hardhat-vendored": patch | ||
| --- | ||
|
|
||
| Added HTML coverage reporting and a new internal `hardhat-vendored` package ([7528](https://github.com/NomicFoundation/hardhat/pull/7528)). |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,3 +2,4 @@ ignorePaths: | |
| - .github/config/regression-tests.yml | ||
| - archive/** | ||
| - pnpm-lock.yaml | ||
| - v-next/hardhat-vendored/src | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| # Node modules | ||
| /node_modules | ||
|
|
||
| # Compilation output | ||
| /dist | ||
|
|
||
| # pnpm deploy output | ||
| /bundle | ||
|
|
||
| # test coverage output | ||
| coverage | ||
|
|
||
| # all the tmp folders in the fixture projects | ||
| /test/fixture-projects/tmp/ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| /node_modules | ||
| /dist | ||
| /coverage | ||
| CHANGELOG.md | ||
| /test/fixture-projects/**/artifacts | ||
| /test/fixture-projects/**/cache |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| MIT License | ||
|
|
||
| Copyright (c) 2025 Nomic Foundation | ||
|
|
||
| Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
|
||
| The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
|
||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| # hardhat-vendored | ||
|
|
||
| > ⚠️ This package is an internal Hardhat component and it's not meant to be used directly. | ||
|
|
||
| This package contains vendored code used by Hardhat 3 and its plugins. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| import { createConfig } from "../config/eslint.config.js"; | ||
|
|
||
| export default createConfig(import.meta.filename, { onlyHardhatError: false }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| { | ||
| "name": "@nomicfoundation/hardhat-vendored", | ||
| "version": "3.0.0", | ||
| "description": "Internal dependencies used by Hardhat that have been vendored to prevent bloating the main package", | ||
| "homepage": "https://github.com/nomicfoundation/hardhat/tree/v-next/v-next/hardhat-vendored", | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "https://github.com/NomicFoundation/hardhat", | ||
| "directory": "v-next/hardhat-vendored" | ||
| }, | ||
| "author": "Nomic Foundation", | ||
| "license": "MIT", | ||
| "type": "module", | ||
| "exports": { | ||
| "./coverage": "./dist/src/coverage-module/index.js", | ||
| "./coverage/types": "./dist/src/coverage-module/types.js" | ||
| }, | ||
| "keywords": [ | ||
| "hardhat" | ||
| ], | ||
| "scripts": { | ||
| "lint": "pnpm prettier --check && pnpm eslint", | ||
| "lint:fix": "pnpm prettier --write && pnpm eslint --fix", | ||
| "eslint": "eslint \"src/**/*.ts\" \"test/**/*.ts\"", | ||
| "prettier": "prettier \"**/*.{ts,js,md,json}\"", | ||
| "test": "node --import tsx/esm --test --test-reporter=@nomicfoundation/hardhat-node-test-reporter \"test/*.ts\" \"test/!(fixture-projects|helpers)/**/*.ts\"", | ||
| "test:only": "node --import tsx/esm --test --test-only --test-reporter=@nomicfoundation/hardhat-node-test-reporter \"test/*.ts\" \"test/!(fixture-projects|helpers)/**/*.ts\"", | ||
| "test:coverage": "c8 --reporter html --reporter text --all --exclude test --exclude \"src/**/{types,type-extensions}.ts\" --src src node --import tsx/esm --test --test-reporter=@nomicfoundation/hardhat-node-test-reporter \"test/*.ts\" \"test/!(fixture-projects|helpers)/**/*.ts\"", | ||
| "pretest": "pnpm build", | ||
| "pretest:only": "pnpm build", | ||
| "build": "tsc --build .", | ||
| "postbuild": "node dist/src/copy-assets.js", | ||
| "prepublishOnly": "pnpm build", | ||
| "clean": "rimraf dist" | ||
| }, | ||
| "files": [ | ||
| "dist/src/", | ||
| "src/", | ||
| "CHANGELOG.md", | ||
| "LICENSE", | ||
| "README.md" | ||
| ], | ||
| "devDependencies": { | ||
| "@nomicfoundation/hardhat-node-test-reporter": "workspace:^3.0.0", | ||
| "@types/bn.js": "^5.1.5", | ||
| "@types/debug": "^4.1.7", | ||
| "@types/node": "^20.14.9", | ||
| "c8": "^9.1.0", | ||
| "eslint": "9.25.1", | ||
| "expect-type": "^1.2.1", | ||
| "prettier": "3.2.5", | ||
| "rimraf": "^5.0.5", | ||
| "tsx": "^4.19.3", | ||
| "typescript": "~5.8.0" | ||
| }, | ||
| "dependencies": {} | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| import { cp } from "node:fs/promises"; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function is invoked by the Used to copy the assets folder, which contains the CSS and JS files used to generate the report, into the dist folder after compilation
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm open to better ideas to solve this issue |
||
| import path from "node:path"; | ||
|
|
||
| async function copyFolder(from: string, to: string): Promise<void> { | ||
| const src = path.resolve(from); | ||
| const dest = path.resolve(to); | ||
|
|
||
| await cp(src, dest, { recursive: true, force: true }); | ||
| console.log(`Copied folder from ${src} -> ${dest}`); | ||
| } | ||
|
|
||
| // eslint-disable-next-line no-restricted-syntax -- allow in this post build script | ||
| await copyFolder( | ||
| path.resolve( | ||
| process.cwd(), | ||
| "src", | ||
| "coverage-module", | ||
| "istanbul-reports", | ||
| "lib", | ||
| "html", | ||
| "assets", | ||
| ), | ||
| path.resolve( | ||
| process.cwd(), | ||
| "dist", | ||
| "src", | ||
| "coverage-module", | ||
| "istanbul-reports", | ||
| "lib", | ||
| "html", | ||
| "assets", | ||
| ), | ||
| ); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| const { replace } = ""; | ||
|
|
||
| // escape | ||
| const es = /&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34);/g; | ||
| const ca = /[&<>'"]/g; | ||
|
|
||
| const esca = { | ||
| "&": "&", | ||
| "<": "<", | ||
| ">": ">", | ||
| "'": "'", | ||
| '"': """, | ||
| }; | ||
| const pe = (m) => esca[m]; | ||
|
|
||
| /** | ||
| * Safely escape HTML entities such as `&`, `<`, `>`, `"`, and `'`. | ||
| * @param {string} es the input to safely escape | ||
| * @returns {string} the escaped input, and it **throws** an error if | ||
| * the input type is unexpected, except for boolean and numbers, | ||
| * converted as string. | ||
| */ | ||
| const escape = (es) => replace.call(es, ca, pe); | ||
| exports.escape = escape; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| import libCoverage from "./lib-coverage/index.cjs"; | ||
| export { libCoverage }; | ||
|
|
||
| import libReport from "./lib-report/index.cjs"; | ||
| export { libReport }; | ||
|
|
||
| import reports from "./istanbul-reports/index.cjs"; | ||
| export { reports }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| "use strict"; | ||
| /* | ||
| Copyright 2012-2015, Yahoo Inc. | ||
| Copyrights licensed under the New BSD License. See the accompanying LICENSE file for terms. | ||
| */ | ||
| const path = require("node:path"); | ||
|
|
||
| module.exports = { | ||
| create(name, cfg) { | ||
| cfg = cfg || {}; | ||
| let Cons; | ||
| try { | ||
| Cons = require(path.join(__dirname, "lib", name, "index.cjs")); | ||
| } catch (e) { | ||
| if (e.code !== "MODULE_NOT_FOUND") { | ||
| throw e; | ||
| } | ||
|
|
||
| Cons = require(name); | ||
| } | ||
|
|
||
| return new Cons(cfg); | ||
| }, | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This step is required to copy the
assetsfolder, which contains the CSS and JS files used to generate the report, into thedistfolder after compilation