Skip to content

Commit 30601ba

Browse files
refactor(urls): Remove isCloud9 from constants file (#5717)
We have some strings that need to resolve a url depending on c9 vs toolkit. The isCloud9() function is causing issues in the constants file. Due to some sort of module import order, isCloud9() did not resolve appropriately when expected. I think we used the constants file before all the dependencies of the isCloud9() function were available The constants file should be a minimal module with as little external dependencies as possible. ## Solution: Move the resolution of c9 vs toolkit docs to an external function. Update uses everywhere. --- <!--- REMINDER: Ensure that your PR meets the guidelines in CONTRIBUTING.md --> License: I confirm that my contribution is made under the terms of the Apache 2.0 license. Signed-off-by: nkomonen-amazon <[email protected]>
1 parent b6c40e1 commit 30601ba

File tree

12 files changed

+120
-74
lines changed

12 files changed

+120
-74
lines changed

packages/core/src/awsService/apprunner/wizards/apprunnerCreateServiceWizard.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ import { AppRunnerImageRepositoryWizard } from './imageRepositoryWizard'
1414
import { AppRunnerCodeRepositoryWizard } from './codeRepositoryWizard'
1515
import { GitExtension } from '../../../shared/extensions/git'
1616
import { makeDeploymentButton } from './deploymentButton'
17-
import { apprunnerCreateServiceDocsUrl } from '../../../shared/constants'
1817
import { createExitPrompter } from '../../../shared/ui/common/exitPrompter'
1918
import { DefaultIamClient } from '../../../shared/clients/iamClient'
2019
import { DefaultEcrClient } from '../../../shared/clients/ecrClient'
2120
import { DefaultAppRunnerClient } from '../../../shared/clients/apprunnerClient'
21+
import { getAppRunnerCreateServiceDocUrl } from '../../../shared/extensionUtilities'
2222

2323
const localize = nls.loadMessageBundle()
2424

@@ -68,7 +68,7 @@ function createInstanceStep(): Prompter<AppRunner.InstanceConfiguration> {
6868

6969
return picker.createQuickPick(items, {
7070
title: localize('AWS.apprunner.createService.selectInstanceConfig.title', 'Select instance configuration'),
71-
buttons: createCommonButtons(apprunnerCreateServiceDocsUrl),
71+
buttons: createCommonButtons(getAppRunnerCreateServiceDocUrl()),
7272
})
7373
}
7474

@@ -92,7 +92,7 @@ function createSourcePrompter(
9292

9393
return picker.createQuickPick([ecrPath, repositoryPath], {
9494
title: localize('AWS.apprunner.createService.sourceType.title', 'Select a source code location type'),
95-
buttons: [autoDeployButton, ...createCommonButtons(apprunnerCreateServiceDocsUrl)],
95+
buttons: [autoDeployButton, ...createCommonButtons(getAppRunnerCreateServiceDocUrl())],
9696
})
9797
}
9898

@@ -137,7 +137,7 @@ export class CreateAppRunnerServiceWizard extends Wizard<AppRunner.CreateService
137137
input.createInputBox({
138138
title: localize('AWS.apprunner.createService.name.title', 'Name your service'),
139139
validateInput: validateName, // TODO: we can check if names match any already made services
140-
buttons: createCommonButtons(apprunnerCreateServiceDocsUrl),
140+
buttons: createCommonButtons(getAppRunnerCreateServiceDocUrl()),
141141
})
142142
)
143143

packages/core/src/awsService/apprunner/wizards/codeRepositoryWizard.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,10 @@ import { AppRunnerClient } from '../../../shared/clients/apprunnerClient'
1515
import { makeDeploymentButton } from './deploymentButton'
1616
import { createLabelQuickPick, createQuickPick, QuickPickPrompter } from '../../../shared/ui/pickerPrompter'
1717
import { createInputBox, InputBoxPrompter } from '../../../shared/ui/inputPrompter'
18-
import {
19-
apprunnerConnectionHelpUrl,
20-
apprunnerConfigHelpUrl,
21-
apprunnerRuntimeHelpUrl,
22-
apprunnerCreateServiceDocsUrl,
23-
} from '../../../shared/constants'
18+
import { apprunnerConnectionHelpUrl, apprunnerConfigHelpUrl, apprunnerRuntimeHelpUrl } from '../../../shared/constants'
2419
import { Wizard, WIZARD_BACK } from '../../../shared/wizards/wizard'
2520
import { openUrl } from '../../../shared/utilities/vsCodeUtils'
21+
import { getAppRunnerCreateServiceDocUrl } from '../../../shared/extensionUtilities'
2622

