@@ -6,12 +6,6 @@ import * as fs from 'fs'
66import type { CLIContext , CLIProcess , ExecResult } from './cli.js'
77import type { BrowserContext } from './browser.js'
88
9- // Env override applied to all CLI helpers — strips CLIENT_ID so commands use the app's own toml.
10- // NOTE: Do NOT add SHOPIFY_CLI_PARTNERS_TOKEN here. The partners token overrides OAuth in the
11- // CLI's auth priority, and the App Management API token it exchanges to lacks permissions to
12- // create apps (403). OAuth provides the full set of required permissions.
13- const FRESH_APP_ENV = { SHOPIFY_FLAG_CLIENT_ID : undefined }
14-
159// ---------------------------------------------------------------------------
1610// CLI helpers — thin wrappers around cli.exec()
1711// ---------------------------------------------------------------------------
@@ -46,7 +40,7 @@ export async function createApp(ctx: {
4640
4741 const result = await cli . execCreateApp ( args , {
4842 // Strip CLIENT_ID so the CLI creates a new app instead of linking to a pre-existing one
49- env : { FORCE_COLOR : '0' , ... FRESH_APP_ENV } ,
43+ env : { FORCE_COLOR : '0' } ,
5044 timeout : 5 * 60 * 1000 ,
5145 } )
5246
@@ -81,6 +75,29 @@ export async function createApp(ctx: {
8175 return { ...result , appDir}
8276}
8377
78+ /**
79+ * Read the client_id from a shopify.app.toml file.
80+ */
81+ export function extractClientId ( appDir : string ) : string {
82+ const toml = fs . readFileSync ( path . join ( appDir , 'shopify.app.toml' ) , 'utf8' )
83+ const match = toml . match ( / c l i e n t _ i d \s * = \s * " ( [ ^ " ] + ) " / )
84+ if ( ! match ?. [ 1 ] ) {
85+ throw new Error ( `Could not find client_id in ${ path . join ( appDir , 'shopify.app.toml' ) } ` )
86+ }
87+ return match [ 1 ]
88+ }
89+
90+ /**
91+ * Overwrite a created app's shopify.app.toml with a fixture TOML template.
92+ * The template should contain `__CLIENT_ID__` and `__NAME__` placeholders which get
93+ * replaced with the app's real client_id and the provided name.
94+ */
95+ export function injectFixtureToml ( appDir : string , fixtureTomlContent : string , name : string ) : void {
96+ const clientId = extractClientId ( appDir )
97+ const toml = fixtureTomlContent . replace ( '__CLIENT_ID__' , clientId ) . replace ( '__NAME__' , name )
98+ fs . writeFileSync ( path . join ( appDir , 'shopify.app.toml' ) , toml )
99+ }
100+
84101export async function generateExtension (
85102 ctx : CLIContext & {
86103 name : string
@@ -90,11 +107,11 @@ export async function generateExtension(
90107) : Promise < ExecResult > {
91108 const args = [ 'app' , 'generate' , 'extension' , '--name' , ctx . name , '--path' , ctx . appDir , '--template' , ctx . template ]
92109 if ( ctx . flavor ) args . push ( '--flavor' , ctx . flavor )
93- return ctx . cli . exec ( args , { env : FRESH_APP_ENV , timeout : 5 * 60 * 1000 } )
110+ return ctx . cli . exec ( args , { timeout : 5 * 60 * 1000 } )
94111}
95112
96113export async function buildApp ( ctx : CLIContext ) : Promise < ExecResult > {
97- return ctx . cli . exec ( [ 'app' , 'build' , '--path' , ctx . appDir ] , { env : FRESH_APP_ENV , timeout : 5 * 60 * 1000 } )
114+ return ctx . cli . exec ( [ 'app' , 'build' , '--path' , ctx . appDir ] , { timeout : 5 * 60 * 1000 } )
98115}
99116
100117export async function deployApp (
@@ -112,7 +129,7 @@ export async function deployApp(
112129 if ( ctx . version ) args . push ( '--version' , ctx . version )
113130 if ( ctx . message ) args . push ( '--message' , ctx . message )
114131 if ( ctx . config ) args . push ( '--config' , ctx . config )
115- return ctx . cli . exec ( args , { env : FRESH_APP_ENV , timeout : 5 * 60 * 1000 } )
132+ return ctx . cli . exec ( args , { timeout : 5 * 60 * 1000 } )
116133}
117134
118135export async function appInfo ( ctx : CLIContext ) : Promise < {
@@ -124,15 +141,15 @@ export async function appInfo(ctx: CLIContext): Promise<{
124141 entrySourceFilePath : string
125142 } [ ]
126143} > {
127- const result = await ctx . cli . exec ( [ 'app' , 'info' , '--path' , ctx . appDir , '--json' ] , { env : FRESH_APP_ENV } )
144+ const result = await ctx . cli . exec ( [ 'app' , 'info' , '--path' , ctx . appDir , '--json' ] )
128145 if ( result . exitCode !== 0 ) {
129146 throw new Error ( `app info failed (exit ${ result . exitCode } ):\nstdout: ${ result . stdout } \nstderr: ${ result . stderr } ` )
130147 }
131148 return JSON . parse ( result . stdout )
132149}
133150
134151export async function functionBuild ( ctx : CLIContext ) : Promise < ExecResult > {
135- return ctx . cli . exec ( [ 'app' , 'function' , 'build' , '--path' , ctx . appDir ] , { env : FRESH_APP_ENV , timeout : 3 * 60 * 1000 } )
152+ return ctx . cli . exec ( [ 'app' , 'function' , 'build' , '--path' , ctx . appDir ] , { timeout : 3 * 60 * 1000 } )
136153}
137154
138155export async function functionRun (
@@ -141,14 +158,12 @@ export async function functionRun(
141158 } ,
142159) : Promise < ExecResult > {
143160 return ctx . cli . exec ( [ 'app' , 'function' , 'run' , '--path' , ctx . appDir , '--input' , ctx . inputPath ] , {
144- env : FRESH_APP_ENV ,
145161 timeout : 60 * 1000 ,
146162 } )
147163}
148164
149165export async function versionsList ( ctx : CLIContext ) : Promise < ExecResult > {
150166 return ctx . cli . exec ( [ 'app' , 'versions' , 'list' , '--path' , ctx . appDir , '--json' ] , {
151- env : FRESH_APP_ENV ,
152167 timeout : 60 * 1000 ,
153168 } )
154169}
@@ -159,7 +174,6 @@ export async function configLink(
159174 } ,
160175) : Promise < ExecResult > {
161176 return ctx . cli . exec ( [ 'app' , 'config' , 'link' , '--path' , ctx . appDir , '--client-id' , ctx . clientId ] , {
162- env : FRESH_APP_ENV ,
163177 timeout : 2 * 60 * 1000 ,
164178 } )
165179}
@@ -374,13 +388,9 @@ export async function cleanupApp(
374388// ---------------------------------------------------------------------------
375389
376390export const appTestFixture = authFixture . extend < { authReady : void } > ( {
377- // Auto-trigger authLogin and strip CLIENT_ID so tests create their own apps
391+ // Auto-trigger authLogin so the OAuth session is available for all app tests
378392 authReady : [
379- async (
380- { authLogin : _authLogin , env} : { authLogin : void ; env : import ( './env.js' ) . E2EEnv } ,
381- use : ( ) => Promise < void > ,
382- ) => {
383- delete env . processEnv . SHOPIFY_FLAG_CLIENT_ID
393+ async ( { authLogin : _authLogin } : { authLogin : void } , use : ( ) => Promise < void > ) => {
384394 await use ( )
385395 } ,
386396 { auto : true } ,
0 commit comments