1- import process from 'process'
1+ import { platform } from 'process'
22
33import fetch from 'node-fetch'
44import pWaitFor from 'p-wait-for'
@@ -7,7 +7,7 @@ import { v4 as uuidv4 } from 'uuid'
77import { fetchLatestVersion , shouldFetchLatestVersion } from '../lib/exec-fetcher.js'
88import { getPathInHome } from '../lib/settings.js'
99
10- import { NETLIFYDEVERR , NETLIFYDEVLOG , chalk , log } from './command-helpers.js'
10+ import { NETLIFYDEVERR , NETLIFYDEVLOG , chalk , exit , log } from './command-helpers.js'
1111import execa from './execa.js'
1212import type CLIState from './cli-state.js'
1313
@@ -50,8 +50,12 @@ const createTunnel = async function ({
5050 const data = await response . json ( )
5151
5252 if ( response . status !== 201 ) {
53- // @ts -expect-error(serhalp) -- Use typed `netlify` API client?
54- throw new Error ( data . message )
53+ // TODO(serhalp): Use typed `netlify` API client?
54+ throw new Error (
55+ data != null && typeof data === 'object' && 'message' in data && typeof data . message === 'string'
56+ ? data . message
57+ : '' ,
58+ )
5559 }
5660
5761 return data as LiveSession
@@ -74,9 +78,9 @@ const connectTunnel = function ({
7478 }
7579
7680 const ps = execa ( execPath , args , { stdio : 'inherit' } )
77- ps . on ( 'close' , ( code ) => process . exit ( code ?? undefined ) )
78- ps . on ( 'SIGINT' , process . exit )
79- ps . on ( 'SIGTERM' , process . exit )
81+ void ps . on ( 'close' , ( code ) => exit ( code ?? undefined ) )
82+ void ps . on ( 'SIGINT' , ( ) => exit ( ) )
83+ void ps . on ( 'SIGTERM' , ( ) => exit ( ) )
8084}
8185
8286const installTunnelClient = async function ( ) {
@@ -98,7 +102,7 @@ const installTunnelClient = async function () {
98102 packageName : PACKAGE_NAME ,
99103 execName : EXEC_NAME ,
100104 destination : binPath ,
101- extension : process . platform === 'win32' ? 'zip' : 'tar.gz' ,
105+ extension : platform === 'win32' ? 'zip' : 'tar.gz' ,
102106 } )
103107}
104108
@@ -119,13 +123,20 @@ export const startLiveTunnel = async ({
119123 'netlify init' ,
120124 ) } or ${ chalk . yellow ( 'netlify link' ) } ?`,
121125 )
122- process . exit ( 1 )
126+ return exit ( 1 )
127+ }
128+ if ( ! netlifyApiToken ) {
129+ console . error (
130+ `${ NETLIFYDEVERR } Error: no Netlify auth token defined, did you forget to run ${ chalk . yellow (
131+ 'netlify login' ,
132+ ) } or define 'NETLIFY_AUTH_TOKEN'?`,
133+ )
134+ return exit ( 1 )
123135 }
124136
125137 const session = await createTunnel ( {
126138 siteId,
127- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- XXX(serhalp): removed in favor of runtime user feedback in stacked PR
128- netlifyApiToken : netlifyApiToken ! ,
139+ netlifyApiToken,
129140 slug,
130141 } )
131142
@@ -141,15 +152,18 @@ export const startLiveTunnel = async ({
141152 const data = await response . json ( )
142153
143154 if ( response . status !== 200 ) {
144- // @ts -expect-error(serhalp) -- Use typed `netlify` API client?
145- throw new Error ( data . message )
155+ // TODO(serhalp): Use typed `netlify` API client?
156+ throw new Error (
157+ data != null && typeof data === 'object' && 'message' in data && typeof data . message === 'string'
158+ ? data . message
159+ : '' ,
160+ )
146161 }
147162
148163 return ( data as LiveSession ) . state === 'online'
149164 }
150165
151- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- XXX(serhalp): removed in favor of runtime user feedback in stacked PR
152- connectTunnel ( { session, netlifyApiToken : netlifyApiToken ! , localPort } )
166+ connectTunnel ( { session, netlifyApiToken, localPort } )
153167
154168 // Waiting for the live session to have a state of `online`.
155169 await pWaitFor ( isLiveTunnelReady , {
0 commit comments