one
Version:
One is a new React Framework that makes Vite serve both native and web.
102 lines (100 loc) • 4.01 kB
JavaScript
;
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all) __defProp(target, name, {
get: all[name],
enumerable: true
});
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from)) if (!__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: true
}) : target, mod));
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
value: true
}), mod);
var utils_exports = {};
__export(utils_exports, {
getAvailablePort: () => getAvailablePort,
getBundleIdFromConfig: () => getBundleIdFromConfig
});
module.exports = __toCommonJS(utils_exports);
var fs = __toESM(require("fs"), 1);
var path = __toESM(require("path"), 1);
function getBundleIdFromConfig(root) {
var appJsonPath = path.join(root, "app.json");
if (!fs.existsSync(appJsonPath)) {
return void 0;
}
try {
var _appConfig_expo_ios, _appConfig_expo, _appConfig_expo_android, _appConfig_expo1, _appConfig_expo2, _appConfig_expo3;
var appConfig = JSON.parse(fs.readFileSync(appJsonPath, "utf-8"));
if ((_appConfig_expo = appConfig.expo) === null || _appConfig_expo === void 0 ? void 0 : (_appConfig_expo_ios = _appConfig_expo.ios) === null || _appConfig_expo_ios === void 0 ? void 0 : _appConfig_expo_ios.bundleIdentifier) {
return appConfig.expo.ios.bundleIdentifier;
}
if ((_appConfig_expo1 = appConfig.expo) === null || _appConfig_expo1 === void 0 ? void 0 : (_appConfig_expo_android = _appConfig_expo1.android) === null || _appConfig_expo_android === void 0 ? void 0 : _appConfig_expo_android.package) {
return appConfig.expo.android.package;
}
if ((_appConfig_expo2 = appConfig.expo) === null || _appConfig_expo2 === void 0 ? void 0 : _appConfig_expo2.slug) {
return appConfig.expo.slug;
}
if ((_appConfig_expo3 = appConfig.expo) === null || _appConfig_expo3 === void 0 ? void 0 : _appConfig_expo3.name) {
return appConfig.expo.name.toLowerCase().replace(/\s+/g, "-");
}
if (appConfig.name) {
return appConfig.name.toLowerCase().replace(/\s+/g, "-");
}
return void 0;
} catch (unused) {
return void 0;
}
}
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