Monorepo Updating
Helper functions for updating dependencies within a monorepo.
Functions
Section titled “Functions”lintMonorepoPackageJSONs()
Section titled “lintMonorepoPackageJSONs()”function lintMonorepoPackageJSONs(monorepoRoot): Promise<void>;Defined in: functions/monorepoUpdate.ts:60
Helper function to:
- Check if all of the dependencies in the monorepo children “package.json” files are up to date.
- Check if all of the dependencies in the monorepo children “package.json” files are non-exact.
- Check if any dependencies in the monorepo root “package.json” are unused.
This is intended to be called in a monorepo lint script. It will exit the program with an error code of 1 if discrepancies are found.
This function attempts to find the monorepo root directory automatically based on searching backwards from the file of the calling function.
Note that this function is not needed if the monorepo is using the pnpm or bun “catalog” feature, since that will automatically keep package dependencies in-sync.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
monorepoRoot |
string |
Returns
Section titled “Returns”Promise<void>
Throws
Section titled “Throws”If one or more child “package.json” files are out of sync.
updatePackageJSONDependenciesMonorepo()
Section titled “updatePackageJSONDependenciesMonorepo()”function updatePackageJSONDependenciesMonorepo( importMetaDirname, packagesWithoutCooldown?,): Promise<boolean>;Defined in: functions/monorepoUpdate.ts:96
Helper function to update the dependencies in all of the monorepo “package.json” files. If there are any updates, the package manager used in the project will be automatically invoked to install them.
(This is only useful in monorepos that do not use the “catalog” feature to
consolidate dependency versions. For those cases, the
updatePackageJSONDependencies function should be used, since it properly
handles workspaces.)
This function attempts to find the monorepo root directory automatically based on searching backwards from the file of the calling function.
Under the hood, this function calls the updatePackageJSONDependencies and
updatePackageJSONDependenciesMonorepoChildren helper functions.
If you need to check to see if the monorepo dependencies are up to date in a
lint script, then use the lintMonorepoPackageJSONs function instead.
Parameters
Section titled “Parameters”| Parameter | Type | Default value | Description |
|---|---|---|---|
importMetaDirname |
string |
undefined |
The value of import.meta.dirname (so that this function can find the package root). |
packagesWithoutCooldown |
readonly string[] |
[] |
Optional. Package names that should be updated without applying the dependency cooldown. |
Returns
Section titled “Returns”Promise<boolean>
Whether any “package.json” files were changed.
updatePackageJSONDependenciesMonorepoChildren()
Section titled “updatePackageJSONDependenciesMonorepoChildren()”function updatePackageJSONDependenciesMonorepoChildren( monorepoRoot, dryRun?,): Promise<boolean>;Defined in: functions/monorepoUpdate.ts:141
Helper function to only update the dependencies in the “package.json” files of the sub-packages of a monorepo.
This will update both the normal dependencies (to match what is in the monorepo root “package.json”) and the monorepo dependencies (to be what is listed in the “version” field of the respective “package.json” file).
This function is called by the updatePackageJSONDependenciesMonorepo script.
If you need to check to see if the monorepo dependencies are up to date in a
lint script, then use the lintMonorepoPackageJSONs function instead.
Note that this function will be a no-op if the “package.json” file is found to contain a catalog.
Parameters
Section titled “Parameters”| Parameter | Type | Default value | Description |
|---|---|---|---|
monorepoRoot |
string |
undefined |
The full path to the monorepo root directory. |
dryRun |
boolean |
false |
Optional. If true, will not modify the “package.json” files. Defaults to false. |
Returns
Section titled “Returns”Promise<boolean>
Whether all of the “package.json” files were valid.
Throws
Section titled “Throws”If one or more monorepo dependencies are unused.
