@@ -10,19 +10,20 @@ import { Messages } from '../messages';
10
10
import { Logger } from '../logger' ;
11
11
import { ConfigAggregator } from '../config/configAggregator' ;
12
12
import { SfProject } from '../sfProject' ;
13
- import { SfError } from '../sfError ' ;
13
+ import { Lifecycle } from '../lifecycleEvents ' ;
14
14
import { Org } from './org' ;
15
15
import {
16
16
authorizeScratchOrg ,
17
17
requestScratchOrgCreation ,
18
18
pollForScratchOrgInfo ,
19
19
deploySettingsAndResolveUrl ,
20
- ScratchOrgInfo ,
21
20
} from './scratchOrgInfoApi' ;
21
+ import { ScratchOrgInfo } from './scratchOrgTypes' ;
22
22
import SettingsGenerator from './scratchOrgSettingsGenerator' ;
23
23
import { generateScratchOrgInfo , getScratchOrgInfoPayload } from './scratchOrgInfoGenerator' ;
24
24
import { AuthFields , AuthInfo } from './authInfo' ;
25
25
import { Connection } from './connection' ;
26
+ import { emit } from './scratchOrgLifecycleEvents' ;
26
27
27
28
Messages . importMessagesDirectory ( __dirname ) ;
28
29
const messages = Messages . load ( '@salesforce/core' , 'scratchOrgCreate' , [
@@ -106,8 +107,9 @@ const validateWait = (wait: Duration): void => {
106
107
107
108
export const scratchOrgCreate = async ( options : ScratchOrgCreateOptions ) : Promise < ScratchOrgCreateResult > => {
108
109
const logger = await Logger . child ( 'scratchOrgCreate' ) ;
109
- logger . debug ( 'scratchOrgCreate' ) ;
110
110
111
+ logger . debug ( 'scratchOrgCreate' ) ;
112
+ await emit ( { stage : 'prepare request' } ) ;
111
113
const {
112
114
hubOrg,
113
115
connectedAppConsumerKey,
@@ -151,7 +153,6 @@ export const scratchOrgCreate = async (options: ScratchOrgCreateOptions): Promis
151
153
152
154
// creates the scratch org info in the devhub
153
155
const scratchOrgInfoRequestResult = await requestScratchOrgCreation ( hubOrg , scratchOrgInfo , settingsGenerator ) ;
154
-
155
156
const scratchOrgInfoId = ensureString ( getString ( scratchOrgInfoRequestResult , 'id' ) ) ;
156
157
157
158
logger . debug ( `scratch org has recordId ${ scratchOrgInfoId } ` ) ;
@@ -177,6 +178,8 @@ export const scratchOrgCreate = async (options: ScratchOrgCreateOptions): Promis
177
178
logger . debug ( `scratch org username ${ username } ` ) ;
178
179
179
180
const configAggregator = new ConfigAggregator ( ) ;
181
+ await emit ( { stage : 'deploy settings' , scratchOrgInfo : scratchOrgInfoResult } ) ;
182
+
180
183
const authInfo = await deploySettingsAndResolveUrl (
181
184
scratchOrgAuthInfo ,
182
185
apiversion ??
@@ -189,6 +192,7 @@ export const scratchOrgCreate = async (options: ScratchOrgCreateOptions): Promis
189
192
logger . trace ( 'Settings deployed to org' ) ;
190
193
/** updating the revision num to zero during org:creation if source members are created during org:create.This only happens for some specific scratch org definition file.*/
191
194
await updateRevisionCounterToZero ( scratchOrg ) ;
195
+ await emit ( { stage : 'done' , scratchOrgInfo : scratchOrgInfoResult } ) ;
192
196
193
197
return {
194
198
username,
@@ -212,15 +216,16 @@ const getSignupTargetLoginUrl = async (): Promise<string | undefined> => {
212
216
const updateRevisionCounterToZero = async ( scratchOrg : Org ) : Promise < void > => {
213
217
const conn = scratchOrg . getConnection ( ) ;
214
218
const queryResult = await conn . tooling . sobject ( 'SourceMember' ) . find ( { RevisionCounter : { $gt : 0 } } , [ 'Id' ] ) ;
219
+ if ( queryResult . length === 0 ) {
220
+ return ;
221
+ }
215
222
try {
216
223
await conn . tooling
217
224
. sobject ( 'SourceMember' )
218
225
. update ( queryResult . map ( ( record ) => ( { Id : record . Id , RevisionCounter : 0 } ) ) ) ;
219
226
} catch ( err ) {
220
- const message = messages . getMessage ( 'SourceStatusResetFailureError' , [
221
- scratchOrg . getOrgId ( ) ,
222
- scratchOrg . getUsername ( ) ,
223
- ] ) ;
224
- throw new SfError ( message , 'SourceStatusResetFailure' ) ;
227
+ await Lifecycle . getInstance ( ) . emitWarning (
228
+ messages . getMessage ( 'SourceStatusResetFailureError' , [ scratchOrg . getOrgId ( ) , scratchOrg . getUsername ( ) ] )
229
+ ) ;
225
230
}
226
231
} ;
0 commit comments