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

Error raised when copying a folder instead of a file #9

Open
opheliagame opened this issue Feb 22, 2025 · 2 comments
Open

Error raised when copying a folder instead of a file #9

opheliagame opened this issue Feb 22, 2025 · 2 comments
Labels
enhancement New feature or request

Comments

@opheliagame
Copy link

Here is my importmap

config :phoenix_importmap, :importmap, %{
  app: "/assets/js/app.js",
  topbar: "/assets/vendor/topbar.js",
  three: "/assets/vendor/threejs/three.module.js",
  "three/addons/": "/assets/vendor/jsm/",
  phoenix_html: "/deps/phoenix_html/priv/static/phoenix_html.js",
  phoenix: "/deps/phoenix/priv/static/phoenix.mjs",
  phoenix_live_view: "/deps/phoenix_live_view/priv/static/phoenix_live_view.esm.js"
}

I need to copy an entire folder, but when doing this an error happens

(File.CopyError) could not copy from "<path>/assets/vendor/jsm/" to "<path>/priv/static/assets/": illegal operation on a directory

Is there a way to get around this and enable using directories in importmaps?

@gilest gilest added the enhancement New feature or request label Feb 24, 2025
@gilest
Copy link
Owner

gilest commented Feb 24, 2025

Hey, thanks for reporting 🙂

This isn't supported in the existing release, which only copies individual assets.

I started implementing recursive copying of files today and it does work.

However I haven't yet figured out a way to have this support asset fingerprints in production. Since the importmap read by the browser and the import written in Module JS reference the plain asset path, (missing the cache digest or "fingerprint" in its filename).

I'd rather not release such a feature without a plan for how it will support proper asset caching in produciton.

We could maybe get around this by having an identifier per module generated automatically as part of the importmap generation.

As a not-ideal workaround though, you might be able to enumerate each plugin module you import as a specific importmap line.

For example:

config :phoenix_importmap, :importmap, %{
  three: "/assets/vendor/threejs/three.module.js",
  "three/addons/libs/stats.module.js": "/assets/vendor/jsm/three/addons/libs/stats.module.js",
}
import Stats from 'three/addons/libs/stats.module.js';

Curious to hear how that works for you. I'll have take pass at the implementation soon.

@opheliagame
Copy link
Author

opheliagame commented Feb 24, 2025

@gilest

As a not-ideal workaround though, you might be able to enumerate each plugin module you import as a specific importmap line.

I thought about this as well but the modules themselves are importing other modules which makes the enumeration task not trivial. Although this is threejs specific, I imagine this must be a common enough situation when it comes to other libraries as well.

I'll have take pass at the implementation soon.

excited!

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

No branches or pull requests

2 participants