Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pnpm-sync-lib] Improve approach to console logging #14

Closed
octogonz opened this issue Feb 27, 2024 · 1 comment
Closed

[pnpm-sync-lib] Improve approach to console logging #14

octogonz opened this issue Feb 27, 2024 · 1 comment

Comments

@octogonz
Copy link
Member

From https://github.com/microsoft/rushstack/pull/4530/files#r1504932679:

image

  1. Also I would suggest to improve the formatting of the message:

    pnpm-sync: Copied 107 files in 95ms from C:\Git\rushstack\libraries\terminal
    
  2. It seems pnpmSyncCopy() is printing this message directly to the console. We should improve the API to provide a messaging callback that allows the output to be redirected and (ideally) optionally reformatted. Something like this:

    pnpmSyncCopy({
      pnpmSyncJsonPath,
      messageCallback: ({ message, messageKind: 'error'|'warning'|'info'|'verbose'|'timing', messageId, details }) => {
        if (messageKind === 'verbose' && !debug) {
          return;
        }
        switch (messageId) {
          case 'sync-finished':
            // customized logging; the structure of details can depend on messageId
            terminal.writeLine(colors.green('pnpm-sync') 
              + ` copied ${details.fileCount} files in ${details.totalMs} ms from ${details.sourcePath}`);
            break;
          default:
            // simple preformatted logging
            if (messageKind === 'error' | messageKind === 'warning') {
              console.error(message);
            } else {
              console.log(message);
            }
            break;
        }
      }
    })

    This would ensure that Rush (and in the future PNPM) has full ownership of its CLI UX.

@octogonz
Copy link
Member Author

octogonz commented Feb 27, 2024

This message can also be improved:

Generate pnpm-sync.json ...
The pnpm-lock.yaml file path => C:\Git\rushstack\common\temp\pnpm-lock.yaml
The .pnpm folder path => C:\Git\rushstack\common\temp\node_modules\.pnpm
pnpm-sync prepare: 51.144ms

Maybe something like this:

For a normal and --verbose build:

Regenerated pnpm-sync.json in 51ms.

For a --debug build:

pnpm-sync-prepare: Starting operation...
pnpm-sync-prepare: lockfile path is C:\Git\rushstack\common\temp\pnpm-lock.yaml
pnpm-sync-prepare: .pnpm path is C:\Git\rushstack\common\temp\node_modules\.pnpm
Regenerated pnpm-sync.json in 51ms.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants