15815213711
2024-08-26 67b8b6731811983447e053d4396b3708c14dfe3c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import isNpmOrYarn from './isNpmOrYarn';
import hasNewVersion from './hasNewVersion';
import { IUpdate } from './types';
import borderedText from './borderedText';
 
const simpleUpdateNotifier = async (args: IUpdate) => {
  if (
    !args.alwaysRun &&
    (!process.stdout.isTTY || (isNpmOrYarn && !args.shouldNotifyInNpmScript))
  ) {
    if (args.debug) {
      console.error('Opting out of running simpleUpdateNotifier()');
    }
    return;
  }
 
  try {
    const latestVersion = await hasNewVersion(args);
    if (latestVersion) {
      console.error(
        borderedText(`New version of ${args.pkg.name} available!
Current Version: ${args.pkg.version}
Latest Version: ${latestVersion}`)
      );
    }
  } catch (err) {
    // Catch any network errors or cache writing errors so module doesn't cause a crash
    if (args.debug && err instanceof Error) {
      console.error('Unexpected error in simpleUpdateNotifier():', err);
    }
  }
};
 
export default simpleUpdateNotifier;