Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable password flag for theme dev #953

Merged
merged 6 commits into from
Dec 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/old-chefs-smash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/cli-kit': minor
---

Upgrade CLI 2.0 and theme-check dependencies
7 changes: 7 additions & 0 deletions .changeset/serious-cherries-cheer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@shopify/cli': minor
'@shopify/theme': minor
'@shopify/cli-kit': patch
---

Enable password flag for theme dev
2 changes: 1 addition & 1 deletion packages/cli-kit/src/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ export function getOutputUpdateCLIReminder(
const versionMessage = `💡 Version ${version} available!`
if (!packageManager || packageManager === 'unknown') return versionMessage

const updateCommand = token.packagejsonScript(packageManager, 'shopify', 'upgrade')
const updateCommand = token.packagejsonScript(packageManager, 'shopify upgrade')
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was showing something like Run npm run shopify -- upgrade for npm.

Copy link
Contributor

Choose a reason for hiding this comment

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

If I'm not wrong I think that's necessary with npm because otherwise it treats those flags and arguments as npm's

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure what you mean. In this case, upgrade is not a flag, but part of the command, so we don't need the -- separator. The third argument is used for flags, which do need the separator for npm.

We are doing the same in other places: https://github.com/Shopify/cli/blob/upgrade-cli2/packages/cli-hydrogen/src/cli/services/preview.ts#L23

return content`${versionMessage} Run ${updateCommand}`.value
}

Expand Down
4 changes: 2 additions & 2 deletions packages/cli-kit/src/public/node/ruby.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import {platformAndArch} from '../../os.js'
import {AbortSignal} from 'abort-controller'
import {Writable} from 'node:stream'

const RubyCLIVersion = '2.32.0'
const ThemeCheckVersion = '1.10.3'
const RubyCLIVersion = '2.33.0'
const ThemeCheckVersion = '1.12.1'
const MinBundlerVersion = '2.3.8'
const MinRubyVersion = '2.7.5'

Expand Down
8 changes: 8 additions & 0 deletions packages/cli-kit/src/session.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,14 @@ describe('ensureAuthenticatedStorefront', () => {
expect(got).toEqual('storefront_token')
})

it('returns the password if provided', async () => {
// Given/When
const got = await ensureAuthenticatedStorefront([], 'theme_access_password')

// Then
expect(got).toEqual('theme_access_password')
})

it('throws error if there is no storefront token', async () => {
// Given
vi.mocked(validateSession).mockResolvedValueOnce('ok')
Expand Down
7 changes: 6 additions & 1 deletion packages/cli-kit/src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,12 @@ ${token.json(scopes)}
* @param scopes - Optional array of extra scopes to authenticate with.
* @returns The access token for the Storefront API.
*/
export async function ensureAuthenticatedStorefront(scopes: string[] = []): Promise<string> {
export async function ensureAuthenticatedStorefront(
scopes: string[] = [],
password: string | undefined = undefined,
): Promise<string> {
if (password) return password

debug(content`Ensuring that the user is authenticated with the Storefront API with the following scopes:
${token.json(scopes)}
`)
Expand Down
7 changes: 0 additions & 7 deletions packages/cli-main/src/index.test.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/theme/oclif.manifest.json

Large diffs are not rendered by default.

11 changes: 6 additions & 5 deletions packages/theme/src/cli/commands/theme/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export default class Dev extends ThemeCommand {
description: 'Proceed without confirmation, if current directory does not seem to be theme directory.',
env: 'SHOPIFY_FLAG_FORCE',
}),
password: themeFlags.password,
}

static cli2Flags = [
Expand Down Expand Up @@ -108,18 +109,18 @@ export default class Dev extends ThemeCommand {
controller.abort()
controller = new abort.Controller()
// eslint-disable-next-line @typescript-eslint/no-floating-promises
this.execute(store, command, controller)
this.execute(store, flags.password, command, controller)
}, this.ThemeRefreshTimeoutInMs)

// eslint-disable-next-line @typescript-eslint/no-floating-promises
this.execute(store, command, controller)
this.execute(store, flags.password, command, controller)
await system.sleep(this.HardTimeoutInSeconds)
clearInterval(refreshThemeSessionInterval)
}

async execute(store: string, command: string[], controller: abort.Controller) {
const adminSession = await session.ensureAuthenticatedThemes(store, undefined, [], true)
const storefrontToken = await session.ensureAuthenticatedStorefront()
async execute(store: string, password: string | undefined, command: string[], controller: abort.Controller) {
const adminSession = await session.ensureAuthenticatedThemes(store, password, [], true)
const storefrontToken = await session.ensureAuthenticatedStorefront([], password)
return execCLI2(command, {adminSession, storefrontToken, signal: controller.signal})
}
}