Skip to content

[Asset] [DX] Option to make asset manifests strict on missing item #38495

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
Jul 25, 2021

Conversation

GromNaN
Copy link
Member

@GromNaN GromNaN commented Oct 9, 2020

Q A
Branch? 5.4
Bug fix? no
New feature? yes
Deprecations? no
Tickets -
License MIT
Doc PR symfony/symfony-docs#14414

In all the projects I use a JSON manifest, when an asset is not listed in manifest.json, the asset file is not generated. The current behavior is permissive as it returns the unmodified path of the asset. Which ends with a 404 when the browser tries to load the asset.

With the option strict_mode: true, an exception is thrown when we try to use an asset that is not listed in manifest.json. Thereby we don't have to check that asset urls are actually working in tests (manual or automated).

Usage:
The option strict_mode is optional for backward compatibility. Using the %kernel.debug% value is safe to flush bugs on dev or test mode but keep the application working on production.

# config/packages/assets.yaml

framework:
    assets:
        packages:
            app:
                # Uses a JSON manifest (can be a local path or an url remote file)
                json_manifest_path: '%kernel.project_dir%/public/build/manifest.json'
                # Throws an exception when an expected entry is missing in the manifest
                strict_mode: '%kernel.debug%'

Todo:

@nicolas-grekas nicolas-grekas added this to the 5.x milestone Oct 12, 2020
@GromNaN GromNaN marked this pull request as ready for review October 14, 2020 20:39
@GromNaN GromNaN requested a review from stof October 14, 2020 20:39
@GromNaN GromNaN changed the title [Asset] Option to make asset manifests strict on missing item [DX][Asset] Option to make asset manifests strict on missing item Oct 15, 2020
Copy link
Member

@weaverryan weaverryan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it! WebpackEncoreBundle has had this option for a long time - called strict_mode - for an entry that doesn’t appear in entrypoints.json

])

->set('assets.remote_json_manifest_version_strategy', RemoteJsonManifestVersionStrategy::class)
->abstract()
->args([
abstract_arg('manifest url'),
service('http_client'),
false,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these should both be abstract args - as we fill both in always

Copy link
Member Author

@GromNaN GromNaN Oct 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used a fixed value to prevent breaking compatibility in the eventuality someone extends this abstract definition.

Copy link
Member Author

@GromNaN GromNaN May 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it something I must change ?

@GromNaN GromNaN force-pushed the assets-strict branch 2 times, most recently from 7d60341 to abeb56c Compare October 16, 2020 07:46
@GromNaN

This comment has been minimized.

@GromNaN GromNaN force-pushed the assets-strict branch 2 times, most recently from ed7d12f to e76aea7 Compare January 30, 2021 22:38
@GromNaN GromNaN requested a review from weaverryan January 30, 2021 22:39
@GromNaN
Copy link
Member Author

GromNaN commented Jan 30, 2021

Thanks to the refactoring done by @jderusse in #39484, this PR has been simplified.

@carsonbot carsonbot changed the title [DX][Asset] Option to make asset manifests strict on missing item [Asset] [DX] Option to make asset manifests strict on missing item Feb 16, 2021
@nicolas-grekas
Copy link
Member

(small rebase needed)

@GromNaN
Copy link
Member Author

GromNaN commented Feb 17, 2021

Rebased. The CS fix suggested by fabbot are not related to this PR.

@GromNaN
Copy link
Member Author

GromNaN commented Apr 26, 2021

Rebased again.

Copy link
Member

@javiereguiluz javiereguiluz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice proposal! Jérôme, thanks for contributing this feature. I hope it's merged 👍

@fabpot
Copy link
Member

fabpot commented Jul 25, 2021

Thank you @GromNaN.

@fabpot fabpot merged commit 7e28580 into symfony:5.4 Jul 25, 2021
@GromNaN GromNaN deleted the assets-strict branch October 14, 2021 19:04
This was referenced Nov 5, 2021
javiereguiluz added a commit to symfony/symfony-docs that referenced this pull request Dec 13, 2021
…ategy (GromNaN)

This PR was merged into the 5.4 branch.

Discussion
----------

[Asset] Add option $strictMode to JsonManifestVersionStrategy

Documentation for symfony/symfony#38495

Commits
-------

c4e19eb [Assets] Add doc for strict mode strategy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants