diff --git a/libs/features/mas/scripts/build.mjs b/libs/features/mas/build.mjs similarity index 77% rename from libs/features/mas/scripts/build.mjs rename to libs/features/mas/build.mjs index c2a6803007c..a5d7aaff0e5 100644 --- a/libs/features/mas/scripts/build.mjs +++ b/libs/features/mas/build.mjs @@ -1,7 +1,7 @@ import { writeFileSync } from 'node:fs'; import { build } from 'esbuild'; -const outfolder = '../../../../libs/deps/mas'; +const outfolder = '../../deps/mas'; const defaults = { bundle: true, @@ -11,22 +11,34 @@ const defaults = { platform: 'browser', }; -async function buildLitComponent(name) { - const { metafile } = await build({ - ...defaults, - entryPoints: [`./src/${name}.js`], - external: ['lit'], - metafile: true, - outfile: `${outfolder}/${name}.js`, - plugins: [rewriteImports()], - }); +// commerce.js +const { metafile } = await build({ + ...defaults, + alias: { + react: 'test/mocks/react.js', + }, + entryPoints: ['./src/commerce.js'], + metafile: true, + outfile: `${outfolder}/commerce.js`, + platform: 'browser', + target: ['es2020'], +}); +writeFileSync(`commerce.json`, JSON.stringify(metafile)); - writeFileSync( - `../../../../libs/deps/mas/${name}.json`, - JSON.stringify(metafile), - ); -} +// mas.js +await build({ + ...defaults, + entryPoints: ['./src/mas.js'], + outfile: './dist/mas.js', +}); + +await build({ + ...defaults, + entryPoints: ['./src/mas.js'], + outfile: `${outfolder}/mas.js`, +}); +// web components Promise.all([ build({ ...defaults, @@ -60,7 +72,6 @@ Promise.all([ buildLitComponent('merch-quantity-select'), buildLitComponent('merch-secure-transaction'), buildLitComponent('merch-stock'), - buildLitComponent('merch-subscription-panel'), buildLitComponent('merch-twp-d2p'), buildLitComponent('merch-whats-included'), buildLitComponent('merch-mnemonic-list'), @@ -80,6 +91,18 @@ function rewriteImports() { }; } +async function buildLitComponent(name) { + const { metafile } = await build({ + ...defaults, + entryPoints: [`./src/${name}.js`], + external: ['lit'], + metafile: true, + outfile: `${outfolder}/${name}.js`, + plugins: [rewriteImports()], + }); + writeFileSync(`${outfolder}/${name}.json`, JSON.stringify(metafile)); +} + function rewriteImportsToLibsFolder() { return { name: 'rewrite-imports-to-libs-folder', diff --git a/libs/features/mas/scripts/commerce-build.mjs b/libs/features/mas/scripts/commerce-build.mjs deleted file mode 100644 index 7dfe9467e2a..00000000000 --- a/libs/features/mas/scripts/commerce-build.mjs +++ /dev/null @@ -1,18 +0,0 @@ -import { build } from 'esbuild'; -import fs from 'node:fs'; - -const { metafile } = await build({ - alias: { - react: '../mocks/react.js', - }, - bundle: true, - entryPoints: ['./src/index.js'], - format: 'esm', - metafile: true, - minify: true, - outfile: '../../../../libs/deps/mas/commerce.js', - platform: 'browser', - target: ['es2020'], -}); - -fs.writeFileSync('stats.json', JSON.stringify(metafile)); diff --git a/libs/features/mas/scripts/mas-build.mjs b/libs/features/mas/scripts/mas-build.mjs deleted file mode 100644 index b8e2187a3dd..00000000000 --- a/libs/features/mas/scripts/mas-build.mjs +++ /dev/null @@ -1,30 +0,0 @@ -import { build } from 'esbuild'; -import fs from 'node:fs'; - -const defaults = { - alias: { - react: '../mocks/react.js', - }, - bundle: true, - format: 'esm', - metafile: true, - minify: true, - platform: 'browser', - target: ['es2020'], - external: [], - sourcemap: false, -}; - -const { metafile } = await build({ - ...defaults, - entryPoints: ['./src/mas.js'], - outfile: './dist/mas.js', -}); - -await build({ - ...defaults, - entryPoints: ['./src/mas.js'], - outfile: '../../../deps/mas/mas.js', -}); - -fs.writeFileSync('mas.json', JSON.stringify(metafile)); diff --git a/libs/features/mas/src/commerce.js b/libs/features/mas/src/commerce.js index eded1b7c502..e7806672915 100644 --- a/libs/features/mas/src/commerce.js +++ b/libs/features/mas/src/commerce.js @@ -1,21 +1,31 @@ -import { EVENT_TYPE_READY, TAG_NAME_SERVICE } from './constants.js'; +import { CheckoutLink } from './checkout-link.js'; +import { Landscape } from './constants.js'; +import { Defaults } from './defaults.js'; +import { TAG_NAME_SERVICE } from './mas-commerce-service.js'; +import { + CheckoutWorkflow, + CheckoutWorkflowStep, + WcsCommitment, + WcsTerm, + WcsPlanType, + applyPlanType, +} from './external.js'; +import { InlinePrice } from './inline-price.js'; +import { Log } from './log.js'; +import { getSettings } from './settings.js'; -/** - * Waits for commerce service to be ready and returns. - */ -export async function getService() { - const { head } = document; - const current = head.querySelector(TAG_NAME_SERVICE); - if (current) return Promise.resolve(current); - return new Promise((resolve, reject) => { - head.addEventListener( - EVENT_TYPE_READY, - () => { - const service = head.querySelector(TAG_NAME_SERVICE); - if (service) resolve(service); - else reject(new Error('Commerce service not found')); - }, - { once: true }, - ); - }); -} +export { + TAG_NAME_SERVICE, + CheckoutLink, + CheckoutWorkflow, + CheckoutWorkflowStep, + Defaults, + InlinePrice, + Log, + WcsCommitment, + Landscape, + WcsTerm, + WcsPlanType, + applyPlanType, + getSettings, +}; diff --git a/libs/features/mas/src/index.js b/libs/features/mas/src/index.js deleted file mode 100644 index e7806672915..00000000000 --- a/libs/features/mas/src/index.js +++ /dev/null @@ -1,31 +0,0 @@ -import { CheckoutLink } from './checkout-link.js'; -import { Landscape } from './constants.js'; -import { Defaults } from './defaults.js'; -import { TAG_NAME_SERVICE } from './mas-commerce-service.js'; -import { - CheckoutWorkflow, - CheckoutWorkflowStep, - WcsCommitment, - WcsTerm, - WcsPlanType, - applyPlanType, -} from './external.js'; -import { InlinePrice } from './inline-price.js'; -import { Log } from './log.js'; -import { getSettings } from './settings.js'; - -export { - TAG_NAME_SERVICE, - CheckoutLink, - CheckoutWorkflow, - CheckoutWorkflowStep, - Defaults, - InlinePrice, - Log, - WcsCommitment, - Landscape, - WcsTerm, - WcsPlanType, - applyPlanType, - getSettings, -};