Skip to content
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

Convert project to use ES modules #29

Merged
merged 4 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
955 changes: 319 additions & 636 deletions dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

28 changes: 25 additions & 3 deletions dist/licenses.txt
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,31 @@ 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.

@friedemannsommer/lcov-parser
MIT
MIT License

Copyright (c) 2023 Friedemann Sommer

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.


@octokit/auth-token
MIT
The MIT License
Expand Down Expand Up @@ -535,9 +560,6 @@ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.


parse-lcov
MIT

sax
ISC
The ISC License
Expand Down
3 changes: 3 additions & 0 deletions dist/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "module"
}
File renamed without changes.
2 changes: 1 addition & 1 deletion dist/src/covered.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as Range from 'drange';
import { default as Range } from 'drange';
export type CoverageFormat = 'lcov' | 'istanbul' | 'cobertura';
type Opts = {
base: string;
Expand Down
1 change: 0 additions & 1 deletion dist/test.d.ts

This file was deleted.

10 changes: 5 additions & 5 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
const eslint = require('@eslint/js');
const tseslint = require('typescript-eslint');
import eslint from '@eslint/js';
import tseslint from 'typescript-eslint';

module.exports = tseslint.config(
export default tseslint.config(
// Global ignores
{
ignores: ["dist/*", 'eslint.config.js', 'jest.config.mjs', 'coverage/*'],
ignores: ["dist/*", 'eslint.config.js', 'jest.config.js']
},
eslint.configs.recommended,
...tseslint.configs.recommendedTypeChecked,
{
languageOptions: {
parserOptions: {
project: true,
tsconfigRootDir: __dirname,
tsconfigRootDir: import.meta.dirname,
},
},
},
Expand Down
9 changes: 9 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export default {
extensionsToTreatAsEsm: [".ts", ".tsx", ".mts"],
transform: {
"^.+\\.m?[tj]sx?$": [
"ts-jest",
{ useESM: true, isolatedModules: true, diagnostics: false },
],
},
};
13 changes: 0 additions & 13 deletions jest.config.mjs

This file was deleted.

18 changes: 10 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "annotate-uncovered-lines-action",
"version": "3.2.0",
"main": "dist/index.js",
"type": "module",
"author": "Smartly.io Solutions Oy",
"license": "MIT",
"scripts": {
Expand All @@ -14,16 +15,16 @@
"prebundle": "npm run clean",
"bundle": "ncc build src/index.ts --source-map --license licenses.txt --target es2022",
"pretest": "npm run fixture:setup",
"test": "jest",
"test": "NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" jest",
"typecheck": "tsc --noEmit",
"version": "npm run bundle && git add -f -- dist/index.js"
},
"dependencies": {
"@actions/core": "^1.10.1",
"@actions/github": "^6.0.0",
"@cvrg-report/cobertura-json": "^0.1.3",
"drange": "2.0.1",
"parse-lcov": "^1.0.4"
"@friedemannsommer/lcov-parser": "^3.1.1",
"drange": "2.0.1"
},
"devDependencies": {
"@eslint/js": "^8.57.0",
Expand Down
14 changes: 12 additions & 2 deletions src/cobertura-json.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
declare module '@cvrg-report/cobertura-json' {
import { LCOVRecord } from 'parse-lcov';
export function parseContent(content: string): Promise<LCOVRecord[]>;
export function parseContent(content: string): Promise<
{
title: string;
file: string;
lines: {
details: {
line: number;
hit: number;
}[];
};
}[]
>;
}
29 changes: 18 additions & 11 deletions src/covered.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { readFile } from 'fs/promises';
import * as child from 'child_process';
import * as pathFs from 'path';
import * as Range from 'drange';
import * as assert from 'assert';
import parseLCOV, { LCOVRecord } from 'parse-lcov';
import { parseContent as parseCobertura } from '@cvrg-report/cobertura-json';
import { default as Range } from 'drange';
import assert from 'node:assert';
import lcovParser from '@friedemannsommer/lcov-parser';
import { default as cobertura } from '@cvrg-report/cobertura-json';

export type CoverageFormat = 'lcov' | 'istanbul' | 'cobertura';

Expand Down Expand Up @@ -135,11 +135,13 @@ async function coveredLines(opts: Opts): Promise<Record<Path, Hits>> {
}
}

function coverageRecordsToLines(records: LCOVRecord[]): Record<Path, Hits> {
function coverageRecordsToLines(
records: { path: string; lines: { details: { hit: number; line: number }[] } }[]
): Record<Path, Hits> {
return records.reduce<Record<Path, Hits>>((result, fileEntry) => {
const path = pathFs.isAbsolute(fileEntry.file)
? pathFs.normalize(pathFs.relative(process.cwd(), fileEntry.file))
: pathFs.normalize(fileEntry.file);
const path = pathFs.isAbsolute(fileEntry.path)
? pathFs.normalize(pathFs.relative(process.cwd(), fileEntry.path))
: pathFs.normalize(fileEntry.path);
result[path] = fileEntry.lines.details.map(({ line, hit }) => ({
hits: hit,
start: line,
Expand Down Expand Up @@ -173,14 +175,19 @@ async function istanbulCoveredLines(opts: Opts): Promise<Record<Path, Hits>> {

async function lcovCoveredLines(opts: Opts): Promise<Record<Path, Hits>> {
const fileContents = await readFile(opts.coverage, 'utf8');
const lcovData = parseLCOV(fileContents);
const lcovData = await lcovParser({ from: fileContents });
return coverageRecordsToLines(lcovData);
}

async function coberturaCoveredLines(opts: Opts): Promise<Record<Path, Hits>> {
const fileContents = await readFile(opts.coverage, 'utf8');
const records = await parseCobertura(fileContents);
return coverageRecordsToLines(records);
const records = await cobertura.parseContent(fileContents);
return coverageRecordsToLines(
records.map(record => ({
path: record.file,
lines: record.lines
}))
);
}

export type Result = { covered: number; total: number; uncoveredLines: Record<Path, Range> };
Expand Down
28 changes: 0 additions & 28 deletions test.ts

This file was deleted.

2 changes: 1 addition & 1 deletion test/test.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as coverage from '../src/covered';
import * as Range from 'drange';
import { default as Range } from 'drange';

describe('coverage', () => {
describe('uncovered', () => {
Expand Down
16 changes: 7 additions & 9 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@
"compilerOptions": {
"strict": true,
"declaration": true,
"target": "es2017",
"lib": ["es6", "es2017", "dom", "esnext.asynciterable"],
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"removeComments": false,
"alwaysStrict": true,
"typeRoots": ["./src/types", "./node_modules/@types"],
"baseUrl": "src",
"module": "ESNext",
"lib": ["es2023"],
"target": "es2022",
"moduleResolution": "Bundler",
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"outDir": "dist"
},
"exclude": ["packages"]
"include": ["src/**/*", "test/**/*", "test-fixture/**/*"],
}
Loading