Skip to content

fix: give up patching yarn pnp automatically which is impossible#25

Merged
JounQin merged 4 commits intoun-ts:mainfrom
mrginglymus:break-tests
Apr 27, 2025
Merged

fix: give up patching yarn pnp automatically which is impossible#25
JounQin merged 4 commits intoun-ts:mainfrom
mrginglymus:break-tests

Conversation

@mrginglymus
Copy link
Contributor

@mrginglymus mrginglymus commented Apr 26, 2025

Yarn PnP doesn't work with this, but tests claim it does. There are three reasons

  1. nodeLinker was not specified explicitly, so pnp may not have been used
  2. The link protocol doesn't capture the dependency behaviour correctly
  3. The tests are not catching failures! - running yarn in the fixtures directory shows the error, but the tests claim everything is fine.

edit: ah the problem is that yarn is not exiting non-zero with this error, just emitting errors.

Summary by CodeRabbit

  • Chores
    • Updated Yarn configurations to specify node linker strategies and track patch directories.
    • Changed local dependency references from "link:" to "portal:" protocol in development dependencies.
    • Improved test cases to explicitly check for error-free execution and updated error message expectations.
    • Enhanced error logging consistency and robustness in package installation and path resolution.
    • Updated versioning script to refresh test snapshots during release.
    • Refined package metadata handling and error message formatting for clearer diagnostics.

@changeset-bot
Copy link

changeset-bot bot commented Apr 26, 2025

🦋 Changeset detected

Latest commit: ca21c84

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

This PR includes changesets to release 1 package
Name Type
napi-postinstall 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

@coderabbitai
Copy link

coderabbitai bot commented Apr 26, 2025

Warning

Rate limit exceeded

@JounQin has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 17 minutes and 25 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between c235c1c and ca21c84.

