cli icon indicating copy to clipboard operation
cli copied to clipboard

Upgrade reminders

Open amcaplan opened this issue 1 year ago β€’ 4 comments

WHY are these changes introduced?

To encourage faster CLI upgrades and reduce the number of support cases where users are using old CLI versions.

WHAT is this pull request doing?

  1. Checks for a current CLI version once daily in the background of a running command, caching the result
  2. When a cached updated CLI version is found, warns the user to upgrade on each command run

Since this system exists, we can remove the check + warning to upgrade from the version and app info commands.

How to test your changes?

  1. Use the CLI normally a few times. Nothing should happen.
  2. Then, change this line to have a lower cli-kit version.
  3. On the next command, nothing should happen (though if it's a really fast command it might hang for a second at the end).
  4. On the command after that, you should see a warning right away that you need to upgrade to the latest version.
  5. OPTIONAL: Clear the cache by opening ~/Library/Preferences/shopify-cli-kit-nodejs/config.json, looking for the cache section, and deleting the "npm-package-@shopify/cli" value. When you run the CLI again, the warning disappears for the first run (the run which populates the cache). In the next run, you'll see the warning again.

Measuring impact

How do we know this change was effective? Please choose one:

  • [ ] n/a - this doesn't need measurement, e.g. a linting rule or a bug-fix
  • [x] Existing analytics will cater for this addition
  • [ ] PR includes analytics changes to measure impact

Checklist

  • [x] I've considered possible cross-platform impacts (Mac, Linux, Windows)
  • [x] I've considered possible documentation changes

amcaplan avatar Aug 11 '24 21:08 amcaplan

We detected some changes at either packages/*/src or packages/cli-kit/assets/cli-ruby/** and there are no updates in the .changeset. If the changes are user-facing, run "pnpm changeset add" to track your changes and include them in the next release CHANGELOG.

github-actions[bot] avatar Aug 11 '24 21:08 github-actions[bot]

Coverage report

St.:grey_question:
Category Percentage Covered / Total
🟑 Statements
73.24% (+0.22% πŸ”Ό)
8138/11112
🟑 Branches
69.68% (+0.38% πŸ”Ό)
3976/5706
🟑 Functions
71.91% (+0.22% πŸ”Ό)
2127/2958
🟑 Lines
73.55% (+0.2% πŸ”Ό)
7695/10462
Show new covered files 🐣
St.:grey_question:
File Statements Branches Functions Lines
🟒
... / host-theme-manager.ts
100% 66.67% 100% 100%
🟒
... / host-theme-watcher.ts
100% 85.71% 100% 100%
🟒
... / upgrade.ts
100% 100% 100% 100%
Show files with reduced coverage πŸ”»
St.:grey_question:
File Statements Branches Functions Lines
🟒
... / app_config_privacy_compliance_webhooks.ts
100%
93.94% (-0.35% πŸ”»)
100% 100%
🟒
... / info.ts
90.18% (-0.58% πŸ”»)
75% (-0.86% πŸ”»)
93.33% (-0.22% πŸ”»)
92.23% (-0.49% πŸ”»)
🟒
... / logs.ts
100%
83.33% (-6.67% πŸ”»)
100% 100%
🟒
... / string.ts
83.93% (-0.82% πŸ”»)
79.17%
72.73% (-1.19% πŸ”»)
85.42% (-0.86% πŸ”»)
🟑
... / prerun.ts
78.13% (+0.85% πŸ”Ό)
92.86% (-7.14% πŸ”»)
90% (+2.5% πŸ”Ό)
77.42% (+1.23% πŸ”Ό)

Test suite run success

1847 tests passing in 839 suites.

Report generated by πŸ§ͺjest coverage report action from 05cbe6356605c77d87aeba565efb985a4ee0c311

github-actions[bot] avatar Aug 12 '24 11:08 github-actions[bot]

Looks good to me on the UX side. Thanks Ariel!

jessehoek avatar Aug 15 '24 14:08 jessehoek

Differences in type declarations

We detected differences in the type declarations generated by Typescript for this branch compared to the baseline ('main' branch). Please, review them to ensure they are backward-compatible. Here are some important things to keep in mind:

  • Some seemingly private modules might be re-exported through public modules.
  • If the branch is behind main you might see odd diffs, rebase main into this branch.

New type declarations

packages/cli-kit/dist/public/node/upgrade.d.ts
/**
 * Utility function for generating an install command for the user to run
 * to install an updated version of Shopify CLI.
 *
 * @returns A string with the command to run.
 */
export declare function cliInstallCommand(): string;
/**
 * Generates a message to remind the user to update the CLI.
 *
 * @param version - The version to update to.
 * @returns The message to remind the user to update the CLI.
 */
export declare function getOutputUpdateCLIReminder(version: string): string;

Existing type declarations

packages/cli-kit/dist/private/node/conf-store.d.ts
@@ -5,9 +5,12 @@ interface CacheValue<T> {
 }
 export type IntrospectionUrlKey = ;
 export type PackageVersionKey = ;
+type MostRecentOccurrenceKey = ;
+type ExportedKey = IntrospectionUrlKey | PackageVersionKey;
 interface Cache {
     [introspectionUrlKey: IntrospectionUrlKey]: CacheValue<string>;
     [packageVersionKey: PackageVersionKey]: CacheValue<string>;
+    [MostRecentOccurrenceKey: MostRecentOccurrenceKey]: CacheValue<boolean>;
 }
 export interface ConfSchema {
     sessionStore: string;
@@ -39,5 +42,28 @@ type CacheValueForKey<TKey extends keyof Cache> = NonNullable<Cache[TKey]>['valu
  * If the cached value is older than this, it will be refreshed.
  * @returns The value from the cache or the result of the function.
  */
-export declare function cacheRetrieveOrRepopulate(key: keyof Cache, fn: () => Promise<CacheValueForKey<typeof key>>, timeout?: number, config?: LocalStorage<ConfSchema>): Promise<CacheValueForKey<typeof key>>;
+export declare function cacheRetrieveOrRepopulate(key: ExportedKey, fn: () => Promise<CacheValueForKey<typeof key>>, timeout?: number, config?: LocalStorage<ConfSchema>): Promise<CacheValueForKey<typeof key>>;
+/**
+ * Fetch from cache if already populated, otherwise return undefined.
+ * @param key - The key to use for the cache.
+ * @returns The value from the cache or the result of the function.
+ */
+export declare function cacheRetrieve(key: ExportedKey, config?: LocalStorage<ConfSchema>): CacheValueForKey<typeof key> | undefined;
+export declare function cacheClear(config?: LocalStorage<ConfSchema>): void;
+interface TimeInterval {
+    days?: number;
+    hours?: number;
+    minutes?: number;
+    seconds?: number;
+}
+/**
+ * Execute a task only if the most recent occurrence of the task is older than the specified timeout.
+ * @param key - The key to use for the cache.
+ * @param timeout - The maximum valid age of the most recent occurrence, expressed as an object with
+ * days, hours, minutes, and seconds properties.
+ * If the most recent occurrence is older than this, the task will be executed.
+ * @param task - The task to run if the most recent occurrence is older than the timeout.
+ * @returns The result of the task, or undefined if the task was not run.
+ */
+export declare function runAtMinimumInterval(key: string, timeout: TimeInterval, task: () => Promise<void>, config?: LocalStorage<ConfSchema>): Promise<boolean | undefined>;
 export {};
\ No newline at end of file

packages/cli-kit/dist/public/node/node-package-manager.d.ts
@@ -126,13 +126,20 @@ export declare function usesWorkspaces(appDirectory: string): Promise<boolean>;
  * Given an NPM dependency, it checks if there's a more recent version, and if there is, it returns its value.
  * @param dependency - The dependency name (e.g. react)
  * @param currentVersion - The current version.
- * @param refreshIfOlderThanSeconds - If the last check was done more than this amount of seconds ago, it will
+ * @param cacheExpiryInHours - If the last check was done more than this amount of hours ago, it will
  * refresh the cache. Defaults to always refreshing.
  * @returns A promise that resolves with a more recent version or undefined if there's no more recent version.
  */
 export declare function checkForNewVersion(dependency: string, currentVersion: string, { cacheExpiryInHours }?: {
     cacheExpiryInHours?: number | undefined;
 }): Promise<string | undefined>;
+/**
+ * Given an NPM dependency, it checks if there's a cached more recent version, and if there is, it returns its value.
+ * @param dependency - The dependency name (e.g. react)
+ * @param currentVersion - The current version.
+ * @returns A more recent version or undefined if there's no more recent version.
+ */
+export declare function checkForCachedNewVersion(dependency: string, currentVersion: string): string | undefined;
 /**
  * Utility function used to check whether a package version satisfies some requirements
  * @param version - The version to check

packages/cli-kit/dist/public/node/output.d.ts
@@ -184,14 +184,6 @@ export declare function unstyled(message: string): string;
  * @returns True if the console outputs should display colors, false otherwise.
  */
 export declare function shouldDisplayColors(_process?: NodeJS.Process): boolean;
-/**
- * Generates a message to remind the user to update the CLI.
- *
- * @param packageManager - The package manager that is being used.
- * @param version - The version to update to.
- * @returns The message to remind the user to update the CLI.
- */
-export declare function getOutputUpdateCLIReminder(packageManager: PackageManager | undefined, version: string): string;
 /**
  * Parse title and body to be a single formatted string.
  *

packages/cli-kit/dist/public/node/hooks/prerun.d.ts
@@ -9,4 +9,8 @@ export declare function parseCommandContent(cmdInfo: {
     id: string;
     aliases: string[];
     pluginAlias?: string;
-}): CommandContent;
\ No newline at end of file
+}): CommandContent;
+/**
+ * Warns the user if there is a new version of the CLI available
+ */
+export declare function warnOnAvailableUpgrade(): Promise<void>;
\ No newline at end of file

github-actions[bot] avatar Aug 19 '24 13:08 github-actions[bot]