From 24cbe846893427c5b4985733e5888e1aa5f30c69 Mon Sep 17 00:00:00 2001 From: Daniel Jung Date: Tue, 30 May 2023 20:42:58 +0200 Subject: [PATCH] fix: use update-notifier lib with dynamic import --- src/cli/index.ts | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/src/cli/index.ts b/src/cli/index.ts index a52c6061..6ffe21f5 100755 --- a/src/cli/index.ts +++ b/src/cli/index.ts @@ -1,5 +1,4 @@ import { program } from 'commander'; -import updateNotifier from 'update-notifier'; import chalk from 'chalk'; program @@ -22,22 +21,24 @@ program.description('Start Jest Preview server.').action(() => { program.parse(process.argv); -// Checks for available update and notify user -const notifier = updateNotifier({ - // Built output is at /cli so the relative path is ../package.json - pkg: require('../../package.json'), - updateCheckInterval: 0, // How often to check for updates - shouldNotifyInNpmScript: true, // Allows notification to be shown when running as an npm script - distTag: 'latest', // Can be use to notify user about pre-relase version -}); +import('update-notifier').then(({ default: updateNotifier }) => { + // Checks for available update and notify user + const notifier = updateNotifier({ + // Built output is at /cli so the relative path is ../package.json + pkg: require('../../package.json'), + updateCheckInterval: 0, // How often to check for updates + shouldNotifyInNpmScript: true, // Allows notification to be shown when running as an npm script + distTag: 'latest', // Can be use to notify user about pre-relase version + }); -notifier.notify({ - defer: true, // Try not to annoy user by showing the notification after the process has exited - message: [ - `${chalk.blue('{packageName}')} has an update available: ${chalk.gray( - '{currentVersion}', - )} → ${chalk.green('{latestVersion}')}`, - `Please run ${chalk.cyan('`{updateCommand}`')} to update.`, - ].join('\n'), + notifier.notify({ + defer: true, // Try not to annoy user by showing the notification after the process has exited + message: [ + `${chalk.blue('{packageName}')} has an update available: ${chalk.gray( + '{currentVersion}', + )} → ${chalk.green('{latestVersion}')}`, + `Please run ${chalk.cyan('`{updateCommand}`')} to update.`, + ].join('\n'), + }); + // END checks for available update and notify user }); -// END checks for available update and notify user