feat(esm): Add better ESM support to prerendering#368
Conversation
✅ Deploy Preview for cedarjs canceled.
|
There was a problem hiding this comment.
Greptile Summary
This PR enhances the prerendering functionality in CedarJS by adding proper ESM (ECMAScript Modules) support when importing GraphQL tag functions. The change addresses a fundamental compatibility issue between different module systems during the prerendering build process.
The core modification involves importing the projectIsEsm function from @cedarjs/project-config to detect whether the current project uses ESM or CommonJS. Based on this detection, the code conditionally configures the unimport plugin to use the correct import syntax for the gql function from the graphql-tag library:
- For ESM projects: Uses named import syntax (
import { gql } from 'graphql-tag') - For CommonJS projects: Uses default import syntax (
import gql from 'graphql-tag')
This change integrates seamlessly with CedarJS's existing build system architecture. The prerendering process uses Rollup to bundle code, and the unimport plugin needs to know the correct way to import dependencies based on the project's module system. The projectIsEsm() function provides this crucial information, allowing the build process to generate the appropriate import statements during bundling. This ensures that GraphQL queries can be processed correctly regardless of whether the project is configured for ESM or CommonJS.
Confidence score: 4/5
- This PR is safe to merge with minimal risk as it addresses a specific compatibility issue without affecting core functionality
- Score reflects a targeted fix for module system compatibility with proper conditional logic and existing utility usage
- Pay close attention to the buildAndImport.ts file to ensure the conditional import logic works correctly across different project configurations
1 file reviewed, no comments
Use correct
gqlimport depending on ESM vs CJS projects16/n in #349 series