2723
const localize = nls.loadMessageBundle()
2824

@@ -140,7 +136,7 @@ function createPortPrompter(): InputBoxPrompter {
140136
validateInput: validatePort,
141137
title: localize('AWS.apprunner.createService.selectPort.title', 'Enter a port for the new service'),
142138
placeholder: 'Enter a port',
143-
buttons: createCommonButtons(apprunnerCreateServiceDocsUrl),
139+
buttons: createCommonButtons(getAppRunnerCreateServiceDocUrl()),
144140
})
145141
}
146142

@@ -220,7 +216,7 @@ function createCodeRepositorySubForm(git: GitExtension): WizardForm<AppRunner.Co
220216
codeConfigForm.body.StartCommand.bindPrompter((state) => createStartCommandPrompter(state.Runtime!))
221217
codeConfigForm.body.Port.bindPrompter(createPortPrompter)
222218
codeConfigForm.body.RuntimeEnvironmentVariables.bindPrompter(() =>
223-
createVariablesPrompter(createCommonButtons(apprunnerCreateServiceDocsUrl))
219+
createVariablesPrompter(createCommonButtons(getAppRunnerCreateServiceDocUrl()))
224220
)
225221
// TODO: ask user if they would like to save their parameters into an App Runner config file
226222

packages/core/src/awsService/apprunner/wizards/imageRepositoryWizard.ts

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

6-
import * as vscode from 'vscode'
76
import { AppRunner, IAM } from 'aws-sdk'
87
import { createCommonButtons, QuickInputButton, QuickInputToggleButton } from '../../../shared/ui/buttons'
98
import { toArrayAsync } from '../../../shared/utilities/collectionUtils'
@@ -21,8 +20,7 @@ import { makeDeploymentButton } from './deploymentButton'
2120
import { IamClient } from '../../../shared/clients/iamClient'
2221
import { createRolePrompter } from '../../../shared/ui/common/roles'
2322
import { getLogger } from '../../../shared/logger/logger'
24-
import { isCloud9 } from '../../../shared/extensionUtilities'
25-
import { apprunnerCreateServiceDocsUrl } from '../../../shared/constants'
23+
import { getAppRunnerCreateServiceDocUrl, isCloud9 } from '../../../shared/extensionUtilities'
2624
import { createExitPrompter } from '../../../shared/ui/common/exitPrompter'
2725

2826
const localize = nls.loadMessageBundle()
@@ -162,7 +160,7 @@ function createPortPrompter(): Prompter<string> {
162160
validateInput: validatePort,
163161
title: localize('AWS.apprunner.createService.selectPort.title', 'Enter a port for the new service'),
164162
placeholder: 'Enter a port',
165-
buttons: createCommonButtons(apprunnerCreateServiceDocsUrl),
163+
buttons: createCommonButtons(getAppRunnerCreateServiceDocUrl()),
166164
})
167165
}
168166

