11import * as fs from "node:fs" ;
22import * as path from "node:path" ;
33import * as os from "node:os" ;
4+ import * as module from "node:module" ;
5+ import { isMainThread } from "node:worker_threads" ;
46import { exec , writeJson } from "../src/utils.ts" ;
57
68export interface DenoJson {
@@ -10,6 +12,16 @@ export interface DenoJson {
1012 license : string ;
1113}
1214
15+ /**
16+ * By default when node run ts file it's in ESM context so __dirname is not defined.
17+ * But we use it in source code and `tsc` transpiles to ESM/CJS
18+ * So we need to deifnefpr test context.
19+ */
20+ if ( isMainThread && "register" in module ) {
21+ const __dirname = path . dirname ( new URL ( import . meta. url ) . pathname ) ;
22+ globalThis . __dirname = __dirname ;
23+ }
24+
1325/**
1426 * This sets the `packageManager` field in the `package.json` of the
1527 * specified directory to be the latest modern stable version of yarn.
@@ -25,10 +37,18 @@ export async function runJsr(
2537 captureOutput = false ,
2638) {
2739 const bin = path . resolve ( "src" , "bin.ts" ) ;
40+ const testutils = path . resolve ( "test" , "test_utils.ts" ) ;
2841
2942 return await exec (
3043 "node" ,
31- [ "--no-warnings" , "--experimental-strip-types" , bin , ...args ] ,
44+ [
45+ "--no-warnings" ,
46+ "--import" ,
47+ testutils ,
48+ "--experimental-strip-types" ,
49+ bin ,
50+ ...args ,
51+ ] ,
3252 cwd ,
3353 {
3454 ...process . env ,
0 commit comments