Skip to content

Commit

Permalink
rename to externalPackageMappings
Browse files Browse the repository at this point in the history
  • Loading branch information
fpbrault committed Sep 19, 2024
1 parent f885356 commit 2a92402
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 67 deletions.
6 changes: 3 additions & 3 deletions packages/atomic/.storybook/main.mts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {nxViteTsPaths} from '@nx/vite/plugins/nx-tsconfig-paths.plugin';
import type {StorybookConfig} from '@storybook/web-components-vite';
import {mergeConfig} from 'vite';
import {packageMappings} from '../scripts/packageMappings';
import {externalPackageMappings} from '../scripts/externalPackageMappings';

const isCDN = process.env.DEPLOYMENT_ENVIRONMENT === 'CDN';

Expand Down Expand Up @@ -36,13 +36,13 @@ function externalizeDependencies() {
if (/^\/(headless|bueno)/.test(id)) {
return false;
}
if (packageMappings[id]) {
if (externalPackageMappings[id]) {
if (!isCDN) {
return false;
}

return {
id: packageMappings[id].cdn,
id: externalPackageMappings[id].cdn,
external: 'absolute',
};
}
Expand Down
57 changes: 57 additions & 0 deletions packages/atomic/scripts/externalPackageMappings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import path from 'node:path';
import headlessJson from '../../headless/package.json';
import buenoJson from '../../headless/package.json';

let headlessVersion: string = '';
let buenoVersion: string = '';

headlessVersion = 'v' + headlessJson.version;
buenoVersion = 'v' + buenoJson.version;

export const externalPackageMappings: {
[key: string]: {devWatch: string; cdn: string};
} = {
'@coveo/headless/commerce': {
devWatch: path.resolve(
__dirname,
'../src/external-builds/commerce/headless.esm.js'
),
cdn: `/headless/${headlessVersion}/commerce/headless.esm.js`,
},
'@coveo/headless/insight': {
devWatch: path.resolve(
__dirname,
'../src/external-builds/insight/headless.esm.js'
),
cdn: `/headless/${headlessVersion}/insight/headless.esm.js`,
},
'@coveo/headless/product-recommendation': {
devWatch: path.resolve(
__dirname,
'../src/external-builds/product-recommendation/headless.esm.js'
),
cdn: `/headless/${headlessVersion}/product-recommendation/headless.esm.js`,
},
'@coveo/headless/recommendation': {
devWatch: path.resolve(
__dirname,
'../src/external-builds/recommendation/headless.esm.js'
),
cdn: `/headless/${headlessVersion}/recommendation/headless.esm.js`,
},
'@coveo/headless/case-assist': {
devWatch: path.resolve(
__dirname,
'../src/external-builds/case-assist/headless.esm.js'
),
cdn: `/headless/${headlessVersion}/case-assist/headless.esm.js`,
},
'@coveo/headless': {
devWatch: path.resolve(__dirname, '../src/external-builds/headless.esm.js'),
cdn: `/headless/${headlessVersion}/headless.esm.js`,
},
'@coveo/bueno': {
devWatch: path.resolve(__dirname, './src/external-builds/bueno.esm.js'),
cdn: `/bueno/${buenoVersion}/bueno.esm.js`,
},
};
59 changes: 0 additions & 59 deletions packages/atomic/scripts/packageMappings.ts

This file was deleted.

8 changes: 4 additions & 4 deletions packages/atomic/stencil.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ import html from 'rollup-plugin-html';
import {inlineSvg} from 'stencil-inline-svg';
import tailwind from 'tailwindcss';
import tailwindNesting from 'tailwindcss/nesting';
import {packageMappings} from './scripts/packageMappings';
import {externalPackageMappings} from './scripts/externalPackageMappings';
import {generateAngularModuleDefinition as angularModule} from './stencil-plugin/atomic-angular-module';

const isProduction = process.env.BUILD === 'production';
const isCDN = process.env.DEPLOYMENT_ENVIRONMENT === 'CDN';

function generateAliasEntries() {
return Object.entries(packageMappings).map(([find, paths]) => ({
return Object.entries(externalPackageMappings).map(([find, paths]) => ({
find,
replacement: paths.devWatch,
}));
Expand Down Expand Up @@ -212,13 +212,13 @@ function externalizeDependenciesPlugin() {
return {
name: 'externalize-dependencies',
resolveId: (id: string) => {
if (packageMappings[id]) {
if (externalPackageMappings[id]) {
if (!isCDN) {
return false;
}

return {
id: packageMappings[id].cdn,
id: externalPackageMappings[id].cdn,
external: 'absolute',
};
}
Expand Down
2 changes: 1 addition & 1 deletion packages/atomic/tsconfig.storybook.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@
".storybook/*.jsx",
".storybook/register.tsx",
".storybook/main.mts",
"scripts/packageMappings.ts"
"scripts/externalPackageMappings.ts"
]
}

0 comments on commit 2a92402

Please sign in to comment.