package.json
Файл манифеста пакета. Он содержит все метаданные пакета, включая зависимости, заголовок, автора и т.д. Это стандарт для всех основных пакетных менеджеров Node.JS, включая pnpm.
engines
Вы можете указать версию Node и pnpm, на которой работает ваш программный продукт:
{
"engines": {
"node": ">=10",
"pnpm": ">=3"
}
}
Во время локальной разработки pnpm всегда выдает сообщение об ошибке, если его версия не совпадает с версией, указанной в поле engines.
Если только пользователь не установил флаг конфигурации engine-strict (см. .npmrc), это поле носит исключительно рекомендательный характер и будет выдавать предупреждения только тогда, когда ваш пакет установлен как зависимость.
dependenciesMeta
Additional meta information used for dependencies declared inside dependencies, optionalDependencies, and devDependencies.
dependenciesMeta.*.injected
If this is set to true for a dependency that is a local workspace package, that package will be installed by creating a hard linked copy in the virtual store (node_modules/.pnpm).
If this is set to false or not set, then the dependency will instead be installed by creating a node_modules symlink that points to the package's source directory in the workspace. This is the default, as it is faster and ensures that any modifications to the dependency will be immediately visible to its consumers.
For example, suppose the following package.json is a local workspace package:
{
"name": "card",
"dependencies": {
"button": "workspace:1.0.0"
}
}
The button dependency will normally be installed by creating a symlink in the node_modules directory of card, pointing to the development directory for button.
But what if button specifies react in its peerDependencies? If all projects in the monorepo use the same version of react, then there is no problem. But what if button is required by card that uses react@16 and form that uses react@17? Normally you'd have to choose a single version of react and specify it using devDependencies of button. Symlinking does not provide a way for the react peer dependency to be satisfied differently by different consumers such as card and form.
The injected field solves this problem by installing a hard linked copies of button in the virtual store. To accomplish this, the package.json of card could be configured as follows:
{
"name": "card",
"dependencies": {
"button": "workspace:1.0.0",
"react": "16"
},
"dependenciesMeta": {
"button": {
"injected": true
}
}
}
Whereas the package.json of form could be configured as follows:
{
"name": "form",
"dependencies": {
"button": "workspace:1.0.0",
"react": "17"
},
"dependenciesMeta": {
"button": {
"injected": true
}
}
}