Skip to content

Commit

Permalink
fix(sanity): guard against telemetry not provided from older global C…
Browse files Browse the repository at this point in the history
…LI versions (#5420)

We recently added a `telemetry` instance to the context passed from the global cli to project cli commands. However, if the global CLI is on an older version than the one installed locally, the local command implementation will be provided a context from an old version of the CLI which does not have context, which again will crash the CLI. This patch fixes the issue, by falling back to a noop telemetry instance, if it's not provided.
  • Loading branch information
bjoerge authored Dec 21, 2023
1 parent 2cedcaf commit 7e435e4
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/@sanity/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
},
"dependencies": {
"@babel/traverse": "^7.23.5",
"@sanity/telemetry": "^0.7.3",
"@sanity/telemetry": "^0.7.5",
"chalk": "^4.1.2",
"esbuild": "^0.19.8",
"esbuild-register": "^3.4.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/sanity/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@
"@sanity/portable-text-editor": "3.23.1",
"@sanity/presentation": "1.4.0",
"@sanity/schema": "3.23.1",
"@sanity/telemetry": "^0.7.3",
"@sanity/telemetry": "^0.7.5",
"@sanity/types": "3.23.1",
"@sanity/ui": "2.0.0-beta.13",
"@sanity/util": "3.23.1",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import path from 'path'
import {promisify} from 'util'
import chalk from 'chalk'
import {noopLogger} from '@sanity/telemetry'
import rimrafCallback from 'rimraf'
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore This may not yet be built.
Expand All @@ -27,7 +28,7 @@ export default async function buildSanityStudio(
overrides?: {basePath?: string},
): Promise<{didCompile: boolean}> {
const timer = getTimer()
const {output, prompt, workDir, cliConfig, telemetry} = context
const {output, prompt, workDir, cliConfig, telemetry = noopLogger} = context
const flags: BuildSanityStudioCommandFlags = {
minify: true,
stats: false,
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3778,10 +3778,10 @@
dependencies:
"@sanity/uuid" "3.0.2"

"@sanity/telemetry@^0.7.3":
version "0.7.3"
resolved "https://registry.yarnpkg.com/@sanity/telemetry/-/telemetry-0.7.3.tgz#05715dbf3cd7313b6eeeba23faa2bba8b5c8c381"
integrity sha512-gzHQJPQ9PjKOS/T/SLqrbSgTGwb2ZTrbBZBH0Yx25P5cP2C9kBGCoHRIJvQU0axBFSBRajVQDKtIUSrZ59XBSw==
"@sanity/telemetry@^0.7.5":
version "0.7.5"
resolved "https://registry.yarnpkg.com/@sanity/telemetry/-/telemetry-0.7.5.tgz#e9c39d35a55892ec230654f33d008f75aa2a398a"
integrity sha512-lY1Lmt2zl9YIIXO2bAFGXR542ovpn8jmLmIos1mQU4D+ItbZsPBxt9g72bJCsUZ7yodMf2K4t4Tp7BTv0as9sg==
dependencies:
lodash "^4.17.21"
react "^18.2.0"
Expand Down

2 comments on commit 7e435e4

@vercel
Copy link

@vercel vercel bot commented on 7e435e4 Dec 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

performance-studio – ./

performance-studio.sanity.build
performance-studio-git-next.sanity.build

@vercel
Copy link

@vercel vercel bot commented on 7e435e4 Dec 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

test-studio – ./

test-studio.sanity.build
test-studio-git-next.sanity.build

Please sign in to comment.