Skip to content

[AssetMapper] Fix jsdelivr import parsing with no imported value #52508

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
Nov 10, 2023

Conversation

weaverryan
Copy link
Member

Q A
Branch? 6.4
Bug fix? yes
New feature? no
Deprecations? no
Issues Fix #52467
License MIT

Another new import syntax found by @tacman! I think this one is kind of a bug in the library - a module environment should not import 'foo' (i.e. import a module and not actually use any value), but our job is just to find these, not judge them ;).

FYI - I have an issue on jsdelivr proposing that they create an API endpoint to expose this info, so we don't need to parse it. They agree and already were thinking about this - jsdelivr/jsdelivr#18538 - so this may be something helpful in the future.

Cheers!

@stof
Copy link
Member

stof commented Nov 9, 2023

Actually, if the import has side effects, this is a valid usage.

@tacman
Copy link
Contributor

tacman commented Nov 9, 2023

I think in this case the side effect is to add the plugin to the global jquery object.

@weaverryan
Copy link
Member Author

Actually, if the import has side effects, this is a valid usage.

You're right. I guess i'm pleading into the void: "Can we please stop causing side effects with modules!!!" :)

@tacman
Copy link
Contributor

tacman commented Nov 9, 2023

I'm no expert, but I also think the idea of explicitly adding the plugin to jquery is better than automatically adding it, even though it's an additional line of code. Because modules don't allow for conditional imports, I don't see how it's possible to selectively add theme-specific plugins.

That is, if there's are select-bs4, select-bs5 and select-tailwind plugins, and merely importing them adds the plugin to jquery, there's no way to say "no, just bs5".

Better, I think would be

import selectBs5 from 'select-bs5';
import selectBs4 from 'select-bs4';
let plugin =  (theme=='bs4') ? selectBs4 : selectBs5;
$.addPlugin(plugin);

Allan is working on version 2 of datatables, as importmaps and javascript modules become more prominent perhaps he'll allow something like that.

@stof
Copy link
Member

stof commented Nov 9, 2023

@tacman that's something to discuss elsewhere. AssetMapper has to handle JS files as they exist.

@weaverryan weaverryan force-pushed the asset-mapper-jsdelivr-no-import branch from a789bdf to db7f7ea Compare November 9, 2023 18:10
@weaverryan weaverryan force-pushed the asset-mapper-jsdelivr-no-import branch from db7f7ea to dc1b27d Compare November 10, 2023 02:24
@fabpot fabpot merged commit 3128c60 into symfony:6.4 Nov 10, 2023
This was referenced Nov 10, 2023
@tacman
Copy link
Contributor

tacman commented Nov 10, 2023

Yes, it's working now, the datatables modules are working. And fontawesome is working when I add those lines, I'm not sure if there's supposed to be a way to simply import.

@weaverryan weaverryan deleted the asset-mapper-jsdelivr-no-import branch November 11, 2023 01:31
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.

[AssetMapper] jQuery plugin fails locally but not remotely
5 participants