Configuration File
Monorepolint (mrl) requires a configuration file located at the root of your monorepo, named .monorepolint.config.mjs
. This file serves as the central configuration for your project, allowing you to maintain consistency across your sub-projects.
In earlier versions of monorepolint, the configuration file was named monorepolint.config.ts
. Due to difficulties in maintaining TypeScript configurations that type-checked properly, particularly in Visual Studio Code, this format has been removed.
If you prefer to use TypeScript for your configuration, consider creating a separate project and referencing it from your root configuration file.
Configuration File Format
A monorepolint configuration file is a simple JavaScript file. To apply specific rules, simply import and invoke the corresponding functions:
import { alphabeticalDependencies } from "@monorepolint/rules";
export default {
rules: [alphabeticalDependencies({})],
};
Using a factory function
(Since v0.6.0) You may also do some preprocessing work if needed. For example, you can create a factory function that returns a rule configuration object:
import { alphabeticalDependencies } from "@monorepolint/rules";
function createConfig(context) {
return {
rules: [alphabeticalDependencies({})],
};
}
export default createConfig;
Built-in and Custom Rules
Built-in rules are just functions exported from @monorepolint/rules
. For information on creating custom rules, refer to the Writing Custom Rules documentation.
:::
Common Configuration Options
Each rule configuration supports the following options:
type CommonOptions<T> {
/** Unique Per Rule **/
options?: T;
/**
* Package names or minimatch globs of package names
* allowing certain packages to be excluded from this rule.
* @default excluding no child packages.
**/
excludePackages?: string[] | undefined;
/**
* Package names or minimatch globs of package names
* for specifying specific packages this applies to.
* @default including all child packages.
**/
includePackages?: string[] | undefined;
/**
* Whether to include the root package for this rule
* @default false
*/
includeWorkspaceRoot?: boolean | undefined;
}
Detailed Example
import {
alphabeticalDependencies,
alphabeticalScripts,
bannedDependencies,
consistentDependences,
packageOrder,
packageScript,
} from "@monorepolint/rules";
export default {
rules: [
packageScript({
options: {
scripts: {
clean: "rm -rf build lib node_modules *.tgz",
test: "../../node_modules/.bin/jest --colors --passWithNoTests",
},
},
}),
packageOrder({}),
alphabeticalDependencies({}),
bannedDependencies({
options: {
bannedDependencies: ["lodash"],
},
includeWorkspaceRoot: true,
}),
consistentDependencies({}),
],
};
This will ensure that all projects have a clean
and test
task, that the order of the entries in package.json are sane, that dependencies and scripts are kept in alphabetical order, that lodash is banned from the project, and the last one ensures that if a package is listed in the root package.json, all packages in the workspace that list that dependency must match the same version.