-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[AssetMapper] Make asset-map:compile
clean assets in debug mode, require --force
to generate them
#59073
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
[AssetMapper] Make asset-map:compile
clean assets in debug mode, require --force
to generate them
#59073
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,11 +49,12 @@ public function __construct( | |
protected function configure(): void | ||
{ | ||
$this | ||
->addOption('force', 'f', null, 'Force compiling the assets even in debug mode') | ||
->setHelp(<<<'EOT' | ||
The <info>%command.name%</info> command compiles and dumps all the assets in | ||
the asset mapper into the final public directory (usually <comment>public/assets</comment>). | ||
|
||
This command is meant to be run during deployment. | ||
When run in debug mode, this command actually removes those assets, unless <info>--force</info> is passed. | ||
EOT | ||
); | ||
} | ||
|
@@ -62,8 +63,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int | |
{ | ||
$io = new SymfonyStyle($input, $output); | ||
|
||
$this->eventDispatcher?->dispatch(new PreAssetsCompileEvent($io)); | ||
|
||
// remove existing config files | ||
$this->compiledConfigReader->removeConfig(AssetMapper::MANIFEST_FILE_NAME); | ||
$this->compiledConfigReader->removeConfig(ImportMapGenerator::IMPORT_MAP_CACHE_FILENAME); | ||
|
@@ -74,6 +73,26 @@ protected function execute(InputInterface $input, OutputInterface $output): int | |
$entrypointFiles[$entrypointName] = $path; | ||
} | ||
|
||
if ($this->isDebug && !$input->getOption('force')) { | ||
$didUnlink = false; | ||
$publicDir = $this->assetsFilesystem->getDestinationPath(); | ||
|
||
foreach ($this->assetMapper->allAssets() as $asset) { | ||
if (is_file($publicDir.'/'.$asset->publicPath)) { | ||
unlink($publicDir.'/'.$asset->publicPath); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe, the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not without reasons. What would be yours? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hello, it handles issues in case of errors like "impossible" to remove a directory and raise an IOException well formatted and |
||
$didUnlink = true; | ||
} | ||
} | ||
|
||
if ($didUnlink) { | ||
$io->warning('Running in debug mode: removed compiled assets to let them be served dynamically. Use --force to generate them instead.'); | ||
} | ||
|
||
return 0; | ||
nicolas-grekas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
$this->eventDispatcher?->dispatch(new PreAssetsCompileEvent($io)); | ||
|
||
$manifest = $this->createManifestAndWriteFiles($io); | ||
$manifestPath = $this->compiledConfigReader->saveConfig(AssetMapper::MANIFEST_FILE_NAME, $manifest); | ||
$io->comment(\sprintf('Manifest written to <info>%s</info>', $this->shortenPath($manifestPath))); | ||
|
@@ -87,13 +106,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int | |
$styledEntrypointNames = array_map(fn (string $entrypointName) => \sprintf('<info>%s</>', $entrypointName), array_keys($entrypointFiles)); | ||
$io->comment(\sprintf('Entrypoint metadata written for <comment>%d</> entrypoints (%s).', \count($entrypointFiles), implode(', ', $styledEntrypointNames))); | ||
|
||
if ($this->isDebug) { | ||
$io->warning(\sprintf( | ||
'Debug mode is enabled in your project: Symfony will not serve any changed assets until you delete the files in the "%s" directory again.', | ||
$this->shortenPath(\dirname($manifestPath)) | ||
)); | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would not have been easier to get / use with an option "--purge" + keeping the current behaviour ?
A compile command that clear files feels very weird .. using different arguments to do the same thing also 🤷
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My reasoning is that in dev mode you don't want the assets to block dynamic generation, yet this is the default right now, and this serves no DX purpose.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Current DX can be improved for users after they compile assets locally, yes.
But this PR can also make things worse for all the others.. Two opposite behaviour between debug and not debug.. i'm not sure this will be a DX win. 🤷♂️
Two commands:
asset-map:compile
andasset-map:purge
(orasset-map:clear
) feels easier to explain, document, use.Just a personal feeling.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please explain what you mean by "worse".
The behavior I'm proposing here is not opposite, it's consistent with what each mode (debug/non-debug) needs to work. Adding a myriad of commands for fine grained operations will just make things more complex, aka worse, when we know what the behavior should be to make things Just Work (TM)