@@ -13,13 +13,13 @@ import open from 'open';
1313import { ApifyCommand } from '../../lib/apify_command.js' ;
1414import { CommandExitCodes , DEPRECATED_LOCAL_CONFIG_NAME , LOCAL_CONFIG_PATH } from '../../lib/consts.js' ;
1515import { sumFilesSizeInBytes } from '../../lib/files.js' ;
16+ import { useActorConfig } from '../../lib/hooks/useActorConfig.js' ;
1617import { error , info , link , run , success , warning } from '../../lib/outputs.js' ;
1718import { transformEnvToEnvVars } from '../../lib/secrets.js' ;
1819import {
1920 createActZip ,
2021 createSourceFiles ,
2122 getActorLocalFilePaths ,
22- getLocalConfigOrThrow ,
2323 getLocalUserInfo ,
2424 getLoggedClientOrThrow ,
2525 outputJobLog ,
@@ -131,19 +131,16 @@ export class ActorsPushCommand extends ApifyCommand<typeof ActorsPushCommand> {
131131
132132 const apifyClient = await getLoggedClientOrThrow ( ) ;
133133
134- let localConfig : Record < string , unknown > ;
134+ const actorConfigResult = await useActorConfig ( { cwd } ) ;
135135
136- try {
137- localConfig = ( await getLocalConfigOrThrow ( cwd ) ) ! ;
138- } catch ( _error ) {
139- const casted = _error as Error ;
140- const cause = casted . cause as Error ;
141-
142- error ( { message : `${ casted . message } \n ${ cause . message } ` } ) ;
136+ if ( actorConfigResult . isErr ( ) ) {
137+ error ( { message : actorConfigResult . unwrapErr ( ) . message } ) ;
143138 process . exitCode = CommandExitCodes . InvalidActorJson ;
144139 return ;
145140 }
146141
142+ const { config : actorConfig } = actorConfigResult . unwrap ( ) ;
143+
147144 const userInfo = await getLocalUserInfo ( ) ;
148145 const isOrganizationLoggedIn = ! ! userInfo . organizationOwnerUserId ;
149146 const redirectUrlPart = isOrganizationLoggedIn ? `/organization/${ userInfo . id } ` : '' ;
@@ -154,9 +151,9 @@ export class ActorsPushCommand extends ApifyCommand<typeof ActorsPushCommand> {
154151
155152 // User can override Actor version and build tag, attributes in localConfig will remain same.
156153 const version =
157- this . flags . version || ( localConfig ?. version as string | undefined ) || DEFAULT_ACTOR_VERSION_NUMBER ;
154+ this . flags . version || ( actorConfig ?. version as string | undefined ) || DEFAULT_ACTOR_VERSION_NUMBER ;
158155
159- let buildTag = this . flags . buildTag || ( localConfig ! . buildTag as string | undefined ) ;
156+ let buildTag = this . flags . buildTag || ( actorConfig ? .buildTag as string | undefined ) ;
160157
161158 // We can't add the default build tag to everything. If a user creates a new
162159 // version, e.g. for testing, but forgets to add a tag, it would use the default
@@ -180,16 +177,16 @@ export class ActorsPushCommand extends ApifyCommand<typeof ActorsPushCommand> {
180177 actorId = actor . id ;
181178 } else {
182179 const usernameOrId = userInfo . username || userInfo . id ;
183- actor = ( await apifyClient . actor ( `${ usernameOrId } /${ localConfig ! . name } ` ) . get ( ) ) ! ;
180+ actor = ( await apifyClient . actor ( `${ usernameOrId } /${ actorConfig ! . name } ` ) . get ( ) ) ! ;
184181 if ( actor ) {
185182 actorId = actor . id ;
186183 } else {
187184 const { templates } = await fetchManifest ( ) ;
188- const actorTemplate = templates . find ( ( t ) => t . name === localConfig ! . template ) ;
185+ const actorTemplate = templates . find ( ( t ) => t . name === actorConfig ! . template ) ;
189186 const defaultRunOptions = ( actorTemplate ?. defaultRunOptions ||
190187 DEFAULT_RUN_OPTIONS ) as ActorDefaultRunOptions ;
191188 const newActor : ActorCollectionCreateOptions = {
192- name : localConfig ! . name as string ,
189+ name : actorConfig ! . name as string ,
193190 defaultRunOptions,
194191 versions : [
195192 {
@@ -204,11 +201,11 @@ export class ActorsPushCommand extends ApifyCommand<typeof ActorsPushCommand> {
204201 actor = await apifyClient . actors ( ) . create ( newActor ) ;
205202 actorId = actor . id ;
206203 isActorCreatedNow = true ;
207- info ( { message : `Created Actor with name ${ localConfig ! . name } on Apify.` } ) ;
204+ info ( { message : `Created Actor with name ${ actorConfig ! . name } on Apify.` } ) ;
208205 }
209206 }
210207
211- info ( { message : `Deploying Actor '${ localConfig ! . name } ' to Apify.` } ) ;
208+ info ( { message : `Deploying Actor '${ actorConfig ! . name } ' to Apify.` } ) ;
212209
213210 const filesSize = await sumFilesSizeInBytes ( filePathsToPush , cwd ) ;
214211 const actorClient = apifyClient . actor ( actorId ) ;
@@ -235,10 +232,10 @@ export class ActorsPushCommand extends ApifyCommand<typeof ActorsPushCommand> {
235232 ! this . flags . force &&
236233 actorModifiedMs &&
237234 mostRecentModifiedFileMs < actorModifiedMs &&
238- ( localConfig ?. name || forceActorId )
235+ ( actorConfig ?. name || forceActorId )
239236 ) {
240237 throw new Error (
241- `Actor with identifier "${ localConfig ?. name || forceActorId } " is already on the platform and was modified there since modified locally.
238+ `Actor with identifier "${ actorConfig ?. name || forceActorId } " is already on the platform and was modified there since modified locally.
242239Skipping push. Use --force to override.` ,
243240 ) ;
244241 }
@@ -268,8 +265,8 @@ Skipping push. Use --force to override.`,
268265
269266 // Update Actor version
270267 const actorCurrentVersion = await actorClient . version ( version ) . get ( ) ;
271- const envVars = localConfig ! . environmentVariables
272- ? transformEnvToEnvVars ( localConfig ! . environmentVariables as Record < string , string > )
268+ const envVars = actorConfig ! . environmentVariables
269+ ? transformEnvToEnvVars ( actorConfig ! . environmentVariables as Record < string , string > )
273270 : undefined ;
274271
275272 if ( actorCurrentVersion ) {
0 commit comments