From 726f3da532a3bd3f3079ee4865029822ea2e8a77 Mon Sep 17 00:00:00 2001 From: Jason Slavin Date: Wed, 19 Jun 2024 13:01:39 -0700 Subject: [PATCH] Places the set/getLibs functions in script.js and removes utils dependency. Leaves utils.js as other code in our repo calls getLibs --- scripts/scripts.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/scripts/scripts.js b/scripts/scripts.js index 533c05d..3eb23f1 100644 --- a/scripts/scripts.js +++ b/scripts/scripts.js @@ -1,5 +1,3 @@ -import { setLibs } from './utils.js'; - const LIBS = '/libs'; const STYLES = ['/styles/styles.css']; const CONFIG = { @@ -157,6 +155,22 @@ const loadStyle = (path) => { eagerLoad(marquee.querySelector('img')); }()); +export const [setLibs, getLibs] = (() => { + let libs; + return [ + (prodLibs, location) => { + libs = (() => { + const { hostname, search } = location || window.location; + if (!(hostname.includes('.hlx.') || hostname.includes('local'))) return prodLibs; + const branch = new URLSearchParams(search).get('milolibs') || 'main'; + if (branch === 'local') return 'http://localhost:6456/libs'; + return branch.includes('--') ? `https://${branch}.hlx.live/libs` : `https://${branch}--milo--adobecom.hlx.live/libs`; + })(); + return libs; + }, () => libs, + ]; +})(); + const miloLibs = setLibs(LIBS); (function loadStyles() {