Skip to content

Commit a6e59eb

Browse files
authored
Merge pull request #355 from rajbos/devContainerMount
devContainerMount
2 parents 6ed36a0 + 5130b70 commit a6e59eb

File tree

2 files changed

+71
-1
lines changed

2 files changed

+71
-1
lines changed

.devcontainer/devcontainer.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,16 @@
1919
"editor.formatOnSave": true,
2020
"editor.defaultFormatter": "esbenp.prettier-vscode",
2121
"eslint.enable": true,
22-
"typescript.tsdk": "node_modules/typescript/lib"
22+
"typescript.tsdk": "node_modules/typescript/lib",
23+
"chat.tools.autoApprove": true
2324
}
2425
}
2526
},
27+
"initializeCommand": "powershell -ExecutionPolicy Bypass -File .devcontainer/init-mounts.ps1",
28+
"mounts": [
29+
"source=${localEnv:APPDATA}/Code/User,target=/home/node/.config/Code/User,type=bind,readonly=true",
30+
"source=${localEnv:APPDATA}/Code - Insiders/User,target=/home/node/.config/Code - Insiders/User,type=bind,readonly=true"
31+
],
2632
"postCreateCommand": "npm ci",
2733
"remoteUser": "node"
2834
}

.devcontainer/init-mounts.ps1

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Ensures host directories used as devcontainer bind mounts exist before Docker tries to mount them.
2+
# If "Code - Insiders" is not installed, we create an empty directory so the mount succeeds;
3+
# the extension then falls back to the always-present "Code" (stable) data automatically.
4+
5+
# ── Detect which VS Code edition launched this devcontainer ──────────────────
6+
$launchedFrom = "Unknown"
7+
8+
# $env:VSCODE_PID is set by VS Code in its integrated terminal / task runner.
9+
# Use it to look up the executable path of the launching process.
10+
if ($env:VSCODE_PID) {
11+
try {
12+
$vsProc = Get-Process -Id $env:VSCODE_PID -ErrorAction Stop
13+
$exePath = $vsProc.MainModule.FileName
14+
if ($exePath -match 'Insiders') {
15+
$launchedFrom = "Code - Insiders"
16+
} else {
17+
$launchedFrom = "Code"
18+
}
19+
Write-Host "Detected VS Code edition from PID $($env:VSCODE_PID): $launchedFrom ($exePath)"
20+
} catch {
21+
Write-Host "Could not resolve VSCODE_PID $($env:VSCODE_PID): $_"
22+
}
23+
}
24+
25+
# Fallback: scan running processes for Code/Code-Insiders executables
26+
if ($launchedFrom -eq "Unknown") {
27+
$insidersRunning = Get-Process -ErrorAction SilentlyContinue |
28+
Where-Object { try { $_.MainModule.FileName -match 'Code.*Insiders' } catch { $false } } |
29+
Select-Object -First 1
30+
31+
$stableRunning = Get-Process -ErrorAction SilentlyContinue |
32+
Where-Object { try { $_.MainModule.FileName -match '\\Code\\' } catch { $false } } |
33+
Select-Object -First 1
34+
35+
if ($insidersRunning) {
36+
$launchedFrom = "Code - Insiders (detected from running process)"
37+
} elseif ($stableRunning) {
38+
$launchedFrom = "Code (detected from running process)"
39+
} else {
40+
$launchedFrom = "Could not detect (no Code process found; defaulting to stable)"
41+
}
42+
Write-Host "VS Code edition (fallback detection): $launchedFrom"
43+
}
44+
45+
$activeSubPath = if ($launchedFrom -match 'Insiders') { "Code - Insiders\User" } else { "Code\User" }
46+
$activePath = Join-Path $env:APPDATA $activeSubPath
47+
Write-Host "Active VS Code session data: $activePath"
48+
49+
# ── Ensure both mount source directories exist ───────────────────────────────
50+
$stablePath = Join-Path $env:APPDATA "Code\User"
51+
$insidersPath = Join-Path $env:APPDATA "Code - Insiders\User"
52+
53+
foreach ($entry in @(
54+
@{ Path = $stablePath; Label = "Code (stable)" },
55+
@{ Path = $insidersPath; Label = "Code - Insiders" }
56+
)) {
57+
if (-not (Test-Path $entry.Path)) {
58+
Write-Host "$($entry.Label) not found at '$($entry.Path)'. Creating empty directory so the bind mount does not fail."
59+
New-Item -ItemType Directory -Force $entry.Path | Out-Null
60+
} else {
61+
$marker = if ($entry.Path -eq $activePath) { " ← active" } else { "" }
62+
Write-Host "$($entry.Label) found at '$($entry.Path)'.$marker"
63+
}
64+
}

0 commit comments

Comments
 (0)