one
Version:
One is a new React Framework that makes Vite serve both native and web.
78 lines (76 loc) • 2.73 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
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 __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
value: true
}), mod);
var url_exports = {};
__export(url_exports, {
getStaticUrlFromOneRouter: () => getStaticUrlFromOneRouter
});
module.exports = __toCommonJS(url_exports);
var protocolWarningString = `{ plugins: [["router", { origin: "...<URL>..." }]] }`;
function memoize(fn) {
var cache = {};
return function () {
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
var key = JSON.stringify(args);
if (cache[key]) {
return cache[key];
}
var result = fn(...args);
cache[key] = result;
return result;
};
}
function sanitizeUrl(url) {
var _parsed, _protocol;
var parsed = new URL(url);
var validProtocol = !parsed.protocol || parsed.protocol === "http:" || parsed.protocol === "https:";
if (!validProtocol) {
throwOrAlert(`One Head: Native origin has invalid protocol "${parsed.protocol}" for URL in Config: ${protocolWarningString}.`);
}
parsed.pathname = "";
parsed.search = "";
parsed.hash = "";
(_protocol = (_parsed = parsed).protocol) !== null && _protocol !== void 0 ? _protocol : _parsed.protocol = "https:";
return parsed.toString().replace(/\/$/, "");
}
var memoSanitizeUrl = memoize(sanitizeUrl);
function getUrlFromConstants() {
var origin = process.env.One_ORIGIN;
if (!origin) {
throwOrAlert(`One Head: Add the handoff origin to the Config (requires rebuild). Add the Config Plugin ${protocolWarningString}, where \`origin\` is the hosted URL.`);
return "https://expo.dev";
}
if (!origin.match(/^http(s)?:\/\//)) {
console.warn(`One Head: origin "${origin}" is missing a \`https://\` protocol. ${protocolWarningString}.`);
}
return memoSanitizeUrl(origin);
}
function throwOrAlert(msg) {
console.warn(`TODO FIX: ${msg}`);
}
function getStaticUrlFromOneRouter(pathname) {
return getUrlFromConstants() + pathname;
}
//# sourceMappingURL=url.native.js.map