Skip to content

Commit a7ec8af

Browse files
committed
feature #59464 [AssetMapper] Add --dry-run option on importmap:require command (chadyred)
This PR was merged into the 7.3 branch. Discussion ---------- [AssetMapper] Add `--dry-run` option on `importmap:require` command | Q | A | ------------- | --- | Branch? | 7.3 | Bug fix? | no | New feature? | yes | Deprecations? | no | License | MIT We are working with `@smnandre` on several ideas to **improve AssetMapper DX**, focusing here on the `importmap:require` command. Currently, there is no way to know in advance which dependent packages will be downloaded too, and the final output display lacks clarity. This PR aims to solve both issues by adding a new `--dry-run` flag and reworking the command output (with `-v` verbosity) <img width="845" alt="1" src="https://github.com/user-attachments/assets/26616802-f6f1-413f-9535-7a1a5205d277" /> <details><summary>Console output</summary> ```console php bin/console importmap:require bootstrap --dry-run -v [DRY-RUN] No changes will apply to the importmap configuration. -------------------------------------- --------- ---------------------------------------------------- Package Version Path -------------------------------------- --------- ---------------------------------------------------- bootstrap 5.3.3 assets/vendor/bootstrap/bootstrap.index.js `@popperjs`/core 2.11.8 assets/vendor/`@popperjs`/core/core.index.js bootstrap/dist/css/bootstrap.min.css 5.3.3 assets/vendor/bootstrap/dist/css/bootstrap.min.css -------------------------------------- --------- ---------------------------------------------------- [OK] 3 new items (bootstrap, `@popperjs`/core, bootstrap/dist/css/bootstrap.min.css) added to the importmap.php! [DRY-RUN] No changes applied to the importmap configuration. ``` </details> ## New `--dry-run` option This flag allows developers to simulate the installation process, without any alteration: - no modification of `importmap.php` file; - no file added or updated in the `assets` and `public` directories. The `--dry-run` flag allows developers to: - **check** commands for **mistakes** (e.g., typing `bootrap` instead of `bootstrap`, or `jquery`); - **list** dependent **packages** that will be installed (e.g., requiring `bootstrap` will also install ``@popperjs`/core`); - **test** for potential issues while **downloading**[^1] files. The console will display a line at start and end of execution to signal the dry-run mode. <img width="845" alt="2" src="https://github.com/user-attachments/assets/4df6abc0-6205-410e-9039-8c4b37a41055" /> <details><summary>Console output</summary> ```bash php bin/console importmap:require bootstrap --dry-run [DRY-RUN] No changes will apply to the importmap configuration. [OK] 3 new items (bootstrap, `@popperjs`/core, bootstrap/dist/css/bootstrap.min.css) added to the importmap.php! [DRY-RUN] No changes applied to the importmap configuration. ``` </details> ## New `-v` verbose output This PR also reworks the output for the `-v` (verbose) flag to provide more clarity when running the command with additional verbosity. <img width="845" alt="3" src="https://github.com/user-attachments/assets/46ff8d22-887c-4900-b778-36d9aaac1512" /> --- All feedback welcome! [^1]: AssetMapper recursively extracts the dependencies of JavaScript modules. Even with the `--dry-run` option, the `importmap:require` command requires a working `HttpClient` to download metadata and JavaScript files from various registries/repositories (mainly JSDelivr for now). Commits ------- 337c4655f3f [AssetMapper] Add `--dry-run` option on `importmap:require` command
2 parents 52b51ab + 373bdf5 commit a7ec8af

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

Resources/config/asset_mapper.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@
232232
->args([
233233
service('asset_mapper.importmap.manager'),
234234
service('asset_mapper.importmap.version_checker'),
235+
param('kernel.project_dir'),
235236
])
236237
->tag('console.command')
237238

0 commit comments

Comments
 (0)