-
Notifications
You must be signed in to change notification settings - Fork 1
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
fix: addresses issue and test for the issue succeeds #51
fix: addresses issue and test for the issue succeeds #51
Conversation
Warning There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure. 🔧 eslint
tests/esm-js/index.jsOops! Something went wrong! :( ESLint: 9.17.0 ESLint couldn't find an eslint.config.(js|mjs|cjs) file. From ESLint v9.0.0, the default configuration file is now eslint.config.js. https://eslint.org/docs/latest/use/configure/migration-guide If you still have problems after following the migration guide, please stop by WalkthroughThis pull request focuses on enhancing the ESM (ECMAScript Module) compatibility for the Changes
Sequence DiagramsequenceDiagram
participant User
participant TestScript as test.sh
participant ESMIndex as index.js
participant Package as @smarttools/eslint-plugin-rxjs
User->>TestScript: Execute test script
TestScript->>Package: Copy package to node_modules
TestScript->>ESMIndex: Run index.js
ESMIndex->>Package: Import eslintPluginRxjs
ESMIndex-->>TestScript: Log imported module
TestScript-->>User: Report test result
Possibly related issues
Possibly related PRs
Poem
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
View your CI Pipeline Execution ↗ for commit 64b1e44.
☁️ Nx Cloud last updated this comment at |
There was a problem hiding this 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 (3)
tests/esm-js/test.sh (3)
1-9
: Add error handling for script permissionsThe script should verify it has execution permissions. Also, consider adding cleanup on script exit.
#!/bin/bash # Exit on any error set -e + +# Verify script has execution permissions +if [[ ! -x "$0" ]]; then + echo "Error: Script must have execution permissions" + echo "Run: chmod +x $0" + exit 1 +fi + +# Cleanup function +cleanup() { + # Remove temporary files/directories if any + if [ -d "$DEST_DIR" ]; then + rm -rf "$DEST_DIR" + fi +} + +# Register cleanup function +trap cleanup EXIT
10-12
: Consider using environment variables for pathsThe hardcoded paths could be made configurable through environment variables with defaults.
-# Define source and destination paths relative to root -SRC_DIR="$ROOT_DIR/dist/packages/eslint-plugin-rxjs" -DEST_DIR="$ROOT_DIR/node_modules/@smarttools/eslint-plugin-rxjs" +# Allow path configuration through environment variables +SRC_DIR="${PLUGIN_SRC_DIR:-$ROOT_DIR/dist/packages/eslint-plugin-rxjs}" +DEST_DIR="${PLUGIN_DEST_DIR:-$ROOT_DIR/node_modules/@smarttools/eslint-plugin-rxjs}"
36-44
: Add more detailed test outputThe test output could be more informative about what's being tested.
-# Run the index.js file -echo "Running index.js..." +# Run ESM compatibility tests +echo "Running ESM compatibility tests..." +echo "Test file: $SCRIPT_DIR/index.js" if node "$SCRIPT_DIR/index.js"; then - echo "✓ Tests completed successfully" + echo "✓ ESM compatibility tests passed" exit 0 else - echo "✗ Tests failed" + echo "✗ ESM compatibility tests failed" + echo "Check the error output above for details" exit 1 fi
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
packages/eslint-plugin-rxjs/package.json
(1 hunks)test/package.json
(1 hunks)tests/esm-js/index.js
(1 hunks)tests/esm-js/package.json
(1 hunks)tests/esm-js/test.sh
(1 hunks)
✅ Files skipped from review due to trivial changes (3)
- tests/esm-js/index.js
- tests/esm-js/package.json
- test/package.json
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: main
"types": "./index.d.ts", | ||
"import": "./index.cjs" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codebase verification
Critical: Entry point file index.cjs
is missing
The package configuration points to index.cjs
for both CommonJS and ESM imports, but this file doesn't exist in the package. This will cause the package to fail in both CommonJS and ESM environments.
- Ensure the build process correctly generates
index.cjs
in the package root - Verify the build output structure matches the package.json configuration
🔗 Analysis chain
Verify ESM compatibility with .cjs extension
While adding the "import" condition is a step towards ESM support, pointing it to a .cjs file might cause issues in strict ESM environments. Consider:
- Creating a dedicated ESM entry point (index.mjs)
- Using dynamic imports for ESM compatibility
Let's verify ESM compatibility:
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Check if the package works in ESM context
cd tests/esm-js
# Attempt ESM import
echo 'import pkg from "@smarttools/eslint-plugin-rxjs"; console.log(pkg);' > test.mjs
node --experimental-vm-modules test.mjs 2>&1 || true
Length of output: 941
Script:
#!/bin/bash
# Check package configuration and structure
echo "=== Package.json content ==="
cat packages/eslint-plugin-rxjs/package.json
echo -e "\n=== Index.cjs content ==="
cat packages/eslint-plugin-rxjs/index.cjs 2>/dev/null || echo "File not found"
echo -e "\n=== Check for MJS files ==="
fd -e mjs . packages/eslint-plugin-rxjs/
echo -e "\n=== Check for JS files ==="
fd -e js . packages/eslint-plugin-rxjs/ --exclude '*.cjs' --exclude '*.mjs'
Length of output: 1356
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that file is created as part of the build process and is not expected here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@DaveMBush Understood, thank you for the clarification. I'll note this for future reviews.
✏️ Learnings added
Learnt from: DaveMBush
PR: DaveMBush/eslint-plugin-rxjs#51
File: packages/eslint-plugin-rxjs/package.json:34-35
Timestamp: 2025-01-10T15:20:25.714Z
Learning: In the @smarttools/eslint-plugin-rxjs package, index.cjs is generated during the build process and is not expected to exist in the source code.
Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.
If you found this review helpful, would you consider giving us a shout-out on X?
Thank you for using CodeRabbit!
Issue Number: #38
Body
Allows esm to load module correctly
Summary by CodeRabbit
New Features
@smarttools/eslint-plugin-rxjs
Chores
Tests