-
Notifications
You must be signed in to change notification settings - Fork 438
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): respect
--no-auto-updates flag
in CLI config (#7396)
* feat: respect no-auto-updates flag in cli config * test: add unit tests
- Loading branch information
1 parent
f53cd0e
commit c83021e
Showing
4 changed files
with
72 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
packages/sanity/src/_internal/cli/util/__tests__/shouldAutoUpdate.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import {describe, expect, it} from '@jest/globals' | ||
import {type CliConfig} from '@sanity/cli' | ||
|
||
import {type BuildSanityStudioCommandFlags} from '../../actions/build/buildAction' | ||
import {shouldAutoUpdate} from '../shouldAutoUpdate' | ||
|
||
describe('shouldAutoUpdate', () => { | ||
it('should return true when flags["auto-updates"] is true', () => { | ||
const flags: BuildSanityStudioCommandFlags = {'auto-updates': true} | ||
expect(shouldAutoUpdate({flags})).toBe(true) | ||
}) | ||
|
||
it('should return false when flags["auto-updates"] is false', () => { | ||
const flags: BuildSanityStudioCommandFlags = {'auto-updates': false} | ||
expect(shouldAutoUpdate({flags})).toBe(false) | ||
}) | ||
|
||
it('should return true when cliConfig.autoUpdates is true and flags["auto-updates"] is not set', () => { | ||
const flags: BuildSanityStudioCommandFlags = {} | ||
const cliConfig: CliConfig = {autoUpdates: true} | ||
expect(shouldAutoUpdate({flags, cliConfig})).toBe(true) | ||
}) | ||
|
||
it('should return false when cliConfig.autoUpdates is false and flags["auto-updates"] is not set', () => { | ||
const flags: BuildSanityStudioCommandFlags = {} | ||
const cliConfig: CliConfig = {autoUpdates: false} | ||
expect(shouldAutoUpdate({flags, cliConfig})).toBe(false) | ||
}) | ||
|
||
it('should return false when both flags["auto-updates"] and cliConfig.autoUpdates are not set', () => { | ||
const flags: BuildSanityStudioCommandFlags = {} | ||
expect(shouldAutoUpdate({flags})).toBe(false) | ||
}) | ||
|
||
it('should prioritize flags over cliConfig when both are set', () => { | ||
const flags: BuildSanityStudioCommandFlags = {'auto-updates': false} | ||
const cliConfig: CliConfig = {autoUpdates: true} | ||
expect(shouldAutoUpdate({flags, cliConfig})).toBe(false) | ||
}) | ||
}) |
27 changes: 27 additions & 0 deletions
27
packages/sanity/src/_internal/cli/util/shouldAutoUpdate.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import {type CliConfig} from '@sanity/cli' | ||
|
||
import {type BuildSanityStudioCommandFlags} from '../actions/build/buildAction' | ||
|
||
interface AutoUpdateSources { | ||
flags: BuildSanityStudioCommandFlags | ||
cliConfig?: CliConfig | ||
} | ||
|
||
/** | ||
* Compares parameters from various sources to determine whether or not to auto-update | ||
* @param sources - The sources of the auto-update parameter, including CLI flags and the CLI config | ||
* @returns boolean | ||
* @internal | ||
*/ | ||
export function shouldAutoUpdate({flags, cliConfig}: AutoUpdateSources): boolean { | ||
// cli flags (for example, '--no-auto-updates') should take precedence | ||
if ('auto-updates' in flags) { | ||
return Boolean(flags['auto-updates']) | ||
} | ||
|
||
if (cliConfig && 'autoUpdates' in cliConfig) { | ||
return Boolean(cliConfig.autoUpdates) | ||
} | ||
|
||
return false | ||
} |