Skip to content

Commit 693e81b

Browse files
JesseColnmetulev
andauthored
Revert the change to use ".winappglobal" for the global winapp dir (#190)
This makes it so WinAppCLI's global dir uses "$userProfile/.winapp" again by default instead of ".winappglobal". Using ".winappglobal" was getting too complicated, and I don't have time to see it through right now. Instead: * Make all the tests use a different dir for the global vs local * Add a test to make sure we never return the global dir as the local dir This change reverts #178 This is meant as a replacement for #186 --------- Co-authored-by: Nikola Metulev <[email protected]>
1 parent f74b7e1 commit 693e81b

File tree

8 files changed

+63
-50
lines changed

8 files changed

+63
-50
lines changed

docs/usage.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -482,20 +482,20 @@ All commands support these global options:
482482

483483
Winapp creates a directory to cache files that can be shared between multiple projects.
484484

485-
By default, winapp creates a directory at `$UserProfile/.winappglobal` as the global cache directory.
485+
By default, winapp creates a directory at `$UserProfile/.winapp` as the global cache directory.
486486

487487
To use a different location, set the `WINAPP_CLI_CACHE_DIRECTORY` environment variable.
488488

489489
In **cmd**:
490490
```cmd
491491
REM Set a custom location for winapp's global cache
492-
set WINAPP_CLI_CACHE_DIRECTORY=d:\temp\.winappglobal
492+
set WINAPP_CLI_CACHE_DIRECTORY=d:\temp\.winapp
493493
```
494494

495495
In **Powershell** and **pwsh**:
496496
```pwsh
497497
# Set a custom location for winapp's global cache
498-
$env:WINAPP_CLI_CACHE_DIRECTORY=d:\temp\.winappglobal
498+
$env:WINAPP_CLI_CACHE_DIRECTORY=d:\temp\.winapp
499499
```
500500

501501
Winapp will create this directory automatically when you run commands like `init` or `restore`.

src/winapp-CLI/WinApp.Cli.Tests/BaseCommandTests.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public abstract class BaseCommandTests(bool configPaths = true)
1212
{
1313
private protected DirectoryInfo _tempDirectory = null!;
1414
private protected DirectoryInfo _testWinappDirectory = null!;
15-
private protected DirectoryInfo _testGlobalDirectory = null!;
15+
private protected DirectoryInfo _testCacheDirectory = null!;
1616
private protected IConfigService _configService = null!;
1717
private protected IBuildToolsService _buildToolsService = null!;
1818

@@ -57,10 +57,9 @@ public void SetupBase()
5757
_configService = GetRequiredService<IConfigService>();
5858
_configService.ConfigPath = new FileInfo(Path.Combine(_tempDirectory.FullName, "winapp.yaml"));
5959

60-
_testGlobalDirectory = _tempDirectory.CreateSubdirectory(".winappglobal");
61-
6260
var directoryService = GetRequiredService<IWinappDirectoryService>();
63-
directoryService.SetCacheDirectoryForTesting(_testGlobalDirectory);
61+
_testCacheDirectory = _tempDirectory.CreateSubdirectory(".winappcache");
62+
directoryService.SetCacheDirectoryForTesting(_testCacheDirectory);
6463
_buildToolsService = GetRequiredService<IBuildToolsService>();
6564
}
6665
}

src/winapp-CLI/WinApp.Cli.Tests/BuildToolsServiceTests.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public void BuildToolsService_WithTestCacheDirectory_UsesOverriddenDirectory()
2323
Assert.IsNull(result);
2424

