fix: write .npmrc in preinstall to resolve bun install 401 on @packrat-ai/nativewindui#1901
fix: write .npmrc in preinstall to resolve bun install 401 on @packrat-ai/nativewindui#1901
Conversation
…1 error Co-authored-by: andrew-bierman <94939237+andrew-bierman@users.noreply.github.com>
|
@coderabbitai Please review this PR for code quality, best practices, and potential issues. |
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain🏁 Script executed: Length of output: 4946
🐛 Bug — Double blank line when merging into an existing
|
|
@copilot CodeRabbit has reviewed this PR and provided feedback. Please address the review comments and push updates. Once you've made the changes, the monitor will ask CodeRabbit to re-review. |
There was a problem hiding this comment.
Pull request overview
This PR fixes a bun install 401 error when fetching @packrat-ai/nativewindui from npm.pkg.github.com. The root cause was that the preinstall script set PACKRAT_NATIVEWIND_UI_GITHUB_TOKEN via process.env, but env mutations in a child process don't propagate back to the parent bun install process that reads bunfig.toml. The fix writes the token directly to a repo-root .npmrc file, which bun reads for registry authentication across all processes.
Changes:
writeNpmrc()helper that creates or merges a.npmrcfile with the GitHub registry auth token (mode0o600), replacing theprocess.envmutation approach.- All three auth paths (CI env var, local env var,
gh auth token) now callwriteNpmrc()to persist the token. .npmrcis added to.gitignoreto prevent the generated file from being committed.
Reviewed changes
Copilot reviewed 1 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
.github/scripts/configure-deps.ts |
Adds writeNpmrc() function and routes all auth paths through it instead of process.env mutation |
.gitignore |
Adds .npmrc entry to prevent the generated auth file from being committed |
You can also share your feedback on Copilot code review. Take the survey.
| writeNpmrc(process.env.PACKRAT_NATIVEWIND_UI_GITHUB_TOKEN); | ||
| console.log('✓ Using PACKRAT_NATIVEWIND_UI_GITHUB_TOKEN for CI authentication'); | ||
| return; | ||
| } | ||
|
|
||
| // For local development, check if PACKRAT_NATIVEWIND_UI_GITHUB_TOKEN is already set | ||
| if (process.env.PACKRAT_NATIVEWIND_UI_GITHUB_TOKEN) { | ||
| writeNpmrc(process.env.PACKRAT_NATIVEWIND_UI_GITHUB_TOKEN); |
There was a problem hiding this comment.
The writeNpmrc function does not trim the token internally, yet the two env-var code paths (CI and local env var) pass the value directly from process.env without calling .trim(), while the GitHub CLI path explicitly calls token.trim() before passing. If a token in the environment variable has accidental leading/trailing whitespace (e.g. from a .env file), the auth line will be written with embedded whitespace, producing an invalid token. Either trim inside writeNpmrc so all callers benefit uniformly, or add .trim() at lines 74 and 81 to match the behavior at line 95.
| } else { | ||
| // Append before any trailing newline | ||
| lines.push(newAuthLine); | ||
| } |
There was a problem hiding this comment.
The comment on line 51 says "Append before any trailing newline", but the implementation doesn't do that. When an existing .npmrc ends with a newline (as is typical), existing.split('\n') produces a trailing empty string '' at the end of lines. Pushing newAuthLine after that empty string and then joining produces a blank line before the auth token and no trailing newline on the file (e.g., "line1\n\n//npm.pkg.github.com/…").
To correctly insert before the trailing newline, the code should check whether the last element is an empty string and, if so, insert before it using splice rather than push. While the resulting file is still functionally parseable, the blank line is an unintended formatting artifact that contradicts the stated intent.
|
@copilot Please address the CodeRabbit review feedback on this PR (2 inline comments). |
…logic Co-authored-by: andrew-bierman <94939237+andrew-bierman@users.noreply.github.com>
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the 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. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
.github/scripts/configure-deps.tsto write a.npmrcfile with the auth token instead of setting env var (which doesn't propagate to parent process).npmrcgracefully by merging (update auth line if present, insert before trailing newline otherwise).npmrcto.gitignoreto prevent committing the auth token.npmrcis used instead ofprocess.envwriteNpmrcuniformly for all callers (review feedback)split('\n'), not after (review feedback)Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.