Skip to content

Commit

Permalink
feat: use pnpm-sync-lib log callback
Browse files Browse the repository at this point in the history
  • Loading branch information
g-chao committed Mar 21, 2024
1 parent 2b2ebf9 commit 28b521d
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 14 deletions.
10 changes: 5 additions & 5 deletions common/config/rush/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion common/config/rush/repo-state.json
@@ -1,5 +1,5 @@
// DO NOT MODIFY THIS FILE MANUALLY BUT DO COMMIT IT. It is generated and used by Rush.
{
"pnpmShrinkwrapHash": "1da0835844b2dddb8f340063ceb13ccf02a65dea",
"pnpmShrinkwrapHash": "ad10d70df4b7a0566f8b4275f15a636958303afb",
"preferredVersionsHash": "c3ce06bc821dea3e1fe5dbc73da35b305908795a"
}
2 changes: 1 addition & 1 deletion libraries/rush-lib/package.json
Expand Up @@ -57,7 +57,7 @@
"tar": "~6.1.11",
"true-case-path": "~2.2.1",
"uuid": "~8.3.2",
"pnpm-sync-lib": "0.1.4"
"pnpm-sync-lib": "0.1.6"
},
"devDependencies": {
"@pnpm/logger": "4.0.0",
Expand Down
27 changes: 25 additions & 2 deletions libraries/rush-lib/src/cli/RushXCommandLine.ts
Expand Up @@ -4,7 +4,7 @@
import * as path from 'path';
import { PackageJsonLookup, type IPackageJson, Text, FileSystem, Async } from '@rushstack/node-core-library';
import { Colorize, DEFAULT_CONSOLE_WIDTH, PrintUtilities } from '@rushstack/terminal';
import { pnpmSyncCopyAsync } from 'pnpm-sync-lib';
import { type ILogMessageCallbackOptions, pnpmSyncCopyAsync } from 'pnpm-sync-lib';

import { Utilities } from '../utilities/Utilities';
import { ProjectCommandSet } from '../logic/ProjectCommandSet';
Expand Down Expand Up @@ -223,7 +223,30 @@ export class RushXCommandLine {
pnpmSyncJsonPath,
ensureFolder: FileSystem.ensureFolderAsync,
forEachAsyncWithConcurrency: Async.forEachAsync,
getPackageIncludedFiles: PackageExtractor.getPackageIncludedFilesAsync
getPackageIncludedFiles: PackageExtractor.getPackageIncludedFilesAsync,
logMessageCallback: (logMessageOptions: ILogMessageCallbackOptions) => {
const { message, messageKind } = logMessageOptions;
switch (messageKind) {
case 'error':
// eslint-disable-next-line no-console
console.error(Colorize.red(message));
break;
case 'warning':
// eslint-disable-next-line no-console
console.error(Colorize.yellow(message));
break;
case 'verbose':
if (rushxArguments.isDebug) {
// eslint-disable-next-line no-console
console.error(message);
}
break;
default:
// eslint-disable-next-line no-console
console.log(message);
break;
}
}
});
}
}
Expand Down
Expand Up @@ -407,10 +407,11 @@ export class PhasedScriptAction extends BaseScriptAction<IPhasedCommandConfig> {
this.rushConfiguration?.packageManager === 'pnpm' &&
experiments?.usePnpmSyncForInjectedDependencies
) {
const isVerbose: boolean = !this._verboseParameter.value || this.parser.isDebug;
const { PnpmSyncCopyOperationPlugin } = await import(
'../../logic/operations/PnpmSyncCopyOperationPlugin'
);
new PnpmSyncCopyOperationPlugin().apply(this.hooks);
new PnpmSyncCopyOperationPlugin(terminal, isVerbose).apply(this.hooks);
}

