11import EventEmitter from 'events' ;
2+ import { createRequire } from 'module' ;
23import { cliux } from '@contentstack/cli-utilities' ;
34import { ApolloClient , ObservableQuery } from '@apollo/client/core' ;
45import { Ora } from 'ora' ;
@@ -8,6 +9,8 @@ import { deploymentQuery, deploymentLogsQuery, serverlessLogsQuery } from '../gr
89import { setTimeout as sleep } from 'timers/promises' ;
910import { isNotDevelopment } from './apollo-client' ;
1011
12+ const requireApolloDeprecation = createRequire ( __filename ) ;
13+
1114export default class LogPolling {
1215 private config : ConfigType ;
1316 private $event ! : EventEmitter ;
@@ -33,19 +36,25 @@ export default class LogPolling {
3336 * only during its execution, and restored immediately after.
3437 */
3538 private withDeprecationsDisabled < T > ( fn : ( ) => T ) : T {
36-
3739 if ( ! isNotDevelopment ) {
3840 return fn ( ) ;
3941 }
40-
41- let withDisabledDeprecations : any ;
42+
43+ let withDisabledDeprecations : unknown ;
4244 try {
43- withDisabledDeprecations = require ( '@apollo/client/utilities/deprecation' ) . withDisabledDeprecations ;
45+ withDisabledDeprecations = requireApolloDeprecation (
46+ '@apollo/client/utilities/deprecation' ,
47+ ) . withDisabledDeprecations ;
4448 } catch {
4549 return fn ( ) ;
4650 }
4751
48- const handler = withDisabledDeprecations ( ) ;
52+ if ( typeof withDisabledDeprecations !== 'function' ) {
53+ return fn ( ) ;
54+ }
55+
56+ const handler = ( withDisabledDeprecations as ( ) => unknown ) ( ) ;
57+
4958 try {
5059 return fn ( ) ;
5160 } finally {
@@ -61,14 +70,18 @@ export default class LogPolling {
6170 dispose . call ( handler ) ;
6271 return ;
6372 }
64- } catch { }
73+ } catch {
74+ void 0 ;
75+ }
6576 try {
6677 const asyncDispose = ( handler as any ) [ ( Symbol as any ) . asyncDispose ] ;
6778 if ( typeof asyncDispose === 'function' ) {
6879 asyncDispose . call ( handler ) ;
6980 return ;
7081 }
71- } catch { }
82+ } catch {
83+ void 0 ;
84+ }
7285 try {
7386 const symbols = Object . getOwnPropertySymbols ( handler ) ;
7487 for ( const sym of symbols ) {
@@ -78,7 +91,9 @@ export default class LogPolling {
7891 break ;
7992 }
8093 }
81- } catch { }
94+ } catch {
95+ void 0 ;
96+ }
8297 }
8398
8499 /**
@@ -101,17 +116,17 @@ export default class LogPolling {
101116 > {
102117 return this . withDeprecationsDisabled ( ( ) => {
103118 const statusWatchQuery = this . apolloManageClient . watchQuery ( {
104- fetchPolicy : 'network-only' ,
105- query : deploymentQuery ,
106- variables : {
107- query : {
108- uid : this . config . deployment ,
109- environment : this . config . environment ,
119+ fetchPolicy : 'network-only' ,
120+ query : deploymentQuery ,
121+ variables : {
122+ query : {
123+ uid : this . config . deployment ,
124+ environment : this . config . environment ,
125+ } ,
110126 } ,
111- } ,
112- pollInterval : this . config . pollingInterval ,
113- errorPolicy : 'all' ,
114- } ) ;
127+ pollInterval : this . config . pollingInterval ,
128+ errorPolicy : 'all' ,
129+ } ) ;
115130 return statusWatchQuery ;
116131 } ) ;
117132 }
@@ -146,14 +161,14 @@ export default class LogPolling {
146161 } ) ;
147162 const logsWatchQuery = this . withDeprecationsDisabled ( ( ) => {
148163 return this . apolloLogsClient . watchQuery ( {
149- fetchPolicy : 'network-only' ,
150- query : deploymentLogsQuery ,
151- variables : {
152- deploymentUid : this . config . deployment ,
153- } ,
154- pollInterval : this . config . pollingInterval ,
155- errorPolicy : 'all' ,
156- } ) ;
164+ fetchPolicy : 'network-only' ,
165+ query : deploymentLogsQuery ,
166+ variables : {
167+ deploymentUid : this . config . deployment ,
168+ } ,
169+ pollInterval : this . config . pollingInterval ,
170+ errorPolicy : 'all' ,
171+ } ) ;
157172 } ) ;
158173 this . subscribeDeploymentLogs ( logsWatchQuery ) ;
159174 }
@@ -243,19 +258,19 @@ export default class LogPolling {
243258
244259 const serverLogsWatchQuery = this . withDeprecationsDisabled ( ( ) => {
245260 return this . apolloLogsClient . watchQuery ( {
246- fetchPolicy : 'network-only' ,
247- query : serverlessLogsQuery ,
248- variables : {
249- query : {
250- environmentUid : this . config . environment ,
251- startTime : this . startTime ,
252- endTime : this . endTime ,
253- deploymentUid : this . config . deployment ,
261+ fetchPolicy : 'network-only' ,
262+ query : serverlessLogsQuery ,
263+ variables : {
264+ query : {
265+ environmentUid : this . config . environment ,
266+ startTime : this . startTime ,
267+ endTime : this . endTime ,
268+ deploymentUid : this . config . deployment ,
269+ } ,
254270 } ,
255- } ,
256- pollInterval : this . config . pollingInterval ,
257- errorPolicy : 'all' ,
258- } ) ;
271+ pollInterval : this . config . pollingInterval ,
272+ errorPolicy : 'all' ,
273+ } ) ;
259274 } ) ;
260275 this . subscribeServerLogs ( serverLogsWatchQuery ) ;
261276 }
0 commit comments