Skip to content

fix(types): incorrect and unfinished NodeResolverOptions typing #15

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 1 commit into from
May 27, 2025

Conversation

JounQin
Copy link
Member

@JounQin JounQin commented May 27, 2025

Important

Fixes and completes NodeResolverOptions typing in types.ts, and updates eslint-import-context resolution in package.json.

  • Types:
    • Corrects and completes NodeResolverOptions typing in types.ts, adding properties like basedir, includeCoreModules, extensions, paths, moduleDirectory, and preserveSymlinks.
    • Marks package, packageFilter, pathFilter, and packageIterator as deprecated in NodeResolverOptions.
  • Package:
    • Adds eslint-import-context resolution in package.json.

This description was created by Ellipsis for dd3ac5c. You can customize this summary. It will automatically update as commits are pushed.

Summary by CodeRabbit

  • Bug Fixes

    • Improved the accuracy and completeness of type definitions for configuration options, ensuring more reliable and predictable behavior.
  • Chores

    • Updated package resolution to use a local version of a dependency, enhancing development workflow consistency.

@JounQin JounQin self-assigned this May 27, 2025
@Copilot Copilot AI review requested due to automatic review settings May 27, 2025 01:15
@JounQin JounQin added bug Something isn't working types labels May 27, 2025
Copy link

changeset-bot bot commented May 27, 2025

🦋 Changeset detected

Latest commit: dd3ac5c

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

This PR includes changesets to release 1 package
Name Type
eslint-import-context 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 May 27, 2025

Walkthrough

This update expands and corrects the NodeResolverOptions type definition, adding detailed properties and deprecated fields for backward compatibility. The LegacyResolverRecord interface is also modified to allow its webpack property to accept a boolean. The package.json is updated to resolve eslint-import-context locally.

Changes

File(s) Change Summary
src/types.ts Expanded and corrected NodeResolverOptions type; updated LegacyResolverRecord to allow boolean for webpack.
.changeset/swift-carrots-heal.md Added a changeset describing the typing corrections and completions.
package.json Added a local resolution for eslint-import-context in the resolutions field.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Module
    participant Resolver

    User->>Module: Import/require with options
    Module->>Resolver: Passes NodeResolverOptions (with new structure)
    Resolver-->>Module: Resolves module using updated options
    Module-->>User: Returns resolved module
Loading

Possibly related PRs

  • fix: LegacyResolver typing #6: Involves typing improvements for legacy resolver types, similar to the expanded and restructured type definitions in this PR.

Suggested labels

dependencies

Poem

In fields of code where carrots grow,
A rabbit tweaks the types below.
Options clearer, types refined,
Legacy paths now well-defined.
With local links and backward grace,
The modules hop in tidy space.
🥕

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/types.ts

