Skip to content

Commit f87dec9

Browse files
authored
MWPW-185658: clean up libs/features/mas (#5284)
* MWPW-185658: clean up libs/features/mas merch block and OST tool, and related resources stays in Milo. * fix lint issue * wip * revert gnav test and remove merch import * revert global-navigation.js * remove mas from gnav * fix imports * revert gnav changes * clean up * fix importmap * fix test * update pkg name and maslibs local port * update mas pkg name * rename mas npm package name * revert .js to .html test conversions * revert .js to .html test conversions * fix lint * revert line * revert line * use chrome channel to avoid http2 errors * removing this line in favor of channel: chrome Playwright setting. * removing extraHTTPHeaders in favor of channel: chrome Playwright setting. * improve resilience of tests in webkit * revert line
1 parent 5a97847 commit f87dec9

File tree

323 files changed

+1724
-89236
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

323 files changed

+1724
-89236
lines changed

.eslintrc-code-compatibility.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ module.exports = {
1414
],
1515
ignorePatterns: [
1616
'/libs/deps/*',
17-
'/libs/features/mas/*',
1817
'/libs/navigation/dist/*',
1918
'/tools/loc/*',
2019
],

.eslintrc.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ module.exports = {
5959
],
6060
ignorePatterns: [
6161
'/libs/deps/*',
62-
'/libs/features/mas/*',
6362
'/tools/loc/*',
6463
'/libs/features/spectrum-web-components/*',
6564
'/libs/navigation/dist/*',

.github/codeql/codeql-config.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,3 @@ paths-ignore:
55
- 'tools/floodgate/**'
66
- 'tools/translation/**'
77
- node_modules
8-
- libs/deps/mas
9-
- libs/features/mas/dist

.github/workflows/run-mas-tests.yaml

Lines changed: 0 additions & 39 deletions
This file was deleted.

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ logs/*
77
.idea
88
.iml
99
.env
10-
**/mas/*/stats.json
1110
test-html-results/
1211
test-results/
1312
test-a11y-results/

.hlxignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,3 @@ build/*
88
LICENSE
99
web-test-runner.config.mjs
1010
codecov.yaml
11-
libs/features/mas/*
12-
!libs/features/mas/docs
13-
!libs/features/mas/dist

CODEOWNERS

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
/libs/features/georouting/ @adobecom/milo-core
1010
/libs/features/georoutingv2/ @adobecom/milo-core
1111
/libs/features/icons/ @adobecom/milo-core
12-
/libs/features/mas/ @adobecom/tacocat
1312
/libs/features/personalization/ @adobecom/mep-squad
1413
/libs/features/seotech/ @adobecom/milo-core
1514
/libs/features/spectrum-web-components/ @adobecom/tacocat

libs/blocks/global-navigation/global-navigation.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
getFederatedUrl,
1313
getFedsPlaceholderConfig,
1414
shouldBlockFreeTrialLinks,
15+
getCountry,
1516
} from '../../utils/utils.js';
1617

1718
const cssPromise = (async () => {
@@ -55,17 +56,14 @@ const asideJsPromise = getMetadata('gnav-promo-source') ? import('./features/asi
5556

5657
const breadCrumbsJsPromise = document.querySelector('header')?.classList.contains('has-breadcrumbs') ? import('./features/breadcrumbs/breadcrumbs.js') : null;
5758

58-
const [utilities, placeholders, merch, { processTrackingLabels }] = await Promise.all([
59+
const [utilities, placeholders, { processTrackingLabels }] = await Promise.all([
5960
import('./utilities/utilities.js'),
6061
import('../../features/placeholders.js'),
61-
import('../merch/merch.js'),
6262
import('../../martech/attributes.js'),
6363
]);
6464

6565
const { replaceKey, replaceKeyArray } = placeholders;
6666

67-
const { getMiloLocaleSettings } = merch;
68-
6967
const {
7068
closeAllDropdowns,
7169
createErrorPopup,
@@ -914,7 +912,7 @@ class Gnav {
914912
target: this.blocks.universalNav,
915913
env: environment,
916914
locale,
917-
countryCode: getMiloLocaleSettings(getConfig().locale)?.country || 'US',
915+
countryCode: getCountry() || 'US',
918916
imsClientId: window.adobeid?.client_id,
919917
theme: isDarkMode() ? 'dark' : 'light',
920918
analyticsContext: {
@@ -1540,15 +1538,15 @@ class Gnav {
15401538
item.parentElement.replaceWith(item);
15411539

15421540
return addMepHighlightAndTargetId(toFragment`<div class="feds-navItem feds-navItem--centered" role="listitem">
1543-
${decorateCta({ elem: item.classList.contains('merch') ? await merch.default(item) : item, type: itemType, index: index + 1 })}
1541+
${decorateCta({ elem: item.classList.contains('merch') ? await (await import('../merch/merch.js')).default(item) : item, type: itemType, index: index + 1 })}
15441542
</div>`, item);
15451543
case 'link': {
15461544
let customLinkModifier = '';
15471545
let removeCustomLink = false;
15481546
let linkElem = item.querySelector('a');
15491547
if (shouldBlockFreeTrialLinks(linkElem)) return null;
15501548
if (linkElem.classList.contains('merch')) {
1551-
linkElem = await merch.default(linkElem);
1549+
linkElem = await (await import('../merch/merch.js')).default(linkElem);
15521550
}
15531551
const customLinksSection = item.closest('.link-group');
15541552
linkElem.className = 'feds-navLink';
@@ -1584,7 +1582,7 @@ class Gnav {
15841582
}
15851583
case 'text':
15861584
return addMepHighlightAndTargetId(toFragment`<div class="feds-navItem feds-navItem--centered">
1587-
${item.classList.contains('merch') ? await merch.default(item) : item.textContent}
1585+
${item.classList.contains('merch') ? await (await import('../merch/merch.js')).default(item) : item.textContent}
15881586
</div>`, item);
15891587
default:
15901588
/* c8 ignore next 3 */

libs/blocks/merch/merch.js

Lines changed: 19 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
import { replaceKey } from '../../features/placeholders.js';
66

77
// MAS Component Names
8-
export const MAS_COMMERCE_SERVICE = 'commerce';
8+
export const COMMERCE_LIBRARY = 'commerce';
99
export const MAS_MERCH_CARD = 'merch-card';
1010
export const MAS_MERCH_CARD_COLLECTION = 'merch-card-collection';
1111
export const MAS_MERCH_MNEMONIC_LIST = 'merch-mnemonic-list';
@@ -373,7 +373,7 @@ export function getMasLibs() {
373373
const sanitizedMasLibs = masLibs.trim().toLowerCase();
374374

375375
if (sanitizedMasLibs === 'local') {
376-
return 'http://localhost:3030/web-components/dist';
376+
return 'http://localhost:3000/web-components/dist';
377377
}
378378
if (sanitizedMasLibs === 'main') {
379379
return 'http://www.adobe.com/mas/libs';
@@ -405,7 +405,7 @@ function getFragmentClientUrl() {
405405
const sanitizedMasLibs = masLibs.trim().toLowerCase();
406406

407407
if (sanitizedMasLibs === 'local') {
408-
return 'http://localhost:3030/studio/libs/fragment-client.js';
408+
return 'http://localhost:3000/studio/libs/fragment-client.js';
409409
}
410410
if (sanitizedMasLibs === 'main') {
411411
return 'https://mas.adobe.com/studio/libs/fragment-client.js';
@@ -432,59 +432,40 @@ const failedExternalLoads = new Set();
432432
const loadingPromises = new Map();
433433

434434
/**
435-
* Checks if mas-ff-mas-deps feature flag is enabled
436-
* @returns {boolean} true if flag is on
437-
*/
438-
function isMasDepsFlagEnabled() {
439-
const metaFlag = getMetadata('mas-ff-mas-deps');
440-
if (metaFlag === 'off' || metaFlag === 'false') return false;
441-
return true;
442-
}
443-
444-
/**
445-
* Loads a MAS component either from external URL (if masLibs present) or local deps
435+
* Loads a MAS component either from external URL (if masLibs present) or from production CDN
446436
* @param {string} componentName - Name of the component to load (e.g., 'commerce', 'merch-card')
447437
* @returns {Promise} Promise that resolves when component is loaded
448438
*/
449439
export async function loadMasComponent(componentName) {
440+
// Return existing loading promise if already in progress
450441
if (loadingPromises.has(componentName)) {
451442
return loadingPromises.get(componentName);
452443
}
453444

445+
// Component already loaded, return immediately
454446
if (customElements.get(componentName)) {
455447
return Promise.resolve();
456448
}
457449

458450
const loadPromise = (async () => {
459451
const masLibsBase = getMasLibs();
452+
const productionUrl = `https://www.adobe.com/mas/libs/${componentName}.js`;
453+
const targetUrl = masLibsBase ? `${masLibsBase}/${componentName}.js` : productionUrl;
460454

461-
if (masLibsBase) {
462-
const externalUrl = `${masLibsBase}/${componentName}.js`;
463-
464-
if (failedExternalLoads.has(externalUrl)) {
465-
throw new Error(`Failed to load component from ${externalUrl}`);
466-
}
455+
// Fail fast if this URL has already failed before
456+
if (failedExternalLoads.has(targetUrl)) {
457+
throw new Error(`Previously failed to load component from ${targetUrl}`);
458+
}
467459

468-
try {
469-
return await import(externalUrl);
470-
} catch (error) {
471-
failedExternalLoads.add(externalUrl);
472-
throw error;
473-
}
474-
} else if (isMasDepsFlagEnabled()) {
475-
const masUrl = `https://www.adobe.com/mas/libs/${componentName}.js`;
476-
try {
477-
return await import(masUrl);
478-
} catch (error) {
479-
// eslint-disable-next-line no-console
480-
console.warn(`Failed to load from MAS repository, falling back to Milo deps: ${error.message}`);
481-
return import(`../../deps/mas/${componentName}.js`);
482-
}
483-
} else {
484-
return import(`../../deps/mas/${componentName}.js`);
460+
try {
461+
return await import(targetUrl);
462+
} catch (error) {
463+
failedExternalLoads.add(targetUrl);
464+
throw error;
485465
}
486466
})();
487467

468+
// Cache the promise and clean up when done
488469
loadingPromises.set(componentName, loadPromise);
489470
loadPromise.finally(() => loadingPromises.delete(componentName));
490471

@@ -1083,7 +1064,7 @@ export async function initService(force = false, attributes = {}) {
10831064
});
10841065
initService.promise = initService.promise
10851066
?? polyfills().then(async () => {
1086-
await loadMasComponent(MAS_COMMERCE_SERVICE);
1067+
await loadMasComponent(COMMERCE_LIBRARY);
10871068

10881069
// Load fragment-client.js when maslibs is present
10891070
const fragmentClientUrl = getFragmentClientUrl();

libs/blocks/ost/ost.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import ctaTextOption from './ctaTextOption.js';
22
import {
33
getConfig, getLocale, getMetadata, loadScript, loadStyle, createTag,
44
} from '../../utils/utils.js';
5-
import { initService, loadMasComponent, getMasLibs, getMiloLocaleSettings, MAS_COMMERCE_SERVICE } from '../merch/merch.js';
5+
import { initService, loadMasComponent, getMasLibs, getMiloLocaleSettings, COMMERCE_LIBRARY } from '../merch/merch.js';
66

77
export const AOS_API_KEY = 'wcms-commerce-ims-user-prod';
88
export const CHECKOUT_CLIENT_ID = 'creative';
@@ -159,7 +159,7 @@ export async function loadOstEnv() {
159159
}
160160
await initService(true, attributes);
161161
// Load commerce.js based on masLibs parameter
162-
masCommerceService = await loadMasComponent(MAS_COMMERCE_SERVICE);
162+
masCommerceService = await loadMasComponent(COMMERCE_LIBRARY);
163163

164164
// Get the exports - they might be in different places depending on how it was loaded
165165
let Log;
@@ -169,7 +169,8 @@ export async function loadOstEnv() {
169169
({ Log, Defaults } = window.mas.commerce);
170170
} else {
171171
// Loaded as module
172-
({ Log, Defaults } = await import('../../deps/mas/commerce.js'));
172+
// eslint-disable-next-line import/no-unresolved
173+
({ Log, Defaults } = await import('https://www.adobe.com/mas/libs/commerce.js'));
173174
}
174175

175176
const defaultPlaceholderOptions = Object.fromEntries([

0 commit comments

Comments
 (0)