Upgrade reminders
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?
- Checks for a current CLI version once daily in the background of a running command, caching the result
- 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?
- Use the CLI normally a few times. Nothing should happen.
- Then, change this line to have a lower cli-kit version.
- On the next command, nothing should happen (though if it's a really fast command it might hang for a second at the end).
- On the command after that, you should see a warning right away that you need to upgrade to the latest version.
- OPTIONAL: Clear the cache by opening
~/Library/Preferences/shopify-cli-kit-nodejs/config.json, looking for thecachesection, 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
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.
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
Looks good to me on the UX side. Thanks Ariel!
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
mainyou might see odd diffs, rebasemaininto 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