Skip to content
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

Handle nested controllers #6

Closed
Intrepidd opened this issue Sep 7, 2021 · 3 comments
Closed

Handle nested controllers #6

Intrepidd opened this issue Sep 7, 2021 · 3 comments
Labels
bug Something isn't working

Comments

@Intrepidd
Copy link
Contributor

Welcome to the hype :)

This plug-in doesn't recursively look through controller folders.

If you do several imports it works but the definitions are not prefixed with the namespace as expected

How about adding resursive lookup of controllers?

@zombiezen zombiezen added the question Further information is requested label Sep 7, 2021
@zombiezen
Copy link
Owner

Welcome to the hype :)

Thanks! Did I get linked somewhere? 😅

This plug-in doesn't recursively look through controller folders.

If you do several imports it works but the definitions are not prefixed with the namespace as expected

How about adding resursive lookup of controllers?

Hm, there is logic to recurse into subdirectories:

if (ent.isDirectory()) {
result.push(...await walk(
path.join(dir, ent.name),
ent.name + '--',
moduleDir + '/' + ent.name,
));
continue;
}

Can you provide a Minimal, Reproducible Example of what you did and what isn't working for you?

@Intrepidd
Copy link
Contributor Author

Thanks! Did I get linked somewhere? 😅

Not directly but with rails 7 embracing esbuild this plugin is gonna get some attention I'm sure :)

So realised the issue is that if there are 2 levels of recursion, the identifier ignores the first level of recursion.

Here is the repro : https://github.com/Intrepidd/esbuild-stimulus-issue

I have controller/directory1/directory2/baz_controller.js, but in the outfile, here is what I get :

  var definitions = [
    { identifier: "directory1--bar", controllerConstructor: bar_controller_default },
    { identifier: "directory2--baz", controllerConstructor: baz_controller_default },
    { identifier: "foo", controllerConstructor: foo_controller_default }
  ];

I have directory2--baz when I actually expect directory1--directory2--baz

I guess a naive fix would look like :

            result.push(...await walk(
              path.join(dir, ent.name),
              - ent.name + '--',
              + (prefix ? prefix + '--' : '') + ent.name + '--',
              moduleDir + '/' + ent.name,
            ));

So that the prefix is not reset for each recursive call

Thanks !

@Intrepidd
Copy link
Contributor Author

Intrepidd commented Sep 8, 2021

Also _ is replaced by - which breaks the folder name, for instance :

foo_bar/some_controller.js will be foo_bar--some whereas it will be foo-bar--some with the existing @stimulus/webpack-helpers package

@zombiezen zombiezen added bug Something isn't working and removed question Further information is requested labels Sep 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants