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

Access linked node dependencies in buildPhase #28

Open
sternenseemann opened this issue Jul 22, 2020 · 6 comments
Open

Access linked node dependencies in buildPhase #28

sternenseemann opened this issue Jul 22, 2020 · 6 comments

Comments

@sternenseemann
Copy link
Collaborator

In buildNodePackage you can set a custom buildPhase, but such a buildPhase has no way of accessing the node_modules folder in which its dependencies are located, in fact this is only generated in installPhase.

Many node packages will however will need some of their devDependencies at build time, maybe to do CoffeScript transpilation using their prepare script or similar.

Possible fixes:

  • Export NODE_PATH pointing to node_modules. This environment variable seemingly is considered depreacated by now, but node's require for example will check here for dependencies.
  • Symlink node_modules into the build directory — probably a huge nightmare
@sternenseemann
Copy link
Collaborator Author

Probably this would be a good opportunity to resolve #5.

@Profpatsch
Copy link
Owner

So we do need a way to pass devDependencies as a separate set, and then to pass them to the build phase.

I would like to think that we can treat devDependencies as a separate list of dependencies, completely removed from dependencies (and thus have to only pass devDependencies to the build phase), but in practice many packages will expect both dependencies and devDependencies to be availabe during the build …

So I guess what I’m trying to say is that we want to treat them as separate sets, pass both into the buildPhase, and then pass only dependencies into the final runtime closure by default, and provide a flag to add more dependencies from devDependencies into the runtime deps in case the package is buggy and depends on devDependencies at runtime.

@sternenseemann
Copy link
Collaborator Author

You also need access to the normal dependencies for some use cases, for example if you are building a frontend application using browserify which effectively mashes all deps in a single js file at build time (I think we should support such a use case, since it should only be a matter of passing a custom buildPhase and installPhase).

Also here it can be made seen why splitting devDependencies and dependencies might be dangerous business: It is already sometimes very difficult to impossible to convince JavaScript tooling to search for node_modules somewhere else than the current directory. Making them check for stuff in two places will probably be a lot of hassle.

I think your approach is sensible in this regard, we'll just increase the build time by linking a separate set, but at least it will work.

@sternenseemann
Copy link
Collaborator Author

I guess we should add some kind of setup hook for this — which would make it transparent to the user and even configurable. Setting NODE_PATH could be convenient, but possibly surprising behavior.

@sternenseemann
Copy link
Collaborator Author

Also PATH should be extended to include ${linkNodeDeps nodeBuildInputs}/.bin in case you want to run any scripts using yarn/npm involving transpilers etc.

@sternenseemann
Copy link
Collaborator Author

node2nix seems to set NODE_PATH to its built node_modules directory.

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