Skip to content
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
20 changes: 9 additions & 11 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
14 changes: 8 additions & 6 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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<CoverageOptions>(content);
if (isYaml(filePath)) return yamlParse<CoverageOptions>(content);
return JSONC.parse<CoverageOptions>(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]
Expand All @@ -65,4 +65,6 @@ export const loadConfig = (
return parseConfig(content, file);
} catch {}
}

return Object.create(null);
};
10 changes: 4 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading