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

Support for optionalDependencies #37

Open
Profpatsch opened this issue Jul 24, 2020 · 5 comments
Open

Support for optionalDependencies #37

Profpatsch opened this issue Jul 24, 2020 · 5 comments

Comments

@Profpatsch
Copy link
Owner

Profpatsch commented Jul 24, 2020

Looks like npm finally added a field optionalDependencies.

So we should support it somehow.

I have no idea what the semantics are.

@sternenseemann
Copy link
Collaborator

Maybe a switch to enable including optionalDependencies in the node_modules directory? Such a switch would be a last resort if a build fails otherwise, since theoretically you'd expect an optional dependency being in the dependencies field somewhere in the dependency tree.

@Profpatsch
Copy link
Owner Author

since theoretically you'd expect an optional dependency being in the dependencies field somewhere in the dependency tree.

That wouldn’t make the require() for package Y work however, because we just symlink the tree; let’s see X has dep D it as a normal dependency and Y has it as optionalDependency:

X/node_modules/D  (symlink to /nix/store/…)
Y/node_modules/… (no reference to D because it’s an optionalDependency, require() returns `null`)

@Profpatsch
Copy link
Owner Author

Profpatsch commented Jul 24, 2020

tbh I have no idea how to handle this situation except for making it easy to add optional dependencies to certain packages in the lockfile. We already have at least partial override support, so maybe this is just a matter of documentation (after finding a use-case where it makes sense to enable an optional dependency that is).

@Profpatsch
Copy link
Owner Author

Another step would be to figure out the following: does the yarn.lock file contain optionalDependencies (and peerDependencies) by default, or do you have to tell yarn explicitly to include them?

@sternenseemann
Copy link
Collaborator

That wouldn’t make the require() for package Y work however, because we just symlink the tree; let’s see X has dep D it as a normal dependency and Y has it as optionalDependency:

This problem could be circumvented by wrapping output executables and collecting all node_modules directories into NODE_PATH (now that I write it — sounds horrible). The big problem here is that apparently support for NODE_PATH in the node community seems to be rather poor, some even call it deprecated. For example browserify/resolve which claims to implement the nodejs require.resolve() algorithm diverts from nodejs by not supporting NODE_PATH (see this dismissed PR and this issue).

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