@@ -249,7 +247,7 @@ function createImageRepositorySubForm(
249247

250248
form.ImageConfiguration.Port.bindPrompter(() => createPortPrompter())
251249
form.ImageConfiguration.RuntimeEnvironmentVariables.bindPrompter(() =>
252-
createVariablesPrompter(createCommonButtons(apprunnerCreateServiceDocsUrl))
250+
createVariablesPrompter(createCommonButtons(getAppRunnerCreateServiceDocUrl()))
253251
)
254252

255253
return subform
@@ -262,7 +260,7 @@ export class AppRunnerImageRepositoryWizard extends Wizard<AppRunner.SourceConfi
262260
const createAccessRolePrompter = () => {
263261
return createRolePrompter(iamClient, {
264262
title: localize('AWS.apprunner.createService.selectRole.title', 'Select a role to pull from ECR'),
265-
helpUrl: vscode.Uri.parse(apprunnerCreateServiceDocsUrl),
263+
helpUrl: getAppRunnerCreateServiceDocUrl(),
266264
roleFilter: (role) => (role.AssumeRolePolicyDocument ?? '').includes(appRunnerEcrEntity),
267265
createRole: createEcrRole.bind(undefined, iamClient),
268266
}).transform((resp) => resp.Arn)

packages/core/src/extension.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ import * as nls from 'vscode-nls'
1616
import globals, { initialize, isWeb } from './shared/extensionGlobals'
1717
import { join } from 'path'
1818
import { Commands } from './shared/vscode/commands2'
19-
import { documentationUrl, endpointsFileUrl, githubCreateIssueUrl, githubUrl } from './shared/constants'
20-
import { getIdeProperties, aboutExtension, isCloud9 } from './shared/extensionUtilities'
19+
import { endpointsFileUrl, githubCreateIssueUrl, githubUrl } from './shared/constants'
20+
import { getIdeProperties, aboutExtension, isCloud9, getDocUrl } from './shared/extensionUtilities'
2121
import { logAndShowError, logAndShowWebviewError } from './shared/utilities/logAndShowUtils'
2222
import { AuthStatus, telemetry } from './shared/telemetry/telemetry'
2323
import { openUrl } from './shared/utilities/vsCodeUtils'
@@ -149,7 +149,7 @@ export async function activateCommon(
149149
),
150150
// register URLs in extension menu
151151
Commands.register(`aws.toolkit.help`, async () => {
152-
void openUrl(vscode.Uri.parse(documentationUrl))
152+
void openUrl(getDocUrl())
153153
telemetry.aws_help.emit()
154154
})
155155
)

packages/core/src/lambda/commands/createNewSamApp.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,12 @@ import { isTemplateTargetProperties } from '../../shared/sam/debugger/awsSamDebu
3939
import { TemplateTargetProperties } from '../../shared/sam/debugger/awsSamDebugConfiguration'
4040
import { openLaunchJsonFile } from '../../shared/sam/debugger/commands/addSamDebugConfiguration'
4141
import { waitUntil } from '../../shared/utilities/timeoutUtils'
42-
import { debugNewSamAppUrl, launchConfigDocUrl } from '../../shared/constants'
43-
import { getIdeProperties, isCloud9 } from '../../shared/extensionUtilities'
42+
import {
43+
getIdeProperties,
44+
getDebugNewSamAppDocUrl,
45+
isCloud9,
46+
getLaunchConfigDocUrl,
47+
} from '../../shared/extensionUtilities'
4448
import { execFileSync } from 'child_process'
4549
import { checklogs } from '../../shared/localizedText'
4650
import globals from '../../shared/extensionGlobals'
@@ -316,7 +320,7 @@ export async function createNewSamApplication(
316320
)
317321
.then(async (buttonText) => {
318322
if (buttonText === helpText) {
319-
void openUrl(vscode.Uri.parse(launchConfigDocUrl))
323+
void openUrl(getLaunchConfigDocUrl())
320324
}
321325
})
322326
}
@@ -441,7 +445,7 @@ async function showCompletionNotification(appName: string, configs: string): Pro
441445
if (action === openJson) {
442446
await openLaunchJsonFile()
443447
} else if (action === learnMore) {
444-
void openUrl(vscode.Uri.parse(debugNewSamAppUrl))
448+
void openUrl(getDebugNewSamAppDocUrl())
445449
}
446450
}
447451

packages/core/src/lambda/wizards/samDeployWizard.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ const localize = nls.loadMessageBundle()
1010

