Skip to content
This repository was archived by the owner on Sep 10, 2026. It is now read-only.
This repository was archived by the owner on Sep 10, 2026. It is now read-only.

What about undeclared dynamic dependencies? #73

Open

Description

@alexeagle

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?

Activity

  1. alexeagle commented on Aug 24, 2018

    @alexeagle
    Author

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

  2. pcj commented on Aug 24, 2018

    @pcj
    Contributor

    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?

  3. alexeagle commented on Aug 28, 2018

    @alexeagle
    Author
  4. pcj commented on Aug 28, 2018

    @pcj
    Contributor

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

  5. alexeagle commented on Sep 11, 2018

    @alexeagle
    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.

  6. gregmagolan commented on Sep 13, 2018

    @gregmagolan

    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?

  7. alexeagle commented on Feb 13, 2019

    @alexeagle
    Author

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

  8. alexeagle commented on Feb 13, 2019

    @alexeagle
    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?

  9. sgammon commented on Jun 21, 2019

    @sgammon

    @alexeagle did bazelDynamicDependencies ever get implemented?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions