Skip to content

Commit

Permalink
[rush] Add option to suppress hardcoded npmjs.org registry call (#4900)
Browse files Browse the repository at this point in the history
Co-authored-by: David Michon <[email protected]>
  • Loading branch information
dmichon-msft and dmichon-msft authored Aug 23, 2024
1 parent de9aa4a commit 3ed14b7
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -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"
}
7 changes: 7 additions & 0 deletions libraries/rush-lib/assets/rush-init/rush.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions libraries/rush-lib/src/api/RushConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ export interface IRushConfigurationJson {
nodeSupportedVersionRange?: string;
nodeSupportedVersionInstructions?: string;
suppressNodeLtsWarning?: boolean;
suppressRushIsPublicVersionCheck?: boolean;
projectFolderMinDepth?: number;
projectFolderMaxDepth?: number;
allowMostlyStandardPackageNames?: boolean;
Expand Down
32 changes: 18 additions & 14 deletions libraries/rush-lib/src/logic/base/BaseInstallManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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, */*';

Expand Down
6 changes: 4 additions & 2 deletions libraries/rush-lib/src/logic/setup/SetupPackageRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -284,7 +284,9 @@ export class SetupPackageRegistry {
): Promise<void> {
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);

Expand Down
4 changes: 4 additions & 0 deletions libraries/rush-lib/src/schemas/rush.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 3ed14b7

Please sign in to comment.