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: shared build #19

Merged
merged 1 commit into from
Jan 6, 2025
Merged

feat: shared build #19

merged 1 commit into from
Jan 6, 2025

Conversation

ycjcl868
Copy link
Owner

@ycjcl868 ycjcl868 commented Jan 6, 2025

Summary by CodeRabbit

Release Notes

  • Build Configuration

    • Enhanced package build process with support for ESM and CJS module formats
    • Updated TypeScript configuration to use modern module resolution
    • Improved build scripts for more flexible package distribution
  • Development

    • Updated development script to use TypeScript compiler in watch mode
    • Simplified package exports and configuration management
  • Package Structure

    • Added new output directories for ESM and CJS builds
    • Refined package.json to better support module imports

Copy link

vercel bot commented Jan 6, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
dumi-app ❌ Failed (Inspect) Jan 6, 2025 9:28am
express-app ❌ Failed (Inspect) Jan 6, 2025 9:28am
next-app ❌ Failed (Inspect) Jan 6, 2025 9:28am
react-app ❌ Failed (Inspect) Jan 6, 2025 9:28am
remix-app ❌ Failed (Inspect) Jan 6, 2025 9:28am
umi-app ❌ Failed (Inspect) Jan 6, 2025 9:28am
vite-app ❌ Failed (Inspect) Jan 6, 2025 9:28am
vite-react-app ❌ Failed (Inspect) Jan 6, 2025 9:28am

Copy link

coderabbitai bot commented Jan 6, 2025

Walkthrough

The pull request introduces significant changes to the build configuration and module export strategy for the @infras/shared package. The modifications primarily focus on enhancing the build process by adding support for both ECMAScript (ESM) and CommonJS (CJS) module outputs. This involves creating new TypeScript configuration files, updating package scripts, and refining the package.json export definitions. The changes aim to improve module compatibility and build flexibility while maintaining the existing package structure.

Changes

File Change Summary
packages/native/index.js Code formatting: Consolidated multi-line variable assignments into single lines
packages/shared/package.json - Added build scripts for ESM and CJS
- Updated browser and exports fields
- Added files field
- Removed tsup dependency
packages/shared/tsconfig.cjs.json New configuration file for CommonJS module compilation
packages/shared/tsconfig.json - Updated output directory to ./dist/esm
- Updated ECMAScript target to es2018
- Changed module system to Node16
- Added declarationMap option
packages/shared/tsup.config.ts Removed bundler configuration file

Poem

🐰 Hop, hop, build with glee,
ESM and CJS, now set free!
Configs dancing, scripts so bright,
Modules aligned with pure delight 🚀
A rabbit's build, clean and neat! 📦


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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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.

Copy link

@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: 1

🧹 Nitpick comments (2)
packages/shared/package.json (2)

10-10: Optimize build scripts to prevent redundant builds.

The prepack script runs the same commands as the build script, which is already called by prepare. This could lead to redundant builds.

Consider this optimization:

-    "prepack": "npm run build:esm && npm run build:cjs",
-    "prepare": "npm run build",
+    "prepack": "npm run build",
+    "prepare": "npm run build"

Also applies to: 11-11


15-16: Consider conditional exports for browser field.

The browser field points to ESM modules, but some bundlers might prefer CJS. Consider using conditional exports instead.

Example approach:

-  "browser": {
-    "./types": "./dist/esm/types/index.js",
-    "./utils": "./dist/esm/utils/index.js"
-  },
+  "exports": {
+    "./types": {
+      "browser": "./dist/esm/types/index.js",
+      "import": "./dist/esm/types/index.js",
+      "require": "./dist/cjs/types/index.js"
+    },
+    "./utils": {
+      "browser": "./dist/esm/utils/index.js",
+      "import": "./dist/esm/utils/index.js",
+      "require": "./dist/cjs/utils/index.js"
+    }
+  }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2c8336c and 86107c2.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (5)
  • packages/native/index.js (4 hunks)
  • packages/shared/package.json (1 hunks)
  • packages/shared/tsconfig.cjs.json (1 hunks)
  • packages/shared/tsconfig.json (1 hunks)
  • packages/shared/tsup.config.ts (0 hunks)
💤 Files with no reviewable changes (1)
  • packages/shared/tsup.config.ts
✅ Files skipped from review due to trivial changes (2)
  • packages/shared/tsconfig.cjs.json
  • packages/native/index.js
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: eslint_test
🔇 Additional comments (5)
packages/shared/tsconfig.json (3)

12-12: LGTM! Good practice for source organization.

Narrowing the include paths to src/**/* is a good practice for better source organization and build clarity.


