-
Notifications
You must be signed in to change notification settings - Fork 256
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
Fix allowing imports of individual source files/modules from blacklight-frontend npm package #3128
Conversation
…rted from blacklight-frontend npm package eg local app might import 'blacklight-frontend/app/javascript/blacklight/core'; import 'blacklight-frontend/app/javascript/blacklight/modal'; or import Blacklight from 'blacklight-frontend/app/javascript/blacklight/core' import Modal from 'blacklight-frontend/app/javascript/blacklight/modal';
60c6267
to
d8c0ec4
Compare
@jrochkind is the |
@jcoyne While it worked for me without that, some documentation i found suggested that it was necessary in ES6 for relative-path imports. So I added it. I can't find the exact page I was looking at that said espeically for relative paths, but googling now I see:
—https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import It may depend on exactly what JS bundler you are using? It seemed to do no harm and be extra safe to me, in this wild JS landscape, but it works for me without it so I don't insist. Thanks for reviewing! |
Here's another suggestion:
I'm not totally sure if we expect these individual uncombined source files might be used in the browser? That is not my use case. But from my reserach (not a JS expert!), it seemed like including extension was safer across the diversity of possible bundlers and environments, and did no harm. I definitely defer to anyone who knows more than me though! |
Thanks for checking that. |
Hi this change is no longer in Does anyone know if it got intentionally reversed, but without a link or comment here? I will try to do some code archeology to see what happened. |
OK, I found the revert, from @corylown 5f847ec @corylown , I still need this! I believe it is necessary to use the ESM modules from any traditional Javascript loader. (ie not rails-importmaps). It doesn't look like that commit was part of any PR (was it made directly to master?), I can't find it with Can we talk? |
@jrochkind here's the revert PR: #3164 |
Closes #3050
All imports should be relative, so individual files can still be imported from blacklight-frontend npm packagerted from blacklight-frontend npm package
It turns out the solution to #3050 was as simple as this! Thank you for letting me rubber-duck it at the blacklight committers meeting, @jcoyne, @tpendragon @hackartisan @tampakis
I have built the NPM package locally, and verified this appears to work in WIP BL8 upgrade, to let me selective import like I did before (with the somewhat odd source path that remians the same from BL7):
Or instead you can now also do like (that i don't think you could in BL7 but now can):
I am not an expert in JS or in what BL is trying to do with JS; I don't think this will cause any problems for existing uses, but perhaps @jcoyne or @cbeer want to review?
Not sure how to encourage/instruct people to keep using only relative paths in these source files, since tests don't currently test for anything relevant here, but better than nothing.