From 5e0941d0a3ee547f60ce371d73942c0a1626e932 Mon Sep 17 00:00:00 2001 From: Felix Perron-Brault Date: Tue, 17 Sep 2024 18:01:53 -0400 Subject: [PATCH] make bueno external for headless https://coveord.atlassian.net/browse/KIT-3551 --- package-lock.json | 34 ++++++++++++++++++++++++++++++- packages/atomic/package.json | 3 ++- packages/atomic/stencil.config.ts | 8 ++++++-- packages/bueno/esbuild.mjs | 30 ++++++++++++++++++++++++++- packages/bueno/project.json | 12 +++++++++++ packages/headless/.gitignore | 4 +++- packages/headless/esbuild.mjs | 19 ++++++++++++++--- packages/headless/package.json | 1 + 8 files changed, 102 insertions(+), 9 deletions(-) diff --git a/package-lock.json b/package-lock.json index 4840951bd1c..1c69ca223f1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -28514,6 +28514,36 @@ "integrity": "sha512-jyfL/pwPqaFXyKnj8lP8iLk6Z0m099uXR45aSN8Av1XD4vhvQutxxPzgA2bTcAwQpa1zCXDcWOlhFgyP3GKqhQ==", "dev": true }, + "node_modules/esbuild-plugin-alias-path": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/esbuild-plugin-alias-path/-/esbuild-plugin-alias-path-2.0.2.tgz", + "integrity": "sha512-YK8H9bzx6/CG6YBV11XjoNLjRhNZP0Ta4xZ3ATHhPn7pN8ljQGg+zne4d47DpIzF8/sX2qM+xQWev0CvaD2rSQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "find-up": "5.0.0", + "fs-extra": "^10.1.0", + "jsonfile": "^6.1.0" + }, + "peerDependencies": { + "esbuild": ">= 0.14.0" + } + }, + "node_modules/esbuild-plugin-alias-path/node_modules/fs-extra": { + "version": "10.1.0", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-10.1.0.tgz", + "integrity": "sha512-oRXApq54ETRj4eMiFzGnHWGy+zo5raudjuxN0b8H7s/RU2oW0Wvsx9O0ACRN/kRq9E8Vu/ReskGB5o3ji+FzHQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "graceful-fs": "^4.2.0", + "jsonfile": "^6.0.1", + "universalify": "^2.0.0" + }, + "engines": { + "node": ">=12" + } + }, "node_modules/esbuild-plugin-umd-wrapper": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/esbuild-plugin-umd-wrapper/-/esbuild-plugin-umd-wrapper-2.0.3.tgz", @@ -51982,7 +52012,8 @@ "node": "^20.9.0" }, "peerDependencies": { - "@coveo/headless": "3.0.0" + "@coveo/bueno": "0.46.1", + "@coveo/headless": "2.80.0" } }, "packages/atomic-angular": { @@ -55369,6 +55400,7 @@ "@microsoft/api-extractor": "7.47.3", "@microsoft/api-extractor-model": "7.29.3", "@microsoft/tsdoc": "0.15.0", + "esbuild-plugin-alias-path": "2.0.2", "eslint-plugin-canonical": "4.18.0", "execa": "8.0.1", "install": "0.13.0", diff --git a/packages/atomic/package.json b/packages/atomic/package.json index 31a6db524c7..1ef5a5513b6 100644 --- a/packages/atomic/package.json +++ b/packages/atomic/package.json @@ -141,7 +141,8 @@ "wait-on": "7.2.0" }, "peerDependencies": { - "@coveo/headless": "3.0.0" + "@coveo/headless": "2.80.0", + "@coveo/bueno": "0.46.1" }, "license": "Apache-2.0", "engines": { diff --git a/packages/atomic/stencil.config.ts b/packages/atomic/stencil.config.ts index 15d55a49733..3ecb9510821 100644 --- a/packages/atomic/stencil.config.ts +++ b/packages/atomic/stencil.config.ts @@ -17,15 +17,19 @@ import {inlineSvg} from 'stencil-inline-svg'; import tailwind from 'tailwindcss'; import tailwindNesting from 'tailwindcss/nesting'; import headlessJson from '../../packages/headless/package.json'; +import buenoJson 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 = ''; +let buenoVersion: string = ''; + if (isCDN) { console.log('Building for CDN'); headlessVersion = 'v' + headlessJson.version; + buenoVersion = 'v' + buenoJson.version; } const packageMappings: {[key: string]: {devWatch: string; cdn: string}} = { @@ -68,10 +72,10 @@ const packageMappings: {[key: string]: {devWatch: string; cdn: string}} = { devWatch: path.resolve(__dirname, './src/external-builds/headless.esm.js'), cdn: `/headless/${headlessVersion}/headless.esm.js`, }, - /* '@coveo/bueno': { + '@coveo/bueno': { devWatch: path.resolve(__dirname, './src/external-builds/bueno.esm.js'), cdn: `/bueno/${buenoVersion}/bueno.esm.js`, - }, */ + }, }; function generateAliasEntries() { diff --git a/packages/bueno/esbuild.mjs b/packages/bueno/esbuild.mjs index 92a53cbe190..7ec5d636e38 100644 --- a/packages/bueno/esbuild.mjs +++ b/packages/bueno/esbuild.mjs @@ -44,6 +44,28 @@ function browserEsm() { }); } +function browserEsmForAtomicDevelopment() { + const buildAtomic = build({ + ...base, + platform: 'browser', + outfile: '../atomic/src/external-builds/bueno.esm.js', + format: 'esm', + watch: devMode, + minify: false, + }); + + const buildHeadless = build({ + ...base, + platform: 'browser', + outfile: '../headless/src/external-builds/bueno.esm.js', + format: 'esm', + watch: devMode, + minify: false, + }); + + return Promise.all([buildAtomic, buildHeadless]); +} + function browserUmd() { return build({ ...base, @@ -58,7 +80,13 @@ function browserUmd() { } async function main() { - await Promise.all([nodeCjs(), nodeEsm(), browserEsm(), browserUmd()]); + await Promise.all([ + nodeCjs(), + nodeEsm(), + browserEsm(), + browserUmd(), + browserEsmForAtomicDevelopment(), + ]); } main(); diff --git a/packages/bueno/project.json b/packages/bueno/project.json index d3cec81afb3..17a91046d3a 100644 --- a/packages/bueno/project.json +++ b/packages/bueno/project.json @@ -1,10 +1,22 @@ { "name": "bueno", "$schema": "../../node_modules/nx/schemas/project-schema.json", + "namedInputs": { + "negativeBuildOutputs": [ + "!{projectRoot}/dist", + "!{workspaceRoot}/packages/atomic/src/external-builds", + "!{workspaceRoot}/packages/headless/src/external-builds" + ] + }, "targets": { "release:phase1": {}, "cached:build": { "executor": "nx:run-commands", + "outputs": [ + "{projectRoot}/dist", + "{workspaceRoot}/packages/atomic/src/external-builds", + "{workspaceRoot}/packages/headless/src/external-builds" + ], "options": { "commands": ["npm run build:bundles", "npm run build:definitions"], "parallel": true, diff --git a/packages/headless/.gitignore b/packages/headless/.gitignore index a38284ed80e..a1fe693e0be 100644 --- a/packages/headless/.gitignore +++ b/packages/headless/.gitignore @@ -1,3 +1,5 @@ docs/js temp/ -doc-parser/build \ No newline at end of file +doc-parser/build + +src/external-builds diff --git a/packages/headless/esbuild.mjs b/packages/headless/esbuild.mjs index f338a8a8436..60a60abed63 100644 --- a/packages/headless/esbuild.mjs +++ b/packages/headless/esbuild.mjs @@ -1,14 +1,17 @@ import alias from 'esbuild-plugin-alias'; +import {aliasPath} from 'esbuild-plugin-alias-path'; import {umdWrapper} from 'esbuild-plugin-umd-wrapper'; -import {readFileSync, promises, writeFileSync} from 'node:fs'; +import {readFileSync, writeFileSync} from 'node:fs'; import {createRequire} from 'node:module'; -import {dirname, resolve} from 'node:path'; +import path, {dirname, resolve} from 'node:path'; import {build} from '../../scripts/esbuild/build.mjs'; import {apacheLicense} from '../../scripts/license/apache.mjs'; const require = createRequire(import.meta.url); const devMode = process.argv[2] === 'dev'; +const __dirname = dirname(new URL(import.meta.url).pathname); + const useCaseEntries = { search: 'src/index.ts', recommendation: 'src/recommendation.index.ts', @@ -85,6 +88,16 @@ const browserEsmForAtomicDevelopment = Object.entries(useCaseEntries).map( format: 'esm', watch: devMode, minify: false, + plugins: [ + aliasPath({ + alias: { + '@coveo/bueno': path.resolve( + __dirname, + './src/external-builds/bueno.esm.js' + ), + }, + }), + ], }, outDir ); @@ -192,7 +205,7 @@ async function buildBrowserConfig(options, outDir) { minify: true, sourcemap: true, metafile: true, - external: ['crypto'], + external: ['crypto', '@coveo/bueno'], ...options, plugins: [ alias({ diff --git a/packages/headless/package.json b/packages/headless/package.json index 83b7c00fdf9..46ef870f7e9 100644 --- a/packages/headless/package.json +++ b/packages/headless/package.json @@ -165,6 +165,7 @@ "@microsoft/api-extractor": "7.47.3", "@microsoft/api-extractor-model": "7.29.3", "@microsoft/tsdoc": "0.15.0", + "esbuild-plugin-alias-path": "2.0.2", "eslint-plugin-canonical": "4.18.0", "execa": "8.0.1", "install": "0.13.0",