2525
// Additional verification: Create a fake bin directory structure and verify it's found
26-
var packagesDir = Path.Combine(_testGlobalDirectory.FullName, "packages");
26+
var packagesDir = Path.Combine(_testCacheDirectory.FullName, "packages");
2727
var buildToolsPackageDir = Path.Combine(packagesDir, "Microsoft.Windows.SDK.BuildTools.10.0.26100.1");
2828
var binDir = Path.Combine(buildToolsPackageDir, "bin", "10.0.26100.0", "x64");
2929
Directory.CreateDirectory(binDir);
@@ -40,7 +40,7 @@ public void BuildToolsService_WithTestCacheDirectory_UsesOverriddenDirectory()
4040
public void GetBuildToolPath_WithNonExistentTool_ReturnsNull()
4141
{
4242
// Arrange - Create package structure but without the requested tool
43-
var packagesDir = Path.Combine(_testGlobalDirectory.FullName, "packages");
43+
var packagesDir = Path.Combine(_testCacheDirectory.FullName, "packages");
4444
var buildToolsPackageDir = Path.Combine(packagesDir, "Microsoft.Windows.SDK.BuildTools.10.0.26100.1");
4545
var binDir = Path.Combine(buildToolsPackageDir, "bin", "10.0.26100.0", "x64");
4646
Directory.CreateDirectory(binDir);
@@ -59,7 +59,7 @@ public void GetBuildToolPath_WithNonExistentTool_ReturnsNull()
5959
public void GetBuildToolPath_WithMultipleVersions_ReturnsLatestVersion()
6060
{
6161
// Arrange - Create multiple package versions
62-
var packagesDir = Path.Combine(_testGlobalDirectory.FullName, "packages");
62+
var packagesDir = Path.Combine(_testCacheDirectory.FullName, "packages");
6363

6464
// Create older version
6565
var olderPackageDir = Path.Combine(packagesDir, "Microsoft.Windows.SDK.BuildTools.10.0.22000.1");
@@ -86,7 +86,7 @@ public void GetBuildToolPath_WithMultipleVersions_ReturnsLatestVersion()
8686
public void GetBuildToolPath_WithPinnedVersion_ReturnsPinnedVersion()
8787
{
8888
// Arrange - Create multiple package versions
89-
var packagesDir = Path.Combine(_testGlobalDirectory.FullName, "packages");
89+
var packagesDir = Path.Combine(_testCacheDirectory.FullName, "packages");
9090

9191
// Create older version
9292
var olderPackageDir = Path.Combine(packagesDir, "Microsoft.Windows.SDK.BuildTools.10.0.22000.1742");
@@ -122,7 +122,7 @@ public void GetBuildToolPath_WithPinnedVersion_ReturnsPinnedVersion()
122122
public void GetBuildToolPath_WithMultipleArchitectures_ReturnsCorrectArchitecture()
123123
{
124124
// Arrange - Create package with multiple architectures
125-
var packagesDir = Path.Combine(_testGlobalDirectory.FullName, "packages");
125+
var packagesDir = Path.Combine(_testCacheDirectory.FullName, "packages");
126126
var buildToolsPackageDir = Path.Combine(packagesDir, "Microsoft.Windows.SDK.BuildTools.10.0.26100.1");
127127
var binVersionDir = Path.Combine(buildToolsPackageDir, "bin", "10.0.26100.0");
128128

@@ -149,7 +149,7 @@ public void GetBuildToolPath_WithMultipleArchitectures_ReturnsCorrectArchitectur
149149
public async Task RunBuildToolAsync_WithValidTool_ReturnsOutput()
150150
{
151151
// Arrange - Create a fake tool that outputs to stdout
152-
var packagesDir = Path.Combine(_testGlobalDirectory.FullName, "packages");
152+
var packagesDir = Path.Combine(_testCacheDirectory.FullName, "packages");
153153
var buildToolsPackageDir = Path.Combine(packagesDir, "Microsoft.Windows.SDK.BuildTools.10.0.26100.1");
154154
var binDir = Path.Combine(buildToolsPackageDir, "bin", "10.0.26100.0", "x64");
155155
Directory.CreateDirectory(binDir);
@@ -198,7 +198,7 @@ public async Task EnsureBuildToolsAsync_WithNoExistingPackage_ShouldAttemptInsta
198198
public async Task EnsureBuildToolsAsync_WithExistingPackage_ReturnsExistingPath()
199199
{
200200
// Arrange - Create existing package structure
201-
var packagesDir = Path.Combine(_testGlobalDirectory.FullName, "packages");
201+
var packagesDir = Path.Combine(_testCacheDirectory.FullName, "packages");
202202
var buildToolsPackageDir = Path.Combine(packagesDir, "Microsoft.Windows.SDK.BuildTools.10.0.26100.1");
203203
var binDir = Path.Combine(buildToolsPackageDir, "bin", "10.0.26100.0", "x64");
204204
Directory.CreateDirectory(binDir);
@@ -214,7 +214,7 @@ public async Task EnsureBuildToolsAsync_WithExistingPackage_ReturnsExistingPath(
214214
public async Task EnsureBuildToolsAsync_WithForceLatest_ShouldAttemptReinstallation()
215215
{
216216
// Arrange - Create existing package structure
217-
var packagesDir = Path.Combine(_testGlobalDirectory.FullName, "packages");
217+
var packagesDir = Path.Combine(_testCacheDirectory.FullName, "packages");
218218
var buildToolsPackageDir = Path.Combine(packagesDir, "Microsoft.Windows.SDK.BuildTools.10.0.26100.1");
219219
var binDir = Path.Combine(buildToolsPackageDir, "bin", "10.0.26100.0", "x64");
220220
Directory.CreateDirectory(binDir);
@@ -231,7 +231,7 @@ public async Task EnsureBuildToolsAsync_WithForceLatest_ShouldAttemptReinstallat
231231
public async Task EnsureBuildToolAvailableAsync_WithExistingTool_ReturnsToolPath()
232232
{
233233
// Arrange - Create package structure with a tool
234-
var packagesDir = Path.Combine(_testGlobalDirectory.FullName, "packages");
234+
var packagesDir = Path.Combine(_testCacheDirectory.FullName, "packages");
235235
var buildToolsPackageDir = Path.Combine(packagesDir, "Microsoft.Windows.SDK.BuildTools.10.0.26100.1");
236236
var binDir = Path.Combine(buildToolsPackageDir, "bin", "10.0.26100.0", "x64");
237237
Directory.CreateDirectory(binDir);
@@ -250,7 +250,7 @@ public async Task EnsureBuildToolAvailableAsync_WithExistingTool_ReturnsToolPath
250250
public async Task EnsureBuildToolAvailableAsync_WithToolNameWithoutExtension_AddsExtensionAndReturnsPath()
251251
{
252252
// Arrange - Create package structure with a tool
253-
var packagesDir = Path.Combine(_testGlobalDirectory.FullName, "packages");
253+
var packagesDir = Path.Combine(_testCacheDirectory.FullName, "packages");
254254
var buildToolsPackageDir = Path.Combine(packagesDir, "Microsoft.Windows.SDK.BuildTools.10.0.26100.1");
255255
var binDir = Path.Combine(buildToolsPackageDir, "bin", "10.0.26100.0", "x64");
256256
Directory.CreateDirectory(binDir);
@@ -297,7 +297,7 @@ public async Task EnsureBuildToolAvailableAsync_WithNoExistingPackageAndInstallS
297297
public async Task EnsureBuildToolAvailableAsync_WithNonExistentTool_ThrowsFileNotFoundException()
298298
{
299299
// Arrange - Create package structure but without the requested tool
300-
var packagesDir = Path.Combine(_testGlobalDirectory.FullName, "packages");
300+
var packagesDir = Path.Combine(_testCacheDirectory.FullName, "packages");
301301
var buildToolsPackageDir = Path.Combine(packagesDir, "Microsoft.Windows.SDK.BuildTools.10.0.26100.1");
302302
var binDir = Path.Combine(buildToolsPackageDir, "bin", "10.0.26100.0", "x64");
303303
Directory.CreateDirectory(binDir);
@@ -340,7 +340,7 @@ public async Task RunBuildToolAsync_WithNoExistingPackage_AutoInstallsAndRuns()
340340
public async Task RunBuildToolAsync_WithExistingTool_RunsDirectly()
341341
{
342342
// Arrange - Create package structure with a working batch file
343-
var packagesDir = Path.Combine(_testGlobalDirectory.FullName, "packages");
343+
var packagesDir = Path.Combine(_testCacheDirectory.FullName, "packages");
344344
var buildToolsPackageDir = Path.Combine(packagesDir, "Microsoft.Windows.SDK.BuildTools.10.0.26100.1");
345345
var binDir = Path.Combine(buildToolsPackageDir, "bin", "10.0.26100.0", "x64");
346346
Directory.CreateDirectory(binDir);

src/winapp-CLI/WinApp.Cli.Tests/SignCommandTests.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88
namespace WinApp.Cli.Tests;
99

1010
[TestClass]
11+
[DoNotParallelize] // Locally sometimes ExportCertificateFromStore fails with:
12+
// Initialization method WinApp.Cli.Tests.SignCommandTests.Setup threw exception.
13+
// System.InvalidOperationException: Failed to export certificate from store: No valid certificate
14+
// found in store with subject: CN=WinappTestPublisher ---> System.InvalidOperationException:
15+
// No valid certificate found in store with subject: CN=WinappTestPublisher.
1116
public class SignCommandTests : BaseCommandTests
1217
{
1318
private FileInfo _testExecutablePath = null!;

src/winapp-CLI/WinApp.Cli.Tests/WinappDirectoryServiceTests.cs

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public void GetGlobalWinappDirectory_WithoutOverride_ReturnsDefaultDirectory()
2121
var result = directoryService.GetGlobalWinappDirectory();
2222

2323
// Assert
24-
var expectedDefaultPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".winappglobal");
24+
var expectedDefaultPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".winapp");
2525
Assert.AreEqual(expectedDefaultPath, result.FullName);
2626
}
2727

@@ -170,25 +170,37 @@ public void GetLocalWinappDirectory_WithNullBaseDirectory_UsesCurrentDirectory()
170170
}
171171

172172
[TestMethod]
173-
public void GetLocalWinappDirectory_WhenLocalAndGlobalAreSame_ReturnsLocalWinappDirectory()
173+
public void GetLocalWinappDirectory_WhenGlobalIsInParentDir_DontReturnGlobalAsLocal()
174174
{
175+
// Directory structure:
176+
// topDir/
177+
// .winapp/ <- expected result - should find this one
178+
// appDir/
179+
// .winapp/ <- global (set as cache dir) - should skip
180+
// winapp.yaml
181+
// subdir/ <- search from here
182+
175183
// Arrange - Create a .winapp directory and winapp.yaml in the same location
176-
var localWinappDir = _tempDirectory.CreateSubdirectory(".winapp");
177-
var winappYamlPath = Path.Combine(_tempDirectory.FullName, "winapp.yaml");
184+
var topDir = _tempDirectory.CreateSubdirectory("topDir");
185+
var topWinAppDir = topDir.CreateSubdirectory(".winapp");
186+
187+
var appDir = topDir.CreateSubdirectory("appDir");
188+
var localWinappDir = appDir.CreateSubdirectory(".winapp");
189+
var winappYamlPath = Path.Combine(appDir.FullName, "winapp.yaml");
178190
File.WriteAllText(winappYamlPath, "# test winapp.yaml");
179191

180-
// Set the global directory to be the same as the local directory
192+
// Set the appDir/.winapp as the global cache directory
181193
var directoryService = GetRequiredService<IWinappDirectoryService>();
182194
directoryService.SetCacheDirectoryForTesting(localWinappDir);
183195

184196
// Create a subdirectory to search from (so we test walking up the tree)
185-
var subDir = _tempDirectory.CreateSubdirectory("subdir");
197+
var subDir = appDir.CreateSubdirectory("subdir");
186198

187199
// Act - Search for local .winapp from subdirectory
188200
var result = directoryService.GetLocalWinappDirectory(subDir);
189201

190-
// Assert - Should find the local .winapp (which is also the global one) because winapp.yaml exists
191-
Assert.AreEqual(localWinappDir.FullName, result.FullName,
192-
"Should return the .winapp directory when winapp.yaml exists, even if it's also the global directory");
202+
// Assert - Should find the topDir .winapp because we skip the appDir/.winapp since it's set as global cache dir
203+
Assert.AreEqual(topWinAppDir.FullName, result.FullName,
204+
"Should return the top .winapp directory when local and global are the same");
193205
}
194206
}

src/winapp-CLI/WinApp.Cli/Commands/GetWinappPathCommand.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ static GetWinappPathCommand()
1717
{
1818
GlobalOption = new Option<bool>("--global")
1919
{
20-
Description = "Get the global .winappglobal directory instead of local .winapp"
20+
Description = "Get the global .winapp directory instead of local"
2121
};
2222
}
2323

24-
public GetWinappPathCommand() : base("get-winapp-path", "Get the path to the .winapp directory (local) or .winappglobal directory (global)")
24+
public GetWinappPathCommand() : base("get-winapp-path", "Get the path to the .winapp directory (local by default, global with --global)")
2525
{
2626
Options.Add(GlobalOption);
2727
}
@@ -39,7 +39,7 @@ public override Task<int> InvokeAsync(ParseResult parseResult, CancellationToken
3939

4040
if (global)
4141
{
42-
// Get the global .winappglobal directory
42+
// Get the global .winapp directory
4343
winappDir = winappDirectoryService.GetGlobalWinappDirectory();
4444
directoryType = "Global";
4545
}
@@ -53,7 +53,7 @@ public override Task<int> InvokeAsync(ParseResult parseResult, CancellationToken
5353
// For global directories, check if they exist
5454
if (global && !winappDir.Exists)
5555
{
56-
logger.LogError("{UISymbol} {DirectoryType} .winappglobal directory not found: {WinappDir}", UiSymbols.Error, directoryType, winappDir);
56+
logger.LogError("{UISymbol} {DirectoryType} .winapp directory not found: {WinappDir}", UiSymbols.Error, directoryType, winappDir);
5757
logger.LogError(" Make sure to run 'winapp init' first");
5858
return Task.FromResult(1);
5959
}
@@ -62,8 +62,7 @@ public override Task<int> InvokeAsync(ParseResult parseResult, CancellationToken
6262
logger.LogInformation("{WinappDir}", winappDir);
6363

6464
var status = winappDir.Exists ? "exists" : "does not exist";
65-
var dirName = global ? ".winappglobal" : ".winapp";
66-
logger.LogDebug("{UISymbol} {DirectoryType} {DirName} directory: {WinappDir} ({Status})", UiSymbols.Folder, directoryType, dirName, winappDir, status);
65+
logger.LogDebug("{UISymbol} {DirectoryType} .winapp directory: {WinappDir} ({Status})", UiSymbols.Folder, directoryType, winappDir, status);
6766

6867
return Task.FromResult(0);
6968
}

src/winapp-CLI/WinApp.Cli/Services/WinappDirectoryService.cs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,31 +35,29 @@ public DirectoryInfo GetGlobalWinappDirectory()
3535
}
3636

3737
var userProfile = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
38-
var winappDir = Path.Combine(userProfile, ".winappglobal");
38+
var winappDir = Path.Combine(userProfile, ".winapp");
3939
return new DirectoryInfo(winappDir);
4040
}
4141

4242
public DirectoryInfo GetLocalWinappDirectory(DirectoryInfo? baseDirectory = null)
4343
{
4444
baseDirectory ??= new DirectoryInfo(currentDirectoryProvider.GetCurrentDirectory());
4545

46+
DirectoryInfo globalWinappDirectory = GetGlobalWinappDirectory();
47+
4648
var originalBaseDir = new DirectoryInfo(baseDirectory.FullName);
4749
var dir = originalBaseDir;
4850
while (dir != null)
4951
{
5052
var winappDirectory = Path.Combine(dir.FullName, ".winapp");
51-
if (Directory.Exists(winappDirectory))
53+
if (Directory.Exists(winappDirectory))
5254
{
53-
// Does this dir have a "packages" subdirectory? If so, it's probably the old global dir
54-
bool hasPackagesSubdir = Directory.Exists(Path.Combine(winappDirectory, "packages"));
55-
if (hasPackagesSubdir)
55+
bool isGlobalWinAppDir =
56+
string.Equals(winappDirectory, globalWinappDirectory.FullName, StringComparison.OrdinalIgnoreCase);
57+
if (isGlobalWinAppDir)
5658
{
57-
Console.ForegroundColor = ConsoleColor.Yellow;
58-
Console.WriteLine(
59-
$"Warning: Found .winapp folder in UserProfile directory: {winappDirectory}. " +
60-
"The global winapp folder is now named .winappglobal. " +
61-
"Please remove the .winapp folder from your UserProfile directory or rename to .winappglobal.");
62-
Console.ResetColor();
59+
// We don't currently allow the global winapp directory to be used as a local winapp directory,
60+
// so continue searching upwards.
6361
}
6462
else
6563
{
@@ -70,5 +68,5 @@ public DirectoryInfo GetLocalWinappDirectory(DirectoryInfo? baseDirectory = null
7068
}
7169

7270
return new DirectoryInfo(Path.Combine(originalBaseDir.FullName, ".winapp"));
73-
}
74-
}
71+
}
72+
}

src/winapp-npm/winapp-path-utils.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ function getWinappPath(isGlobal = false) {
2424
}
2525

2626
/**
27-
* Get the path to the global .winappglobal directory
28-
* @returns {string} The full path to the global .winappglobal directory
29-
* @throws {Error} If the global .winappglobal directory is not found
27+
* Get the path to the global .winapp directory
28+
* @returns {string} The full path to the global .winapp directory
29+
* @throws {Error} If the global .winapp directory is not found
3030
*/
3131
function getGlobalWinappPath() {
3232
return getWinappPath(true);

0 commit comments

Comments
 (0)