Skip to content

[AssetMapper] Exclude dot files #52712

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
merged 1 commit into from
Nov 25, 2023
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
[AssetMapper] Adding an option (true by default) to not publish dot f…
…iles
  • Loading branch information
weaverryan committed Nov 24, 2023
commit 85c0ef6b416451739ada6d13d5ec6e3128ce3d69
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,11 @@ private function addAssetMapperSection(ArrayNodeDefinition $rootNode, callable $
->prototype('scalar')->end()
->example(['*/assets/build/*', '*/*_.scss'])
->end()
// boolean called defaulting to true
->booleanNode('exclude_dotfiles')
->info('If true, any files starting with "." will be excluded from the asset mapper')
->defaultTrue()
->end()
->booleanNode('server')
->info('If true, a "dev server" will return the assets from the public directory (true in "debug" mode only by default)')
->defaultValue($this->debug)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1351,7 +1351,8 @@ private function registerAssetMapperConfiguration(array $config, ContainerBuilde

$container->getDefinition('asset_mapper.repository')
->setArgument(0, $paths)
->setArgument(2, $excludedPathPatterns);
->setArgument(2, $excludedPathPatterns)
->setArgument(3, $config['exclude_dotfiles']);

$container->getDefinition('asset_mapper.public_assets_path_resolver')
->setArgument(0, $config['public_prefix']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
abstract_arg('array of asset mapper paths'),
param('kernel.project_dir'),
abstract_arg('array of excluded path patterns'),
abstract_arg('exclude dot files'),
])

->set('asset_mapper.public_assets_path_resolver', PublicAssetsPathResolver::class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@
<xsd:element name="importmap-script-attribute" type="asset_mapper_attribute" minOccurs="0" maxOccurs="unbounded" />
</xsd:sequence>
<xsd:attribute name="enabled" type="xsd:boolean" />
<xsd:attribute name="exclude-dotfiles" type="xsd:boolean" />
<xsd:attribute name="server" type="xsd:boolean" />
<xsd:attribute name="public-prefix" type="xsd:string" />
<xsd:attribute name="missing-import-mode" type="missing-import-mode" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ public function testAssetMapperCanBeEnabled()
'importmap_polyfill' => 'es-module-shims',
'vendor_dir' => '%kernel.project_dir%/assets/vendor',
'importmap_script_attributes' => [],
'exclude_dotfiles' => true,
];

$this->assertEquals($defaultConfig, $config['asset_mapper']);
Expand Down Expand Up @@ -674,6 +675,7 @@ protected static function getBundleDefaultConfig()
'importmap_polyfill' => 'es-module-shims',
'vendor_dir' => '%kernel.project_dir%/assets/vendor',
'importmap_script_attributes' => [],
'exclude_dotfiles' => true,
],
'cache' => [
'pools' => [],
Expand Down
5 changes: 5 additions & 0 deletions src/Symfony/Component/AssetMapper/AssetMapperRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public function __construct(
private readonly array $paths,
private readonly string $projectRootDir,
private readonly array $excludedPathPatterns = [],
private readonly bool $excludeDotFiles = true,
) {
}

Expand Down Expand Up @@ -185,6 +186,10 @@ private function isExcluded(string $filesystemPath): bool
}
}

if ($this->excludeDotFiles && str_starts_with(basename($filesystemPath), '.')) {
return true;
}

return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,24 @@ public function testExcludedPaths()
$this->assertNull($repository->find('file3.css'));
$this->assertNull($repository->findLogicalPath(__DIR__.'/Fixtures/dir2/file3.css'));
}

public function testDotFilesExcluded()
{
$repository = new AssetMapperRepository([
'dot_file' => '',
], __DIR__.'/Fixtures', [], true);

$actualAssets = array_keys($repository->all());
$this->assertEquals([], $actualAssets);
}

public function testDotFilesNotExcluded()
{
$repository = new AssetMapperRepository([
'dot_file' => '',
], __DIR__.'/Fixtures', [], false);

$actualAssets = array_keys($repository->all());
$this->assertEquals(['.dotfile'], $actualAssets);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
I'm a dot file!
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy