one
Version:
One is a new React Framework that makes Vite serve both native and web.
69 lines (68 loc) • 3.09 kB
JavaScript
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf, __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: !0 });
}, __copyProps = (to, from, except, desc) => {
if (from && typeof from == "object" || typeof from == "function")
for (let key of __getOwnPropNames(from))
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target,
mod
)), __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
var utils_exports = {};
__export(utils_exports, {
getAvailablePort: () => getAvailablePort,
getBundleIdFromConfig: () => getBundleIdFromConfig
});
module.exports = __toCommonJS(utils_exports);
var fs = __toESM(require("node:fs"), 1), path = __toESM(require("node:path"), 1);
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);
});
});
}
//# sourceMappingURL=utils.js.map