diff --git a/common/changes/@microsoft/rush/user-dmichon-suppress-registry-call_2024-08-22-21-46.json b/common/changes/@microsoft/rush/user-dmichon-suppress-registry-call_2024-08-22-21-46.json new file mode 100644 index 00000000000..f5fc65cddba --- /dev/null +++ b/common/changes/@microsoft/rush/user-dmichon-suppress-registry-call_2024-08-22-21-46.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@microsoft/rush", + "comment": "Add rush.json option \"suppressRushIsPublicVersionCheck\" to allow suppressing hardcoded calls to the npmjs.org registry.", + "type": "none" + } + ], + "packageName": "@microsoft/rush" +} \ No newline at end of file diff --git a/libraries/rush-lib/assets/rush-init/rush.json b/libraries/rush-lib/assets/rush-init/rush.json index 7a9a788c35d..f77555b001b 100644 --- a/libraries/rush-lib/assets/rush-init/rush.json +++ b/libraries/rush-lib/assets/rush-init/rush.json @@ -65,6 +65,13 @@ */ /*[LINE "HYPOTHETICAL"]*/ "suppressNodeLtsWarning": false, + /** + * Rush normally prints a warning if it detects that the current version is not one published to the + * public npmjs.org registry. If you need to block calls to the npm registry, you can use this setting to disable + * Rush's check. + */ + /*[LINE "HYPOTHETICAL"]*/ "suppressRushIsPublicVersionCheck": false, + /** * Large monorepos can become intimidating for newcomers if project folder paths don't follow * a consistent and recognizable pattern. When the system allows nested folder trees, diff --git a/libraries/rush-lib/src/api/RushConfiguration.ts b/libraries/rush-lib/src/api/RushConfiguration.ts index fdf86ae1859..70ed8338ab0 100644 --- a/libraries/rush-lib/src/api/RushConfiguration.ts +++ b/libraries/rush-lib/src/api/RushConfiguration.ts @@ -158,6 +158,7 @@ export interface IRushConfigurationJson { nodeSupportedVersionRange?: string; nodeSupportedVersionInstructions?: string; suppressNodeLtsWarning?: boolean; + suppressRushIsPublicVersionCheck?: boolean; projectFolderMinDepth?: number; projectFolderMaxDepth?: number; allowMostlyStandardPackageNames?: boolean; diff --git a/libraries/rush-lib/src/logic/base/BaseInstallManager.ts b/libraries/rush-lib/src/logic/base/BaseInstallManager.ts index f781e34b766..6334a7a9567 100644 --- a/libraries/rush-lib/src/logic/base/BaseInstallManager.ts +++ b/libraries/rush-lib/src/logic/base/BaseInstallManager.ts @@ -48,7 +48,7 @@ import { ShrinkwrapFileFactory } from '../ShrinkwrapFileFactory'; import { Utilities } from '../../utilities/Utilities'; import { InstallHelpers } from '../installManager/InstallHelpers'; import * as PolicyValidator from '../policy/PolicyValidator'; -import { WebClient, type WebClientResponse } from '../../utilities/WebClient'; +import type { WebClient as WebClientType, WebClientResponse } from '../../utilities/WebClient'; import { SetupPackageRegistry } from '../setup/SetupPackageRegistry'; import { PnpmfileConfiguration } from '../pnpm/PnpmfileConfiguration'; import type { IInstallManagerOptions } from './BaseInstallManagerTypes'; @@ -207,19 +207,21 @@ export abstract class BaseInstallManager { console.log(); await this.validateNpmSetupAsync(); - let publishedRelease: boolean | undefined; - try { - publishedRelease = await this._checkIfReleaseIsPublishedAsync(); - } catch { - // If the user is working in an environment that can't reach the registry, - // don't bother them with errors. - } + if (!this.rushConfiguration.rushConfigurationJson.suppressRushIsPublicVersionCheck) { + let publishedRelease: boolean | undefined; + try { + publishedRelease = await this._checkIfReleaseIsPublishedAsync(); + } catch { + // If the user is working in an environment that can't reach the registry, + // don't bother them with errors. + } - if (publishedRelease === false) { - // eslint-disable-next-line no-console - console.log( - Colorize.yellow('Warning: This release of the Rush tool was unpublished; it may be unstable.') - ); + if (publishedRelease === false) { + // eslint-disable-next-line no-console + console.log( + Colorize.yellow('Warning: This release of the Rush tool was unpublished; it may be unstable.') + ); + } } // Delete the successful install file to indicate the install transaction has started @@ -1008,7 +1010,9 @@ ${gitLfsHookHandling} // Note that the "@" symbol does not normally get URL-encoded queryUrl += RushConstants.rushPackageName.replace('/', '%2F'); - const webClient: WebClient = new WebClient(); + const { WebClient } = await import('../../utilities/WebClient'); + + const webClient: WebClientType = new WebClient(); webClient.userAgent = `pnpm/? npm/? node/${process.version} ${os.platform()} ${os.arch()}`; webClient.accept = 'application/vnd.npm.install-v1+json; q=1.0, application/json; q=0.8, */*'; diff --git a/libraries/rush-lib/src/logic/setup/SetupPackageRegistry.ts b/libraries/rush-lib/src/logic/setup/SetupPackageRegistry.ts index 460e8900935..ac6acbc2a43 100644 --- a/libraries/rush-lib/src/logic/setup/SetupPackageRegistry.ts +++ b/libraries/rush-lib/src/logic/setup/SetupPackageRegistry.ts @@ -17,7 +17,7 @@ import { PrintUtilities, Colorize, ConsoleTerminalProvider, Terminal } from '@ru import type { RushConfiguration } from '../../api/RushConfiguration'; import { Utilities } from '../../utilities/Utilities'; import { type IArtifactoryPackageRegistryJson, ArtifactoryConfiguration } from './ArtifactoryConfiguration'; -import { WebClient, type WebClientResponse } from '../../utilities/WebClient'; +import type { WebClient as WebClientType, WebClientResponse } from '../../utilities/WebClient'; import { TerminalInput } from './TerminalInput'; interface IArtifactoryCustomizableMessages { @@ -284,7 +284,9 @@ export class SetupPackageRegistry { ): Promise { this._terminal.writeLine('\nFetching an NPM token from the Artifactory service...'); - const webClient: WebClient = new WebClient(); + // Defer this import since it is conditionally needed. + const { WebClient } = await import('../../utilities/WebClient'); + const webClient: WebClientType = new WebClient(); webClient.addBasicAuthHeader(artifactoryUser, artifactoryKey); diff --git a/libraries/rush-lib/src/schemas/rush.schema.json b/libraries/rush-lib/src/schemas/rush.schema.json index 46965cbbd41..af9e2481548 100644 --- a/libraries/rush-lib/src/schemas/rush.schema.json +++ b/libraries/rush-lib/src/schemas/rush.schema.json @@ -64,6 +64,10 @@ "description": "Rush normally prints a warning if it detects a pre-LTS Node.js version. If you are testing pre-LTS versions in preparation for supporting the first LTS version, you can use this setting to disable Rush's warning.", "type": "boolean" }, + "suppressRushIsPublicVersionCheck": { + "description": "Rush normally prints a warning if it detects that the current version is not one published to the public npmjs.org registry. If you need to block calls to the npm registry, you can use this setting to disable Rush's check.", + "type": "boolean" + }, "projectFolderMinDepth": { "description": "The minimum folder depth for the projectFolder field. The default value is 1, i.e. no slashes in the path name.", "type": "number"