1111
import * as path from 'path'
1212
import * as vscode from 'vscode'
13-
import { samDeployDocUrl } from '../../shared/constants'
1413
import * as localizedText from '../../shared/localizedText'
1514
import { getLogger } from '../../shared/logger'
1615
import { createHelpButton } from '../../shared/ui/buttons'
@@ -35,7 +34,7 @@ import { minSamCliVersionForImageSupport } from '../../shared/sam/cli/samCliVali
3534
import { ExtContext } from '../../shared/extensions'
3635
import { validateBucketName } from '../../awsService/s3/util'
3736
import { showViewLogsMessage } from '../../shared/utilities/messages'
38-
import { getIdeProperties, isCloud9 } from '../../shared/extensionUtilities'
37+
import { getIdeProperties, getSamDeployDocUrl, isCloud9 } from '../../shared/extensionUtilities'
3938
import { recentlyUsed } from '../../shared/localizedText'
4039
import globals from '../../shared/extensionGlobals'
4140
import { SamCliSettings } from '../../shared/sam/cli/samCliSettings'
@@ -252,7 +251,7 @@ export class DefaultSamDeployWizardContext implements SamDeployWizardContext {
252251
if (button === vscode.QuickInputButtons.Back) {
253252
resolve(undefined)
254253
} else if (button === this.helpButton) {
255-
void openUrl(vscode.Uri.parse(samDeployDocUrl))
254+
void openUrl(getSamDeployDocUrl())
256255
}
257256
},
258257
})
@@ -292,7 +291,7 @@ export class DefaultSamDeployWizardContext implements SamDeployWizardContext {
292291
if (button === vscode.QuickInputButtons.Back) {
293292
resolve(undefined)
294293
} else if (button === this.helpButton) {
295-
void openUrl(vscode.Uri.parse(samDeployDocUrl))
294+
void openUrl(getSamDeployDocUrl())
296295
}
297296
},
298297
})
@@ -336,7 +335,7 @@ export class DefaultSamDeployWizardContext implements SamDeployWizardContext {
336335
if (button === vscode.QuickInputButtons.Back) {
337336
resolve(undefined)
338337
} else if (button === this.helpButton) {
339-
void openUrl(vscode.Uri.parse(samDeployDocUrl))
338+
void openUrl(getSamDeployDocUrl())
340339
}
341340
},
342341
})
@@ -385,7 +384,7 @@ export class DefaultSamDeployWizardContext implements SamDeployWizardContext {
385384
if (button === vscode.QuickInputButtons.Back) {
386385
resolve(undefined)
387386
} else if (button === this.helpButton) {
388-
void openUrl(vscode.Uri.parse(samDeployDocUrl))
387+
void openUrl(getSamDeployDocUrl())
389388
}
390389
},
391390
})
@@ -459,7 +458,7 @@ export class DefaultSamDeployWizardContext implements SamDeployWizardContext {
459458
if (button === vscode.QuickInputButtons.Back) {
460459
resolve(undefined)
461460
} else if (button === this.helpButton) {
462-
void openUrl(vscode.Uri.parse(samDeployDocUrl))
461+
void openUrl(getSamDeployDocUrl())
463462
} else if (button === createBucket) {
464463
resolve([{ label: CREATE_NEW_BUCKET }])
465464
} else if (button === enterBucket) {
@@ -515,7 +514,7 @@ export class DefaultSamDeployWizardContext implements SamDeployWizardContext {
515514
if (button === vscode.QuickInputButtons.Back) {
516515
resolve(undefined)
517516
} else if (button === this.helpButton) {
518-
void openUrl(vscode.Uri.parse(samDeployDocUrl))
517+
void openUrl(getSamDeployDocUrl())
519518
} else if (bucketProps.buttonHandler) {
520519
bucketProps.buttonHandler(button, inputBox, resolve, reject)
521520
}
@@ -559,7 +558,7 @@ export class DefaultSamDeployWizardContext implements SamDeployWizardContext {
559558
if (button === vscode.QuickInputButtons.Back) {
560559
resolve(undefined)
561560
} else if (button === this.helpButton) {
562-
void openUrl(vscode.Uri.parse(samDeployDocUrl))
561+
void openUrl(getSamDeployDocUrl())
563562
}
564563
},
565564
})
@@ -612,7 +611,7 @@ export class DefaultSamDeployWizardContext implements SamDeployWizardContext {
612611
if (button === vscode.QuickInputButtons.Back) {
613612
resolve(undefined)
614613
} else if (button === this.helpButton) {
615-
void openUrl(vscode.Uri.parse(samDeployDocUrl))
614+
void openUrl(getSamDeployDocUrl())
616615
}
617616
},
618617
})