const projectConfigurations: ReadonlyMap<RushConfigurationProject, RushProjectConfiguration> = this
Expand Down
Expand Up @@ -37,7 +37,7 @@ import { BaseProjectShrinkwrapFile } from '../base/BaseProjectShrinkwrapFile';
import { type CustomTipId, type ICustomTipInfo, PNPM_CUSTOM_TIPS } from '../../api/CustomTipsConfiguration';
import { PnpmShrinkwrapFile } from '../pnpm/PnpmShrinkwrapFile';
import { objectsAreDeepEqual } from '../../utilities/objectUtilities';
import { type ILockfile, pnpmSyncPrepareAsync } from 'pnpm-sync-lib';
import { type ILockfile, pnpmSyncPrepareAsync, type ILogMessageCallbackOptions } from 'pnpm-sync-lib';
import type { Subspace } from '../../api/Subspace';
import { Colorize, ConsoleTerminalProvider } from '@rushstack/terminal';
import { BaseLinkManager, SymlinkKind } from '../base/BaseLinkManager';
Expand Down Expand Up @@ -513,7 +513,8 @@ export class WorkspaceInstallManager extends BaseInstallManager {
// the pnpm-sync will generate the pnpm-sync.json based on lockfile
if (this.rushConfiguration.packageManager === 'pnpm' && experiments?.usePnpmSyncForInjectedDependencies) {
const pnpmLockfilePath: string = subspace.getTempShrinkwrapFilename();
const pnpmStorePath: string = `${this.rushConfiguration.commonTempFolder}/node_modules/.pnpm`;
const pnpmStorePath: string = `${subspace.getSubspaceTempFolder()}/node_modules/.pnpm`;
debugger;
await pnpmSyncPrepareAsync({
lockfilePath: pnpmLockfilePath,
storePath: pnpmStorePath,
Expand All @@ -527,10 +528,31 @@ export class WorkspaceInstallManager extends BaseInstallManager {
return undefined;
} else {
const result: ILockfile = {
lockfileVersion: wantedPnpmLockfile.shrinkwrapFileMajorVersion,
importers: Object.fromEntries(wantedPnpmLockfile.importers.entries())
};
return result;
}
},
logMessageCallback: (logMessageOptions: ILogMessageCallbackOptions) => {
const { message, messageKind } = logMessageOptions;
switch (messageKind) {
case 'error':
this._terminal.writeErrorLine(message);
break;
case 'warning':
this._terminal.writeWarningLine(message);
break;
case 'verbose':
if (this.options.debug) {
this._terminal.writeLine(message);
}
break;
default:
this._terminal.writeLine();
this._terminal.writeLine(message);
break;
}
}
});
}
Expand Down
Expand Up @@ -2,16 +2,24 @@
// See LICENSE in the project root for license information.

import { Async, FileSystem } from '@rushstack/node-core-library';
import { pnpmSyncCopyAsync } from 'pnpm-sync-lib';
import { type ILogMessageCallbackOptions, pnpmSyncCopyAsync } from 'pnpm-sync-lib';

import { OperationStatus } from './OperationStatus';
import type { IOperationRunnerContext } from './IOperationRunner';
import type { IPhasedCommandPlugin, PhasedCommandHooks } from '../../pluginFramework/PhasedCommandHooks';
import type { OperationExecutionRecord } from './OperationExecutionRecord';
import type { ITerminal } from '@rushstack/terminal';

const PLUGIN_NAME: 'PnpmSyncCopyOperationPlugin' = 'PnpmSyncCopyOperationPlugin';

export class PnpmSyncCopyOperationPlugin implements IPhasedCommandPlugin {
private readonly _terminal: ITerminal;
private readonly _isVerbose: boolean;

public constructor(terminal: ITerminal, isVerbose: boolean) {
this._terminal = terminal;
this._isVerbose = isVerbose;
}
public apply(hooks: PhasedCommandHooks): void {
hooks.afterExecuteOperation.tapPromise(
PLUGIN_NAME,
Expand Down Expand Up @@ -42,7 +50,26 @@ export class PnpmSyncCopyOperationPlugin implements IPhasedCommandPlugin {
pnpmSyncJsonPath,
ensureFolder: FileSystem.ensureFolderAsync,
forEachAsyncWithConcurrency: Async.forEachAsync,
getPackageIncludedFiles: PackageExtractor.getPackageIncludedFilesAsync
getPackageIncludedFiles: PackageExtractor.getPackageIncludedFilesAsync,
logMessageCallback: (logMessageOptions: ILogMessageCallbackOptions) => {
const { message, messageKind } = logMessageOptions;
switch (messageKind) {
case 'error':
this._terminal.writeErrorLine(message);
break;
case 'warning':
this._terminal.writeWarningLine(message);
break;
case 'verbose':
if (this._isVerbose) {
this._terminal.writeVerboseLine(message);
}
break;
default:
this._terminal.writeLine(message);
break;
}
}
});
}
}
Expand Down

0 comments on commit 28b521d

Please sign in to comment.