socketsupply / union-app-studio

Like Codepen, but for native apps!

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Why are you putting code by this library in a node_modules folder?

Haroenv opened this issue · comments

This is just out of curiosity, but why didn't you put them in the same folder as index.js and require('./editor')? This seems like an odd pattern I haven't seen before :)

This is a strategy for code organization. The main benefits are...

  1. It's not an arbitrary structure. One unit of discrete functionality is described as one module.
  2. It provides a clear path for making application code public (without breaking things internally).
  3. It makes refactors so simpler (no paths are hard coded, no paths are ambiguous).
  4. It's not any more difficult to understand, it only improves readability of a codebase.

I could keep listing reasons, but you get the idea.

I don't agree with this (it's your project, you don't have to listen to me). Storing project code in node_modules is not a good idea. Many processes and systems ignore or delete node_modules because it's supposed to be reproducible from package.json. So your project should be in a state which at any given time, node_modules can be deleted and reinstalled and nothing changes.

But in your case, if that node_modules folder is deleted, all your application logic is gone and the app does nothing. If you want to keep them there, you can publish the modules separately to npm under a namespace. eg. @scratches/editor and require them from there.

But this way, you're only hacking Node's module resolution algorithm just to avoid requiring the modules using a ./ style path.