diff --git a/package-lock.json b/package-lock.json index 8e7fa07..29fc969 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,28 +8,33 @@ "name": "@pokujs/coverage", "version": "0.8.1", "license": "MIT", + "dependencies": { + "acorn": "^8.16.0", + "jsonc.min": "^1.1.2", + "toml.min": "^1.0.0", + "yaml.min": "^1.0.0" + }, + "bin": { + "coverage": "lib/bin/cli.js" + }, "devDependencies": { "@ianvs/prettier-plugin-sort-imports": "^4.7.1", "@jridgewell/trace-mapping": "^0.3.31", "@sveltejs/acorn-typescript": "^1.0.9", "@types/lcov-parse": "^1.0.2", "@types/node": "^25.6.0", - "acorn": "^8.16.0", "cross-env": "^10.1.0", "domhandler": "^6.0.1", "dts-bundle-generator": "^9.5.1", "esbuild": "^0.28.0", "fast-xml-parser": "^5.7.2", "htmlparser2": "^12.0.0", - "jsonc.min": "^1.1.2", "lcov-parse": "^1.0.0", "packages-update": "^2.0.0", "poku": "^4.3.0", "prettier": "^3.8.3", - "toml.min": "^1.0.0", "tsx": "^4.21.0", - "typescript": "^6.0.3", - "yaml.min": "^1.0.0" + "typescript": "^6.0.3" }, "engines": { "node": ">=18.x.x" @@ -40,9 +45,12 @@ }, "peerDependencies": { "poku": "^4.3.0", - "typescript": "^6.0.3" + "typescript": "^5.9.3 || ^6.0.3" }, "peerDependenciesMeta": { + "poku": { + "optional": true + }, "typescript": { "optional": true } @@ -741,7 +749,6 @@ "version": "8.16.0", "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.16.0.tgz", "integrity": "sha512-UVJyE9MttOsBQIDKw1skb9nAwQuR5wuGD3+82K6JgJlm/Y+KI92oNsMNGZCYdDsVtRHSak0pcV5Dno5+4jh9sw==", - "dev": true, "license": "MIT", "bin": { "acorn": "bin/acorn" @@ -1162,7 +1169,6 @@ "version": "1.1.2", "resolved": "https://registry.npmjs.org/jsonc.min/-/jsonc.min-1.1.2.tgz", "integrity": "sha512-8DzkaJnjZF8Tm/pozI77pH2Gd5JaKmk/JaO/cGXxQMtzzxG3DBg7SLEoHPrtU1KY386o5jOwrdgsGHVAR05kCA==", - "dev": true, "license": "MIT", "engines": { "bun": ">=1.0.0", @@ -1375,7 +1381,6 @@ "version": "1.0.0", "resolved": "https://registry.npmjs.org/toml.min/-/toml.min-1.0.0.tgz", "integrity": "sha512-AxGMz8dc0gx3xGYGFzs9SrcqamCsJEUQ1D6whZgfeJWCHvytqhsl2OExMc2xEWjy1S51HHuap0r6bK4O+CcjiA==", - "dev": true, "license": "MIT", "engines": { "node": ">=18.x.x" @@ -1958,7 +1963,6 @@ "version": "1.0.0", "resolved": "https://registry.npmjs.org/yaml.min/-/yaml.min-1.0.0.tgz", "integrity": "sha512-p/mX2R20rnblQo57YJHcOpFtbut5JBeq0PLMn2WXQn9XLRMGmisMRQk/ug1rnpA4eBKaTr9O7H332hdIwMUhxA==", - "dev": true, "license": "MIT", "engines": { "node": ">=18.0.0" diff --git a/package.json b/package.json index d114730..a16eb98 100644 --- a/package.json +++ b/package.json @@ -3,9 +3,18 @@ "private": false, "version": "0.8.1", "description": "☔️ The world's first V8 and JSC coverage tool to generate reports for Node.js, Bun, Deno, and TypeScript at the same time.", - "type": "commonjs", + "type": "module", "main": "./lib/index.js", + "module": "./lib/index.js", "types": "./lib/index.d.ts", + "exports": { + ".": { + "types": "./lib/index.d.ts", + "import": "./lib/index.js", + "require": "./lib/index.cjs", + "default": "./lib/index.js" + } + }, "bin": { "coverage": "./lib/bin/cli.js" }, @@ -47,7 +56,7 @@ }, "peerDependencies": { "poku": "^4.3.0", - "typescript": "^6.0.3" + "typescript": "^5.9.3 || ^6.0.3" }, "peerDependenciesMeta": { "poku": { @@ -63,22 +72,18 @@ "@sveltejs/acorn-typescript": "^1.0.9", "@types/lcov-parse": "^1.0.2", "@types/node": "^25.6.0", - "acorn": "^8.16.0", "cross-env": "^10.1.0", "domhandler": "^6.0.1", "dts-bundle-generator": "^9.5.1", "esbuild": "^0.28.0", "fast-xml-parser": "^5.7.2", "htmlparser2": "^12.0.0", - "jsonc.min": "^1.1.2", "lcov-parse": "^1.0.0", "packages-update": "^2.0.0", "poku": "^4.3.0", "prettier": "^3.8.3", - "toml.min": "^1.0.0", "tsx": "^4.21.0", - "typescript": "^6.0.3", - "yaml.min": "^1.0.0" + "typescript": "^6.0.3" }, "publishConfig": { "access": "public" @@ -124,5 +129,11 @@ "monocart-coverage-reports", "monocart", "one-double-zero" - ] + ], + "dependencies": { + "acorn": "^8.16.0", + "jsonc.min": "^1.1.2", + "toml.min": "^1.0.0", + "yaml.min": "^1.0.0" + } } diff --git a/poku.config.js b/poku.config.js index aaec8e9..fdef203 100644 --- a/poku.config.js +++ b/poku.config.js @@ -1,18 +1,19 @@ // @ts-check -'use strict'; - -const { cp, readdir, rm } = require('node:fs/promises'); -const { homedir, platform } = require('node:os'); -const { basename, join } = require('node:path'); -const { env } = require('node:process'); -const { defineConfig } = require('poku'); -const { coverage } = require('./lib/index.js'); - -const fixturesRoot = join(__dirname, 'test', '__fixtures__', 'e2e'); -const snapshotsRoot = join(__dirname, 'test', '__snapshots__', 'e2e'); +import { cp, readdir, rm } from 'node:fs/promises'; +import { homedir, platform } from 'node:os'; +import { basename, dirname, join } from 'node:path'; +import { env } from 'node:process'; +import { fileURLToPath } from 'node:url'; +import { defineConfig } from 'poku'; +import { coverage } from './lib/index.js'; + +const rootDir = dirname(fileURLToPath(import.meta.url)); + +const fixturesRoot = join(rootDir, 'test', '__fixtures__', 'e2e'); +const snapshotsRoot = join(rootDir, 'test', '__snapshots__', 'e2e'); const reportersResourcesRoot = join( - __dirname, + rootDir, 'test', '__resources__', 'e2e', @@ -117,7 +118,7 @@ const clearPlatformSnapshots = async (directory = snapshotsRoot) => { ); }; -module.exports = defineConfig({ +export default defineConfig({ include: ['test/e2e'], reporter: 'compact', timeout: 30000, diff --git a/scripts/lint-types.sh b/scripts/lint-types.sh index df3acde..333198a 100755 --- a/scripts/lint-types.sh +++ b/scripts/lint-types.sh @@ -27,7 +27,7 @@ fi doubleCastHits="$( cd "$repositoryRoot" && find . \ - \( -path './.git' -o -path './node_modules' -o -path './lib' -o -path './tools/debug' \) -prune -o \ + \( -path './.git' -o -name 'node_modules' -o -path './lib' -o -path './tools/debug' \) -prune -o \ -type f \( -name '*.ts' -o -name '*.mts' -o -name '*.cts' \) \ ! -name "$(basename "${BASH_SOURCE[0]}")" \ -print0 \ diff --git a/src/converters/shared/ast-cache.ts b/src/converters/shared/ast-cache.ts index 11e4be6..80a4144 100644 --- a/src/converters/shared/ast-cache.ts +++ b/src/converters/shared/ast-cache.ts @@ -1,5 +1,4 @@ import type { Options, Program } from 'acorn'; -// @ts-expect-error: ESM-only package import { tsPlugin } from '@sveltejs/acorn-typescript'; import { Parser } from 'acorn'; diff --git a/src/reporters/html-spa/copy-assets.ts b/src/reporters/html-spa/copy-assets.ts index 679c793..e126018 100644 --- a/src/reporters/html-spa/copy-assets.ts +++ b/src/reporters/html-spa/copy-assets.ts @@ -1,4 +1,5 @@ import { join } from 'node:path'; +import { moduleDir } from '../../utils/module-dir.js'; import { copyAssetSet } from '../shared/html/copy-assets.js'; import { HTML_ASSET_FILENAMES, @@ -12,7 +13,7 @@ const SPA_ASSET_FILENAMES: readonly string[] = [ ]; const spaAssetsDir = (): string => - join(__dirname, '..', 'resources', 'html-spa'); + join(moduleDir.from(import.meta.url), '..', 'resources', 'html-spa'); export const copyAssets = (reportsDir: string): void => { copyAssetSet(reportsDir, htmlAssetsDir(), HTML_ASSET_FILENAMES); diff --git a/src/reporters/shared/html/html-assets.ts b/src/reporters/shared/html/html-assets.ts index ff43463..bf78ed5 100644 --- a/src/reporters/shared/html/html-assets.ts +++ b/src/reporters/shared/html/html-assets.ts @@ -1,4 +1,5 @@ import { join } from 'node:path'; +import { moduleDir } from '../../../utils/module-dir.js'; export const HTML_ASSET_FILENAMES: readonly string[] = [ 'base.css', @@ -11,4 +12,4 @@ export const HTML_ASSET_FILENAMES: readonly string[] = [ ]; export const htmlAssetsDir = (): string => - join(__dirname, '..', 'resources', 'html'); + join(moduleDir.from(import.meta.url), '..', 'resources', 'html'); diff --git a/src/runtimes/bun.ts b/src/runtimes/bun.ts index fc848e5..4a0131f 100644 --- a/src/runtimes/bun.ts +++ b/src/runtimes/bun.ts @@ -4,6 +4,7 @@ import type { CoverageOptions, CoverageState } from '../@types/coverage.js'; import type { JscInspectorHandle } from '../@types/jsc.js'; import type { DataListener } from '../@types/runtimes.js'; import { join } from 'node:path'; +import { moduleDir } from '../utils/module-dir.js'; import { strings } from '../utils/strings.js'; import { jscInspector } from './bun/inspector.js'; import { FLUSH_MARKER } from './bun/marker.js'; @@ -12,7 +13,10 @@ import { lifecycle } from './lifecycle.js'; const INSPECTOR_URL_PATTERN = /ws:\/\/(?:\d{1,3}(?:\.\d{1,3}){3}|\[[0-9a-fA-F:]+\]|[A-Za-z0-9.-]+):\d{1,5}\/[A-Za-z0-9._-]+/; -const PRELOAD_SCRIPT_PATH = join(__dirname, 'preload-bun.js'); +const PRELOAD_SCRIPT_PATH = join( + moduleDir.from(import.meta.url), + 'preload-bun.js' +); const makeLineFilter = ( file: string, diff --git a/src/utils/module-dir.ts b/src/utils/module-dir.ts new file mode 100644 index 0000000..3600842 --- /dev/null +++ b/src/utils/module-dir.ts @@ -0,0 +1,6 @@ +import { dirname } from 'node:path'; +import { fileURLToPath } from 'node:url'; + +const from = (metaUrl: string): string => dirname(fileURLToPath(metaUrl)); + +export const moduleDir = { from } as const; diff --git a/tools/build.mts b/tools/build.mts index 70bc1da..67509e3 100644 --- a/tools/build.mts +++ b/tools/build.mts @@ -19,8 +19,15 @@ const buildOptions: BuildOptions = { target: 'node16', logLevel: 'info', treeShaking: true, - format: 'cjs', - external: ['jsonc.min', 'poku', 'poku/plugin', 'toml.min', 'yaml.min'], + minifySyntax: true, + external: [ + 'acorn', + 'jsonc.min', + 'poku', + 'poku/plugin', + 'toml.min', + 'yaml.min', + ], }; await rm('lib', { recursive: true, force: true }); @@ -28,22 +35,33 @@ await mkdir('lib', { recursive: true }); await Promise.all([ build({ ...buildOptions, + format: 'esm', entryPoints: ['src/index.ts'], outfile: 'lib/index.js', - minifySyntax: true, }), build({ ...buildOptions, + format: 'cjs', + entryPoints: ['src/index.ts'], + outfile: 'lib/index.cjs', + banner: { + js: "const __importMetaUrl = require('node:url').pathToFileURL(__filename).href;", + }, + define: { 'import.meta.url': '__importMetaUrl' }, + }), + build({ + ...buildOptions, + format: 'esm', entryPoints: ['src/runtimes/bun/preload.ts'], outfile: 'lib/preload-bun.js', minify: true, }), build({ ...buildOptions, + format: 'esm', entryPoints: ['src/bin/cli.ts'], outfile: 'lib/bin/cli.js', banner: { js: '#!/usr/bin/env node' }, - minifySyntax: true, external: ['../index.js'], }), writeFile('lib/index.d.ts', dtsBundle, 'utf-8'),