Skip to content

feat(esm): Add better ESM support to prerendering#368

Merged
Tobbe merged 1 commit into
mainfrom
tobbe-esm-prerender-support
Aug 10, 2025
Merged

feat(esm): Add better ESM support to prerendering#368
Tobbe merged 1 commit into
mainfrom
tobbe-esm-prerender-support

Conversation

@Tobbe
Copy link
Copy Markdown
Member

@Tobbe Tobbe commented Aug 10, 2025

Use correct gql import depending on ESM vs CJS projects

16/n in #349 series

@Tobbe Tobbe added this to the next-release milestone Aug 10, 2025
@netlify
Copy link
Copy Markdown

netlify Bot commented Aug 10, 2025

Deploy Preview for cedarjs canceled.

Name Link
🔨 Latest commit 6538dde
🔍 Latest deploy log https://app.netlify.com/projects/cedarjs/deploys/68987693300f570008dde43c

Copy link
Copy Markdown
Contributor

@greptile-apps greptile-apps Bot left a comment

Choose a reason for hiding this comment

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

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

Edit Code Review Bot Settings | Greptile

@Tobbe Tobbe merged commit 0d1a96f into main Aug 10, 2025
52 checks passed
@Tobbe Tobbe deleted the tobbe-esm-prerender-support branch August 10, 2025 11:11
@Tobbe Tobbe modified the milestones: next-release, v0.10.0 Aug 26, 2025
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