8-9: Consider future Node.js version compatibility.

Using "Node16" for both module and moduleResolution ties the package to Node.js 16+. This is a relatively recent version that might not be supported in all environments.

Let's check the Node.js version requirements in the project:


4-9: Verify browser compatibility with ES2018 target.

The target has been updated to ES2018. While this provides access to newer JavaScript features, ensure this aligns with your browser support requirements.

Run this command to check browser compatibility:

✅ Verification successful

ES2018 target is compatible with browser requirements

The ES2018 target in packages/shared/tsconfig.json is compatible with the browserslist configurations found in the apps. Both React and Vue apps target modern browsers that fully support ES2018 features.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check browser compatibility for ES2018 features
# Look for any browserslist config in the project
fd -t f -e json -e js -e yml -e yaml -e rc '(package|browserslist|babel)' | xargs cat | grep -i browserslist

Length of output: 150


Script:

#!/bin/bash
# Get complete browserslist configuration
echo "=== Package.json browserslist ==="
fd -t f "package.json" -x sh -c 'echo "File: {}"; cat {} | jq -r ".browserslist"'

echo -e "\n=== Standalone browserslist config ==="
fd -t f "^\.browserslistrc$"  -x sh -c 'echo "File: {}"; cat {}'

Length of output: 1533

packages/shared/package.json (2)

25-28: LGTM! Explicit files inclusion.

The files field explicitly includes the necessary directories for distribution.


19-23: Verify the wildcard exports configuration.

The new exports configuration uses wildcards for both ESM and CJS paths. While this provides flexibility, ensure all necessary files are properly built and exported.

Let's verify the export paths:

✅ Verification successful

The exports configuration is correctly structured

The wildcard exports configuration is properly aligned with:

  • The source files structure in src/ directory
  • The build scripts that generate both ESM and CJS outputs
  • The files field that ensures all necessary directories are included in the package
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if all source files have corresponding build outputs
echo "Checking source files..."
fd -t f . src/ -e ts -x echo "Source: {}" \
  -x sh -c 'echo "ESM: dist/esm/${0#src/}" && echo "CJS: dist/cjs/${0#src/}"' {} \;

Length of output: 279


Script:

#!/bin/bash
# Find source files
echo "=== Source Files ==="
fd -e ts -e js

echo -e "\n=== Directory Structure ==="
ls -la

echo -e "\n=== Package JSON Content ==="
cat packages/shared/package.json

echo -e "\n=== Build Output Structure ==="
ls -la packages/shared/dist 2>/dev/null || echo "dist directory not found"

Length of output: 4456

Comment on lines +8 to +9
"build:esm": "tsc -p tsconfig.json && echo '{\"type\": \"module\"}' > dist/esm/package.json",
"build:cjs": "tsc -p tsconfig.cjs.json && echo '{\"type\": \"commonjs\"}' > dist/cjs/package.json",
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Improve cross-platform compatibility of build scripts.

The echo commands for creating package.json files might not work correctly on Windows. Consider using a cross-platform solution.

Here's a more robust approach:

-    "build:esm": "tsc -p tsconfig.json && echo '{\"type\": \"module\"}' > dist/esm/package.json",
-    "build:cjs": "tsc -p tsconfig.cjs.json && echo '{\"type\": \"commonjs\"}' > dist/cjs/package.json",
+    "build:esm": "tsc -p tsconfig.json && node -e \"fs.writeFileSync('dist/esm/package.json', JSON.stringify({type:'module'}, null, 2))\"",
+    "build:cjs": "tsc -p tsconfig.cjs.json && node -e \"fs.writeFileSync('dist/cjs/package.json', JSON.stringify({type:'commonjs'}, null, 2))\""
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
"build:esm": "tsc -p tsconfig.json && echo '{\"type\": \"module\"}' > dist/esm/package.json",
"build:cjs": "tsc -p tsconfig.cjs.json && echo '{\"type\": \"commonjs\"}' > dist/cjs/package.json",
"build:esm": "tsc -p tsconfig.json && node -e \"fs.writeFileSync('dist/esm/package.json', JSON.stringify({type:'module'}, null, 2))\"",
"build:cjs": "tsc -p tsconfig.cjs.json && node -e \"fs.writeFileSync('dist/cjs/package.json', JSON.stringify({type:'commonjs'}, null, 2))\""

@ycjcl868 ycjcl868 merged commit 10857e4 into master Jan 6, 2025
3 of 11 checks passed
@ycjcl868 ycjcl868 deleted the feat/shared branch January 6, 2025 09:29
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