@@ -14,7 +14,7 @@ import * as nls from 'vscode-nls'
14
14
import globals , { initialize } from './shared/extensionGlobals'
15
15
import { join } from 'path'
16
16
import { Commands } from './shared/vscode/commands2'
17
- import { documentationUrl , githubCreateIssueUrl , githubUrl } from './shared/constants'
17
+ import { documentationUrl , endpointsFileUrl , githubCreateIssueUrl , githubUrl } from './shared/constants'
18
18
import { getIdeProperties , aboutToolkit , isCloud9 } from './shared/extensionUtilities'
19
19
import { telemetry } from './shared/telemetry/telemetry'
20
20
import { openUrl } from './shared/utilities/vsCodeUtils'
@@ -31,7 +31,7 @@ import { initialize as initializeAuth } from './auth/activation'
31
31
import { LoginManager } from './auth/deprecated/loginManager'
32
32
import { CredentialsStore } from './auth/credentials/store'
33
33
import { initializeAwsCredentialsStatusBarItem } from './auth/ui/statusBarItem'
34
- import { RegionProvider } from './shared/regions/regionProvider'
34
+ import { RegionProvider , getEndpointsFromFetcher } from './shared/regions/regionProvider'
35
35
import { ChildProcess } from './shared/utilities/childProcess'
36
36
import { isWeb } from './common/webUtils'
37
37
import { registerErrorHandler as registerCommandErrorHandler } from './shared/vscode/commands2'
@@ -45,6 +45,8 @@ import { ExtContext } from './shared/extensions'
45
45
import { getSamCliContext } from './shared/sam/cli/samCliContext'
46
46
import { UriHandler } from './shared/vscode/uriHandler'
47
47
import { disableAwsSdkWarning } from './shared/awsClientBuilder'
48
+ import { FileResourceFetcher } from './shared/resourcefetcher/fileResourceFetcher'
49
+ import { ResourceFetcher } from './shared/resourcefetcher/resourcefetcher'
48
50
49
51
disableAwsSdkWarning ( )
50
52
@@ -53,14 +55,8 @@ let localize: nls.LocalizeFunc
53
55
/**
54
56
* Activation/setup code that is shared by the regular (nodejs) extension AND web mode extension.
55
57
* Most setup code should live here, unless there is a reason not to.
56
- *
57
- * @param getRegionProvider - HACK telemetry requires the region provider but we cannot create it yet in this
58
- * "shared" function since it breaks in web mode. So for now the caller must provide it.
59
58
*/
60
- export async function activateShared (
61
- context : vscode . ExtensionContext ,
62
- getRegionProvider : ( ) => RegionProvider
63
- ) : Promise < ExtContext > {
59
+ export async function activateShared ( context : vscode . ExtensionContext ) : Promise < ExtContext > {
64
60
localize = nls . loadMessageBundle ( )
65
61
66
62
// some "initialize" functions
@@ -109,7 +105,7 @@ export async function activateShared(
109
105
globals . manifestPaths . lambdaSampleRequests = context . asAbsolutePath (
110
106
join ( 'resources' , 'vs-lambda-sample-request-manifest.xml' )
111
107
)
112
- globals . regionProvider = getRegionProvider ( )
108
+ globals . regionProvider = RegionProvider . fromEndpointsProvider ( makeEndpointsProvider ( ) )
113
109
114
110
// telemetry
115
111
await activateTelemetry ( context , globals . awsContext , Settings . instance )
@@ -238,6 +234,36 @@ function logAndShowWebviewError(err: unknown, webviewId: string, command: string
238
234
} )
239
235
}
240
236
237
+ /**
238
+ * Returns an object that provides AWS service endpoints that the toolkit supports.
239
+ *
240
+ * https://docs.aws.amazon.com/general/latest/gr/rande.html
241
+ */
242
+ function makeEndpointsProvider ( ) {
243
+ let localManifestFetcher : ResourceFetcher
244
+ let remoteManifestFetcher : ResourceFetcher
245
+ if ( isWeb ( ) ) {
246
+ // In web mode everything must be in a single file, so things like the endpoints file will not be available.
247
+ // The following imports the endpoints file, which causes webpack to bundle it in the final output file
248
+ const endpoints = require ( '../resources/endpoints.json' )
249
+ localManifestFetcher = { get : async ( ) => JSON . stringify ( endpoints ) }
250
+ // Cannot use HttpResourceFetcher due to web mode breaking on import
251
+ remoteManifestFetcher = { get : async ( ) => ( await fetch ( endpointsFileUrl ) ) . text ( ) }
252
+ } else {
253
+ localManifestFetcher = new FileResourceFetcher ( globals . manifestPaths . endpoints )
254
+ // HACK: HttpResourceFetcher breaks web mode when imported, so we use webpack.IgnorePlugin()
255
+ // to exclude it from the bundle.
256
+ // TODO: Make HttpResourceFetcher web mode compatible
257
+ const { HttpResourceFetcher } = require ( './shared/resourcefetcher/httpResourceFetcher' )
258
+ remoteManifestFetcher = new HttpResourceFetcher ( endpointsFileUrl , { showUrl : true } )
259
+ }
260
+
261
+ return {
262
+ local : ( ) => getEndpointsFromFetcher ( localManifestFetcher ) ,
263
+ remote : ( ) => getEndpointsFromFetcher ( remoteManifestFetcher ) ,
264
+ }
265
+ }
266
+
241
267
/**
242
268
* Wraps the `vscode.window.withProgress` functionality with functionality that also writes to the output channel.
243
269
*
0 commit comments