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

three/addons alias #336

Closed
CodyJasonBennett opened this issue Feb 4, 2023 · 2 comments · Fixed by #340 or #356
Closed

three/addons alias #336

CodyJasonBennett opened this issue Feb 4, 2023 · 2 comments · Fixed by #340 or #356
Labels
enhancement New feature or request

Comments

@CodyJasonBennett
Copy link
Contributor

CodyJasonBennett commented Feb 4, 2023

Describe the feature you'd like:

Since r144 (mrdoob/three.js#23406), three.js supports a three/addons alias that would currently redirect to three/examples/jsm.

For instance, the following resolve to the same file:

import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js'
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js'

Suggested implementation:

TypeScript doesn't recognize the above behavior since the alias is currently handled through package.exports and types only exist for examples/jsm on disk (this might be something to check in TypeScript upstream). We can implement this by copying examples/jsm to addons at build-time if there's no easy way to alias as a library.

You can work-around this in user-land with:

{
  "compilerOptions": {
    "paths": {
      "three/addons/*": ["./node_modules/three/examples/jsm/*"]
    }
  }
}
@CodyJasonBennett CodyJasonBennett added the enhancement New feature or request label Feb 4, 2023
@Methuselah96
Copy link
Contributor

Methuselah96 commented Feb 5, 2023

I think TypeScript will correctly perform the alias if we add the exports field to the package.json of @types/three. I've created #340 to do just that and it seems to work for me in my local testing (i.e., TypeScript lets me import three/addons/controls/OrbitControls.js). I'm hoping DefinitelyTyped will preserve the field when publishing the types, but we might have to try it to find out.

@Methuselah96
Copy link
Contributor

Methuselah96 commented Feb 22, 2023

Did some testing, and this won't work until we add file extensions to imports, which is waiting on DefinitelyTyped to support imports with file extensions without having to add them to OTHER_FILES.

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
2 participants