From e1a69be885c0cfa03f17328c81518885fd55457c Mon Sep 17 00:00:00 2001 From: Alex Prudhomme <78121423+alexprudhomme@users.noreply.github.com> Date: Mon, 21 Oct 2024 15:20:43 -0400 Subject: [PATCH 1/2] fix(atomic): deploy loader to the CDN https://coveord.atlassian.net/browse/KIT-3666 --- .prettierignore | 1 - packages/atomic-react/package.json | 1 + packages/atomic-react/project.json | 1 + .../scripts/fix-loader-import-paths.js | 29 +++++++++++++++++++ packages/atomic/.eslintrc.cjs | 1 - packages/atomic/package.json | 9 +++--- packages/atomic/project.json | 2 +- packages/atomic/stencil.config.ts | 1 - 8 files changed, 36 insertions(+), 9 deletions(-) create mode 100644 packages/atomic-react/scripts/fix-loader-import-paths.js diff --git a/.prettierignore b/.prettierignore index 6603d0cf302..d8fb45a0552 100644 --- a/.prettierignore +++ b/.prettierignore @@ -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 diff --git a/packages/atomic-react/package.json b/packages/atomic-react/package.json index 5d59ed54a9a..4ed196877a4 100644 --- a/packages/atomic-react/package.json +++ b/packages/atomic-react/package.json @@ -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", diff --git a/packages/atomic-react/project.json b/packages/atomic-react/project.json index 5af3ade9955..7c26443d165 100644 --- a/packages/atomic-react/project.json +++ b/packages/atomic-react/project.json @@ -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" diff --git a/packages/atomic-react/scripts/fix-loader-import-paths.js b/packages/atomic-react/scripts/fix-loader-import-paths.js new file mode 100644 index 00000000000..0a8283afaae --- /dev/null +++ b/packages/atomic-react/scripts/fix-loader-import-paths.js @@ -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(); diff --git a/packages/atomic/.eslintrc.cjs b/packages/atomic/.eslintrc.cjs index 5078021b491..3226298d692 100644 --- a/packages/atomic/.eslintrc.cjs +++ b/packages/atomic/.eslintrc.cjs @@ -13,7 +13,6 @@ module.exports = { 'src/external-builds/**/*', 'dist/**/*', 'www/**/*', - 'loader/**/*', 'docs/**/*', 'dist-storybook', ], diff --git a/packages/atomic/package.json b/packages/atomic/package.json index 697c058ec44..c125b6212a7 100644 --- a/packages/atomic/package.json +++ b/packages/atomic/package.json @@ -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", @@ -39,8 +39,7 @@ "files": [ "dist/", "docs/", - "licenses/", - "loader/" + "licenses/" ], "scripts": { "clean": "rimraf -rf dist/* dist-storybook/* www/* docs/* loader/* playwright-report/*", diff --git a/packages/atomic/project.json b/packages/atomic/project.json index 6b1ab3fa7a9..e0f4e24627b 100644 --- a/packages/atomic/project.json +++ b/packages/atomic/project.json @@ -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" } } diff --git a/packages/atomic/stencil.config.ts b/packages/atomic/stencil.config.ts index fd92aada780..2873c7fea7a 100644 --- a/packages/atomic/stencil.config.ts +++ b/packages/atomic/stencil.config.ts @@ -155,7 +155,6 @@ export const config: Config = { { type: 'dist', collectionDir: null, - esmLoaderPath: '../loader', copy: [ {src: 'themes'}, { From d5ed2765611bfe54f8da3133086e0d7fcfe45422 Mon Sep 17 00:00:00 2001 From: Alex Prudhomme <78121423+alexprudhomme@users.noreply.github.com> Date: Tue, 22 Oct 2024 13:52:15 -0400 Subject: [PATCH 2/2] fix stencil sample but resolving atomic paths to node_modules https://coveord.atlassian.net/browse/KIT-3666 --- packages/samples/stencil/stencil.config.ts | 32 ++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/packages/samples/stencil/stencil.config.ts b/packages/samples/stencil/stencil.config.ts index a29e147a5f8..38fe68af107 100644 --- a/packages/samples/stencil/stencil.config.ts +++ b/packages/samples/stencil/stencil.config.ts @@ -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 @@ -36,6 +38,36 @@ export const config: Config = { html({ include: 'src/components/**/*.html', }), + resolveAtomicPaths(), ], }, }; + +function resolveAtomicPaths() { + return { + resolveId(source: string) { + if (source.startsWith('@coveo/atomic/')) { + const nodeModulesLocation = '../../../node_modules'; + + const packageJsonPath = join( + process.cwd(), + nodeModulesLocation, + '@coveo', + '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; + }, + }; +}