packages/core/src/lambda/wizards/samInitWizard.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import * as path from 'path'
1010
import * as vscode from 'vscode'
1111
import { SchemasDataProvider } from '../../eventSchemas/providers/schemasDataProvider'
1212
import { DefaultSchemaClient } from '../../shared/clients/schemaClient'
13-
import { eventBridgeSchemasDocUrl, samInitDocUrl } from '../../shared/constants'
13+
import { eventBridgeSchemasDocUrl } from '../../shared/constants'
1414
import {
1515
Architecture,
1616
createRuntimeQuickPick,
@@ -37,6 +37,7 @@ import { Region } from '../../shared/regions/endpoints'
3737
import { createCommonButtons } from '../../shared/ui/buttons'
3838
import { createExitPrompter } from '../../shared/ui/common/exitPrompter'
3939
import { getNonexistentFilename } from '../../shared/filesystemUtilities'
40+
import { getSamInitDocUrl } from '../../shared/extensionUtilities'
4041

4142
const localize = nls.loadMessageBundle()
4243

@@ -55,7 +56,7 @@ export interface CreateNewSamAppWizardForm {
5556
function createRuntimePrompter(samCliVersion: string): QuickPickPrompter<RuntimeAndPackage> {
5657
return createRuntimeQuickPick({
5758
showImageRuntimes: semver.gte(samCliVersion, minSamCliVersionForImageSupport),
58-
buttons: createCommonButtons(samInitDocUrl),
59+
buttons: createCommonButtons(getSamInitDocUrl()),
5960
})
6061
}
6162

@@ -73,7 +74,7 @@ function createSamTemplatePrompter(
7374

7475
return createQuickPick(items, {
7576
title: localize('AWS.samcli.initWizard.template.prompt', 'Select a SAM Application Template'),
76-
buttons: createCommonButtons(samInitDocUrl),
77+
buttons: createCommonButtons(getSamInitDocUrl()),
7778
})
7879
}
7980

@@ -91,7 +92,7 @@ function createDependencyPrompter(currRuntime: Runtime): QuickPickPrompter<Depen
9192

9293
return createLabelQuickPick(items, {
9394
title: localize('AWS.samcli.initWizard.dependencyManager.prompt', 'Select a Dependency Manager'),
94-
buttons: createCommonButtons(samInitDocUrl),
95+
buttons: createCommonButtons(getSamInitDocUrl()),
9596
})
9697
}
9798

@@ -117,7 +118,7 @@ function createRegistryPrompter(region: string, credentials?: AWS.Credentials):
117118

118119
return createLabelQuickPick(items, {
119120
title: localize('AWS.samcli.initWizard.schemas.registry.prompt', 'Select a Registry'),
120-
buttons: createCommonButtons(samInitDocUrl),
121+
buttons: createCommonButtons(getSamInitDocUrl()),
121122
})
122123
}
123124

@@ -179,15 +180,15 @@ function createNamePrompter(defaultValue: string): InputBoxPrompter {
179180
return createInputBox({
180181
value: defaultValue,
181182
title: localize('AWS.samcli.initWizard.name.prompt', 'Enter a name for your new application'),
182-
buttons: createCommonButtons(samInitDocUrl),
183+
buttons: createCommonButtons(getSamInitDocUrl()),
183184
validateInput: validateName,
184185
})
185186
}
186187

187188
function createArchitecturePrompter(): QuickPickPrompter<Architecture> {
188189
return createLabelQuickPick<Architecture>([{ label: 'x86_64' }, { label: 'arm64' }], {
189190
title: localize('AWS.samcli.initWizard.architecture.prompt', 'Select an Architecture'),
190-
buttons: createCommonButtons(samInitDocUrl),
191+
buttons: createCommonButtons(getSamInitDocUrl()),
191192
})
192193
}
193194

@@ -266,7 +267,7 @@ export class CreateNewSamAppWizard extends Wizard<CreateNewSamAppWizardForm> {
266267

267268
this.form.location.bindPrompter(() =>
268269
createFolderPrompt(vscode.workspace.workspaceFolders ?? [], {
269-
buttons: createCommonButtons(samInitDocUrl),
270+
buttons: createCommonButtons(getSamInitDocUrl()),
270271
title: localize('AWS.samInit.location.title', 'Select the folder for your new SAM application'),
271272
browseFolderDetail: localize(
272273
'AWS.samInit.location.detail',

0 commit comments

Comments
 (0)