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

Allow to pin modules with .jsm extension #99

Open
mildred opened this issue Jan 17, 2022 · 5 comments
Open

Allow to pin modules with .jsm extension #99

mildred opened this issue Jan 17, 2022 · 5 comments

Comments

@mildred
Copy link

mildred commented Jan 17, 2022

The .jsm extension can be used to refer to javascript modules, and allows to distinguish javascript files from those that are used as modules. In some circumstances, it can be useful to make this distinction.

My use case : I use a source bundler (esbuild) and I want to register some imports as external so the bundled code can make a reference to another javascript module in the browser. It allows for lighter bundles and also allows to import dynamic modules. I planned to use the .jsm extension for that.

importmap should allow to pin .jsm modules. Proposed syntax:

pin "extra", extname: ".jsm", preload: true

The extname keyword is already in use in sprockets to refer to assets by name in order to have sprockets compute the correct asset path.

Also, .jsm should be a registered mime type by default.

@dhh
Copy link
Member

dhh commented Feb 19, 2022

This explores similar territory to #57. I've been hesitant on #57, though. It feels like a lot to solve a little. Maybe we could simply allow .js(m|x)? as the extension instead. I'd find that much easier to merge.

@guybedford
Copy link
Contributor

Note that .mjs is the preferred alternative extension to .js for modules and has a correctly registered MIME type unlike .jsm.

@mtgrosser
Copy link

If other filename extensions than .js are to be allowed, the list of accepted extensions needs to be taken into account in four different places:

  • Directory expansion (pin_all_from), when scanning the filesystem
  • Module name derivation
  • Module path derivation
  • Cache sweeping, during watcher initialization

#57 has been updated to provide this, while keeping the accepted extensions in one place.

From there, making the extensions configurable instead of hardcoding them adds four more lines, ensuring compatibility of import maps with the (still) existing asset pipeline.

@mildred
Copy link
Author

mildred commented Sep 13, 2022

The fact is that some packages out there are not using the plain .js extension, and to be able to use them we need to be able to pin other extensions.

For example chart.js main module name is chart.mjs. Once downloaded in the vendor directory, in the default configuration the pinning does not work.

@tgaff
Copy link

tgaff commented Mar 31, 2023

The preference for .mjs for modules comes from V8: https://v8.dev/features/modules#mjs It's likely widely followed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants