Skip to content

[Stimulus Bridge] Entrypoint: Allow to import aliases#1390

Open
Jibbarth wants to merge 1 commit into
symfony:mainfrom
Jibbarth:feature/stimulus-bridge-external-entrypoint
Open

[Stimulus Bridge] Entrypoint: Allow to import aliases#1390
Jibbarth wants to merge 1 commit into
symfony:mainfrom
Jibbarth:feature/stimulus-bridge-external-entrypoint

Conversation

@Jibbarth
Copy link
Copy Markdown

Q A
Bug fix? no
New feature? yes
Deprecations? no
Issues Fix #...
License MIT

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

// acme-feature-bundle/assets/package.json

    {
        "name": "@acme/feature",
        "symfony": {
            "entrypoints": {
                "@acme/feature/entrypoint": "@acme/feature/entrypoint.js"
            }
        }
    }

@carsonbot carsonbot added Feature New Feature Status: Needs Review Needs to be reviewed labels Feb 15, 2026
Comment thread test/functional.js

const version = packageHelper.getPackageVersion('@symfony/stimulus-bridge');
if (!semver.satisfies(version, '^3.0.0')) {
if (!semver.satisfies(version, '>3.0.0')) {
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

i had the v4.0.0 on my side, so this test wasn't triggered. That's why I changed the comparison here

Comment thread lib/WebpackConfig.js

for (let name in controllersData.entrypoints) {
// Imported entrypoint (e.g. from node_modules) should be used as-is
if (controllersData.entrypoints[name].startsWith('@')) {
Copy link
Copy Markdown
Member

@Kocal Kocal Feb 19, 2026

Choose a reason for hiding this comment

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

I am not sure about this one, only scoped-packages are supported? What if the package name is tototata? It can't define aliases?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

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:
image

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 ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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... 😬

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@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

@carsonbot carsonbot added Status: Needs Work Additional work is needed and removed Status: Needs Review Needs to be reviewed labels Feb 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Feature New Feature Status: Needs Work Additional work is needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants