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

chore: setup lit cohabitation #4834

Merged
merged 43 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from 39 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
f11bd1b
proxy loader & co
louis-bompart Dec 5, 2024
781224c
check if browser before observe
louis-bompart Dec 6, 2024
aa6fdb4
one migration working, in storybook
louis-bompart Dec 6, 2024
db2c67a
angular & sample to fix
louis-bompart Dec 6, 2024
d34ef11
angular working
louis-bompart Dec 6, 2024
e75f353
everything build
louis-bompart Dec 6, 2024
7efee96
plock 2
louis-bompart Dec 6, 2024
79942fd
plock 2
louis-bompart Dec 6, 2024
9e3a6d8
dev might work
louis-bompart Dec 11, 2024
255b7b4
quirck-quantic
louis-bompart Dec 11, 2024
7794101
derp
louis-bompart Dec 11, 2024
44eed9b
derp
louis-bompart Dec 11, 2024
2aaf66a
derp
louis-bompart Dec 11, 2024
6b89d3e
tweak cypress test
louis-bompart Dec 11, 2024
a4b8def
reify.mjs types update
louis-bompart Dec 11, 2024
ff09a36
odd linting
louis-bompart Dec 11, 2024
66b00ff
tweak icon cypress test
louis-bompart Dec 11, 2024
f1dd311
assets path
louis-bompart Dec 11, 2024
262f47a
restore nx.json
louis-bompart Dec 11, 2024
b50b220
resultTemplateRegistered should be false first
louis-bompart Dec 11, 2024
ebca588
use accessible css in test
louis-bompart Dec 11, 2024
dc1db44
change app type
louis-bompart Dec 12, 2024
453e689
tweak
louis-bompart Dec 12, 2024
3e3970a
mergemaster
louis-bompart Dec 12, 2024
7103238
react-ok
louis-bompart Dec 13, 2024
7509d2b
shouldwork
louis-bompart Dec 13, 2024
7feb498
tweak lit/stencil boundaries
louis-bompart Dec 13, 2024
13cb108
derp
louis-bompart Dec 13, 2024
e859842
Merge branch 'master' into lab/migrate-one
louis-bompart Dec 13, 2024
1c2f41d
trigger build
louis-bompart Dec 13, 2024
6be1235
clean up, use index
louis-bompart Dec 13, 2024
d01efd6
generated react output for lit
louis-bompart Dec 13, 2024
0ef3abe
lint generated files
louis-bompart Dec 13, 2024
f48d497
mv lit to prd dep
louis-bompart Dec 13, 2024
1e5207b
comment out exports of atomic-text
louis-bompart Jan 7, 2025
21fab6d
revert back atomic-text
louis-bompart Jan 7, 2025
bf9f467
mergemaster
louis-bompart Jan 7, 2025
3d8186a
cleaning
louis-bompart Jan 7, 2025
2b6cd7e
cleaning
louis-bompart Jan 8, 2025
dcadb13
Merge branch 'master' into chore/cohab-setup
louis-bompart Jan 8, 2025
08d7c1f
Delete packages/atomic/src/components/common/interface/lit-bindings.ts
louis-bompart Jan 8, 2025
23fce64
merge master
louis-bompart Jan 13, 2025
5430069
bump
louis-bompart Jan 13, 2025
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
2 changes: 2 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ module.exports = {
'scripts/deploy/execute-deployment-pipeline.mjs',
'build',
'.deployment.config.json',
'packages/atomic-angular/scripts/build-lit.mjs',
'packages/atomic-react/scripts/build-lit.mjs',
],
env: {
jest: true,
Expand Down
4 changes: 2 additions & 2 deletions .github/actions/e2e-atomic-insight-panel/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ runs:
browser: chrome
command-prefix: 'npx -w @coveo/atomic cypress-repeat run -n 3 --until-passes --rerun-failed-only --'
config-file: cypress-insight-panel.config.mjs
start: npm start -w @coveo/atomic
wait-on: 'http://localhost:3333/ping'
start: npx nx web:dev atomic
wait-on: 'http://localhost:3333'
wait-on-timeout: 600000
install: false
record: false
4 changes: 2 additions & 2 deletions .github/actions/e2e-atomic-screenshots/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ runs:
browser: chrome
command-prefix: 'npx -w @coveo/atomic cypress-repeat run -n 3 --until-passes --rerun-failed-only --'
config-file: cypress-screenshots.config.mjs
start: npm start -w @coveo/atomic
wait-on: 'http://localhost:3333/ping'
start: npx nx web:dev atomic
wait-on: 'http://localhost:3333'
wait-on-timeout: 600000
install: false
record: false
Expand Down
4 changes: 2 additions & 2 deletions .github/actions/e2e-atomic/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ runs:
browser: chrome
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/ping'
start: npx nx web:dev atomic
wait-on: 'http://localhost:3333'
wait-on-timeout: 600000
install: false
record: false
Expand Down
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@ packages/samples/headless-commerce-ssr-remix/build/**/*
packages/samples/angular/src/lang/*.json
packages/samples/vuejs/public/lang/*.json
.deployment.config.json
packages/atomic-angular/scripts/build-lit.mjs
packages/atomic-react/scripts/build-lit.mjs
28 changes: 15 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion packages/atomic-angular/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
"dependsOn": ["^build"],
"executor": "nx:run-commands",
"options": {
"commands": ["npm run build:bundles", "npm run build:assets"],
"commands": [
"node ./scripts/build-lit.mjs",
"npm run build:bundles",
"npm run build:assets"
],
"parallel": false,
"cwd": "packages/atomic-angular"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3084,3 +3084,5 @@ export class AtomicTimeframeFacet {
export declare interface AtomicTimeframeFacet extends Components.AtomicTimeframeFacet {}



import type {} from '@coveo/atomic/components';
59 changes: 59 additions & 0 deletions packages/atomic-angular/scripts/build-lit.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import cem from '@coveo/atomic/custom-elements-manifest' with {type: 'json'};
import { createWriteStream, readFileSync, writeFileSync } from 'fs';

const isLitDeclaration = (declaration) => declaration?.superclass?.name === 'LitElement';

const atomicAngularModuleFilePath ='projects/atomic-angular/src/lib/stencil-generated/atomic-angular.module.ts';
const atomicAngularModuleFileContent = readFileSync(atomicAngularModuleFilePath, 'utf-8');
const atomicAngularComponentFileStream = createWriteStream('projects/atomic-angular/src/lib/stencil-generated/components.ts', {flags: 'a'});
const litDeclarations = [];


const declarationToProxyCmp = (declaration) =>
`
@ProxyCmp({
inputs: [${declaration.attributes.map(attr => `'${attr.name}'`).join(', ')}]
})
@Component({
selector: '${declaration.tagName}',
changeDetection: ChangeDetectionStrategy.OnPush,
template: '<ng-content></ng-content>',
// eslint-disable-next-line @angular-eslint/no-inputs-metadata-property
inputs: [${declaration.attributes.map(attr => `'${attr.name}'`).join(', ')}]
})
export class ${declaration.name} {
protected readonly el: HTMLElement;
constructor(c: ChangeDetectorRef, el: ElementRef, protected z: NgZone) {
c.detach();
this.el = el.nativeElement;
}
}

export declare interface ${declaration.name} extends Lit${declaration.name} {}
`

const declarationToLitImport = (declaration) => `${declaration.name} as Lit${declaration.name}`;

const litImports = []

for (const module of cem.modules) {
for (const declaration of module.declarations) {
if (isLitDeclaration(declaration)) {
atomicAngularComponentFileStream.write(declarationToProxyCmp(declaration));
litImports.push(declarationToLitImport(declaration));
litDeclarations.push(`${declaration.name}`);
}
}
}
atomicAngularComponentFileStream.write(`\nimport type {${litImports.join(',')}} from '@coveo/atomic/components';`);
atomicAngularComponentFileStream.end();


if(litDeclarations.length > 0) {
writeFileSync(
atomicAngularModuleFilePath,
atomicAngularModuleFileContent
.replace(/const DECLARATIONS = \[\n/m, `const DECLARATIONS = [\n${litDeclarations.join(',\n')},\n`)
.replace(/^import \{$/m, `import {\n${litDeclarations.join(',\n')},`)
);
}
4 changes: 3 additions & 1 deletion packages/atomic-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
"commerce/"
],
"dependencies": {
"@coveo/atomic": "3.12.1"
"@coveo/atomic": "3.12.1",
"@lit/react": "1.0.6",
"lit": "3.2.1"
},
"devDependencies": {
"@coveo/release": "1.0.0",
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": [
"node ./scripts/build-lit.mjs",
"npm run build:fixLoaderImportPaths",
"npm run build:fixGeneratedImportPaths",
"npm run build:bundles",
Expand Down
5 changes: 5 additions & 0 deletions packages/atomic-react/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,12 @@ const commonExternal = [
'react-dom',
'react-dom/client',
'react-dom/server',
'lit',
'lit/decorators.js',
'@lit/react',
'@coveo/atomic',
'@coveo/atomic/loader',
'@coveo/atomic/components',
'@coveo/headless',
'@coveo/headless/recommendation',
'@coveo/headless/commerce',
Expand Down
90 changes: 90 additions & 0 deletions packages/atomic-react/scripts/build-lit.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import cem from '@coveo/atomic/custom-elements-manifest' with {type: 'json'};
import {writeFileSync} from 'node:fs';
import * as prettier from 'prettier';

const isLitDeclaration = (declaration) =>
declaration?.superclass?.name === 'LitElement';

const entries = [
{
path: 'src/components/search/components.ts',
content: '',
excludedComponents: [
'atomic-result-template',
'atomic-recs-result-template',
'atomic-field-condition',
],
excludedComponentDirectories: ['src/components/commerce'],
computedComponentImports: [],
},
{
path: 'src/components/commerce/components.ts',
content: '',
excludedComponents: [
'atomic-product-template',
'atomic-recs-result-template',
'atomic-field-condition',
],
excludedComponentDirectories: [
'src/components/search',
'src/components/recommendations',
],
computedComponentImports: [],
},
];

const declarationToLitImport = (declaration) =>
`${declaration.name} as Lit${declaration.name}`;

const declarationToComponent = (declaration) =>
`
export const ${declaration.name} = createComponent({
tagName: '${declaration.tagName}',
react: React,
elementClass: Lit${declaration.name},
});
`;

for (const module of cem.modules) {
for (const declaration of module.declarations) {
if (isLitDeclaration(declaration)) {
for (const entry of entries) {
if (
entry.excludedComponentDirectories.some((directory) =>
module.path.startsWith(directory)
) ||
entry.excludedComponents.includes(declaration.tagName)
) {
continue;
}
entry.computedComponentImports.push(
declarationToLitImport(declaration)
);
entry.content+=(declarationToComponent(declaration));
}
}
}
}

for (const entry of entries) {
const prettierConfig = {
...(await prettier.resolveConfig(entry.path)),
parser: 'typescript'
};
if(entry.computedComponentImports.length===0) {
writeFileSync(entry.path, await prettier.format('export {}', prettierConfig));
continue;
}
writeFileSync(
entry.path,
await prettier.format(
[
`import {createComponent} from '@lit/react';`,
`import React from 'react';`,
`import {${entry.computedComponentImports.join(',')}} from '@coveo/atomic/components';`,
entry.content
].join('\n'),
prettierConfig
)
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {};
1 change: 1 addition & 0 deletions packages/atomic-react/src/components/commerce/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './components.js';
export * from '../stencil-generated/commerce/index.js';
export {CommerceBindings, i18n} from '@coveo/atomic';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export * from '../stencil-generated/search/index.js';
export * from '../search/components.js';

export {RecsBindings, i18n} from '@coveo/atomic';

// Important: Re-exporting under the same name (eg: "AtomicRecsInterface") shadows the original component
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {};
1 change: 1 addition & 0 deletions packages/atomic-react/src/components/search/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from '../stencil-generated/search/index.js';
export * from './components.js';
export {Bindings, i18n} from '@coveo/atomic';

// Important: Re-exporting under the same name (eg: "AtomicSearchInterface") shadows the original component
Expand Down
3 changes: 2 additions & 1 deletion packages/atomic/custom-elements-manifest.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import {cemPlugin} from './scripts/cem-plugin.mjs';

export default {
/** Globs to analyze */
globs: ['src/**/*.tsx'],
globs: ['src/**/*.tsx', 'src/**/*.ts'],
/** Globs to exclude */
exclude: ['**/*.stories.tsx', '**/*.stories.ts', '**/*.stories.js'],
stencil: true,
litelement: true,
plugins: [cemPlugin()],
};
Loading
Loading