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

Import normalization #14

Closed
timkurvers opened this issue May 25, 2020 · 3 comments
Closed

Import normalization #14

timkurvers opened this issue May 25, 2020 · 3 comments

Comments

@timkurvers
Copy link
Member

timkurvers commented May 25, 2020

Currently, this repo does not use file extensions when importing modules. It also uses index imports in various locations.

As outlined in differences between ESM and CJS in the Node.js documentation, Node will no longer allow extensionless imports nor use of a directory index for ESM modules.

Webpack – used in this repo – is a bit of a different beast and may support these features for some time to come. For the sake of consistency across repos we could opt to force webpack to also require extensions and disallow use of a directory index:

This would require restructuring of nested modules. For example, refactoring gfx:

src/gfx
├── Color.mjs
├── Device
│   └── index.mjs
├── Screen
│   ├── Layer.mjs
│   └── index.mjs
├── Shader
│   ├── Registry.mjs
│   └── index.mjs
├── Texture
│   ├── Registry.mjs
│   └── index.mjs
...

Into:

src/gfx
├── Color.mjs
├── Device.mjs
├── Screen.mjs
├── ScreenLayer.mjs
├── ShaderRegistry.mjs
├── Shader.mjs
├── TextureRegistry.mjs
├── Texture.mjs
...
@fallenoak
Copy link
Member

fallenoak commented May 25, 2020

We can still keep the directories around with the new style of imports:

src/gfx/
├── Screen.mjs
├── Screen/
│   ├── Layer.mjs
...

We'd just need to re-export ScreenLayer from Screen.

On a related note: personally, I much prefer naming modules explicitly: Screen/Layer.mjs requires reading the path for context. Screen/ScreenLayer.mjs doesn't.

@timkurvers
Copy link
Member Author

We can still keep the directories around with the new style of imports

Ah, interesting, hadn't considered that variant. Agree on explicitly naming modules.

How would you feel about:

src/gfx/screen/
├── Screen.mjs
├── ScreenLayer.mjs
...

I think getting rid of index where appropriate may be worth it regardless of whichever structure we land on.

@timkurvers
Copy link
Member Author

Addressed through #44 by dropping (most) usage of index, and rather spelling out modules fully qualified.

Original example:

src/gfx
├── Color.mjs
├── Device
│   └── index.mjs
├── Screen
│   ├── Layer.mjs
│   └── index.mjs
├── Shader
│   ├── Registry.mjs
│   └── index.mjs
...

Is now:

src/gfx
├── Color.ts
├── Device.ts
├── Screen.ts
├── ScreenLayer.ts
├── ShaderRegistry.ts
├── Shader.ts
...

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

2 participants