Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(atomic): allow atomic loader to be deployed to the CDN #4568

Merged
merged 3 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ utils/**/.storybook/**
scripts/deploy/execute-deployment-pipeline.mjs
**/staticresources/**
packages/atomic-hosted-page/loader/**/*
packages/atomic/loader/**/*
packages/atomic/docs/**/*
packages/atomic/dist-storybook/**/*
packages/atomic/src/components/search/atomic-search-interface/lang/*.json
Expand Down
1 change: 1 addition & 0 deletions packages/atomic-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"scripts": {
"build": "nx build",
"clean": "rimraf -rf dist",
"build:fixLoaderImportPaths": "node ./scripts/fix-loader-import-paths.js",
"build:fixGeneratedImportPaths": "fix-esm-import-path src/components/stencil-generated",
"build:bundles:esm": "tsc -p tsconfig.esm.json",
"build:bundles:iife-cjs": "rollup --config rollup.config.mjs --bundleConfigAsCjs",
Expand Down
1 change: 1 addition & 0 deletions packages/atomic-react/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"executor": "nx:run-commands",
"options": {
"commands": [
"npm run build:fixLoaderImportPaths",
"npm run build:fixGeneratedImportPaths",
"npm run build:bundles",
"npm run build:assets"
Expand Down
29 changes: 29 additions & 0 deletions packages/atomic-react/scripts/fix-loader-import-paths.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import {promises as fs} from 'fs';
import path from 'path';

const files = [
path.resolve('src/components/stencil-generated/commerce/index.ts'),
path.resolve('src/components/stencil-generated/search/index.ts'),
];

const oldImport =
"import { defineCustomElements } from '@coveo/atomic/dist/loader';";
const newImport =
"import { defineCustomElements } from '@coveo/atomic/loader';";

const updateFiles = async () => {
await Promise.all(
files.map(async (filePath) => {
try {
let data = await fs.readFile(filePath, 'utf8');
const updatedData = data.replace(oldImport, newImport);
await fs.writeFile(filePath, updatedData, 'utf8');
console.log(`File updated: ${filePath}`);
} catch (err) {
console.error(`Error updating file: ${filePath}`, err);
}
})
);
};

updateFiles();
1 change: 0 additions & 1 deletion packages/atomic/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ module.exports = {
'src/external-builds/**/*',
'dist/**/*',
'www/**/*',
'loader/**/*',
'docs/**/*',
'dist-storybook',
],
Expand Down
9 changes: 4 additions & 5 deletions packages/atomic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
"types": "dist/types/index.d.ts",
"exports": {
"./loader": {
"types": "./loader/index.d.ts",
"import": "./loader/index.js",
"require": "./loader/index.cjs.js"
"types": "./dist/loader/index.d.ts",
"import": "./dist/loader/index.js",
"require": "./dist/loader/index.cjs.js"
},
".": {
"types": "./dist/types/index.d.ts",
Expand All @@ -39,8 +39,7 @@
"files": [
"dist/",
"docs/",
"licenses/",
"loader/"
"licenses/"
],
"scripts": {
"clean": "rimraf -rf dist/* dist-storybook/* www/* docs/* loader/* playwright-report/*",
Expand Down
2 changes: 1 addition & 1 deletion packages/atomic/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@
"dependsOn": ["^build", "cached:build:stencil"],
"executor": "nx:run-commands",
"options": {
"command": "rm ./loader/package.json",
"command": "rm ./dist/loader/package.json",
"cwd": "packages/atomic"
}
}
Expand Down
1 change: 0 additions & 1 deletion packages/atomic/stencil.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ export const config: Config = {
{
type: 'dist',
collectionDir: null,
esmLoaderPath: '../loader',
copy: [
{src: 'themes'},
{
Expand Down
32 changes: 32 additions & 0 deletions packages/samples/stencil/stencil.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import {Config} from '@stencil/core';
import {readFileSync} from 'fs';
import {join} from 'path';
import html from 'rollup-plugin-html';

// https://stenciljs.com/docs/config
Expand Down Expand Up @@ -36,6 +38,36 @@ export const config: Config = {
html({
include: 'src/components/**/*.html',
}),
resolveAtomicPaths(),
],
},
};

function resolveAtomicPaths() {
alexprudhomme marked this conversation as resolved.
Show resolved Hide resolved
return {
resolveId(source: string) {
if (source.startsWith('@coveo/atomic/')) {
const nodeModulesLocation = '../../../node_modules';

const packageJsonPath = join(
process.cwd(),
nodeModulesLocation,
'@coveo',
alexprudhomme marked this conversation as resolved.
Show resolved Hide resolved
'atomic',
'package.json'
);

const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8'));

const subPath = './' + source.replace('@coveo/atomic/', '');
const subPathImport = packageJson.exports[subPath].import;

const id = `${nodeModulesLocation}/@coveo/atomic/${subPathImport}`;
return {
id,
};
}
return null;
},
};
}
Loading