Skip to content
Fallow home
All docs pages

Docs home

Workspace configuration

Find the options and config keys that scope a run to packages, add workspace patterns and set keys for some packages of a monorepo.

A monorepo needs settings that a single package does not. One team wants the report of its own package only. A folder such as tools/codegen has a package.json, but no workspace pattern declares it, so its files show as unused. A library package has exports that only other repositories import. The examples below use the small monorepo of Workspaces, which explains how fallow finds the packages and follows imports between them. Analyze a monorepo shows the steps of a first run.

Start with the packages that fallow found:

npx fallow workspaces
Discovered 2 workspaces
  @acme/ui -> packages/ui (internal dep)
  @acme/web -> packages/web
1 workspace discovery diagnostic:
  - Directory 'tools/codegen' contains package.json but is not declared as a workspace. Add it to package.json workspaces or pnpm-workspace.yaml, or add it to ignorePatterns.

Scope a run to packages

These options limit the report to some workspaces. Fallow still analyzes each package, so an export that another package uses stays used. In the example monorepo, fallow dead-code -w packages/web reports only the unused left-pad dependency of packages/web, and leaves out packages/ui/src/old-card.ts.

OptionEffect
--workspace <PATTERN>, -wReport only the selected packages. A pattern is a package name, a workspace path, a glob or a ! exclusion. Separate patterns with commas, or repeat the option.
--changed-workspaces <REF>Report only the packages with a file that changed since the Git ref. You cannot use it together with --workspace.
--group-by packageGroup the report by package.
# All apps except one
fallow dead-code -w 'apps/*,!apps/legacy'

# Only the packages that this branch changed
fallow dead-code --changed-workspaces origin/main

A package inside a selected package stays in the report. To leave it out, add a ! pattern for it, for example -w 'apps/web,!apps/web/plugin'.

Put a pattern with ! or * in quotes, so that your shell does not change it. Global options has each option.

Config keys

An option changes one run. A setting that must apply to each run, for each person and each CI job, goes in the config file:

KeyUse
workspaces.patternsAdd packages that the package manager does not declare.
workspaces.settingsSet ignoreDependencies and includeEntryExports for some packages.
workspaces.changedSinceGive each package its own Git ref for the changed files.
publicPackagesKeep the exports of packages that code outside the repository uses.
overridesSet rule severities for the files of some packages.

Fallow loads one config file for each run. It looks in the project root and then in each parent directory. Thus a run in a package directory uses the root config when the package has no config file. Config file names has the order. The keys of a workspace, such as workspaces.settings, name each package by its path relative to the project root, as fallow workspaces prints it.

Additional workspace patterns

Fallow reads the workspace patterns of package.json, pnpm-workspace.yaml, a root deno.json and the references of tsconfig.json. In the example, none of them declares tools/codegen, so fallow dead-code reports tools/codegen/index.js as an unused file. Add the packages that none of these files declare:

// .fallowrc.json
{
  "workspaces": {
    "patterns": ["tools/*"]
  }
}
Discovered 3 workspaces
  @acme/ui -> packages/ui (internal dep)
  @acme/web -> packages/web
  @acme/codegen -> tools/codegen

With the pattern, the main file of tools/codegen/package.json becomes an entry point, so tools/codegen/index.js is reachable and is not an unused file. A package that a pattern finds is a full workspace. It gets its own plugins, entry points and dependency checks. --workspace, --changed-workspaces, --group-by package and fallow workspaces use it too.

Per-workspace settings

Packages differ: a server app needs a native package that no file imports, and a library must check the exports of its entry files. workspaces.settings sets two keys for the packages that a key selects. A key is a workspace path or a glob over workspace paths.

// .fallowrc.json
{
  "workspaces": {
    "settings": {
      "packages/*": { "includeEntryExports": true },
      "apps/server": { "ignoreDependencies": ["pg-native"] }
    }
  }
}
  • ignoreDependencies: a package gets the global list and the list of each key that selects it.
  • includeEntryExports: an exact path wins over a glob, and a longer glob wins over a shorter glob. A package that no key selects uses the global value. The --include-entry-exports option turns the check on in each package.
  • The root package uses only the global keys. A key that selects no package gives a warning.

Per-package change baselines

In a large monorepo, the packages are often at different stages of a cleanup. A team that starts today wants to see only the findings of its new work. workspaces.changedSince gives a package its own Git ref. For that package, fallow reports only the findings in files that changed since the ref. Other packages and the files outside each package stay in full scope.

// .fallowrc.json
{
  "workspaces": {
    "changedSince": {
      "packages/web": "main",
      "packages/legacy": "release/2024.10"
    }
  }
}
  • fallow dead-code, fallow dupes, the bare fallow run and the editor read the map. fallow audit, fallow health and fallow security do not read it.
  • A --changed-since option replaces the map for the run.
  • --no-package-baselines or FALLOW_PACKAGE_BASELINES=false turns the map off.
  • A key that names no package, or a ref that Git cannot find, turns the map off for the run. Fallow writes a warning, and the report covers each package.
  • A malformed key or ref, such as an absolute path or a ref with a space, stops the run with exit code 2.

