Skip to content

Commit

Permalink
Merge pull request #20 from s2b/bugfix/nonExistentExtDir
Browse files Browse the repository at this point in the history
[BUGFIX] Exception if EXT entrypoint doesn’t exist
  • Loading branch information
s2b authored Oct 2, 2023
2 parents 0c64c32 + ed6feb8 commit d0d7cf8
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
6 changes: 6 additions & 0 deletions Classes/Service/ViteService.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,12 @@ protected function determineAssetIdentifierFromExtensionPath(string $identifier)
$absolutePath = $this->packageManager->resolvePackagePath($identifier);
$file = PathUtility::basename($absolutePath);
$dir = realpath(PathUtility::dirname($absolutePath));
if ($dir === false) {
throw new ViteException(sprintf(
'The specified extension path "%s" does not exist.',
$identifier
), 1696238083);
}
$relativeDirToProjectRoot = PathUtility::getRelativePath(Environment::getProjectPath(), $dir);

return $relativeDirToProjectRoot . $file;
Expand Down
29 changes: 25 additions & 4 deletions Tests/Unit/Service/ViteServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ public function setUp(): void
'EXT:symlink_extension/Resources/Private/JavaScript/Main.js',
$fixtureDir . 'symlink_extension/Resources/Private/JavaScript/Main.js',
],
[
'EXT:test_extension/Resources/Private/JavaScript/NonExistent/NonExistent.js',
$fixtureDir . 'test_extension/Resources/Private/NonExistent/NonExistent.js',
],
]);

$this->viteService = new ViteService(
Expand Down Expand Up @@ -409,15 +413,32 @@ public function getAssetWithExtPathFromManifest(): void
);
}

public static function getAssetPathFromManifestErrorHandlingDataProvider(): array
{
$fixtureDir = realpath(__DIR__ . '/../../Fixtures') . '/';
return [
[
$fixtureDir . 'ValidManifest/manifest.json',
'NonExistentEntry.css',
1690735353,
],
[
$fixtureDir . 'ValidManifest/manifest.json',
'EXT:test_extension/Resources/Private/JavaScript/NonExistent/NonExistent.js',
1696238083,
],
];
}

/**
* @test
* @dataProvider getAssetPathFromManifestErrorHandlingDataProvider
*/
public function getAssetPathFromManifestErrorHandling(): void
public function getAssetPathFromManifestErrorHandling(string $manifestFile, string $entry, int $exceptionCode): void
{
$this->expectException(ViteException::class);
$this->expectExceptionCode(1690735353);
$this->expectExceptionCode($exceptionCode);

$fixtureDir = realpath(__DIR__ . '/../../Fixtures') . '/';
$this->viteService->getAssetPathFromManifest($fixtureDir . 'ValidManifest/manifest.json', 'NonExistentEntry.css');
$this->viteService->getAssetPathFromManifest($manifestFile, $entry);
}
}

0 comments on commit d0d7cf8

Please sign in to comment.