one
Version:
One is a new React Framework that makes Vite serve both native and web.
84 lines (82 loc) • 3.8 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("fs"), 1),
path = __toESM(require("path"), 1);
function getBundleIdFromConfig(root) {
var appJsonPath = path.join(root, "app.json");
if (fs.existsSync(appJsonPath)) try {
var _appConfig_expo_ios,
_appConfig_expo,
_appConfig_expo_android,
_appConfig_expo1,
_appConfig_expo2,
_appConfig_expo3,
appConfig = JSON.parse(fs.readFileSync(appJsonPath, "utf-8"));
return !((_appConfig_expo = appConfig.expo) === null || _appConfig_expo === void 0 || (_appConfig_expo_ios = _appConfig_expo.ios) === null || _appConfig_expo_ios === void 0) && _appConfig_expo_ios.bundleIdentifier ? appConfig.expo.ios.bundleIdentifier : !((_appConfig_expo1 = appConfig.expo) === null || _appConfig_expo1 === void 0 || (_appConfig_expo_android = _appConfig_expo1.android) === null || _appConfig_expo_android === void 0) && _appConfig_expo_android.package ? appConfig.expo.android.package : !((_appConfig_expo2 = appConfig.expo) === null || _appConfig_expo2 === void 0) && _appConfig_expo2.slug ? appConfig.expo.slug : !((_appConfig_expo3 = appConfig.expo) === null || _appConfig_expo3 === void 0) && _appConfig_expo3.name ? appConfig.expo.name.toLowerCase().replace(/\s+/g, "-") : appConfig.name ? appConfig.name.toLowerCase().replace(/\s+/g, "-") : void 0;
} catch {
return;
}
}
var MAX_PORT = 65535;
function getAvailablePort(preferredPort, excludePort) {
return new Promise(function (resolve, reject) {
import("net").then(function (netModule) {
var tryPort = function (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;
}
var server = netModule.createServer();
server.once("error", function () {
server.close(), tryPort(port + 1);
}), server.once("listening", function () {
server.close(function () {
resolve(port);
});
}), server.listen(port, "0.0.0.0");
};
tryPort(preferredPort);
});
});
}
//# sourceMappingURL=utils.native.js.map