Oops! Something went wrong! :(

ESLint: 9.27.0

Error [ERR_MODULE_NOT_FOUND]: Cannot find package '@1stg/eslint-config' imported from /eslint.config.mjs
at Object.getPackageJSONURL (node:internal/modules/package_json_reader:255:9)
at packageResolve (node:internal/modules/esm/resolve:767:81)
at moduleResolve (node:internal/modules/esm/resolve:853:18)
at defaultResolve (node:internal/modules/esm/resolve:983:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:799:12)
at #cachedDefaultResolve (node:internal/modules/esm/loader:723:25)
at ModuleLoader.resolve (node:internal/modules/esm/loader:706:38)
at ModuleLoader.getModuleJobForImport (node:internal/modules/esm/loader:307:38)
at #link (node:internal/modules/esm/module_job:170:49)


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between ec4b277 and dd3ac5c.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (3)
  • .changeset/swift-carrots-heal.md (1 hunks)
  • package.json (1 hunks)
  • src/types.ts (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (11)
  • GitHub Check: Lint and Test with Node.js 24 on ubuntu-latest
  • GitHub Check: Lint and Test with Node.js 24 on macos-latest
  • GitHub Check: Lint and Test with Node.js 24 on windows-latest
  • GitHub Check: Lint and Test with Node.js 22 on macos-latest
  • GitHub Check: Lint and Test with Node.js 18 on ubuntu-latest
  • GitHub Check: Lint and Test with Node.js 22 on ubuntu-latest
  • GitHub Check: Lint and Test with Node.js 20 on ubuntu-latest
  • GitHub Check: Lint and Test with Node.js 18 on macos-latest
  • GitHub Check: Lint and Test with Node.js 20 on macos-latest
  • GitHub Check: Lint and Test with Node.js 18 on windows-latest
  • GitHub Check: Lint and Test with Node.js 22 on windows-latest
🔇 Additional comments (7)
package.json (1)

103-103: LGTM! Standard development practice for local package resolution.

The local link resolution ensures that the development version of "eslint-import-context" is used consistently during testing, which is essential when making type definition changes like those in this PR.

src/types.ts (5)

40-42: Well-documented interface extension design.

The interface now properly extends NapiResolveOptions while omitting extensions to provide a more specific definition. The reference to DefinitelyTyped ensures consistency with established typing patterns.


43-68: Comprehensive property definitions with excellent documentation.

The new properties provide a complete and well-documented interface for node resolution options. The JSDoc comments clearly explain the purpose and defaults for each property, which greatly improves developer experience.

Key improvements:

  • Clear parameter types (string | readonly string[] for arrays)
  • Detailed documentation with defaults
  • Important notes about future changes (preserveSymlinks default)

70-78: Proper backward compatibility handling.

The deprecated properties are correctly marked with @deprecated JSDoc tags and typed as unknown to maintain backward compatibility while discouraging new usage. This is the right approach for a non-breaking migration.


164-164: LGTM! Consistent boolean option support.

The change to allow WebpackResolverOptions | boolean for the webpack property maintains consistency with other resolver options that accept boolean shortcuts.


47-48:

❓ Verification inconclusive

Verify the mixed string/array typing for extensions property.

The extensions property accepts both string | readonly string[], which could lead to confusion in usage. Please verify this is intentional and consistent with the underlying resolver's expectations.


🏁 Script executed:

#!/bin/bash
# Description: Check how extensions property is used in the codebase and verify the type expectations

# Search for extensions property usage patterns
echo "=== Searching for extensions property usage ==="
rg -A 3 -B 1 "extensions.*:" --type ts

echo -e "\n=== Searching for NapiResolveOptions extensions definition ==="
rg -A 2 -B 1 "extensions.*:" node_modules/unrs-resolver/index.d.ts || echo "Package types not found in node_modules"

echo -e "\n=== Checking resolve function calls with extensions ==="
rg -A 2 -B 1 "resolve.*extensions" --type ts

Length of output: 1393


Confirm and standardize the extensions option in src/types.ts

The extensions property is currently declared three different ways in src/types.ts:

  • extensions?: string | readonly string[] (around line 47–48)
  • extensions?: string[]
  • extensions?: readonly FileExtension[]

We weren’t able to locate corresponding type definitions in node_modules/unrs-resolver, so it’s unclear which form the resolver actually expects. Please verify the intended shape against the resolver’s implementation or documentation, then unify all extensions declarations to a single, consistent type.

.changeset/swift-carrots-heal.md (1)

1-6: Well-documented changeset.

The changeset properly categorizes this as a patch-level fix and clearly describes the improvement to NodeResolverOptions typing. The semver level is appropriate since backward compatibility is maintained.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate sequence diagram to generate a sequence diagram of the changes in 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.

Pull Request Overview

This PR corrects and completes the NodeResolverOptions type definition and adjusts a legacy resolver signature, plus pins a local link for ESLint context.

  • Extends NodeResolverOptions from NapiResolveOptions, reintroducing and deprecating fields with accurate JSDoc
  • Changes LegacyResolverResolveImport return type from string | undefined to string
  • Adds a Yarn resolution linking eslint-import-context to the local package

Reviewed Changes

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

File Description
src/types.ts Expanded NodeResolverOptions typing and updated resolver return
package.json Added Yarn resolution for eslint-import-context
Comments suppressed due to low confidence (2)

src/types.ts:102

  • The return type for LegacyResolverResolveImport was changed from string | undefined to string, which could break callers expecting undefined. Consider restoring | undefined or updating upstream code to handle only string results.
) => string

package.json:103

  • [nitpick] Using a link:. resolution for eslint-import-context is non-standard and may confuse collaborators. Consider documenting this override in README or using a fixed version instead.
"eslint-import-context": "link:."

Copy link

codesandbox-ci bot commented May 27, 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 May 27, 2025

Open in StackBlitz

npm i https://pkg.pr.new/eslint-import-context@15

commit: dd3ac5c

Copy link
Contributor

github-actions bot commented May 27, 2025

Deploy preview for eslint-import-context ready!

✅ Preview
https://eslint-import-context-9jwppob0e-1stg.vercel.app

Built with commit dd3ac5c.
This pull request is being automatically deployed with vercel-action

Copy link
Contributor

github-actions bot commented May 27, 2025

📊 Package size report   2%↑

File Before After
lib/types.d.ts 4.3 kB 7%↑4.6 kB
package.json 3.4 kB 1%↑3.5 kB
Total (Includes all files) 20.2 kB 2%↑20.6 kB
Tarball size 6.6 kB 1%↑6.6 kB
Unchanged files
File Size
lib/index.d.ts 351 B
lib/index.js 1.2 kB
lib/index.js.map 452 B
lib/types.js 110 B
lib/types.js.map 102 B
lib/utils.d.ts 741 B
lib/utils.js 2.0 kB
lib/utils.js.map 1.4 kB
LICENSE 1.1 kB
README.md 5.0 kB

🤖 This report was automatically generated by pkg-size-action

Copy link

codecov bot commented May 27, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (ec4b277) to head (dd3ac5c).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main       #15   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            3         3           
  Lines           53        53           
  Branches        16        16           
=========================================
  Hits            53        53           

☔ 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

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

Important

Looks good to me! 👍

Reviewed everything up to 1bed527 in 1 minute and 39 seconds. Click for details.
  • Reviewed 74 lines of code in 2 files
  • Skipped 1 files when reviewing.
  • Skipped posting 3 draft comments. View those below.
  • Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.
1. package.json:102
  • Draft comment:
    Verify that local linking via 'link:.' in resolutions is intentional and won't conflict with dependency resolution.
  • Reason this comment was not posted:
    Comment did not seem useful. Confidence is useful = 0% <= threshold 50% The comment is asking the author to verify their intention regarding a specific change in dependency resolution. This violates the rule against asking the author to confirm their intention or ensure behavior is intended. The comment does not provide a specific suggestion or point out a clear issue.
2. src/types.ts:40
  • Draft comment:
    Review union types (string | readonly string[]) in NodeResolverOptions; ensure this flexibility and the extension via Omit<NapiResolveOptions, 'extensions'> are intended.
  • Reason this comment was not posted:
    Decided after close inspection that this draft comment was likely wrong and/or not actionable: usefulness confidence = 10% vs. threshold = 50% The comment appears to be asking the author to verify their intentions rather than pointing out a specific issue. The union types are well-documented with clear purposes (e.g. "Array of file extensions" for extensions, "Directory (or directories)" for moduleDirectory). The Omit usage seems intentional to override the extensions type from the base interface. The types could potentially cause runtime issues if not handled properly in the implementation. The comment might be trying to prevent potential bugs. The types are clearly documented and appear intentional. If there were implementation issues, they would be caught during testing or type checking. Delete the comment as it merely asks for confirmation of intentional changes rather than pointing out a specific issue that needs fixing.
3. src/types.ts:65
  • Draft comment:
    LegacyResolverResolveImport return type changed from 'string | undefined' to 'string'; ensure that legacy implementations correctly handle cases where undefined was expected.
  • Reason this comment was not posted:
    Decided after close inspection that this draft comment was likely wrong and/or not actionable: usefulness confidence = 20% vs. threshold = 50% This is a breaking change in the type definition that removes the possibility of returning undefined. This could cause runtime errors if existing implementations rely on undefined returns. However, the comment is asking for verification rather than pointing out a specific issue. It starts with "ensure that..." which violates our rules. We should not ask authors to verify things. The type change could be intentional and well-tested. Without seeing the implementations, we can't be certain this is actually a problem. While the type change is significant, asking for verification doesn't add value. If there were actual problems, they would show up in tests or TypeScript errors. Delete the comment because it asks for verification rather than pointing out a specific issue. If there are problems, they will be caught by TypeScript compilation.

Workflow ID: wflow_AWVO4epGYivMT9K9

You can customize Ellipsis by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.

Copy link
Contributor

github-actions bot commented May 27, 2025

size-limit report 📦

Path Size
src/index.ts 184 B (0%)

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.

Important

Looks good to me! 👍

Reviewed dd3ac5c in 1 minute and 43 seconds. Click for details.
  • Reviewed 86 lines of code in 3 files
  • Skipped 1 files when reviewing.
  • Skipped posting 5 draft comments. View those below.
  • Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.
1. .changeset/swift-carrots-heal.md:1
  • Draft comment:
    Changeset file looks valid. Ensure YAML quotes are intentional.
  • Reason this comment was not posted:
    Confidence changes required: 20% <= threshold 50% None
2. package.json:102
  • Draft comment:
    Local linking for 'eslint-import-context' is set in resolutions. Confirm this aligns with dependency usage.
  • Reason this comment was not posted:
    Confidence changes required: 20% <= threshold 50% None
3. src/types.ts:41
  • Draft comment:
    Expanded NodeResolverOptions improves flexibility. Update the 'extensions' comment to mention that a single string is allowed as shorthand for an array.
  • Reason this comment was not posted:
    Confidence changes required: 33% <= threshold 50% None
4. src/types.ts:163
  • Draft comment:
    Allowing webpack options as boolean is a sensible addition. Ensure downstream consumers correctly handle a boolean value.
  • Reason this comment was not posted:
    Confidence changes required: 33% <= threshold 50% None
5. src/types.ts:56
  • Draft comment:
    In the comment for the moduleDirectory option, the phrase "(default to 'node_modules')" appears. Consider changing it to "(defaults to 'node_modules')" for improved grammatical consistency.
  • Reason this comment was not posted:
    Decided after close inspection that this draft comment was likely wrong and/or not actionable: usefulness confidence = 10% vs. threshold = 50% This is a very minor grammatical suggestion. The code is actually copied from DefinitelyTyped types as noted in the comment above. Making small grammatical changes to copied documentation could cause confusion or divergence from the source. The current wording is perfectly understandable even if not optimal. The grammatical issue does make the documentation slightly less professional. Consistency in documentation is important for maintainability. While documentation consistency is valuable, this is an extremely minor issue that doesn't impact code functionality or understanding. The comment is about copied documentation where maintaining alignment with the source is more important. Delete this comment as it suggests an extremely minor grammatical change to documentation that was intentionally copied from another source.

Workflow ID: wflow_ybHiFIXHsyl6TqNg

You can customize Ellipsis by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.

@JounQin JounQin merged commit 71ca774 into main May 27, 2025
40 checks passed
@JounQin JounQin deleted the fix/types branch May 27, 2025 01:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working types
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant