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

What about undeclared dynamic dependencies? #73

Open
alexeagle opened this issue Aug 24, 2018 · 9 comments
Open

What about undeclared dynamic dependencies? #73

alexeagle opened this issue Aug 24, 2018 · 9 comments

Comments

@alexeagle
Copy link

npm has the semantics that all programs see the entire node_modules tree. This allows libraries to have the dubious behavior "I don't declare any kind of dependency on foolib in my package.json, but if you just install foolib into your project, I'll have different behavior". That's because a program can just try { require('foolib') } and have conditional behavior based on whether it was found.

It seems to me that any formulation of individual npm packages under bazel, where a package's dependencies are expected to be declared statically, is going to have the flaw that some program behavior no longer works because the dynamic lookup of foolib fails when it's not in the declared action inputs.

Have you thought about this at all?

@alexeagle
Copy link
Author

Ping @pcj in case you don't check new issues in this repo very often.

@pcj
Copy link
Contributor

pcj commented Aug 24, 2018

I see your point.

My personal opinion is that implicit/undeclared dependencies in npm modules should be regarded as bugs. As an npm library developer I SHOULD declare all my dependencies. For bazel, it would seem that end-users / application develops will need to be aware of these undeclared dependencies and explicitly declare them.

Granted I'm sure this is an over-simplification. WDYT?

@alexeagle
Copy link
Author

alexeagle commented Aug 28, 2018 via email

@pcj
Copy link
Contributor

pcj commented Aug 28, 2018

Do you have a concrete example? Could be a foundation to educate community better.

@alexeagle
Copy link
Author

We just made a change to Angular, such that the closure compiler compat layer (tsickle) is not required for @angular/compiler-cli. We attempt to require it, and if found, then we output code that has closure compiler JSDoc annotations.

@gregmagolan
Copy link

I don't think using optionalDependencies approach will work for the tsickle case. npm and yarn always attempt to install optionalDependencies and if the install fails then it is ignored.

Packages are meant to handle a missing optional dependency gracefully at runtime. For example, chokidar has an optional dependency on fsevents, which installs fine on osx/linux but fails to install on Windows. chokidar would have to handle gracefully at runtime if fsevents is missing.

For the tsickle case, we'd need bazel specific attribute in a package.json that would mean check if this dependency exists in node_modules and add it as a transitive dep in the filegroup if it does. npm & yarn wouldn't install and deps listed in that attribute.

Thoughts?

@alexeagle
Copy link
Author

I'm bumping into this again in bazelbuild/rules_typescript#398

@alexeagle
Copy link
Author

I think we are settling on bazelDynamicDependencies
We would like to use dynamicDependencies but maybe npm will decide that has a meaning in the future?

@sgammon
Copy link

sgammon commented Jun 21, 2019

@alexeagle did bazelDynamicDependencies ever get implemented?

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

4 participants