8000 chore: always use pnpm to install wasm binding on webcontainer · unrs/unrs-resolver@d20ddda · GitHub
[go: up one dir, main page]

Skip to content

Commit d20ddda

Browse files
committed
chore: always use pnpm to install wasm binding on webcontainer
1 parent bcd9da6 commit d20ddda

File tree

1 file changed

+33
-43
lines changed

1 file changed

+33
-43
lines changed

napi/fallback.js

Lines changed: 33 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -5,37 +5,6 @@ const path = require('node:path')
55

66
const { version } = require('unrs-resolver/package.json')
77

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-
398
if (process.versions.webcontainer) {
409
const baseDir = path.resolve(os.tmpdir(), `unrs-resolver-${version}`)
4110

@@ -50,24 +19,13 @@ if (process.versions.webcontainer) {
5019
fs.rmSync(baseDir, { recursive: true, force: true })
5120
fs.mkdirSync(baseDir, { recursive: true })
5221

53-
fs.writeFileSync(path.resolve(baseDir, 'package.json'), JSON.stringify({}))
54-
5522
const bindingPkg = `${bindingPkgName}@${version}`
5623

5724
console.log(
5825
`[unrs-resolver] Downloading \`${bindingPkg}\` on WebContainer...`,
5926
)
6027

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], {
7129
cwd: baseDir,
7230
stdio: 'inherit',
7331
})
@@ -78,6 +36,38 @@ if (process.versions.webcontainer) {
7836
return
7937
}
8038

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+
8171
const { command, args } = constructCommand(executor, [
8272
'napi-postinstall',
8373
'unrs-resolver',

0 commit comments

Comments
 (0)
0