Skip to content

Commit 8efd1b7

Browse files
Merge staging into feature/featureDev-codegen
2 parents 6b76aaa + eb1d9e7 commit 8efd1b7

File tree

6 files changed

+70
-43
lines changed

6 files changed

+70
-43
lines changed

packages/toolkit/src/extension.ts

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import { SharedCredentialsProviderFactory } from './auth/providers/sharedCredent
1414
import { activate as activateSchemas } from './eventSchemas/activation'
1515
import { activate as activateLambda } from './lambda/activation'
1616
import { activate as activateCloudFormationTemplateRegistry } from './shared/cloudformation/activation'
17-
import { endpointsFileUrl } from './shared/constants'
1817
import { AwsContextCommands } from './shared/awsContextCommands'
1918
import {
2019
getIdeProperties,
@@ -24,9 +23,6 @@ import {
2423
showWelcomeMessage,
2524
} from './shared/extensionUtilities'
2625
import { getLogger, Logger } from './shared/logger/logger'
27-
import { getEndpointsFromFetcher, RegionProvider } from './shared/regions/regionProvider'
28-
import { FileResourceFetcher } from './shared/resourcefetcher/fileResourceFetcher'
29-
import { HttpResourceFetcher } from './shared/resourcefetcher/httpResourceFetcher'
3026
import { activate as activateEcr } from './ecr/activation'
3127
import { activate as activateEc2 } from './ec2/activation'
3228
import { activate as activateSam } from './shared/sam/activation'
@@ -74,9 +70,7 @@ export async function activate(context: vscode.ExtensionContext) {
7470

7571
try {
7672
// IMPORTANT: If you are doing setup that should also work in web mode (browser), it should be done in the function below
77-
const extContext = await activateShared(context, () =>
78-
RegionProvider.fromEndpointsProvider(makeEndpointsProvider())
79-
)
73+
const extContext = await activateShared(context)
8074

8175
initializeNetworkAgent()
8276
initializeCredentialsProviderManager()
@@ -236,16 +230,6 @@ function initializeCredentialsProviderManager() {
236230
manager.addProviders(new Ec2CredentialsProvider(), new EcsCredentialsProvider(), new EnvVarsCredentialsProvider())
237231
}
238232

239-
function makeEndpointsProvider() {
240-
const localManifestFetcher = new FileResourceFetcher(globals.manifestPaths.endpoints)
241-
const remoteManifestFetcher = new HttpResourceFetcher(endpointsFileUrl, { showUrl: true })
242-
243-
return {
244-
local: () => getEndpointsFromFetcher(localManifestFetcher),
245-
remote: () => getEndpointsFromFetcher(remoteManifestFetcher),
246-
}
247-
}
248-
249233
function recordToolkitInitialization(activationStartedOn: number, settingsValid: boolean, logger?: Logger) {
250234
try {
251235
const activationFinishedOn = Date.now()

packages/toolkit/src/extensionShared.ts

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import * as nls from 'vscode-nls'
1414
import globals, { initialize } from './shared/extensionGlobals'
1515
import { join } from 'path'
1616
import { Commands } from './shared/vscode/commands2'
17-
import { documentationUrl, githubCreateIssueUrl, githubUrl } from './shared/constants'
17+
import { documentationUrl, endpointsFileUrl, githubCreateIssueUrl, githubUrl } from './shared/constants'
1818
import { getIdeProperties, aboutToolkit, isCloud9 } from './shared/extensionUtilities'
1919
import { telemetry } from './shared/telemetry/telemetry'
2020
import { openUrl } from './shared/utilities/vsCodeUtils'
@@ -31,7 +31,7 @@ import { initialize as initializeAuth } from './auth/activation'
3131
import { LoginManager } from './auth/deprecated/loginManager'
3232
import { CredentialsStore } from './auth/credentials/store'
3333
import { initializeAwsCredentialsStatusBarItem } from './auth/ui/statusBarItem'
34-
import { RegionProvider } from './shared/regions/regionProvider'
34+
import { RegionProvider, getEndpointsFromFetcher } from './shared/regions/regionProvider'
3535
import { ChildProcess } from './shared/utilities/childProcess'
3636
import { isWeb } from './common/webUtils'
3737
import { registerErrorHandler as registerCommandErrorHandler } from './shared/vscode/commands2'
@@ -45,6 +45,8 @@ import { ExtContext } from './shared/extensions'
4545
import { getSamCliContext } from './shared/sam/cli/samCliContext'
4646
import { UriHandler } from './shared/vscode/uriHandler'
4747
import { disableAwsSdkWarning } from './shared/awsClientBuilder'
48+
import { FileResourceFetcher } from './shared/resourcefetcher/fileResourceFetcher'
49+
import { ResourceFetcher } from './shared/resourcefetcher/resourcefetcher'
4850

4951
disableAwsSdkWarning()
5052

@@ -53,14 +55,8 @@ let localize: nls.LocalizeFunc
5355
/**
5456
* Activation/setup code that is shared by the regular (nodejs) extension AND web mode extension.
5557
* 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.
5958
*/
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> {
6460
localize = nls.loadMessageBundle()
6561

6662
// some "initialize" functions
@@ -109,7 +105,7 @@ export async function activateShared(
109105
globals.manifestPaths.lambdaSampleRequests = context.asAbsolutePath(
110106
join('resources', 'vs-lambda-sample-request-manifest.xml')
111107
)
112-
globals.regionProvider = getRegionProvider()
108+
globals.regionProvider = RegionProvider.fromEndpointsProvider(makeEndpointsProvider())
113109

114110
// telemetry
115111
await activateTelemetry(context, globals.awsContext, Settings.instance)
@@ -238,6 +234,36 @@ function logAndShowWebviewError(err: unknown, webviewId: string, command: string
238234
})
239235
}
240236

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+
241267
/**
242268
* Wraps the `vscode.window.withProgress` functionality with functionality that also writes to the output channel.
243269
*

packages/toolkit/src/extensionWeb.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import * as vscode from 'vscode'
77
import { setWeb } from './common/webUtils'
88
import { getLogger } from './shared/logger'
99
import { activateShared, deactivateShared } from './extensionShared'
10-
import { RegionProvider, defaultRegion } from './shared/regions/regionProvider'
1110
import os from 'os'
1211

1312
export async function activate(context: vscode.ExtensionContext) {
@@ -18,11 +17,7 @@ export async function activate(context: vscode.ExtensionContext) {
1817

1918
// IMPORTANT: Any new activation code should be done in the function below unless
2019
// it is web mode specific activation code.
21-
await activateShared(context, () => {
22-
return {
23-
guessDefaultRegion: () => defaultRegion,
24-
} as RegionProvider
25-
})
20+
await activateShared(context)
2621
} catch (error) {
2722
const stacktrace = (error as Error).stack?.split('\n')
2823
// truncate if the stacktrace is unusually long

packages/toolkit/src/shared/resourcefetcher/fileResourceFetcher.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
import * as fs from 'fs-extra'
6+
import { fsCommon } from '../../srcShared/fs'
77
import { getLogger, Logger } from '../logger'
88
import { ResourceFetcher } from './resourcefetcher'
99

@@ -18,7 +18,7 @@ export class FileResourceFetcher implements ResourceFetcher {
1818
public async get(): Promise<string | undefined> {
1919
try {
2020
this.logger.verbose('loading file resource: "%s"', this.filepath)
21-
return (await fs.readFile(this.filepath)).toString()
21+
return await fsCommon.readFileAsString(this.filepath)
2222
} catch (err) {
2323
this.logger.verbose('failed to load file resource: "%s": %s', this.filepath, (err as Error).message)
2424
return undefined
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*!
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
import assert from 'assert'
7+
import globals from '../shared/extensionGlobals'
8+
9+
describe('activation', async () => {
10+
it('defines a region provider that can provide regions when in web mode', async () => {
11+
assert(globals.regionProvider.getRegions().length > 0)
12+
})
13+
})

packages/webpack.web.config.js

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,6 @@ const baseConfig = require('./webpack.base.config')
1818
const webConfig = merge(baseConfig, {
1919
name: 'web',
2020
target: 'webworker',
21-
/**
22-
* We currently inherit the value "source-map" for the key 'devtool' from the base config. But during debugging w/ Chromium this
23-
* is known to cause breakpoints to be offset. See this thread: https://github.com/webpack/webpack/issues/1487
24-
*
25-
* TODO: We do not want to use `eval-source-map` for Production since it is recommended for Development builds. Look for a solution to use something
26-
* better when in Production. https://webpack.js.org/configuration/devtool/
27-
*/
28-
devtool: 'eval-source-map',
2921
/**
3022
* The keys in the following 'entry' object are the relative paths of the final output files in 'dist'.
3123
* They are suffixed with '.js' implicitly.
@@ -44,6 +36,22 @@ const webConfig = merge(baseConfig, {
4436
NODE_DEBUG: 'development',
4537
READABLE_STREAM: 'disable',
4638
}),
39+
/**
40+
* HACK: the HttpResourceFetcher breaks Web mode if imported, BUT we still dynamically import this module for non web mode
41+
* environments. The following allows compilation to pass in Web mode by never bundling the module in the final output.
42+
*/
43+
new webpack.IgnorePlugin({
44+
resourceRegExp: /httpResourceFetcher/, // matches the path in the require() statement
45+
}),
46+
/**
47+
* The following solves issues w/ breakpoints being offset when debugging in Chrome. IDK WHY!!!!
48+
*
49+
* To sanity check, comment out the following, set a breakpoint in the toolkit activation function, then see how the breakpoints
50+
* are not working as expected.
51+
*/
52+
new webpack.SourceMapDevToolPlugin({
53+
exclude: /\*\*\/node_modules\/\*\*/,
54+
}),
4755
],
4856
resolve: {
4957
extensions: ['.ts', '.js'],
@@ -73,6 +81,7 @@ const webConfig = merge(baseConfig, {
7381
},
7482
mode: 'production', // lets see if we can change this to 'development' later
7583
optimization: {
84+
// If `true` then we will get confusing variable names in the debugging menu
7685
minimize: false,
7786
},
7887
})

0 commit comments

Comments
 (0)