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(headless, atomic-react)!: add exports field in package.json #4376

Closed
wants to merge 24 commits into from

Conversation

alexprudhomme
Copy link
Contributor

@alexprudhomme alexprudhomme commented Sep 4, 2024

https://coveord.atlassian.net/browse/KIT-2541

  • Switch back to rollup for all builds, too many issues with 'require' and esbuild. Clean up rollup config file & keep old file names to have no breaking changes for iife in v3. Do this with esbuild at the same time and incrementally compare.

This PR adds the "exports" field for @coveo/headless and @coveo/atomic-react. More details here - > https://github.com/coveo/ui-kit/pull/4376/files#r1746030192

this PR also updates stencil, angular-output-target and react-output-target

Copy link

github-actions bot commented Sep 4, 2024

Pull Request Report

PR Title

✅ Title follows the conventional commit spec.

Live demo links

Bundle Size

File Old (kb) New (kb) Change (%)
case-assist 242.3 242.3 0
commerce 342.3 342.3 0
search 413.3 413.3 0
insight 396.3 396.3 0
product-listing 306.6 306.6 0
product-recommendation 213.2 213.2 0
recommendation 256.1 256.1 0
ssr 405.9 405.9 0
ssr-commerce 354.5 354.5 0

SSR Progress

Use case SSR (#) CSR (#) Progress (%)
search 39 44 89
recommendation 0 4 0
product-recommendation 0 10 0
product-listing 0 13 0
case-assist 0 6 0
insight 0 27 0
commerce 0 15 0
Detailed logs search : buildInteractiveResult
search : buildInteractiveInstantResult
search : buildInteractiveRecentResult
search : buildInteractiveCitation
search : buildGeneratedAnswer
recommendation : missing SSR support
product-recommendation : missing SSR support
product-listing : missing SSR support
case-assist : missing SSR support
insight : missing SSR support
commerce : missing SSR support

@alexprudhomme alexprudhomme added this to the V3 milestone Sep 5, 2024
@alexprudhomme alexprudhomme marked this pull request as ready for review September 5, 2024 18:59
@alexprudhomme alexprudhomme requested review from a team as code owners September 5, 2024 18:59
Comment on lines +9 to +12
- module: import_typescript.default.ModuleKind.ESNext,
- moduleResolution: import_typescript.default.ModuleResolutionKind.NodeJs,
+ module: import_typescript.default.ModuleKind.ES2022,
+ moduleResolution: import_typescript.default.ModuleResolutionKind.Bundler,
Copy link
Contributor Author

@alexprudhomme alexprudhomme Sep 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new "exports" field in package.json defining the different entry points needs moduleResolution in tsconfig.ts to be either Bundler/Node16/NodeNext . From now on, every user of Headless will have to use one of these three for their typescript compiler to understand where to look for subpackages. More info on the "exports" field .

There is a problem with Stencil however. Inside of their compiler, they use an old version of moduleResolution that cant find the subpackages with the "exports" field. This is a known bug and will be fixed in v5.

This patch above fixes this by changing the default value used by the stencil compiler.

@alexprudhomme alexprudhomme marked this pull request as draft September 5, 2024 19:36
Comment on lines +80 to +92
async function main() {
const buildPromises = Object.entries(USE_CASES).flatMap(
([useCaseName, entryPoint]) => [
browserEsm(entryPoint, useCaseName),
esm(entryPoint, useCaseName),
cjs(entryPoint, useCaseName),
iife(entryPoint, useCaseName),
]
);
await Promise.all(buildPromises);
}

main();
Copy link
Contributor Author

@alexprudhomme alexprudhomme Sep 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ended up having problems with the build process of Atomic-React. It was using simply tsc compilation to compile for these 2 use case (esm, cjs) and rollup for iife. Since it was just using tsc compilation and since we now have to put either Bundler/node16/nodeNext as moduleResolution. We couldnt use tsc to compile into cjs and iife. I had to change the build process to esbuild. All the changes in the /atomic-react folder are related to this.

I also added a browserEsm output for <script type="module"> cases. All the new output looks like this.

image

Comment on lines -7 to -10
import {
QuerySetSection,
QuerySuggestionSection,
} from '@coveo/headless/dist/definitions/state/state-sections';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shows how you cant import from anything other than the "exports" defined paths in the package json. Only from @coveo/headless , @coveo/headless/commerce, and so on...

@alexprudhomme alexprudhomme changed the title chore(headless)!: add exports field in package.json chore(headless, atomic-react)!: add exports field in package.json Sep 6, 2024
Comment on lines 9 to 10
- `);for(const p of n){const u=p.tagName,l=T(u),$=`${l}Element`,b=`${l}CustomEvent`;e.addImportDeclaration({moduleSpecifier:`${s}/${i}/${u}.js`,namedImports:[{name:l,alias:$},{name:"defineCustomElement",alias:`define${l}`}]});const F=(p.events||[]).filter(o=>o.internal===!1),y=[];for(const o of F)if(Object.keys(o.complexType.references).length>0){for(const _ of Object.keys(o.complexType.references))o.complexType.references[_].location==="global"||e.addImportDeclaration({moduleSpecifier:s,namedImports:[{name:_,isTypeOnly:!0}]});e.addImportDeclaration({moduleSpecifier:s,namedImports:[{name:b,isTypeOnly:!0}]}),y.push({originalName:o.name,name:j(o.name),type:`EventName<${b}<${o.complexType.original}>>`})}else y.push({originalName:o.name,name:j(o.name),type:`EventName<CustomEvent<${o.complexType.original}>>`});const E=`${l}Events`;e.addTypeAlias({name:E,type:y.length>0?`{ ${y.map(o=>`${o.name}: ${o.type}`).join(`,
+ `);for(const p of n){const u=p.tagName,l=T(u),$=`${l}Element`,b=`${l}CustomEvent`;e.addImportDeclaration({moduleSpecifier:`${s}/${i}/${u}.js`,namedImports:[{name:l,alias:$},{name:"defineCustomElement",alias:`define${l}`}]});const F=(p.events||[]).filter(o=>o.internal===!1),y=[];for(const o of F)if(Object.keys(o.complexType.references).length>0){for(const _ of Object.keys(o.complexType.references))o.complexType.references[_].location==="global"||e.addImportDeclaration({moduleSpecifier:s,namedImports:[{name:_,isTypeOnly:!0}]});e.addImportDeclaration({moduleSpecifier:s,namedImports:[{name:b,isTypeOnly:!0}]}),y.push({originalName:o.name,name:j(o.name),type:`EventName<${b}<${o.complexType.original}>>`})}else y.push({originalName:o.name,name:j(o.name),type:`EventName<CustomEvent<${o.complexType.original}>>`});const E=`${l}Events`;e.addTypeAlias({name:E,type:y.length>0?`{ ${y.map(o=>`'${o.name}': ${o.type}`).join(`,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leaving traces about this patch. This patch is to enable event names with '/' in them like "atomic/redirect". This change is only 4 lines. 2 lines in both .cjs and .js file.

Precisely this :
image

And this :

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant