diff --git a/package-lock.json b/package-lock.json index 3278042..d204d0c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,7 +16,7 @@ "jsonc.min": "^1.1.2", "one-double-zero": "^1.1.1", "toml.min": "^0.1.3", - "yaml": "^2.8.3" + "yaml.min": "^1.0.0" }, "devDependencies": { "@ianvs/prettier-plugin-sort-imports": "^4.7.1", @@ -1737,19 +1737,17 @@ "node": ">=8" } }, - "node_modules/yaml": { - "version": "2.8.3", - "resolved": "https://registry.npmjs.org/yaml/-/yaml-2.8.3.tgz", - "integrity": "sha512-AvbaCLOO2Otw/lW5bmh9d/WEdcDFdQp2Z2ZUH3pX9U2ihyUY0nvLv7J6TrWowklRGPYbB/IuIMfYgxaCPg5Bpg==", - "license": "ISC", - "bin": { - "yaml": "bin.mjs" - }, + "node_modules/yaml.min": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/yaml.min/-/yaml.min-1.0.0.tgz", + "integrity": "sha512-p/mX2R20rnblQo57YJHcOpFtbut5JBeq0PLMn2WXQn9XLRMGmisMRQk/ug1rnpA4eBKaTr9O7H332hdIwMUhxA==", + "license": "MIT", "engines": { - "node": ">= 14.6" + "node": ">=18.0.0" }, "funding": { - "url": "https://github.com/sponsors/eemeli" + "type": "github", + "url": "https://github.com/sponsors/wellwelwel" } }, "node_modules/yocto-queue": { diff --git a/package.json b/package.json index d9eeb6c..9e5d152 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,7 @@ "jsonc.min": "^1.1.2", "one-double-zero": "^1.1.1", "toml.min": "^0.1.3", - "yaml": "^2.8.3" + "yaml.min": "^1.0.0" }, "peerDependencies": { "poku": "^4.1.0" diff --git a/src/config.ts b/src/config.ts index d873edc..69465e1 100644 --- a/src/config.ts +++ b/src/config.ts @@ -3,7 +3,7 @@ import { existsSync, readFileSync } from 'node:fs'; import { join } from 'node:path'; import { JSONC } from 'jsonc.min'; import { parse as tomlParse } from 'toml.min'; -import YAML from 'yaml'; +import { parse as yamlParse } from 'yaml.min'; const scriptExtensions = new Set([ '.js', @@ -31,16 +31,16 @@ const getExtension = (filePath: string): string => { }; const parseConfig = (content: string, filePath: string): CoverageOptions => { - if (isToml(filePath)) return tomlParse(content) as CoverageOptions; - if (isYaml(filePath)) return YAML.parse(content) as CoverageOptions; - return JSONC.parse(content) as CoverageOptions; + if (isToml(filePath)) return tomlParse(content); + if (isYaml(filePath)) return yamlParse(content); + return JSONC.parse(content); }; export const loadConfig = ( cwd: string, customPath?: string | false -): CoverageOptions | undefined => { - if (customPath === false) return; +): CoverageOptions => { + if (customPath === false) return Object.create(null); const expectedFiles = customPath ? [customPath] @@ -65,4 +65,6 @@ export const loadConfig = ( return parseConfig(content, file); } catch {} } + + return Object.create(null); }; diff --git a/src/index.ts b/src/index.ts index 02d94d7..73b823c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -125,24 +125,22 @@ export const coverage = ( setup(context) { if (options.requireFlag && !process.argv.includes('--coverage')) return; - enabled = true; - - cwd = context.cwd; - if (context.runtime !== 'node') console.warn( `[@pokujs/one-double-zero] V8 coverage is only supported on Node.js (current runtime: ${context.runtime}). Coverage data may not be collected.` ); + enabled = true; + cwd = context.cwd; + const cliConfig = process.argv .find((arg) => arg.startsWith('--coverageConfig')) ?.split('=')[1]; const resolvedConfig = cliConfig ?? options.config; - const fileConfig = loadConfig(context.cwd, resolvedConfig); - if (fileConfig) options = { ...fileConfig, ...options }; + options = { ...fileConfig, ...options }; originalEnv = process.env.NODE_V8_COVERAGE; tempDir = options.coverageDirectory