one
Version:
One is a new React Framework that makes Vite serve both native and web.
46 lines (45 loc) • 1.58 kB
JavaScript
import * as fs from "node:fs";
import * as path from "node:path";
function getBundleIdFromConfig(root) {
const appJsonPath = path.join(root, "app.json");
if (fs.existsSync(appJsonPath))
try {
const appConfig = JSON.parse(fs.readFileSync(appJsonPath, "utf-8"));
return appConfig.expo?.ios?.bundleIdentifier ? appConfig.expo.ios.bundleIdentifier : appConfig.expo?.android?.package ? appConfig.expo.android.package : appConfig.expo?.slug ? appConfig.expo.slug : appConfig.expo?.name ? appConfig.expo.name.toLowerCase().replace(/\s+/g, "-") : appConfig.name ? appConfig.name.toLowerCase().replace(/\s+/g, "-") : void 0;
} catch {
return;
}
}
const MAX_PORT = 65535;
function getAvailablePort(preferredPort, excludePort) {
return new Promise((resolve, reject) => {
import("node:net").then((netModule) => {
const tryPort = (port) => {
if (port > MAX_PORT) {
reject(
new Error(`No available port found between ${preferredPort} and ${MAX_PORT}`)
);
return;
}
if (port === excludePort) {
tryPort(port + 1);
return;
}
const server = netModule.createServer();
server.once("error", () => {
server.close(), tryPort(port + 1);
}), server.once("listening", () => {
server.close(() => {
resolve(port);
});
}), server.listen(port, "0.0.0.0");
};
tryPort(preferredPort);
});
});
}
export {
getAvailablePort,
getBundleIdFromConfig
};
//# sourceMappingURL=utils.js.map