@@ -5,37 +5,6 @@ const path = require('node:path')
5
5
6
6
const { version } = require ( 'unrs-resolver/package.json' )
7
7
8
- const userAgent =
9
- ( process . env . npm_config_user_agent || '' ) . split ( '/' ) [ 0 ] || 'npm'
10
-
11
- const EXECUTORS = {
12
- npm : 'npx' ,
13
- pnpm : 'pnpm' ,
14
- yarn : 'yarn' ,
15
- bun : 'bun' ,
16
- deno : ( args ) => [ 'deno' , 'run' , `npm:${ args [ 0 ] } ` , ...args . slice ( 1 ) ] ,
17
- }
18
-
19
- const executor = EXECUTORS [ userAgent ]
20
-
21
- if ( ! executor ) {
22
- console . error (
23
- `Unsupported package manager: ${ userAgent } . Supported managers are: ${ Object . keys (
24
- EXECUTORS ,
25
- ) . join ( ', ' ) } .`,
26
- )
27
- process . exitCode = 1
28
- return
29
- }
30
-
31
- function constructCommand ( value , args ) {
32
- const list = typeof value === 'function' ? value ( args ) : [ value ] . concat ( args )
33
- return {
34
- command : list [ 0 ] ,
35
- args : list . slice ( 1 ) ,
36
- }
37
- }
38
-
39
8
if ( process . versions . webcontainer ) {
40
9
const baseDir = path . resolve ( os . tmpdir ( ) , `unrs-resolver-${ version } ` )
41
10
@@ -50,24 +19,13 @@ if (process.versions.webcontainer) {
50
19
fs . rmSync ( baseDir , { recursive : true , force : true } )
51
20
fs . mkdirSync ( baseDir , { recursive : true } )
52
21
53
- fs . writeFileSync ( path . resolve ( baseDir , 'package.json' ) , JSON . stringify ( { } ) )
54
-
55
22
const bindingPkg = `${ bindingPkgName } @${ version } `
56
23
57
24
console . log (
58
25
`[unrs-resolver] Downloading \`${ bindingPkg } \` on WebContainer...` ,
59
26
)
60
27
61
- const installer =
62
- userAgent === 'npm'
63
- ? [ userAgent , 'i' ]
64
- : userAgent === 'deno'
65
- ? ( args ) => [ 'deno' , 'add' , `npm:${ args [ 0 ] } ` , ...args . slice ( 1 ) ]
66
- : [ userAgent , 'add' ]
67
-
68
- const { command, args } = constructCommand ( installer , [ bindingPkg ] )
69
-
70
- execFileSync ( command , args , {
28
+ execFileSync ( 'pnpm' , [ 'i' , bindingPkg ] , {
71
29
cwd : baseDir ,
72
30
stdio : 'inherit' ,
73
31
} )
@@ -78,6 +36,38 @@ if (process.versions.webcontainer) {
78
36
return
79
37
}
80
38
39
+ const userAgent =
40
+ ( process . env . npm_config_user_agent || '' ) . split ( '/' ) [ 0 ] || 'npm'
41
+
42
+ const EXECUTORS = {
43
+ npm : 'npx' ,
44
+ pnpm : 'pnpm' ,
45
+ yarn : 'yarn' ,
46
+ bun : 'bun' ,
47
+ deno : ( args ) => [ 'deno' , 'run' , `npm:${ args [ 0 ] } ` , ...args . slice ( 1 ) ] ,
48
+ }
49
+
50
+ const executor = EXECUTORS [ userAgent ]
51
+
52
+ if ( ! executor ) {
53
+ console . error (
54
+ `Unsupported package manager: ${ userAgent } . Supported managers are: ${ Object . keys (
55
+ EXECUTORS ,
56
+ ) . join ( ', ' ) } .`,
57
+ )
58
+ process . exitCode = 1
59
+ return
60
+ }
61
+
62
+ function constructCommand ( value , args ) {
63
+ const list =
64
+ typeof value === 'function' ? value ( args ) : [ ] . concat ( value , args )
65
+ return {
66
+ command : list [ 0 ] ,
67
+ args : list . slice ( 1 ) ,
68
+ }
69
+ }
70
+
81
71
const { command, args } = constructCommand ( executor , [
82
72
'napi-postinstall' ,
83
73
'unrs-resolver' ,
0 commit comments