Avoid postinstall by using optionalDependencies for each platform#105
Open
sverrejoh wants to merge 6 commits intomicrosoft:mainfrom
Open
Avoid postinstall by using optionalDependencies for each platform#105sverrejoh wants to merge 6 commits intomicrosoft:mainfrom
sverrejoh wants to merge 6 commits intomicrosoft:mainfrom
Conversation
added 6 commits
December 1, 2025 11:38
Implements the esbuild pattern for distributing platform-specific binaries using optionalDependencies instead of relying solely on postinstall scripts. Changes: - Add platform-specific packages (@azureauth/darwin-arm64, darwin-x64, win32-x64) - Update azure-auth-command.ts to check optional deps first, then fallback - Update install.ts to skip download if optional dep is present - Add publish-all.mjs script for publishing platform + main packages This approach: - Works with package managers that don't run postinstall (like yarn PnP) - Reduces install time when optional deps are available - Maintains backward compatibility via postinstall fallback
dannyvv
approved these changes
Jan 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary of the Pull Request
Uses npm's
optionalDependencieswithosandcpufields to provide the azureauth binary through the normal package installation flow, making the postinstall download optional.References and Relevant Issues
Detailed Description of the Pull Request / Additional comments
Problem
The postinstall download approach has compatibility and reliability issues:
Solution
Creates three platform-specific packages under the
@microsoftnpm scope:@microsoft/azureauth-darwin-arm64- macOS ARM64@microsoft/azureauth-darwin-x64- macOS x64@microsoft/azureauth-win32-x64- Windows x64Package manager support
Fallback
The postinstall script still exists for backwards compatibility. It checks if the binary is already available and exits early:
This handles unsupported platforms (Linux), older package managers, or disabled optionalDependencies.
Validation Steps Performed
Test the publish script (dry run)
cd packages/node-azureauth yarn bundle yarn publish-all:dry-runTest installation manually (on macOS or Windows)
Note: Full binary testing requires macOS or Windows (Linux binaries not available).
PR Checklist