@@ -11,9 +11,7 @@ import {
1111import { Flags } from '@oclif/core'
1212import { globalFlags } from '@shopify/cli-kit/node/cli'
1313import { execCLI2 } from '@shopify/cli-kit/node/ruby'
14- import { AbortController } from '@shopify/cli-kit/node/abort'
15- import { AdminSession , ensureAuthenticatedStorefront , ensureAuthenticatedThemes } from '@shopify/cli-kit/node/session'
16- import { sleep } from '@shopify/cli-kit/node/system'
14+ import { ensureAuthenticatedStorefront , ensureAuthenticatedThemes } from '@shopify/cli-kit/node/session'
1715import { outputDebug } from '@shopify/cli-kit/node/output'
1816
1917export default class Dev extends ThemeCommand {
@@ -102,18 +100,18 @@ export default class Dev extends ThemeCommand {
102100 'notify' ,
103101 ]
104102
105- // Tokens are valid for 120m , better to be safe and refresh every 110min
103+ // Tokens are valid for 120 min , better to be safe and refresh every 110 min
106104 ThemeRefreshTimeoutInMs = 110 * 60 * 1000
107105
108106 /**
109107 * Executes the theme serve command.
110- * Every 110 minutes, it will refresh the session token and restart the server .
108+ * Every 110 minutes, it will refresh the session token.
111109 */
112110 async run ( ) : Promise < void > {
113111 showDeprecationWarnings ( this . argv )
114112 let { flags} = await this . parse ( Dev )
115113 const store = ensureThemeStore ( flags )
116- const adminSession = await ensureAuthenticatedThemes ( store , flags . password , [ ] , true )
114+ const adminSession = await refreshTokens ( store , flags . password )
117115
118116 if ( ! flags . theme ) {
119117 const theme = await new DevelopmentThemeManager ( adminSession ) . findOrCreate ( )
@@ -131,31 +129,20 @@ export default class Dev extends ThemeCommand {
131129 return
132130 }
133131
134- let controller = new AbortController ( )
132+ renderLinks ( store , flags . theme ! , flags . host , flags . port )
135133
136134 setInterval ( ( ) => {
137- outputDebug ( 'Refreshing theme session token and restarting theme server...' )
138- controller . abort ( )
139- controller = new AbortController ( )
135+ outputDebug ( 'Refreshing theme session tokens...' )
140136 // eslint-disable-next-line @typescript-eslint/no-floating-promises
141- this . execute ( adminSession , flags . password , command , controller , true )
137+ refreshTokens ( store , flags . password )
142138 } , this . ThemeRefreshTimeoutInMs )
143-
144- renderLinks ( store , flags . theme ! , flags . host , flags . port )
145-
146- // eslint-disable-next-line @typescript-eslint/no-floating-promises
147- this . execute ( adminSession , flags . password , command , controller , false )
139+ await execCLI2 ( command , { store, adminToken : adminSession . token } )
148140 }
141+ }
149142
150- async execute (
151- adminSession : AdminSession ,
152- password : string | undefined ,
153- command : string [ ] ,
154- controller : AbortController ,
155- shouldWait : boolean ,
156- ) {
157- if ( shouldWait ) await sleep ( 3 )
158- const storefrontToken = await ensureAuthenticatedStorefront ( [ ] , password )
159- return execCLI2 ( command , { adminSession, storefrontToken, signal : controller . signal } )
160- }
143+ async function refreshTokens ( store : string , password : string | undefined ) {
144+ const adminSession = await ensureAuthenticatedThemes ( store , password , [ ] , true )
145+ const storefrontToken = await ensureAuthenticatedStorefront ( [ ] , password )
146+ await execCLI2 ( [ 'theme' , 'token' , '--admin' , adminSession . token , '--sfr' , storefrontToken ] )
147+ return adminSession
161148}
0 commit comments