Skip to content

Commit bc56e36

Browse files
Simplify bundle handling for uriHandler (#1832)
- Move the bundle building to a postbuild command that always runs instead of people having to run build:bundle. - Consolidate the bundle-nodescript.ps1 logic into build.ps1
1 parent 817ddac commit bc56e36

File tree

5 files changed

+43
-87
lines changed

5 files changed

+43
-87
lines changed

dotnet/agentLauncher/src/Build.ps1

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ $projectFile = Join-Path $scriptDir "AgentLauncher.csproj"
1212
$configuration = "Debug"
1313
$platform = "x64"
1414

15+
# Calculate paths for uriHandler bundle
16+
$uriHandlerPath = Join-Path $scriptDir "..\..\..\ts\packages\uriHandler" | Resolve-Path -ErrorAction SilentlyContinue
17+
$bundleOutput = if ($uriHandlerPath) { Join-Path $uriHandlerPath "bundle\agent-uri-handler.bundle.js" } else { $null }
18+
$targetDir = Join-Path $scriptDir "Scripts"
19+
$targetPath = Join-Path $targetDir "agent-uri-handler.bundle.js"
20+
1521
# Find MSBuild
1622
$msbuildPath2022 = "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\MSBuild.exe";
1723
$msbuildPath2026 = "C:\Program Files\Microsoft Visual Studio\18\Enterprise\MSBuild\Current\Bin\MSBuild.exe";
@@ -34,14 +40,46 @@ Write-Host " Configuration: $configuration"
3440
Write-Host " Platform: $platform"
3541
Write-Host ""
3642

43+
# Copy bundle from uriHandler
44+
Write-Host "Step 1: Copying uriHandler bundle..." -ForegroundColor Yellow
45+
if (-not $bundleOutput -or -not (Test-Path $bundleOutput)) {
46+
Write-Host ""
47+
Write-Host "ERROR: Bundle file not found at: $bundleOutput" -ForegroundColor Red
48+
Write-Host ""
49+
Write-Host "You must first build the uriHandler package:" -ForegroundColor Yellow
50+
if ($uriHandlerPath) {
51+
Write-Host " 1. Navigate to: $uriHandlerPath" -ForegroundColor Cyan
52+
} else {
53+
Write-Host " 1. Navigate to the uriHandler package directory" -ForegroundColor Cyan
54+
}
55+
Write-Host " 2. Run: pnpm run build" -ForegroundColor Cyan
56+
Write-Host ""
57+
exit 1
58+
}
59+
60+
$bundleSize = (Get-Item $bundleOutput).Length
61+
$bundleSizeKB = [Math]::Round($bundleSize / 1KB, 2)
62+
Write-Host " Bundle found: $bundleSizeKB KB at $bundleOutput" -ForegroundColor Green
63+
64+
New-Item -ItemType Directory -Force -Path $targetDir | Out-Null
65+
Copy-Item $bundleOutput $targetPath -Force
66+
67+
if (Test-Path $targetPath) {
68+
Write-Host " Bundle copied successfully to: $targetPath" -ForegroundColor Green
69+
} else {
70+
Write-Host " ERROR: Failed to copy bundle" -ForegroundColor Red
71+
exit 1
72+
}
73+
Write-Host ""
74+
3775
# Clean previous build
38-
Write-Host "Step 1: Cleaning previous build..." -ForegroundColor Yellow
76+
Write-Host "Step 2: Cleaning previous build..." -ForegroundColor Yellow
3977
Remove-Item -Recurse -Force obj,bin -ErrorAction SilentlyContinue
4078
Write-Host " Clean complete" -ForegroundColor Green
4179
Write-Host ""
4280

4381
# Build
44-
Write-Host "Step 2: Building project..." -ForegroundColor Yellow
82+
Write-Host "Step 3: Building project..." -ForegroundColor Yellow
4583
$buildArgs = @(
4684
$projectFile,
4785
"-t:Restore,Build",
@@ -62,7 +100,7 @@ Write-Host " Build complete" -ForegroundColor Green
62100
Write-Host ""
63101

64102
# Package
65-
Write-Host "Step 3: Creating MSIX package..." -ForegroundColor Yellow
103+
Write-Host "Step 4: Creating MSIX package..." -ForegroundColor Yellow
66104
$packageArgs = @(
67105
$projectFile,
68106
"-t:_GenerateAppxPackage",

dotnet/agentLauncher/src/Bundle-NodeScript.ps1

Lines changed: 0 additions & 71 deletions
This file was deleted.

ts/.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ pnpm-lock.yaml
1212
.rollup.cache/**
1313
.tsc-cache-*.json
1414
.frontend-build-cache.json
15+
packages/uriHandler/bundle/agent-uri-handler.bundle.js
1516

1617
.scratch
1718

ts/packages/uriHandler/bundle-config.js

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ import { dirname, join } from "path";
77

88
const __dirname = dirname(fileURLToPath(import.meta.url));
99

10-
console.log("TypeAgent URI Handler - Bundle Configuration");
11-
console.log("===========================================\n");
12-
1310
const config = {
1411
entryPoints: [join(__dirname, "dist", "index.js")],
1512
bundle: true,
@@ -45,14 +42,6 @@ const require = createRequire(import.meta.url);
4542
],
4643
};
4744

48-
console.log("Configuration:");
49-
console.log(` Entry: ${config.entryPoints[0]}`);
50-
console.log(` Output: ${config.outfile}`);
51-
console.log(` Platform: ${config.platform}`);
52-
console.log(` Format: ${config.format}`);
53-
console.log(` Target: ${config.target}`);
54-
console.log("");
55-
5645
try {
5746
await esbuild.build(config);
5847
console.log("\n✓ Bundle created successfully");

ts/packages/uriHandler/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818
},
1919
"scripts": {
2020
"build": "npm run tsc",
21-
"build:bundle": "npm run build && npm run bundle",
22-
"bundle": "node bundle-config.js",
21+
"postbuild": "node bundle-config.js",
2322
"clean": "rimraf --glob dist bundle *.tsbuildinfo *.done.build.log",
2423
"prettier": "prettier --check . --ignore-path ../../.prettierignore",
2524
"prettier:fix": "prettier --write . --ignore-path ../../.prettierignore",

0 commit comments

Comments
 (0)