1
1
import * as fs from "node:fs" ;
2
2
import * as path from "node:path" ;
3
3
import * as os from "node:os" ;
4
+ import * as module from "node:module" ;
5
+ import { isMainThread } from "node:worker_threads" ;
4
6
import { exec , writeJson } from "../src/utils.ts" ;
5
7
6
8
export interface DenoJson {
@@ -10,6 +12,16 @@ export interface DenoJson {
10
12
license : string ;
11
13
}
12
14
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
+
13
25
/**
14
26
* This sets the `packageManager` field in the `package.json` of the
15
27
* specified directory to be the latest modern stable version of yarn.
@@ -25,10 +37,18 @@ export async function runJsr(
25
37
captureOutput = false ,
26
38
) {
27
39
const bin = path . resolve ( "src" , "bin.ts" ) ;
40
+ const testutils = path . resolve ( "test" , "test_utils.ts" ) ;
28
41
29
42
return await exec (
30
43
"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
+ ] ,
32
52
cwd ,
33
53
{
34
54
...process . env ,
0 commit comments