Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[AssetMapper] ignore missing directory in isVendor() #58859

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,6 @@ private function isVendor(string $sourcePath): bool
$sourcePath = realpath($sourcePath);
$vendorDir = realpath($this->vendorDir);

return $sourcePath && str_starts_with($sourcePath, $vendorDir);
return $sourcePath && $vendorDir && str_starts_with($sourcePath, $vendorDir);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

class MappedAssetFactoryTest extends TestCase
{
private const DEFAULT_FIXTURES = __DIR__.'/../Fixtures/assets/vendor';

private AssetMapperInterface&MockObject $assetMapper;

public function testCreateMappedAsset()
Expand Down Expand Up @@ -137,7 +139,15 @@ public function testCreateMappedAssetInVendor()
$this->assertTrue($asset->isVendor);
}

private function createFactory(?AssetCompilerInterface $extraCompiler = null): MappedAssetFactory
public function testCreateMappedAssetInMissingVendor()
{
$assetMapper = $this->createFactory(null, '/this-path-does-not-exist/');
$asset = $assetMapper->createMappedAsset('lodash.js', __DIR__.'/../Fixtures/assets/vendor/lodash/lodash.index.js');
$this->assertSame('lodash.js', $asset->logicalPath);
$this->assertFalse($asset->isVendor);
}

private function createFactory(?AssetCompilerInterface $extraCompiler = null, ?string $vendorDir = self::DEFAULT_FIXTURES): MappedAssetFactory
{
$compilers = [
new JavaScriptImportPathCompiler($this->createMock(ImportMapConfigReader::class)),
Expand All @@ -162,7 +172,7 @@ private function createFactory(?AssetCompilerInterface $extraCompiler = null): M
$factory = new MappedAssetFactory(
$pathResolver,
$compiler,
__DIR__.'/../Fixtures/assets/vendor',
$vendorDir,
);

// mock the AssetMapper to behave like normal: by calling back to the factory
Expand Down
Loading