-
Notifications
You must be signed in to change notification settings - Fork 38
π docs: clarify NATIVEWIND token export for bun install #2225
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,77 +1,71 @@ | ||||||||||||||||||||||||||||
| #!/usr/bin/env bun | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||
| * Configure dependencies for installation | ||||||||||||||||||||||||||||
| * Verify that GitHub Packages auth is available for `bun install`. | ||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||
| * This script ensures that GitHub packages authentication is properly set up | ||||||||||||||||||||||||||||
| * for installing private packages from the GitHub Package Registry. | ||||||||||||||||||||||||||||
| * IMPORTANT: Bun reads bunfig.toml at process startup, BEFORE this preinstall | ||||||||||||||||||||||||||||
| * hook runs. That means we cannot inject PACKRAT_NATIVEWIND_UI_GITHUB_TOKEN | ||||||||||||||||||||||||||||
| * into the parent process β the variable must already be exported in the | ||||||||||||||||||||||||||||
| * shell that invokes `bun install`. This script's job is to detect a missing | ||||||||||||||||||||||||||||
| * token early and print the exact command to fix it. | ||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||
| * It runs automatically before `bun install` via the preinstall hook. | ||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||
| * Token Usage Pattern: | ||||||||||||||||||||||||||||
| * - Local development: GitHub CLI token (from `gh auth token`) β PACKRAT_NATIVEWIND_UI_GITHUB_TOKEN | ||||||||||||||||||||||||||||
| * - CI/CD: Uses PACKRAT_NATIVEWIND_UI_GITHUB_TOKEN directly from secrets | ||||||||||||||||||||||||||||
| * - The token is used by bunfig.toml to authenticate with npm.pkg.github.com | ||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||
| * Requirements: | ||||||||||||||||||||||||||||
| * - Local development: GitHub CLI must be installed and authenticated with `read:packages` scope | ||||||||||||||||||||||||||||
| * - CI/CD: PACKRAT_NATIVEWIND_UI_GITHUB_TOKEN environment variable must be set | ||||||||||||||||||||||||||||
| * Expected flow: | ||||||||||||||||||||||||||||
| * - Local dev: `export PACKRAT_NATIVEWIND_UI_GITHUB_TOKEN=$(gh auth token)` then `bun install` | ||||||||||||||||||||||||||||
| * - CI/CD: PACKRAT_NATIVEWIND_UI_GITHUB_TOKEN set from repo secrets | ||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| import { $ } from 'bun'; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| async function configureDeps() { | ||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||
| // Check if we're in a CI environment | ||||||||||||||||||||||||||||
| const isCI = | ||||||||||||||||||||||||||||
| process.env.CI === '1' || process.env.CI === 'true' || process.env.GITHUB_ACTIONS === 'true'; | ||||||||||||||||||||||||||||
| const TOKEN_VAR = 'PACKRAT_NATIVEWIND_UI_GITHUB_TOKEN'; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| if (isCI) { | ||||||||||||||||||||||||||||
| // In CI, bunfig.toml will use PACKRAT_NATIVEWIND_UI_GITHUB_TOKEN | ||||||||||||||||||||||||||||
| if (!process.env.PACKRAT_NATIVEWIND_UI_GITHUB_TOKEN) { | ||||||||||||||||||||||||||||
| console.error('β PACKRAT_NATIVEWIND_UI_GITHUB_TOKEN not found in CI'); | ||||||||||||||||||||||||||||
| console.error('Please ensure PACKRAT_NATIVEWIND_UI_GITHUB_TOKEN is set in your CI secrets'); | ||||||||||||||||||||||||||||
| process.exit(1); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| console.log('β Using PACKRAT_NATIVEWIND_UI_GITHUB_TOKEN for CI authentication'); | ||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| function isCI(): boolean { | ||||||||||||||||||||||||||||
| return ( | ||||||||||||||||||||||||||||
| process.env.CI === '1' || process.env.CI === 'true' || process.env.GITHUB_ACTIONS === 'true' | ||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| // For local development, check if PACKRAT_NATIVEWIND_UI_GITHUB_TOKEN is already set | ||||||||||||||||||||||||||||
| if (process.env.PACKRAT_NATIVEWIND_UI_GITHUB_TOKEN) { | ||||||||||||||||||||||||||||
| console.log('β PACKRAT_NATIVEWIND_UI_GITHUB_TOKEN already set in environment'); | ||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| function printLocalFix(): void { | ||||||||||||||||||||||||||||
| console.error(`\nβ ${TOKEN_VAR} is not exported in your shell.`); | ||||||||||||||||||||||||||||
| console.error('\nBun reads bunfig.toml before the preinstall hook runs, so the token'); | ||||||||||||||||||||||||||||
| console.error('must be present in the parent shell. Run one of:\n'); | ||||||||||||||||||||||||||||
| console.error(' # Inline'); | ||||||||||||||||||||||||||||
| console.error(` export ${TOKEN_VAR}=$(gh auth token)`); | ||||||||||||||||||||||||||||
| console.error(' bun install\n'); | ||||||||||||||||||||||||||||
| console.error(' # One-liner'); | ||||||||||||||||||||||||||||
| console.error(` ${TOKEN_VAR}=$(gh auth token) bun install\n`); | ||||||||||||||||||||||||||||
| console.error(' # Persist β add to ~/.zshrc or ~/.bashrc'); | ||||||||||||||||||||||||||||
| console.error(` export ${TOKEN_VAR}=$(gh auth token 2>/dev/null)\n`); | ||||||||||||||||||||||||||||
| console.error('If gh is not set up yet:'); | ||||||||||||||||||||||||||||
| console.error(' gh auth login'); | ||||||||||||||||||||||||||||
| console.error(' gh auth refresh -h github.com -s read:packages'); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| // Try to get token from GitHub CLI | ||||||||||||||||||||||||||||
| const ghStatus = await $`gh auth status`.quiet().nothrow(); | ||||||||||||||||||||||||||||
| async function configureDeps() { | ||||||||||||||||||||||||||||
| if (process.env[TOKEN_VAR]) { | ||||||||||||||||||||||||||||
| console.log(`β ${TOKEN_VAR} is set β bun install will authenticate to GitHub Packages`); | ||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| if (ghStatus.exitCode === 0) { | ||||||||||||||||||||||||||||
| // Note: gh auth status doesn't show read:packages in the output even when it's granted | ||||||||||||||||||||||||||||
| // The token will work if the user has followed the authentication steps | ||||||||||||||||||||||||||||
| if (isCI()) { | ||||||||||||||||||||||||||||
| console.error(`β ${TOKEN_VAR} not found in CI environment`); | ||||||||||||||||||||||||||||
| console.error(`Set ${TOKEN_VAR} in your CI secrets and expose it to this job.`); | ||||||||||||||||||||||||||||
| process.exit(1); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| // Get the GitHub token from gh CLI and set it as PACKRAT_NATIVEWIND_UI_GITHUB_TOKEN | ||||||||||||||||||||||||||||
| const token = await $`gh auth token`.text(); | ||||||||||||||||||||||||||||
| process.env.PACKRAT_NATIVEWIND_UI_GITHUB_TOKEN = token.trim(); | ||||||||||||||||||||||||||||
| console.log('β Using GitHub CLI token for authentication'); | ||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||
| console.error('β GitHub CLI not found or not authenticated'); | ||||||||||||||||||||||||||||
| console.error('\nTo fix this:'); | ||||||||||||||||||||||||||||
| console.error('1. Install GitHub CLI: https://cli.github.com'); | ||||||||||||||||||||||||||||
| console.error('2. Authenticate: gh auth login'); | ||||||||||||||||||||||||||||
| console.error('3. Add packages scope: gh auth refresh -h github.com -s read:packages'); | ||||||||||||||||||||||||||||
| console.error( | ||||||||||||||||||||||||||||
| '\nAlternatively, set PACKRAT_NATIVEWIND_UI_GITHUB_TOKEN environment variable with a personal access token', | ||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||
| process.exit(1); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| } catch (error) { | ||||||||||||||||||||||||||||
| console.error('β Configuration failed:', error); | ||||||||||||||||||||||||||||
| const ghStatus = await $`gh auth status`.quiet().nothrow(); | ||||||||||||||||||||||||||||
| if (ghStatus.exitCode !== 0) { | ||||||||||||||||||||||||||||
| console.error('β GitHub CLI not found or not authenticated.\n'); | ||||||||||||||||||||||||||||
| console.error('1. Install GitHub CLI: https://cli.github.com'); | ||||||||||||||||||||||||||||
| console.error('2. Authenticate: gh auth login'); | ||||||||||||||||||||||||||||
| console.error('3. Add packages scope: gh auth refresh -h github.com -s read:packages'); | ||||||||||||||||||||||||||||
| console.error(`4. Then export ${TOKEN_VAR}=$(gh auth token) and re-run bun install.`); | ||||||||||||||||||||||||||||
|
Comment on lines
+58
to
+61
|
||||||||||||||||||||||||||||
| console.error('1. Install GitHub CLI: https://cli.github.com'); | |
| console.error('2. Authenticate: gh auth login'); | |
| console.error('3. Add packages scope: gh auth refresh -h github.com -s read:packages'); | |
| console.error(`4. Then export ${TOKEN_VAR}=$(gh auth token) and re-run bun install.`); | |
| console.error('You can fix this in either of these ways:\n'); | |
| console.error('1. Use GitHub CLI'); | |
| console.error(' - Install GitHub CLI: https://cli.github.com'); | |
| console.error(' - Authenticate: gh auth login'); | |
| console.error(' - Add packages scope: gh auth refresh -h github.com -s read:packages'); | |
| console.error(` - Then export ${TOKEN_VAR}=$(gh auth token) and re-run bun install.\n`); | |
| console.error('2. Set the token manually'); | |
| console.error(` - Export ${TOKEN_VAR} directly in your shell before running bun install`); | |
| console.error(' - For example, use a GitHub PAT with the read:packages scope'); |
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.
The success message asserts that
bun install will authenticate, but this script doesnβt actually validate the token against GitHub Packagesβonly that the env var is non-empty. Consider softening the wording (e.g., βtoken is setβ) or adding a lightweight validation if you want the message to be strictly accurate.