Налаштування (pnpm-workspace.yaml)

pnpm отримує налаштування з командного рядка, змінних середовища та файлу pnpm-workspace.yaml.

Only auth, registry, TLS, proxy, and local-address settings are read from .npmrc files. All other settings are configured in pnpm-workspace.yaml or the global config.yaml. Some settings are limited to one of them: settings that define the structure of node_modules (like hoistPattern, publicHoistPattern, nodeLinker, or shamefullyHoist) can only be set in pnpm-workspace.yaml, while settings that name machine-level state (like stateDir or pnpmHomeDir) are not read from pnpm-workspace.yaml.

Команду pnpm config можна використовувати для читання та редагування вмісту файлів проєкту та файлів глобальної конфігурації.

Відповідні конфігураційні файли:

  • Конфігураційний файл для кожного проєкту: /path/to/my/project/pnpm-workspace.yaml
  • Global configuration file

нотатка

Налаштування, пов'язані з авторизацією, обробляються через .npmrc.

Значення у файлах конфігурації можуть містити змінні env із використанням синтаксису ${NAME}. Змінні env також можуть бути вказані зі стандартними значеннями. Використання ${NAME-fallback} поверне fallback, якщо NAME не задано. ${NAME:-fallback} поверне fallback, якщо NAME не задано або є порожнім рядком. Since v12.7.0, ${NAME?} expands to an empty string without a warning when NAME isn't set, as in npm.

попередження

Env variables are not expanded in settings of pnpm-workspace.yaml that define registry URLs: registry and the URL values of registries and namedRegistries. A ${...} placeholder in these settings fails the command, because ignoring the URL would resolve packages from another registry. In the registry declaration shape of registries, the URL is the key rather than the value, and the same rule applies to the keys. Because pnpm-workspace.yaml is committed to the repository, expanding env variables in registry URLs could be exploited by a malicious repository to leak secrets from the environment to an attacker-controlled registry. Configure dynamic registry URLs in a trusted location instead: the global configuration file or CLI options.

Since v12.7.0, the same applies to userAgent: a userAgent in pnpm-workspace.yaml that contains a ${...} placeholder is ignored, because the user agent is sent to the configured registry with every request.

нотатка

A project's pnpm-workspace.yaml cannot choose where pnpm keeps its credentials, its own installation, or other machine-level state: bin, configDir, dir, globalBinDir, globalDir, macosBackup, npmrcAuthFile, pnpmHomeDir, scope, stateDir, userconfig, and workspaceDir are ignored there, with a warning. So are ci, globalShims, symlinkedLockfileTargetDirs, and tools. Of these, only globalShims may also be set in a pnpm-workspace.yaml in the pnpm home directory. Set them in the global configuration file or on the command line instead. cacheDir and storeDir are unaffected.

packages#

Besides settings, pnpm-workspace.yaml defines the root of the workspace and enables you to include / exclude directories from the workspace. If the packages field is omitted, only the root package is included in the workspace.

Наприклад:

pnpm-workspace.yaml
packages:
  # вказує на пакунок у безпосередній теці кореня
  - 'my-app'
  # всі пакунки в безпосередніх вкладених теках packages/
  - 'packages/*'
  # всі пакунки у вкладених теках components/
  - 'components/**'
  # виключити пакунки, які знаходяться всередині тестових тек
  - '!**/test/**'

Кореневий пакунок завжди включається, навіть якщо використовуються користувацькі шаблони розташування.

A pattern may be written with a ./ prefix, may contain . and .. segments, and may repeat slashes: ./packages/* and packages//* select the same projects, and !./packages/legacy excludes the same directory that !packages/legacy does. A * never matches a name beginning with a dot, so packages/* skips packages/.cache; name such a directory explicitly to include it.

нотатка

pnpm reads the workspace from pnpm-workspace.yaml, not from the workspaces field of the root package.json. Since v12.4.1, a root manifest that declares a non-empty workspaces array in a project with no pnpm-workspace.yaml gets a warning, because such an install silently links no project at all.

Каталоги також визначено у файлі pnpm-workspace.yaml. Докладніше див. у Каталоги.

pnpm-workspace.yaml
packages:
  - 'packages/*'

catalog:
  chalk: ^4.1.2

catalogs:
  react16:
    react: ^16.7.0
    react-dom: ^16.7.0
  react17:
    react: ^17.10.0
    react-dom: ^17.10.0

packageConfigs#

Дозволяє налаштовувати параметри для окремих пакунків робочого простору відповідно до вимог конкретного проєкту. Це замінює файли .npmrc, що належать до конкретних проєктів у робочому просторі.

packageConfigs можна вказати у вигляді мапи, в якій імена пакунків відповідають об’єктам конфігурації:

pnpm-workspace.yaml
packages:
  - "packages/project-1"
  - "packages/project-2"
packageConfigs:
  "project-1":
    saveExact: true
  "project-2":
    savePrefix: "~"

Або у вигляді масиву правил, що відповідають шаблонам:

pnpm-workspace.yaml
packages:
  - "packages/project-1"
  - "packages/project-2"
packageConfigs:
  - match: ["project-1", "project-2"]
    modulesDir: "node_modules"
    saveExact: true

Settings that shape resolution or the layout of node_modules (overrides, hoist, modulesDir, saveExact, savePrefix, and their neighbours) take effect per project only where each project has its own lockfile, that is with sharedWorkspaceLockfile: false. A workspace on the default shared lockfile has one resolution for every project, so pnpm reports which entries it ignored instead of applying them silently.

Налаштування#

Every setting is listed below, grouped by topic. Follow a setting to read its documentation, or open the full reference of a group.

Розвʼязання залежностей#

Full reference →

node_modules settings#

Full reference →

Dependency hoisting settings#

Full reference →

Store settings#

Full reference →

Lockfile settings#

Full reference →

Network settings#

Full reference →

Request settings#

Full reference →

Peer dependency settings#

Full reference →

Параметри CLI#

Full reference →

Node.js settings#

Full reference →

Build settings#

Full reference →

Versioning settings#

Full reference →

Other settings#

Full reference →

Workspace settings#

These settings are configured in pnpm-workspace.yaml as well, but are documented together with the workspace feature they belong to.

Full reference →

Settings documented elsewhere#