The map also limits a saved baseline. To save a baseline of the whole project, add --no-package-baselines:

fallow dead-code --no-package-baselines --save-baseline fallow-baselines/dead-code.json

Public packages

A library package can have exports that only code outside the repository uses. List the package in publicPackages, and fallow treats its entry points and exports as used:

// .fallowrc.json
{ "publicPackages": ["@acme/sdk", "@acme/ui-*"] }

A value is a package name or a glob over package names.

Fallow treats a workspace package as internal unless publicPackages lists it. Some packages look published: the package.json is not "private": true and has an exports, main or module field. When such a package has findings on the exports or members that its entry publishes, fallow names the package in a note:

Note: these workspace packages look published, but publicPackages does not list them: @acme/sdk (12 findings on the exports or members of its entry). If a package is published, add it to publicPackages, so fallow treats its entry exports as public API.

If the project publishes the package, add it to publicPackages. If the package is internal, set "private": true in its package.json. The note changes no finding and no exit code. A --workspace run shows the note only for the selected packages, and a --changed-since, diff or --file run does not show it. JSON output has the same hint as a public-package-candidate entry in workspace_diagnostics.

Details

When a package in your repository has an unusual layout, find its case in this table:

TopicFact
Nested projectsA folder with its own package.json and also a pnpm-workspace.yaml or a lockfile (package-lock.json, npm-shrinkwrap.json, yarn.lock, pnpm-lock.yaml, bun.lock or bun.lockb), which no root pattern declares, is an independent project. Fallow looks for these folders up to two levels below the root, and only when the root declares workspace patterns. The project is a workspace with a nested-project-root diagnostic, which is information only. Framework plugins activate from its dependencies, for example Docusaurus for a docs site in docs/. With a pnpm-workspace.yaml, the members of its packages list are workspaces too, and its catalog: references use its own catalog. A folder with a package.json and no lockfile gets undeclared-workspace. To leave a project out, add it to ignorePatterns.
Gitignored workspace membersIn a Git repository, fallow does not read the files of a member in a folder that .gitignore excludes, for example an upstream repository that CI clones into the workspace. Fallow then does not report the dependencies of that member as unused. The member is still a workspace, so imports and catalog references reach its package.json.
Workspace aliasesA dependency such as "vite": "workspace:@myorg/core@*" installs the workspace @myorg/core under the name vite. Fallow resolves vite/<subpath> through the exports of @myorg/core, also when another workspace has the name vite. The use counts for the dependency vite.
Members of nested npm and Yarn projectsFallow reads the members of a nested project only through its pnpm-workspace.yaml. It does not read the workspaces field of a nested package.json.
Nested package manifestsFallow checks the imports of a file against the nearest package.json in the project, also when no workspace pattern declares that package. That package.json does not make the folder a workspace.
Symlinks and the pnpm storeAn import of a workspace package resolves through the link in node_modules to the real source file, and the use counts there. Fallow also maps a path in the .pnpm virtual store of pnpm back to the source file of the workspace.
exports subpathsFallow resolves the exports field of each workspace, with conditions and subpath patterns. With "./theme/*": "./src/theme/*.ts", an import of @acme/ui/theme/dark resolves to packages/ui/src/theme/dark.ts.
Output foldersA package.json target in dist, build, out, esm or cjs maps to the same path under src/. Fallow tries the extensions .ts, .tsx, .mts, .cts, .js, .jsx, .mjs and .cjs. This also applies to a nested path and to a type target: dist/index.d.ts maps to src/index.ts. A target in lib/ maps to src/ only when the lib/ file is not in the analyzed files, for example before the build. A package with hand-written source in lib/ keeps its files.
Path aliases of a workspaceFallow uses the nearest tsconfig.json of each file, so the paths of a workspace apply to the files of that workspace. A framework alias of a workspace, such as SvelteKit $lib or Nuxt ~/, also applies only to the files of that workspace.
Dependency declarationsThe workspace of a file must declare each package that the file imports, also a workspace package. This applies to the project root too. A private workspace, or a test, config or build file, can use a declaration of a parent workspace or of the root. A production file of a publishable workspace needs its own declaration. A package can import itself by name. When your project permits an import without a declaration, add the package to ignoreDependencies.
Deno workspacesFallow reads the workspace field of a root deno.json or deno.jsonc, as an array or as { "members": [...] }. The name and exports of a member work like the same fields of package.json. When a member has both files, package.json gives the package name. Member names count as declared dependencies. A malformed root Deno config stops the run with exit code 2. A Deno project without a package.json gets no diagnostic for a missing node_modules.
Deno import mapsFallow resolves the imports of the root and member configs. An exact match wins. Else the longest matching entry that ends with / applies.