Skip to content

fix: support run with worker eval #300

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

Merged
merged 5 commits into from
Apr 15, 2025
Merged

fix: support run with worker eval #300

merged 5 commits into from
Apr 15, 2025

Conversation

JounQin
Copy link
Member

@JounQin JounQin commented Apr 15, 2025

close #296


Important

Fixes worker evaluation mode compatibility in src/meta.ts and updates dependencies in package.json.

  • Bug Fix:
    • In src/meta.ts, updated cjsRequire logic to use EVAL_FILENAMES.has(__filename) for compatibility with worker evaluation mode.
  • Dependencies:
    • Updated @pkgr/core to ^0.2.4 and type-fest to ^4.40.0 in package.json.
  • Release:
    • Added changeset spotty-months-end.md for a patch release of eslint-plugin-import-x.

This description was created by Ellipsis for 501d643. It will automatically update as commits are pushed.


Summary by CodeRabbit

  • Bug Fixes
    • Improved compatibility with worker evaluation mode to ensure smoother operation in more environments.
  • Chores
    • Updated documentation to reflect the latest patch and changes.
    • Upgraded core dependencies for enhanced stability and performance.

@JounQin JounQin requested a review from Copilot April 15, 2025 11:50
Copy link

changeset-bot bot commented Apr 15, 2025

🦋 Changeset detected

Latest commit: c067e37

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
eslint-plugin-import-x Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

coderabbitai bot commented Apr 15, 2025

Walkthrough

A new changeset file was added to document a patch release for the eslint-plugin-import-x package, describing a fix for compatibility with worker evaluation mode. In the source code, the logic determining when to use createRequire(import.meta.url) instead of the native require function was updated. The check now uses a set of special evaluation filenames imported from @pkgr/core rather than a single hardcoded string, broadening support for different execution environments. Additionally, dependencies for @pkgr/core and type-fest were updated. No changes were made to exported or public entities.

Changes

File(s) Change Summary
.changeset/spotty-months-end.md Added a changeset documenting a patch update for worker evaluation mode support.
src/meta.ts Updated condition to check if __filename is in a set of evaluation filenames from @pkgr/core to decide on using createRequire.
package.json Upgraded dependencies: @pkgr/core from ^0.2.3 to ^0.2.4 and type-fest from ^4.39.1 to ^4.40.0.

Sequence Diagram(s)

sequenceDiagram
    participant Module as src/meta.ts
    participant NodeEnv as Node.js Environment

    NodeEnv->>Module: Execute module
    Module->>Module: Check if __filename is in EVAL_FILENAMES set
    alt __filename in EVAL_FILENAMES
        Module->>Module: Use createRequire(import.meta.url)
    else
        Module->>Module: Use native require
    end
Loading

Assessment against linked issues

