Skip to content
Merged
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
5 changes: 4 additions & 1 deletion common/config/azure-pipelines/npm-post-publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,12 @@ extends:
--verbose
DisplayName: 'Rush Build (repo-toolbox)'

# Query the public feed directly to bypass propagation latency in the private feed.
- template: /common/config/azure-pipelines/templates/run-repo-toolbox.yaml@self
parameters:
Arguments: 'bump-decoupled-local-dependencies'
Arguments: >
bump-decoupled-local-dependencies
--feed-url https://registry.npmjs.org/
DisplayName: 'Bump decoupled local dependencies'

# If Rush itself was updated by bump-decoupled-local-dependencies, we need to bootstrap
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,28 @@ import { Async, Executable, FileSystem, type FolderItem, JsonFile } from '@rushs
import type { ITerminal } from '@rushstack/terminal';
import { DependencyType, PackageJsonEditor, RushConfiguration, type Subspace } from '@microsoft/rush-lib';
import type { IRushConfigurationJson } from '@microsoft/rush-lib/lib/api/RushConfiguration';
import { CommandLineAction } from '@rushstack/ts-command-line';
import { CommandLineAction, type CommandLineStringParameter } from '@rushstack/ts-command-line';

async function _getLatestPublishedVersionAsync(
terminal: ITerminal,
packageName: string,
feedUrl: string | undefined
): Promise<string> {
const npmArgs: string[] = ['view', packageName, 'version'];
if (feedUrl) {
npmArgs.push('--registry', feedUrl);
}

async function _getLatestPublishedVersionAsync(terminal: ITerminal, packageName: string): Promise<string> {
return await new Promise((resolve: (result: string) => void, reject: (error: Error) => void) => {
const childProcess: ChildProcess = Executable.spawn('npm', ['view', packageName, 'version'], {
stdio: ['ignore', 'pipe', 'pipe']
});
const stdoutBuffer: string[] = [];
childProcess.stdout!.on('data', (chunk) => stdoutBuffer.push(chunk));
childProcess.on('close', (exitCode: number | null, signal: NodeJS.Signals | null) => {
if (exitCode) {
reject(new Error(`Exited with ${exitCode}`));
} else if (signal) {
reject(new Error(`Terminated by ${signal}`));
} else {
const version: string = stdoutBuffer.join('').trim();
terminal.writeLine(`Found version "${version}" for "${packageName}"`);
resolve(version);
}
});
const childProcess: ChildProcess = Executable.spawn('npm', npmArgs, {
stdio: ['ignore', 'pipe', 'pipe']
});
const { stdout: version } = await Executable.waitForExitAsync(childProcess, {
encoding: 'utf-8',
throwOnNonZeroExitCode: true,
throwOnSignal: true
});
terminal.writeLine(`Found version "${version}" for "${packageName}"`);
return version;
}

interface IProjectLike {
Expand All @@ -38,6 +39,7 @@ interface IProjectLike {
}

export class BumpDecoupledLocalDependencies extends CommandLineAction {
readonly #feedUrlParameter: CommandLineStringParameter;
readonly #terminal: ITerminal;

public constructor(terminal: ITerminal) {
Expand All @@ -48,10 +50,17 @@ export class BumpDecoupledLocalDependencies extends CommandLineAction {
});

this.#terminal = terminal;

this.#feedUrlParameter = this.defineStringParameter({
parameterLongName: '--feed-url',
description: 'The package feed URL to query for the latest published versions.',
argumentName: 'FEED_URL'
});
}

protected override async onExecuteAsync(): Promise<void> {
const terminal: ITerminal = this.#terminal;
const feedUrl: string | undefined = this.#feedUrlParameter.value;
const rushConfiguration: RushConfiguration = RushConfiguration.loadFromDefaultLocation({
startingFolder: process.cwd()
});
Expand Down Expand Up @@ -125,7 +134,11 @@ export class BumpDecoupledLocalDependencies extends CommandLineAction {
await Async.forEachAsync(
allDecoupledLocalDependencyNames,
async (decoupledLocalDependencyName) => {
const version: string = await _getLatestPublishedVersionAsync(terminal, decoupledLocalDependencyName);
const version: string = await _getLatestPublishedVersionAsync(
terminal,
decoupledLocalDependencyName,
feedUrl
);
decoupledLocalDependencyVersionsByName.set(decoupledLocalDependencyName, version);
},
{
Expand Down Expand Up @@ -178,7 +191,11 @@ export class BumpDecoupledLocalDependencies extends CommandLineAction {
terminal.writeLine();

// Update the Rush version in rush.json
const latestRushVersion: string = await _getLatestPublishedVersionAsync(terminal, '@microsoft/rush');
const latestRushVersion: string = await _getLatestPublishedVersionAsync(
terminal,
'@microsoft/rush',
feedUrl
);
const rushJson: IRushConfigurationJson = await JsonFile.loadAsync(rushJsonFile);
const existingRushVersion: string = rushJson.rushVersion;
const rushWasUpdated: boolean = existingRushVersion !== latestRushVersion;
Expand Down