diff --git a/.deployment.config.json b/.deployment.config.json index 30434007746..342cb7e371c 100644 --- a/.deployment.config.json +++ b/.deployment.config.json @@ -114,39 +114,6 @@ } } }, - { - "id": "deploy-atomic-headless-patch-to-s3-version", - "s3": { - "bucket": "{terraform.infra.infra.bucket_binaries}", - "directory": "proda/StaticCDN/atomic/v$[ATOMIC_PATCH_VERSION]/headless", - "source": "packages/headless/dist/browser", - "parameters": { - "acl": "public-read" - } - } - }, - { - "id": "deploy-atomic-headless-minor-to-s3-version", - "s3": { - "bucket": "{terraform.infra.infra.bucket_binaries}", - "directory": "proda/StaticCDN/atomic/v$[ATOMIC_MINOR_VERSION]/headless", - "source": "packages/headless/dist/browser", - "parameters": { - "acl": "public-read" - } - } - }, - { - "id": "deploy-atomic-headless-major-to-s3-version", - "s3": { - "bucket": "{terraform.infra.infra.bucket_binaries}", - "directory": "proda/StaticCDN/atomic/v$[ATOMIC_MAJOR_VERSION]/headless", - "source": "packages/headless/dist/browser", - "parameters": { - "acl": "public-read" - } - } - }, { "id": "deploy-atomic-minor-storybook-to-s3-version", "s3": { diff --git a/.github/actions/e2e-atomic-insight-panel/action.yml b/.github/actions/e2e-atomic-insight-panel/action.yml index 449ec3e0af3..4aaa6f6b7bb 100644 --- a/.github/actions/e2e-atomic-insight-panel/action.yml +++ b/.github/actions/e2e-atomic-insight-panel/action.yml @@ -15,7 +15,7 @@ runs: command-prefix: 'npx -w @coveo/atomic cypress-repeat run -n 3 --until-passes --rerun-failed-only --' config-file: cypress-insight-panel.config.ts start: npm start -w @coveo/atomic - wait-on: 'http://localhost:3333' + wait-on: 'http://localhost:3333/ping' wait-on-timeout: 600000 install: false record: false diff --git a/.github/actions/e2e-atomic-screenshots/action.yml b/.github/actions/e2e-atomic-screenshots/action.yml index ce94ed56c43..d5882bfed41 100644 --- a/.github/actions/e2e-atomic-screenshots/action.yml +++ b/.github/actions/e2e-atomic-screenshots/action.yml @@ -17,7 +17,7 @@ runs: command-prefix: 'npx -w @coveo/atomic cypress-repeat run -n 3 --until-passes --rerun-failed-only --' config-file: cypress-screenshots.config.ts start: npm start -w @coveo/atomic - wait-on: 'http://localhost:3333' + wait-on: 'http://localhost:3333/ping' wait-on-timeout: 600000 install: false record: false diff --git a/.github/actions/e2e-atomic/action.yml b/.github/actions/e2e-atomic/action.yml index 8003386e9f4..8779a9b0c42 100644 --- a/.github/actions/e2e-atomic/action.yml +++ b/.github/actions/e2e-atomic/action.yml @@ -26,7 +26,7 @@ runs: command-prefix: 'npx -w @coveo/atomic cypress-repeat run -n 3 --until-passes --rerun-failed-only --' spec: ${{ inputs.spec }} start: npm start -w @coveo/atomic - wait-on: 'http://localhost:3333' + wait-on: 'http://localhost:3333/ping' wait-on-timeout: 600000 install: false record: false diff --git a/package-lock.json b/package-lock.json index 8abc42bad00..3384e8e60c9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -20,6 +20,7 @@ "packages/atomic-react", "packages/atomic-angular", "packages/atomic-angular/projects/*", + "packages/rollup-plugin-replace-with-ast", "packages/samples/*", "packages/samples/headless-ssr/*", "utils/*" @@ -4978,6 +4979,10 @@ "resolved": "utils/release", "link": true }, + "node_modules/@coveo/rollup-plugin-replace-with-ast": { + "resolved": "packages/rollup-plugin-replace-with-ast", + "link": true + }, "node_modules/@coveo/semantic-monorepo-tools": { "version": "2.4.43", "resolved": "https://registry.npmjs.org/@coveo/semantic-monorepo-tools/-/semantic-monorepo-tools-2.4.43.tgz", @@ -10817,6 +10822,7 @@ "resolved": "https://registry.npmjs.org/@rollup/plugin-typescript/-/plugin-typescript-11.1.6.tgz", "integrity": "sha512-R92yOmIACgYdJ7dJ97p4K69I8gg6IEHt8M7dUBxN3W6nrO8uUxX5ixl0yU/N3aZTi8WhPuICvOHXQvF6FaykAA==", "dev": true, + "license": "MIT", "dependencies": { "@rollup/pluginutils": "^5.1.0", "resolve": "^1.22.1" @@ -35458,6 +35464,7 @@ "resolved": "https://registry.npmjs.org/jest/-/jest-29.7.0.tgz", "integrity": "sha512-NIy3oAFp9shda19hy4HK0HRTWKtPJmGdnvywu01nOqNC2vZg+Z+fvJDxpMQA88eb2I9EcafcdjYgsDthnYTvGw==", "dev": true, + "license": "MIT", "dependencies": { "@jest/core": "^29.7.0", "@jest/types": "^29.6.3", @@ -51879,6 +51886,7 @@ "license": "Apache-2.0", "dependencies": { "@coveo/bueno": "0.46.1", + "@coveo/headless": "2.80.0", "@popperjs/core": "^2.11.6", "@salesforce-ux/design-system": "^2.16.1", "@stencil/store": "2.0.16", @@ -51897,8 +51905,8 @@ "@axe-core/playwright": "4.9.1", "@babel/core": "7.24.9", "@coveo/atomic": "file:.", - "@coveo/headless": "2.80.0", "@coveo/release": "1.0.0", + "@coveo/rollup-plugin-replace-with-ast": "1.0.0", "@custom-elements-manifest/analyzer": "0.10.3", "@fullhuman/postcss-purgecss": "6.0.0", "@nx/js": "19.5.3", @@ -52149,8 +52157,8 @@ "@coveo/atomic": "2.78.0" }, "devDependencies": { - "@coveo/headless": "2.80.0", "@coveo/release": "1.0.0", + "@coveo/rollup-plugin-replace-with-ast": "1.0.0", "@rollup/plugin-commonjs": "^25.0.0", "@rollup/plugin-json": "6.1.0", "@rollup/plugin-node-resolve": "^15.0.0", @@ -52813,6 +52821,13 @@ "postcss": "^8.0.0" } }, + "packages/atomic/node_modules/@jridgewell/sourcemap-codec": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.5.0.tgz", + "integrity": "sha512-gv3ZRaISU3fjPAgNsriBRqGWQL6quFx04YMPW/zD8XMLsU32mhCCbfbO6KZFLjvYpCZ8zyDEgqsgf+PwPaM7GQ==", + "dev": true, + "license": "MIT" + }, "packages/atomic/node_modules/@lit/reactive-element": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/@lit/reactive-element/-/reactive-element-2.0.4.tgz", @@ -53471,6 +53486,19 @@ "puppeteer": "*" } }, + "packages/atomic/node_modules/acorn": { + "version": "8.12.1", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.12.1.tgz", + "integrity": "sha512-tcpGyI9zbizT9JbV6oYE477V6mTlXvvi0T0G3SNIYE2apm/G5huBa1+K89VGeovbg+jycCrfhl3ADxErOuO6Jg==", + "dev": true, + "license": "MIT", + "bin": { + "acorn": "bin/acorn" + }, + "engines": { + "node": ">=0.4.0" + } + }, "packages/atomic/node_modules/ansi-styles": { "version": "4.3.0", "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", @@ -53918,6 +53946,16 @@ "@types/trusted-types": "^2.0.2" } }, + "packages/atomic/node_modules/magic-string": { + "version": "0.30.11", + "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.30.11.tgz", + "integrity": "sha512-+Wri9p0QHMy+545hKww7YAu5NyzF8iomPL/RQazugQ9+Ez4Ic3mERMd8ZTX5rfK944j+560ZJi8iAwgak1Ac7A==", + "dev": true, + "license": "MIT", + "dependencies": { + "@jridgewell/sourcemap-codec": "^1.5.0" + } + }, "packages/atomic/node_modules/marked": { "version": "12.0.2", "resolved": "https://registry.npmjs.org/marked/-/marked-12.0.2.tgz", @@ -57576,6 +57614,256 @@ "browserslist": ">= 4.21.0" } }, + "packages/rollup-plugin-replace-with-ast": { + "name": "@coveo/rollup-plugin-replace-with-ast", + "version": "1.0.0", + "license": "Apache-2.0", + "devDependencies": { + "@rollup/plugin-typescript": "11.1.6", + "@rollup/pluginutils": "5.1.0", + "acorn": "8.12.1", + "magic-string": "0.30.11", + "rollup": "4.0.0-24", + "typescript": "4.8.3" + }, + "engines": { + "node": "^20.9.0" + }, + "peerDependencies": { + "rollup": "^1.20.0||^2.0.0||^3.0.0||^4.0.0" + }, + "peerDependenciesMeta": { + "rollup": { + "optional": true + } + } + }, + "packages/rollup-plugin-replace-with-ast/node_modules/@jridgewell/sourcemap-codec": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.5.0.tgz", + "integrity": "sha512-gv3ZRaISU3fjPAgNsriBRqGWQL6quFx04YMPW/zD8XMLsU32mhCCbfbO6KZFLjvYpCZ8zyDEgqsgf+PwPaM7GQ==", + "dev": true, + "license": "MIT" + }, + "packages/rollup-plugin-replace-with-ast/node_modules/@rollup/rollup-android-arm-eabi": { + "version": "4.0.0-24", + "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm-eabi/-/rollup-android-arm-eabi-4.0.0-24.tgz", + "integrity": "sha512-19cF3V1fHfzPzwu0cgZEdWLMdNkqSmKOhidqQv1CkUqAMcb7etA7WLx8YrX5ob31ruI0BYYrUDBunlIuMHHUrg==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ] + }, + "packages/rollup-plugin-replace-with-ast/node_modules/@rollup/rollup-android-arm64": { + "version": "4.0.0-24", + "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm64/-/rollup-android-arm64-4.0.0-24.tgz", + "integrity": "sha512-ftTp5ByyyozDsHfmYGeErrQmBi4ZEVZItC4Siilwretkf+cMv9z0s0Ru8ncd28OZpaO0cr9b7Afm+DIRDyE8Kw==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ] + }, + "packages/rollup-plugin-replace-with-ast/node_modules/@rollup/rollup-darwin-arm64": { + "version": "4.0.0-24", + "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-arm64/-/rollup-darwin-arm64-4.0.0-24.tgz", + "integrity": "sha512-wYXWdPbMLiIRHQeTF/r9ZoDcf3k1ROR0Kyd/caUtbs5VEZOBfnpZ/FHQPzXW0S1fzxTtD5W4tXULxARMHAlNdQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ] + }, + "packages/rollup-plugin-replace-with-ast/node_modules/@rollup/rollup-darwin-x64": { + "version": "4.0.0-24", + "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-x64/-/rollup-darwin-x64-4.0.0-24.tgz", + "integrity": "sha512-8tIz6Uga/5XdeRkid7kfNtxrvru7o4lDBxAPooZezKXbyB2ap2yKAKCqTFEXyTuPhl2yxLMa5zqZ91FBEnSbPg==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ] + }, + "packages/rollup-plugin-replace-with-ast/node_modules/@rollup/rollup-linux-arm-gnueabihf": { + "version": "4.0.0-24", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm-gnueabihf/-/rollup-linux-arm-gnueabihf-4.0.0-24.tgz", + "integrity": "sha512-ZCNBOaw2NV3BnpQ049VCPJSamss3wAoCunFcWYfhWgGyu9C0hiRvZAcKvhd7e/9EhuoIxsNxMLwI46NmZx9WBQ==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "packages/rollup-plugin-replace-with-ast/node_modules/@rollup/rollup-linux-arm64-gnu": { + "version": "4.0.0-24", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-gnu/-/rollup-linux-arm64-gnu-4.0.0-24.tgz", + "integrity": "sha512-BGnRktAZq4RI6FSicI+F6ws9paiYmjyaXUNKSukLthzgzPC91V4SXVylbFOCKvrhdWAr0lvZgcTrkgYNAmAcuQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "packages/rollup-plugin-replace-with-ast/node_modules/@rollup/rollup-linux-x64-gnu": { + "version": "4.0.0-24", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-gnu/-/rollup-linux-x64-gnu-4.0.0-24.tgz", + "integrity": "sha512-FzhHpp+vRTjIUYXMExj9Ffj2bCQgnRAzlWlsQTdYGYvPQMVadfPMvnlcr4Li8P7Yv1iBFtDzRVfZAgL5glvIAA==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "packages/rollup-plugin-replace-with-ast/node_modules/@rollup/rollup-linux-x64-musl": { + "version": "4.0.0-24", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-musl/-/rollup-linux-x64-musl-4.0.0-24.tgz", + "integrity": "sha512-0y+oXnCCT5+U5V58bY7dy65yDrWWfopFJwtC2EbFeA9SHrVjG36/TQo535ML3zdFwO+fma8r5FP1os0psbQBXQ==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "packages/rollup-plugin-replace-with-ast/node_modules/@rollup/rollup-win32-arm64-msvc": { + "version": "4.0.0-24", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-arm64-msvc/-/rollup-win32-arm64-msvc-4.0.0-24.tgz", + "integrity": "sha512-xT8djNMxVB84cCm1XILpQXkMcu8S+GBKjurXM4sc6eB1FQpFpcTAOsuQSg9xOhfPqm1xa7qqXA6ZpUhoUMboVQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ] + }, + "packages/rollup-plugin-replace-with-ast/node_modules/@rollup/rollup-win32-ia32-msvc": { + "version": "4.0.0-24", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-ia32-msvc/-/rollup-win32-ia32-msvc-4.0.0-24.tgz", + "integrity": "sha512-3gXFBlG5f18xbhVxKTM+zwciJPk097i3YswLI9cajVd4MAqMw5bGbuZkGOZOMnkzeIX0ELxovYWPbGDyUr+f5g==", + "cpu": [ + "ia32" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ] + }, + "packages/rollup-plugin-replace-with-ast/node_modules/@rollup/rollup-win32-x64-msvc": { + "version": "4.0.0-24", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-x64-msvc/-/rollup-win32-x64-msvc-4.0.0-24.tgz", + "integrity": "sha512-41+QkzRaKEZwmA14Fa2DI0QKN5hkcN/orA2KOg5vJAtvwSfB1uQTUmf6T4SGZLw/8In2TEmViB9tDVlbnXmH1A==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ] + }, + "packages/rollup-plugin-replace-with-ast/node_modules/acorn": { + "version": "8.12.1", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.12.1.tgz", + "integrity": "sha512-tcpGyI9zbizT9JbV6oYE477V6mTlXvvi0T0G3SNIYE2apm/G5huBa1+K89VGeovbg+jycCrfhl3ADxErOuO6Jg==", + "dev": true, + "license": "MIT", + "bin": { + "acorn": "bin/acorn" + }, + "engines": { + "node": ">=0.4.0" + } + }, + "packages/rollup-plugin-replace-with-ast/node_modules/magic-string": { + "version": "0.30.11", + "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.30.11.tgz", + "integrity": "sha512-+Wri9p0QHMy+545hKww7YAu5NyzF8iomPL/RQazugQ9+Ez4Ic3mERMd8ZTX5rfK944j+560ZJi8iAwgak1Ac7A==", + "dev": true, + "license": "MIT", + "dependencies": { + "@jridgewell/sourcemap-codec": "^1.5.0" + } + }, + "packages/rollup-plugin-replace-with-ast/node_modules/rollup": { + "version": "4.0.0-24", + "resolved": "https://registry.npmjs.org/rollup/-/rollup-4.0.0-24.tgz", + "integrity": "sha512-Tcdk9cYyF5abnUQP68AWuSHahowglrzQH6olnHB4Lxi7VBuflwrlpavK7d046Ep2WmwDN0ey5sr+QzLShQ7Odw==", + "dev": true, + "license": "MIT", + "bin": { + "rollup": "dist/bin/rollup" + }, + "engines": { + "node": ">=18.0.0", + "npm": ">=8.0.0" + }, + "optionalDependencies": { + "@rollup/rollup-android-arm-eabi": "4.0.0-24", + "@rollup/rollup-android-arm64": "4.0.0-24", + "@rollup/rollup-darwin-arm64": "4.0.0-24", + "@rollup/rollup-darwin-x64": "4.0.0-24", + "@rollup/rollup-linux-arm-gnueabihf": "4.0.0-24", + "@rollup/rollup-linux-arm64-gnu": "4.0.0-24", + "@rollup/rollup-linux-x64-gnu": "4.0.0-24", + "@rollup/rollup-linux-x64-musl": "4.0.0-24", + "@rollup/rollup-win32-arm64-msvc": "4.0.0-24", + "@rollup/rollup-win32-ia32-msvc": "4.0.0-24", + "@rollup/rollup-win32-x64-msvc": "4.0.0-24", + "fsevents": "~2.3.2" + } + }, + "packages/rollup-plugin-replace-with-ast/node_modules/typescript": { + "version": "4.8.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.8.3.tgz", + "integrity": "sha512-goMHfm00nWPa8UvR/CPSvykqf6dVV8x/dp0c5mFTMTIu0u0FlGWRioyy7Nn0PGAdHxpJZnuO/ut+PpQ8UiHAig==", + "dev": true, + "license": "Apache-2.0", + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=4.2.0" + } + }, "packages/samples/angular": { "name": "@coveo/atomic-angular-samples", "version": "0.0.0", diff --git a/package.json b/package.json index d6990785023..1bfadb68ef5 100644 --- a/package.json +++ b/package.json @@ -110,6 +110,7 @@ "packages/atomic-react", "packages/atomic-angular", "packages/atomic-angular/projects/*", + "packages/rollup-plugin-replace-with-ast", "packages/samples/*", "packages/samples/headless-ssr/*", "utils/*" diff --git a/packages/atomic-react/package.json b/packages/atomic-react/package.json index 56be96dc814..c5c9c45a02c 100644 --- a/packages/atomic-react/package.json +++ b/packages/atomic-react/package.json @@ -12,7 +12,7 @@ "build": "nx build", "clean": "rimraf -rf dist", "build:bundles:esm": "tsc -p tsconfig.esm.json", - "build:bundles:iife-cjs": "rollup --config rollup.config.mjs", + "build:bundles:iife-cjs": "rollup --config rollup.config.mjs --bundleConfigAsCjs", "build:bundles": "concurrently \"npm run build:bundles:esm\" \"npm run build:bundles:iife-cjs\"", "publish:npm": "npm run-script -w=@coveo/release npm-publish", "publish:bump": "npm run-script -w=@coveo/release bump", @@ -31,7 +31,7 @@ "@coveo/atomic": "2.78.0" }, "devDependencies": { - "@coveo/headless": "2.80.0", + "@coveo/rollup-plugin-replace-with-ast": "1.0.0", "@coveo/release": "1.0.0", "@rollup/plugin-commonjs": "^25.0.0", "@rollup/plugin-json": "6.1.0", diff --git a/packages/atomic-react/rollup.config.mjs b/packages/atomic-react/rollup.config.mjs index 2ecafadaa1f..090d265f86b 100644 --- a/packages/atomic-react/rollup.config.mjs +++ b/packages/atomic-react/rollup.config.mjs @@ -1,11 +1,70 @@ +import replaceWithASTPlugin from '@coveo/rollup-plugin-replace-with-ast'; import commonjs from '@rollup/plugin-commonjs'; import json from '@rollup/plugin-json'; import {nodeResolve} from '@rollup/plugin-node-resolve'; import replace from '@rollup/plugin-replace'; // import terser from '@rollup/plugin-terser'; import typescript from '@rollup/plugin-typescript'; +import {readFileSync} from 'fs'; +import {join, dirname} from 'path'; import {defineConfig} from 'rollup'; import nodePolyfills from 'rollup-plugin-polyfill-node'; +import {fileURLToPath} from 'url'; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = dirname(__filename); + +const isCDN = process.env.DEPLOYMENT_ENVIRONMENT === 'CDN'; + +let headlessVersion; + +if (isCDN) { + console.log('Building for CDN'); + + const headlessPackageJsonPath = join( + __dirname, + '../../packages/headless/package.json' + ); + + try { + const headlessPackageJson = JSON.parse( + readFileSync(headlessPackageJsonPath, 'utf8') + ); + headlessVersion = 'v' + headlessPackageJson.version; + console.log('Using headless version from package.json:', headlessVersion); + } catch (error) { + console.error('Error reading headless package.json:', error); + throw new Error('Error reading headless package.json'); + } +} + +function generateReplaceValues() { + return Object.entries(packageMappings).reduce((acc, [find, paths]) => { + acc[find] = paths.cdn; + return acc; + }, {}); +} + +const packageMappings = { + '@coveo/headless/commerce': { + cdn: `https://static.cloud.coveo.com/headless/${headlessVersion}/commerce/headless.esm.js`, + }, + '@coveo/headless/insight': { + cdn: `https://static.cloud.coveo.com/headless/${headlessVersion}/insight/headless.esm.js`, + }, + '@coveo/headless/product-recommendation': { + cdn: `https://static.cloud.coveo.com/headless/${headlessVersion}/product-recommendation/headless.esm.js`, + }, + '@coveo/headless/recommendation': { + cdn: `https://static.cloud.coveo.com/headless/${headlessVersion}/recommendation/headless.esm.js`, + }, + '@coveo/headless/case-assist': { + cdn: `https://static.cloud.coveo.com/headless/${headlessVersion}/case-assist/headless.esm.js`, + }, + '@coveo/headless': { + cdn: `https://static.cloud.coveo.com/headless/${headlessVersion}/headless.esm.js`, + }, +}; // /** @type {import("rollup").GlobalsOption} */ // const globals = { @@ -61,6 +120,10 @@ const outputCJS = ({useCase}) => ({ // }); const plugins = [ + isCDN && + replaceWithASTPlugin({ + replacements: generateReplaceValues(), + }), json(), nodePolyfills(), typescript({tsconfig: 'tsconfig.iife.json'}), diff --git a/packages/atomic/package.json b/packages/atomic/package.json index 37276ac0e3a..82c352d13ae 100644 --- a/packages/atomic/package.json +++ b/packages/atomic/package.json @@ -48,6 +48,7 @@ }, "dependencies": { "@coveo/bueno": "0.46.1", + "@coveo/headless": "2.80.0", "@popperjs/core": "^2.11.6", "@salesforce-ux/design-system": "^2.16.1", "@stencil/store": "2.0.16", @@ -66,8 +67,8 @@ "@axe-core/playwright": "4.9.1", "@babel/core": "7.24.9", "@coveo/atomic": "file:.", - "@coveo/headless": "2.80.0", "@coveo/release": "1.0.0", + "@coveo/rollup-plugin-replace-with-ast": "1.0.0", "@custom-elements-manifest/analyzer": "0.10.3", "@fullhuman/postcss-purgecss": "6.0.0", "@nx/js": "19.5.3", diff --git a/packages/atomic/stencil.config.ts b/packages/atomic/stencil.config.ts index d2f992757db..c61b7a98eb0 100644 --- a/packages/atomic/stencil.config.ts +++ b/packages/atomic/stencil.config.ts @@ -1,3 +1,4 @@ +import replaceWithASTPlugin from '@coveo/rollup-plugin-replace-with-ast'; import alias from '@rollup/plugin-alias'; import replacePlugin from '@rollup/plugin-replace'; import {postcss} from '@stencil-community/postcss'; @@ -16,10 +17,81 @@ import html from 'rollup-plugin-html'; import {inlineSvg} from 'stencil-inline-svg'; import tailwind from 'tailwindcss'; import tailwindNesting from 'tailwindcss/nesting'; +import headlessJson from '../../packages/headless/package.json'; import {generateAngularModuleDefinition as angularModule} from './stencil-plugin/atomic-angular-module'; const isProduction = process.env.BUILD === 'production'; +const isCDN = process.env.DEPLOYMENT_ENVIRONMENT === 'CDN'; +let headlessVersion: string; + +if (isCDN) { + console.log('Building for CDN'); + headlessVersion = 'v' + headlessJson.version; +} + +const packageMappings: {[key: string]: {devWatch: string; cdn: string}} = { + '@coveo/headless/commerce': { + devWatch: path.resolve( + __dirname, + './src/external-builds/commerce/headless.esm.js' + ), + cdn: `https://static.cloud.coveo.com/headless/${headlessVersion}/commerce/headless.esm.js`, + }, + '@coveo/headless/insight': { + devWatch: path.resolve( + __dirname, + './src/external-builds/insight/headless.esm.js' + ), + cdn: `https://static.cloud.coveo.com/headless/${headlessVersion}/insight/headless.esm.js`, + }, + '@coveo/headless/product-recommendation': { + devWatch: path.resolve( + __dirname, + './src/external-builds/product-recommendation/headless.esm.js' + ), + cdn: `https://static.cloud.coveo.com/headless/${headlessVersion}/product-recommendation/headless.esm.js`, + }, + '@coveo/headless/recommendation': { + devWatch: path.resolve( + __dirname, + './src/external-builds/recommendation/headless.esm.js' + ), + cdn: `https://static.cloud.coveo.com/headless/${headlessVersion}/recommendation/headless.esm.js`, + }, + '@coveo/headless/case-assist': { + devWatch: path.resolve( + __dirname, + './src/external-builds/case-assist/headless.esm.js' + ), + cdn: `https://static.cloud.coveo.com/headless/${headlessVersion}/case-assist/headless.esm.js`, + }, + '@coveo/headless': { + devWatch: path.resolve(__dirname, './src/external-builds/headless.esm.js'), + cdn: `https://static.cloud.coveo.com/headless/${headlessVersion}/headless.esm.js`, + }, + /* '@coveo/bueno': { + devWatch: path.resolve(__dirname, './src/external-builds/bueno.esm.js'), + cdn: `https://static.cloud.coveo.com/bueno/${headlessVersion}/bueno.esm.js`, + }, */ +}; + +function generateAliasEntries() { + return Object.entries(packageMappings).map(([find, paths]) => ({ + find, + replacement: paths.devWatch, + })); +} + +function generateReplaceValues(): {[key: string]: string} { + return Object.entries(packageMappings).reduce( + (acc: {[key: string]: string}, [find, paths]) => { + acc[find] = paths.cdn; + return acc; + }, + {} + ); +} function filterComponentsByUseCaseForReactOutput(useCasePath: string) { return readdirSync(useCasePath, { recursive: true, @@ -56,8 +128,10 @@ function replace() { const env = isProduction ? 'production' : 'development'; const version = getPackageVersion(); return replacePlugin({ - 'process.env.NODE_ENV': JSON.stringify(env), - 'process.env.VERSION': JSON.stringify(version), + values: { + 'process.env.NODE_ENV': JSON.stringify(env), + 'process.env.VERSION': JSON.stringify(version), + }, preventAssignment: true, }); } @@ -180,63 +254,38 @@ export const config: Config = { ], }), replace(), + isCDN && + replaceWithASTPlugin({ + replacements: generateReplaceValues(), + }), ], rollupPlugins: { before: [ isDevWatch && alias({ - entries: [ - { - find: '@coveo/headless/case-assist', - replacement: path.resolve( - __dirname, - './src/external-builds/case-assist/headless.esm.js' - ), - }, - { - find: '@coveo/headless/commerce', - replacement: path.resolve( - __dirname, - './src/external-builds/commerce/headless.esm.js' - ), - }, - { - find: '@coveo/headless/recommendation', - replacement: path.resolve( - __dirname, - './src/external-builds/recommendation/headless.esm.js' - ), - }, - { - find: '@coveo/headless/commerce', - replacement: path.resolve( - __dirname, - './src/external-builds/commerce/headless.esm.js' - ), - }, - { - find: '@coveo/headless/insight', - replacement: path.resolve( - __dirname, - './src/external-builds/insight/headless.esm.js' - ), - }, - { - find: '@coveo/headless', - replacement: path.resolve( - __dirname, - './src/external-builds/headless.esm.js' - ), - }, - ], + entries: generateAliasEntries(), }), html({ include: 'src/templates/**/*.html', }), isDevWatch && replaceHeadlessMap(), + externalizeDependenciesPlugin(), ], }, extras: { enableImportInjection: true, }, }; + +function externalizeDependenciesPlugin() { + return { + name: 'externalize-dependencies', + resolveId(source: string) { + // Externalize @coveo/headless and @coveo/bueno + if (/^@coveo\/(headless)/.test(source)) { + return false; + } + return null; + }, + }; +} diff --git a/packages/headless/tsconfig.json b/packages/headless/tsconfig.json index 8181d8bb420..379cab99ab1 100644 --- a/packages/headless/tsconfig.json +++ b/packages/headless/tsconfig.json @@ -12,5 +12,11 @@ "noUnusedParameters": true, "types": ["node", "jest"] }, - "exclude": ["./temp/**", "./dist/**", "./docs/**", "./ponyfills/**"] + "exclude": [ + "./temp/**", + "./dist/**", + "./docs/**", + "./ponyfills/**", + "./src/external-builds/**" + ] } diff --git a/packages/rollup-plugin-replace-with-ast/LICENSE b/packages/rollup-plugin-replace-with-ast/LICENSE new file mode 100644 index 00000000000..052e59b641a --- /dev/null +++ b/packages/rollup-plugin-replace-with-ast/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright 2024 Coveo Solutions Inc. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. \ No newline at end of file diff --git a/packages/rollup-plugin-replace-with-ast/package.json b/packages/rollup-plugin-replace-with-ast/package.json new file mode 100644 index 00000000000..bad2213f1fb --- /dev/null +++ b/packages/rollup-plugin-replace-with-ast/package.json @@ -0,0 +1,49 @@ +{ + "name": "@coveo/rollup-plugin-replace-with-ast", + "repository": { + "type": "git", + "url": "git+https://github.com/coveo/ui-kit.git", + "directory": "packages/rollup-plugin-replace-with-ast" + }, + "private": true, + "main": "./dist/cjs/index.js", + "module": "./dist/es/index.js", + "exports": { + "types": "./types/index.d.ts", + "import": "./dist/es/index.js", + "default": "./dist/cjs/index.js" + }, + "engines": { + "node": "^20.9.0" + }, + "types": "./dist/definitions/index.d.ts", + "license": "Apache-2.0", + "version": "1.0.0", + "files": [ + "dist/", + "types/" + ], + "scripts": { + "dev": "concurrently \"npm run build:definitions -- -w\" \"npm run build:bundles -- dev\"", + "build": "nx build", + "build:bundles": "rollup -c", + "build:definitions": "tsc -d --emitDeclarationOnly --declarationDir dist/definitions", + "clean": "rimraf -rf dist/*" + }, + "peerDependencies": { + "rollup": "^1.20.0||^2.0.0||^3.0.0||^4.0.0" + }, + "peerDependenciesMeta": { + "rollup": { + "optional": true + } + }, + "devDependencies": { + "@rollup/plugin-typescript": "11.1.6", + "@rollup/pluginutils": "5.1.0", + "acorn": "8.12.1", + "magic-string": "0.30.11", + "rollup": "4.0.0-24", + "typescript": "4.8.3" + } +} diff --git a/packages/rollup-plugin-replace-with-ast/project.json b/packages/rollup-plugin-replace-with-ast/project.json new file mode 100644 index 00000000000..03c1747237b --- /dev/null +++ b/packages/rollup-plugin-replace-with-ast/project.json @@ -0,0 +1,20 @@ +{ + "name": "rollup-plugin-replace-with-ast", + "private": true, + "$schema": "../../node_modules/nx/schemas/project-schema.json", + "targets": { + "release:phase1": {}, + "cached:build": { + "executor": "nx:run-commands", + "options": { + "commands": ["npm run build:bundles", "npm run build:definitions"], + "parallel": true, + "cwd": "packages/rollup-plugin-replace-with-ast" + } + }, + "build": { + "dependsOn": ["cached:build"], + "executor": "nx:noop" + } + } +} diff --git a/packages/rollup-plugin-replace-with-ast/rollup.config.mjs b/packages/rollup-plugin-replace-with-ast/rollup.config.mjs new file mode 100644 index 00000000000..eb7b91fe275 --- /dev/null +++ b/packages/rollup-plugin-replace-with-ast/rollup.config.mjs @@ -0,0 +1,35 @@ +import typescript from '@rollup/plugin-typescript'; + +export default { + input: 'src/index.ts', + + output: [ + { + file: 'dist/cjs/index.js', + format: 'cjs', + exports: 'named', + footer: 'module.exports = Object.assign(exports.default, exports);', + sourcemap: true, + }, + { + file: './dist/es/index.js', + format: 'es', + sourcemap: true, + plugins: [emitModulePackageFile()], + }, + ], + plugins: [typescript({sourceMap: true})], +}; + +export function emitModulePackageFile() { + return { + name: 'emit-module-package-file', + generateBundle() { + this.emitFile({ + type: 'asset', + fileName: 'package.json', + source: `{"type":"module"}`, + }); + }, + }; +} diff --git a/packages/rollup-plugin-replace-with-ast/src/index.ts b/packages/rollup-plugin-replace-with-ast/src/index.ts new file mode 100644 index 00000000000..174add14412 --- /dev/null +++ b/packages/rollup-plugin-replace-with-ast/src/index.ts @@ -0,0 +1,81 @@ +import {createFilter} from '@rollup/pluginutils'; +import { + parse, + Node, + ImportDeclaration, + ExportNamedDeclaration, + ExportAllDeclaration, + Program, +} from 'acorn'; +import MagicString from 'magic-string'; + +interface PluginOptions { + include?: string | string[]; + exclude?: string | string[]; + replacements?: Record; +} + +function replaceWithASTPlugin(options: PluginOptions = {}) { + const filter = createFilter(options.include, options.exclude); + const replacements = options.replacements || {}; + + return { + name: 'replace-with-ast-plugin', + + transform(code: string, id: unknown) { + if (!filter(id)) { + return null; + } + + let ast: Program; + try { + ast = parse(code, {ecmaVersion: 2020, sourceType: 'module'}); + } catch (error) { + console.error(`Error parsing ${id}: ${(error as Error).message}`); + return null; + } + + const magicString = new MagicString(code); + + ast.body.forEach((node: Node) => { + if ( + node.type === 'ImportDeclaration' || + node.type === 'ImportDefaultSpecifier' || + node.type === 'ImportSpecifier' || + node.type === 'ImportNamespaceSpecifier' || + node.type === 'ExportSpecifier' || + node.type === 'ExportDefaultSpecifier' || + node.type === 'ExportNamedDeclaration' || + node.type === 'ExportAllDeclaration' + ) { + const source = ( + node as + | ImportDeclaration + | ExportNamedDeclaration + | ExportAllDeclaration + ).source; + if ( + source && + typeof source.value === 'string' && + replacements[source.value] + ) { + const start = source.start; + const end = source.end; + magicString.overwrite( + start, + end, + JSON.stringify(replacements[source.value]) + ); + } + } + }); + + return { + code: magicString.toString(), + map: magicString.generateMap({hires: true}), + }; + }, + }; +} + +export default replaceWithASTPlugin; diff --git a/packages/rollup-plugin-replace-with-ast/tsconfig.json b/packages/rollup-plugin-replace-with-ast/tsconfig.json new file mode 100644 index 00000000000..1c7b2d4da00 --- /dev/null +++ b/packages/rollup-plugin-replace-with-ast/tsconfig.json @@ -0,0 +1,18 @@ +{ + "compilerOptions": { + "allowSyntheticDefaultImports": true, + "esModuleInterop": true, + "lib": ["es6"], + "module": "esnext", + "moduleResolution": "node", + "skipLibCheck": true, + "noEmitOnError": false, + "noUnusedLocals": true, + "noUnusedParameters": true, + "pretty": true, + "sourceMap": true, + "strict": true, + "target": "es2019" + }, + "exclude": ["./dist/**", "./test/types/**"] +} diff --git a/packages/rollup-plugin-replace-with-ast/types/index.d.ts b/packages/rollup-plugin-replace-with-ast/types/index.d.ts new file mode 100644 index 00000000000..a94814dbf52 --- /dev/null +++ b/packages/rollup-plugin-replace-with-ast/types/index.d.ts @@ -0,0 +1,12 @@ +import type { Plugin } from 'rollup'; + +export interface PluginOptions { + include?: string | string[]; + exclude?: string | string[]; + replacements?: Record; +} + +/** + * A Rollup plugin for replacing import/export paths using AST. + */ +export default function replaceWithASTPlugin(options?: PluginOptions): Plugin; diff --git a/packages/samples/angular/project.json b/packages/samples/angular/project.json index 0acb475365c..718e6f28c55 100644 --- a/packages/samples/angular/project.json +++ b/packages/samples/angular/project.json @@ -6,7 +6,10 @@ "dependsOn": ["^build", "clean"], "executor": "nx:run-commands", "options": { - "commands": ["npm run build:assets", "npm run build:angular"], + "commands": [ + "if [ \"$DEPLOYMENT_ENVIRONMENT\" != \"CDN\" ]; then npm run build:assets; fi", + "if [ \"$DEPLOYMENT_ENVIRONMENT\" != \"CDN\" ]; then npm run build:angular; fi" + ], "parallel": false, "cwd": "packages/samples/angular" } diff --git a/packages/samples/atomic-next/project.json b/packages/samples/atomic-next/project.json index 87776124b46..413f5a9be29 100644 --- a/packages/samples/atomic-next/project.json +++ b/packages/samples/atomic-next/project.json @@ -6,9 +6,9 @@ "executor": "nx:run-commands", "options": { "commands": [ - "npx next build", - "tsc --noEmit", - "tsc --module commonjs --noEmit" + "if [ \"$DEPLOYMENT_ENVIRONMENT\" != \"CDN\" ]; then npx next build; fi", + "if [ \"$DEPLOYMENT_ENVIRONMENT\" != \"CDN\" ]; then tsc --noEmit; fi", + "if [ \"$DEPLOYMENT_ENVIRONMENT\" != \"CDN\" ]; then tsc --module commonjs --noEmit; fi" ], "parallel": true, "cwd": "packages/samples/atomic-next" diff --git a/packages/samples/stencil/src/components/app-root/app-root.tsx b/packages/samples/stencil/src/components/app-root/app-root.tsx index 5b48bdcbca9..2e6a2d78825 100644 --- a/packages/samples/stencil/src/components/app-root/app-root.tsx +++ b/packages/samples/stencil/src/components/app-root/app-root.tsx @@ -18,6 +18,7 @@ export class AppRoot { const searchInterface: HTMLAtomicSearchInterfaceElement = document.querySelector('atomic-search-interface')!; + await customElements.whenDefined('atomic-search-interface'); await searchInterface.initialize({ ...getSampleSearchEngineConfiguration(), analytics: {analyticsMode: 'legacy'}, diff --git a/packages/samples/stencil/src/pages/hsp.html b/packages/samples/stencil/src/pages/hsp.html index 481ac94a17c..d394ea5cb3f 100644 --- a/packages/samples/stencil/src/pages/hsp.html +++ b/packages/samples/stencil/src/pages/hsp.html @@ -4,16 +4,9 @@ Atomic in Stencil - + - - - - + diff --git a/packages/samples/stencil/src/utils/atomic-loader.ts b/packages/samples/stencil/src/utils/atomic-loader.ts new file mode 100644 index 00000000000..fd6969dc69a --- /dev/null +++ b/packages/samples/stencil/src/utils/atomic-loader.ts @@ -0,0 +1,3 @@ +import {defineCustomElements} from '@coveo/atomic/loader'; + +defineCustomElements(); diff --git a/packages/samples/stencil/stencil.config.ts b/packages/samples/stencil/stencil.config.ts index 78aa589eb14..a29e147a5f8 100644 --- a/packages/samples/stencil/stencil.config.ts +++ b/packages/samples/stencil/stencil.config.ts @@ -5,6 +5,7 @@ import html from 'rollup-plugin-html'; export const config: Config = { globalStyle: 'src/style/index.css', + globalScript: 'src/utils/atomic-loader.ts', taskQueue: 'async', outputTargets: [ { @@ -13,8 +14,18 @@ export const config: Config = { copy: [ {src: 'pages', keepDirStructure: false}, { - src: '../../../../node_modules/@coveo/atomic/dist/atomic', - dest: 'build/atomic', + src: '../../../../node_modules/@coveo/atomic/dist/atomic/assets', + dest: 'assets', + keepDirStructure: false, + }, + { + src: '../../../../node_modules/@coveo/atomic/dist/atomic/lang', + dest: 'lang', + keepDirStructure: false, + }, + { + src: '../../../../node_modules/@coveo/atomic/dist/atomic/themes', + dest: 'themes', keepDirStructure: false, }, ],