@@ -146,36 +146,56 @@ export function hasSageMakerEnvVars(): boolean {
146
146
/**
147
147
* Checks if the current environment is running on Amazon Linux 2.
148
148
*
149
- * This function attempts to detect if we're running in a container on an AL2 host
150
- * by checking both the OS release and container-specific indicators .
149
+ * This function detects if we're actually running on AL2, not just if the host is AL2.
150
+ * In containerized environments, we check the container's OS, not the host's .
151
151
*
152
152
* Example: `5.10.220-188.869.amzn2int.x86_64` or `5.10.236-227.928.amzn2.x86_64` (Cloud Dev Machine)
153
153
*/
154
154
export function isAmazonLinux2 ( ) {
155
+ // Skip AL2 detection for web environments
156
+ // In web mode, we're running in a browser, not on AL2
157
+ if ( isWeb ( ) ) {
158
+ return false
159
+ }
160
+
155
161
// First check if we're in a SageMaker environment, which should not be treated as AL2
156
162
// even if the underlying host is AL2
157
163
if ( hasSageMakerEnvVars ( ) ) {
158
164
return false
159
165
}
160
166
161
- // Check if we're in a container environment that's not AL2
162
- if ( process . env . container === 'docker' || process . env . DOCKER_HOST || process . env . DOCKER_BUILDKIT ) {
163
- // Additional check for container OS - if we can determine it's not AL2
164
- try {
165
- const fs = require ( 'fs' )
166
- if ( fs . existsSync ( '/etc/os-release' ) ) {
167
- const osRelease = fs . readFileSync ( '/etc/os-release' , 'utf8' )
168
- if ( ! osRelease . includes ( 'Amazon Linux 2' ) && ! osRelease . includes ( 'amzn2' ) ) {
169
- return false
170
- }
167
+ // For containerized environments, check the actual container OS
168
+ // not the host kernel version
169
+ try {
170
+ const fs = require ( 'fs' )
171
+ if ( fs . existsSync ( '/etc/os-release' ) ) {
172
+ const osRelease = fs . readFileSync ( '/etc/os-release' , 'utf8' )
173
+ // Check if this is actually Amazon Linux 2
174
+ const isAL2 =
175
+ osRelease . includes ( 'Amazon Linux 2' ) ||
176
+ ( osRelease . includes ( 'ID="amzn"' ) && osRelease . includes ( 'VERSION_ID="2"' ) )
177
+
178
+ // If we found os-release file, trust its content over kernel version
179
+ if ( ! isAL2 ) {
180
+ // Explicitly not AL2 based on os-release
181
+ return false
171
182
}
172
- } catch ( e ) {
173
- // If we can't read the file, fall back to the os.release() check
183
+ // If it is AL2 according to os-release, continue to kernel check for confirmation
174
184
}
185
+ } catch ( e ) {
186
+ // If we can't read the file, fall back to the os.release() check
187
+ // This might happen in some restricted environments
188
+ getLogger ( ) . error ( `Checking the current environment failed with error: ${ e } ` )
175
189
}
176
190
177
- // Standard check for AL2 in the OS release string
178
- return ( os . release ( ) . includes ( '.amzn2int.' ) || os . release ( ) . includes ( '.amzn2.' ) ) && process . platform === 'linux'
191
+ // Check kernel version as a fallback or confirmation
192
+ // This should only be trusted if we couldn't determine from /etc/os-release
193
+ // or if /etc/os-release confirmed it's AL2
194
+ const kernelRelease = os . release ( )
195
+ const hasAL2Kernel =
196
+ ( kernelRelease . includes ( '.amzn2int.' ) || kernelRelease . includes ( '.amzn2.' ) ) && process . platform === 'linux'
197
+
198
+ return hasAL2Kernel
179
199
}
180
200
181
201
/**
@@ -217,9 +237,9 @@ export function getExtRuntimeContext(): {
217
237
extensionHost : ExtensionHostLocation
218
238
} {
219
239
const extensionHost =
220
- // taken from https://github.com/microsoft/vscode/blob/7c9e4bb23992c63f20cd86bbe7a52a3aa4bed89d/extensions/github-authentication/src/githubServer.ts#L121 to help determine which auth flows
221
- // should be used
222
- typeof navigator === 'undefined'
240
+ // Check if we're in a Node.js environment (desktop/remote) vs web worker
241
+ // Updated to be compatible with Node.js v22 which includes navigator global
242
+ typeof process === 'object' && process . versions ?. node
223
243
? globals . context . extension . extensionKind === vscode . ExtensionKind . UI
224
244
? 'local'
225
245
: 'remote'
0 commit comments