Skip to content

Commit f76fd45

Browse files
authored
Update setup.js
1 parent 28de9f0 commit f76fd45

1 file changed

Lines changed: 30 additions & 1 deletion

File tree

utils/setup.js

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,37 @@ const { execSync } = require("node:child_process");
1111
const fs = require("node:fs");
1212
const path = require("node:path");
1313
const PLATFORM_FILES = [".DS_Store"];
14+
const PACKAGE_MANAGERS = new Set(["bun", "npm", "pnpm", "yarn"]);
1415

15-
execSync("npm install", { stdio: "inherit" });
16+
function getPackageManager() {
17+
const userAgent = process.env.npm_config_user_agent;
18+
const packageManager = userAgent?.split("/")[0];
19+
20+
if (PACKAGE_MANAGERS.has(packageManager)) {
21+
return packageManager;
22+
}
23+
24+
return "npm";
25+
}
26+
27+
function installDependencies() {
28+
const packageManager = getPackageManager();
29+
30+
try {
31+
execSync(`${packageManager} install`, { stdio: "inherit" });
32+
} catch (error) {
33+
if (packageManager === "npm") {
34+
throw error;
35+
}
36+
37+
console.warn(
38+
`Failed to install dependencies with ${packageManager}. Falling back to npm.`,
39+
);
40+
execSync("npm install", { stdio: "inherit" });
41+
}
42+
}
43+
44+
installDependencies();
1645
try {
1746
execSync("cordova platform add android", { stdio: "inherit" });
1847
} catch (error) {

0 commit comments

Comments
 (0)