appservice: Enforce lazy loading of @azure dependencies (and more)#2188
appservice: Enforce lazy loading of @azure dependencies (and more)#2188bwateratmsft wants to merge 11 commits intomainfrom
@azure dependencies (and more)#2188Conversation
This comment was marked as resolved.
This comment was marked as resolved.
@azure dependencies@azure dependencies (and more)
There was a problem hiding this comment.
Pull request overview
This PR focuses on reducing startup cost by enforcing lazy-loading of heavy dependencies (notably @azure/*) across the appservice package, alongside dependency upgrades and type-import cleanup.
Changes:
- Convert many
@azure/*and related imports toimport typeand/or switch to dynamic imports to avoid eager module loading. - Update
appservicedependencies/devDependencies (Azure SDKs,p-retry,simple-git,ws, etc.) and adjust code for API/type changes. - Add an ESLint flat-config rule (
lazyImportRuleConfig) to enforce lazy-loading patterns moving forward.
Reviewed changes
Copilot reviewed 41 out of 42 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| appservice/src/verifyNoRunFromPackageSetting.ts | Removes eager type import; relies on inferred return type from client call. |
| appservice/src/utils/azureUtils.ts | Changes AzExtPipelineResponse to a type-only import. |
| appservice/src/utils/azureClients.ts | Adds stricter typing helpers for lazy-loaded Azure clients (incl. subscription client type). |
| appservice/src/tree/DeploymentsTreeItem.ts | Removes eager ARM type imports; relies on inferred types. |
| appservice/src/tree/DeploymentTreeItem.ts | Removes eager ARM type import; relies on inferred type. |
| appservice/src/swapSlot.ts | Removes eager ARM client type import; relies on inferred type. |
| appservice/src/startStreamingLogs.ts | Drops @azure/abort-controller import and uses global AbortController. |
| appservice/src/siteFiles.ts | Updates to p-retry v7 APIs (AbortError import). |
| appservice/src/remoteDebug/startRemoteDebug.ts | Converts Azure utils import to type-only. |
| appservice/src/github/connectToGitHub.ts | Uses inline type import for GitHubContext. |
| appservice/src/extensionVariables.ts | Removes GitHub extension variable registration; aligns extension vars interface with current UIExtensionVariables. |
| appservice/src/editScmType.ts | Removes eager ARM type imports; relies on inferred types. |
| appservice/src/disconnectRepo.ts | Removes eager ARM type import; relies on inferred type. |
| appservice/src/deploy/wizard/deployZip/DeployZipPushExecuteStep.ts | Converts AzExtPipelineResponse to type-only import. |
| appservice/src/deploy/wizard/deployZip/DeployZipBaseExecuteStep.ts | Converts AzExtPipelineResponse to type-only import. |
| appservice/src/deploy/wizard/deployZip/DeployFlexExecuteStep.ts | Converts ARM Site import to type-only. |
| appservice/src/deploy/wizard/deployZip/DelayFirstWebAppDeployStep.ts | Removes eager ARM plan type import; relies on inferred types. |
| appservice/src/deploy/wizard/createDeployWizard.ts | Removes eager ARM type import; relies on inferred types. |
| appservice/src/deploy/wizard/PostDeployTaskExecuteStep.ts | Converts ARM SiteConfig import to type-only. |
| appservice/src/deploy/wizard/DeployExecuteStepBase.ts | Converts ARM imports to type-only; relies more on inference. |
| appservice/src/deploy/runWithZipStream.ts | Converts AzExtPipelineResponse import to type-only. |
| appservice/src/deploy/localGitDeploy.ts | Switches simple-git to dynamic import to support lazy-loading. |
| appservice/src/deploy/deployToStorageAccount.ts | Switches @azure/storage-blob to dynamic import and removes eager SDK imports. |
| appservice/src/deploy/deploy.ts | Removes eager ARM type import; relies on inferred promise type. |
| appservice/src/deploy/IDeployContext.ts | Converts ARM AppServicePlan import to type-only. |
| appservice/src/createSlot.ts | Removes eager ARM client/type imports; relies on inferred types and shared helpers. |
| appservice/src/createAppService/setLocationsTask.ts | Removes explicit type in map callback; relies on inference. |
| appservice/src/createAppService/getAppInsightsSupportedLocation.ts | Removes eager ARM/core-client type imports; relies on inference. |
| appservice/src/createAppService/SiteNameStep.ts | Removes some explicit ARM types; relies on inference for ARM responses. |
| appservice/src/createAppService/IAppServiceWizardContext.ts | Converts azureutils wizard context imports to type-only. |
| appservice/src/createAppService/AppServicePlanSkuStep.ts | Removes unused ARM type import; relies on inference. |
| appservice/src/createAppService/AppServicePlanRedundancyStep.ts | Converts imports to type-only. |
| appservice/src/createAppService/AppServicePlanListStep.ts | Removes explicit ARM client type usage; relies on inference. |
| appservice/src/createAppService/AppServicePlanCreateStep.ts | Removes explicit ARM client typing; relies on inference. |
| appservice/src/createAppService/AppInsightsNameStep.ts | Removes explicit ARM type annotation; relies on inference. |
| appservice/src/createAppService/AppInsightsListStep.ts | Removes explicit AI client type annotation; relies on inference. |
| appservice/src/createAppService/AppInsightsCreateStep.ts | Removes explicit AI/RG type annotations; relies on inference. |
| appservice/src/TunnelProxy.ts | Lazily imports ws at runtime; keeps only type import at top-level. |
| appservice/src/SiteClient.ts | Removes explicit ServiceClient typing; relies on inference from createGenericClient. |
| appservice/package.json | Bumps version and updates runtime/dev dependencies to newer releases. |
| appservice/eslint.config.mjs | Adds lazy-import enforcement via lazyImportRuleConfig in flat ESLint config. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| }; | ||
|
|
||
| export async function localGitDeploy(site: ParsedSite, options: LocalGitOptions, context: IActionContext): Promise<void> { | ||
| const { simpleGit } = await import('simple-git'); |
There was a problem hiding this comment.
simple-git was previously consumed via a default import, but this change destructures simpleGit from the dynamic import. For CommonJS/default-export interop, await import('simple-git') typically exposes the function on the module’s default export, so simpleGit may be undefined at runtime (especially in the CJS build). Update the lazy import to read the default export (or otherwise handle both default/named export shapes) before calling it.
| const { simpleGit } = await import('simple-git'); | |
| const simpleGitModule = await import('simple-git'); | |
| const simpleGit = (simpleGitModule as any).default ?? (simpleGitModule as any).simpleGit ?? simpleGitModule; |
| }; | ||
|
|
||
| export async function localGitDeploy(site: ParsedSite, options: LocalGitOptions, context: IActionContext): Promise<void> { | ||
| const { simpleGit } = await import('simple-git'); |
| } | ||
|
|
||
| private async setupTunnelServer(bearerToken: string, token: CancellationToken): Promise<void> { | ||
| const ws = await import('ws'); |
There was a problem hiding this comment.
Check this import too.
| import { AzExtPipelineResponse, createGenericClient } from '@microsoft/vscode-azext-azureutils'; | ||
| import { IActionContext, IParsedError, parseError } from '@microsoft/vscode-azext-utils'; | ||
| import retry from 'p-retry'; | ||
| import { AbortError, default as retry } from 'p-retry'; |
There was a problem hiding this comment.
Should be OK since this isn't an await import but verify.
Also updates dependencies, clears some unnecessary type imports (which will help if we do the
@azure-restpackage), and so on.TODO:
All three have ESM variants so I don't think there will be a problem, but worth verifying.