[Stimulus Bridge] Entrypoint: Allow to import aliases#1390
Conversation
|
|
||
| const version = packageHelper.getPackageVersion('@symfony/stimulus-bridge'); | ||
| if (!semver.satisfies(version, '^3.0.0')) { | ||
| if (!semver.satisfies(version, '>3.0.0')) { |
There was a problem hiding this comment.
i had the v4.0.0 on my side, so this test wasn't triggered. That's why I changed the comparison here
|
|
||
| for (let name in controllersData.entrypoints) { | ||
| // Imported entrypoint (e.g. from node_modules) should be used as-is | ||
| if (controllersData.entrypoints[name].startsWith('@')) { |
There was a problem hiding this comment.
I am not sure about this one, only scoped-packages are supported? What if the package name is tototata? It can't define aliases?
There was a problem hiding this comment.
That's my guess yes @Kocal
This is for package.json imported from a bundle, not for a dependency imported directly in the app package.json (unless i'm wrong)
We already recommend to use the @ in the package.json name of a bundle:

The entrypoint section that package.json is read by symfony flex and added in /assets/controllers.json of the app as it.
I'm not sure of the purpose, maybe it was to be completed by a recipe that would copy that entrypoint inside assets folder to be used directly ?
By adding these line, we allow to reference to the assets from the bundle, and yes only if the package name start with @.
Maybe an other option could be "if not start by ./" but maybe it could break somewhere.
Or improve flex to add some directive telling the entrypoint added came from a bundle?
WDYT ?
There was a problem hiding this comment.
Sorry for the late response, but to be honest I'm not sure about everything here and I can't give you a yes or no, or a better alternative... 😬
There was a problem hiding this comment.
@Kocal maybe we should invert the check instead.
First, resolve the entrypoint relative to the controllers.json root dir and use it if the file exists, like before. Otherwise, pass the entrypoint as-is to webpack and let webpack resolve it.
This should cover both scoped packages (@acme/package/...) and non-scoped packages (tototata/...). If webpack cannot resolve it, it will raise the usual module resolution error.
I will work on a patch update for this
I was re-working on the doc pr to expose entrypoint inside a UX bundle.
symfony/symfony-docs#21292
I didn't really like the fact that, to expose an entrypoint in webpack encore, user must add it relative to node_modules folder :
{ "name": "@acme/feature", "symfony": { "entrypoints": { "@acme/feature/entrypoint": "../node_modules/@acme/feature/entrypoint.js" } } }With that change in enableStimulusBridge, we allow to import entrypoint from a bundle like that