Skip to content

Commit

Permalink
Merge branch 'stage' into MWPW-163785
Browse files Browse the repository at this point in the history
  • Loading branch information
TsayAdobe authored Jan 2, 2025
2 parents 735d422 + 99ca9d0 commit 4ef9689
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 39 deletions.
15 changes: 6 additions & 9 deletions acrobat/blocks/unity/unity.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,13 @@ export const localeMap = {
};

function getUnityLibs(prodLibs = '/unitylibs') {
const { hostname } = window.location;
if (!hostname.includes('hlx.page')
&& !hostname.includes('hlx.live')
&& !hostname.includes('localhost')) {
return prodLibs;
}
const { hostname, search } = window.location;
if (!/\.hlx\.|\.aem\.|local|stage/.test(hostname)) return prodLibs;
// eslint-disable-next-line compat/compat
const branch = new URLSearchParams(window.location.search).get('unitylibs') || 'main';
if (branch.indexOf('--') > -1) return `https://${branch}.hlx.live/unitylibs`;
return `https://${branch}--unity--adobecom.hlx.live/unitylibs`;
const branch = new URLSearchParams(search).get('unitylibs') || 'main';
if (branch === 'main' && hostname === 'www.stage.adobe.com') return prodLibs;
const env = hostname.includes('.hlx.') ? 'hlx' : 'aem';
return `https://${branch}${branch.includes('--') ? '' : '--unity--adobecom'}.${env}.live/unitylibs`;
}

export default async function init(el) {
Expand Down
2 changes: 1 addition & 1 deletion acrobat/scripts/contentSecurityPolicy/dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ const scriptSrc = [
'*.aem.page',
'*.aem.live',
'tr.snapchat.com',
'\'sha256-XZLMiKjK7kZsMSJR/aV6U3pMxjqlvU6v3tJSIimxjHs=\'',
'\'sha256-nAigApwVAFaAG381OAPIUWINK3JzGgUcb2TZvwX6MK8=\'',
';',
];

Expand Down
2 changes: 1 addition & 1 deletion acrobat/scripts/contentSecurityPolicy/prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ const scriptSrc = [
'rum.hlx.page',
'tr.snapchat.com',
'api.demandbase.com/api/v3',
'\'sha256-XZLMiKjK7kZsMSJR/aV6U3pMxjqlvU6v3tJSIimxjHs=\'',
'\'sha256-nAigApwVAFaAG381OAPIUWINK3JzGgUcb2TZvwX6MK8=\'',
';',
];

Expand Down
2 changes: 1 addition & 1 deletion acrobat/scripts/contentSecurityPolicy/stage.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ const scriptSrc = [
's.yimg.jp',
'yjtag.yahoo.co.jp',
'tr.snapchat.com',
'\'sha256-XZLMiKjK7kZsMSJR/aV6U3pMxjqlvU6v3tJSIimxjHs=\'',
'\'sha256-nAigApwVAFaAG381OAPIUWINK3JzGgUcb2TZvwX6MK8=\'',
';',
];

Expand Down
11 changes: 6 additions & 5 deletions acrobat/scripts/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@ document.querySelectorAll('a').forEach((p, idx) => {
/**
* The decision engine for where to get Milo's libs from.
*/
const setLibs = (prodLibs, location) => {
const { hostname, search } = location || window.location;
const setLibs = (prodLibs, location = window.location) => {
const { hostname, search } = location;
if (!/\.hlx\.|\.aem\.|local|stage/.test(hostname)) return prodLibs;
// eslint-disable-next-line compat/compat
const branch = new URLSearchParams(search).get('milolibs') || 'main';
if (branch === 'main' && hostname === 'www.stage.adobe.com') return 'https://www.stage.adobe.com/libs';
if (!(hostname.includes('.hlx.') || hostname.includes('local') || hostname.includes('stage'))) return prodLibs;
if (branch === 'main' && hostname === 'www.stage.adobe.com') return '/libs';
if (branch === 'local') return 'http://localhost:6456/libs';
return branch.includes('--') ? `https://${branch}.hlx.live/libs` : `https://${branch}--milo--adobecom.hlx.live/libs`;
const env = hostname.includes('.hlx.') ? 'hlx' : 'aem';
return `https://${branch}${branch.includes('--') ? '' : '--milo--adobecom'}.${env}.live/libs`;
};

const getLocale = (locales, pathname = window.location.pathname) => {
Expand Down
17 changes: 9 additions & 8 deletions acrobat/scripts/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,29 @@ export const [setLibs, getLibs] = (() => {
(prodLibs, location) => {
libs = (() => {
const { hostname, search } = location || window.location;
if (!/\.hlx\.|\.aem\.|local|stage/.test(hostname)) return prodLibs;
// eslint-disable-next-line compat/compat
const branch = new URLSearchParams(search).get('milolibs') || 'main';
if (branch === 'main' && hostname === 'www.stage.adobe.com') return '/libs';
if (!(hostname.includes('.hlx.') || hostname.includes('local') || hostname.includes('stage'))) return prodLibs;
if (branch === 'local') return 'http://localhost:6456/libs';
return branch.includes('--') ? `https://${branch}.hlx.live/libs` : `https://${branch}--milo--adobecom.hlx.live/libs`;
const env = hostname.includes('.hlx.') ? 'hlx' : 'aem';
return `https://${branch}${branch.includes('--') ? '' : '--milo--adobecom'}.${env}.live/libs`;
})();
return libs;
}, () => libs,
];
})();

export function getEnv() {
const prodHosts = ['www.adobe.com', 'sign.ing', 'edit.ing'];
const stageHosts = [
const { hostname } = window.location;
if (['www.adobe.com', 'sign.ing', 'edit.ing'].includes(hostname)) return 'prod';
if ([
'stage--dc--adobecom.hlx.page', 'main--dc--adobecom.hlx.page',
'stage--dc--adobecom.hlx.live', 'main--dc--adobecom.hlx.live',
'stage--dc--adobecom.aem.page', 'main--dc--adobecom.aem.page',
'stage--dc--adobecom.aem.live', 'main--dc--adobecom.aem.live',
'www.stage.adobe.com',
];

if (prodHosts.includes(window.location.hostname)) return 'prod';
if (stageHosts.includes(window.location.hostname)) return 'stage';
].includes(hostname)) return 'stage';
return 'dev';
}

Expand Down
17 changes: 9 additions & 8 deletions head.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,21 @@
<script>
window.setLibs = (prodLibs, location = window.location) => {
const { hostname, search } = location;
if (!/\.hlx\.|\.aem\.|local|stage/.test(hostname)) return prodLibs;
const branch = new URLSearchParams(search).get('milolibs') || 'main';
if (branch === 'main' && hostname === 'www.stage.adobe.com') return 'https://www.stage.adobe.com/libs';
if (!/(\.hlx\.|local|stage)/.test(hostname)) return prodLibs;
if (branch === 'main' && hostname === 'www.stage.adobe.com') return '/libs';
if (branch === 'local') return 'http://localhost:6456/libs';
return branch.includes('--') ? `https://${branch}.hlx.live/libs` : `https://${branch}--milo--adobecom.hlx.live/libs`;
const env = hostname.includes('.hlx.') ? 'hlx' : 'aem';
return `https://${branch}${branch.includes('--') ? '' : '--milo--adobecom'}.${env}.live/libs`;
};

window.getUnityLibs = (prodLibs = '/unitylibs') => {
const { hostname, search } = window.location;
if (!hostname.includes('hlx.page') && !hostname.includes('hlx.live') && !hostname.includes('localhost')) {
return prodLibs;
}
if (!/\.hlx\.|\.aem\.|local|stage/.test(hostname)) return prodLibs;
const branch = new URLSearchParams(search).get('unitylibs') || 'main';
return branch.includes('--') ? `https://${branch}.hlx.live/unitylibs` : `https://${branch}--unity--adobecom.hlx.live/unitylibs`;
if (branch === 'main' && hostname === 'www.stage.adobe.com') return prodLibs;
const env = hostname.includes('.hlx.') ? 'hlx' : 'aem';
return `https://${branch}${branch.includes('--')? '' : '--unity--adobecom'}.${env}.live/unitylibs`;
}

window.loadLink = (href, options = {}) => {
Expand Down
17 changes: 11 additions & 6 deletions test/scripts/utils.test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import { setLibs, getLibs } from '../../acrobat/scripts/utils';
import * as sinon from 'sinon';
/* eslint-disable compat/compat */
import { expect } from '@esm-bundle/chai';
import { setLibs } from '../../acrobat/scripts/utils.js';

describe('Test utils.js', async () => {
it('tests setLibs', async () => {
const libs = setLibs('/lib');
expect(libs).to.equal('https://main--milo--adobecom.hlx.live/libs');
describe('Test utils.js', () => {
it('tests setLibs with hlx domain', () => {
const libs = setLibs('/lib', new URL('https://stage--dc--adobecom.hlx.live?milolibs=test'));
expect(libs).to.equal('https://test--milo--adobecom.hlx.live/libs');
});

it('tests setLibs with aem domain', () => {
const libs = setLibs('/lib', new URL('https://stage--dc--adobecom.aem.live?milolibs=test'));
expect(libs).to.equal('https://test--milo--adobecom.aem.live/libs');
});
});

0 comments on commit 4ef9689

Please sign in to comment.