From 1ba3b64fea6e5e7b729aa35fb9335394e5a850df 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] 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 | 6 ++-- packages/atomic/project.json | 2 +- packages/atomic/stencil.config.ts | 1 - 8 files changed, 35 insertions(+), 7 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..644f3cddc95 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", 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'}, {