Skip to content

Commit f763f88

Browse files
authored
fix: windows reporter reference (#104)
1 parent 339c691 commit f763f88

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

borp.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@ import { findUp } from 'find-up'
66
import { mkdtemp, rm, readFile } from 'node:fs/promises'
77
import { createWriteStream } from 'node:fs'
88
import { finished } from 'node:stream/promises'
9-
import { join, relative } from 'node:path'
9+
import { join, relative, resolve } from 'node:path'
1010
import posix from 'node:path/posix'
1111
import runWithTypeScript from './lib/run.js'
1212
import githubReporter from '@reporters/github'
1313
import { Report } from 'c8'
1414
import { checkCoverages } from 'c8/lib/commands/check-coverage.js'
1515
import os from 'node:os'
1616
import { execa } from 'execa'
17+
import { pathToFileURL } from 'node:url'
1718

1819
/* c8 ignore next 4 */
1920
process.on('unhandledRejection', (err) => {
@@ -120,7 +121,12 @@ try {
120121
} else {
121122
try {
122123
// Try to load a custom reporter from a file relative to the process.
123-
const modPath = join(process.cwd(), name.replace(/^['"]/, '').replace(/['"]$/, ''))
124+
let modPath = resolve(join(process.cwd(), name.replace(/^['"]/, '').replace(/['"]$/, '')))
125+
if (process.platform === 'win32') {
126+
// On Windows, absolute paths must be valid file:// URLs
127+
modPath = pathToFileURL(modPath).href
128+
}
129+
124130
Ctor = await import(modPath).then((m) => m.default || m)
125131
} catch {
126132
// Fallback to trying to load the reporter from node_modules resolution.

0 commit comments

Comments
 (0)