From 7c06ba688177596447cc70c58a5121265d80fd79 Mon Sep 17 00:00:00 2001 From: Nazar Hussain Date: Thu, 28 Nov 2024 11:50:36 +0100 Subject: [PATCH] feat: support esm and cjs build (#28) * Support esm and cjs build * Fix lint errors for ts module resolution * Fix benchmark loader for esm * Update doc script --- .mocharc.yaml | 4 +- .prettierrc.js | 2 +- bin/index.js | 3 + eslint.config.mjs => eslint.config.js | 7 ++ package.json | 23 ++++-- scripts/writeOptionsMd.ts | 2 +- src/cli.ts | 12 ++- src/compare/compute.ts | 2 +- src/compare/index.ts | 10 +-- src/github/comment.ts | 6 +- src/github/octokit.ts | 2 +- src/history/append.ts | 2 +- src/history/gaCache.ts | 8 +- src/history/index.ts | 14 ++-- src/history/local.ts | 12 +-- src/history/location.ts | 6 +- src/history/provider.ts | 2 +- src/history/s3.ts | 10 +-- src/history/schema.ts | 2 +- src/history/shouldPersist.ts | 4 +- src/index.ts | 2 +- src/mochaPlugin/index.ts | 12 +-- src/mochaPlugin/mochaRunner.ts | 8 +- src/mochaPlugin/reporter.ts | 8 +- src/mochaPlugin/runBenchFn.ts | 2 +- src/options.ts | 4 +- src/run.ts | 20 ++--- src/types.ts | 2 +- src/utils/currentBranch.ts | 6 +- src/utils/defaultBranch.ts | 8 +- src/utils/file.ts | 6 +- src/utils/gaContext.ts | 2 +- src/utils/git.ts | 2 +- src/utils/index.ts | 18 ++--- src/utils/mochaCliExports.ts | 6 +- src/utils/render.ts | 2 +- src/utils/shell.ts | 4 +- test/perf/iteration.test.ts | 4 +- test/unit/history/gaCache.test.ts | 6 +- test/unit/history/local.test.ts | 6 +- test/unit/history/s3.test.ts | 6 +- test/unit/utils/file.test.ts | 2 +- tsconfig.build.cjs.json | 9 +++ ...nfig.build.json => tsconfig.build.esm.json | 4 +- tsconfig.json | 5 +- yarn.lock | 74 ++++++++++++++++++- 46 files changed, 230 insertions(+), 131 deletions(-) create mode 100755 bin/index.js rename eslint.config.mjs => eslint.config.js (94%) create mode 100644 tsconfig.build.cjs.json rename tsconfig.build.json => tsconfig.build.esm.json (52%) diff --git a/.mocharc.yaml b/.mocharc.yaml index cc948fa..0ec947f 100644 --- a/.mocharc.yaml +++ b/.mocharc.yaml @@ -1,5 +1,5 @@ -require: - - ts-node/register +loader: + - ts-node/esm colors: true timeout: 5000 exit: true diff --git a/.prettierrc.js b/.prettierrc.js index ee8eee2..5125fad 100644 --- a/.prettierrc.js +++ b/.prettierrc.js @@ -1,4 +1,4 @@ -module.exports = { +export default { printWidth: 120, tabWidth: 2, useTabs: false, diff --git a/bin/index.js b/bin/index.js new file mode 100755 index 0000000..9b08b14 --- /dev/null +++ b/bin/index.js @@ -0,0 +1,3 @@ +#!/usr/bin/env node + +await import("../lib/esm/cli.js"); diff --git a/eslint.config.mjs b/eslint.config.js similarity index 94% rename from eslint.config.mjs rename to eslint.config.js index 5579126..2be1369 100644 --- a/eslint.config.mjs +++ b/eslint.config.js @@ -35,6 +35,7 @@ export default ts.config( ], "func-call-spacing": "error", "import/no-duplicates": "off", + "import/no-unresolved": ["error", {commonjs: false}], "new-parens": "error", "no-caller": "error", "no-bitwise": "off", @@ -58,6 +59,12 @@ export default ts.config( project: "./tsconfig.json", }, }, + settings: { + "import/resolver": { + "typescript": { + } + } + }, }, { files: ["**/test/**/*.ts"], diff --git a/package.json b/package.json index d1a856d..12bc9cd 100644 --- a/package.json +++ b/package.json @@ -1,12 +1,11 @@ { "name": "@dapplion/benchmark", "version": "0.2.5", - "main": "lib/index.js", "repository": "git@github.com:dapplion/benchmark.git", "author": "dapplion <35266934+dapplion@users.noreply.github.com>", "license": "MIT", "bin": { - "benchmark": "lib/cli.js" + "benchmark": "./bin/index.js" }, "files": [ "lib/**/*.d.ts", @@ -15,18 +14,29 @@ "*.d.ts", "*.js" ], + "type": "module", + "main": "./lib/cjs/index.js", + "module": "./lib/esm/index.js", + "exports": { + ".": { + "import": "./lib/esm/index.js", + "require": "./lib/cjs/index.js" + } + }, "scripts": { - "build": "tsc -p tsconfig.build.json && chmod +x lib/cli.js", + "build": "yarn build:esm && yarn build:cjs", + "build:esm": "tsc -p tsconfig.build.esm.json && echo '{\"type\": \"module\"}' > ./lib/esm/package.json", + "build:cjs": "tsc -p tsconfig.build.cjs.json && echo '{\"type\": \"commonjs\"}' > ./lib/cjs/package.json", "test:unit": "mocha test/unit/**/*.test.ts", "lint": "eslint --color src/ test/", "prepublishOnly": "yarn build", - "benchmark": "node -r ts-node/register src/cli.ts 'test/perf/**/*.test.ts'", - "writeDocs": "ts-node scripts/writeOptionsMd.ts" + "benchmark": "node --loader ts-node/esm ./src/cli.ts 'test/perf/**/*.test.ts'", + "writeDocs": "node --loader ts-node/esm scripts/writeOptionsMd.ts" }, "devDependencies": { "@types/chai": "^4.2.19", "@types/mocha": "^10.0.9", - "@types/node": "^15.12.4", + "@types/node": "^18.15.3", "@types/rimraf": "^3.0.0", "@types/yargs": "^17.0.33", "chai": "^4.5.0", @@ -34,6 +44,7 @@ "eslint": "^9.15.0", "@eslint/js": "^9.15.0", "eslint-plugin-import": "^2.31.0", + "eslint-import-resolver-typescript": "^3.6.3", "eslint-plugin-prettier": "^5.2.1", "eslint-config-prettier": "^9.1.0", "mocha": "^10.8.2", diff --git a/scripts/writeOptionsMd.ts b/scripts/writeOptionsMd.ts index f4817d4..48f80ee 100644 --- a/scripts/writeOptionsMd.ts +++ b/scripts/writeOptionsMd.ts @@ -1,4 +1,4 @@ -import {options} from "../src/options"; +import {options} from "../src/options.js"; const sections: string[] = []; diff --git a/src/cli.ts b/src/cli.ts index 73e5091..c02649d 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -1,11 +1,9 @@ -#!/usr/bin/env node - // Must not use `* as yargs`, see https://github.com/yargs/yargs/issues/1131 import yargs from "yargs"; -import {loadOptions, handleRequires} from "./utils/mochaCliExports"; -import {options, optionsDefault} from "./options"; -import {run} from "./run"; -import {Opts} from "./types"; +import {loadOptions, handleRequires} from "./utils/mochaCliExports.js"; +import {options, optionsDefault} from "./options.js"; +import {run} from "./run.js"; +import {Opts} from "./types.js"; /** * Common factory for running the CLI and running integration tests @@ -15,7 +13,7 @@ const argv = process.argv.slice(2); const args = loadOptions(argv); -void yargs +void yargs() .env("BENCHMARK") .scriptName("benchmark") .command({ diff --git a/src/compare/compute.ts b/src/compare/compute.ts index 4cfba4a..84e7ea1 100644 --- a/src/compare/compute.ts +++ b/src/compare/compute.ts @@ -1,4 +1,4 @@ -import {ResultComparision, BenchmarkComparision, Benchmark, BenchmarkResult} from "../types"; +import {ResultComparision, BenchmarkComparision, Benchmark, BenchmarkResult} from "../types.js"; export function computeBenchComparision( currBench: Benchmark, diff --git a/src/compare/index.ts b/src/compare/index.ts index 6a3b2b7..c9615ed 100644 --- a/src/compare/index.ts +++ b/src/compare/index.ts @@ -1,9 +1,9 @@ import * as github from "@actions/github"; -import {Benchmark, Opts} from "../types"; -import {getGithubEventData, GithubActionsEventData, parseBranchFromRef, getDefaultBranch} from "../utils"; -import {isGaRun} from "../github/context"; -import {IHistoryProvider} from "../history/provider"; -import {validateBenchmark} from "../history/schema"; +import {Benchmark, Opts} from "../types.js"; +import {getGithubEventData, GithubActionsEventData, parseBranchFromRef, getDefaultBranch} from "../utils/index.js"; +import {isGaRun} from "../github/context.js"; +import {IHistoryProvider} from "../history/provider.js"; +import {validateBenchmark} from "../history/schema.js"; enum CompareWithType { latestCommitInBranch = "latestCommitInBranch", diff --git a/src/github/comment.ts b/src/github/comment.ts index 5785290..f668ad2 100644 --- a/src/github/comment.ts +++ b/src/github/comment.ts @@ -1,7 +1,7 @@ import * as github from "@actions/github"; -import {BenchmarkComparision} from "../types"; -import {commetToPrUpdatable, commentToCommit} from "./octokit"; -import {getGithubEventData, GithubActionsEventData, renderComment} from "../utils"; +import {BenchmarkComparision} from "../types.js"; +import {commetToPrUpdatable, commentToCommit} from "./octokit.js"; +import {getGithubEventData, GithubActionsEventData, renderComment} from "../utils/index.js"; export async function postGaComment(resultsComp: BenchmarkComparision): Promise { switch (github.context.eventName) { diff --git a/src/github/octokit.ts b/src/github/octokit.ts index 0570231..6f1b9a4 100644 --- a/src/github/octokit.ts +++ b/src/github/octokit.ts @@ -1,4 +1,4 @@ -import {getContext} from "./context"; +import {getContext} from "./context.js"; const commentTag = "benchmarkbot/action"; diff --git a/src/history/append.ts b/src/history/append.ts index e9f8efb..6d6d571 100644 --- a/src/history/append.ts +++ b/src/history/append.ts @@ -1,4 +1,4 @@ -import {Benchmark, BenchmarkHistory, Opts} from "../types"; +import {Benchmark, BenchmarkHistory, Opts} from "../types.js"; export function appendBenchmarkToHistoryAndPrune( history: BenchmarkHistory, diff --git a/src/history/gaCache.ts b/src/history/gaCache.ts index 526f511..26bcf6c 100644 --- a/src/history/gaCache.ts +++ b/src/history/gaCache.ts @@ -1,8 +1,8 @@ -import fs from "fs"; +import fs from "node:fs"; import * as cache from "@actions/cache"; -import {Benchmark} from "../types"; -import {LocalHistoryProvider} from "./local"; -import {HistoryProviderType, IHistoryProvider} from "./provider"; +import {Benchmark} from "../types.js"; +import {LocalHistoryProvider} from "./local.js"; +import {HistoryProviderType, IHistoryProvider} from "./provider.js"; /** * Persist results in CSV, one benchmark result per file diff --git a/src/history/index.ts b/src/history/index.ts index fe84804..cab1900 100644 --- a/src/history/index.ts +++ b/src/history/index.ts @@ -1,10 +1,10 @@ -import {Opts} from "../types"; -import {resolveHistoryLocation} from "./location"; -import {LocalHistoryProvider} from "./local"; -import {getGaCacheHistoryProvider} from "./gaCache"; -import {IHistoryProvider} from "./provider"; -import {optionsDefault} from "../options"; -import {S3HistoryProvider} from "./s3"; +import {Opts} from "../types.js"; +import {resolveHistoryLocation} from "./location.js"; +import {LocalHistoryProvider} from "./local.js"; +import {getGaCacheHistoryProvider} from "./gaCache.js"; +import {IHistoryProvider} from "./provider.js"; +import {optionsDefault} from "../options.js"; +import {S3HistoryProvider} from "./s3.js"; export {resolveHistoryLocation}; export function getHistoryProvider(opts: Opts): IHistoryProvider { diff --git a/src/history/local.ts b/src/history/local.ts index 9e424fc..73cf942 100644 --- a/src/history/local.ts +++ b/src/history/local.ts @@ -1,9 +1,9 @@ -import fs from "fs"; -import path from "path"; -import {HistoryProviderType, IHistoryProvider} from "./provider"; -import {Benchmark, BenchmarkResults} from "../types"; -import {fromCsv, toCsv} from "../utils/file"; -import {FsError} from "../utils"; +import fs from "node:fs"; +import path from "node:path"; +import {HistoryProviderType, IHistoryProvider} from "./provider.js"; +import {Benchmark, BenchmarkResults} from "../types.js"; +import {fromCsv, toCsv} from "../utils/file.js"; +import {FsError} from "../utils/index.js"; const extension = ".csv"; const historyDir = "history"; diff --git a/src/history/location.ts b/src/history/location.ts index 563c559..cef5c0a 100644 --- a/src/history/location.ts +++ b/src/history/location.ts @@ -1,6 +1,6 @@ -import {isGaRun} from "../github/context"; -import {Opts} from "../types"; -import {optionsDefault} from "../options"; +import {isGaRun} from "../github/context.js"; +import {Opts} from "../types.js"; +import {optionsDefault} from "../options.js"; export type HistoryLocation = {type: "local"; path: string} | {type: "ga-cache"; key: string}; diff --git a/src/history/provider.ts b/src/history/provider.ts index 5ee4491..6d55154 100644 --- a/src/history/provider.ts +++ b/src/history/provider.ts @@ -1,4 +1,4 @@ -import {Benchmark} from "../types"; +import {Benchmark} from "../types.js"; export enum HistoryProviderType { Local = "Local", diff --git a/src/history/s3.ts b/src/history/s3.ts index e8cbf21..c33ad0b 100644 --- a/src/history/s3.ts +++ b/src/history/s3.ts @@ -1,8 +1,8 @@ -import path from "path"; -import S3 from "aws-sdk/clients/s3"; -import {Benchmark, BenchmarkResults} from "../types"; -import {fromCsv, toCsv, extendError, AwsError} from "../utils"; -import {HistoryProviderType, IHistoryProvider} from "./provider"; +import path from "node:path"; +import S3 from "aws-sdk/clients/s3.js"; +import {Benchmark, BenchmarkResults} from "../types.js"; +import {fromCsv, toCsv, extendError, AwsError} from "../utils/index.js"; +import {HistoryProviderType, IHistoryProvider} from "./provider.js"; export type S3Config = Pick & { Bucket: string; diff --git a/src/history/schema.ts b/src/history/schema.ts index 73f334f..c97a882 100644 --- a/src/history/schema.ts +++ b/src/history/schema.ts @@ -1,5 +1,5 @@ import Ajv from "ajv"; -import {BenchmarkHistory, Benchmark} from "../types"; +import {BenchmarkHistory, Benchmark} from "../types.js"; export const emptyBenchmarkHistory: BenchmarkHistory = {benchmarks: {}}; diff --git a/src/history/shouldPersist.ts b/src/history/shouldPersist.ts index 8c3a747..b4a8507 100644 --- a/src/history/shouldPersist.ts +++ b/src/history/shouldPersist.ts @@ -1,5 +1,5 @@ -import {Opts} from "../types"; -import {getDefaultBranch} from "../utils/defaultBranch"; +import {Opts} from "../types.js"; +import {getDefaultBranch} from "../utils/defaultBranch.js"; export async function resolveShouldPersist(opts: Opts, branch: string): Promise { // Force persist diff --git a/src/index.ts b/src/index.ts index 78292f8..12b30d0 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1 +1 @@ -export * from "./mochaPlugin"; +export * from "./mochaPlugin/index.js"; diff --git a/src/mochaPlugin/index.ts b/src/mochaPlugin/index.ts index 6edbc4a..a1e9cef 100644 --- a/src/mochaPlugin/index.ts +++ b/src/mochaPlugin/index.ts @@ -1,9 +1,9 @@ -import fs from "fs"; -import path from "path"; -import {BenchmarkOpts} from "../types"; -import {optsByRootSuite, optsMap, resultsByRootSuite} from "./globalState"; -import {BenchmarkRunOptsWithFn, runBenchFn} from "./runBenchFn"; -import {getRootSuite, getParentSuite} from "./utils"; +import fs from "node:fs"; +import path from "node:path"; +import {BenchmarkOpts} from "../types.js"; +import {optsByRootSuite, optsMap, resultsByRootSuite} from "./globalState.js"; +import {BenchmarkRunOptsWithFn, runBenchFn} from "./runBenchFn.js"; +import {getRootSuite, getParentSuite} from "./utils.js"; type PartialBy = Omit & Partial>; diff --git a/src/mochaPlugin/mochaRunner.ts b/src/mochaPlugin/mochaRunner.ts index 9b9bc1e..1a2b53c 100644 --- a/src/mochaPlugin/mochaRunner.ts +++ b/src/mochaPlugin/mochaRunner.ts @@ -1,9 +1,9 @@ // eslint-disable-next-line import/no-extraneous-dependencies import Mocha from "mocha"; -import {optsByRootSuite, resultsByRootSuite} from "./globalState"; -import {collectFiles, FileCollectionOptions} from "../utils/mochaCliExports"; -import {benchmarkReporterWithPrev} from "./reporter"; -import {Benchmark, BenchmarkOpts, BenchmarkResult, onlyBenchmarkOpts, Opts} from "../types"; +import {optsByRootSuite, resultsByRootSuite} from "./globalState.js"; +import {collectFiles, FileCollectionOptions} from "../utils/mochaCliExports.js"; +import {benchmarkReporterWithPrev} from "./reporter.js"; +import {Benchmark, BenchmarkOpts, BenchmarkResult, onlyBenchmarkOpts, Opts} from "../types.js"; export async function runMochaBenchmark( opts: Opts & BenchmarkOpts, diff --git a/src/mochaPlugin/reporter.ts b/src/mochaPlugin/reporter.ts index 1fa73b6..f1771dd 100644 --- a/src/mochaPlugin/reporter.ts +++ b/src/mochaPlugin/reporter.ts @@ -1,9 +1,9 @@ // eslint-disable-next-line import/no-extraneous-dependencies import Mocha from "mocha"; -import {Benchmark, BenchmarkResult} from "../types"; -import {resultsByRootSuite} from "./globalState"; -import {formatResultRow} from "./format"; -import {getRootSuite} from "./utils"; +import {Benchmark, BenchmarkResult} from "../types.js"; +import {resultsByRootSuite} from "./globalState.js"; +import {formatResultRow} from "./format.js"; +import {getRootSuite} from "./utils.js"; const { EVENT_RUN_BEGIN, diff --git a/src/mochaPlugin/runBenchFn.ts b/src/mochaPlugin/runBenchFn.ts index 14852ea..9e5adb0 100644 --- a/src/mochaPlugin/runBenchFn.ts +++ b/src/mochaPlugin/runBenchFn.ts @@ -1,4 +1,4 @@ -import {BenchmarkResult, BenchmarkOpts} from "../types"; +import {BenchmarkResult, BenchmarkOpts} from "../types.js"; export type BenchmarkRunOpts = BenchmarkOpts & { id: string; diff --git a/src/options.ts b/src/options.ts index d856be0..8569a6b 100644 --- a/src/options.ts +++ b/src/options.ts @@ -1,6 +1,6 @@ import {Options} from "yargs"; -import {Opts, BenchmarkOpts} from "./types"; -import {FileCollectionOptions} from "./utils/mochaCliExports"; +import {Opts, BenchmarkOpts} from "./types.js"; +import {FileCollectionOptions} from "./utils/mochaCliExports.js"; export const optionsDefault = { threshold: 2, diff --git a/src/run.ts b/src/run.ts index d94cb98..e5b6aa7 100644 --- a/src/run.ts +++ b/src/run.ts @@ -1,14 +1,14 @@ import * as github from "@actions/github"; -import {getHistoryProvider} from "./history"; -import {resolveShouldPersist} from "./history/shouldPersist"; -import {validateBenchmark} from "./history/schema"; -import {Benchmark, BenchmarkOpts, Opts} from "./types"; -import {renderCompareWith, resolveCompareWith, resolvePrevBenchmark} from "./compare"; -import {parseBranchFromRef, getCurrentCommitInfo, shell, getCurrentBranch} from "./utils"; -import {runMochaBenchmark} from "./mochaPlugin/mochaRunner"; -import {computeBenchComparision} from "./compare/compute"; -import {postGaComment} from "./github/comment"; -import {isGaRun} from "./github/context"; +import {getHistoryProvider} from "./history/index.js"; +import {resolveShouldPersist} from "./history/shouldPersist.js"; +import {validateBenchmark} from "./history/schema.js"; +import {Benchmark, BenchmarkOpts, Opts} from "./types.js"; +import {renderCompareWith, resolveCompareWith, resolvePrevBenchmark} from "./compare/index.js"; +import {parseBranchFromRef, getCurrentCommitInfo, shell, getCurrentBranch} from "./utils/index.js"; +import {runMochaBenchmark} from "./mochaPlugin/mochaRunner.js"; +import {computeBenchComparision} from "./compare/compute.js"; +import {postGaComment} from "./github/comment.js"; +import {isGaRun} from "./github/context.js"; /* eslint-disable no-console */ diff --git a/src/types.ts b/src/types.ts index d031516..f3f7cd4 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,4 +1,4 @@ -import {FileCollectionOptions} from "./utils/mochaCliExports"; +import {FileCollectionOptions} from "./utils/mochaCliExports.js"; export type Opts = Partial & { defaultBranch?: string; diff --git a/src/utils/currentBranch.ts b/src/utils/currentBranch.ts index 4a85d82..466df98 100644 --- a/src/utils/currentBranch.ts +++ b/src/utils/currentBranch.ts @@ -1,7 +1,7 @@ import * as github from "@actions/github"; -import {getGithubEventData, GithubActionsEventData, parseBranchFromRef} from "../utils"; -import {isGaRun} from "../github/context"; -import {shell} from "./shell"; +import {getGithubEventData, GithubActionsEventData, parseBranchFromRef} from "../utils/index.js"; +import {isGaRun} from "../github/context.js"; +import {shell} from "./shell.js"; export async function getCurrentBranch(): Promise { if (isGaRun()) { diff --git a/src/utils/defaultBranch.ts b/src/utils/defaultBranch.ts index e959729..fbae6cf 100644 --- a/src/utils/defaultBranch.ts +++ b/src/utils/defaultBranch.ts @@ -1,7 +1,7 @@ -import {isGaRun} from "../github/context"; -import {getGithubDefaultBranch} from "../github/octokit"; -import {Opts} from "../types"; -import {shell} from "./shell"; +import {isGaRun} from "../github/context.js"; +import {getGithubDefaultBranch} from "../github/octokit.js"; +import {Opts} from "../types.js"; +import {shell} from "./shell.js"; let defaultBranch: string | null = null; diff --git a/src/utils/file.ts b/src/utils/file.ts index b967174..91ce55d 100644 --- a/src/utils/file.ts +++ b/src/utils/file.ts @@ -1,6 +1,6 @@ -import fs from "fs"; -import csvParse from "csv-parse/lib/sync"; -import csvStringify from "csv-stringify/lib/sync"; +import fs from "node:fs"; +import csvParse from "csv-parse/lib/sync.js"; +import csvStringify from "csv-stringify/lib/sync.js"; type CsvMetadata = Record; // eslint-disable-next-line @typescript-eslint/no-explicit-any diff --git a/src/utils/gaContext.ts b/src/utils/gaContext.ts index 929734d..babbe37 100644 --- a/src/utils/gaContext.ts +++ b/src/utils/gaContext.ts @@ -1,4 +1,4 @@ -import fs from "fs"; +import fs from "node:fs"; /** * Github actions store the event data payload at a JSON file with path diff --git a/src/utils/git.ts b/src/utils/git.ts index 0a88013..a387ac5 100644 --- a/src/utils/git.ts +++ b/src/utils/git.ts @@ -1,4 +1,4 @@ -import {shell} from "./shell"; +import {shell} from "./shell.js"; export async function getCurrentCommitInfo(): Promise<{ /** commit hash `71f08b12d45d44255c31f7b7d135bd15a93fdaac` */ diff --git a/src/utils/index.ts b/src/utils/index.ts index 14d1572..eff30e7 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -1,9 +1,9 @@ -export * from "./currentBranch"; -export * from "./defaultBranch"; -export * from "./error"; -export * from "./file"; -export * from "./gaContext"; -export * from "./git"; -export * from "./gitRef"; -export * from "./render"; -export * from "./shell"; +export * from "./currentBranch.js"; +export * from "./defaultBranch.js"; +export * from "./error.js"; +export * from "./file.js"; +export * from "./gaContext.js"; +export * from "./git.js"; +export * from "./gitRef.js"; +export * from "./render.js"; +export * from "./shell.js"; diff --git a/src/utils/mochaCliExports.ts b/src/utils/mochaCliExports.ts index 0c9d08e..cb6fb6d 100644 --- a/src/utils/mochaCliExports.ts +++ b/src/utils/mochaCliExports.ts @@ -1,15 +1,15 @@ // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore // eslint-disable-next-line import/no-extraneous-dependencies -import {lookupFiles as lookupFilesMocha, loadOptions as loadOptionsMocha} from "mocha/lib/cli"; +import {lookupFiles as lookupFilesMocha, loadOptions as loadOptionsMocha} from "mocha/lib/cli/index.js"; // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore // eslint-disable-next-line import/no-extraneous-dependencies -import collectFilesMocha from "mocha/lib/cli/collect-files"; +import collectFilesMocha from "mocha/lib/cli/collect-files.js"; // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore // eslint-disable-next-line import/no-extraneous-dependencies -import {handleRequires as handleRequiresMocha} from "mocha/lib/cli/run-helpers"; +import {handleRequires as handleRequiresMocha} from "mocha/lib/cli/run-helpers.js"; export const lookupFiles = lookupFilesMocha as ( filepath: string, diff --git a/src/utils/render.ts b/src/utils/render.ts index 03d74f9..04b8b85 100644 --- a/src/utils/render.ts +++ b/src/utils/render.ts @@ -1,4 +1,4 @@ -import {BenchmarkComparision, ResultComparision} from "../types"; +import {BenchmarkComparision, ResultComparision} from "../types.js"; type CommitsSha = Pick; diff --git a/src/utils/shell.ts b/src/utils/shell.ts index 2bfaf43..cc55a69 100644 --- a/src/utils/shell.ts +++ b/src/utils/shell.ts @@ -1,5 +1,5 @@ -import util from "util"; -import child from "child_process"; +import util from "node:util"; +import child from "node:child_process"; const exec = util.promisify(child.exec); diff --git a/test/perf/iteration.test.ts b/test/perf/iteration.test.ts index 1ea1522..135eaeb 100644 --- a/test/perf/iteration.test.ts +++ b/test/perf/iteration.test.ts @@ -1,5 +1,5 @@ -import assert from "assert"; -import {itBench, setBenchOpts} from "../../src"; +import assert from "node:assert"; +import {itBench, setBenchOpts} from "../../src/index.js"; // As of Jun 17 2021 // Compare state root diff --git a/test/unit/history/gaCache.test.ts b/test/unit/history/gaCache.test.ts index 56da326..1bfad1c 100644 --- a/test/unit/history/gaCache.test.ts +++ b/test/unit/history/gaCache.test.ts @@ -1,7 +1,7 @@ import {expect} from "chai"; -import {Benchmark} from "../../../src/types"; -import {getGaCacheHistoryProvider} from "../../../src/history/gaCache"; -import {isGaRun} from "../../../src/github/context"; +import {Benchmark} from "../../../src/types.js"; +import {getGaCacheHistoryProvider} from "../../../src/history/gaCache.js"; +import {isGaRun} from "../../../src/github/context.js"; // Currently fails with // diff --git a/test/unit/history/local.test.ts b/test/unit/history/local.test.ts index df38a80..0b58df0 100644 --- a/test/unit/history/local.test.ts +++ b/test/unit/history/local.test.ts @@ -1,8 +1,8 @@ -import fs from "fs"; +import fs from "node:fs"; import {expect} from "chai"; import rimraf from "rimraf"; -import {Benchmark} from "../../../src/types"; -import {LocalHistoryProvider} from "../../../src/history/local"; +import {Benchmark} from "../../../src/types.js"; +import {LocalHistoryProvider} from "../../../src/history/local.js"; describe("benchmark history local", () => { const branch = "main"; diff --git a/test/unit/history/s3.test.ts b/test/unit/history/s3.test.ts index b725387..cf8d2cd 100644 --- a/test/unit/history/s3.test.ts +++ b/test/unit/history/s3.test.ts @@ -1,7 +1,7 @@ import {expect} from "chai"; -import S3 from "aws-sdk/clients/s3"; -import {Benchmark} from "../../../src/types"; -import {S3HistoryProvider} from "../../../src/history/s3"; +import S3 from "aws-sdk/clients/s3.js"; +import {Benchmark} from "../../../src/types.js"; +import {S3HistoryProvider} from "../../../src/history/s3.js"; import dotenv from "dotenv"; dotenv.config(); diff --git a/test/unit/utils/file.test.ts b/test/unit/utils/file.test.ts index bea866d..6672917 100644 --- a/test/unit/utils/file.test.ts +++ b/test/unit/utils/file.test.ts @@ -1,5 +1,5 @@ import {expect} from "chai"; -import {toCsv, fromCsv} from "../../../src/utils"; +import {toCsv, fromCsv} from "../../../src/utils/index.js"; describe("utils / file - csv", () => { it("Convert to and from CSV", () => { diff --git a/tsconfig.build.cjs.json b/tsconfig.build.cjs.json new file mode 100644 index 0000000..5c299e9 --- /dev/null +++ b/tsconfig.build.cjs.json @@ -0,0 +1,9 @@ +{ + "extends": "./tsconfig.json", + "include": ["src"], + "compilerOptions": { + "outDir": "./lib/cjs", + "esModuleInterop": true, + "module": "commonjs", + } +} diff --git a/tsconfig.build.json b/tsconfig.build.esm.json similarity index 52% rename from tsconfig.build.json rename to tsconfig.build.esm.json index a6d45ce..4079686 100644 --- a/tsconfig.build.json +++ b/tsconfig.build.esm.json @@ -2,6 +2,8 @@ "extends": "./tsconfig.json", "include": ["src"], "compilerOptions": { - "outDir": "./lib" + "outDir": "./lib/esm", + "esModuleInterop": true, + "module": "es2020", } } diff --git a/tsconfig.json b/tsconfig.json index d02da2c..bc3f2ba 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,9 +2,10 @@ "compilerOptions": { "outDir": "./lib", - "target": "es2019", - "module": "commonjs", + "target": "ESNext", + "module": "ESNext", "pretty": true, + "moduleResolution": "node", "lib": ["es2020", "esnext.bigint", "es2020.string", "es2020.symbol.wellknown"], "strict": true, diff --git a/yarn.lock b/yarn.lock index c28b880..6657bab 100644 --- a/yarn.lock +++ b/yarn.lock @@ -295,6 +295,11 @@ "@nodelib/fs.scandir" "2.1.5" fastq "^1.6.0" +"@nolyfill/is-core-module@1.0.39": + version "1.0.39" + resolved "https://registry.yarnpkg.com/@nolyfill/is-core-module/-/is-core-module-1.0.39.tgz#3dc35ba0f1e66b403c00b39344f870298ebb1c8e" + integrity sha512-nn5ozdjYQpUCZlWGuxcJY/KpxkWQs4DcbMCmKojjyrYDEAGy4Ce19NN4v5MduafTwJlbKc99UA8YhSVqq9yPZA== + "@octokit/auth-token@^2.4.4": version "2.4.5" resolved "https://registry.yarnpkg.com/@octokit/auth-token/-/auth-token-2.4.5.tgz#568ccfb8cb46f36441fac094ce34f7a875b197f3" @@ -467,11 +472,18 @@ "@types/node" "*" form-data "^3.0.0" -"@types/node@*", "@types/node@^15.12.4": +"@types/node@*": version "15.12.4" resolved "https://registry.yarnpkg.com/@types/node/-/node-15.12.4.tgz#e1cf817d70a1e118e81922c4ff6683ce9d422e26" integrity sha512-zrNj1+yqYF4WskCMOHwN+w9iuD12+dGm0rQ35HLl9/Ouuq52cEtd0CH9qMgrdNmi5ejC1/V7vKEXYubB+65DkA== +"@types/node@^18.15.3": + version "18.19.67" + resolved "https://registry.yarnpkg.com/@types/node/-/node-18.19.67.tgz#77c4b01641a1e3e1509aff7e10d39e4afd5ae06d" + integrity sha512-wI8uHusga+0ZugNp0Ol/3BqQfEcCCNfojtO6Oou9iVNGPTL6QNSdnUdqq85fRgIorLhLMuPIKpsN98QE9Nh+KQ== + dependencies: + undici-types "~5.26.4" + "@types/rimraf@^3.0.0": version "3.0.0" resolved "https://registry.yarnpkg.com/@types/rimraf/-/rimraf-3.0.0.tgz#b9d03f090ece263671898d57bb7bb007023ac19f" @@ -1083,6 +1095,14 @@ emoji-regex@^8.0.0: resolved "https://registry.yarnpkg.com/emoji-regex/-/emoji-regex-8.0.0.tgz#e818fd69ce5ccfcb404594f842963bf53164cc37" integrity sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A== +enhanced-resolve@^5.15.0: + version "5.17.1" + resolved "https://registry.yarnpkg.com/enhanced-resolve/-/enhanced-resolve-5.17.1.tgz#67bfbbcc2f81d511be77d686a90267ef7f898a15" + integrity sha512-LMHl3dXhTcfv8gM4kEzIUeTQ+7fpdA0l2tUf34BddXPkz2A5xJ5L/Pchd5BL6rdccM9QGvu0sWZzK1Z1t4wwyg== + dependencies: + graceful-fs "^4.2.4" + tapable "^2.2.0" + es-abstract@^1.22.1, es-abstract@^1.22.3, es-abstract@^1.23.0, es-abstract@^1.23.2, es-abstract@^1.23.5: version "1.23.5" resolved "https://registry.yarnpkg.com/es-abstract/-/es-abstract-1.23.5.tgz#f4599a4946d57ed467515ed10e4f157289cd52fb" @@ -1203,7 +1223,21 @@ eslint-import-resolver-node@^0.3.9: is-core-module "^2.13.0" resolve "^1.22.4" -eslint-module-utils@^2.12.0: +eslint-import-resolver-typescript@^3.6.3: + version "3.6.3" + resolved "https://registry.yarnpkg.com/eslint-import-resolver-typescript/-/eslint-import-resolver-typescript-3.6.3.tgz#bb8e388f6afc0f940ce5d2c5fd4a3d147f038d9e" + integrity sha512-ud9aw4szY9cCT1EWWdGv1L1XR6hh2PaRWif0j2QjQ0pgTY/69iw+W0Z4qZv5wHahOl8isEr+k/JnyAqNQkLkIA== + dependencies: + "@nolyfill/is-core-module" "1.0.39" + debug "^4.3.5" + enhanced-resolve "^5.15.0" + eslint-module-utils "^2.8.1" + fast-glob "^3.3.2" + get-tsconfig "^4.7.5" + is-bun-module "^1.0.2" + is-glob "^4.0.3" + +eslint-module-utils@^2.12.0, eslint-module-utils@^2.8.1: version "2.12.0" resolved "https://registry.yarnpkg.com/eslint-module-utils/-/eslint-module-utils-2.12.0.tgz#fe4cfb948d61f49203d7b08871982b65b9af0b0b" integrity sha512-wALZ0HFoytlyh/1+4wuZ9FJCD/leWHQzzrxJ8+rebyReSLk7LApMyd3WJaLVoN+D5+WIdJyDK1c6JnE65V4Zyg== @@ -1533,6 +1567,13 @@ get-symbol-description@^1.0.2: es-errors "^1.3.0" get-intrinsic "^1.2.4" +get-tsconfig@^4.7.5: + version "4.8.1" + resolved "https://registry.yarnpkg.com/get-tsconfig/-/get-tsconfig-4.8.1.tgz#8995eb391ae6e1638d251118c7b56de7eb425471" + integrity sha512-k9PN+cFBmaLWtVz29SkUoqU5O0slLuHJXt/2P+tMVFT+phsSGXGkp9t3rQIqdz0e+06EHNGs3oM6ZX1s2zHxRg== + dependencies: + resolve-pkg-maps "^1.0.0" + glob-parent@^5.1.2, glob-parent@~5.1.2: version "5.1.2" resolved "https://registry.yarnpkg.com/glob-parent/-/glob-parent-5.1.2.tgz#869832c58034fe68a4093c17dc15e8340d8401c4" @@ -1590,6 +1631,11 @@ gopd@^1.0.1: dependencies: get-intrinsic "^1.1.3" +graceful-fs@^4.2.4: + version "4.2.11" + resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.11.tgz#4183e4e8bf08bb6e05bbb2f7d2e0c8f712ca40e3" + integrity sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ== + graphemer@^1.4.0: version "1.4.0" resolved "https://registry.yarnpkg.com/graphemer/-/graphemer-1.4.0.tgz#fb2f1d55e0e3a1849aeffc90c4fa0dd53a0e66c6" @@ -1742,6 +1788,13 @@ is-boolean-object@^1.1.0: dependencies: call-bind "^1.0.2" +is-bun-module@^1.0.2: + version "1.3.0" + resolved "https://registry.yarnpkg.com/is-bun-module/-/is-bun-module-1.3.0.tgz#ea4d24fdebfcecc98e81bcbcb506827fee288760" + integrity sha512-DgXeu5UWI0IsMQundYb5UAOzm6G2eVnarJ0byP6Tm55iZNKceD59LNPA2L4VvsScTtHcw0yEkVwSf7PC+QoLSA== + dependencies: + semver "^7.6.3" + is-callable@^1.1.3, is-callable@^1.2.7: version "1.2.7" resolved "https://registry.yarnpkg.com/is-callable/-/is-callable-1.2.7.tgz#3bc2a85ea742d9e36205dcacdd72ca1fdc51b055" @@ -2359,6 +2412,11 @@ resolve-from@^4.0.0: resolved "https://registry.yarnpkg.com/resolve-from/-/resolve-from-4.0.0.tgz#4abcd852ad32dd7baabfe9b40e00a36db5f392e6" integrity sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g== +resolve-pkg-maps@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/resolve-pkg-maps/-/resolve-pkg-maps-1.0.0.tgz#616b3dc2c57056b5588c31cdf4b3d64db133720f" + integrity sha512-seS2Tj26TBVOC2NIc2rOe2y2ZO7efxITtLZcGSOnHHNOQ7CkiUBfw0Iw2ck6xkIhPwLhKNLS8BO+hEpngQlqzw== + resolve@^1.22.4: version "1.22.8" resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.22.8.tgz#b6c87a9f2aa06dfab52e3d70ac8cde321fa5a48d" @@ -2431,7 +2489,7 @@ semver@^6.3.1: resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.1.tgz#556d2ef8689146e46dcea4bfdd095f3434dffcb4" integrity sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA== -semver@^7.6.0: +semver@^7.6.0, semver@^7.6.3: version "7.6.3" resolved "https://registry.yarnpkg.com/semver/-/semver-7.6.3.tgz#980f7b5550bc175fb4dc09403085627f9eb33143" integrity sha512-oVekP1cKtI+CTDvHWYFUcMtsK/00wmAEfyqKfNdARm8u1wNVhSgaX7A8d4UuIlUI5e84iEwOhs7ZPYRmzU9U6A== @@ -2584,6 +2642,11 @@ synckit@^0.9.1: "@pkgr/core" "^0.1.0" tslib "^2.6.2" +tapable@^2.2.0: + version "2.2.1" + resolved "https://registry.yarnpkg.com/tapable/-/tapable-2.2.1.tgz#1967a73ef4060a82f12ab96af86d52fdb76eeca0" + integrity sha512-GNzQvQTOIP6RyTfE2Qxb8ZVlNmw0n88vp1szwWRimP02mnTsx3Wtn5qRdqY9w2XduFNUgvOwhNnQsjwCp+kqaQ== + to-regex-range@^5.0.1: version "5.0.1" resolved "https://registry.yarnpkg.com/to-regex-range/-/to-regex-range-5.0.1.tgz#1648c44aae7c8d988a326018ed72f5b4dd0392e4" @@ -2744,6 +2807,11 @@ unbox-primitive@^1.0.2: has-symbols "^1.0.3" which-boxed-primitive "^1.0.2" +undici-types@~5.26.4: + version "5.26.5" + resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-5.26.5.tgz#bcd539893d00b56e964fd2657a4866b221a65617" + integrity sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA== + universal-user-agent@^6.0.0: version "6.0.0" resolved "https://registry.yarnpkg.com/universal-user-agent/-/universal-user-agent-6.0.0.tgz#3381f8503b251c0d9cd21bc1de939ec9df5480ee"