⛔ Files ignored due to path filters (2)
  • test/fixtures/yarn-pnp/.yarn/patches/rollup-npm-4.40.0-5ee51badc3.patch is excluded by !**/.yarn/**
  • test/fixtures/yarn-pnp/yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (13)
  • .changeset/fresh-worms-suffer.md (1 hunks)
  • .github/workflows/pkg-size.yml (1 hunks)
  • .github/workflows/size-limit.yml (1 hunks)
  • .github/workflows/vercel.yml (1 hunks)
  • .size-limit.json (1 hunks)
  • package.json (1 hunks)
  • src/constants.ts (1 hunks)
  • src/helpers.ts (4 hunks)
  • src/index.ts (10 hunks)
  • test/basic.spec.ts (1 hunks)
  • test/fixtures.spec.ts (1 hunks)
  • test/fixtures/yarn-pnp/.gitignore (1 hunks)
  • test/fixtures/yarn-pnp/package.json (1 hunks)

Walkthrough

The changes update configuration and dependency management in two Yarn-based test fixture directories. Both .yarnrc.yml files are modified to explicitly specify the nodeLinker strategy, with one set to node-modules and the other to pnp. Additionally, both package.json files update the napi-postinstall development dependency from using the link: protocol to the portal: protocol for local package referencing, and one also changes the rollup dependency to use a Yarn patch. The test suite was updated to replace generic no-throw assertions with explicit checks that the stderr output of executed commands is empty, including a new failure expectation for the yarn-pnp fixture. Other changes include prefixing error messages with a log prefix constant, improving error handling in package installation and extraction, refining imports of package metadata, updating a version script to run tests with snapshot updates, and modifying .gitignore to track .yarn/patches. No changes were made to public or exported entities.

Changes

Files Change Summary
test/fixtures/yarn/.yarnrc.yml
test/fixtures/yarn-pnp/.yarnrc.yml
Added explicit nodeLinker configuration: node-modules for yarn, pnp for yarn-pnp.
test/fixtures/yarn/package.json
test/fixtures/yarn-pnp/package.json
Changed napi-postinstall devDependency from link: to portal: protocol; yarn-pnp also changed rollup dependency to use a Yarn patch.
test/fixtures/yarn-pnp/.gitignore Modified .gitignore to exclude .yarn/patches from being ignored, ensuring patches directory is tracked by Git.
test/fixtures.spec.ts
test/basic.spec.ts
Updated tests to explicitly await exec calls and assert stderr is empty; yarn-pnp fixture test now expects failure with detailed warning.
src/constants.ts Refactored import of package metadata: export full meta object instead of destructured name and version; name and version kept local.
src/helpers.ts Added errorLog and errorMessage functions; prefixed error messages with LOG_PREFIX constant for consistent logging.
src/index.ts Added isYarnPnp function; prefixed error messages with LOG_PREFIX; improved error handling in directory creation, package installation, and path resolution; added Yarn PnP support with fallback installation attempts.
package.json Updated version script to run tests with snapshot update flag -u.

Suggested labels

enhancement

Poem

🐇
In Yarn’s warren, configs align,
Linkers set and portals shine.
No more links, but portals new,
To guide our packages straight and true.
Errors logged with prefix bright,
Tests await with watchful sight.
The rabbit hops through code’s delight! 🌟

✨ 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.
    • 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 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

@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)
test/fixtures.spec.ts (1)

9-18: Consider consistent test validation across all package managers.

While the Yarn tests have been updated to check for empty stderr output, the npm and pnpm tests still only verify that no exceptions are thrown. For consistency and to catch similar issues across all package managers, consider updating these tests to follow the same pattern as the Yarn tests.

describe('npm fixture', () => {
-  it('should just work', () =>
-    expect(
-      exec('npm', ['install'], {
-        nodeOptions: {
-          cwd: path.resolve(fixtures, 'npm'),
-        },
-      }),
-    ).resolves.not.toThrow())
+  it('should just work', async () => {
+    const res = await exec('npm', ['install'], {
+      nodeOptions: {
+        cwd: path.resolve(fixtures, 'npm'),
+      },
+    })
+    expect(res.stderr).toEqual('')
+  })
})

Also applies to: 20-29, 31-40

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 190946d and 0bc4042.

📒 Files selected for processing (1)
  • test/fixtures.spec.ts (1 hunks)
🔇 Additional comments (2)
test/fixtures.spec.ts (2)

42-50: Enhanced test validation for Yarn fixture.

The test has been improved to explicitly check for empty stderr output rather than just checking if the command doesn't throw an exception. This addresses the issue mentioned in the PR objectives where Yarn doesn't exit with a non-zero status code for certain errors but still emits error messages, which the previous tests weren't catching.


53-61: Improved error detection for Yarn PnP fixture.

Similar to the previous test, this change enhances validation by specifically checking for empty stderr output. This is particularly important for the PnP fixture since the PR objectives note that the tests were previously failing to detect PnP-related errors.

@JounQin
Copy link
Member

JounQin commented Apr 27, 2025

The tests are not catching failures! - running yarn in the fixtures directory shows the error, but the tests claim everything is fine.

I didn't have this issue locally, corepack must be enabled.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Apr 27, 2025

Open in StackBlitz

npm i https://pkg.pr.new/napi-postinstall@25

commit: ca21c84

@JounQin
Copy link
Member

JounQin commented Apr 27, 2025

@mrginglymus Thanks, should we adapt other fixtures at the same time?

@JounQin JounQin force-pushed the break-tests branch 4 times, most recently from 0eb4059 to c235c1c Compare April 27, 2025 02:21
@JounQin JounQin changed the title Break tests fix: give up patching yarn pnp automatically which is impossible Apr 27, 2025
@JounQin JounQin changed the title fix: give up patching yarn pnp automatically which is impossible fix: give up patching yarn pnp automatically which is impossible Apr 27, 2025
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 0eb4059 and c235c1c.

⛔ Files ignored due to path filters (2)
  • test/fixtures/yarn-pnp/.yarn/patches/rollup-npm-4.40.0-5ee51badc3.patch is excluded by !**/.yarn/**
  • test/fixtures/yarn-pnp/yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (8)
  • package.json (1 hunks)
  • src/constants.ts (1 hunks)
  • src/helpers.ts (4 hunks)
  • src/index.ts (10 hunks)
  • test/basic.spec.ts (1 hunks)
  • test/fixtures.spec.ts (1 hunks)
  • test/fixtures/yarn-pnp/.gitignore (1 hunks)
  • test/fixtures/yarn-pnp/package.json (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • test/fixtures/yarn-pnp/package.json
🚧 Files skipped from review as they are similar to previous changes (6)
  • test/basic.spec.ts
  • package.json
  • test/fixtures/yarn-pnp/.gitignore
  • src/constants.ts
  • test/fixtures.spec.ts
  • src/helpers.ts
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/index.ts (4)
src/helpers.ts (4)
  • errorMessage (280-282)
  • getErrorMessage (272-274)
  • errorLog (276-278)
  • downloadedNodePath (38-41)
src/constants.ts (3)
  • PACKAGE_JSON (21-21)
  • WASM32_WASI (17-17)
  • meta (7-9)
test/fixtures/yarn-pnp/postinstall.js (1)
  • require (1-1)
test/fixtures/yarn/postinstall.js (1)
  • require (1-1)
🔇 Additional comments (12)
src/index.ts (12)

9-9: Consistent import of package metadata from constants.

The import now retrieves the full meta object from constants.js instead of destructuring specific values, aligning with other parts of the codebase. This change supports the later use of meta.name for path resolution.


12-13: Good addition of error handling helpers.

Adding imports for the errorLog and errorMessage helpers standardizes error reporting across the codebase, making error messages more consistent and maintainable.


51-52: Improved error message formatting.

Using the errorMessage helper ensures consistent error message formatting with the log prefix.


70-70: Standardized error message formatting.

Using the errorMessage helper here maintains consistency in how errors are presented to users.


73-75: Simplified isNpm function.

The redundant boolean casting was removed while maintaining the same functionality. This is a good simplification.


77-82: Added Yarn PnP detection function.

This function appropriately checks for both Yarn in the user agent and the presence of the PnP version, which is essential for the Yarn PnP-specific handling added elsewhere in the code.


106-121: Improved error handling for read-only filesystems.

This change adds graceful handling for EROFS errors when attempting to create the installation directory. Instead of throwing an error, it now provides a helpful message to the user and continues execution, which improves the robustness of the installation process.


238-238: Standardized error logging in download functions.

Replacing console.error calls with the errorLog helper ensures consistent formatting of error messages throughout the codebase.

Also applies to: 245-245


276-278: Consistent error message formatting.

All error messages now use the errorMessage helper, ensuring consistent formatting throughout the codebase.

Also applies to: 308-310, 399-402


323-326: Improved readability with local variable.

Extracting the isWasm32Wasi check into a local variable improves code readability and reduces duplicate checks.


369-380: Added robust path resolution with Yarn PnP fallback.

The added try-catch block improves robustness by providing a fallback path resolution method when the standard approach fails (e.g., in Yarn PnP environments). This is a good defensive programming practice that ensures the code can handle various environment configurations.


382-382: Standardized error logging for installation attempts.

Using the errorLog helper for installation logging ensures consistent formatting and improves the user experience by providing clear, standardized error messages.

Also applies to: 386-389

@JounQin JounQin force-pushed the break-tests branch 7 times, most recently from 9debfbb to f52c452 Compare April 27, 2025 02:53
@JounQin JounQin merged commit 2eb7867 into un-ts:main Apr 27, 2025
18 checks passed
@JounQin
Copy link
Member

JounQin commented Apr 27, 2025

Thanks @mrginglymus!

@mrginglymus mrginglymus deleted the break-tests branch April 27, 2025 08:02
@mrginglymus
Copy link
Contributor Author

Thanks @JounQin - all working on my end now :)

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.

2 participants