Skip to content

Make local-dev-lib a peerdependancy#34

Merged
camden11 merged 1 commit into
mainfrom
use-local-dev-lib-peer-dependancy
Nov 7, 2023
Merged

Make local-dev-lib a peerdependancy#34
camden11 merged 1 commit into
mainfrom
use-local-dev-lib-peer-dependancy

Conversation

@camden11
Copy link
Copy Markdown
Contributor

@camden11 camden11 commented Nov 3, 2023

Context

Previously, both hubspot-cli and cli-lib used the cli-lib/config module to interact with the hubspot.config.yml file. The config module stores information about the config file in a global variable called __config. We recently introduced hubspot-local-dev-lib as a dependency to the CLI. Many modules within local-dev-lib also need to interact with config files, and as local-dev-lib is itself a port of cli-lib, it also provides its own config module with its own instance of __config. Having two separate instances of __config causes bugs, so in an attempt to remedy this, we added local-dev-lib as a dep to cli-lib and deferred to its instance of __config. Unfortunately things were not so simple. hubspot-cli's dependancies on hubspot-local-dev-lib look something like this:

  • node_modules/@hubspot/local-dev-lib
  • node_modules/@hubspot/clli-lib/node_modules/local-dev-lib

This works, but only if both hubspot-cli and cli-lib use the same version of @hubspot-local-dev-lib. There are many ways for versions between the two to get out of whack, resulting in two separate __config instances and causing bugs. Our solution is to switch local-dev-lib to a peerDependency within the CLI. Peer dependencies are a feature of npm that allow you to stipulate that package A requires package B, but will not install the dependency on its own. Instead, any package C that has a dependency on package A must also have a dependency on package B. By using them, we can assure that package A (cli-lib) uses the same package B (local-dev-lib) as package C (hubspot-cli).

The only side effect is that now, any package with a dependency on cli-lib must also explicitly specify a dependency on local-dev-lib in its package.json. We will have to do a major release to make this change

Some more info on peerDependencies, since we didn't know much about them prior to running into this problem

Who to Notify

@brandenrodgers

@camden11 camden11 marked this pull request as ready for review November 3, 2023 19:17
Copy link
Copy Markdown
Contributor

@brandenrodgers brandenrodgers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the thorough explanation 🙏

@camden11 camden11 merged commit 1e4553a into main Nov 7, 2023
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

Successfully merging this pull request may close these issues.

2 participants