|
13 | 13 | ?? throw new InvalidOperationException("Could not find repository root"); |
14 | 14 | } |
15 | 15 |
|
16 | | -var astroDir = Path.Combine(repoRoot, "astro"); |
17 | 16 | var serverDir = Path.Combine(repoRoot, "server"); |
18 | 17 | var wwwrootDir = Path.Combine(serverDir, "Docs.Web", "wwwroot"); |
19 | 18 |
|
20 | 19 | // Target names |
21 | 20 | const string Restore = "restore"; |
22 | | -const string AstroInstall = "astro-install"; |
23 | 21 | const string AstroBuild = "astro-build"; |
24 | 22 | const string DotnetBuild = "dotnet-build"; |
25 | 23 | const string DotnetPublish = "dotnet-publish"; |
|
31 | 29 | const string Clean = "clean"; |
32 | 30 | const string Default = "default"; |
33 | 31 |
|
34 | | -// Restore/Install |
| 32 | +// Restore |
35 | 33 | Target(Restore, () => |
36 | 34 | RunAsync("dotnet", "restore Docs.slnx", workingDirectory: serverDir)); |
37 | 35 |
|
38 | | -// Use 'npm install' instead of 'npm ci' due to npm bug with optional dependencies on Windows |
39 | | -// See: https://github.com/npm/cli/issues/4828 |
40 | | -Target(AstroInstall, () => |
41 | | - RunAsync("npm", "install", workingDirectory: astroDir)); |
42 | | - |
43 | | -// Build |
44 | | -Target(AstroBuild, dependsOn: [AstroInstall], () => |
45 | | - RunAsync("npm", "run build -- --outDir ../server/Docs.Web/wwwroot", workingDirectory: astroDir)); |
| 36 | +// Astro build in container - avoids Windows npm issues with platform-specific dependencies |
| 37 | +Target(AstroBuild, async () => |
| 38 | +{ |
| 39 | + // Ensure output directory exists |
| 40 | + Directory.CreateDirectory(wwwrootDir); |
| 41 | + |
| 42 | + // Convert Windows paths to Docker-compatible format (forward slashes) |
| 43 | + var astroPath = Path.Combine(repoRoot, "astro").Replace('\\', '/'); |
| 44 | + var outputPath = wwwrootDir.Replace('\\', '/'); |
| 45 | + |
| 46 | + // Use Docker to build Astro - consistent across all platforms |
| 47 | + // Use Debian-based image (not Alpine) for better compatibility with native modules |
| 48 | + // Increase Node.js memory limit to handle large builds |
| 49 | + await RunAsync("docker", |
| 50 | + "run --rm " + |
| 51 | + $"-v \"{astroPath}:/app\" " + |
| 52 | + $"-v \"{outputPath}:/output\" " + |
| 53 | + "-w /app " + |
| 54 | + "-e NODE_OPTIONS=\"--max-old-space-size=4096\" " + |
| 55 | + "node:22-slim " + |
| 56 | + "sh -c \"npm ci && npm run build -- --outDir /output\"", |
| 57 | + configureEnvironment: env => env.Add("MSYS_NO_PATHCONV", "1")); |
| 58 | +}); |
46 | 59 |
|
47 | 60 | Target(DotnetBuild, dependsOn: [Restore], () => |
48 | 61 | RunAsync("dotnet", "build Docs.slnx --no-restore", workingDirectory: serverDir)); |
|
0 commit comments