Objective Addressed Explanation
Fix error "Cannot find module '../package.json'" in worker/webpack eval environments (#296)

Possibly related PRs

  • chore: bump all (dev) deps #282: Updates the condition for selecting require by checking a set of evaluation filenames from @pkgr/core and bumps @pkgr/core version, related through dependency and logic updates.

Poem

In the warren of code, a patch hops by,
To help worker evals and modules comply.
No more lost packages, no more dismay,
Now require knows just the right way!
With a twitch of my nose and a satisfied grin,
This bunny declares: let the builds begin! 🐇✨

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

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

src/meta.ts

Oops! Something went wrong! :(

ESLint: 9.24.0

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/lib/index.js' imported from /eslint.config.js
at finalizeResolution (node:internal/modules/esm/resolve:257:11)
at moduleResolve (node:internal/modules/esm/resolve:914:10)
at defaultResolve (node:internal/modules/esm/resolve:1038:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:557:12)
at ModuleLoader.resolve (node:internal/modules/esm/loader:525:25)
at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:246:38)
at ModuleJob._link (node:internal/modules/esm/module_job:126:49)
(node:30292) ExperimentalWarning: Importing JSON modules is an experimental feature and might change at any time
(Use node --trace-warnings ... to show where the warning was created)

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.
  • @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

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 1 out of 1 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (1)

src/meta.ts:5

  • [nitpick] The constant name 'EVAL' may be ambiguous given its expanded use with worker eval. Consider renaming it to something more descriptive, such as 'EVAL_FILENAMES' or 'VALID_EVAL_FILENAMES'.
const EVAL = new Set(['[eval]', '[worker eval]'])

Copy link

Walkthrough

This pull request addresses issue #296 by modifying the logic to support running with 'worker eval'. It introduces a new Set to handle evaluation contexts, ensuring compatibility with both standard and worker evaluations.

Changes

File Summary
src/meta.ts Added a Set to manage evaluation contexts, replacing direct string comparison with __filename. This change allows the code to support both '[eval]' and '[worker eval]' contexts.

Copy link

codesandbox-ci bot commented Apr 15, 2025

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Copy link

pkg-pr-new bot commented Apr 15, 2025

Open in StackBlitz

npm i https://pkg.pr.new/eslint-plugin-import-x@300

commit: c067e37

Copy link

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

👍 Looks good to me! Reviewed everything up to b62981b in 1 minute and 18 seconds

More details
  • Looked at 16 lines of code in 1 files
  • Skipped 0 files when reviewing.
  • Skipped posting 4 drafted comments based on config settings.
1. src/meta.ts:5
  • Draft comment:
    Good addition: Using a set to include both '[eval]' and '[worker eval]' improves environment detection.
  • Reason this comment was not posted:
    Confidence changes required: 0% <= threshold 50%
    None
2. src/meta.ts:8
  • Draft comment:
    Ensure that __filename reliably equals '[worker eval]' in worker eval contexts. This resolves issue #296 by covering both eval types.
  • Reason this comment was not posted:
    Confidence changes required: 0% <= threshold 50%
    None
3. src/meta.ts:5
  • Draft comment:
    Consider renaming the constant 'EVAL' to a more descriptive name (e.g., 'SPECIAL_FILENAMES') and adding a short inline comment explaining why these specific __filename values ('[eval]', '[worker eval]') trigger use of createRequire.
  • Reason this comment was not posted:
    Confidence changes required: 33% <= threshold 50%
    None
4. src/meta.ts:8
  • Draft comment:
    The condition using EVAL.has(__filename) now covers both '[eval]' and '[worker eval]'. Ensure that all worker evaluation contexts produce an __filename matching these values, and document this assumption if necessary.
  • Reason this comment was not posted:
    Confidence changes required: 33% <= threshold 50%
    None

Workflow ID: wflow_GzytOMsR2Jf9N9U9


You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

Copy link

codecov bot commented Apr 15, 2025

Codecov Report

Attention: Patch coverage is 50.00000% with 1 line in your changes missing coverage. Please review.

Project coverage is 95.99%. Comparing base (d29f255) to head (c067e37).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
src/meta.ts 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #300      +/-   ##
==========================================
- Coverage   96.01%   95.99%   -0.03%     
==========================================
  Files          91       91              
  Lines        4743     4744       +1     
  Branches     1784     1763      -21     
==========================================
  Hits         4554     4554              
- Misses        188      189       +1     
  Partials        1        1              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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: 0

🧹 Nitpick comments (1)
.changeset/spotty-months-end.md (1)

5-5: Fix typo in changeset description

There's a typo in the changeset description: "suppprt" should be "support".

-fix: suppprt run with worker eval
+fix: support run with worker eval
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between d29f255 and 6ee0263.

📒 Files selected for processing (2)
  • .changeset/spotty-months-end.md (1 hunks)
  • src/meta.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Lint and Test with Node.js 18 and ESLint 9 on windows-latest
🔇 Additional comments (1)
src/meta.ts (1)

5-9: Well-implemented solution for supporting worker eval environments

The introduction of a Set to manage evaluation contexts is a robust solution to handle multiple eval scenarios, including '[worker eval]'. This approach enhances the flexibility and correctness of the module loading logic, making it easier to add more eval contexts in the future if needed.

Copy link

socket-security bot commented Apr 15, 2025

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Updated@​pkgr/​core@​0.2.3 ⏵ 0.2.4100100100100100

View full report

Copy link

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

👍 Looks good to me! Incremental review on 501d643 in 45 seconds

More details
  • Looked at 43 lines of code in 2 files
  • Skipped 1 files when reviewing.
  • Skipped posting 7 drafted comments based on config settings.
1. package.json:74
  • Draft comment:
    Dependency update: Verify that '@pkgr/core' v0.2.4 correctly exports EVAL_FILENAMES needed for worker eval detection.
  • Reason this comment was not posted:
    Confidence changes required: 0% <= threshold 50%
    None
2. package.json:160
  • Draft comment:
    Dependency update: Confirm 'type-fest' v4.40.0 behaves as expected with no breaking changes.
  • Reason this comment was not posted:
    Confidence changes required: 0% <= threshold 50%
    None
3. src/meta.ts:3
  • Draft comment:
    Importing EVAL_FILENAMES from '@pkgr/core' centralizes eval detection; ensure this constant is maintained.
  • Reason this comment was not posted:
    Confidence changes required: 0% <= threshold 50%
    None
4. src/meta.ts:7
  • Draft comment:
    Using createRequire when in a worker/eval context (detected via EVAL_FILENAMES) resolves #296; logic looks correct.
  • Reason this comment was not posted:
    Confidence changes required: 0% <= threshold 50%
    None
5. package.json:74
  • Draft comment:
    Upgrade @pkgr/core to ^0.2.4 provides the necessary EVAL_FILENAMES export. Confirm new API is backward compatible.
  • Reason this comment was not posted:
    Confidence changes required: 0% <= threshold 50%
    None
6. package.json:160
  • Draft comment:
    Bump type-fest to ^4.40.0; ensure no regressions arise from this minor version update.
  • Reason this comment was not posted:
    Confidence changes required: 0% <= threshold 50%
    None
7. src/meta.ts:9
  • Draft comment:
    Using imported EVAL_FILENAMES for the eval check simplifies maintenance and resolves #296. Verify it covers all relevant eval cases.
  • Reason this comment was not posted:
    Confidence changes required: 0% <= threshold 50%
    None

Workflow ID: wflow_EsxUTE8yKlcwrrVe


You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com>
@JounQin JounQin changed the title fix: suppprt run with worker eval fix: support run with worker eval Apr 15, 2025
Copy link

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

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 6ee0263 and c067e37.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (3)
  • .changeset/spotty-months-end.md (1 hunks)
  • package.json (2 hunks)
  • src/meta.ts (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • package.json
🚧 Files skipped from review as they are similar to previous changes (1)
  • .changeset/spotty-months-end.md
🧰 Additional context used
🧠 Learnings (1)
src/meta.ts (1)
Learnt from: JounQin
PR: un-ts/eslint-plugin-import-x#0
File: :0-0
Timestamp: 2025-03-30T09:56:52.604Z
Learning: The project supports both ESM and CommonJS module systems simultaneously, even as it migrates to use ESM as the primary module system. Using `cjsRequire` is part of this strategy to maintain compatibility with both systems.
🪛 GitHub Check: codecov/patch
src/meta.ts

[warning] 9-9: src/meta.ts#L9
Added line #L9 was not covered by tests

⏰ Context from checks skipped due to timeout of 90000ms (21)
  • GitHub Check: Lint and Test with Node.js 22 and ESLint 8.56 on windows-latest
  • GitHub Check: Lint and Test with Node.js 22 and ESLint 8 on windows-latest
  • GitHub Check: Lint and Test with Node.js 22 and ESLint 9 on windows-latest
  • GitHub Check: Lint and Test with Node.js 18 and ESLint 9 on windows-latest
  • GitHub Check: Lint and Test with Node.js 22 and ESLint 9 on macos-latest
  • GitHub Check: Lint and Test with Node.js 18 and ESLint 9 on ubuntu-latest
  • GitHub Check: Lint and Test with Node.js 18 and ESLint 8.56 on windows-latest
  • GitHub Check: Lint and Test with Node.js 20 and ESLint 8 on ubuntu-latest
  • GitHub Check: Lint and Test with Node.js 20 and ESLint 9 on ubuntu-latest
  • GitHub Check: Lint and Test with Node.js 20 and ESLint 9 on macos-latest
  • GitHub Check: Lint and Test with Node.js 18 and ESLint 8 on macos-latest
  • GitHub Check: Lint and Test with Node.js 18 and ESLint 8.56 on windows-latest
  • GitHub Check: Lint and Test with Node.js 18 and ESLint 9 on windows-latest
  • GitHub Check: Lint and Test with Node.js 22 and ESLint 8 on windows-latest
  • GitHub Check: Lint and Test with Node.js 18 and ESLint 8 on windows-latest
  • GitHub Check: Lint and Test with Node.js 22 and ESLint 9 on windows-latest
  • GitHub Check: Lint and Test with Node.js 20 and ESLint 8 on windows-latest
  • GitHub Check: Lint and Test with Node.js 20 and ESLint 8.56 on windows-latest
  • GitHub Check: Lint and Test with Node.js 20 and ESLint 9 on windows-latest
  • GitHub Check: Lint and Test with Node.js 22 and ESLint 8.56 on windows-latest
  • GitHub Check: Codacy Static Code Analysis

@JounQin JounQin merged commit db1824b into master Apr 15, 2025
67 of 69 checks passed
@JounQin JounQin deleted the fix/worker_eval branch April 15, 2025 12:56
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.

Error: Cannot find module '../package.json'
1 participant
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy