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

feat/buildin com mjs format #918

Merged

Conversation

chilingling
Copy link
Member

@chilingling chilingling commented Dec 3, 2024

English | 简体中文

PR

PR Checklist

Please check if your PR fulfills the following requirements:

  • The commit message follows our Commit Message Guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)
  • Built its own designer, fully self-validated

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

Background and solution

builtin 组件产物从 js 格式改为 mjs 格式。

原因:需要支持 import 导入,所以后缀需要改为 mjs

What is the current behavior?

Issue Number: N/A

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Summary by CodeRabbit

  • New Features

    • Transitioned to ECMAScript modules (ESM) for the library output, enhancing compatibility and modernizing the package structure.
  • Bug Fixes

    • Updated file references in configuration and package files to ensure proper module resolution.

Copy link
Contributor

coderabbitai bot commented Dec 3, 2024

Walkthrough

The pull request modifies the vite.config.js file within a Vite project. The primary change is the update of the build.lib.fileName property from returning 'index.js' to returning 'index.mjs', indicating a change in the output file format for the built library. Additionally, the package.json file is updated to reflect this change, with both the main and module fields now pointing to dist/index.mjs. Other configurations remain unchanged.

Changes

File Path Change Summary
packages/builtinComponent/vite.config.js Updated build.lib.fileName from function returning 'index.js' to 'index.mjs'.
packages/builtinComponent/package.json Updated main and module fields from dist/index.js to dist/index.mjs.

Possibly related PRs

Suggested reviewers

  • hexqi
  • yy-wow

Poem

In the land of code where rabbits play,
A change was made, hip-hip-hooray!
From .js to .mjs, a leap so bright,
Our builds now shine with new delight.
Hopping through configs, we cheer and sing,
For every change, new joy it brings! 🐰✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added the refactor-main refactor/develop branch feature label Dec 3, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (1)
packages/builtinComponent/vite.config.js (1)

26-28: Consider adding migration guide for breaking change

The combination of .mjs extension with formats: ['es'] enforces ES module-only distribution. While this is a forward-looking change, it's a potential breaking change for:

  1. CommonJS environments using require()
  2. Bundlers/tools that don't handle .mjs extensions automatically
  3. Existing imports that hardcode the .js extension

Consider:

  1. Adding a migration guide in the PR description
  2. Documenting the ES modules requirement in README
  3. Potentially providing both .mjs and .js outputs during a transition period
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 9e799e7 and cdfa5f5.

📒 Files selected for processing (1)
  • packages/builtinComponent/vite.config.js (1 hunks)
🔇 Additional comments (1)
packages/builtinComponent/vite.config.js (1)

26-26: Verify consumer compatibility with .mjs extension

The change from .js to .mjs extension explicitly indicates an ES module format, which aligns well with formats: ['es']. However, this change might affect existing consumers.

Consider the following impacts:

  • Node.js will enforce strict ES module syntax
  • Import statements must use the .mjs extension explicitly
  • CommonJS require() cannot be used to import this module

Let's verify if there are any direct imports that need updating:

✅ Verification successful

The .mjs extension change is safe to proceed

The change from .js to .mjs extension is well-aligned with the package configuration and won't cause compatibility issues because:

  • The package is already configured with "type": "module" in package.json
  • No direct imports of the specific file extension were found in the codebase
  • The devAliasPlugin references the package by directory (packages/builtinComponent/index.js), which will still work as Node.js resolves the correct file based on package.json
  • The package's main and module fields in package.json point to dist/index.js, which will be updated during build
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for imports of the builtin component
rg -g '!node_modules' -g '!dist' "from.*builtinComponent.*index\.js"

# Search for require statements
rg -g '!node_modules' -g '!dist' "require.*builtinComponent.*index\.js"

Length of output: 144


Script:

#!/bin/bash
# Let's try a broader search for imports of builtinComponent
rg -g '!node_modules' -g '!dist' "from.*builtinComponent"

# Search for any require statements with builtinComponent
rg -g '!node_modules' -g '!dist' "require.*builtinComponent"

# Check package.json files that might reference builtinComponent
fd "package.json" --exec grep -l "builtinComponent"

# Look for any file that might import or use builtinComponent
rg -g '!node_modules' -g '!dist' "builtinComponent" -l

Length of output: 512


Script:

#!/bin/bash
# Let's check the package.json files to understand how builtinComponent is referenced
cat packages/builtinComponent/package.json
cat packages/blockToWebComponentTemplate/package.json

# Check the devAliasPlugin to see how it uses builtinComponent
cat packages/build/vite-config/src/vite-plugins/devAliasPlugin.js

Length of output: 8883

@chilingling chilingling added the ready_for_review This PR requires more reviews label Dec 3, 2024
@chilingling chilingling closed this Dec 3, 2024
@chilingling chilingling reopened this Dec 3, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (1)
packages/builtinComponent/package.json (1)

5-6: Breaking change: Package now uses .mjs extension for ESM format

The change from .js to .mjs aligns with modern JavaScript practices for explicit module formats. However, this is a breaking change that requires careful consideration.

Consider the following recommendations:

  1. Update the package documentation to clearly communicate this breaking change
  2. Provide migration guidelines for consumers still using CommonJS require()
  3. Consider using dual package hazard patterns (providing both ESM and CommonJS builds) if backward compatibility is needed
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between cdfa5f5 and b922761.

📒 Files selected for processing (1)
  • packages/builtinComponent/package.json (1 hunks)
🔇 Additional comments (1)
packages/builtinComponent/package.json (1)

5-6: Verify build output and consumer compatibility

Let's verify the build configuration and potential impacts.

✅ Verification successful

Build configuration is properly set for ESM output

The package is correctly configured for ESM:

  • Vite config is properly set up with formats: ['es'] and outputs .mjs
  • Package.json correctly declares "type": "module"
  • No CommonJS require() statements found in dependent packages
  • Consumers are already using ESM imports
  • Vue is properly externalized in the build config
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check build configuration and potential compatibility issues

# Check if vite config exists and properly configured
echo "Checking Vite config for proper .mjs output..."
rg -l "build.*lib.*fileName.*mjs" "vite.config"

# Look for potential CommonJS require statements that might break
echo "Checking for potential CommonJS require statements in the codebase..."
rg "require\(['\"]@opentiny/tiny-engine-builtin-component['\"]"

# Check if package is imported in other workspace packages
echo "Checking package usage across the workspace..."
rg "from ['\"]@opentiny/tiny-engine-builtin-component['\"]"

Length of output: 1077


Script:

#!/bin/bash
# Let's check the build configuration in the package directory

# Check if there's a vite.config or rollup.config in the package
echo "Checking build config files in package directory..."
fd "vite.config|rollup.config" packages/builtinComponent/

# Check package.json for build scripts and dependencies
echo "Checking package.json build configuration..."
cat packages/builtinComponent/package.json

# Check if there are any type definitions that need to match
echo "Checking for type definitions..."
fd "index.d.ts|types.d.ts|index.d.mts" packages/builtinComponent/

Length of output: 1225


Script:

#!/bin/bash
# Let's check the vite config to ensure proper ESM output configuration
echo "Checking vite.config.js content..."
cat packages/builtinComponent/vite.config.js

# Let's also check the actual source entry point
echo "Checking source entry point..."
fd "index.js|index.ts|index.vue" packages/builtinComponent/src/

Length of output: 1355

@kevinmoch kevinmoch merged commit 7d0956f into opentiny:refactor/develop Dec 4, 2024
3 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Jan 26, 2025
14 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready_for_review This PR requires more reviews refactor-main refactor/develop branch feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants