Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions change/change-4c12df77-7abf-469a-b9fc-dbfdca11d96e.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"changes": [
{
"type": "none",
"comment": "Add platform-specific binary package for azureauth",
"packageName": "@microsoft/azureauth-darwin-arm64",
"email": "sverre.johansen@microsoft.com",
"dependentChangeType": "none"
},
{
"type": "none",
"comment": "Add platform-specific binary package for azureauth",
"packageName": "@microsoft/azureauth-darwin-x64",
"email": "sverre.johansen@microsoft.com",
"dependentChangeType": "none"
},
{
"type": "none",
"comment": "Add platform-specific binary package for azureauth",
"packageName": "@microsoft/azureauth-win32-x64",
"email": "sverre.johansen@microsoft.com",
"dependentChangeType": "none"
}
]
}
11 changes: 11 additions & 0 deletions change/change-7b213891-7a87-43e9-8e50-b3c5772dd1ca.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"type": "patch",
"comment": "Add optionalDependencies support for platform-specific binaries (esbuild pattern)",
"packageName": "azureauth",
"email": "sverre.johansen@microsoft.com",
"dependentChangeType": "patch"
}
]
}
2 changes: 2 additions & 0 deletions packages/azureauth-darwin-arm64/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Binary files are downloaded during publish, not committed
bin/
21 changes: 21 additions & 0 deletions packages/azureauth-darwin-arm64/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) Microsoft Corporation.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
20 changes: 20 additions & 0 deletions packages/azureauth-darwin-arm64/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "@microsoft/azureauth-darwin-arm64",
"version": "0.8.4",
"description": "The macOS ARM64 binary for azureauth",
"repository": {
"url": "https://github.com/microsoft/ado-npm-auth"
},
"license": "MIT",
"preferUnplugged": true,
"os": [
"darwin"
],
"cpu": [
"arm64"
],
"files": [
"bin",
"LICENSE"
]
}
2 changes: 2 additions & 0 deletions packages/azureauth-darwin-x64/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Binary files are downloaded during publish, not committed
bin/
21 changes: 21 additions & 0 deletions packages/azureauth-darwin-x64/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) Microsoft Corporation.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
20 changes: 20 additions & 0 deletions packages/azureauth-darwin-x64/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "@microsoft/azureauth-darwin-x64",
"version": "0.8.4",
"description": "The macOS x64 binary for azureauth",
"repository": {
"url": "https://github.com/microsoft/ado-npm-auth"
},
"license": "MIT",
"preferUnplugged": true,
"os": [
"darwin"
],
"cpu": [
"x64"
],
"files": [
"bin",
"LICENSE"
]
}
2 changes: 2 additions & 0 deletions packages/azureauth-win32-x64/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Binary files are downloaded during publish, not committed
bin/
21 changes: 21 additions & 0 deletions packages/azureauth-win32-x64/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) Microsoft Corporation.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
20 changes: 20 additions & 0 deletions packages/azureauth-win32-x64/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "@microsoft/azureauth-win32-x64",
"version": "0.8.4",
"description": "The Windows x64 binary for azureauth",
"repository": {
"url": "https://github.com/microsoft/ado-npm-auth"
},
"license": "MIT",
"preferUnplugged": true,
"os": [
"win32"
],
"cpu": [
"x64"
],
"files": [
"bin",
"LICENSE"
]
}
7 changes: 5 additions & 2 deletions packages/node-azureauth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,17 @@
"type": "module",
"scripts": {
"build": "tsc",
"bundle": "yarn bundleInstall && yarn bundleCli && yarn bundleIndex",
"bundle": "yarn bundleInstall && yarn bundleCli && yarn bundleIndex && yarn bundlePublish",
"bundleInstall": "esbuild --sourcemap --bundle --minify --platform=node --outfile=dist/install.cjs src/install.ts",
"bundleCli": "esbuild --sourcemap --bundle --minify --platform=node cli.js --outfile=dist/cli.cjs",
"bundleIndex": "esbuild --sourcemap --bundle --minify --platform=node --format=esm src/index.ts --outfile=dist/index.js",
"bundlePublish": "esbuild --sourcemap --bundle --minify --platform=node --outfile=dist/publish-all.cjs src/publish-all.ts",
"lint": "prettier --check src/**/*.ts ./cli.js ",
"start": "tsc --watch",
"test": "vitest run src",
"postinstall": "node ./scripts/install.cjs"
"postinstall": "node ./scripts/install.cjs",
"publish-all": "node ./dist/publish-all.cjs",
"publish-all:dry-run": "node ./dist/publish-all.cjs --dry-run"
},
"files": [
"dist/install.cjs",
Expand Down
49 changes: 49 additions & 0 deletions packages/node-azureauth/src/azure-auth-command.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,56 @@
import path from "node:path";
import process from "node:process";
import fs from "node:fs";
import { createRequire } from "node:module";

import { PLATFORM_PACKAGES } from "./constants.js";

const require = createRequire(import.meta.url);

/**
* Try to find the binary from the platform-specific optional dependency.
* Returns the path to the binary if found, null otherwise.
*/
function getBinaryFromOptionalDep(): string | null {
const platform = process.platform;
const arch = process.arch;

const packageName = PLATFORM_PACKAGES[platform]?.[arch];
if (!packageName) {
return null;
}

const binaryName = platform === "win32" ? "azureauth.exe" : "azureauth";

try {
// Resolve the package directory
const packageJson = require.resolve(`${packageName}/package.json`);
const packageDir = path.dirname(packageJson);
const binaryPath = path.join(packageDir, "bin", binaryName);

if (fs.existsSync(binaryPath)) {
return binaryPath;
}
} catch {
// Package not installed, fall through to return null
}

return null;
}

/**
* Get the path to the azureauth binary.
* First checks for platform-specific optional dependency,
* then falls back to the postinstall-downloaded binary.
*/
export const azureAuthCommand = () => {
// First, try the platform-specific optional dependency
const optionalDepBinary = getBinaryFromOptionalDep();
if (optionalDepBinary) {
return optionalDepBinary;
}

// Fall back to the postinstall-downloaded binary
let azureauth = path.join(__dirname, "..", "bin", "azureauth", "azureauth");

if (process.platform === "win32") {
Expand Down
11 changes: 11 additions & 0 deletions packages/node-azureauth/src/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export const AZURE_AUTH_VERSION = "0.8.4";

export const PLATFORM_PACKAGES: Record<string, Record<string, string>> = {
darwin: {
arm64: "@microsoft/azureauth-darwin-arm64",
x64: "@microsoft/azureauth-darwin-x64",
},
win32: {
x64: "@microsoft/azureauth-win32-x64",
},
};
36 changes: 35 additions & 1 deletion packages/node-azureauth/src/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,33 @@ import fs from "node:fs";
import { DownloaderHelper } from "node-downloader-helper";
import decompress from "decompress";

const AZURE_AUTH_VERSION = "0.8.4";
import { AZURE_AUTH_VERSION, PLATFORM_PACKAGES } from "./constants.js";

declare const require: NodeRequire;

export { AZURE_AUTH_VERSION };

/**
* Check if the binary is available via optional dependency.
*/
function isOptionalDepInstalled(): boolean {
const platformPackage = PLATFORM_PACKAGES[process.platform]?.[process.arch];
if (!platformPackage) {
return false;
}

const binaryName =
process.platform === "win32" ? "azureauth.exe" : "azureauth";

try {
const resolvedPath = require.resolve(`${platformPackage}/package.json`);
const packageDir = path.dirname(resolvedPath);
const binaryPath = path.join(packageDir, "bin", binaryName);
return fs.existsSync(binaryPath);
} catch {
return false;
}
}

async function download(url: string, saveDirectory: string): Promise<void> {
const downloader = new DownloaderHelper(url, saveDirectory);
Expand Down Expand Up @@ -46,6 +72,14 @@ export const AZUREAUTH_NAME =
: AZUREAUTH_NAME_MAP.def;

export const install = async () => {
// Check if binary is available via optional dependency (esbuild pattern)
if (isOptionalDepInstalled()) {
console.log(
"azureauth binary available via platform-specific package, skipping download",
);
return;
}

const OUTPUT_DIR = path.join(__dirname, "..", "bin");
const fileExist = (pathToCheck: string) => {
try {
Expand Down
Loading